@open-xchange/linter-presets 0.7.1 → 0.8.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/CHANGELOG.md +4 -0
- package/dist/eslint/config/base.js +3 -0
- package/dist/eslint/config/ts.js +7 -9
- package/dist/eslint/env/browser.js +2 -2
- package/dist/eslint/env/node.js +2 -2
- package/dist/eslint/rules/no-invalid-hierarchy.js +1 -0
- package/dist/eslint/shared/restricted.d.ts +12 -2
- package/dist/eslint/shared/restricted.js +48 -19
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import eslintJs from "@eslint/js";
|
|
2
2
|
import babelParser from "@babel/eslint-parser";
|
|
3
3
|
import { JS_GLOB, SRC_GLOB, extGlob } from "../shared/env-utils.js";
|
|
4
|
+
import { builtinRestrictedRules } from "../shared/restricted.js";
|
|
4
5
|
// functions ==================================================================
|
|
5
6
|
/**
|
|
6
7
|
* Defines standard module settings and additional rules targeting JavaScript
|
|
@@ -127,6 +128,8 @@ export default function base(options) {
|
|
|
127
128
|
"prefer-spread": "error",
|
|
128
129
|
radix: "error",
|
|
129
130
|
"symbol-description": "error",
|
|
131
|
+
// built-in restricted items
|
|
132
|
+
...builtinRestrictedRules(options),
|
|
130
133
|
},
|
|
131
134
|
},
|
|
132
135
|
];
|
package/dist/eslint/config/ts.js
CHANGED
|
@@ -23,7 +23,7 @@ export default function ts() {
|
|
|
23
23
|
},
|
|
24
24
|
// recommended rules
|
|
25
25
|
extends: [
|
|
26
|
-
...typescriptEslint.configs.
|
|
26
|
+
...typescriptEslint.configs.strictTypeChecked,
|
|
27
27
|
...typescriptEslint.configs.stylisticTypeChecked,
|
|
28
28
|
],
|
|
29
29
|
// reconfigure plugin rules
|
|
@@ -39,9 +39,9 @@ export default function ts() {
|
|
|
39
39
|
allowHigherOrderFunctions: true,
|
|
40
40
|
allowConciseArrowFunctionExpressionsStartingWithVoid: true,
|
|
41
41
|
}],
|
|
42
|
-
"@typescript-eslint/
|
|
43
|
-
"@typescript-eslint/no-
|
|
44
|
-
"@typescript-eslint/no-
|
|
42
|
+
"@typescript-eslint/explicit-member-accessibility": ["error", { accessibility: "no-public", overrides: { constructors: "off" } }],
|
|
43
|
+
"@typescript-eslint/no-confusing-void-expression": "off",
|
|
44
|
+
"@typescript-eslint/no-dynamic-delete": "off",
|
|
45
45
|
"@typescript-eslint/no-empty-function": ["error", {
|
|
46
46
|
allow: ["private-constructors", "protected-constructors", "decoratedFunctions", "overrideMethods"],
|
|
47
47
|
}],
|
|
@@ -50,21 +50,19 @@ export default function ts() {
|
|
|
50
50
|
"@typescript-eslint/no-import-type-side-effects": "error",
|
|
51
51
|
"@typescript-eslint/no-invalid-this": "error",
|
|
52
52
|
"@typescript-eslint/no-loop-func": "error",
|
|
53
|
-
"@typescript-eslint/no-mixed-enums": "error",
|
|
54
53
|
"@typescript-eslint/no-namespace": ["error", { allowDeclarations: true }],
|
|
55
54
|
"@typescript-eslint/no-non-null-assertion": "off",
|
|
56
55
|
"@typescript-eslint/no-redeclare": "error",
|
|
57
56
|
"@typescript-eslint/no-shadow": ["error", { ignoreOnInitialization: true }],
|
|
58
|
-
"@typescript-eslint/no-unnecessary-
|
|
57
|
+
"@typescript-eslint/no-unnecessary-qualifier": "error",
|
|
58
|
+
"@typescript-eslint/no-unnecessary-type-parameters": "off",
|
|
59
59
|
"@typescript-eslint/no-unused-vars": ["error", NO_UNUSED_VARS_OPTIONS],
|
|
60
|
-
"@typescript-eslint/
|
|
61
|
-
"@typescript-eslint/prefer-literal-enum-member": "error",
|
|
60
|
+
"@typescript-eslint/parameter-properties": "error",
|
|
62
61
|
"@typescript-eslint/prefer-nullish-coalescing": ["error", { ignorePrimitives: true }],
|
|
63
62
|
"@typescript-eslint/prefer-readonly": "error",
|
|
64
63
|
"@typescript-eslint/restrict-template-expressions": "off",
|
|
65
64
|
"@typescript-eslint/return-await": ["error", "always"],
|
|
66
65
|
"@typescript-eslint/switch-exhaustiveness-check": "error",
|
|
67
|
-
"@typescript-eslint/use-unknown-in-catch-callback-variable": "error",
|
|
68
66
|
},
|
|
69
67
|
},
|
|
70
68
|
// fixes for module definition files
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import JAVASCRIPT_GLOBALS from "globals";
|
|
2
2
|
import CONFUSING_BROWSER_GLOBALS from "confusing-browser-globals";
|
|
3
3
|
import { concatConfigs, createConfig, customRules } from "../shared/env-utils.js";
|
|
4
|
-
import {
|
|
4
|
+
import { restrictedRulesConfig } from "../shared/restricted.js";
|
|
5
5
|
// constants ==================================================================
|
|
6
6
|
/**
|
|
7
7
|
* Global builtin symbols that are confusing or deprecated.
|
|
@@ -100,7 +100,7 @@ export default function browser(envOptions) {
|
|
|
100
100
|
},
|
|
101
101
|
}),
|
|
102
102
|
// generate the "no-restricted-?" rules according to passed configuration
|
|
103
|
-
|
|
103
|
+
restrictedRulesConfig(envOptions, {
|
|
104
104
|
globals: RESTRICTED_GLOBALS,
|
|
105
105
|
properties: RESTRICTED_PROPERTIES,
|
|
106
106
|
syntax: RESTRICTED_SYNTAX,
|
package/dist/eslint/env/node.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import nodePlugin from "eslint-plugin-n";
|
|
2
2
|
import { concatConfigs, createConfig, customRules } from "../shared/env-utils.js";
|
|
3
|
-
import {
|
|
3
|
+
import { restrictedRulesConfig } from "../shared/restricted.js";
|
|
4
4
|
// functions ==================================================================
|
|
5
5
|
/**
|
|
6
6
|
* Creates configuration objects with global symbols and linter rules for
|
|
@@ -30,7 +30,7 @@ export default function node(envOptions) {
|
|
|
30
30
|
},
|
|
31
31
|
}),
|
|
32
32
|
// generate the "no-restricted-?" rules according to passed configuration
|
|
33
|
-
|
|
33
|
+
restrictedRulesConfig(envOptions),
|
|
34
34
|
// custom rules
|
|
35
35
|
customRules(envOptions, {
|
|
36
36
|
"no-console": "off",
|
|
@@ -73,6 +73,7 @@ export default ESLintUtils.RuleCreator.withoutDocs({
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
// report package hierarchy errors
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- rule does not see assignment in callback function
|
|
76
77
|
if (invalidStatic) {
|
|
77
78
|
context.report({ messageId: "UNEXPECTED_OPTIONAL_STATIC", node: importWrapper.sourceNode });
|
|
78
79
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TSESLint } from "@typescript-eslint/utils";
|
|
2
|
-
import type { EnvFilesOptions, EnvBaseOptions } from "../shared/env-utils.js";
|
|
2
|
+
import type { LanguageOptions, EnvFilesOptions, EnvBaseOptions } from "../shared/env-utils.js";
|
|
3
3
|
/**
|
|
4
4
|
* Configuration for a single banned global or import.
|
|
5
5
|
*/
|
|
@@ -73,6 +73,16 @@ export interface EnvRestrictedOptions extends EnvBaseOptions {
|
|
|
73
73
|
*/
|
|
74
74
|
restricted?: EnvRestrictedOption;
|
|
75
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Creates restricted rules with built-in restricted items only.
|
|
78
|
+
*
|
|
79
|
+
* @param languageOptions
|
|
80
|
+
* The language options passed with the Linter configuration.
|
|
81
|
+
*
|
|
82
|
+
* @returns
|
|
83
|
+
* The rules dictionary with all needed restricted rules.
|
|
84
|
+
*/
|
|
85
|
+
export declare function builtinRestrictedRules(languageOptions: LanguageOptions): TSESLint.FlatConfig.Rules;
|
|
76
86
|
/**
|
|
77
87
|
* Generates various "no-restricted-?" rules from the passed configuration.
|
|
78
88
|
*
|
|
@@ -86,4 +96,4 @@ export interface EnvRestrictedOptions extends EnvBaseOptions {
|
|
|
86
96
|
* @returns
|
|
87
97
|
* The flat configuration objects needed to forbid the restricted items.
|
|
88
98
|
*/
|
|
89
|
-
export declare function
|
|
99
|
+
export declare function restrictedRulesConfig(envOptions: EnvRestrictedOptions, fixed?: EnvRestrictedItems): TSESLint.FlatConfig.ConfigArray;
|
|
@@ -14,7 +14,7 @@ function createRulesRecord(generator) {
|
|
|
14
14
|
const rules = {};
|
|
15
15
|
for (const key of ["globals", "imports", "properties", "syntax"]) {
|
|
16
16
|
const items = generator(key);
|
|
17
|
-
if (items
|
|
17
|
+
if (items.length) {
|
|
18
18
|
rules[`no-restricted-${key}`] = ["error", ...items];
|
|
19
19
|
}
|
|
20
20
|
}
|
|
@@ -24,7 +24,50 @@ function createRulesRecord(generator) {
|
|
|
24
24
|
}
|
|
25
25
|
return rules;
|
|
26
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Merges built-in items and custom items for restricted rules.
|
|
29
|
+
*
|
|
30
|
+
* @param nativeDecorators
|
|
31
|
+
* Whether to support native decorators in the code.
|
|
32
|
+
*
|
|
33
|
+
* @param restrictedItems
|
|
34
|
+
* The custom items for restricted rules to be merged.
|
|
35
|
+
*
|
|
36
|
+
* @returns
|
|
37
|
+
* The rules dictionary with all needed restricted rules.
|
|
38
|
+
*/
|
|
39
|
+
function mergeRestrictedItems(nativeDecorators, ...restrictedItems) {
|
|
40
|
+
const RESTRICTED_GLOBALS = [
|
|
41
|
+
{ name: "isFinite", message: "Use 'Number.isFinite' instead." },
|
|
42
|
+
{ name: "isNaN", message: "Use 'Number.isNaN' instead." },
|
|
43
|
+
];
|
|
44
|
+
const RESTRICTED_SYNTAX = [
|
|
45
|
+
{ selector: ":matches(PropertyDefinition, MethodDefinition[kind!='constructor'])[accessibility='private']" + (nativeDecorators ? "" : "[decorators.length=0]"), message: "Use #private syntax instead." },
|
|
46
|
+
];
|
|
47
|
+
// restricted items for all files in the environment
|
|
48
|
+
return {
|
|
49
|
+
globals: flatArray(RESTRICTED_GLOBALS, ...restrictedItems.map(item => item?.globals)),
|
|
50
|
+
imports: flatArray(...restrictedItems.map(item => item?.imports)),
|
|
51
|
+
properties: flatArray(...restrictedItems.map(item => item?.properties)),
|
|
52
|
+
syntax: flatArray(RESTRICTED_SYNTAX, ...restrictedItems.map(item => item?.syntax)),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
27
55
|
// ----------------------------------------------------------------------------
|
|
56
|
+
/**
|
|
57
|
+
* Creates restricted rules with built-in restricted items only.
|
|
58
|
+
*
|
|
59
|
+
* @param languageOptions
|
|
60
|
+
* The language options passed with the Linter configuration.
|
|
61
|
+
*
|
|
62
|
+
* @returns
|
|
63
|
+
* The rules dictionary with all needed restricted rules.
|
|
64
|
+
*/
|
|
65
|
+
export function builtinRestrictedRules(languageOptions) {
|
|
66
|
+
// built-in restricted items
|
|
67
|
+
const items = mergeRestrictedItems(!!languageOptions.nativeDecorators);
|
|
68
|
+
// generate the rules dictionary
|
|
69
|
+
return createRulesRecord(key => items[key]);
|
|
70
|
+
}
|
|
28
71
|
/**
|
|
29
72
|
* Generates various "no-restricted-?" rules from the passed configuration.
|
|
30
73
|
*
|
|
@@ -38,24 +81,10 @@ function createRulesRecord(generator) {
|
|
|
38
81
|
* @returns
|
|
39
82
|
* The flat configuration objects needed to forbid the restricted items.
|
|
40
83
|
*/
|
|
41
|
-
export function
|
|
42
|
-
const { restricted
|
|
43
|
-
const RESTRICTED_GLOBALS = [
|
|
44
|
-
{ name: "isFinite", message: "Use 'Number.isFinite' instead." },
|
|
45
|
-
{ name: "isNaN", message: "Use 'Number.isNaN' instead." },
|
|
46
|
-
];
|
|
47
|
-
const RESTRICTED_SYNTAX = [
|
|
48
|
-
{ selector: ":matches(PropertyDefinition, MethodDefinition[kind!='constructor'])[accessibility='public']", message: "Remove 'public' keyword." },
|
|
49
|
-
{ selector: ":matches(PropertyDefinition, MethodDefinition[kind!='constructor'])[accessibility='private']" + (restricted.nativeDecorators ? "" : "[decorators.length=0]"), message: "Use #private syntax instead." },
|
|
50
|
-
{ selector: "MethodDefinition[kind='constructor'] TSParameterProperty[accessibility]", message: "Use explicit class properties." },
|
|
51
|
-
];
|
|
84
|
+
export function restrictedRulesConfig(envOptions, fixed) {
|
|
85
|
+
const { restricted } = envOptions;
|
|
52
86
|
// restricted items for all files in the environment
|
|
53
|
-
const items =
|
|
54
|
-
globals: flatArray(RESTRICTED_GLOBALS, fixed?.globals, restricted.globals),
|
|
55
|
-
imports: flatArray(fixed?.imports, restricted.imports),
|
|
56
|
-
properties: flatArray(fixed?.properties, restricted.properties),
|
|
57
|
-
syntax: flatArray(RESTRICTED_SYNTAX, fixed?.syntax, restricted.syntax),
|
|
58
|
-
};
|
|
87
|
+
const items = mergeRestrictedItems(!!restricted?.nativeDecorators, fixed, restricted);
|
|
59
88
|
// generate the configuration objects
|
|
60
89
|
return concatConfigs(
|
|
61
90
|
// base rules for all files in the environment
|
|
@@ -63,7 +92,7 @@ export function restrictedRules(envOptions, fixed) {
|
|
|
63
92
|
rules: createRulesRecord(key => items[key]),
|
|
64
93
|
}),
|
|
65
94
|
// generate the override entries (join with base items)
|
|
66
|
-
restricted
|
|
95
|
+
restricted?.overrides?.map(override => createConfig(override, {
|
|
67
96
|
rules: createRulesRecord(key => flatArray(items[key], override[key])),
|
|
68
97
|
})));
|
|
69
98
|
}
|