Use template literals instead of string concatenation (#1003)

* use template literals instead of string concatenation
* extract function call out of template literals
* add contributing hint to don't put function calls in template-literals
This commit is contained in:
Thomas Rupprecht 2022-12-04 12:00:18 +01:00 committed by GitHub
parent d4a9861751
commit 2b5ffca1b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 12 deletions

View File

@ -5,6 +5,7 @@
"rules": {
"function-paren-newline": "error",
"prefer-arrow-callback": "error",
"prefer-template": "error",
"no-var": "error",
"quotes": [
"error",

View File

@ -14,6 +14,7 @@
The `default.po` files contain translations that can be auto-detected using Poedit, `additional.po` contains generated messages like validations.
* JavaScript code must pass the ESLint check `yarn lint`.
Auto-fixing is supported via `yarn lint:fix`.
* Don't put function calls in a template-literal (template-strings).
## Pull requests
* The PR should contain a short overview of the changes.

View File

@ -7,8 +7,10 @@
export const formatTime = (date) => {
if (!date instanceof Date) return;
return String(date.getHours()).padStart(2, '0') + ':'
+ String(date.getMinutes()).padStart(2, '0');
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
return `${hours}:${minutes}`;
}
/**
@ -20,7 +22,9 @@ export const formatTime = (date) => {
export const formatDay = (date) => {
if (!date instanceof Date) return;
return String(date.getFullYear()) + '-'
+ String(date.getMonth() + 1).padStart(2, '0') + '-'
+ String(date.getDate()).padStart(2, '0');
const year = String(date.getFullYear());
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
return `${year}-${month}-${day}`;
}

View File

@ -17,7 +17,7 @@ const triggerChange = (element) => {
* @param {boolean} checked True if the checkboxes should be checked
*/
global.checkAll = (id, checked) => {
document.querySelectorAll('#' + id + ' input[type="checkbox"]').forEach((element) => {
document.querySelectorAll(`#${id} input[type="checkbox"]`).forEach((element) => {
element.checked = checked;
});
};
@ -29,7 +29,7 @@ global.checkAll = (id, checked) => {
* @param {int[]} shiftsList A list of numbers
*/
global.checkOwnTypes = (id, shiftsList) => {
document.querySelectorAll('#' + id + ' input[type="checkbox"]').forEach((element) => {
document.querySelectorAll(`#${id} input[type="checkbox"]`).forEach((element) => {
const value = parseInt(element.value, 10);
element.checked = shiftsList.includes(value);
});

View File

@ -31,14 +31,14 @@ ready(() => {
window.addEventListener('scroll', () => {
const top = headers.item(0).parentNode.getBoundingClientRect().top;
const left = 15;
const left = Math.max(0, window.scrollX - 15);
timeLane.style.left = Math.max(0, window.scrollX - left) + 'px';
timeLane.style.left = `${left}px`;
const headersTop = Math.max(
0,
window.scrollY - top - 13 + topReference.getBoundingClientRect().top
) + 'px';
applyStyle(headers, 'top', headersTop);
);
applyStyle(headers, 'top', `${headersTop}px`);
});
});

View File

@ -28,7 +28,8 @@ const plugins = [
let themeFileNameRegex = /theme\d+/;
if (process.env.THEMES) {
themeFileNameRegex = new RegExp(`theme(${process.env.THEMES.replace(/,/g, '|')})\\.`);
const themes = process.env.THEMES.replace(/,/g, '|');
themeFileNameRegex = new RegExp(`theme(${themes})\\.`);
}
const themePath = path.resolve('resources/assets/themes');