-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.js
More file actions
141 lines (129 loc) · 4.91 KB
/
Copy patheslint.config.js
File metadata and controls
141 lines (129 loc) · 4.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// eslint.config.js
import { defineConfig } from 'eslint/config';
import js from '@eslint/js';
import globals from 'globals';
import eslintPluginPrettier from 'eslint-plugin-prettier';
import eslintConfigPrettier from 'eslint-config-prettier/flat';
export default defineConfig([
js.configs.recommended,
{
files: ['**/*.{js,mjs,cjs}'],
ignores: ['node_modules/**', 'dist/**', 'build/**'],
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
globals: globals.browser
},
plugins: {
prettier: eslintPluginPrettier
},
rules: {
/*
* Format & basic style
*/
semi: ['error', 'always'], // require semicolons
// eslint-disable-next-line no-magic-numbers
indent: ['error', 4, { SwitchCase: 1 }], // 4 spaces
quotes: ['error', 'single', { avoidEscape: true }], // prefer single quotes
'comma-dangle': ['error', 'never'], // no trailing commas
'no-trailing-spaces': 'error', // no trailing spaces
'eol-last': ['error', 'always'], // newline at EOF
/*
* Variables & scope
*/
'no-var': 'error', // disallow var
'prefer-const': ['error', { destructuring: 'all' }], // prefer const
'no-global-assign': 'error', // prevent assignment to globals
'no-implicit-globals': 'error', // prevent implicit globals (browser)
'no-unused-vars': [
'warn',
{ vars: 'all', args: 'after-used', ignoreRestSiblings: true, caughtErrors: 'none' }
], // warn unused vars
/*
* Equality & coercion
*/
eqeqeq: ['error', 'always'], // enforce strict equality (===)
'no-implicit-coercion': ['error', { allow: ['!!'] }], // avoid implicit coercion
/*
* Functions, purity & side-effects
*/
'consistent-return': 'error', // functions should consistently return
'no-else-return': 'error', // avoid else after return
'no-nested-ternary': 'error', // avoid nested ternary
/*
* Complexity & file size
*/
complexity: ['warn', { max: 15 }],
'max-lines': ['warn', { max: 1000, skipBlankLines: true, skipComments: true }],
/*
* DOM & browser specific
*/
'no-eval': 'error', // ban eval
'no-alert': 'warn', // warn on alert/confirm/prompt
// Block direct use of document.write, mapped via no-restricted-properties:
'no-restricted-properties': [
'error',
{
object: 'document',
property: 'write',
message: 'Avoid using document.write(); use DOM APIs or element.append instead.'
}
],
/*
* Imports & modules
*/
'no-duplicate-imports': 'error', // disallow duplicate imports
// Encourage ES Modules (use `sourceType: module`)
/*
* Magic numbers, logging, todos
*/
'no-magic-numbers': [
'warn',
{
ignore: [-1, 0, 1, 2, 45, 90, 180, 360],
ignoreArrayIndexes: true,
ignoreDefaultValues: true,
ignoreClassFieldInitialValues: true,
detectObjects: false
}
],
'no-console': ['warn', { allow: ['warn', 'error', 'info'] }], // only warn/error allowed
// Track TO-DO / FIX ME using core rule:
'no-warning-comments': ['warn', { terms: ['todo', 'fixme'], location: 'anywhere' }],
/*
* Stylistic preferences (Prettier will override formatting rules)
*/
'object-curly-spacing': ['error', 'always'],
'array-bracket-spacing': ['error', 'never'],
'space-before-function-paren': ['error', 'never'],
/*
* Reporting Prettier formatting problems through ESLint
*/
'prettier/prettier': 'error'
}
},
/*
* Test files overrides (less strict in tests)
*/
{
files: ['**/*.test.js', '**/*.spec.js'],
languageOptions: {
globals: {
describe: 'readonly',
it: 'readonly',
expect: 'readonly',
beforeEach: 'readonly',
afterEach: 'readonly'
}
},
rules: {
'no-magic-numbers': 'off',
'no-console': 'off',
'no-warning-comments': 'off'
}
},
/*
* Prettier integration: disable conflicting ESLint rules and apply Prettier config last
*/
eslintConfigPrettier
]);