@open-xchange/linter-presets 0.7.1 → 0.8.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## `0.8.1` – 2024-Sep-04
4
+
5
+ - change: (ESLint) relax a few strict rules of `@typescript-eslint`
6
+
7
+ ## `0.8.0` – 2024-Sep-04
8
+
9
+ - change: (ESLint) raise `@typescript-eslint` rules to "strict" preset
10
+
3
11
  ## `0.7.1` – 2024-Aug-30
4
12
 
5
13
  - chore: bump dependencies
@@ -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
  ];
@@ -23,7 +23,7 @@ export default function ts() {
23
23
  },
24
24
  // recommended rules
25
25
  extends: [
26
- ...typescriptEslint.configs.recommendedTypeChecked,
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/no-array-constructor": "error",
43
- "@typescript-eslint/no-deprecated": "error",
44
- "@typescript-eslint/no-duplicate-type-constituents": "error",
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
  }],
@@ -49,22 +49,23 @@ export default function ts() {
49
49
  "@typescript-eslint/no-explicit-any": "off",
50
50
  "@typescript-eslint/no-import-type-side-effects": "error",
51
51
  "@typescript-eslint/no-invalid-this": "error",
52
+ "@typescript-eslint/no-invalid-void-type": "off",
52
53
  "@typescript-eslint/no-loop-func": "error",
53
- "@typescript-eslint/no-mixed-enums": "error",
54
54
  "@typescript-eslint/no-namespace": ["error", { allowDeclarations: true }],
55
55
  "@typescript-eslint/no-non-null-assertion": "off",
56
56
  "@typescript-eslint/no-redeclare": "error",
57
57
  "@typescript-eslint/no-shadow": ["error", { ignoreOnInitialization: true }],
58
- "@typescript-eslint/no-unnecessary-template-expression": "error",
58
+ "@typescript-eslint/no-unnecessary-qualifier": "error",
59
+ "@typescript-eslint/no-unnecessary-type-parameters": "off",
59
60
  "@typescript-eslint/no-unused-vars": ["error", NO_UNUSED_VARS_OPTIONS],
60
- "@typescript-eslint/no-useless-constructor": "error",
61
- "@typescript-eslint/prefer-literal-enum-member": "error",
61
+ "@typescript-eslint/parameter-properties": "error",
62
62
  "@typescript-eslint/prefer-nullish-coalescing": ["error", { ignorePrimitives: true }],
63
63
  "@typescript-eslint/prefer-readonly": "error",
64
+ "@typescript-eslint/prefer-reduce-type-parameter": "off",
64
65
  "@typescript-eslint/restrict-template-expressions": "off",
65
66
  "@typescript-eslint/return-await": ["error", "always"],
66
67
  "@typescript-eslint/switch-exhaustiveness-check": "error",
67
- "@typescript-eslint/use-unknown-in-catch-callback-variable": "error",
68
+ "@typescript-eslint/unified-signatures": ["error", { ignoreDifferentlyNamedParameters: true }],
68
69
  },
69
70
  },
70
71
  // 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 { restrictedRules } from "../shared/restricted.js";
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
- restrictedRules(envOptions, {
103
+ restrictedRulesConfig(envOptions, {
104
104
  globals: RESTRICTED_GLOBALS,
105
105
  properties: RESTRICTED_PROPERTIES,
106
106
  syntax: RESTRICTED_SYNTAX,
@@ -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 { restrictedRules } from "../shared/restricted.js";
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
- restrictedRules(envOptions),
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 restrictedRules(envOptions: EnvRestrictedOptions, fixed?: EnvRestrictedItems): TSESLint.FlatConfig.ConfigArray;
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?.length) {
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 restrictedRules(envOptions, fixed) {
42
- const { restricted = {} } = envOptions;
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.overrides?.map(override => createConfig(override, {
95
+ restricted?.overrides?.map(override => createConfig(override, {
67
96
  rules: createRulesRecord(key => flatArray(items[key], override[key])),
68
97
  })));
69
98
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-xchange/linter-presets",
3
- "version": "0.7.1",
3
+ "version": "0.8.1",
4
4
  "description": "Configuration presets for ESLint and StyleLint",
5
5
  "repository": {
6
6
  "type": "git",