eslint-config-complete 1.0.0

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,298 @@
1
+ import ESLintPluginImportX from "eslint-plugin-import-x";
2
+ import tseslint from "typescript-eslint";
3
+
4
+ /** @type {Record<string, import("@typescript-eslint/utils").TSESLint.SharedConfig.RuleEntry>} */
5
+ const HELPFUL_WARNINGS = {
6
+ "import-x/export": "warn",
7
+
8
+ /**
9
+ * Superseded by the `deprecation/deprecation` rule. (That rule is better because it catches
10
+ * deprecated usage that does not come from import statements specifically.)
11
+ */
12
+ "import-x/no-deprecated": "off",
13
+
14
+ "import-x/no-empty-named-blocks": "warn",
15
+
16
+ /**
17
+ * The options are [copied from
18
+ * Airbnb](https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb-base/rules/import.js).
19
+ *
20
+ * We also add a "scripts" directory entry for "devDependencies".
21
+ */
22
+ "import-x/no-extraneous-dependencies": [
23
+ "warn",
24
+ {
25
+ devDependencies: [
26
+ "test/**", // tape, common npm pattern
27
+ "tests/**", // also common npm pattern
28
+ "spec/**", // mocha, rspec-like pattern
29
+ "**/__tests__/**", // jest pattern
30
+ "**/__mocks__/**", // jest pattern
31
+ "test.{js,jsx}", // repos with a single test file
32
+ "test-*.{js,jsx}", // repos with multiple top-level test files
33
+ "**/*{.,_}{test,spec}.{js,jsx}", // tests where the extension or filename suffix denotes that it is a test
34
+ "**/jest.config.js", // jest config
35
+ "**/jest.setup.js", // jest setup
36
+ "**/vue.config.js", // vue-cli config
37
+ "**/webpack.config.js", // webpack config
38
+ "**/webpack.config.*.js", // webpack config
39
+ "**/rollup.config.js", // rollup config
40
+ "**/rollup.config.*.js", // rollup config
41
+ "**/gulpfile.js", // gulp config
42
+ "**/gulpfile.*.js", // gulp config
43
+ "**/Gruntfile{,.js}", // grunt config
44
+ "**/protractor.conf.js", // protractor config
45
+ "**/protractor.conf.*.js", // protractor config
46
+ "**/karma.conf.js", // karma config
47
+ "**/.eslintrc.js", // eslint config
48
+
49
+ "**/scripts/*.{js,cjs,mjs,ts,cts,mts}", // Files inside of a "scripts" directory.
50
+ ],
51
+ optionalDependencies: false,
52
+ },
53
+ ],
54
+
55
+ "import-x/no-mutable-exports": "warn",
56
+ "import-x/no-named-as-default": "warn",
57
+
58
+ /**
59
+ * Disabled because this is [already handled by the TypeScript
60
+ * compiler](https://typescript-eslint.io/linting/troubleshooting/performance-troubleshooting/#eslint-plugin-import).
61
+ */
62
+ "import-x/no-named-as-default-member": "off",
63
+
64
+ /**
65
+ * Disabled since this check is better performed by the [`knip`](https://github.com/webpro/knip)
66
+ * tool.
67
+ */
68
+ "import-x/no-unused-modules": "off",
69
+ };
70
+
71
+ /** @type {Record<string, import("@typescript-eslint/utils").TSESLint.SharedConfig.RuleEntry>} */
72
+ const MODULE_SYSTEMS = {
73
+ "import-x/no-amd": "warn",
74
+ "import-x/no-commonjs": "warn",
75
+ "import-x/no-import-module-exports": "warn",
76
+
77
+ /** Disabled because it is only used in specific environments (like the browser). */
78
+ "import-x/no-nodejs-modules": "off",
79
+
80
+ /** Disabled because this is already handled by the TypeScript compiler. */
81
+ "import-x/unambiguous": "off",
82
+ };
83
+
84
+ /** @type {Record<string, import("@typescript-eslint/utils").TSESLint.SharedConfig.RuleEntry>} */
85
+ const STATIC_ANALYSIS = {
86
+ /**
87
+ * Disabled because this is [already handled by the TypeScript
88
+ * compiler](https://typescript-eslint.io/linting/troubleshooting/performance-troubleshooting/#eslint-plugin-import).
89
+ */
90
+ "import-x/default": "off",
91
+
92
+ /**
93
+ * Disabled because this is [already handled by the TypeScript
94
+ * compiler](https://typescript-eslint.io/linting/troubleshooting/performance-troubleshooting/#eslint-plugin-import).
95
+ */
96
+ "import-x/named": "off",
97
+
98
+ /**
99
+ * Disabled because this is [already handled by the TypeScript
100
+ * compiler](https://typescript-eslint.io/linting/troubleshooting/performance-troubleshooting/#eslint-plugin-import).
101
+ */
102
+ "import-x/namespace": "off",
103
+
104
+ "import-x/no-absolute-path": "warn",
105
+ "import-x/no-cycle": "warn",
106
+ "import-x/no-dynamic-require": "warn",
107
+
108
+ /** Disabled since a prescribed import pattern is not generalizable enough across projects. */
109
+ "import-x/no-internal-modules": "off",
110
+
111
+ "import-x/no-relative-packages": "warn",
112
+
113
+ /**
114
+ * Disabled since a forward import direction pattern is not generalizable enough across projects.
115
+ */
116
+ "import-x/no-relative-parent-imports": "off",
117
+
118
+ /** Disabled since this rule should only contain a project-specific path restriction. */
119
+ "import-x/no-restricted-paths": "off",
120
+
121
+ "import-x/no-self-import": "warn",
122
+
123
+ /**
124
+ * Disabled because this is [already handled by the TypeScript
125
+ * compiler](https://github.com/iamturns/eslint-config-airbnb-typescript/blob/master/lib/shared.js).
126
+ */
127
+ "import-x/no-unresolved": "off",
128
+
129
+ "import-x/no-useless-path-segments": "warn",
130
+ "import-x/no-webpack-loader-syntax": "warn",
131
+ };
132
+
133
+ /** @type {Record<string, import("@typescript-eslint/utils").TSESLint.SharedConfig.RuleEntry>} */
134
+ const STYLE_GUIDE = {
135
+ "import-x/consistent-type-specifier-style": "warn",
136
+
137
+ /** Disabled because it is only useful in environments that use webpack. */
138
+ "import-x/dynamic-import-chunkname": "off",
139
+
140
+ /** Disabled because this style is not generally used. */
141
+ "import-x/exports-last": "off",
142
+
143
+ /** Disabled because this is already handled by the TypeScript compiler. */
144
+ "import-x/extensions": "off",
145
+
146
+ "import-x/first": "warn",
147
+
148
+ /** Disabled because this style is not generally used. */
149
+ "import-x/group-exports": "off",
150
+
151
+ /** Disabled because this rule is deprecated. */
152
+ "import-x/imports-first": "off",
153
+
154
+ /** Disabled since it will trigger false positives in codebases that prefer smaller files. */
155
+ "import-x/max-dependencies": "off",
156
+
157
+ "import-x/newline-after-import": "warn",
158
+
159
+ /**
160
+ * Disabled since we disallow default exports elsewhere in this config (in favor of named
161
+ * exports).
162
+ */
163
+ "import-x/no-anonymous-default-export": "off",
164
+
165
+ /**
166
+ * The case against default exports is [laid out by Basarat Ali
167
+ * Syed](https://basarat.gitbook.io/typescript/main-1/defaultisbad).
168
+ */
169
+ "import-x/no-default-export": "warn",
170
+
171
+ "import-x/no-duplicates": "warn",
172
+ "import-x/no-named-default": "warn",
173
+
174
+ /**
175
+ * Disabled since we disallow default exports elsewhere in this config (in favor of named
176
+ * exports).
177
+ */
178
+ "import-x/no-named-export": "off",
179
+
180
+ /**
181
+ * Disabled since it is too prescriptive for a general audience. (Using `import * as` is common.)
182
+ */
183
+ "import-x/no-namespace": "off",
184
+
185
+ "import-x/no-unassigned-import": "warn",
186
+
187
+ /** Disabled because this is automatically handled by `prettier-plugin-organize-imports`. */
188
+ "import-x/order": "off",
189
+
190
+ /**
191
+ * Disabled because we disallow default exports elsewhere in this config (in favor of named
192
+ * exports).
193
+ */
194
+ "import-x/prefer-default-export": "off",
195
+ };
196
+
197
+ /**
198
+ * Omit `.d.ts` because:
199
+ * 1. TypeScript compilation already confirms that types are resolved.
200
+ * 2. It would mask an unresolved `.ts`/`.tsx`/`.js`/`.jsx` implementation.
201
+ */
202
+ const TYPESCRIPT_EXTENSIONS = [".ts", ".cts", ".mts", ".tsx"];
203
+
204
+ const ALL_EXTENSIONS = [
205
+ ...TYPESCRIPT_EXTENSIONS,
206
+ ".js",
207
+ ".cjs",
208
+ ".mjs",
209
+ ".jsx",
210
+ ];
211
+
212
+ /**
213
+ * This ESLint config only contains rules from `eslint-plugin-import-x`:
214
+ * https://github.com/un-ts/eslint-plugin-import-x
215
+ *
216
+ * Rules are separated into categories:
217
+ * 1) Helpful warnings
218
+ * 2) Module systems
219
+ * 3) Static analysis
220
+ * 4) Style guide
221
+ */
222
+ export const baseImportX = tseslint.config(
223
+ {
224
+ plugins: {
225
+ "import-x": ESLintPluginImportX,
226
+ },
227
+
228
+ // Beyond just specifying the plugin, additional configuration is necessary to make the plugin
229
+ // work properly with TypeScript:
230
+
231
+ // - First, the "eslint-import-resolver-typescript" package needs to be installed, or else an
232
+ // error will appear: "Resolve error: typescript with invalid interface loaded as resolver"
233
+ // - However, it is discussed in this issue to include that dep as part of
234
+ // "eslint-plugin-import-x" itself:
235
+ // https://github.com/un-ts/eslint-plugin-import-x/issues/150
236
+ // - Second, we extend the upstream TypeScript configuration:
237
+ // https://github.com/un-ts/eslint-plugin-import-x/blob/master/src/config/typescript.ts
238
+ // - Third, we need to specify "typescript: true" under the resolver, as documented here:
239
+ // https://github.com/un-ts/eslint-plugin-import-x/issues/29
240
+ // (Otherwise, the "no-cycle" rule will not work.)
241
+ settings: {
242
+ "import-x/extensions": ALL_EXTENSIONS,
243
+ "import-x/external-module-folders": [
244
+ "node_modules",
245
+ "node_modules/@types",
246
+ ],
247
+ "import-x/parsers": {
248
+ "@typescript-eslint/parser": TYPESCRIPT_EXTENSIONS,
249
+ },
250
+ "import-x/resolver": {
251
+ typescript: true,
252
+ node: {
253
+ extensions: ALL_EXTENSIONS,
254
+ },
255
+ },
256
+ },
257
+
258
+ rules: {
259
+ ...HELPFUL_WARNINGS,
260
+ ...MODULE_SYSTEMS,
261
+ ...STATIC_ANALYSIS,
262
+ ...STYLE_GUIDE,
263
+ },
264
+ },
265
+
266
+ // Disable some TypeScript-specific rules in JavaScript files.
267
+ {
268
+ files: ["**/*.js", "**/*.cjs", "**/*.mjs", "**/*.jsx"],
269
+ rules: {
270
+ "import-x/no-commonjs": "off",
271
+ },
272
+ },
273
+
274
+ // Some configuration files must export a default object as a design limitation.
275
+ {
276
+ files: [
277
+ ".remarkrc.js",
278
+ ".remarkrc.mjs",
279
+ "eslint.config.js",
280
+ "eslint.config.mjs",
281
+ "jest.config.js",
282
+ "jest.config.mjs",
283
+ "knip.js",
284
+ "knip.ts",
285
+ "knip.config.js",
286
+ "knip.config.ts",
287
+ "prettier.config.js",
288
+ "prettier.config.mjs",
289
+ "typedoc.config.js",
290
+ "typedoc.config.mjs",
291
+ "vite.config.js",
292
+ "vite.config.mjs",
293
+ ],
294
+ rules: {
295
+ "import-x/no-default-export": "off",
296
+ },
297
+ },
298
+ );
@@ -0,0 +1,276 @@
1
+ import ESLintPluginJSDoc from "eslint-plugin-jsdoc";
2
+ import tseslint from "typescript-eslint";
3
+
4
+ /**
5
+ * This ESLint config only contains rules from `eslint-plugin-jsdoc`:
6
+ * https://github.com/gajus/eslint-plugin-jsdoc
7
+ */
8
+ export const baseJSDoc = tseslint.config(
9
+ {
10
+ plugins: {
11
+ jsdoc: ESLintPluginJSDoc,
12
+ },
13
+
14
+ rules: {
15
+ /** Disabled because it is not needed in TypeScript. */
16
+ "jsdoc/check-access": "off",
17
+
18
+ /** Superseded by the `complete/limit-jsdoc-comments` rule. */
19
+ "jsdoc/check-alignment": "off",
20
+
21
+ /**
22
+ * Disabled since it [does not work with ESLint
23
+ * 8](https://github.com/eslint/eslint/issues/14745).
24
+ */
25
+ "jsdoc/check-examples": "off",
26
+
27
+ /** Superseded by the `complete/limit-jsdoc-comments` rule. */
28
+ "jsdoc/check-indentation": "off",
29
+
30
+ /**
31
+ * Disabled since this is not a common formatting scheme. It is also not recommended by the
32
+ * plugin authors.
33
+ */
34
+ "jsdoc/check-line-alignment": "off",
35
+
36
+ "jsdoc/check-param-names": "warn",
37
+
38
+ /** Disabled because it is not needed in TypeScript. */
39
+ "jsdoc/check-property-names": "off",
40
+
41
+ /** Disabled because it is not needed in TypeScript. */
42
+ "jsdoc/check-syntax": "off",
43
+
44
+ "jsdoc/check-tag-names": [
45
+ "warn",
46
+ {
47
+ definedTags: [
48
+ // Ignore tags used by the TypeScript compiler:
49
+ // https://www.typescriptlang.org/tsconfig#stripInternal
50
+ "internal", // Used by TypeScript
51
+
52
+ // Ignore tags used in TypeDoc:
53
+ // https://typedoc.org/guides/doccomments/
54
+ "category",
55
+ "hidden",
56
+ "notExported", // From: typedoc-plugin-not-exported
57
+ "rename", // From: typedoc-plugin-rename
58
+
59
+ // Ignore tags used in TypeScriptToLua:
60
+ // https://typescripttolua.github.io/docs/advanced/compiler-annotations
61
+ "customName",
62
+ "noResolution",
63
+ "noSelf",
64
+ "noSelfInFile",
65
+
66
+ // Ignore tags used in `ts-json-schema-generator`:
67
+ // https://github.com/vega/ts-json-schema-generator
68
+ "minimum",
69
+ "maximum",
70
+
71
+ // Ignore tags used in `eslint-plugin-complete`:
72
+ // https://github.com/complete-ts/complete/blob/main/packages/eslint-plugin-complete/docs/rules/require-variadic-function-argument.md
73
+ "allowEmptyVariadic",
74
+ ],
75
+ },
76
+ ],
77
+
78
+ "jsdoc/check-template-names": "warn",
79
+
80
+ /** Disabled because it is not needed in TypeScript. */
81
+ "jsdoc/check-types": "off",
82
+
83
+ "jsdoc/check-values": "warn",
84
+
85
+ /**
86
+ * Disabled since it is idiomatic in the TypeScript ecosystem to use a mixture of both JSDoc
87
+ * and non-JSDoc comments.
88
+ */
89
+ "jsdoc/convert-to-jsdoc-comments": "off",
90
+
91
+ "jsdoc/empty-tags": "warn",
92
+ "jsdoc/implements-on-classes": "warn",
93
+
94
+ /** Disabled since you cannot configure it with a path to the correct "package.json" file. */
95
+ "jsdoc/imports-as-dependencies": "off",
96
+
97
+ "jsdoc/informative-docs": "warn",
98
+
99
+ /**
100
+ * Disabled since it is [currently
101
+ * bugged](https://github.com/gajus/eslint-plugin-jsdoc/issues/1296).
102
+ */
103
+ "jsdoc/lines-before-block": "off",
104
+
105
+ /** Superseded by the `complete/jsdoc-full-sentences` rule. */
106
+ "jsdoc/match-description": "off",
107
+
108
+ /** Disabled because it is only needed for projects with specific JSDoc requirements. */
109
+ "jsdoc/match-name": "off",
110
+
111
+ /** Superseded by the `complete/limit-jsdoc-comments` rule. */
112
+ "jsdoc/multiline-blocks": "off",
113
+
114
+ /** Superseded by the `complete/limit-jsdoc-comments` rule. */
115
+ "jsdoc/newline-after-description": "off",
116
+
117
+ /**
118
+ * Disabled because it provides little value; it only detects JSDoc comments with tags in
119
+ * them.
120
+ */
121
+ "jsdoc/no-bad-blocks": "off",
122
+
123
+ /** Superseded by the `complete/format-jsdoc-comments` rule. */
124
+ "jsdoc/no-blank-block-descriptions": "off",
125
+
126
+ /** Superseded by the `complete/no-empty-jsdoc` rule. */
127
+ "jsdoc/no-blank-blocks": "off",
128
+
129
+ /** Disabled because it provides little value; the `@default` tag is rare. */
130
+ "jsdoc/no-defaults": "off",
131
+
132
+ /** Disabled because it is too project-specific. */
133
+ "jsdoc/no-missing-syntax": "off",
134
+
135
+ /** Superseded by the `complete/limit-jsdoc-comments` rule. */
136
+ "jsdoc/no-multi-asterisks": "off",
137
+
138
+ /**
139
+ * Disabled because it is intended for disabling of specific language features per-project.
140
+ */
141
+ "jsdoc/no-restricted-syntax": "off",
142
+
143
+ /** The `contexts` option is set to `any` to make the rule stricter. */
144
+ "jsdoc/no-types": [
145
+ "warn",
146
+ {
147
+ contexts: ["any"],
148
+ },
149
+ ],
150
+
151
+ /** Disabled because it is not needed in TypeScript. */
152
+ "jsdoc/no-undefined-types": "off",
153
+
154
+ "jsdoc/require-asterisk-prefix": "warn",
155
+
156
+ /** Superseded by the `complete/jsdoc-complete-sentences` rule. */
157
+ "jsdoc/require-description-complete-sentence": "off",
158
+
159
+ /** Disabled because it is overboard for every function to have a description. */
160
+ "jsdoc/require-description": "off",
161
+
162
+ /** Disabled because it is overboard for every function to require an example. */
163
+ "jsdoc/require-example": "off",
164
+
165
+ /** Disabled because it is overboard for every file to require an overview. */
166
+ "jsdoc/require-file-overview": "off",
167
+
168
+ /**
169
+ * The `never` option is provided to make the rule match the format of the official TypeScript
170
+ * codebase.
171
+ */
172
+ "jsdoc/require-hyphen-before-param-description": ["warn", "never"],
173
+
174
+ /** Disabled since it is overboard for every function to have a JSDoc comment. */
175
+ "jsdoc/require-jsdoc": "off",
176
+
177
+ /** The `contexts` option is set to `any` to make the rule stricter. */
178
+ "jsdoc/require-param-description": [
179
+ "warn",
180
+ {
181
+ contexts: ["any"],
182
+ },
183
+ ],
184
+
185
+ /** The `contexts` option is set to `any` to make the rule stricter. */
186
+ "jsdoc/require-param-name": [
187
+ "warn",
188
+ {
189
+ contexts: ["any"],
190
+ },
191
+ ],
192
+
193
+ /** Disabled because it is not needed in TypeScript. */
194
+ "jsdoc/require-param-type": "off",
195
+
196
+ /** Configured to only apply when there are one or more parameters. */
197
+ "jsdoc/require-param": [
198
+ "warn",
199
+ {
200
+ contexts: [
201
+ {
202
+ context: "FunctionDeclaration",
203
+ comment: 'JsdocBlock:has(JsdocTag[tag="param"])',
204
+ },
205
+ ],
206
+ },
207
+ ],
208
+
209
+ /** Disabled because it is not needed in TypeScript. */
210
+ "jsdoc/require-property": "off",
211
+
212
+ "jsdoc/require-property-description": "warn",
213
+ "jsdoc/require-property-name": "warn",
214
+
215
+ /** Disabled because it is not needed in TypeScript. */
216
+ "jsdoc/require-property-type": "off",
217
+
218
+ /** Disabled because it is overboard for every function to document every return value. */
219
+ "jsdoc/require-returns-check": "off",
220
+
221
+ /** The `contexts` option is set to `any` to make the rule stricter. */
222
+ "jsdoc/require-returns-description": [
223
+ "warn",
224
+ {
225
+ contexts: ["any"],
226
+ },
227
+ ],
228
+
229
+ /** Disabled because it is not needed in TypeScript. */
230
+ "jsdoc/require-returns-type": "off",
231
+
232
+ /** Disabled because it is overboard for every function to document every return value. */
233
+ "jsdoc/require-returns": "off",
234
+
235
+ /** Disabled because it is overboard to document every generic type variable. */
236
+ "jsdoc/require-template": "off",
237
+
238
+ /** Disabled because it is overboard to document every throw statement. */
239
+ "jsdoc/require-throws": "off",
240
+
241
+ /** Disabled because it is overboard to document every yield. */
242
+ "jsdoc/require-yields": "off",
243
+
244
+ /** Disabled because it is overboard to document every yield. */
245
+ "jsdoc/require-yields-check": "off",
246
+
247
+ /**
248
+ * Disabled because it is not very useful. In most cases, a function will only have `@param`
249
+ * and `@return` tags, making sorting unnecessary.
250
+ */
251
+ "jsdoc/sort-tags": "off",
252
+
253
+ /** Superseded by the `complete/format-jsdoc-comments` rule. */
254
+ "jsdoc/tag-lines": "off",
255
+
256
+ /**
257
+ * Disabled since it is only useful in certain environments (e.g. when your project converts
258
+ * JSDoc comments to Markdown).
259
+ */
260
+ "jsdoc/text-escaping": "off",
261
+
262
+ /** Disabled because it is not needed in TypeScript. */
263
+ "jsdoc/valid-types": "off",
264
+ },
265
+ },
266
+
267
+ // Disable some TypeScript-specific rules in JavaScript files.
268
+ {
269
+ files: ["**/*.js", "**/*.cjs", "**/*.mjs", "**/*.jsx"],
270
+ rules: {
271
+ "jsdoc/no-types": "off",
272
+ "jsdoc/require-param-description": "off",
273
+ "jsdoc/require-returns-description": "off",
274
+ },
275
+ },
276
+ );