@w5s/eslint-config 3.31.0 → 3.32.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.
- package/README.md +30 -0
- package/dist/index.d.ts +111 -21
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +100 -31
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/config/es.ts +104 -6
- package/src/config/imports.ts +3 -1
- package/src/defineConfig.ts +38 -60
- package/src/index.ts +2 -1
- package/src/restrictedGlobals.ts +15 -0
- package/src/restrictedImportPaths.ts +19 -0
- package/src/rules/airbnb-base/overrides.ts +1 -1
- package/src/type/RestrictedGlobals.ts +12 -0
- package/src/type/RestrictedImportPaths.ts +15 -0
- package/src/type.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@w5s/eslint-config",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.32.0",
|
|
4
4
|
"description": "ESLint configuration presets",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -46,9 +46,9 @@
|
|
|
46
46
|
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
47
47
|
"@typescript-eslint/parser": "^8.0.0",
|
|
48
48
|
"@vitest/eslint-plugin": "~1.6.20",
|
|
49
|
-
"@w5s/dev": "^3.
|
|
50
|
-
"@w5s/eslint-config-ignore": "^1.
|
|
51
|
-
"@w5s/prettier-config": "^3.
|
|
49
|
+
"@w5s/dev": "^3.23.0",
|
|
50
|
+
"@w5s/eslint-config-ignore": "^1.22.0",
|
|
51
|
+
"@w5s/prettier-config": "^3.17.0",
|
|
52
52
|
"eslint-merge-processors": "^2.0.0",
|
|
53
53
|
"eslint-plugin-import": "~2.32.0",
|
|
54
54
|
"eslint-plugin-jsdoc": "~64.1.0",
|
|
@@ -85,5 +85,5 @@
|
|
|
85
85
|
"publishConfig": {
|
|
86
86
|
"access": "public"
|
|
87
87
|
},
|
|
88
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "d7a7fcd9a54087b3af6ab1d69362b88df248f85a"
|
|
89
89
|
}
|
package/src/config/es.ts
CHANGED
|
@@ -4,15 +4,28 @@ import globals from 'globals';
|
|
|
4
4
|
|
|
5
5
|
import type { RuleOptions } from '../typegen/jsonc.js';
|
|
6
6
|
|
|
7
|
-
import { esSourceGlob } from '../glob.js';
|
|
7
|
+
import { esSourceGlob, sourceGlob } from '../glob.js';
|
|
8
|
+
import { restrictedGlobals as defaultGlobalRestrictedGlobals } from '../restrictedGlobals.js';
|
|
9
|
+
import { restrictedImportPaths as defaultGlobalRestrictedImportPaths } from '../restrictedImportPaths.js';
|
|
8
10
|
import { esRules } from '../rules/esRules.js';
|
|
9
|
-
import { type Config, type PluginOptionsBase } from '../type.js';
|
|
11
|
+
import { type Config, type PluginOptionsBase, type RestrictedGlobals, type RestrictedImportPaths } from '../type.js';
|
|
10
12
|
|
|
11
13
|
const defaultFiles = [esSourceGlob];
|
|
12
14
|
|
|
13
|
-
// eslint-disable-next-line ts/require-await
|
|
14
15
|
export async function es(options: es.Options) {
|
|
15
|
-
const {
|
|
16
|
+
const {
|
|
17
|
+
defaultRestrictedGlobals = defaultGlobalRestrictedGlobals,
|
|
18
|
+
defaultRestrictedImportPaths = defaultGlobalRestrictedImportPaths,
|
|
19
|
+
recommended = true,
|
|
20
|
+
restrictedImportPaths: paths,
|
|
21
|
+
rules = {},
|
|
22
|
+
} = options;
|
|
23
|
+
const resolvedGlobals =
|
|
24
|
+
typeof options.restrictedGlobals === 'function'
|
|
25
|
+
? options.restrictedGlobals(defaultRestrictedGlobals)
|
|
26
|
+
: options.restrictedGlobals ?? defaultRestrictedGlobals;
|
|
27
|
+
const resolvedPaths =
|
|
28
|
+
typeof paths === 'function' ? paths(defaultRestrictedImportPaths) : paths ?? defaultRestrictedImportPaths;
|
|
16
29
|
|
|
17
30
|
return [
|
|
18
31
|
{
|
|
@@ -43,6 +56,22 @@ export async function es(options: es.Options) {
|
|
|
43
56
|
},
|
|
44
57
|
name: 'w5s/es/setup',
|
|
45
58
|
},
|
|
59
|
+
{
|
|
60
|
+
files: [sourceGlob],
|
|
61
|
+
name: 'w5s/source/restricted-rules',
|
|
62
|
+
rules: {
|
|
63
|
+
'no-restricted-globals': [
|
|
64
|
+
'error',
|
|
65
|
+
...resolvedGlobals,
|
|
66
|
+
],
|
|
67
|
+
'no-restricted-imports': [
|
|
68
|
+
'error',
|
|
69
|
+
{
|
|
70
|
+
paths: resolvedPaths,
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
},
|
|
46
75
|
{
|
|
47
76
|
files: defaultFiles,
|
|
48
77
|
name: 'w5s/es/rules',
|
|
@@ -51,7 +80,7 @@ export async function es(options: es.Options) {
|
|
|
51
80
|
...rules,
|
|
52
81
|
},
|
|
53
82
|
},
|
|
54
|
-
] as [Config, Config] satisfies Array<Config>;
|
|
83
|
+
] as [Config, Config, Config] satisfies Array<Config>;
|
|
55
84
|
}
|
|
56
85
|
|
|
57
86
|
/**
|
|
@@ -63,7 +92,76 @@ es['recommended'] = {
|
|
|
63
92
|
};
|
|
64
93
|
|
|
65
94
|
export namespace es {
|
|
66
|
-
export interface Options extends PluginOptionsBase<Rules> {
|
|
95
|
+
export interface Options extends PluginOptionsBase<Rules> {
|
|
96
|
+
/**
|
|
97
|
+
* The default restricted globals (used by restrictedGlobals).
|
|
98
|
+
*
|
|
99
|
+
* WARNING: prefer using restrictedGlobals
|
|
100
|
+
*
|
|
101
|
+
* You should use defaultRestrictedGlobals only for eslint shared configuration and should rarely be used in project configuration.
|
|
102
|
+
*
|
|
103
|
+
* @internal
|
|
104
|
+
*/
|
|
105
|
+
defaultRestrictedGlobals?: RestrictedGlobals | undefined;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The default restricted import paths (used by restrictedImportPaths).
|
|
109
|
+
*
|
|
110
|
+
* WARNING: prefer using restrictedImportPaths
|
|
111
|
+
*
|
|
112
|
+
* You should use defaultRestrictedImportPaths only for eslint shared configuration and should rarely be used in project configuration.
|
|
113
|
+
*
|
|
114
|
+
* @internal
|
|
115
|
+
*/
|
|
116
|
+
defaultRestrictedImportPaths?: RestrictedImportPaths | undefined;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* An array of restricted globals to override the default restricted globals.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* // As object
|
|
124
|
+
* {
|
|
125
|
+
* restrictedGlobals: {
|
|
126
|
+
* 'event': 'Please use the event parameter instead of the global event.',
|
|
127
|
+
* }, // Will totally override the default restricted globals
|
|
128
|
+
* }
|
|
129
|
+
* // as function
|
|
130
|
+
* {
|
|
131
|
+
* restrictedGlobals: (currentGlobals) => ({
|
|
132
|
+
* ...currentGlobals,
|
|
133
|
+
* 'event': 'Please use the event parameter instead of the global event.',
|
|
134
|
+
* }), // Allow fine grained control over the default restricted globals, you can filter or add new globals.
|
|
135
|
+
* }
|
|
136
|
+
* ```
|
|
137
|
+
* @see https://eslint.org/docs/latest/rules/no-restricted-globals
|
|
138
|
+
*/
|
|
139
|
+
restrictedGlobals?: ((currentGlobals: Readonly<RestrictedGlobals>) => RestrictedGlobals) | RestrictedGlobals | undefined;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* An array of restricted import paths to override the default restricted import paths.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* // As object
|
|
147
|
+
* {
|
|
148
|
+
* restrictedImportPaths: [
|
|
149
|
+
* { name: 'lodash', message: 'Please use the w5s/lodash wrapper instead.' },
|
|
150
|
+
* { name: 'moment', message: 'Please use the w5s/moment wrapper instead.' },
|
|
151
|
+
* ], // Will totally override the default restricted import paths
|
|
152
|
+
* }
|
|
153
|
+
* // as function
|
|
154
|
+
* {
|
|
155
|
+
* restrictedImportPaths: (currentPaths) => [
|
|
156
|
+
* ...currentPaths.filter((path) => path.name !== 'lodash'),
|
|
157
|
+
* { name: 'moment', message: 'Please use the w5s/moment wrapper instead.' },
|
|
158
|
+
* ], // Allow fine grained control over the default restricted import paths, you can filter or add new paths.
|
|
159
|
+
* }
|
|
160
|
+
* @see https://eslint.org/docs/latest/rules/no-restricted-imports
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
restrictedImportPaths?: ((currentPaths: Readonly<RestrictedImportPaths>) => RestrictedImportPaths) | RestrictedImportPaths | undefined;
|
|
164
|
+
}
|
|
67
165
|
|
|
68
166
|
export type Rules = RuleOptions;
|
|
69
167
|
}
|
package/src/config/imports.ts
CHANGED
package/src/defineConfig.ts
CHANGED
|
@@ -4,49 +4,30 @@ import { ESLintConfig } from '@w5s/dev';
|
|
|
4
4
|
|
|
5
5
|
import type { Config } from './type.js';
|
|
6
6
|
|
|
7
|
-
import
|
|
8
|
-
e18e,
|
|
9
|
-
es,
|
|
10
|
-
ignores,
|
|
11
|
-
imports,
|
|
12
|
-
jsdoc,
|
|
13
|
-
jsonc,
|
|
14
|
-
jsx,
|
|
15
|
-
markdown,
|
|
16
|
-
next,
|
|
17
|
-
node,
|
|
18
|
-
perfectionist,
|
|
19
|
-
react,
|
|
20
|
-
stylistic,
|
|
21
|
-
test,
|
|
22
|
-
ts,
|
|
23
|
-
unicorn,
|
|
24
|
-
unusedImports,
|
|
25
|
-
yml,
|
|
26
|
-
} from './config.js';
|
|
7
|
+
import * as config from './config.js';
|
|
27
8
|
|
|
28
|
-
export interface DefineConfigOptions extends ignores.Options {
|
|
9
|
+
export interface DefineConfigOptions extends config.ignores.Options {
|
|
29
10
|
/**
|
|
30
11
|
* Plugins configuration
|
|
31
12
|
*/
|
|
32
13
|
plugins?: {
|
|
33
|
-
'e18e'?: boolean | e18e.Options;
|
|
34
|
-
'es'?: boolean | es.Options;
|
|
35
|
-
'import'?: boolean | imports.Options;
|
|
36
|
-
'jsdoc'?: boolean | jsdoc.Options;
|
|
37
|
-
'jsonc'?: boolean | jsonc.Options;
|
|
38
|
-
'jsx'?: boolean | jsx.Options;
|
|
39
|
-
'markdown'?: boolean | markdown.Options;
|
|
40
|
-
'next'?: boolean | next.Options;
|
|
41
|
-
'node'?: boolean | node.Options;
|
|
42
|
-
'perfectionist'?: boolean | perfectionist.Options;
|
|
43
|
-
'react'?: boolean | react.Options;
|
|
44
|
-
'stylistic'?: boolean | stylistic.Options;
|
|
45
|
-
'test'?: boolean | test.Options;
|
|
46
|
-
'ts'?: boolean | ts.Options;
|
|
47
|
-
'unicorn'?: boolean | unicorn.Options;
|
|
48
|
-
'unused-imports'?: boolean | unusedImports.Options;
|
|
49
|
-
'yml'?: boolean | yml.Options;
|
|
14
|
+
'e18e'?: boolean | config.e18e.Options | undefined;
|
|
15
|
+
'es'?: boolean | config.es.Options | undefined;
|
|
16
|
+
'import'?: boolean | config.imports.Options | undefined;
|
|
17
|
+
'jsdoc'?: boolean | config.jsdoc.Options | undefined;
|
|
18
|
+
'jsonc'?: boolean | config.jsonc.Options | undefined;
|
|
19
|
+
'jsx'?: boolean | config.jsx.Options | undefined;
|
|
20
|
+
'markdown'?: boolean | config.markdown.Options | undefined;
|
|
21
|
+
'next'?: boolean | config.next.Options | undefined;
|
|
22
|
+
'node'?: boolean | config.node.Options | undefined;
|
|
23
|
+
'perfectionist'?: boolean | config.perfectionist.Options | undefined;
|
|
24
|
+
'react'?: boolean | config.react.Options | undefined;
|
|
25
|
+
'stylistic'?: boolean | config.stylistic.Options | undefined;
|
|
26
|
+
'test'?: boolean | config.test.Options | undefined;
|
|
27
|
+
'ts'?: boolean | config.ts.Options | undefined;
|
|
28
|
+
'unicorn'?: boolean | config.unicorn.Options | undefined;
|
|
29
|
+
'unused-imports'?: boolean | config.unusedImports.Options | undefined;
|
|
30
|
+
'yml'?: boolean | config.yml.Options | undefined;
|
|
50
31
|
};
|
|
51
32
|
|
|
52
33
|
/**
|
|
@@ -55,7 +36,7 @@ export interface DefineConfigOptions extends ignores.Options {
|
|
|
55
36
|
rules?: eslint.Linter.RulesRecord;
|
|
56
37
|
}
|
|
57
38
|
|
|
58
|
-
export async function defineConfig(options: DefineConfigOptions = {}) {
|
|
39
|
+
export async function defineConfig(options: DefineConfigOptions = {}): Promise<Array<Config>> {
|
|
59
40
|
const { plugins = {}, rules } = options;
|
|
60
41
|
const stylisticOptions =
|
|
61
42
|
typeof plugins.stylistic === 'boolean' ? { enabled: plugins.stylistic } : { enabled: true, ...plugins.stylistic };
|
|
@@ -71,29 +52,26 @@ export async function defineConfig(options: DefineConfigOptions = {}) {
|
|
|
71
52
|
? { enabled: defaultEnabled }
|
|
72
53
|
: { enabled: defaultEnabled, ...optionsOrBoolean }) as T & { enabled: boolean },
|
|
73
54
|
);
|
|
74
|
-
const includeEnabled = <T extends { enabled?: boolean }, R extends Promise<ReadonlyArray<Config>>>(factory: (config: T) => R, input: T) =>
|
|
55
|
+
const includeEnabled = <T extends { enabled?: boolean | undefined }, R extends Promise<ReadonlyArray<Config>>>(factory: (config: T) => R, input: T) =>
|
|
75
56
|
input.enabled ? [factory(input)] : [];
|
|
76
57
|
|
|
77
|
-
return ESLintConfig.concat(
|
|
78
|
-
|
|
79
|
-
...includeEnabled(
|
|
80
|
-
|
|
81
|
-
//
|
|
82
|
-
...includeEnabled(
|
|
83
|
-
...includeEnabled(
|
|
84
|
-
|
|
85
|
-
...includeEnabled(
|
|
86
|
-
...includeEnabled(
|
|
87
|
-
...includeEnabled(
|
|
88
|
-
...includeEnabled(
|
|
89
|
-
...includeEnabled(
|
|
90
|
-
...includeEnabled(
|
|
91
|
-
...includeEnabled(
|
|
92
|
-
...includeEnabled(
|
|
93
|
-
...includeEnabled(
|
|
94
|
-
...includeEnabled(unicorn, toOption(plugins.unicorn)),
|
|
95
|
-
...includeEnabled(yml, toOption(plugins.yml)),
|
|
96
|
-
...includeEnabled(test, toOption(plugins.test)),
|
|
58
|
+
return ESLintConfig.concat<Config>(
|
|
59
|
+
// ignore files
|
|
60
|
+
...includeEnabled(config.ignores, toOption(options)),
|
|
61
|
+
|
|
62
|
+
// js and ts
|
|
63
|
+
...includeEnabled(config.es, toOption(plugins.es)),
|
|
64
|
+
...includeEnabled(config.ts, toOption(plugins.ts)),
|
|
65
|
+
// js and ts extensions
|
|
66
|
+
...includeEnabled(config.e18e, toOption(plugins.e18e)),
|
|
67
|
+
...includeEnabled(config.unusedImports, toOption(plugins['unused-imports'])),
|
|
68
|
+
...includeEnabled(config.imports, toOption(plugins.import)),
|
|
69
|
+
...includeEnabled(config.perfectionist, toOption(plugins.perfectionist)),
|
|
70
|
+
...includeEnabled(config.node, toOption(plugins.node)),
|
|
71
|
+
...includeEnabled(config.next, toOption(plugins.next, false)),
|
|
72
|
+
...includeEnabled(config.react, toOption(plugins.react)),
|
|
73
|
+
...includeEnabled(config.unicorn, toOption(plugins.unicorn)),
|
|
74
|
+
...includeEnabled(config.test, toOption(plugins.test)),
|
|
97
75
|
...(rules ? [{ rules }] : []),
|
|
98
76
|
);
|
|
99
77
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './config.js';
|
|
2
2
|
export * from './defineConfig.js';
|
|
3
|
-
export { defineConfig as default } from './defineConfig.js';
|
|
4
3
|
export * from './meta.js';
|
|
4
|
+
export * from './restrictedGlobals.js';
|
|
5
|
+
export * from './restrictedImportPaths.js';
|
|
5
6
|
export * from './type.js';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { RestrictedGlobals } from './type.js';
|
|
2
|
+
|
|
3
|
+
export const restrictedGlobals: Readonly<RestrictedGlobals> = Object.freeze([
|
|
4
|
+
// List of restricted globals
|
|
5
|
+
{
|
|
6
|
+
message:
|
|
7
|
+
'Use Number.isFinite instead https://github.com/airbnb/javascript#standard-library--isfinite',
|
|
8
|
+
name: 'isFinite',
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
message:
|
|
12
|
+
'Use Number.isNaN instead https://github.com/airbnb/javascript#standard-library--isnan',
|
|
13
|
+
name: 'isNaN',
|
|
14
|
+
},
|
|
15
|
+
]);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { RestrictedImportPaths } from './type.js';
|
|
2
|
+
/* eslint-disable perfectionist/sort-objects */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This file contains the list of restricted import paths used in the ESLint configuration.
|
|
6
|
+
*/
|
|
7
|
+
export const restrictedImportPaths: Readonly<RestrictedImportPaths> = Object.freeze([
|
|
8
|
+
// List of restricted import
|
|
9
|
+
{ name: 'moment', message: 'Use Temporal, date-fns, or luxon.' },
|
|
10
|
+
{ name: 'jquery', message: 'Use native DOM APIs.' },
|
|
11
|
+
{ name: 'underscore', message: 'Use native APIs or es-toolkit.' },
|
|
12
|
+
{ name: 'bluebird', message: 'Use native Promise.' },
|
|
13
|
+
{ name: 'request', message: 'Use fetch or undici.' },
|
|
14
|
+
{ name: 'request-promise', message: 'Use fetch or undici.' },
|
|
15
|
+
{ name: 'node-fetch', message: 'Use global fetch (Node 18+).' },
|
|
16
|
+
{ name: 'isomorphic-fetch', message: 'Use global fetch.' },
|
|
17
|
+
{ name: 'whatwg-fetch', message: 'Use global fetch.' },
|
|
18
|
+
{ name: 'rxjs/Rx', message: 'Import from "rxjs" or "rxjs/operators".' },
|
|
19
|
+
]);
|
|
@@ -11,6 +11,7 @@ export const overrides = () => ({
|
|
|
11
11
|
'no-nested-ternary': 'off',
|
|
12
12
|
// Too strict, for pure code prefer the functional plugin
|
|
13
13
|
'no-param-reassign': ['error', { props: false }],
|
|
14
|
+
|
|
14
15
|
// Allow for-of syntax
|
|
15
16
|
// 'no-restricted-syntax': baseConfig.rules['no-restricted-syntax'].filter(
|
|
16
17
|
// // @ts-ignore No typing available
|
|
@@ -24,5 +25,4 @@ export const overrides = () => ({
|
|
|
24
25
|
'no-use-before-define': ['error', 'nofunc'],
|
|
25
26
|
// Allow statements, to be compatible with '@typescript-eslint/no-floating-promises' fix
|
|
26
27
|
'no-void': ['error', { allowAsStatement: true }],
|
|
27
|
-
// 'unicode-bom': ['error', 'never'],
|
|
28
28
|
} satisfies Linter.RulesRecord);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Linter } from 'eslint';
|
|
2
|
+
import type { ESLintRules } from 'eslint/rules';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This file contains the type definition for restricted globals used in the ESLint configuration.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export type RestrictedGlobals = Array<NonNullable<
|
|
9
|
+
ESLintRules['no-restricted-globals'] extends Linter.RuleEntry<infer O>
|
|
10
|
+
? O[number]
|
|
11
|
+
: never
|
|
12
|
+
>>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Linter } from 'eslint';
|
|
2
|
+
import type { ESLintRules } from 'eslint/rules';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This file contains the type definition for restricted import paths used in the ESLint configuration.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export type RestrictedImportPaths = NonNullable<
|
|
9
|
+
Extract<
|
|
10
|
+
ESLintRules['no-restricted-imports'] extends Linter.RuleEntry<infer O>
|
|
11
|
+
? O[number]
|
|
12
|
+
: never,
|
|
13
|
+
{ paths?: unknown }
|
|
14
|
+
>['paths']
|
|
15
|
+
>;
|