-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.mjs
More file actions
298 lines (280 loc) · 9.4 KB
/
eslint.config.mjs
File metadata and controls
298 lines (280 loc) · 9.4 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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/**
* @file ESLint Configuration for Code Quality and Formatting.
*
* @description Custom configuration for ESLint v9, the JavaScript/TypeScript
* linter. Defines rules and configurations to maintain quality and consistency
* in your project's code, along with style rules and best practices.
* Integrates with Prettier for code formatting and Airbnb style guide as base.
*
* @see {@link https://eslint.org/docs/latest/use/configure | ESLint Configuration File}
* @see {@link https://github.com/airbnb/javascript | Airbnb JavaScript Style Guide}
* @see {@link https://github.com/prettier/eslint-plugin-prettier | ESLint Prettier Plugin}
*
* @module EslintConfiguration
*/
// ━━ IMPORT MODULES ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// » IMPORT NATIVE NODE MODULES
import path from 'path';
import { fileURLToPath } from 'url';
// » IMPORT THIRD PARTIES MODULES
import { FlatCompat } from '@eslint/eslintrc';
import { defineConfig } from 'eslint/config';
import { fixupPluginRules } from '@eslint/compat';
import eslintConfigPrettier from 'eslint-config-prettier/flat';
import eslintPluginPrettier from 'eslint-plugin-prettier';
import eslintPluginJSDOC from 'eslint-plugin-jsdoc';
// ━━ TYPE DEFINITIONS ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
/**
* Array with glob pattern.
*
* @typedef {Array<string>} BlobPatterns
*/
/**
* Type for Eslint configuration.
*
* @typedef {object} EslintConfigurationOption
* @property {string} name - Unique identifier for this configuration.
* @property {string[]} files - File patterns to apply this configuration to.
* @property {string[]} ignores - Patterns to exclude from linting.
* @property {object[]} extends - Base configurations to extend.
* @property {object} plugins - ESLint plugins with their rules.
* @property {object} languageOptions - Language parsing options.
* @property {object} rules - Custom rule configurations.
*/
/**
* Type for Eslint configurations.
*
* @typedef {Array<EslintConfigurationOptions>} EslintConfigurationOptions
*/
// ━━ CONSTANTS ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
/**
* The full filename of the current module (converted from file URL).
*
* @constant {string} __filename
*/
const __filename = fileURLToPath(import.meta.url); // eslint-disable-line no-underscore-dangle
/**
* The directory name containing the current module.
*
* @constant {string} __filename
*/
const __dirname = path.dirname(__filename); // eslint-disable-line no-underscore-dangle
/**
* Compatibility layer for ESLint Flat Config.
* Enables using legacy ESLint config files with the new flat config system.
*
* @constant compat
* @type {FlatCompat}
* @see {@link https://www.npmjs.com/package/@eslint/eslintrc | @eslint/eslintrc}
*/
const compat = new FlatCompat({
baseDirectory: __dirname,
});
/**
* Airbnb base JavaScript style guide configuration.
* Provides a sensible set of default rules for JavaScript projects.
*
* @constant {object} eslintConfigAirbnbBase
* @see {@link https://www.npmjs.com/package/eslint-config-airbnb-base | eslint-config-airbnb-base}
*/
const eslintConfigAirbnbBase = compat.extends('eslint-config-airbnb-base');
// ━━ IGNORE PATTERNS ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
/**
* Glob pattern for ignore dependencies and packages files.
*
* @constant {BlobPatterns} DEPENDENCIES
*/
const DEPENDENCIES = ['node_modules/', 'jspm_packages/', '.pnp', '.pnp.js'];
/**
* Glob pattern for ignore documentation directories.
*
* @constant {BlobPatterns} DOCUMENTATION
*/
const DOCUMENTATION = ['/docs/**', '/jsdoc/**'];
/**
* Glob pattern for ignore Build y production directories.
*
* @constant {BlobPatterns} BUILD_OUTPUT
*/
const BUILD_OUTPUT = ['/build/**', '/dist/**', 'reports/'];
/**
* Glob pattern for ignore Build y production directories.
*
* @constant {BlobPatterns} TESTING
*/
const TESTING = ['/coverage/**', '/tests/bench/**', '/tests/fixtures/**', '/tests/performance/**'];
/**
* Glob pattern for ignore temporary files.
*
* @constant {BlobPatterns} TEMPORARY
*/
const TEMPORARY = ['/tmp/**', '*.tmp', '*.temp'];
/**
* Glob pattern for ignore development and workspace files and directories.
*
* @constant {BlobPatterns} WORKSPACE
*/
const WORKSPACE = [
'/templates/**',
'/notes/**',
'/development/**',
'/develop.js',
'/develop[-_.][0-9][0-9].js',
];
/**
* Glob pattern for ignore files.
*
* @constant {BlobPatterns} SPECIFIC_FILES
*/
const SPECIFIC_FILES = [
'**/serviceWorker.js',
'!.eslintrc', // Excepción: NO ignorar el archivo .eslintrc
];
const IGNORES_FILES = [
...DEPENDENCIES,
...DOCUMENTATION,
...BUILD_OUTPUT,
...TESTING,
...TEMPORARY,
...WORKSPACE,
...SPECIFIC_FILES,
];
// ━━ MODULE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
/**
* The Eslint settings for the project.
*
* @constant eslintConfiguration
* @type {EslintConfigurationOptions}
*/
const eslintConfiguration = defineConfig([
{
name: 'eslint/main',
files: ['**/*.{js,mjs,cjs,ts,mts,jsx,tsx}'],
ignores: IGNORES_FILES,
extends: [eslintConfigAirbnbBase, eslintConfigPrettier],
plugins: {
prettier: fixupPluginRules(eslintPluginPrettier),
jsdoc: fixupPluginRules(eslintPluginJSDOC),
},
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.mjs', '.cjs', '.ts', '.mts', '.jsx', '.tsx'],
paths: ['.'],
},
alias: true,
},
},
rules: {
// » GENERAL RULES
strict: [2, 'global'],
'no-console': ['error', { allow: ['warn', 'error'] }],
'no-param-reassign': ['error', { props: false }],
// » PRETTIER RULES
'prettier/prettier': [
'error',
{
trailingComma: 'all',
printWidth: 100,
tabWidth: 2,
semi: true,
singleQuote: true,
arrowParens: 'avoid',
},
],
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: ['eslint.config.mjs'],
},
],
'import/no-unresolved': [
'error',
{
commonjs: true,
amd: true,
caseSensitive: true,
ignore: ['^#'], // Ignora los imports que comienzan con #
},
],
'import/extensions': [
'error',
'ignorePackages',
{
js: 'always',
mjs: 'always',
cjs: 'always',
ts: 'always',
jsx: 'always',
tsx: 'always',
},
],
// » JSDOC rules
'jsdoc/check-access': 1,
'jsdoc/check-alignment': 1,
'jsdoc/check-examples': [
0,
{
exampleCodeRegex: '```js\n([\\s\\S]*)```',
},
],
'jsdoc/check-indentation': 1,
'jsdoc/check-line-alignment': [
'error',
'always',
{
tags: ['typedef', 'property'],
customSpacings: { postDelimiter: 1 },
},
],
'jsdoc/check-param-names': 1,
'jsdoc/check-property-names': 1,
'jsdoc/check-syntax': 1,
'jsdoc/check-tag-names': [
'error',
{
definedTags: ['hook', 'record'],
},
],
'jsdoc/check-types': 1,
'jsdoc/check-values': 1,
'jsdoc/empty-tags': 1,
'jsdoc/implements-on-classes': 1,
'jsdoc/match-description': 1,
'jsdoc/newline-after-description': 'off',
'jsdoc/no-bad-blocks': 1,
'jsdoc/no-defaults': 1,
'jsdoc/no-types': 0,
'jsdoc/no-undefined-types': 1,
'jsdoc/require-asterisk-prefix': 1,
'jsdoc/require-description': 1,
'jsdoc/require-description-complete-sentence': 1,
'jsdoc/require-example': 1,
'jsdoc/require-file-overview': 1,
'jsdoc/require-hyphen-before-param-description': 1,
'jsdoc/require-jsdoc': 1,
'jsdoc/require-param': 1,
'jsdoc/require-param-description': 1,
'jsdoc/require-param-name': 1,
'jsdoc/require-param-type': 1,
'jsdoc/require-property': 1,
'jsdoc/require-property-description': 1,
'jsdoc/require-property-name': 1,
'jsdoc/require-property-type': 1,
'jsdoc/require-returns': 1,
'jsdoc/require-returns-check': 1,
'jsdoc/require-returns-description': 1,
'jsdoc/require-returns-type': 1,
'jsdoc/require-throws': 1,
'jsdoc/require-yields': 1,
'jsdoc/require-yields-check': 1,
'jsdoc/valid-types': 1,
},
},
]);
// ━━ EXPORT MODULE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
export default eslintConfiguration;