-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patheslint.config.js
More file actions
221 lines (171 loc) · 5.64 KB
/
eslint.config.js
File metadata and controls
221 lines (171 loc) · 5.64 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
import { FlatCompat } from '@eslint/eslintrc';
import js from '@eslint/js';
import tsParser from '@typescript-eslint/parser';
import globals from 'globals';
import jsonc from 'jsonc-parser';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Initialize FlatCompat to support older ESLint config compatibility
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
});
// Load and parse Prettier configuration from file
const prettierrc = jsonc.parse(fs.readFileSync(path.resolve(__dirname, '.prettierrc.json'), 'utf-8'));
export default [
{
// File paths and patterns to be completely ignored by ESLint
ignores: [
// Markdown files
'**/*.md',
// HTML templates or static HTML content
'**/*.html',
// Python files
'**/*.py',
// Plain text files
'**/*.txt',
// Temporary working directories
'**/tmp/**',
// Application-specific non-source directories
'**/app/**',
// Build output directories
'**/dist/**',
// Dependency directories
'**/node_modules/**',
// Code coverage reports
'**/coverage/**',
// Log storage directories
'**/logs/**',
// Third-party vendor scripts
'**/vendor/**',
// Minified files (e.g., *.min.js, *.min.css)
'**/min.*',
// Lock files for dependency managers
'**/*.lock',
// Public static assets
'**/public/**',
// Yarn internal folder
'**/.yarn/**',
'userscripts/**'
]
},
// Apply recommended rule sets from ESLint, TypeScript, and Prettier
...compat.extends(
// ESLint core recommended rules
'eslint:recommended',
// TypeScript-enhanced ESLint recommended rules
'plugin:@typescript-eslint/eslint-recommended',
// Additional TypeScript best-practice rules
'plugin:@typescript-eslint/recommended',
// Prettier formatting + conflict resolution
'plugin:prettier/recommended'
),
{
linterOptions: {
// Notify when ESLint disable comments are unnecessary
reportUnusedDisableDirectives: true
},
languageOptions: {
// Inject various global variables for browser, Node, AMD, Jest, etc.
globals: {
...globals.browser,
...globals.amd,
...globals.node,
...globals.jest,
// Google reCAPTCHA
grecaptcha: 'readonly',
// jQuery globals
$: 'readonly',
jQuery: 'readonly',
// Google Ads global
adsbygoogle: 'writable',
// Hexo static site generator global
hexo: 'readonly'
},
// TypeScript parser for ESLint
parser: tsParser,
// Enable ECMAScript 2020 syntax
ecmaVersion: 2020,
// Allow usage of ES modules
sourceType: 'module'
},
rules: {
// Enforce Prettier formatting rules with custom overrides
'prettier/prettier': [
'error',
Object.assign(prettierrc, {
overrides: [
{
// Exclude minified files from formatting
excludeFiles: ['*.min.js', '*.min.cjs', '*.min.css', '*.min.html', '*.min.scss'],
// File types to apply Prettier formatting
files: ['*.js', '*.css', '*.sass', '*.html', '*.md', '*.ts'],
// Always require semicolons
options: { semi: true }
},
{
// Use HTML parser for templating languages
files: ['*.ejs', '*.njk', '*.html'],
options: { parser: 'html' }
}
]
})
],
// Disable requirement for explicit return type on functions
'@typescript-eslint/explicit-function-return-type': 'off',
// Disable the base JS unused-vars rule (use TS version instead)
'no-unused-vars': 'off',
// Allow intentionally unused variables and parameters if they start with "_"
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_'
}
],
// Allow the use of the `any` type
'@typescript-eslint/no-explicit-any': 'off',
// Configure restrictions and allowed names for aliasing `this`
'@typescript-eslint/no-this-alias': [
'error',
{
// Disallow destructuring when aliasing `this`
allowDestructuring: false,
// Permit specific safe aliases
allowedNames: ['self', 'hexo']
}
],
// Turn off stylistic enforcement on arrow function bodies
'arrow-body-style': 'off',
// Disable enforcement of arrow callbacks
'prefer-arrow-callback': 'off',
// Allow empty catch blocks (useful for intentional no-op error handling)
'no-empty': ['error', { allowEmptyCatch: true }]
}
},
{
// Overrides for plain JavaScript and CommonJS environments
files: ['**/*.js', '**/*.cjs'],
rules: {
// Allow use of require() in CommonJS files
'@typescript-eslint/no-var-requires': 'off',
// Allow require-style imports
'@typescript-eslint/no-require-imports': 'off',
// Disable restrictions on triple-slash directive references
'@typescript-eslint/triple-slash-reference': 'off'
}
},
{
// Overrides for ECMAScript module files
files: ['**/*.mjs'],
rules: {
// Disable triple-slash reference restrictions for .mjs files
'@typescript-eslint/triple-slash-reference': 'off'
}
}
];