@open-xchange/linter-presets 0.1.5 → 0.1.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.
- package/CHANGELOG.md +5 -0
- package/dist/eslint/env/browser.d.ts +2 -2
- package/dist/eslint/env/browser.js +5 -5
- package/dist/eslint/env/codecept.d.ts +2 -2
- package/dist/eslint/env/codecept.js +5 -5
- package/dist/eslint/env/eslint.d.ts +2 -2
- package/dist/eslint/env/eslint.js +4 -4
- package/dist/eslint/env/jest.d.ts +2 -2
- package/dist/eslint/env/jest.js +5 -5
- package/dist/eslint/env/node.d.ts +2 -2
- package/dist/eslint/env/node.js +6 -6
- package/dist/eslint/env/project.d.ts +7 -3
- package/dist/eslint/env/project.js +5 -5
- package/dist/eslint/env/react.d.ts +2 -2
- package/dist/eslint/env/react.js +8 -8
- package/dist/eslint/env/tsconfig.d.ts +2 -2
- package/dist/eslint/env/tsconfig.js +5 -5
- package/dist/eslint/env/vitest.d.ts +2 -2
- package/dist/eslint/env/vitest.js +6 -6
- package/dist/eslint/rules/no-invalid-modules.js +5 -5
- package/dist/eslint/shared/env-utils.d.ts +15 -15
- package/dist/eslint/shared/env-utils.js +22 -22
- package/doc/eslint/env/project.md +26 -19
- package/package.json +5 -4
- package/test/src/project1/file1.js +26 -0
- package/test/src/project2/file2.js +2 -0
- package/test/src/project3/file3.js +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -13,10 +13,10 @@ export interface EnvBrowserOptions extends EnvRestrictedOptions {
|
|
|
13
13
|
* - `globals`
|
|
14
14
|
* - `confusing-browser-globals`
|
|
15
15
|
*
|
|
16
|
-
* @param
|
|
16
|
+
* @param envOptions
|
|
17
17
|
* Configuration options for the environment.
|
|
18
18
|
*
|
|
19
19
|
* @returns
|
|
20
20
|
* An array of configuration objects to be added to the flat configuration.
|
|
21
21
|
*/
|
|
22
|
-
export default function browser(
|
|
22
|
+
export default function browser(envOptions: EnvBrowserOptions): TSESLint.FlatConfig.ConfigArray;
|
|
@@ -84,26 +84,26 @@ const RESTRICTED_GLOBALS = AMBIGUOUS_BROWSER_TYPES.map(name => {
|
|
|
84
84
|
* - `globals`
|
|
85
85
|
* - `confusing-browser-globals`
|
|
86
86
|
*
|
|
87
|
-
* @param
|
|
87
|
+
* @param envOptions
|
|
88
88
|
* Configuration options for the environment.
|
|
89
89
|
*
|
|
90
90
|
* @returns
|
|
91
91
|
* An array of configuration objects to be added to the flat configuration.
|
|
92
92
|
*/
|
|
93
|
-
export default function browser(
|
|
93
|
+
export default function browser(envOptions) {
|
|
94
94
|
return concatConfigs(
|
|
95
95
|
// register global symbols used in browser scripts
|
|
96
|
-
createConfig(
|
|
96
|
+
createConfig(envOptions, {
|
|
97
97
|
languageOptions: {
|
|
98
98
|
globals: BROWSER_GLOBALS,
|
|
99
99
|
},
|
|
100
100
|
}),
|
|
101
101
|
// generate the "no-restricted-?" rules according to passed configuration
|
|
102
|
-
restrictedRules(
|
|
102
|
+
restrictedRules(envOptions, {
|
|
103
103
|
globals: RESTRICTED_GLOBALS,
|
|
104
104
|
properties: RESTRICTED_PROPERTIES,
|
|
105
105
|
syntax: RESTRICTED_SYNTAX,
|
|
106
106
|
}),
|
|
107
107
|
// custom rules
|
|
108
|
-
customRules(
|
|
108
|
+
customRules(envOptions));
|
|
109
109
|
}
|
|
@@ -13,10 +13,10 @@ export interface EnvCodeceptOptions extends EnvBaseOptions {
|
|
|
13
13
|
* - `eslint-plugin-codeceptjs`
|
|
14
14
|
* - `eslint-plugin-chai-expect`
|
|
15
15
|
*
|
|
16
|
-
* @param
|
|
16
|
+
* @param envOptions
|
|
17
17
|
* Configuration options for the environment.
|
|
18
18
|
*
|
|
19
19
|
* @returns
|
|
20
20
|
* An array of configuration objects to be added to the flat configuration.
|
|
21
21
|
*/
|
|
22
|
-
export default function codecept(
|
|
22
|
+
export default function codecept(envOptions: EnvCodeceptOptions): TSESLint.FlatConfig.ConfigArray;
|
|
@@ -16,16 +16,16 @@ import { concatConfigs, createConfig, customRules } from "../shared/env-utils.js
|
|
|
16
16
|
* - `eslint-plugin-codeceptjs`
|
|
17
17
|
* - `eslint-plugin-chai-expect`
|
|
18
18
|
*
|
|
19
|
-
* @param
|
|
19
|
+
* @param envOptions
|
|
20
20
|
* Configuration options for the environment.
|
|
21
21
|
*
|
|
22
22
|
* @returns
|
|
23
23
|
* An array of configuration objects to be added to the flat configuration.
|
|
24
24
|
*/
|
|
25
|
-
export default function codecept(
|
|
25
|
+
export default function codecept(envOptions) {
|
|
26
26
|
return concatConfigs(
|
|
27
27
|
// "codecept" plugin
|
|
28
|
-
createConfig(
|
|
28
|
+
createConfig(envOptions, {
|
|
29
29
|
// register rule implementations of the plugins
|
|
30
30
|
plugins: {
|
|
31
31
|
codeceptjs: codeceptPlugin,
|
|
@@ -38,9 +38,9 @@ export default function codecept(options) {
|
|
|
38
38
|
rules: codeceptPlugin.configs.recommended.rules,
|
|
39
39
|
}),
|
|
40
40
|
// "chai-expect" plugin
|
|
41
|
-
createConfig(
|
|
41
|
+
createConfig(envOptions, chaiExpectPlugin.configs["recommended-flat"]),
|
|
42
42
|
// custom rules
|
|
43
|
-
customRules(
|
|
43
|
+
customRules(envOptions, {
|
|
44
44
|
"new-cap": ["error", {
|
|
45
45
|
capIsNewExceptions: ["After", "AfterSuite", "Before", "BeforeSuite", "Feature", "Scenario"],
|
|
46
46
|
}],
|
|
@@ -11,10 +11,10 @@ export interface EnvEslintOptions extends EnvBaseOptions {
|
|
|
11
11
|
* Wraps the following packages:
|
|
12
12
|
* - `eslint-plugin-eslint-plugin`
|
|
13
13
|
*
|
|
14
|
-
* @param
|
|
14
|
+
* @param envOptions
|
|
15
15
|
* Configuration options for the environment.
|
|
16
16
|
*
|
|
17
17
|
* @returns
|
|
18
18
|
* An array of configuration objects to be added to the flat configuration.
|
|
19
19
|
*/
|
|
20
|
-
export default function eslint(
|
|
20
|
+
export default function eslint(envOptions: EnvEslintOptions): TSESLint.FlatConfig.ConfigArray;
|
|
@@ -7,16 +7,16 @@ import { concatConfigs, createConfig, customRules } from "../shared/env-utils.js
|
|
|
7
7
|
* Wraps the following packages:
|
|
8
8
|
* - `eslint-plugin-eslint-plugin`
|
|
9
9
|
*
|
|
10
|
-
* @param
|
|
10
|
+
* @param envOptions
|
|
11
11
|
* Configuration options for the environment.
|
|
12
12
|
*
|
|
13
13
|
* @returns
|
|
14
14
|
* An array of configuration objects to be added to the flat configuration.
|
|
15
15
|
*/
|
|
16
|
-
export default function eslint(
|
|
16
|
+
export default function eslint(envOptions) {
|
|
17
17
|
return concatConfigs(
|
|
18
18
|
// register rule implementations and recommended rules
|
|
19
|
-
createConfig(
|
|
19
|
+
createConfig(envOptions, eslintPlugin.configs["flat/rules-recommended"]),
|
|
20
20
|
// custom rules
|
|
21
|
-
customRules(
|
|
21
|
+
customRules(envOptions));
|
|
22
22
|
}
|
|
@@ -12,10 +12,10 @@ export interface EnvJestOptions extends EnvBaseOptions {
|
|
|
12
12
|
* Wraps the following packages:
|
|
13
13
|
* - `eslint-plugin-jest`
|
|
14
14
|
*
|
|
15
|
-
* @param
|
|
15
|
+
* @param envOptions
|
|
16
16
|
* Configuration options for the environment.
|
|
17
17
|
*
|
|
18
18
|
* @returns
|
|
19
19
|
* An array of configuration objects to be added to the flat configuration.
|
|
20
20
|
*/
|
|
21
|
-
export default function jest(
|
|
21
|
+
export default function jest(envOptions: EnvJestOptions): TSESLint.FlatConfig.ConfigArray;
|
package/dist/eslint/env/jest.js
CHANGED
|
@@ -8,22 +8,22 @@ import { concatConfigs, createConfig, customRules } from "../shared/env-utils.js
|
|
|
8
8
|
* Wraps the following packages:
|
|
9
9
|
* - `eslint-plugin-jest`
|
|
10
10
|
*
|
|
11
|
-
* @param
|
|
11
|
+
* @param envOptions
|
|
12
12
|
* Configuration options for the environment.
|
|
13
13
|
*
|
|
14
14
|
* @returns
|
|
15
15
|
* An array of configuration objects to be added to the flat configuration.
|
|
16
16
|
*/
|
|
17
|
-
export default function jest(
|
|
17
|
+
export default function jest(envOptions) {
|
|
18
18
|
return concatConfigs(
|
|
19
19
|
// register rule implementations, globals, and recommended rules
|
|
20
|
-
createConfig(
|
|
20
|
+
createConfig(envOptions, jestPlugin.configs["flat/recommended"]),
|
|
21
21
|
// add recommended stylistic rules
|
|
22
|
-
createConfig(
|
|
22
|
+
createConfig(envOptions, {
|
|
23
23
|
rules: jestPlugin.configs["flat/style"].rules,
|
|
24
24
|
}),
|
|
25
25
|
// custom rules
|
|
26
|
-
customRules(
|
|
26
|
+
customRules(envOptions, {
|
|
27
27
|
"jest/consistent-test-it": ["error", { fn: "it" }],
|
|
28
28
|
"jest/no-commented-out-tests": "error",
|
|
29
29
|
"jest/no-conditional-expect": "off",
|
|
@@ -16,10 +16,10 @@ export interface EnvNodeOptions extends EnvRestrictedOptions {
|
|
|
16
16
|
* Wraps the following packages:
|
|
17
17
|
* - `eslint-plugin-n`
|
|
18
18
|
*
|
|
19
|
-
* @param
|
|
19
|
+
* @param envOptions
|
|
20
20
|
* Configuration options for the environment.
|
|
21
21
|
*
|
|
22
22
|
* @returns
|
|
23
23
|
* An array of configuration objects to be added to the flat configuration.
|
|
24
24
|
*/
|
|
25
|
-
export default function node(
|
|
25
|
+
export default function node(envOptions: EnvNodeOptions): TSESLint.FlatConfig.ConfigArray;
|
package/dist/eslint/env/node.js
CHANGED
|
@@ -8,18 +8,18 @@ import { concatConfigs, createConfig, restrictedRules, customRules } from "../sh
|
|
|
8
8
|
* Wraps the following packages:
|
|
9
9
|
* - `eslint-plugin-n`
|
|
10
10
|
*
|
|
11
|
-
* @param
|
|
11
|
+
* @param envOptions
|
|
12
12
|
* Configuration options for the environment.
|
|
13
13
|
*
|
|
14
14
|
* @returns
|
|
15
15
|
* An array of configuration objects to be added to the flat configuration.
|
|
16
16
|
*/
|
|
17
|
-
export default function node(
|
|
17
|
+
export default function node(envOptions) {
|
|
18
18
|
// the plugin configuration key, according to source module type
|
|
19
|
-
const configKey = (
|
|
19
|
+
const configKey = (envOptions.sourceType === "commonjs") ? "flat/recommended-script" : "flat/recommended-module";
|
|
20
20
|
return concatConfigs(
|
|
21
21
|
// register rule implementations
|
|
22
|
-
createConfig(
|
|
22
|
+
createConfig(envOptions, {
|
|
23
23
|
...nodePlugin.configs[configKey],
|
|
24
24
|
settings: {
|
|
25
25
|
node: {
|
|
@@ -28,9 +28,9 @@ export default function node(options) {
|
|
|
28
28
|
},
|
|
29
29
|
}),
|
|
30
30
|
// generate the "no-restricted-?" rules according to passed configuration
|
|
31
|
-
restrictedRules(
|
|
31
|
+
restrictedRules(envOptions),
|
|
32
32
|
// custom rules
|
|
33
|
-
customRules(
|
|
33
|
+
customRules(envOptions, {
|
|
34
34
|
"n/no-unsupported-features/node-builtins": ["error", { allowExperimental: true }],
|
|
35
35
|
"n/prefer-node-protocol": "error",
|
|
36
36
|
}));
|
|
@@ -4,15 +4,19 @@ import { type RuleNoInvalidModulesOptions } from "../rules/no-invalid-modules.js
|
|
|
4
4
|
/**
|
|
5
5
|
* Configuration options for the environment preset "env.project".
|
|
6
6
|
*/
|
|
7
|
-
export interface EnvProjectOptions extends EnvBaseOptions
|
|
7
|
+
export interface EnvProjectOptions extends EnvBaseOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Options to be passed to the rule "env-project/no-invalid-modules".
|
|
10
|
+
*/
|
|
11
|
+
modules?: RuleNoInvalidModulesOptions;
|
|
8
12
|
}
|
|
9
13
|
/**
|
|
10
14
|
* Adds custom linter rules for checking project setup and module hierarchy.
|
|
11
15
|
*
|
|
12
|
-
* @param
|
|
16
|
+
* @param envOptions
|
|
13
17
|
* Configuration options for the environment.
|
|
14
18
|
*
|
|
15
19
|
* @returns
|
|
16
20
|
* An array of configuration objects to be added to the flat configuration.
|
|
17
21
|
*/
|
|
18
|
-
export default function project(
|
|
22
|
+
export default function project(envOptions: EnvProjectOptions): TSESLint.FlatConfig.ConfigArray;
|
|
@@ -5,16 +5,16 @@ import noInvalidModules from "../rules/no-invalid-modules.js";
|
|
|
5
5
|
/**
|
|
6
6
|
* Adds custom linter rules for checking project setup and module hierarchy.
|
|
7
7
|
*
|
|
8
|
-
* @param
|
|
8
|
+
* @param envOptions
|
|
9
9
|
* Configuration options for the environment.
|
|
10
10
|
*
|
|
11
11
|
* @returns
|
|
12
12
|
* An array of configuration objects to be added to the flat configuration.
|
|
13
13
|
*/
|
|
14
|
-
export default function project(
|
|
14
|
+
export default function project(envOptions) {
|
|
15
15
|
return concatConfigs(
|
|
16
16
|
// register rule implementations
|
|
17
|
-
createConfig(
|
|
17
|
+
createConfig(envOptions, {
|
|
18
18
|
plugins: {
|
|
19
19
|
"env-project": {
|
|
20
20
|
rules: {
|
|
@@ -25,8 +25,8 @@ export default function project(options) {
|
|
|
25
25
|
},
|
|
26
26
|
}),
|
|
27
27
|
// custom rules
|
|
28
|
-
customRules(
|
|
28
|
+
customRules(envOptions, {
|
|
29
29
|
"env-project/no-amd-module-directive": "error",
|
|
30
|
-
"env-project/no-invalid-modules": ["error",
|
|
30
|
+
"env-project/no-invalid-modules": ["error", envOptions.modules ?? {}],
|
|
31
31
|
}));
|
|
32
32
|
}
|
|
@@ -20,10 +20,10 @@ export interface EnvReactOptions extends EnvBaseOptions {
|
|
|
20
20
|
* - `eslint-plugin-jsx-expressions`
|
|
21
21
|
* - `eslint-plugin-jsx-a11y`
|
|
22
22
|
*
|
|
23
|
-
* @param
|
|
23
|
+
* @param envOptions
|
|
24
24
|
* Configuration options for the environment.
|
|
25
25
|
*
|
|
26
26
|
* @returns
|
|
27
27
|
* An array of configuration objects to be added to the flat configuration.
|
|
28
28
|
*/
|
|
29
|
-
export default function react(
|
|
29
|
+
export default function react(envOptions: EnvReactOptions): TSESLint.FlatConfig.ConfigArray;
|
package/dist/eslint/env/react.js
CHANGED
|
@@ -18,16 +18,16 @@ import { concatConfigs, createConfig, customRules } from "../shared/env-utils.js
|
|
|
18
18
|
* - `eslint-plugin-jsx-expressions`
|
|
19
19
|
* - `eslint-plugin-jsx-a11y`
|
|
20
20
|
*
|
|
21
|
-
* @param
|
|
21
|
+
* @param envOptions
|
|
22
22
|
* Configuration options for the environment.
|
|
23
23
|
*
|
|
24
24
|
* @returns
|
|
25
25
|
* An array of configuration objects to be added to the flat configuration.
|
|
26
26
|
*/
|
|
27
|
-
export default function react(
|
|
27
|
+
export default function react(envOptions) {
|
|
28
28
|
return concatConfigs(
|
|
29
29
|
// configure "react" plugin for all source files (JSX and TSX)
|
|
30
|
-
createConfig(
|
|
30
|
+
createConfig(envOptions, {
|
|
31
31
|
// auto-detect installed React version
|
|
32
32
|
settings: {
|
|
33
33
|
react: {
|
|
@@ -43,7 +43,7 @@ export default function react(options) {
|
|
|
43
43
|
},
|
|
44
44
|
}),
|
|
45
45
|
// configure other plugins and rules for all source files (JSX and TSX)
|
|
46
|
-
createConfig(
|
|
46
|
+
createConfig(envOptions, {
|
|
47
47
|
// register rule implementations of the plugins
|
|
48
48
|
plugins: {
|
|
49
49
|
"react-hooks": reactHooksPlugin,
|
|
@@ -58,17 +58,17 @@ export default function react(options) {
|
|
|
58
58
|
},
|
|
59
59
|
}),
|
|
60
60
|
// "react-hooks-static-deps" plugin
|
|
61
|
-
|
|
61
|
+
envOptions.staticHooks && createConfig(envOptions, {
|
|
62
62
|
plugins: {
|
|
63
63
|
"react-hooks-static-deps": fixupPluginRules(reactHooksStaticDepsPlugin), // https://github.com/stoikio/eslint-plugin-react-hooks-static-deps/issues/1
|
|
64
64
|
},
|
|
65
65
|
rules: {
|
|
66
66
|
"react-hooks/exhaustive-deps": "off",
|
|
67
|
-
"react-hooks-static-deps/exhaustive-deps": ["error", { staticHooks:
|
|
67
|
+
"react-hooks-static-deps/exhaustive-deps": ["error", { staticHooks: envOptions.staticHooks }],
|
|
68
68
|
},
|
|
69
69
|
}),
|
|
70
70
|
// additional rules for TSX only
|
|
71
|
-
createConfig(
|
|
71
|
+
createConfig(envOptions, {
|
|
72
72
|
ignores: ["**/*.{js,jsx}"],
|
|
73
73
|
rules: {
|
|
74
74
|
// replace "react/jsx-no-leaked-render" rule with advanced alternative
|
|
@@ -76,7 +76,7 @@ export default function react(options) {
|
|
|
76
76
|
},
|
|
77
77
|
}),
|
|
78
78
|
// custom rules
|
|
79
|
-
customRules(
|
|
79
|
+
customRules(envOptions, {
|
|
80
80
|
// "react" plugin
|
|
81
81
|
"react/hook-use-state": "error",
|
|
82
82
|
"react/iframe-missing-sandbox": "error",
|
|
@@ -12,10 +12,10 @@ export interface EnvTSConfigOptions extends EnvBaseOptions {
|
|
|
12
12
|
/**
|
|
13
13
|
* Creates configuration objects for TypeScript projects.
|
|
14
14
|
*
|
|
15
|
-
* @param
|
|
15
|
+
* @param envOptions
|
|
16
16
|
* Configuration options for the environment.
|
|
17
17
|
*
|
|
18
18
|
* @returns
|
|
19
19
|
* An array of configuration objects to be added to the flat configuration.
|
|
20
20
|
*/
|
|
21
|
-
export default function tsconfig(
|
|
21
|
+
export default function tsconfig(envOptions: EnvTSConfigOptions): TSESLint.FlatConfig.ConfigArray;
|
|
@@ -3,22 +3,22 @@ import { concatConfigs, createConfig, customRules } from "../shared/env-utils.js
|
|
|
3
3
|
/**
|
|
4
4
|
* Creates configuration objects for TypeScript projects.
|
|
5
5
|
*
|
|
6
|
-
* @param
|
|
6
|
+
* @param envOptions
|
|
7
7
|
* Configuration options for the environment.
|
|
8
8
|
*
|
|
9
9
|
* @returns
|
|
10
10
|
* An array of configuration objects to be added to the flat configuration.
|
|
11
11
|
*/
|
|
12
|
-
export default function tsconfig(
|
|
12
|
+
export default function tsconfig(envOptions) {
|
|
13
13
|
return concatConfigs(
|
|
14
14
|
// path to project configuration file
|
|
15
|
-
createConfig(
|
|
15
|
+
createConfig(envOptions, {
|
|
16
16
|
languageOptions: {
|
|
17
17
|
parserOptions: {
|
|
18
|
-
project:
|
|
18
|
+
project: envOptions.project,
|
|
19
19
|
},
|
|
20
20
|
},
|
|
21
21
|
}),
|
|
22
22
|
// custom rules
|
|
23
|
-
customRules(
|
|
23
|
+
customRules(envOptions));
|
|
24
24
|
}
|
|
@@ -14,10 +14,10 @@ export interface EnvVitestOptions extends EnvBaseOptions {
|
|
|
14
14
|
* - `eslint-plugin-jest-dom`
|
|
15
15
|
* - `eslint-plugin-testing-library`
|
|
16
16
|
*
|
|
17
|
-
* @param
|
|
17
|
+
* @param envOptions
|
|
18
18
|
* Configuration options for the environment.
|
|
19
19
|
*
|
|
20
20
|
* @returns
|
|
21
21
|
* An array of configuration objects to be added to the flat configuration.
|
|
22
22
|
*/
|
|
23
|
-
export default function vitest(
|
|
23
|
+
export default function vitest(envOptions: EnvVitestOptions): TSESLint.FlatConfig.ConfigArray;
|
|
@@ -13,16 +13,16 @@ import { concatConfigs, createConfig, customRules } from "../shared/env-utils.js
|
|
|
13
13
|
* - `eslint-plugin-jest-dom`
|
|
14
14
|
* - `eslint-plugin-testing-library`
|
|
15
15
|
*
|
|
16
|
-
* @param
|
|
16
|
+
* @param envOptions
|
|
17
17
|
* Configuration options for the environment.
|
|
18
18
|
*
|
|
19
19
|
* @returns
|
|
20
20
|
* An array of configuration objects to be added to the flat configuration.
|
|
21
21
|
*/
|
|
22
|
-
export default function vitest(
|
|
22
|
+
export default function vitest(envOptions) {
|
|
23
23
|
return concatConfigs(
|
|
24
24
|
// "vitest" plugin
|
|
25
|
-
createConfig(
|
|
25
|
+
createConfig(envOptions, {
|
|
26
26
|
// register rule implementations of the plugins
|
|
27
27
|
plugins: {
|
|
28
28
|
vitest: vitestPlugin,
|
|
@@ -35,9 +35,9 @@ export default function vitest(options) {
|
|
|
35
35
|
rules: vitestPlugin.configs.recommended.rules,
|
|
36
36
|
}),
|
|
37
37
|
// "jest-dom" plugin
|
|
38
|
-
createConfig(
|
|
38
|
+
createConfig(envOptions, jestDomPlugin.configs["flat/recommended"]),
|
|
39
39
|
// "testing-library" plugin
|
|
40
|
-
createConfig(
|
|
40
|
+
createConfig(envOptions, {
|
|
41
41
|
// register rule implementations of the plugins
|
|
42
42
|
plugins: {
|
|
43
43
|
"testing-library": fixupPluginRules(testingLibraryPlugin), // https://github.com/testing-library/eslint-plugin-testing-library/issues/899
|
|
@@ -46,7 +46,7 @@ export default function vitest(options) {
|
|
|
46
46
|
rules: testingLibraryPlugin.configs.react.rules,
|
|
47
47
|
}),
|
|
48
48
|
// custom rules
|
|
49
|
-
customRules(
|
|
49
|
+
customRules(envOptions, {
|
|
50
50
|
// "vitest" plugin
|
|
51
51
|
"vitest/consistent-test-it": "error",
|
|
52
52
|
"vitest/no-alias-methods": "error",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import { posix, dirname, extname } from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import { findUpSync } from "find-up";
|
|
4
4
|
import { AST_NODE_TYPES as NodeType, ESLintUtils } from "@typescript-eslint/utils";
|
|
5
5
|
import { Schema, makeArray, toPosixPath, isFile, matchModuleName, getModuleName } from "../shared/rule-utils.js";
|
|
6
6
|
// constants ==================================================================
|
|
@@ -47,8 +47,8 @@ export default ESLintUtils.RuleCreator.withoutDocs({
|
|
|
47
47
|
// collect all globs for package members
|
|
48
48
|
const packagesGlobs = Array.from(packagesMap.values(), settings => settings.src).flat();
|
|
49
49
|
// resolve file name
|
|
50
|
-
const
|
|
51
|
-
const rootDir =
|
|
50
|
+
const configPath = findUpSync("eslint.config.js");
|
|
51
|
+
const rootDir = configPath && toPosixPath(dirname(configPath));
|
|
52
52
|
const fileName = toPosixPath(context.filename);
|
|
53
53
|
if (!rootDir || !fileName.startsWith(rootDir + "/")) {
|
|
54
54
|
throw new Error("invalid root directory");
|
|
@@ -86,7 +86,7 @@ export default ESLintUtils.RuleCreator.withoutDocs({
|
|
|
86
86
|
return FILE_EXTENSIONS.some(ext => isFile(resolvedPath + "." + ext));
|
|
87
87
|
};
|
|
88
88
|
// returns whether the passed module name is an installed NPM package
|
|
89
|
-
const requireModule = createRequire(
|
|
89
|
+
const requireModule = createRequire(configPath);
|
|
90
90
|
const packageExists = (moduleName) => {
|
|
91
91
|
try {
|
|
92
92
|
requireModule.resolve(moduleName);
|
|
@@ -110,7 +110,7 @@ export default ESLintUtils.RuleCreator.withoutDocs({
|
|
|
110
110
|
// extract alias key, replace with alias path
|
|
111
111
|
const [aliasKey, modulePath] = resolveAlias(moduleName);
|
|
112
112
|
// whether the import is a known external module
|
|
113
|
-
const isExternal =
|
|
113
|
+
const isExternal = matchModuleName(moduleName, options.external);
|
|
114
114
|
// whether the import is an installed NPM package
|
|
115
115
|
const isPackage = !isExternal && !aliasKey && packageExists(moduleName);
|
|
116
116
|
// check existence of source file
|
|
@@ -181,24 +181,23 @@ export declare const NO_UNUSED_VARS_OPTIONS: {
|
|
|
181
181
|
export declare const concatConfigs: (...entries: (TSESLint.FlatConfig.Config | TSESLint.FlatConfig.Config[] | undefined)[]) => TSESLint.FlatConfig.Config[];
|
|
182
182
|
/**
|
|
183
183
|
* Creates a flat configuration object with "files" and "ignores" settings from
|
|
184
|
-
* an environment's "
|
|
184
|
+
* an environment's "envOptions" object.
|
|
185
185
|
*
|
|
186
|
-
* @param
|
|
186
|
+
* @param envOptions
|
|
187
187
|
* The environment options containing "files" and "ignores" settings.
|
|
188
188
|
*
|
|
189
|
-
* @param
|
|
190
|
-
*
|
|
191
|
-
* "
|
|
192
|
-
* "options".
|
|
189
|
+
* @param flatConfig
|
|
190
|
+
* Properties for the flat configuration to be built. Additional "files" and
|
|
191
|
+
* "ignores" properties will be merged with the settings from "envOptions".
|
|
193
192
|
*
|
|
194
193
|
* @returns
|
|
195
194
|
* The resulting flat configuration object.
|
|
196
195
|
*/
|
|
197
|
-
export declare function createConfig(
|
|
196
|
+
export declare function createConfig(envOptions: EnvFilesOptions, flatConfig: TSESLint.FlatConfig.Config): TSESLint.FlatConfig.Config;
|
|
198
197
|
/**
|
|
199
198
|
* Generates various "no-restricted-?" rules from the passed configuration.
|
|
200
199
|
*
|
|
201
|
-
* @param
|
|
200
|
+
* @param envOptions
|
|
202
201
|
* The environment options containing "files", "ignores", and "restricted"
|
|
203
202
|
* settings.
|
|
204
203
|
*
|
|
@@ -208,21 +207,22 @@ export declare function createConfig(options: EnvFilesOptions, config: TSESLint.
|
|
|
208
207
|
* @returns
|
|
209
208
|
* The flat configuration objects needed to forbid the restricted items.
|
|
210
209
|
*/
|
|
211
|
-
export declare function restrictedRules(
|
|
210
|
+
export declare function restrictedRules(envOptions: EnvRestrictedOptions, fixed?: EnvRestrictedItems): TSESLint.FlatConfig.ConfigArray;
|
|
212
211
|
/**
|
|
213
|
-
* Creates a flat configuration object with
|
|
214
|
-
* settings from an environment's
|
|
212
|
+
* Creates a flat configuration object with "files", "ignores", and "rules"
|
|
213
|
+
* settings from an environment's "envOptions" object.
|
|
215
214
|
*
|
|
216
|
-
* @param
|
|
217
|
-
* The environment options containing
|
|
215
|
+
* @param envOptions
|
|
216
|
+
* The environment options containing "files", "ignores", and "rules"
|
|
217
|
+
* settings.
|
|
218
218
|
*
|
|
219
219
|
* @param rules
|
|
220
220
|
* Hard-coded rule settings to be configured by the environment itself. These
|
|
221
|
-
* rule settings will precede the rules contained in "
|
|
221
|
+
* rule settings will precede the rules contained in "envOptions", in order to
|
|
222
222
|
* allow to override them.
|
|
223
223
|
*
|
|
224
224
|
* @returns
|
|
225
225
|
* The resulting flat configuration object, if the environment options contain
|
|
226
226
|
* custom rule settings, otherwise `undefined`.
|
|
227
227
|
*/
|
|
228
|
-
export declare function customRules(
|
|
228
|
+
export declare function customRules(envOptions: EnvBaseOptions, rules?: TSESLint.FlatConfig.Rules): TSESLint.FlatConfig.Config | undefined;
|
|
@@ -62,30 +62,29 @@ function createRulesRecord(generator) {
|
|
|
62
62
|
export const concatConfigs = (flatten);
|
|
63
63
|
/**
|
|
64
64
|
* Creates a flat configuration object with "files" and "ignores" settings from
|
|
65
|
-
* an environment's "
|
|
65
|
+
* an environment's "envOptions" object.
|
|
66
66
|
*
|
|
67
|
-
* @param
|
|
67
|
+
* @param envOptions
|
|
68
68
|
* The environment options containing "files" and "ignores" settings.
|
|
69
69
|
*
|
|
70
|
-
* @param
|
|
71
|
-
*
|
|
72
|
-
* "
|
|
73
|
-
* "options".
|
|
70
|
+
* @param flatConfig
|
|
71
|
+
* Properties for the flat configuration to be built. Additional "files" and
|
|
72
|
+
* "ignores" properties will be merged with the settings from "envOptions".
|
|
74
73
|
*
|
|
75
74
|
* @returns
|
|
76
75
|
* The resulting flat configuration object.
|
|
77
76
|
*/
|
|
78
|
-
export function createConfig(
|
|
77
|
+
export function createConfig(envOptions, flatConfig) {
|
|
79
78
|
return {
|
|
80
|
-
...
|
|
81
|
-
files: flatten(
|
|
82
|
-
ignores: flatten(
|
|
79
|
+
...flatConfig,
|
|
80
|
+
files: flatten(envOptions.files, flatConfig.files),
|
|
81
|
+
ignores: flatten(envOptions.ignores, flatConfig.ignores),
|
|
83
82
|
};
|
|
84
83
|
}
|
|
85
84
|
/**
|
|
86
85
|
* Generates various "no-restricted-?" rules from the passed configuration.
|
|
87
86
|
*
|
|
88
|
-
* @param
|
|
87
|
+
* @param envOptions
|
|
89
88
|
* The environment options containing "files", "ignores", and "restricted"
|
|
90
89
|
* settings.
|
|
91
90
|
*
|
|
@@ -95,8 +94,8 @@ export function createConfig(options, config) {
|
|
|
95
94
|
* @returns
|
|
96
95
|
* The flat configuration objects needed to forbid the restricted items.
|
|
97
96
|
*/
|
|
98
|
-
export function restrictedRules(
|
|
99
|
-
const { restricted = {} } =
|
|
97
|
+
export function restrictedRules(envOptions, fixed) {
|
|
98
|
+
const { restricted = {} } = envOptions;
|
|
100
99
|
const RESTRICTED_GLOBALS = [
|
|
101
100
|
{ name: "isFinite", message: "Use 'Number.isFinite' instead." },
|
|
102
101
|
{ name: "isNaN", message: "Use 'Number.isNaN' instead." },
|
|
@@ -116,7 +115,7 @@ export function restrictedRules(options, fixed) {
|
|
|
116
115
|
// generate the configuration objects
|
|
117
116
|
return concatConfigs(
|
|
118
117
|
// base rules for all files in the environment
|
|
119
|
-
createConfig(
|
|
118
|
+
createConfig(envOptions, {
|
|
120
119
|
rules: createRulesRecord(key => items[key]),
|
|
121
120
|
}),
|
|
122
121
|
// generate the override entries (join with base items)
|
|
@@ -125,23 +124,24 @@ export function restrictedRules(options, fixed) {
|
|
|
125
124
|
})));
|
|
126
125
|
}
|
|
127
126
|
/**
|
|
128
|
-
* Creates a flat configuration object with
|
|
129
|
-
* settings from an environment's
|
|
127
|
+
* Creates a flat configuration object with "files", "ignores", and "rules"
|
|
128
|
+
* settings from an environment's "envOptions" object.
|
|
130
129
|
*
|
|
131
|
-
* @param
|
|
132
|
-
* The environment options containing
|
|
130
|
+
* @param envOptions
|
|
131
|
+
* The environment options containing "files", "ignores", and "rules"
|
|
132
|
+
* settings.
|
|
133
133
|
*
|
|
134
134
|
* @param rules
|
|
135
135
|
* Hard-coded rule settings to be configured by the environment itself. These
|
|
136
|
-
* rule settings will precede the rules contained in "
|
|
136
|
+
* rule settings will precede the rules contained in "envOptions", in order to
|
|
137
137
|
* allow to override them.
|
|
138
138
|
*
|
|
139
139
|
* @returns
|
|
140
140
|
* The resulting flat configuration object, if the environment options contain
|
|
141
141
|
* custom rule settings, otherwise `undefined`.
|
|
142
142
|
*/
|
|
143
|
-
export function customRules(
|
|
144
|
-
return (rules ||
|
|
145
|
-
rules: { ...rules, ...
|
|
143
|
+
export function customRules(envOptions, rules) {
|
|
144
|
+
return (rules || envOptions.rules) && createConfig(envOptions, {
|
|
145
|
+
rules: { ...rules, ...envOptions.rules },
|
|
146
146
|
});
|
|
147
147
|
}
|
|
@@ -20,9 +20,10 @@ function project(options: EnvProjectOptions): Linter.FlatConfig[]
|
|
|
20
20
|
| - | - | - | - |
|
|
21
21
|
| `files` | `string[]` | _required_ | Glob patterns for source files to be included. |
|
|
22
22
|
| `ignores` | `string[]` | `[]` | Glob patterns for source files matching `files` to be ignored. |
|
|
23
|
-
| `
|
|
24
|
-
| `
|
|
25
|
-
| `
|
|
23
|
+
| `modules` | `RuleNoInvalidModulesOptions` | `{}` | Configuration for the rule "env-project/no-invalid-modules": |
|
|
24
|
+
| `modules.alias` | `Record<string, string>` | `{}` | Maps all alias prefixes to actual paths in the project (see below). |
|
|
25
|
+
| `modules.external` | `string \| string[]` | `[]` | Specifies glob patterns for external modules (see below). |
|
|
26
|
+
| `modules.packages` | `Record<string, EnvProjectPackage>` | `{}` | Allows to separate the source files into virtual packages (see below). |
|
|
26
27
|
| `rules` | `Linter.RulesRecord` | `{}` | Additional linter rules to be added to the configuration. |
|
|
27
28
|
|
|
28
29
|
### Option `alias`
|
|
@@ -42,8 +43,10 @@ export default [
|
|
|
42
43
|
...eslint.configure({ /* ... */ }),
|
|
43
44
|
...eslint.env.project({
|
|
44
45
|
files: ["src/**/*.{js,ts}"],
|
|
45
|
-
|
|
46
|
+
modules: {
|
|
47
|
+
alias: {
|
|
46
48
|
"@": "src",
|
|
49
|
+
},
|
|
47
50
|
},
|
|
48
51
|
}),
|
|
49
52
|
]
|
|
@@ -69,8 +72,10 @@ export default [
|
|
|
69
72
|
...eslint.configure({ /* ... */ }),
|
|
70
73
|
...eslint.env.project({
|
|
71
74
|
files: ["src/**/*.{js,ts}"],
|
|
72
|
-
|
|
73
|
-
|
|
75
|
+
modules: {
|
|
76
|
+
alias: { "@": "src" },
|
|
77
|
+
external: ["virtual:*", "@/special/lib/**/*.js"],
|
|
78
|
+
},
|
|
74
79
|
}),
|
|
75
80
|
]
|
|
76
81
|
```
|
|
@@ -105,19 +110,21 @@ export default [
|
|
|
105
110
|
...eslint.configure({ /* ... */ }),
|
|
106
111
|
...eslint.env.project({
|
|
107
112
|
files: ["src/**/*.{js,ts}"],
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
113
|
+
modules: {
|
|
114
|
+
alias: { "@": "src" },
|
|
115
|
+
packages: {
|
|
116
|
+
base: {
|
|
117
|
+
src: ["@/base/**/*", "@/tools/**/*"],
|
|
118
|
+
},
|
|
119
|
+
debug: {
|
|
120
|
+
src: "@/debug/**/*",
|
|
121
|
+
extends: "base",
|
|
122
|
+
optional: true,
|
|
123
|
+
},
|
|
124
|
+
special: {
|
|
125
|
+
src: "@/my/special/**/*",
|
|
126
|
+
extends: ["base", "debug"],
|
|
127
|
+
},
|
|
121
128
|
},
|
|
122
129
|
},
|
|
123
130
|
}),
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@open-xchange/linter-presets",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.6",
|
|
5
5
|
"description": "Configuration presets for ESLint and StyleLint",
|
|
6
6
|
"repository": {
|
|
7
7
|
"url": "https://gitlab.open-xchange.com/fspd/npm-packages/linter-presets"
|
|
@@ -15,9 +15,10 @@
|
|
|
15
15
|
"exports": "./dist/index.js",
|
|
16
16
|
"scripts": {
|
|
17
17
|
"prepare": "husky",
|
|
18
|
-
"prepack": "yarn lint && yarn
|
|
18
|
+
"prepack": "yarn build && yarn lint && yarn test",
|
|
19
19
|
"build": "npx --yes rimraf dist && tsc",
|
|
20
|
-
"lint": "eslint ."
|
|
20
|
+
"lint": "eslint .",
|
|
21
|
+
"test": "cd test && eslint ."
|
|
21
22
|
},
|
|
22
23
|
"lint-staged": {
|
|
23
24
|
"*.{js,ts,json}": "yarn lint"
|
|
@@ -54,8 +55,8 @@
|
|
|
54
55
|
"eslint-plugin-testing-library": "6.2.2",
|
|
55
56
|
"eslint-plugin-vitest": "0.5.4",
|
|
56
57
|
"eslint-plugin-yml": "1.14.0",
|
|
58
|
+
"find-up": "7.0.0",
|
|
57
59
|
"globals": "15.8.0",
|
|
58
|
-
"package-up": "5.0.0",
|
|
59
60
|
"picomatch": "4.0.2",
|
|
60
61
|
"stylelint-config-standard": "36.0.1",
|
|
61
62
|
"stylelint-config-standard-less": "3.0.1",
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
|
|
2
|
+
// eslint-disable-next-line env-project/no-amd-module-directive
|
|
3
|
+
/// <amd-module name="file1"/>
|
|
4
|
+
|
|
5
|
+
// valid imports
|
|
6
|
+
import "find-up";
|
|
7
|
+
import "$/external/module";
|
|
8
|
+
import "@/project1/generated";
|
|
9
|
+
|
|
10
|
+
// eslint-disable-next-line env-project/no-invalid-modules
|
|
11
|
+
import "invalid-package";
|
|
12
|
+
// eslint-disable-next-line env-project/no-invalid-modules
|
|
13
|
+
import "@/project1/invalid";
|
|
14
|
+
// eslint-disable-next-line env-project/no-invalid-modules
|
|
15
|
+
import "@/project2/file2";
|
|
16
|
+
// eslint-disable-next-line env-project/no-invalid-modules
|
|
17
|
+
import "@/project3/file3";
|
|
18
|
+
|
|
19
|
+
await import("find-up");
|
|
20
|
+
await import("@/project1/generated");
|
|
21
|
+
await import("@/project3/file3");
|
|
22
|
+
|
|
23
|
+
// eslint-disable-next-line env-project/no-invalid-modules
|
|
24
|
+
await import("invalid-package");
|
|
25
|
+
// eslint-disable-next-line env-project/no-invalid-modules
|
|
26
|
+
await import("@/project2/file2");
|