@aryaemami59/eslint-config 0.0.4 → 0.0.6

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.
@@ -0,0 +1,251 @@
1
+ import type { Linter } from 'eslint'
2
+ import { disabledRules } from './disabledRules.js'
3
+ import type { FlatConfig } from './external.js'
4
+ import { js, prettierConfig } from './external.js'
5
+ import { globalIgnores } from './globalIgnores.js'
6
+ import { globals } from './globals.js'
7
+ import { packageJsonName } from './packageJsonName.js'
8
+
9
+ /**
10
+ * Flat ESLint configuration tailored for projects using TypeScript.
11
+ *
12
+ * @example
13
+ * <caption>#### __ECMAScript Modules (ESM) usage inside a file like `eslint.config.mts` or `eslint.config.mjs`__</caption>
14
+ *
15
+ * ```ts
16
+ * import { flatESLintConfig } from '@aryaemami59/eslint-config'
17
+ *
18
+ * export default flatESLintConfig
19
+ * ```
20
+ *
21
+ * @example
22
+ * <caption>#### __CommonJS (CJS) usage inside a file like `eslint.config.cts` or `eslint.config.cjs` (using `require`)__</caption>
23
+ *
24
+ * ```ts
25
+ * const { flatESLintConfig } = require('@aryaemami59/eslint-config')
26
+ *
27
+ * module.exports = flatESLintConfig
28
+ * ```
29
+ *
30
+ * @example
31
+ * <caption>#### __CommonJS (CJS) usage inside a file like `eslint.config.cjs` or `eslint.config.cts` (using dynamic import)__</caption>
32
+ *
33
+ * ```ts
34
+ * module.exports = (async () =>
35
+ * (await import('@aryaemami59/eslint-config')).flatESLintConfig)()
36
+ * ```
37
+ *
38
+ * @example
39
+ * <caption>#### __CommonJS (CJS) usage inside a file like `eslint.config.cts` (using import and export assignment)__</caption>
40
+ *
41
+ * ```ts
42
+ * import eslintConfigModule = require('@aryaemami59/eslint-config')
43
+ * import flatESLintConfig = eslintConfigModule.flatESLintConfig
44
+ *
45
+ * export = flatESLintConfig
46
+ * ```
47
+ *
48
+ * @since 0.0.3
49
+ * @public
50
+ */
51
+ export const flatESLintConfig = [
52
+ // `ignores` must be first.
53
+ // config with just `ignores` is the replacement for `.eslintignore`
54
+ globalIgnores,
55
+
56
+ {
57
+ name: `${js.meta.name}/recommended`,
58
+ ...js.configs.recommended,
59
+ } as const satisfies FlatConfig.Config satisfies Linter.Config,
60
+
61
+ // TODO: You can remove the type assertion in the next major version of `typescript-eslint`.
62
+ // TODO: Uncomment this once https://github.com/typescript-eslint/typescript-eslint/issues/11952 is resolved.
63
+ // ...(configs.recommended satisfies Linter.Config[] as Linter.Config<any>[]),
64
+ // TODO: You can remove the type assertion in the next major version of `typescript-eslint`.
65
+ // TODO: Uncomment this once https://github.com/typescript-eslint/typescript-eslint/issues/11952 is resolved.
66
+ // ...(configs.stylistic satisfies Linter.Config[] as Linter.Config<any>[]),
67
+
68
+ {
69
+ languageOptions: {
70
+ globals,
71
+ parserOptions: {
72
+ ecmaVersion: 'latest',
73
+ projectService: true,
74
+ } as const satisfies FlatConfig.ParserOptions satisfies Linter.ParserOptions,
75
+ },
76
+ linterOptions: {
77
+ reportUnusedDisableDirectives: 2,
78
+ reportUnusedInlineConfigs: 2,
79
+ },
80
+ name: `${packageJsonName}/defaults/overrides`,
81
+
82
+ rules: {
83
+ // TODO: Uncomment this once https://github.com/typescript-eslint/typescript-eslint/issues/11952 is resolved.
84
+ // '@typescript-eslint/consistent-type-definitions': [2, 'type'],
85
+ // '@typescript-eslint/consistent-type-exports': [
86
+ // 2,
87
+ // { fixMixedExportsWithInlineTypeSpecifier: false },
88
+ // ],
89
+ // '@typescript-eslint/consistent-type-imports': [
90
+ // 2,
91
+ // {
92
+ // disallowTypeAnnotations: true,
93
+ // fixStyle: 'separate-type-imports',
94
+ // prefer: 'type-imports',
95
+ // },
96
+ // ],
97
+ // '@typescript-eslint/no-confusing-void-expression': [
98
+ // 2,
99
+ // {
100
+ // ignoreArrowShorthand: false,
101
+ // ignoreVoidOperator: false,
102
+ // ignoreVoidReturningFunctions: false,
103
+ // },
104
+ // ],
105
+ // '@typescript-eslint/no-duplicate-type-constituents': [
106
+ // 2,
107
+ // {
108
+ // ignoreIntersections: false,
109
+ // ignoreUnions: false,
110
+ // },
111
+ // ],
112
+ // '@typescript-eslint/no-empty-object-type': [
113
+ // 2,
114
+ // {
115
+ // allowInterfaces: 'never',
116
+ // allowObjectTypes: 'never',
117
+ // },
118
+ // ],
119
+ // '@typescript-eslint/no-explicit-any': [
120
+ // 2,
121
+ // {
122
+ // fixToUnknown: false,
123
+ // ignoreRestArgs: false,
124
+ // },
125
+ // ],
126
+ // '@typescript-eslint/no-inferrable-types': [
127
+ // 2,
128
+ // {
129
+ // ignoreParameters: false,
130
+ // ignoreProperties: false,
131
+ // },
132
+ // ],
133
+ // '@typescript-eslint/no-invalid-void-type': [
134
+ // 2,
135
+ // {
136
+ // allowAsThisParameter: false,
137
+ // allowInGenericTypeArguments: true,
138
+ // },
139
+ // ],
140
+ // '@typescript-eslint/no-namespace': [
141
+ // 2,
142
+ // {
143
+ // allowDeclarations: false,
144
+ // allowDefinitionFiles: true,
145
+ // },
146
+ // ],
147
+ // '@typescript-eslint/no-redundant-type-constituents': [2],
148
+ // '@typescript-eslint/no-require-imports': [
149
+ // 2,
150
+ // {
151
+ // allow: [],
152
+ // allowAsImport: true,
153
+ // },
154
+ // ],
155
+ // '@typescript-eslint/no-restricted-types': [
156
+ // 2,
157
+ // {
158
+ // types: {
159
+ // '{}': {
160
+ // message: `
161
+ // - If you want to represent an empty object, use \`type EmptyObject = Record<string, never>\`.
162
+ // - If you want to represent an object literal, use either \`type AnyObject = Record<string, any>\` or \`object\`.
163
+ // - If you want to represent any non-nullish value, use \`type AnyNonNullishValue = NonNullable<unknown>\`.`,
164
+ // suggest: [
165
+ // 'AnyNonNullishValue',
166
+ // 'EmptyObject',
167
+ // 'AnyObject',
168
+ // 'object',
169
+ // 'Record<string, never>',
170
+ // 'Record<string, any>',
171
+ // 'NonNullable<unknown>',
172
+ // ],
173
+ // },
174
+ // },
175
+ // },
176
+ // ],
177
+ // '@typescript-eslint/no-unnecessary-type-arguments': [2],
178
+ // '@typescript-eslint/no-unnecessary-type-assertion': [
179
+ // 2,
180
+ // { typesToIgnore: [] },
181
+ // ],
182
+ // '@typescript-eslint/no-unnecessary-type-parameters': [2],
183
+ // '@typescript-eslint/prefer-nullish-coalescing': [
184
+ // 2,
185
+ // {
186
+ // allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing: false,
187
+ // ignoreBooleanCoercion: false,
188
+ // ignoreConditionalTests: true,
189
+ // ignoreIfStatements: false,
190
+ // ignoreMixedLogicalExpressions: false,
191
+ // ignorePrimitives: {
192
+ // bigint: false,
193
+ // boolean: false,
194
+ // number: false,
195
+ // string: false,
196
+ // },
197
+ // ignoreTernaryTests: false,
198
+ // },
199
+ // ],
200
+ // '@typescript-eslint/require-await': [2],
201
+ // '@typescript-eslint/unified-signatures': [
202
+ // 2,
203
+ // {
204
+ // ignoreDifferentlyNamedParameters: false,
205
+ // ignoreOverloadsWithDifferentJSDoc: false,
206
+ // },
207
+ // ],
208
+ 'object-shorthand': [
209
+ 2,
210
+ 'always',
211
+ {
212
+ avoidExplicitReturnArrows: true,
213
+ avoidQuotes: true,
214
+ ignoreConstructors: true,
215
+ methodsIgnorePattern: '',
216
+ },
217
+ ],
218
+ 'sort-imports': [
219
+ 2,
220
+ {
221
+ allowSeparatedGroups: true,
222
+ ignoreCase: false,
223
+ ignoreDeclarationSort: true,
224
+ ignoreMemberSort: false,
225
+ memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
226
+ },
227
+ ],
228
+
229
+ ...disabledRules,
230
+ },
231
+ } as const satisfies Linter.Config,
232
+
233
+ {
234
+ files: ['**/*.cjs'],
235
+ languageOptions: {
236
+ sourceType: 'commonjs',
237
+ } as const satisfies FlatConfig.LanguageOptions satisfies Linter.LanguageOptions,
238
+ name: `${packageJsonName}/commonjs-files`,
239
+ rules: {
240
+ '@typescript-eslint/no-require-imports': [
241
+ 0,
242
+ {
243
+ allow: [],
244
+ allowAsImport: false,
245
+ },
246
+ ],
247
+ },
248
+ } as const satisfies Linter.Config,
249
+
250
+ prettierConfig,
251
+ ] as const satisfies Linter.Config[]
package/src/utils.ts ADDED
@@ -0,0 +1,92 @@
1
+ import type { Linter } from 'eslint'
2
+ import { defineConfig } from 'eslint/config'
3
+ import { flatESLintConfig } from './shareableConfigs.js'
4
+
5
+ /**
6
+ * A function that returns {@linkcode flatESLintConfig}
7
+ * along with optional additional overrides.
8
+ * It's made mainly to provide intellisense and eliminate
9
+ * the need for manual type annotations using JSDoc comments.
10
+ *
11
+ * @param [additionalOverrides=[]] - **Optional** additional overrides to apply to the configuration.
12
+ * @returns An augmented version of the default {@linkcode flatESLintConfig}, incorporating any provided overrides.
13
+ *
14
+ * @example
15
+ * <caption>#### __ECMAScript Modules (ESM) usage inside a file like `eslint.config.mts` or `eslint.config.mjs`__</caption>
16
+ *
17
+ * ```ts
18
+ * import { createESLintConfig } from '@aryaemami59/eslint-config'
19
+ *
20
+ * export default createESLintConfig([
21
+ * {
22
+ * rules: {
23
+ * 'no-console': [0],
24
+ * },
25
+ * },
26
+ * {
27
+ * // ...Other additional overrides
28
+ * },
29
+ * ])
30
+ * ```
31
+ *
32
+ * @example
33
+ * <caption>#### __CommonJS (CJS) usage inside a file like `eslint.config.cts` or `eslint.config.cjs` (using `require`)__</caption>
34
+ *
35
+ * ```ts
36
+ * const { createESLintConfig } = require('@aryaemami59/eslint-config')
37
+ *
38
+ * module.exports = createESLintConfig([
39
+ * {
40
+ * rules: {
41
+ * 'no-console': [0],
42
+ * },
43
+ * },
44
+ * {
45
+ * // ...Other additional overrides
46
+ * },
47
+ * ])
48
+ * ```
49
+ *
50
+ * @example
51
+ * <caption>#### __CommonJS (CJS) usage inside a file like `eslint.config.cts` or `eslint.config.cjs` (using dynamic import)__</caption>
52
+ *
53
+ * ```ts
54
+ * module.exports = (async () =>
55
+ * (await import('@aryaemami59/eslint-config')).createESLintConfig([
56
+ * {
57
+ * rules: {
58
+ * 'no-console': [0],
59
+ * },
60
+ * },
61
+ * {
62
+ * // ...Other additional overrides
63
+ * },
64
+ * ]))()
65
+ * ```
66
+ *
67
+ * @example
68
+ * <caption>#### __CommonJS (CJS) usage inside a file like `eslint.config.cts` (using import and export assignment)__</caption>
69
+ *
70
+ * ```ts
71
+ * import eslintConfigModule = require('@aryaemami59/eslint-config')
72
+ * import createESLintConfig = eslintConfigModule.createESLintConfig
73
+ *
74
+ * export = createESLintConfig([
75
+ * {
76
+ * rules: {
77
+ * 'no-console': [0],
78
+ * },
79
+ * },
80
+ * {
81
+ * // ...Other additional overrides
82
+ * },
83
+ * ])
84
+ * ```
85
+ *
86
+ * @since 0.0.3
87
+ * @public
88
+ */
89
+ export const createESLintConfig = (
90
+ additionalOverrides: Parameters<typeof defineConfig> = [],
91
+ ): Linter.Config[] =>
92
+ /* @__PURE__ */ defineConfig(...flatESLintConfig, ...additionalOverrides)