@aryaemami59/eslint-config 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +133 -0
- package/dist/index.cjs +256 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1476 -0
- package/dist/index.d.ts +1476 -0
- package/dist/index.js +216 -0
- package/dist/index.js.map +1 -0
- package/package.json +97 -0
- package/src/index.ts +379 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
import js from '@eslint/js'
|
|
2
|
+
import type { TSESLint } from '@typescript-eslint/utils'
|
|
3
|
+
import type { Linter } from 'eslint'
|
|
4
|
+
import prettierConfig from 'eslint-config-prettier'
|
|
5
|
+
import globalIdentifiers from 'globals'
|
|
6
|
+
import type { ConfigWithExtends } from 'typescript-eslint'
|
|
7
|
+
import { config, configs, parser } from 'typescript-eslint'
|
|
8
|
+
|
|
9
|
+
const { browser, node, nodeBuiltin } = globalIdentifiers
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* An object representing
|
|
13
|
+
* {@link https://eslint.org/docs/latest/use/configure/ignore#ignoring-files | **global ignore patterns**}
|
|
14
|
+
* for ESLint configuration.
|
|
15
|
+
*
|
|
16
|
+
* @since 0.0.3
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
export const globalIgnores = {
|
|
20
|
+
name: '@aryaemami59/global-ignores',
|
|
21
|
+
ignores: [
|
|
22
|
+
'**/dist/',
|
|
23
|
+
'**/.yalc/',
|
|
24
|
+
'**/build/',
|
|
25
|
+
'**/lib/',
|
|
26
|
+
'**/temp/',
|
|
27
|
+
'**/.yarn/',
|
|
28
|
+
'**/coverage/',
|
|
29
|
+
],
|
|
30
|
+
} as const satisfies Linter.Config
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* An object representing the
|
|
34
|
+
* {@link https://vitest.dev/config/#globals | globals} provided by
|
|
35
|
+
* {@link https://vitest.dev | **Vitest**} for use in testing.
|
|
36
|
+
*
|
|
37
|
+
* @since 0.0.3
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
export const vitestGlobals = {
|
|
41
|
+
suite: 'writable',
|
|
42
|
+
test: 'writable',
|
|
43
|
+
describe: 'writable',
|
|
44
|
+
it: 'writable',
|
|
45
|
+
expectTypeOf: 'writable',
|
|
46
|
+
assertType: 'writable',
|
|
47
|
+
expect: 'writable',
|
|
48
|
+
assert: 'writable',
|
|
49
|
+
vitest: 'writable',
|
|
50
|
+
vi: 'writable',
|
|
51
|
+
beforeAll: 'writable',
|
|
52
|
+
afterAll: 'writable',
|
|
53
|
+
beforeEach: 'writable',
|
|
54
|
+
afterEach: 'writable',
|
|
55
|
+
onTestFailed: 'writable',
|
|
56
|
+
onTestFinished: 'writable',
|
|
57
|
+
} as const satisfies Linter.Globals
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* An object that specifies which global
|
|
61
|
+
* variables are available during linting.
|
|
62
|
+
*
|
|
63
|
+
* @since 0.0.3
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
66
|
+
export const globals: typeof vitestGlobals &
|
|
67
|
+
typeof browser &
|
|
68
|
+
typeof node &
|
|
69
|
+
typeof nodeBuiltin = /* @__PURE__ */ Object.assign(
|
|
70
|
+
vitestGlobals,
|
|
71
|
+
browser,
|
|
72
|
+
node,
|
|
73
|
+
nodeBuiltin,
|
|
74
|
+
) satisfies Linter.Globals
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* An object comprised of ESLint rules to disable.
|
|
78
|
+
* These rules are disabled in {@linkcode flatESLintConfig}.
|
|
79
|
+
*
|
|
80
|
+
* @since 0.0.3
|
|
81
|
+
* @public
|
|
82
|
+
*/
|
|
83
|
+
export const rulesToDisable = {
|
|
84
|
+
'no-undef': [0],
|
|
85
|
+
'@typescript-eslint/no-unused-vars': [
|
|
86
|
+
0,
|
|
87
|
+
{
|
|
88
|
+
vars: 'all',
|
|
89
|
+
args: 'after-used',
|
|
90
|
+
caughtErrors: 'all',
|
|
91
|
+
ignoreRestSiblings: false,
|
|
92
|
+
reportUsedIgnorePattern: false,
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
'@typescript-eslint/ban-ts-comment': [
|
|
96
|
+
0,
|
|
97
|
+
[
|
|
98
|
+
{
|
|
99
|
+
'ts-expect-error': 'allow-with-description',
|
|
100
|
+
'ts-ignore': true,
|
|
101
|
+
'ts-nocheck': true,
|
|
102
|
+
'ts-check': false,
|
|
103
|
+
minimumDescriptionLength: 3,
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
],
|
|
107
|
+
} as const satisfies Linter.RulesRecord
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Flat ESLint configuration tailored for projects using TypeScript.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* <caption>#### __ECMAScript Modules (ESM) usage inside a file like `eslint.config.mts` or `eslint.config.mjs`__</caption>
|
|
114
|
+
*
|
|
115
|
+
* ```ts
|
|
116
|
+
* import { flatESLintConfig } from '@aryaemami59/eslint-config'
|
|
117
|
+
*
|
|
118
|
+
* export default flatESLintConfig
|
|
119
|
+
* ```
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* <caption>#### __CommonJS (CJS) usage inside a file like `eslint.config.cts` or `eslint.config.cjs` (using `require`)__</caption>
|
|
123
|
+
*
|
|
124
|
+
* ```ts
|
|
125
|
+
* const { flatESLintConfig } = require('@aryaemami59/eslint-config')
|
|
126
|
+
*
|
|
127
|
+
* module.exports = flatESLintConfig
|
|
128
|
+
* ```
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* <caption>#### __CommonJS (CJS) usage inside a file like `eslint.config.cjs` or `eslint.config.cts` (using dynamic import)__</caption>
|
|
132
|
+
*
|
|
133
|
+
* ```ts
|
|
134
|
+
* module.exports = (async () =>
|
|
135
|
+
* (await import('@aryaemami59/eslint-config')).flatESLintConfig)()
|
|
136
|
+
* ```
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* <caption>#### __CommonJS (CJS) usage inside a file like `eslint.config.cts` (using import and export assignment)__</caption>
|
|
140
|
+
*
|
|
141
|
+
* ```ts
|
|
142
|
+
* import eslintConfigModule = require('@aryaemami59/eslint-config')
|
|
143
|
+
* import flatESLintConfig = eslintConfigModule.flatESLintConfig
|
|
144
|
+
*
|
|
145
|
+
* export = flatESLintConfig
|
|
146
|
+
* ```
|
|
147
|
+
*
|
|
148
|
+
* @since 0.0.3
|
|
149
|
+
* @public
|
|
150
|
+
*/
|
|
151
|
+
export const flatESLintConfig: TSESLint.FlatConfig.Config[] =
|
|
152
|
+
/* @__PURE__ */ config(
|
|
153
|
+
// `ignores` must be first.
|
|
154
|
+
// config with just `ignores` is the replacement for `.eslintignore`
|
|
155
|
+
globalIgnores,
|
|
156
|
+
{ name: '@aryaemami59/javascript', ...js.configs.recommended },
|
|
157
|
+
...configs.recommended,
|
|
158
|
+
...configs.stylistic,
|
|
159
|
+
{ name: '@aryaemami59/prettier-config', ...prettierConfig },
|
|
160
|
+
{
|
|
161
|
+
name: '@aryaemami59/main',
|
|
162
|
+
languageOptions: {
|
|
163
|
+
globals,
|
|
164
|
+
parser,
|
|
165
|
+
parserOptions: {
|
|
166
|
+
projectService: {
|
|
167
|
+
allowDefaultProject: ['.*.js', '.*.mjs', '.*.cjs'],
|
|
168
|
+
defaultProject: './tsconfig.json',
|
|
169
|
+
},
|
|
170
|
+
ecmaVersion: 'latest',
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
rules: {
|
|
174
|
+
'@typescript-eslint/consistent-type-imports': [
|
|
175
|
+
2,
|
|
176
|
+
{
|
|
177
|
+
prefer: 'type-imports',
|
|
178
|
+
fixStyle: 'separate-type-imports',
|
|
179
|
+
disallowTypeAnnotations: true,
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
'@typescript-eslint/consistent-type-exports': [
|
|
183
|
+
2,
|
|
184
|
+
{ fixMixedExportsWithInlineTypeSpecifier: false },
|
|
185
|
+
],
|
|
186
|
+
'@typescript-eslint/no-explicit-any': [
|
|
187
|
+
2,
|
|
188
|
+
{ fixToUnknown: false, ignoreRestArgs: false },
|
|
189
|
+
],
|
|
190
|
+
'@typescript-eslint/no-empty-object-type': [
|
|
191
|
+
2,
|
|
192
|
+
{ allowInterfaces: 'never', allowObjectTypes: 'never' },
|
|
193
|
+
],
|
|
194
|
+
'@typescript-eslint/no-restricted-types': [
|
|
195
|
+
2,
|
|
196
|
+
{
|
|
197
|
+
types: {
|
|
198
|
+
'{}': {
|
|
199
|
+
message: `
|
|
200
|
+
- If you want to represent an empty object, use \`type EmptyObject = Record<string, never>\`.
|
|
201
|
+
- If you want to represent an object literal, use either \`type AnyObject = Record<string, any>\` or \`object\`.
|
|
202
|
+
- If you want to represent any non-nullish value, use \`type AnyNonNullishValue = NonNullable<unknown>\`.`,
|
|
203
|
+
suggest: [
|
|
204
|
+
'AnyNonNullishValue',
|
|
205
|
+
'EmptyObject',
|
|
206
|
+
'AnyObject',
|
|
207
|
+
'object',
|
|
208
|
+
'Record<string, never>',
|
|
209
|
+
'Record<string, any>',
|
|
210
|
+
'NonNullable<unknown>',
|
|
211
|
+
],
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
],
|
|
216
|
+
'@typescript-eslint/no-namespace': [
|
|
217
|
+
2,
|
|
218
|
+
{ allowDeclarations: false, allowDefinitionFiles: true },
|
|
219
|
+
],
|
|
220
|
+
'@typescript-eslint/consistent-type-definitions': [2, 'type'],
|
|
221
|
+
'sort-imports': [
|
|
222
|
+
2,
|
|
223
|
+
{
|
|
224
|
+
ignoreCase: false,
|
|
225
|
+
ignoreDeclarationSort: true,
|
|
226
|
+
ignoreMemberSort: false,
|
|
227
|
+
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
|
|
228
|
+
allowSeparatedGroups: true,
|
|
229
|
+
},
|
|
230
|
+
],
|
|
231
|
+
'@typescript-eslint/unified-signatures': [2],
|
|
232
|
+
'@typescript-eslint/dot-notation': [
|
|
233
|
+
2,
|
|
234
|
+
{
|
|
235
|
+
// Related issue: https://github.com/typescript-eslint/typescript-eslint/issues/10338
|
|
236
|
+
// Base ESLint default options
|
|
237
|
+
allowKeywords: true,
|
|
238
|
+
allowPattern: '',
|
|
239
|
+
// TypeScript ESLint default options
|
|
240
|
+
allowPrivateClassPropertyAccess: false,
|
|
241
|
+
allowProtectedClassPropertyAccess: false,
|
|
242
|
+
allowIndexSignaturePropertyAccess: false,
|
|
243
|
+
},
|
|
244
|
+
],
|
|
245
|
+
'@typescript-eslint/no-unnecessary-type-parameters': [2],
|
|
246
|
+
'@typescript-eslint/no-invalid-void-type': [2],
|
|
247
|
+
'@typescript-eslint/no-confusing-void-expression': [2],
|
|
248
|
+
'@typescript-eslint/no-duplicate-type-constituents': [2],
|
|
249
|
+
'@typescript-eslint/require-await': [2],
|
|
250
|
+
'@typescript-eslint/no-redundant-type-constituents': [2],
|
|
251
|
+
'@typescript-eslint/no-unnecessary-type-arguments': [2],
|
|
252
|
+
'@typescript-eslint/no-unnecessary-type-assertion': [2],
|
|
253
|
+
'@typescript-eslint/prefer-nullish-coalescing': [2],
|
|
254
|
+
'@typescript-eslint/no-inferrable-types': [2],
|
|
255
|
+
'@typescript-eslint/no-empty-function': [
|
|
256
|
+
2,
|
|
257
|
+
{
|
|
258
|
+
// Related issue: https://github.com/typescript-eslint/typescript-eslint/issues/10338
|
|
259
|
+
// Base ESLint default options
|
|
260
|
+
allow: [],
|
|
261
|
+
},
|
|
262
|
+
],
|
|
263
|
+
'@typescript-eslint/no-unused-expressions': [
|
|
264
|
+
2,
|
|
265
|
+
{
|
|
266
|
+
// Related issue: https://github.com/typescript-eslint/typescript-eslint/issues/10338
|
|
267
|
+
// Base ESLint default options
|
|
268
|
+
allowShortCircuit: false,
|
|
269
|
+
allowTernary: false,
|
|
270
|
+
allowTaggedTemplates: false,
|
|
271
|
+
enforceForJSX: false,
|
|
272
|
+
},
|
|
273
|
+
],
|
|
274
|
+
'object-shorthand': [2],
|
|
275
|
+
...rulesToDisable,
|
|
276
|
+
},
|
|
277
|
+
linterOptions: { reportUnusedDisableDirectives: 2 },
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
name: '@aryaemami59/commonjs',
|
|
281
|
+
files: ['**/*.c[jt]s'],
|
|
282
|
+
languageOptions: { sourceType: 'commonjs' },
|
|
283
|
+
rules: {
|
|
284
|
+
'@typescript-eslint/no-require-imports': [
|
|
285
|
+
0,
|
|
286
|
+
[{ allow: [], allowAsImport: false }],
|
|
287
|
+
],
|
|
288
|
+
},
|
|
289
|
+
},
|
|
290
|
+
)
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* A function that returns {@linkcode flatESLintConfig}
|
|
294
|
+
* along with optional additional overrides.
|
|
295
|
+
* It's made mainly to provide intellisense and eliminate
|
|
296
|
+
* the need for manual type annotations using JSDoc comments.
|
|
297
|
+
*
|
|
298
|
+
* @param additionalOverrides - **Optional** additional overrides to apply to the configuration.
|
|
299
|
+
* @returns An augmented version of the default {@linkcode flatESLintConfig}, incorporating any provided overrides.
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* <caption>#### __ECMAScript Modules (ESM) usage inside a file like `eslint.config.mts` or `eslint.config.mjs`__</caption>
|
|
303
|
+
*
|
|
304
|
+
* ```ts
|
|
305
|
+
* import { createESLintConfig } from '@aryaemami59/eslint-config'
|
|
306
|
+
*
|
|
307
|
+
* export default createESLintConfig([
|
|
308
|
+
* {
|
|
309
|
+
* rules: {
|
|
310
|
+
* 'no-console': [0],
|
|
311
|
+
* },
|
|
312
|
+
* },
|
|
313
|
+
* {
|
|
314
|
+
* // ...Other additional overrides
|
|
315
|
+
* },
|
|
316
|
+
* ])
|
|
317
|
+
* ```
|
|
318
|
+
*
|
|
319
|
+
* @example
|
|
320
|
+
* <caption>#### __CommonJS (CJS) usage inside a file like `eslint.config.cts` or `eslint.config.cjs` (using `require`)__</caption>
|
|
321
|
+
*
|
|
322
|
+
* ```ts
|
|
323
|
+
* const { createESLintConfig } = require('@aryaemami59/eslint-config')
|
|
324
|
+
*
|
|
325
|
+
* module.exports = createESLintConfig([
|
|
326
|
+
* {
|
|
327
|
+
* rules: {
|
|
328
|
+
* 'no-console': [0],
|
|
329
|
+
* },
|
|
330
|
+
* },
|
|
331
|
+
* {
|
|
332
|
+
* // ...Other additional overrides
|
|
333
|
+
* },
|
|
334
|
+
* ])
|
|
335
|
+
* ```
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
* <caption>#### __CommonJS (CJS) usage inside a file like `eslint.config.cts` or `eslint.config.cjs` (using dynamic import)__</caption>
|
|
339
|
+
*
|
|
340
|
+
* ```ts
|
|
341
|
+
* module.exports = (async () =>
|
|
342
|
+
* (await import('@aryaemami59/eslint-config')).createESLintConfig([
|
|
343
|
+
* {
|
|
344
|
+
* rules: {
|
|
345
|
+
* 'no-console': [0],
|
|
346
|
+
* },
|
|
347
|
+
* },
|
|
348
|
+
* {
|
|
349
|
+
* // ...Other additional overrides
|
|
350
|
+
* },
|
|
351
|
+
* ]))()
|
|
352
|
+
* ```
|
|
353
|
+
*
|
|
354
|
+
* @example
|
|
355
|
+
* <caption>#### __CommonJS (CJS) usage inside a file like `eslint.config.cts` (using import and export assignment)__</caption>
|
|
356
|
+
*
|
|
357
|
+
* ```ts
|
|
358
|
+
* import eslintConfigModule = require('@aryaemami59/eslint-config')
|
|
359
|
+
* import createESLintConfig = eslintConfigModule.createESLintConfig
|
|
360
|
+
*
|
|
361
|
+
* export = createESLintConfig([
|
|
362
|
+
* {
|
|
363
|
+
* rules: {
|
|
364
|
+
* 'no-console': [0],
|
|
365
|
+
* },
|
|
366
|
+
* },
|
|
367
|
+
* {
|
|
368
|
+
* // ...Other additional overrides
|
|
369
|
+
* },
|
|
370
|
+
* ])
|
|
371
|
+
* ```
|
|
372
|
+
*
|
|
373
|
+
* @since 0.0.3
|
|
374
|
+
* @public
|
|
375
|
+
*/
|
|
376
|
+
export const createESLintConfig = (
|
|
377
|
+
additionalOverrides: ConfigWithExtends[] = [],
|
|
378
|
+
): TSESLint.FlatConfig.Config[] =>
|
|
379
|
+
/* @__PURE__ */ config(...flatESLintConfig, ...additionalOverrides)
|