@open-xchange/linter-presets 0.0.1

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.
Files changed (40) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +39 -0
  3. package/doc/eslint.md +343 -0
  4. package/doc/stylelint.md +3 -0
  5. package/doc/utils.md +30 -0
  6. package/lib/eslint/config/base.js +136 -0
  7. package/lib/eslint/config/directives.js +21 -0
  8. package/lib/eslint/config/js.js +36 -0
  9. package/lib/eslint/config/jsdoc.js +55 -0
  10. package/lib/eslint/config/json.js +37 -0
  11. package/lib/eslint/config/license.js +33 -0
  12. package/lib/eslint/config/promises.js +33 -0
  13. package/lib/eslint/config/stylistic.js +123 -0
  14. package/lib/eslint/config/ts.js +100 -0
  15. package/lib/eslint/config/yaml.js +34 -0
  16. package/lib/eslint/env/browser.d.ts +13 -0
  17. package/lib/eslint/env/browser.js +127 -0
  18. package/lib/eslint/env/codecept.d.ts +13 -0
  19. package/lib/eslint/env/codecept.js +70 -0
  20. package/lib/eslint/env/jest.d.ts +13 -0
  21. package/lib/eslint/env/jest.js +56 -0
  22. package/lib/eslint/env/node.d.ts +21 -0
  23. package/lib/eslint/env/node.js +59 -0
  24. package/lib/eslint/env/plugin.d.ts +13 -0
  25. package/lib/eslint/env/plugin.js +61 -0
  26. package/lib/eslint/env/react.d.ts +19 -0
  27. package/lib/eslint/env/react.js +103 -0
  28. package/lib/eslint/env/tsconfig.d.ts +19 -0
  29. package/lib/eslint/env/tsconfig.js +37 -0
  30. package/lib/eslint/env/vitest.d.ts +13 -0
  31. package/lib/eslint/env/vitest.js +103 -0
  32. package/lib/eslint/index.d.ts +90 -0
  33. package/lib/eslint/index.js +106 -0
  34. package/lib/eslint/shared/constants.js +33 -0
  35. package/lib/eslint/shared/types.d.ts +90 -0
  36. package/lib/index.d.ts +3 -0
  37. package/lib/index.js +3 -0
  38. package/lib/utils/index.d.ts +4 -0
  39. package/lib/utils/index.js +18 -0
  40. package/package.json +61 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 OX Software GmbH, Germany <info@open-xchange.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # @open-xchange/linter-presets
2
+
3
+ This package provides configuration presets for [ESLint](https://eslint.org/) and [StyleLint](https://stylelint.io/), including wrappers for various linter plugins.
4
+
5
+ ## Utils
6
+
7
+ The module `utils` exports utility functions for usage in either ESLint or StyleLint configuration files.
8
+
9
+ See the [documentation](./doc/utils.md) for more details.
10
+
11
+ ## ESLint
12
+
13
+ The module `eslint` exports a `configure` function for setting up the entire project (e.g. TypeScript files, JSON files, license headers, etc.), and a set of environment presets that apply more ESLint plugins and rules to a specific subset of the project (e.g. browser code, unit test code, etc.).
14
+
15
+ Usage example:
16
+
17
+ ```js
18
+ // eslint.config.js
19
+ import { eslint } from "@open-xchange/linter-presets"
20
+
21
+ export default [
22
+
23
+ // global project configuration
24
+ ...eslint.configure({ /* config options */ }),
25
+
26
+ // add environments
27
+ ...eslint.env.browser({ files: ["src/**/*.js"], /* ... */ }),
28
+ ...eslint.env.vitest({ files: ["test/**/*.js"], /* ... */ }),
29
+
30
+ // add custom configurations
31
+ { /* ... */ },
32
+ ]
33
+ ```
34
+
35
+ See the [documentation](./doc/eslint.md) for more details.
36
+
37
+ ## StyleLint
38
+
39
+ See the [documentation](./doc/stylelint.md) for more details.
package/doc/eslint.md ADDED
@@ -0,0 +1,343 @@
1
+ # ESLint Presets
2
+
3
+ The module `eslint` provides a `configure` function for project-wide ESLint configuration (e.g. TypeScript files, JSON files, license headers, etc.), and a set of environment presets that apply more ESLint plugins and rules to a specific subset of the project (e.g. browser code, unit test code, etc.).
4
+
5
+ ## Functions
6
+
7
+ ### Function `configure`
8
+
9
+ Generates standard configuration targeting the source files in the entire project. Internally, various ESLint plugins will be included and configured to use their recommended rule sets.
10
+
11
+ | Target | ESLint Plugin |
12
+ | - | - |
13
+ | JavaScript and TypeScript files (including `.jsx` and `.tsx`) | ESLint core rules |
14
+ | JavaScript files only (including `.jsx`) | ESLint core rules |
15
+ | TypeScript files with type-aware rules (including `.tsx`) | [typescript-eslint](https://typescript-eslint.io/) |
16
+ | JSON files | [eslint-plugin-jsonc](https://ota-meshi.github.io/eslint-plugin-jsonc/) |
17
+ | YAML files | [eslint-plugin-yml](https://ota-meshi.github.io/eslint-plugin-yml/) |
18
+ | License headers | [eslint-plugin-license-header](https://github.com/nikku/eslint-plugin-license-header) |
19
+ | ESLint inline directives | [@eslint-community/eslint-plugin-eslint-comments](https://github.com/eslint-community/eslint-plugin-eslint-comments) |
20
+ | Native ES6 promises | [eslint-plugin-promise](https://github.com/eslint-community/eslint-plugin-promise) |
21
+ | JSDoc source documentation | [eslint-plugin-jsdoc](https://github.com/gajus/eslint-plugin-jsdoc) |
22
+ | Source code formatting | [@stylistic/eslint-plugin](https://eslint.style/packages/default) |
23
+
24
+ #### `configure` Signature
25
+
26
+ `function configure(options?: ESLintPresetsOptions): Linter.FlatConfig[]`
27
+
28
+ #### `configure` Options
29
+
30
+ | Name | Type | Default | Description |
31
+ | - | - | - | - |
32
+ | `ignores` | `string[]` | `[]` | Glob patterns with all files and folders to be ignored by ESlint. |
33
+ | `license` | `string` | `""` | Full path to the template file containing the license header to be used in all source files. |
34
+ | `language` | `LanguageOptions` | | Configuration options for language and project setup. |
35
+ | `language.ecmaVersion` | `number` | `2022` | The ECMAScript version to be used in the project (version or year). |
36
+ | `language.sourceType` | `"module"\|"commonjs"` | `"module"` | Specifies how to treat `.js`, `.jsx`, `.ts`, and `.tsx` files. |
37
+ | `stylistic` | `StylisticOptions` | | Configuration options for code style. |
38
+ | `stylistic.indent` | `number` | `2` | Default indentation size (number of space characters). Will be applied to JavaScript, TypeScript, JSON, and YAML files, as well as JSX markup. |
39
+ | `stylistic.semi` | `boolean` | `false` | Specifies whether to require semicolons following all statements (`true`), or to force to omit semicolons if possible according to ASI rules (`false`). |
40
+ | `stylistic.quotes` | `"single"\|"double"\|"off"` | `"single"` | The type of the string delimiter character. |
41
+ | `stylistic.dangle` | `"always"\|"never"\|"off"` | `"always"` | Specifies how to treat dangling commas in multiline lists. |
42
+ | `rules` | `Linter.RulesRecord` | `{}` | Additional linter rules to be added to the global configuration. |
43
+
44
+ #### `configure` Example
45
+
46
+ ```js
47
+ // eslint.config.js
48
+ import { utils, eslint } from "@open-xchange/linter-presets"
49
+
50
+ const resolve = utils.resolver(import.meta.url)
51
+
52
+ export default [
53
+ ...eslint.configure({
54
+ ignores: ["dist/*", "external/**/*.yaml"],
55
+ language: { ecmaVersion: 2024, sourceType: "commonjs" },
56
+ license: resolve("./license.txt"),
57
+ stylistic: { quotes: "double", semi: true },
58
+ }),
59
+ ]
60
+ ```
61
+
62
+ ## Environment Presets
63
+
64
+ Environment presets will be applied to specific subsets of the project. Usually, they import one or more external ESLint plugins, apply their recommended rule set, and add or modify a few of their rules to establish the default setup for the project.
65
+
66
+ ### Overview
67
+
68
+ | Name | Target | ESLint Plugins |
69
+ | - | - | - |
70
+ | `env.tsconfig` | TypeScript project setup (per `tsconfig.json` file) | |
71
+ | `env.node` | NodeJS modules | [eslint-plugin-n](https://github.com/eslint-community/eslint-plugin-n) |
72
+ | `env.browser` | Modules running in browsers | [globals](https://github.com/sindresorhus/globals), [confusing-browser-globals](https://github.com/facebook/create-react-app/tree/main/packages/confusing-browser-globals) |
73
+ | `env.react` | Source modules using [React](https://react.dev/) library | [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) (and others) |
74
+ | `env.jest` | Unit tests with [Jest](https://jestjs.io/) | [eslint-plugin-jest](https://github.com/jest-community/eslint-plugin-jest) |
75
+ | `env.vitest` | Unit tests with [Vitest](https://vitest.dev/) | [eslint-plugin-vitest](https://github.com/veritem/eslint-plugin-vitest) (and others) |
76
+ | `env.codecept` | E2E tests with [CodeceptJS](https://codecept.io/) | [eslint-plugin-codeceptjs](https://github.com/poenneby/eslint-plugin-codeceptjs) (and others) |
77
+ | `env.plugin` | Implementation of custom ESLint plugins | [eslint-plugin-eslint-plugin](https://github.com/eslint-community/eslint-plugin-eslint-plugin) |
78
+
79
+ ### Environment `env.tsconfig`
80
+
81
+ Creates configuration objects for TypeScript projects (registers a `tsconfig.json` file in the project).
82
+
83
+ #### `env.tsconfig` Signature
84
+
85
+ `function tsconfig(options: EnvTSConfigOptions): Linter.FlatConfig[]`
86
+
87
+ #### `env.tsconfig` Options
88
+
89
+ | Name | Type | Default | Description |
90
+ | - | - | - | - |
91
+ | `files` | `string[]` | _required_ | Glob patterns for source files to be included. |
92
+ | `ignores` | `string[]` | `[]` | Glob patterns for source files matching `files` to be ignored. |
93
+ | `project` | `string` | _required_ | The path to the TypeScript project configuration file (`tsconfig.json`). |
94
+ | `rules` | `Linter.RulesRecord` | `{}` | Additional linter rules to be added to the configuration. |
95
+
96
+ #### `env.tsconfig` Example
97
+
98
+ ```js
99
+ // eslint.config.js
100
+ import { utils, eslint } from "@open-xchange/linter-presets"
101
+
102
+ const resolve = utils.resolver(import.meta.url)
103
+
104
+ export default [
105
+ ...eslint.configure({ /* ... */ }),
106
+ ...eslint.env.tsconfig({
107
+ files: ["src/**/*.ts"],
108
+ project: resolve("src/tsconfig.json"),
109
+ }),
110
+ ]
111
+ ```
112
+
113
+ ### Environment `env.node`
114
+
115
+ Creates configuration objects with global symbols and linter rules for NodeJS modules. Adds the plugin [eslint-plugin-n](https://github.com/eslint-community/eslint-plugin-n) and its recommended rules.
116
+
117
+ #### `env.node` Signature
118
+
119
+ `function node(options: EnvNodeOptions): Linter.FlatConfig[]`
120
+
121
+ #### `env.node` Options
122
+
123
+ | Name | Type | Default | Description |
124
+ | - | - | - | - |
125
+ | `files` | `string[]` | _required_ | Glob patterns for source files to be included. |
126
+ | `ignores` | `string[]` | `[]` | Glob patterns for source files matching `files` to be ignored. |
127
+ | `sourceType` | `"module"\|"commonjs"` | `"module"` | Specifies how to treat `.js`, `.jsx`, `.ts`, and `.tsx`. |
128
+ | `rules` | `Linter.RulesRecord` | `{}` | Additional linter rules to be added to the configuration. |
129
+
130
+ #### `env.node` Example
131
+
132
+ ```js
133
+ // eslint.config.js
134
+ import { utils, eslint } from "@open-xchange/linter-presets"
135
+
136
+ export default [
137
+ ...configure({ /* ... */ }),
138
+ ...env.node({
139
+ files: ["*.config.{js,ts}", "scripts/**/*.js"],
140
+ rules: { /* ... */ },
141
+ }),
142
+ ]
143
+ ```
144
+
145
+ ### Environment `env.browser`
146
+
147
+ Creates configuration objects with global symbols and linter rules for modules running in the browser. Adds well-known [browser globals](https://github.com/sindresorhus/globals), and forbids [confusing browser globals](https://github.com/facebook/create-react-app/tree/main/packages/confusing-browser-globals).
148
+
149
+ #### `env.browser` Signature
150
+
151
+ `function browser(options: EnvBrowserOptions): Linter.FlatConfig[]`
152
+
153
+ #### `env.browser` Options
154
+
155
+ | Name | Type | Default | Description |
156
+ | - | - | - | - |
157
+ | `files` | `string[]` | _required_ | Glob patterns for source files to be included. |
158
+ | `ignores` | `string[]` | `[]` | Glob patterns for source files matching `files` to be ignored. |
159
+ | `rules` | `Linter.RulesRecord` | `{}` | Additional linter rules to be added to the configuration. |
160
+
161
+ #### `env.browser` Example
162
+
163
+ ```js
164
+ // eslint.config.js
165
+ import { eslint } from "@open-xchange/linter-presets"
166
+
167
+ export default [
168
+ ...eslint.configure({ /* ... */ }),
169
+ ...eslint.env.browser({
170
+ files: ["src/**/*.{js,ts}"],
171
+ rules: { /* ... */ },
172
+ }),
173
+ ]
174
+ ```
175
+
176
+ ### Environment `env.react`
177
+
178
+ Creates configuration objects with linter rules for ReactJS. Adds the following plugins and their recommended rules:
179
+
180
+ - [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react)
181
+ - [eslint-plugin-react-hooks](https://github.com/facebook/react/tree/main/packages/eslint-plugin-react-hooks)
182
+ - [eslint-plugin-react-hooks-static-deps](https://github.com/stoikio/eslint-plugin-react-hooks-static-deps)
183
+ - [eslint-plugin-react-refresh](https://github.com/ArnaudBarre/eslint-plugin-react-refresh)
184
+ - [eslint-plugin-jsx-expressions](https://github.com/hluisson/eslint-plugin-jsx-expressions)
185
+ - [eslint-plugin-jsx-a11y](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y)
186
+
187
+ #### `env.react` Signature
188
+
189
+ `function react(options: EnvReactOptions): Linter.FlatConfig[]`
190
+
191
+ #### `env.react` Options
192
+
193
+ | Name | Type | Default | Description |
194
+ | - | - | - | - |
195
+ | `files` | `string[]` | _required_ | Glob patterns for source files to be included. |
196
+ | `ignores` | `string[]` | `[]` | Glob patterns for source files matching `files` to be ignored. |
197
+ | `rules` | `Linter.RulesRecord` | `{}` | Additional linter rules to be added to the configuration. |
198
+
199
+ #### `env.react` Example
200
+
201
+ ```js
202
+ // eslint.config.js
203
+ import { eslint } from "@open-xchange/linter-presets"
204
+
205
+ export default [
206
+ ...eslint.configure({ /* ... */ }),
207
+ ...eslint.env.react({
208
+ files: ["src/**/*.{js,ts}"],
209
+ rules: { /* ... */ },
210
+ }),
211
+ ]
212
+ ```
213
+
214
+ ### Environment `env.jest`
215
+
216
+ Creates configuration objects with global symbols and linter rules for unit tests using Jest. Adds the plugin [eslint-plugin-jest](https://github.com/jest-community/eslint-plugin-jest) and its recommended rules.
217
+
218
+ #### `env.jest` Signature
219
+
220
+ `function jest(options: EnvJestOptions): Linter.FlatConfig[]`
221
+
222
+ #### `env.jest` Options
223
+
224
+ | Name | Type | Default | Description |
225
+ | - | - | - | - |
226
+ | `files` | `string[]` | _required_ | Glob patterns for source files to be included. |
227
+ | `ignores` | `string[]` | `[]` | Glob patterns for source files matching `files` to be ignored. |
228
+ | `rules` | `Linter.RulesRecord` | `{}` | Additional linter rules to be added to the configuration. |
229
+
230
+ #### `env.jest` Example
231
+
232
+ ```js
233
+ // eslint.config.js
234
+ import { eslint } from "@open-xchange/linter-presets"
235
+
236
+ export default [
237
+ ...eslint.configure({ /* ... */ }),
238
+ ...eslint.env.jest({
239
+ files: ["test/**/*.{js,ts}"],
240
+ rules: { /* ... */ },
241
+ }),
242
+ ]
243
+ ```
244
+
245
+ ### Environment `env.vitest`
246
+
247
+ Creates configuration objects with global symbols and linter rules for unit tests using Vitest. Adds the following plugins and their recommended rules:
248
+
249
+ - [eslint-plugin-vitest](https://github.com/veritem/eslint-plugin-vitest)
250
+ - [eslint-plugin-testing-library](https://github.com/testing-library/eslint-plugin-testing-library)
251
+ - [eslint-plugin-jest-dom](https://github.com/testing-library/eslint-plugin-jest-dom)
252
+
253
+ #### `env.vitest` Signature
254
+
255
+ `function vitest(options: EnvVitestOptions): Linter.FlatConfig[]`
256
+
257
+ #### `env.vitest` Options
258
+
259
+ | Name | Type | Default | Description |
260
+ | - | - | - | - |
261
+ | `files` | `string[]` | _required_ | Glob patterns for source files to be included. |
262
+ | `ignores` | `string[]` | `[]` | Glob patterns for source files matching `files` to be ignored. |
263
+ | `rules` | `Linter.RulesRecord` | `{}` | Additional linter rules to be added to the configuration. |
264
+
265
+ #### `env.vitest` Example
266
+
267
+ ```js
268
+ // eslint.config.js
269
+ import { eslint } from "@open-xchange/linter-presets"
270
+
271
+ export default [
272
+ ...eslint.configure({ /* ... */ }),
273
+ ...eslint.env.vitest({
274
+ files: ["test/**/*.{js,ts}"],
275
+ rules: { /* ... */ },
276
+ }),
277
+ ]
278
+ ```
279
+
280
+ ### Environment `env.codecept`
281
+
282
+ Creates configuration objects with global symbols and linter rules for E2E tests using CodeceptJS. Adds the following plugins and their recommended rules:
283
+
284
+ - [eslint-plugin-codeceptjs](https://github.com/poenneby/eslint-plugin-codeceptjs)
285
+ - [eslint-plugin-chai-expect](https://github.com/turbo87/eslint-plugin-chai-expect)
286
+
287
+ #### `env.codecept` Signature
288
+
289
+ `function codecept(options: EnvCodeceptOptions): Linter.FlatConfig[]`
290
+
291
+ #### `env.codecept` Options
292
+
293
+ | Name | Type | Default | Description |
294
+ | - | - | - | - |
295
+ | `files` | `string[]` | _required_ | Glob patterns for source files to be included. |
296
+ | `ignores` | `string[]` | `[]` | Glob patterns for source files matching `files` to be ignored. |
297
+ | `rules` | `Linter.RulesRecord` | `{}` | Additional linter rules to be added to the configuration. |
298
+
299
+ #### `env.codecept` Example
300
+
301
+ ```js
302
+ // eslint.config.js
303
+ import { eslint } from "@open-xchange/linter-presets"
304
+
305
+ export default [
306
+ ...eslint.configure({ /* ... */ }),
307
+ ...eslint.env.codecept({
308
+ files: ["e2e/**/*.{js,ts}"],
309
+ rules: { /* ... */ },
310
+ }),
311
+ ]
312
+ ```
313
+
314
+ ### Environment `env.plugin`
315
+
316
+ Creates configuration objects with linter rules for implementing custom ESlint plugins. Adds the plugin [eslint-plugin-eslint-plugin](https://github.com/eslint-community/eslint-plugin-eslint-plugin) and its recommended rules.
317
+
318
+ #### `env.plugin` Signature
319
+
320
+ `function plugin(options: EnvPluginOptions): Linter.FlatConfig[]`
321
+
322
+ #### `env.plugin` Options
323
+
324
+ | Name | Type | Default | Description |
325
+ | - | - | - | - |
326
+ | `files` | `string[]` | _required_ | Glob patterns for source files to be included. |
327
+ | `ignores` | `string[]` | `[]` | Glob patterns for source files matching `files` to be ignored. |
328
+ | `rules` | `Linter.RulesRecord` | `{}` | Additional linter rules to be added to the configuration. |
329
+
330
+ #### `env.plugin` Example
331
+
332
+ ```js
333
+ // eslint.config.js
334
+ import { eslint } from "@open-xchange/linter-presets"
335
+
336
+ export default [
337
+ ...eslint.configure({ /* ... */ }),
338
+ ...eslint.env.plugin({
339
+ files: ["rules/**/*.{js,ts}"],
340
+ rules: { /* ... */ },
341
+ }),
342
+ ]
343
+ ```
@@ -0,0 +1,3 @@
1
+ # StyleLint Presets
2
+
3
+ The module `stylelint` provides a `configure` function for project-wide StyleLint configuration.
package/doc/utils.md ADDED
@@ -0,0 +1,30 @@
1
+ # Utility Functions
2
+
3
+ The `utils` module provides utility functions for usage in either ESLint or StyleLint configuration files.
4
+
5
+ ## Functions
6
+
7
+ ### Function `resolver`
8
+
9
+ Creates and returns a function that will convert relative file paths to absolute file paths. Intended to be used with the base URL of the calling script, usually `import.meta.url`.
10
+
11
+ #### `resolver` Signature
12
+
13
+ `function resolver(url: string): (file: string) => string`
14
+
15
+ #### `resolver` Example
16
+
17
+ ```js
18
+ // eslint.config.js
19
+ import { utils, eslint } from "@open-xchange/linter-presets"
20
+
21
+ const resolve = utils.resolver(import.meta.url)
22
+
23
+ export default [
24
+ ...eslint.configure({
25
+ // ...
26
+ license: resolve("./license.txt"),
27
+ // ...
28
+ }),
29
+ ]
30
+ ```
@@ -0,0 +1,136 @@
1
+
2
+ import eslintJs from "@eslint/js";
3
+
4
+ // functions ==================================================================
5
+
6
+ /**
7
+ * Defines standard module settings and additional rules targeting JavaScript
8
+ * _and_ TypeScript source files.
9
+ *
10
+ * Wraps the following packages:
11
+ * - `@eslint/js`
12
+ *
13
+ * @param {Required<import("../shared/types").LanguageOptions>} options
14
+ * Resolved configuration options.
15
+ *
16
+ * @returns {import("../shared/types").FlatConfigArray}
17
+ * An array of configuration objects to be added to the flat configuration.
18
+ */
19
+ export default function base(options) {
20
+
21
+ /**
22
+ * Returns language options for specific file extensions.
23
+ *
24
+ * @param {"module"|"commonjs"} sourceType
25
+ * Module type specifier.
26
+ *
27
+ * @param {string[]} extensions
28
+ * List of file extensions.
29
+ *
30
+ * @returns {import("eslint").Linter.FlatConfig}
31
+ * The configuration entry.
32
+ */
33
+ function languageOptions(sourceType, ...extensions) {
34
+ const { ecmaVersion } = options;
35
+ return {
36
+ files: extensions.map(ext => "*/**." + ext),
37
+ languageOptions: { ecmaVersion, sourceType },
38
+ };
39
+ }
40
+
41
+ return [
42
+
43
+ // global linter configuration
44
+ {
45
+ linterOptions: {
46
+ // report unused inline linter directives in source code
47
+ reportUnusedDisableDirectives: "error",
48
+ },
49
+ },
50
+
51
+ // ECMA version and module type for ES modules
52
+ languageOptions("module", "mjs", "mts"),
53
+
54
+ // ECMA version and module type for CommonJS modules
55
+ languageOptions("commonjs", "cjs", "cts"),
56
+
57
+ // ECMA version and module type for *.js and *.ts files
58
+ languageOptions(options.sourceType, "js", "jsx", "ts", "tsx"),
59
+
60
+ // configure linter rules
61
+ {
62
+ files: ["**/*.{js,jsx,mjs,cjs,ts,tsx,mts,cts}"],
63
+ rules: {
64
+ // enable all rules recommended by ESLint itself
65
+ ...eslintJs.configs.recommended.rules,
66
+ // possible problems
67
+ "no-cond-assign": ["error", "except-parens"],
68
+ "no-constant-binary-expression": "error",
69
+ "no-constructor-return": "error",
70
+ "no-control-regex": "off",
71
+ "no-new-native-nonconstructor": "error",
72
+ "no-new-symbol": "off", // disabled in favour of "no-new-native-nonconstructor"
73
+ "no-promise-executor-return": ["error", { allowVoid: true }],
74
+ "no-self-compare": "error",
75
+ "no-template-curly-in-string": "error",
76
+ "no-unreachable-loop": "error",
77
+ "no-unsafe-optional-chaining": ["error", { disallowArithmeticOperators: true }],
78
+ "no-unused-private-class-members": "error",
79
+ "require-atomic-updates": "error",
80
+ // suggestions
81
+ "block-scoped-var": "error",
82
+ curly: "error",
83
+ eqeqeq: "error",
84
+ "grouped-accessor-pairs": "error",
85
+ "new-cap": "error",
86
+ "no-alert": "error",
87
+ "no-caller": "error",
88
+ "no-console": "error",
89
+ "no-else-return": "error",
90
+ "no-empty": "off",
91
+ "no-empty-static-block": "error",
92
+ "no-eval": "error",
93
+ "no-extend-native": "error",
94
+ "no-extra-bind": "error",
95
+ "no-extra-label": "error",
96
+ "no-implicit-coercion": ["error", { disallowTemplateShorthand: true, allow: ["!!"] }],
97
+ "no-implied-eval": "error",
98
+ "no-iterator": "error",
99
+ "no-label-var": "error",
100
+ "no-labels": "error",
101
+ "no-lone-blocks": "error",
102
+ "no-lonely-if": "error",
103
+ "no-multi-str": "error",
104
+ "no-new": "error",
105
+ "no-new-func": "error",
106
+ "no-new-wrappers": "error",
107
+ "no-object-constructor": "error",
108
+ "no-octal-escape": "error",
109
+ "no-proto": "error",
110
+ "no-return-assign": ["error", "except-parens"],
111
+ "no-script-url": "error",
112
+ "no-sequences": ["error", { allowInParentheses: false }],
113
+ "no-unneeded-ternary": ["error", { defaultAssignment: false }],
114
+ "no-unused-expressions": "error",
115
+ "no-useless-assignment": "error",
116
+ "no-useless-call": "error",
117
+ "no-useless-computed-key": "error",
118
+ "no-useless-concat": "error",
119
+ "no-useless-rename": "error",
120
+ "no-useless-return": "error",
121
+ "no-var": "error",
122
+ "object-shorthand": "error",
123
+ "one-var": ["error", "never"],
124
+ "operator-assignment": "error",
125
+ "prefer-arrow-callback": "error",
126
+ "prefer-const": ["error", { ignoreReadBeforeAssign: true }],
127
+ "prefer-numeric-literals": "error",
128
+ "prefer-regex-literals": "error",
129
+ "prefer-rest-params": "error",
130
+ "prefer-spread": "error",
131
+ radix: "error",
132
+ "symbol-description": "error",
133
+ },
134
+ },
135
+ ];
136
+ }
@@ -0,0 +1,21 @@
1
+
2
+ import commentsPluginConfigs from "@eslint-community/eslint-plugin-eslint-comments/configs";
3
+
4
+ // functions ==================================================================
5
+
6
+ /**
7
+ * Checks inline linter directives.
8
+ *
9
+ * Wraps the following packages:
10
+ * - `eslint-plugin-eslint-comments`
11
+ *
12
+ * @returns {import("../shared/types").FlatConfigArray}
13
+ * An array of configuration objects to be added to the flat configuration.
14
+ */
15
+ export default function directives() {
16
+
17
+ return [
18
+ // register rule implementations and recommended rules
19
+ commentsPluginConfigs.recommended,
20
+ ];
21
+ }
@@ -0,0 +1,36 @@
1
+
2
+ import { NO_UNUSED_VARS_OPTIONS } from "../shared/constants.js";
3
+
4
+ // functions ==================================================================
5
+
6
+ /**
7
+ * Defines additional standard rules targeting JavaScript but _not_ TypeScript
8
+ * source files.
9
+ *
10
+ * @returns {import("../shared/types.js").FlatConfigArray}
11
+ * An array of configuration objects to be added to the flat configuration.
12
+ */
13
+ export default function js() {
14
+
15
+ return [{
16
+ files: ["**/*.{js,jsx,cjs,mjs}"],
17
+ rules: {
18
+ // possible problems
19
+ "no-duplicate-imports": "error",
20
+ "no-loss-of-precision": "off",
21
+ "no-unused-vars": ["error", NO_UNUSED_VARS_OPTIONS],
22
+ // suggestions
23
+ "default-param-last": "error",
24
+ "dot-notation": "error",
25
+ "no-array-constructor": "error",
26
+ "no-invalid-this": "error",
27
+ "no-loop-func": "error",
28
+ "no-redeclare": "error",
29
+ "no-shadow": ["error", { ignoreOnInitialization: true }],
30
+ "no-throw-literal": "error",
31
+ "no-useless-constructor": "error",
32
+ "prefer-promise-reject-errors": "error",
33
+ "require-await": "error",
34
+ },
35
+ }];
36
+ }