Skip to content

Commit 80755dd

Browse files
committed
build: Add eslint
These changes introduce ESLint configuration to the project, establishing standardized code quality and style guidelines. The `eslint.config.mjs` file defines rules for JavaScript, HTML, and Twig files, ensuring code consistency and maintainability. Here's a breakdown of the key aspects: - **ESLint Integration:** The primary change is the introduction of ESLint rules. ESLint helps enforce consistent coding styles and identifies potential errors. - **Rule Configuration:** The `eslint.config.mjs` file specifies various ESLint rules for JavaScript, HTML, and Twig files, such as brace style, indentation, and semicolon usage. - **Global Declarations:** The ESLint configuration explicitly defines global variables, clarifying their usage and preventing unintended conflicts. - **Code Style Enforcement:** This setup enforces consistent code style across the project, making code easier to read and understand. - **Error Detection:** ESLint helps identify potential code issues early on, reducing the chances of runtime errors and improving code quality. - All current issues have been identified and fixed inside the codebase. Additionally, the changes to `main.js` illustrate the application of ESLint rules to existing code. The `no-unused-vars` rule is enabled, helping ensure that all variables are used within their scope. This change helps maintain code clarity and reduce clutter. Overall, these changes represent a significant step towards establishing a robust code quality and style framework for the project.
1 parent 70866f7 commit 80755dd

27 files changed

Lines changed: 2177 additions & 657 deletions

eslint.config.mjs

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
import eslintConfigPrettier from "eslint-config-prettier";
2+
import globals from "globals";
3+
import html from "eslint-plugin-html";
4+
import json from "eslint-plugin-json";
5+
import pluginJs from "@eslint/js";
6+
import stylisticJs from "@stylistic/eslint-plugin-js";
7+
8+
export default [
9+
pluginJs.configs.recommended,
10+
eslintConfigPrettier,
11+
{
12+
files: ["**/*.js", "**/*.html", "**/*.twig"],
13+
languageOptions: {
14+
ecmaVersion: "latest",
15+
sourceType: "commonjs",
16+
globals: {
17+
...globals.browser,
18+
...globals.commonjs,
19+
...globals.node,
20+
$: "readonly",
21+
$id: "readonly",
22+
arch: "readonly",
23+
checkMount: "readonly",
24+
dialog: "readonly",
25+
formatBytes: "readonly",
26+
formatEta: "readonly",
27+
hash_alg: "readonly",
28+
id: "readonly",
29+
ipcRenderer: "readonly",
30+
loadInclude: "readonly",
31+
path: "readonly",
32+
platform: "readonly",
33+
remote: "readonly",
34+
shell: "readonly",
35+
sidenoderHome: "readonly",
36+
version: "readonly",
37+
win: "readonly",
38+
},
39+
},
40+
plugins: {
41+
html,
42+
"@stylistic/js": stylisticJs,
43+
},
44+
rules: {
45+
"@stylistic/js/brace-style": [
46+
"error",
47+
"1tbs",
48+
{ allowSingleLine: false },
49+
],
50+
"@stylistic/js/indent": [
51+
"error",
52+
2,
53+
{
54+
ignoredNodes: ["TemplateLiteral"],
55+
SwitchCase: 1,
56+
},
57+
],
58+
"@stylistic/js/no-mixed-spaces-and-tabs": ["error"],
59+
"@stylistic/js/semi": ["error", "always"],
60+
"constructor-super": ["error"],
61+
curly: ["error", "all"],
62+
eqeqeq: ["error", "always"],
63+
"for-direction": ["error"],
64+
"getter-return": ["error"],
65+
"no-async-promise-executor": ["error"],
66+
"no-case-declarations": ["error"],
67+
"no-class-assign": ["error"],
68+
"no-compare-neg-zero": ["error"],
69+
"no-cond-assign": ["error"],
70+
"no-const-assign": ["error"],
71+
"no-constant-condition": ["error"],
72+
"no-control-regex": ["error"],
73+
"no-debugger": ["error"],
74+
"no-delete-var": ["error"],
75+
"no-dupe-args": ["error"],
76+
"no-dupe-class-members": ["error"],
77+
"no-dupe-else-if": ["error"],
78+
"no-dupe-keys": ["error"],
79+
"no-duplicate-case": ["error"],
80+
"no-else-return": ["error"],
81+
"no-empty": ["error"],
82+
"no-empty-character-class": ["error"],
83+
"no-empty-pattern": ["error"],
84+
"no-ex-assign": ["error"],
85+
"no-extra-boolean-cast": ["off"],
86+
"no-fallthrough": ["error"],
87+
"no-func-assign": ["error"],
88+
"no-global-assign": ["error"],
89+
"no-import-assign": ["error"],
90+
"no-inner-declarations": ["off"],
91+
"no-invalid-regexp": ["error"],
92+
"no-irregular-whitespace": ["error"],
93+
"no-loss-of-precision": ["error"],
94+
"no-misleading-character-class": ["error"],
95+
"no-nonoctal-decimal-escape": ["error"],
96+
"no-obj-calls": ["error"],
97+
"no-octal": ["error"],
98+
"no-prototype-builtins": ["error"],
99+
"no-redeclare": ["error"],
100+
"no-regex-spaces": ["error"],
101+
"no-self-assign": ["error"],
102+
"no-setter-return": ["error"],
103+
"no-shadow-restricted-names": ["error"],
104+
"no-sparse-arrays": ["error"],
105+
"no-this-before-super": ["error"],
106+
"no-undef": ["error"],
107+
"no-unexpected-multiline": ["error"],
108+
"no-unreachable": ["error"],
109+
"no-unsafe-finally": ["error"],
110+
"no-unsafe-negation": ["error"],
111+
"no-unsafe-optional-chaining": ["error"],
112+
"no-unused-labels": ["error"],
113+
"no-unused-vars": [
114+
"error",
115+
{
116+
argsIgnorePattern: "^_",
117+
caughtErrors: "all",
118+
caughtErrorsIgnorePattern: "^_",
119+
},
120+
],
121+
"no-use-before-define": [
122+
"error",
123+
{
124+
functions: false,
125+
classes: true,
126+
variables: true,
127+
allowNamedExports: true,
128+
},
129+
],
130+
"no-useless-backreference": ["error"],
131+
"no-useless-catch": ["error"],
132+
"no-useless-escape": ["error"],
133+
"no-var": ["error"],
134+
"no-with": ["error"],
135+
"prefer-const": [
136+
"error",
137+
{
138+
destructuring: "all",
139+
},
140+
],
141+
"prefer-regex-literals": ["error"],
142+
"prefer-template": ["error"],
143+
"require-yield": ["error"],
144+
"use-isnan": ["error"],
145+
"valid-typeof": ["error"],
146+
},
147+
},
148+
{
149+
files: ["**/*.mjs"],
150+
languageOptions: {
151+
sourceType: "module",
152+
},
153+
},
154+
{
155+
files: ["**/*.json"],
156+
plugins: {
157+
json,
158+
},
159+
processor: json.processors[".json"],
160+
rules: {
161+
...json.configs.recommended.rules,
162+
},
163+
},
164+
{
165+
ignores: ["**/node_modules/**", "**/*.min.js", "**/modernizr.custom.js"],
166+
},
167+
];

0 commit comments

Comments
 (0)