@open-xchange/linter-presets 0.1.4 → 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.
@@ -0,0 +1,3 @@
1
+ {
2
+ "typescript.tsdk": "node_modules/typescript/lib"
3
+ }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.1.6] - 2024-07-23
4
+
5
+ - changed: [ESLint] moved rule options for `env.project` into own `modules` option
6
+ - chore: [ESLint] unit test for `env.project`
7
+
8
+ ## [0.1.5] - 2024-07-23
9
+
10
+ - chore: bump dependencies
11
+
3
12
  ## [0.1.4] - 2024-07-15
4
13
 
5
14
  - added: [ESLint] option `language.nativeDecorators` to support native ES decorators in JS files
@@ -119,7 +119,7 @@ export default function base(options) {
119
119
  "object-shorthand": "error",
120
120
  "operator-assignment": "error",
121
121
  "prefer-arrow-callback": "error",
122
- "prefer-const": ["error", { ignoreReadBeforeAssign: true }],
122
+ "prefer-const": ["error", { destructuring: "all", ignoreReadBeforeAssign: true }],
123
123
  "prefer-numeric-literals": "error",
124
124
  "prefer-regex-literals": "error",
125
125
  "prefer-rest-params": "error",
@@ -63,9 +63,11 @@ export default function ts() {
63
63
  "@typescript-eslint/no-shadow": ["error", { ignoreOnInitialization: true }],
64
64
  "@typescript-eslint/no-unnecessary-template-expression": "error",
65
65
  "@typescript-eslint/no-unsafe-enum-comparison": "error",
66
+ "@typescript-eslint/no-unsafe-function-type": "error",
66
67
  "@typescript-eslint/no-unsafe-unary-minus": "error",
67
68
  "@typescript-eslint/no-unused-vars": ["error", NO_UNUSED_VARS_OPTIONS],
68
69
  "@typescript-eslint/no-useless-constructor": "error",
70
+ "@typescript-eslint/no-wrapper-object-types": "error",
69
71
  "@typescript-eslint/only-throw-error": "error",
70
72
  "@typescript-eslint/prefer-find": "error",
71
73
  "@typescript-eslint/prefer-literal-enum-member": "error",
@@ -1,14 +1,9 @@
1
1
  import type { TSESLint } from "@typescript-eslint/utils";
2
- import type { EnvBaseOptions, EnvRestrictedOptions } from "../shared/env-utils.js";
2
+ import type { EnvRestrictedOptions } from "../shared/env-utils.js";
3
3
  /**
4
4
  * Configuration options for the environment preset "env.browser".
5
5
  */
6
- export interface EnvBrowserOptions extends EnvBaseOptions {
7
- /**
8
- * All globals, imports, properties, and syntax constructs to be banned for
9
- * the files included by the environment.
10
- */
11
- restricted?: EnvRestrictedOptions;
6
+ export interface EnvBrowserOptions extends EnvRestrictedOptions {
12
7
  }
13
8
  /**
14
9
  * Creates configuration objects with global symbols and linter rules for for
@@ -18,10 +13,10 @@ export interface EnvBrowserOptions extends EnvBaseOptions {
18
13
  * - `globals`
19
14
  * - `confusing-browser-globals`
20
15
  *
21
- * @param options
16
+ * @param envOptions
22
17
  * Configuration options for the environment.
23
18
  *
24
19
  * @returns
25
20
  * An array of configuration objects to be added to the flat configuration.
26
21
  */
27
- export default function browser(options: EnvBrowserOptions): TSESLint.FlatConfig.ConfigArray;
22
+ export default function browser(envOptions: EnvBrowserOptions): TSESLint.FlatConfig.ConfigArray;
@@ -1,6 +1,6 @@
1
1
  import JAVASCRIPT_GLOBALS from "globals";
2
2
  import CONFUSING_BROWSER_GLOBALS from "confusing-browser-globals";
3
- import { generateRestrictedRules } from "../shared/env-utils.js";
3
+ import { concatConfigs, createConfig, restrictedRules, customRules } from "../shared/env-utils.js";
4
4
  // constants ==================================================================
5
5
  /**
6
6
  * Global builtin symbols that are confusing or deprecated.
@@ -84,37 +84,26 @@ const RESTRICTED_GLOBALS = AMBIGUOUS_BROWSER_TYPES.map(name => {
84
84
  * - `globals`
85
85
  * - `confusing-browser-globals`
86
86
  *
87
- * @param options
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(options) {
94
- // configuration properties
95
- const { files, ignores = [], rules } = options;
93
+ export default function browser(envOptions) {
94
+ return concatConfigs(
95
+ // register global symbols used in browser scripts
96
+ createConfig(envOptions, {
97
+ languageOptions: {
98
+ globals: BROWSER_GLOBALS,
99
+ },
100
+ }),
96
101
  // generate the "no-restricted-?" rules according to passed configuration
97
- const restricted = generateRestrictedRules({
102
+ restrictedRules(envOptions, {
98
103
  globals: RESTRICTED_GLOBALS,
99
104
  properties: RESTRICTED_PROPERTIES,
100
105
  syntax: RESTRICTED_SYNTAX,
101
- }, options?.restricted);
102
- return [
103
- // base configuration for the environment
104
- {
105
- files,
106
- ignores,
107
- // register global symbols used in browser scripts
108
- languageOptions: {
109
- globals: BROWSER_GLOBALS,
110
- },
111
- // configure rules
112
- rules: {
113
- ...restricted.rules,
114
- ...rules,
115
- },
116
- },
117
- // "no-restricted-?" rules overrides for specific files
118
- ...restricted.overrides,
119
- ];
106
+ }),
107
+ // custom rules
108
+ customRules(envOptions));
120
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 options
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(options: EnvCodeceptOptions): TSESLint.FlatConfig.ConfigArray;
22
+ export default function codecept(envOptions: EnvCodeceptOptions): TSESLint.FlatConfig.ConfigArray;
@@ -6,6 +6,7 @@
6
6
  */
7
7
  import codeceptPlugin from "eslint-plugin-codeceptjs";
8
8
  import chaiExpectPlugin from "eslint-plugin-chai-expect";
9
+ import { concatConfigs, createConfig, customRules } from "../shared/env-utils.js";
9
10
  // functions ==================================================================
10
11
  /**
11
12
  * Creates configuration objects with global symbols and linter rules for E2E
@@ -15,47 +16,35 @@ import chaiExpectPlugin from "eslint-plugin-chai-expect";
15
16
  * - `eslint-plugin-codeceptjs`
16
17
  * - `eslint-plugin-chai-expect`
17
18
  *
18
- * @param options
19
+ * @param envOptions
19
20
  * Configuration options for the environment.
20
21
  *
21
22
  * @returns
22
23
  * An array of configuration objects to be added to the flat configuration.
23
24
  */
24
- export default function codecept(options) {
25
- // configuration properties
26
- const { files, ignores = [], rules } = options;
27
- return [
28
- {
29
- files,
30
- ignores,
31
- // register rule implementations of the plugins
32
- plugins: {
33
- codeceptjs: codeceptPlugin,
34
- },
35
- // register global symbols of CodeceptJS
36
- languageOptions: {
37
- globals: {
38
- ...codeceptPlugin.environments.codeceptjs.globals,
39
- },
40
- },
41
- // configure plugin rules
42
- rules: {
43
- // recommended rules
44
- ...codeceptPlugin.configs.recommended.rules,
45
- // extra rules
46
- "new-cap": ["error", {
47
- capIsNewExceptions: ["After", "AfterSuite", "Before", "BeforeSuite", "Feature", "Scenario"],
48
- }],
49
- "no-restricted-properties": ["warn", { object: "Scenario", property: "todo", message: "Unexpected unimplemented test." }],
50
- "codeceptjs/no-skipped-tests": "warn",
51
- // custom rules
52
- ...rules,
53
- },
25
+ export default function codecept(envOptions) {
26
+ return concatConfigs(
27
+ // "codecept" plugin
28
+ createConfig(envOptions, {
29
+ // register rule implementations of the plugins
30
+ plugins: {
31
+ codeceptjs: codeceptPlugin,
54
32
  },
55
- {
56
- files,
57
- ignores,
58
- ...chaiExpectPlugin.configs["recommended-flat"],
33
+ // register global symbols of CodeceptJS
34
+ languageOptions: {
35
+ globals: codeceptPlugin.environments.codeceptjs.globals,
59
36
  },
60
- ];
37
+ // recommended rules
38
+ rules: codeceptPlugin.configs.recommended.rules,
39
+ }),
40
+ // "chai-expect" plugin
41
+ createConfig(envOptions, chaiExpectPlugin.configs["recommended-flat"]),
42
+ // custom rules
43
+ customRules(envOptions, {
44
+ "new-cap": ["error", {
45
+ capIsNewExceptions: ["After", "AfterSuite", "Before", "BeforeSuite", "Feature", "Scenario"],
46
+ }],
47
+ "no-restricted-properties": ["warn", { object: "Scenario", property: "todo", message: "Unexpected unimplemented test." }],
48
+ "codeceptjs/no-skipped-tests": "warn",
49
+ }));
61
50
  }
@@ -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 options
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(options: EnvEslintOptions): TSESLint.FlatConfig.ConfigArray;
20
+ export default function eslint(envOptions: EnvEslintOptions): TSESLint.FlatConfig.ConfigArray;
@@ -1,4 +1,5 @@
1
1
  import eslintPlugin from "eslint-plugin-eslint-plugin";
2
+ import { concatConfigs, createConfig, customRules } from "../shared/env-utils.js";
2
3
  // exports ====================================================================
3
4
  /**
4
5
  * Adds linter rules for ESLint plugin implementations.
@@ -6,29 +7,16 @@ import eslintPlugin from "eslint-plugin-eslint-plugin";
6
7
  * Wraps the following packages:
7
8
  * - `eslint-plugin-eslint-plugin`
8
9
  *
9
- * @param options
10
+ * @param envOptions
10
11
  * Configuration options for the environment.
11
12
  *
12
13
  * @returns
13
14
  * An array of configuration objects to be added to the flat configuration.
14
15
  */
15
- export default function eslint(options) {
16
- // configuration properties
17
- const { files, ignores = [], rules = {} } = options;
18
- // the plugin configuration
19
- const pluginConfig = eslintPlugin.configs["flat/rules-recommended"];
20
- return [
21
- // register rule implementations and recommended rules
22
- {
23
- files,
24
- ignores,
25
- ...pluginConfig,
26
- },
27
- // reconfigure plugin rules
28
- {
29
- files,
30
- ignores,
31
- rules,
32
- },
33
- ];
16
+ export default function eslint(envOptions) {
17
+ return concatConfigs(
18
+ // register rule implementations and recommended rules
19
+ createConfig(envOptions, eslintPlugin.configs["flat/rules-recommended"]),
20
+ // custom rules
21
+ customRules(envOptions));
34
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 options
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(options: EnvJestOptions): TSESLint.FlatConfig.ConfigArray;
21
+ export default function jest(envOptions: EnvJestOptions): TSESLint.FlatConfig.ConfigArray;
@@ -1,4 +1,5 @@
1
1
  import jestPlugin from "eslint-plugin-jest";
2
+ import { concatConfigs, createConfig, customRules } from "../shared/env-utils.js";
2
3
  // functions ==================================================================
3
4
  /**
4
5
  * Creates configuration objects with global symbols and linter rules for unit
@@ -7,43 +8,36 @@ import jestPlugin from "eslint-plugin-jest";
7
8
  * Wraps the following packages:
8
9
  * - `eslint-plugin-jest`
9
10
  *
10
- * @param options
11
+ * @param envOptions
11
12
  * Configuration options for the environment.
12
13
  *
13
14
  * @returns
14
15
  * An array of configuration objects to be added to the flat configuration.
15
16
  */
16
- export default function jest(options) {
17
- // config properties
18
- const { files, ignores = [], rules } = options;
19
- return [{
20
- files,
21
- ignores,
22
- // register rule implementations, globals
23
- ...jestPlugin.configs["flat/recommended"],
24
- // configure plugin rules
25
- rules: {
26
- // recommended rules
27
- ...jestPlugin.configs["flat/recommended"].rules,
28
- ...jestPlugin.configs["flat/style"].rules,
29
- // extra rules
30
- "jest/consistent-test-it": ["error", { fn: "it" }],
31
- "jest/no-commented-out-tests": "error",
32
- "jest/no-conditional-expect": "off",
33
- "jest/no-confusing-set-timeout": "error",
34
- "jest/no-duplicate-hooks": "error",
35
- "jest/no-test-return-statement": "error",
36
- "jest/prefer-comparison-matcher": "error",
37
- "jest/prefer-equality-matcher": "error",
38
- "jest/prefer-expect-resolves": "error",
39
- "jest/prefer-hooks-on-top": "error",
40
- "jest/prefer-lowercase-title": "error",
41
- "jest/prefer-mock-promise-shorthand": "error",
42
- "jest/prefer-spy-on": "error",
43
- "jest/prefer-todo": "error",
44
- "jest/require-top-level-describe": "error",
45
- // custom rules
46
- ...rules,
47
- },
48
- }];
17
+ export default function jest(envOptions) {
18
+ return concatConfigs(
19
+ // register rule implementations, globals, and recommended rules
20
+ createConfig(envOptions, jestPlugin.configs["flat/recommended"]),
21
+ // add recommended stylistic rules
22
+ createConfig(envOptions, {
23
+ rules: jestPlugin.configs["flat/style"].rules,
24
+ }),
25
+ // custom rules
26
+ customRules(envOptions, {
27
+ "jest/consistent-test-it": ["error", { fn: "it" }],
28
+ "jest/no-commented-out-tests": "error",
29
+ "jest/no-conditional-expect": "off",
30
+ "jest/no-confusing-set-timeout": "error",
31
+ "jest/no-duplicate-hooks": "error",
32
+ "jest/no-test-return-statement": "error",
33
+ "jest/prefer-comparison-matcher": "error",
34
+ "jest/prefer-equality-matcher": "error",
35
+ "jest/prefer-expect-resolves": "error",
36
+ "jest/prefer-hooks-on-top": "error",
37
+ "jest/prefer-lowercase-title": "error",
38
+ "jest/prefer-mock-promise-shorthand": "error",
39
+ "jest/prefer-spy-on": "error",
40
+ "jest/prefer-todo": "error",
41
+ "jest/require-top-level-describe": "error",
42
+ }));
49
43
  }
@@ -1,18 +1,13 @@
1
1
  import type { TSESLint } from "@typescript-eslint/utils";
2
- import type { LanguageOptions, EnvBaseOptions, EnvRestrictedOptions } from "../shared/env-utils.js";
2
+ import type { LanguageOptions, EnvRestrictedOptions } from "../shared/env-utils.js";
3
3
  /**
4
4
  * Configuration options for the environment preset "env.node".
5
5
  */
6
- export interface EnvNodeOptions extends EnvBaseOptions {
6
+ export interface EnvNodeOptions extends EnvRestrictedOptions {
7
7
  /**
8
8
  * The module mode used by the linted files. Default value is "module".
9
9
  */
10
10
  sourceType?: LanguageOptions["sourceType"];
11
- /**
12
- * All globals, imports, properties, and syntax constructs to be banned for
13
- * the files included by the environment.
14
- */
15
- restricted?: EnvRestrictedOptions;
16
11
  }
17
12
  /**
18
13
  * Creates configuration objects with global symbols and linter rules for
@@ -21,10 +16,10 @@ export interface EnvNodeOptions extends EnvBaseOptions {
21
16
  * Wraps the following packages:
22
17
  * - `eslint-plugin-n`
23
18
  *
24
- * @param options
19
+ * @param envOptions
25
20
  * Configuration options for the environment.
26
21
  *
27
22
  * @returns
28
23
  * An array of configuration objects to be added to the flat configuration.
29
24
  */
30
- export default function node(options: EnvNodeOptions): TSESLint.FlatConfig.ConfigArray;
25
+ export default function node(envOptions: EnvNodeOptions): TSESLint.FlatConfig.ConfigArray;
@@ -1,5 +1,5 @@
1
1
  import nodePlugin from "eslint-plugin-n";
2
- import { generateRestrictedRules } from "../shared/env-utils.js";
2
+ import { concatConfigs, createConfig, restrictedRules, customRules } from "../shared/env-utils.js";
3
3
  // functions ==================================================================
4
4
  /**
5
5
  * Creates configuration objects with global symbols and linter rules for
@@ -8,44 +8,30 @@ import { generateRestrictedRules } from "../shared/env-utils.js";
8
8
  * Wraps the following packages:
9
9
  * - `eslint-plugin-n`
10
10
  *
11
- * @param options
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(options) {
18
- // configuration properties
19
- const { files, ignores = [], sourceType = "module", rules } = options;
20
- // the plugin configuration
21
- const configKey = (sourceType === "commonjs") ? "flat/recommended-script" : "flat/recommended-module";
22
- const nodeConfig = nodePlugin.configs[configKey];
23
- // generate the "no-restricted-?" rules according to passed configuration
24
- const restricted = generateRestrictedRules({}, options?.restricted);
25
- return [
26
- // register rule implementations
27
- {
28
- files,
29
- ignores,
30
- ...nodeConfig,
31
- settings: {
32
- node: {
33
- tryExtensions: [".js", ".ts", ".d.ts"], // automatically add missing extensions in imports
34
- },
35
- },
36
- },
37
- // reconfigure plugin rules
38
- {
39
- files,
40
- ignores,
41
- rules: {
42
- "n/no-unsupported-features/node-builtins": ["error", { allowExperimental: true }],
43
- "n/prefer-node-protocol": "error",
44
- ...restricted.rules,
45
- ...rules,
17
+ export default function node(envOptions) {
18
+ // the plugin configuration key, according to source module type
19
+ const configKey = (envOptions.sourceType === "commonjs") ? "flat/recommended-script" : "flat/recommended-module";
20
+ return concatConfigs(
21
+ // register rule implementations
22
+ createConfig(envOptions, {
23
+ ...nodePlugin.configs[configKey],
24
+ settings: {
25
+ node: {
26
+ tryExtensions: [".js", ".ts", ".d.ts"], // automatically add missing extensions in imports
46
27
  },
47
28
  },
48
- // "no-restricted-?" rules overrides for specific files
49
- ...restricted.overrides,
50
- ];
29
+ }),
30
+ // generate the "no-restricted-?" rules according to passed configuration
31
+ restrictedRules(envOptions),
32
+ // custom rules
33
+ customRules(envOptions, {
34
+ "n/no-unsupported-features/node-builtins": ["error", { allowExperimental: true }],
35
+ "n/prefer-node-protocol": "error",
36
+ }));
51
37
  }
@@ -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, RuleNoInvalidModulesOptions {
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 options
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(options: EnvProjectOptions): TSESLint.FlatConfig.ConfigArray;
22
+ export default function project(envOptions: EnvProjectOptions): TSESLint.FlatConfig.ConfigArray;
@@ -1,35 +1,32 @@
1
+ import { concatConfigs, createConfig, customRules } from "../shared/env-utils.js";
1
2
  import noAmdModuleDirective from "../rules/no-amd-module-directive.js";
2
3
  import noInvalidModules from "../rules/no-invalid-modules.js";
3
4
  // exports ====================================================================
4
5
  /**
5
6
  * Adds custom linter rules for checking project setup and module hierarchy.
6
7
  *
7
- * @param options
8
+ * @param envOptions
8
9
  * Configuration options for the environment.
9
10
  *
10
11
  * @returns
11
12
  * An array of configuration objects to be added to the flat configuration.
12
13
  */
13
- export default function project(options) {
14
- // configuration properties
15
- const { files, ignores = [], rules, ...rest } = options;
16
- return [{
17
- files,
18
- ignores,
19
- // register rule implementations
20
- plugins: {
21
- "env-project": {
22
- rules: {
23
- "no-amd-module-directive": noAmdModuleDirective,
24
- "no-invalid-modules": noInvalidModules,
25
- },
14
+ export default function project(envOptions) {
15
+ return concatConfigs(
16
+ // register rule implementations
17
+ createConfig(envOptions, {
18
+ plugins: {
19
+ "env-project": {
20
+ rules: {
21
+ "no-amd-module-directive": noAmdModuleDirective,
22
+ "no-invalid-modules": noInvalidModules,
26
23
  },
27
24
  },
28
- // configure rules
29
- rules: {
30
- "env-project/no-amd-module-directive": "error",
31
- "env-project/no-invalid-modules": ["error", rest],
32
- ...rules,
33
- },
34
- }];
25
+ },
26
+ }),
27
+ // custom rules
28
+ customRules(envOptions, {
29
+ "env-project/no-amd-module-directive": "error",
30
+ "env-project/no-invalid-modules": ["error", envOptions.modules ?? {}],
31
+ }));
35
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 options
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(options: EnvReactOptions): TSESLint.FlatConfig.ConfigArray;
29
+ export default function react(envOptions: EnvReactOptions): TSESLint.FlatConfig.ConfigArray;