@open-xchange/linter-presets 0.0.6 → 0.1.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.
Files changed (90) hide show
  1. package/CHANGELOG.md +19 -14
  2. package/README.md +3 -3
  3. package/dist/eslint/config/base.d.ts +16 -0
  4. package/{lib → dist}/eslint/config/base.js +5 -26
  5. package/dist/eslint/config/directives.d.ts +11 -0
  6. package/{lib → dist}/eslint/config/directives.js +1 -5
  7. package/dist/eslint/config/imports.d.ts +15 -0
  8. package/dist/eslint/config/imports.js +58 -0
  9. package/dist/eslint/config/js.d.ts +9 -0
  10. package/dist/eslint/config/js.js +32 -0
  11. package/dist/eslint/config/jsdoc.d.ts +11 -0
  12. package/{lib → dist}/eslint/config/jsdoc.js +1 -9
  13. package/dist/eslint/config/json.d.ts +15 -0
  14. package/{lib → dist}/eslint/config/json.js +2 -8
  15. package/dist/eslint/config/license.d.ts +14 -0
  16. package/{lib → dist}/eslint/config/license.js +12 -18
  17. package/dist/eslint/config/promises.d.ts +11 -0
  18. package/{lib → dist}/eslint/config/promises.js +3 -9
  19. package/dist/eslint/config/stylistic.d.ts +16 -0
  20. package/{lib → dist}/eslint/config/stylistic.js +12 -22
  21. package/dist/eslint/config/ts.d.ts +11 -0
  22. package/{lib → dist}/eslint/config/ts.js +9 -18
  23. package/dist/eslint/config/yaml.d.ts +15 -0
  24. package/{lib → dist}/eslint/config/yaml.js +2 -8
  25. package/dist/eslint/env/browser.d.ts +27 -0
  26. package/{lib → dist}/eslint/env/browser.js +5 -26
  27. package/dist/eslint/env/codecept.d.ts +22 -0
  28. package/{lib → dist}/eslint/env/codecept.js +4 -13
  29. package/dist/eslint/env/eslint.d.ts +20 -0
  30. package/{lib → dist}/eslint/env/eslint.js +2 -9
  31. package/dist/eslint/env/jest.d.ts +21 -0
  32. package/dist/eslint/env/jest.js +49 -0
  33. package/dist/eslint/env/node.d.ts +30 -0
  34. package/{lib → dist}/eslint/env/node.js +2 -14
  35. package/dist/eslint/env/project.d.ts +18 -0
  36. package/{lib → dist}/eslint/env/project.js +18 -25
  37. package/dist/eslint/env/react.d.ts +29 -0
  38. package/{lib → dist}/eslint/env/react.js +3 -15
  39. package/dist/eslint/env/tsconfig.d.ts +21 -0
  40. package/{lib → dist}/eslint/env/tsconfig.js +15 -21
  41. package/dist/eslint/env/vitest.d.ts +23 -0
  42. package/{lib → dist}/eslint/env/vitest.js +3 -16
  43. package/dist/eslint/index.d.ts +63 -0
  44. package/{lib → dist}/eslint/index.js +3 -25
  45. package/dist/eslint/rules/no-amd-module-directive.d.ts +3 -0
  46. package/{lib → dist}/eslint/rules/no-amd-module-directive.js +22 -26
  47. package/dist/eslint/rules/no-invalid-modules.d.ts +38 -0
  48. package/{lib → dist}/eslint/rules/no-invalid-modules.js +40 -63
  49. package/dist/eslint/shared/env-utils.d.ts +150 -0
  50. package/{lib → dist}/eslint/shared/env-utils.js +12 -23
  51. package/dist/eslint/shared/rule-utils.d.ts +76 -0
  52. package/{lib → dist}/eslint/shared/rule-utils.js +27 -60
  53. package/dist/index.d.ts +3 -0
  54. package/{lib → dist}/index.js +0 -1
  55. package/dist/stylelint/index.d.ts +49 -0
  56. package/{lib → dist}/stylelint/index.js +5 -22
  57. package/dist/utils/index.d.ts +12 -0
  58. package/{lib → dist}/utils/index.js +2 -5
  59. package/package.json +12 -4
  60. package/lib/eslint/config/imports.js +0 -68
  61. package/lib/eslint/config/js.js +0 -36
  62. package/lib/eslint/env/browser.d.ts +0 -21
  63. package/lib/eslint/env/codecept.d.ts +0 -14
  64. package/lib/eslint/env/eslint.d.ts +0 -14
  65. package/lib/eslint/env/jest.d.ts +0 -14
  66. package/lib/eslint/env/jest.js +0 -56
  67. package/lib/eslint/env/node.d.ts +0 -28
  68. package/lib/eslint/env/project.d.ts +0 -21
  69. package/lib/eslint/env/react.d.ts +0 -20
  70. package/lib/eslint/env/tsconfig.d.ts +0 -20
  71. package/lib/eslint/env/vitest.d.ts +0 -14
  72. package/lib/eslint/index.d.ts +0 -43
  73. package/lib/eslint/shared/env-utils.d.ts +0 -95
  74. package/lib/eslint/shared/types.d.ts +0 -107
  75. package/lib/index.d.ts +0 -4
  76. package/lib/stylelint/index.d.ts +0 -18
  77. package/lib/stylelint/types.d.ts +0 -44
  78. package/lib/utils/index.d.ts +0 -4
  79. /package/{lib → doc}/eslint/README.md +0 -0
  80. /package/{lib → doc}/eslint/env/browser.md +0 -0
  81. /package/{lib → doc}/eslint/env/codecept.md +0 -0
  82. /package/{lib → doc}/eslint/env/eslint.md +0 -0
  83. /package/{lib → doc}/eslint/env/jest.md +0 -0
  84. /package/{lib → doc}/eslint/env/node.md +0 -0
  85. /package/{lib → doc}/eslint/env/project.md +0 -0
  86. /package/{lib → doc}/eslint/env/react.md +0 -0
  87. /package/{lib → doc}/eslint/env/tsconfig.md +0 -0
  88. /package/{lib → doc}/eslint/env/vitest.md +0 -0
  89. /package/{lib → doc}/stylelint/README.md +0 -0
  90. /package/{lib → doc}/utils/README.md +0 -0
@@ -4,41 +4,33 @@
4
4
  * This program is proprietary software and licensed to you under Open-Xchange
5
5
  * GmbH's Software License Agreement.
6
6
  */
7
-
8
7
  import typescriptEslint from "typescript-eslint";
9
-
10
8
  import { NO_UNUSED_VARS_OPTIONS } from "../shared/env-utils.js";
11
-
12
9
  // functions ==================================================================
13
-
14
10
  /**
15
11
  * Defines standard rules for TypeScript source files.
16
12
  *
17
13
  * Wraps the following packages:
18
14
  * - `typescript-eslint`
19
15
  *
20
- * @returns {import("../shared/types.js").FlatConfigArray}
16
+ * @returns
21
17
  * An array of configuration objects to be added to the flat configuration.
22
18
  */
23
19
  export default function ts() {
24
-
25
20
  // plugin configuration, additional rules
26
21
  return typescriptEslint.config({
27
22
  files: ["**/*.{ts,tsx,mts,cts}"],
28
-
29
23
  // suppress warning for new TypeScript versions
30
24
  languageOptions: {
31
25
  parserOptions: {
32
26
  warnOnUnsupportedTypeScriptVersion: false,
33
27
  },
34
28
  },
35
-
36
29
  // recommended rules
37
30
  extends: [
38
31
  ...typescriptEslint.configs.recommendedTypeChecked,
39
32
  ...typescriptEslint.configs.stylisticTypeChecked,
40
33
  ],
41
-
42
34
  // reconfigure plugin rules
43
35
  rules: {
44
36
  "@typescript-eslint/array-type": ["error", { default: "array-simple" }],
@@ -48,17 +40,17 @@ export default function ts() {
48
40
  "@typescript-eslint/default-param-last": "error",
49
41
  "@typescript-eslint/dot-notation": "error",
50
42
  "@typescript-eslint/explicit-function-return-type": ["error", {
51
- allowExpressions: true,
52
- allowTypedFunctionExpressions: true,
53
- allowHigherOrderFunctions: true,
54
- allowConciseArrowFunctionExpressionsStartingWithVoid: true,
55
- }],
43
+ allowExpressions: true,
44
+ allowTypedFunctionExpressions: true,
45
+ allowHigherOrderFunctions: true,
46
+ allowConciseArrowFunctionExpressionsStartingWithVoid: true,
47
+ }],
56
48
  "@typescript-eslint/no-array-constructor": "error",
57
49
  "@typescript-eslint/no-array-delete": "error",
58
50
  "@typescript-eslint/no-duplicate-type-constituents": "error",
59
51
  "@typescript-eslint/no-empty-function": ["error", {
60
- allow: ["private-constructors", "protected-constructors", "decoratedFunctions", "overrideMethods"],
61
- }],
52
+ allow: ["private-constructors", "protected-constructors", "decoratedFunctions", "overrideMethods"],
53
+ }],
62
54
  "@typescript-eslint/no-empty-interface": "off",
63
55
  "@typescript-eslint/no-explicit-any": "off",
64
56
  "@typescript-eslint/no-import-type-side-effects": "error",
@@ -86,8 +78,7 @@ export default function ts() {
86
78
  "@typescript-eslint/switch-exhaustiveness-check": "error",
87
79
  "@typescript-eslint/use-unknown-in-catch-callback-variable": "error",
88
80
  },
89
- },
90
-
81
+ },
91
82
  // fixes for module definition files
92
83
  {
93
84
  files: ["**/*.d.{ts,tsx,mts,cts}"],
@@ -0,0 +1,15 @@
1
+ import type { TSESLint } from "@typescript-eslint/utils";
2
+ import type { StylisticOptions } from "../shared/env-utils.js";
3
+ /**
4
+ * Defines standard linting rules for YAML files.
5
+ *
6
+ * Wraps the following packages:
7
+ * - `eslint-plugin-yml`
8
+ *
9
+ * @param options
10
+ * Resolved configuration options.
11
+ *
12
+ * @returns
13
+ * An array of configuration objects to be added to the flat configuration.
14
+ */
15
+ export default function yaml(options: Required<StylisticOptions>): TSESLint.FlatConfig.ConfigArray;
@@ -1,27 +1,21 @@
1
-
2
1
  import yamlPlugin from "eslint-plugin-yml";
3
-
4
2
  // functions ==================================================================
5
-
6
3
  /**
7
4
  * Defines standard linting rules for YAML files.
8
5
  *
9
6
  * Wraps the following packages:
10
7
  * - `eslint-plugin-yml`
11
8
  *
12
- * @param {Required<import("../shared/types").StylisticOptions>} options
9
+ * @param options
13
10
  * Resolved configuration options.
14
11
  *
15
- * @returns {import("../shared/types").FlatConfigArray}
12
+ * @returns
16
13
  * An array of configuration objects to be added to the flat configuration.
17
14
  */
18
15
  export default function yaml(options) {
19
-
20
16
  return [
21
-
22
17
  // register rule implementations and recommended rules
23
18
  ...yamlPlugin.configs["flat/recommended"],
24
-
25
19
  // reconfigure plugin rules
26
20
  {
27
21
  rules: {
@@ -0,0 +1,27 @@
1
+ import type { TSESLint } from "@typescript-eslint/utils";
2
+ import type { EnvBaseOptions, EnvRestrictedOptions } from "../shared/env-utils.js";
3
+ /**
4
+ * Configuration options for the environment preset "env.browser".
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;
12
+ }
13
+ /**
14
+ * Creates configuration objects with global symbols and linter rules for for
15
+ * browser modules.
16
+ *
17
+ * Wraps the following packages:
18
+ * - `globals`
19
+ * - `confusing-browser-globals`
20
+ *
21
+ * @param options
22
+ * Configuration options for the environment.
23
+ *
24
+ * @returns
25
+ * An array of configuration objects to be added to the flat configuration.
26
+ */
27
+ export default function browser(options: EnvBrowserOptions): TSESLint.FlatConfig.ConfigArray;
@@ -1,11 +1,7 @@
1
-
2
1
  import JAVASCRIPT_GLOBALS from "globals";
3
2
  import CONFUSING_BROWSER_GLOBALS from "confusing-browser-globals";
4
-
5
3
  import { generateRestrictedRules } from "../shared/env-utils.js";
6
-
7
4
  // constants ==================================================================
8
-
9
5
  /**
10
6
  * Global builtin symbols that are confusing or deprecated.
11
7
  */
@@ -21,7 +17,6 @@ const CONFUSING_BUILTIN_GLOBALS = [
21
17
  "unescape",
22
18
  "valueOf",
23
19
  ];
24
-
25
20
  /**
26
21
  * Global browser classes that may conflict with custom application classes.
27
22
  * For disambiguation, custom classes must be imported, and global browser
@@ -35,14 +30,12 @@ const AMBIGUOUS_BROWSER_TYPES = [
35
30
  "Storage",
36
31
  "Transformer",
37
32
  ];
38
-
39
33
  /**
40
34
  * Properties of global objects to be banned in all browser modules.
41
35
  */
42
36
  const RESTRICTED_PROPERTIES = [
43
37
  { object: "Object", property: "hasOwn", message: "Missing browser support." },
44
38
  ];
45
-
46
39
  /**
47
40
  * Syntax constructs to be banned in all browser modules.
48
41
  */
@@ -50,9 +43,7 @@ const RESTRICTED_SYNTAX = [
50
43
  { selector: "ClassBody > StaticBlock", message: "Static blocks not supported yet." },
51
44
  { selector: "ExportNamedDeclaration > TSEnumDeclaration[const=true]", message: "Do not export const enums." },
52
45
  ];
53
-
54
46
  // initialization =============================================================
55
-
56
47
  /**
57
48
  * All supported global browser symbols intended to be used without fully
58
49
  * qualified name (e.g. `HTMLElement` instead of `window.HTMLElement`).
@@ -61,35 +52,30 @@ const RESTRICTED_SYNTAX = [
61
52
  * misspelled variables or parameter names.
62
53
  */
63
54
  const BROWSER_GLOBALS = {};
64
-
65
55
  // Add all builtin ES globals.
66
56
  for (const name of Object.keys(JAVASCRIPT_GLOBALS.builtin)) {
67
57
  BROWSER_GLOBALS[name] = "readonly";
68
58
  }
69
-
70
59
  // Add browser globals (skip writable properties, e.g. window event handlers).
71
60
  for (const [name, writable] of Object.entries(JAVASCRIPT_GLOBALS.browser)) {
72
- if (!writable) { BROWSER_GLOBALS[name] = "readonly"; }
61
+ if (!writable) {
62
+ BROWSER_GLOBALS[name] = "readonly";
63
+ }
73
64
  }
74
-
75
65
  // Remove commonly known confusing or deprecated builtin globals.
76
66
  for (const name of CONFUSING_BUILTIN_GLOBALS) {
77
67
  delete BROWSER_GLOBALS[name];
78
68
  }
79
-
80
69
  // Remove commonly known confusing browser globals (e.g. `name`, `event`).
81
70
  for (const name of CONFUSING_BROWSER_GLOBALS) {
82
71
  delete BROWSER_GLOBALS[name];
83
72
  }
84
-
85
73
  // Create the configuration list for rule "no-restricted-globals".
86
74
  const RESTRICTED_GLOBALS = AMBIGUOUS_BROWSER_TYPES.map(name => {
87
75
  const message = `Import custom type '${name}', or use 'window.${name}' for disambiguation.`;
88
76
  return { name, message };
89
77
  });
90
-
91
78
  // functions ==================================================================
92
-
93
79
  /**
94
80
  * Creates configuration objects with global symbols and linter rules for for
95
81
  * browser modules.
@@ -98,43 +84,36 @@ const RESTRICTED_GLOBALS = AMBIGUOUS_BROWSER_TYPES.map(name => {
98
84
  * - `globals`
99
85
  * - `confusing-browser-globals`
100
86
  *
101
- * @param {import("./browser").EnvBrowserOptions} options
87
+ * @param options
102
88
  * Configuration options for the environment.
103
89
  *
104
- * @returns {import("../shared/types").FlatConfigArray}
90
+ * @returns
105
91
  * An array of configuration objects to be added to the flat configuration.
106
92
  */
107
93
  export default function browser(options) {
108
-
109
94
  // configuration properties
110
95
  const { files, ignores = [], rules } = options;
111
-
112
96
  // generate the "no-restricted-?" rules according to passed configuration
113
97
  const restricted = generateRestrictedRules({
114
98
  globals: RESTRICTED_GLOBALS,
115
99
  properties: RESTRICTED_PROPERTIES,
116
100
  syntax: RESTRICTED_SYNTAX,
117
101
  }, options?.restricted);
118
-
119
102
  return [
120
-
121
103
  // base configuration for the environment
122
104
  {
123
105
  files,
124
106
  ignores,
125
-
126
107
  // register global symbols used in browser scripts
127
108
  languageOptions: {
128
109
  globals: BROWSER_GLOBALS,
129
110
  },
130
-
131
111
  // configure rules
132
112
  rules: {
133
113
  ...restricted.rules,
134
114
  ...rules,
135
115
  },
136
116
  },
137
-
138
117
  // "no-restricted-?" rules overrides for specific files
139
118
  ...restricted.overrides,
140
119
  ];
@@ -0,0 +1,22 @@
1
+ import type { TSESLint } from "@typescript-eslint/utils";
2
+ import type { EnvBaseOptions } from "../shared/env-utils.js";
3
+ /**
4
+ * Configuration options for the environment preset "env.codecept".
5
+ */
6
+ export interface EnvCodeceptOptions extends EnvBaseOptions {
7
+ }
8
+ /**
9
+ * Creates configuration objects with global symbols and linter rules for E2E
10
+ * tests using CodeceptJS.
11
+ *
12
+ * Wraps the following packages:
13
+ * - `eslint-plugin-codeceptjs`
14
+ * - `eslint-plugin-chai-expect`
15
+ *
16
+ * @param options
17
+ * Configuration options for the environment.
18
+ *
19
+ * @returns
20
+ * An array of configuration objects to be added to the flat configuration.
21
+ */
22
+ export default function codecept(options: EnvCodeceptOptions): TSESLint.FlatConfig.ConfigArray;
@@ -4,12 +4,9 @@
4
4
  * This program is proprietary software and licensed to you under Open-Xchange
5
5
  * GmbH's Software License Agreement.
6
6
  */
7
-
8
7
  import codeceptPlugin from "eslint-plugin-codeceptjs";
9
8
  import chaiExpectPlugin from "eslint-plugin-chai-expect";
10
-
11
9
  // functions ==================================================================
12
-
13
10
  /**
14
11
  * Creates configuration objects with global symbols and linter rules for E2E
15
12
  * tests using CodeceptJS.
@@ -18,49 +15,43 @@ import chaiExpectPlugin from "eslint-plugin-chai-expect";
18
15
  * - `eslint-plugin-codeceptjs`
19
16
  * - `eslint-plugin-chai-expect`
20
17
  *
21
- * @param {import("./codecept").EnvCodeceptOptions} options
18
+ * @param options
22
19
  * Configuration options for the environment.
23
20
  *
24
- * @returns {import("../shared/types").FlatConfigArray}
21
+ * @returns
25
22
  * An array of configuration objects to be added to the flat configuration.
26
23
  */
27
24
  export default function codecept(options) {
28
-
29
25
  // configuration properties
30
26
  const { files, ignores = [], rules } = options;
31
-
32
27
  return [
33
28
  {
34
29
  files,
35
30
  ignores,
36
-
37
31
  // register rule implementations of the plugins
38
32
  plugins: {
39
33
  codeceptjs: codeceptPlugin,
40
34
  },
41
-
42
35
  // register global symbols of CodeceptJS
43
36
  languageOptions: {
44
37
  globals: {
45
38
  ...codeceptPlugin.environments.codeceptjs.globals,
46
39
  },
47
40
  },
48
-
49
41
  // configure plugin rules
50
42
  rules: {
51
43
  // recommended rules
52
44
  ...codeceptPlugin.configs.recommended.rules,
53
45
  // extra rules
54
46
  "new-cap": ["error", {
55
- capIsNewExceptions: ["After", "AfterSuite", "Before", "BeforeSuite", "Feature", "Scenario"],
56
- }],
47
+ capIsNewExceptions: ["After", "AfterSuite", "Before", "BeforeSuite", "Feature", "Scenario"],
48
+ }],
57
49
  "no-restricted-properties": ["warn", { object: "Scenario", property: "todo", message: "Unexpected unimplemented test." }],
58
50
  "codeceptjs/no-skipped-tests": "warn",
59
51
  // custom rules
60
52
  ...rules,
61
53
  },
62
54
  },
63
-
64
55
  {
65
56
  files,
66
57
  ignores,
@@ -0,0 +1,20 @@
1
+ import type { TSESLint } from "@typescript-eslint/utils";
2
+ import type { EnvBaseOptions } from "../shared/env-utils.js";
3
+ /**
4
+ * Configuration options for the environment preset "env.eslint".
5
+ */
6
+ export interface EnvEslintOptions extends EnvBaseOptions {
7
+ }
8
+ /**
9
+ * Adds linter rules for ESLint plugin implementations.
10
+ *
11
+ * Wraps the following packages:
12
+ * - `eslint-plugin-eslint-plugin`
13
+ *
14
+ * @param options
15
+ * Configuration options for the environment.
16
+ *
17
+ * @returns
18
+ * An array of configuration objects to be added to the flat configuration.
19
+ */
20
+ export default function eslint(options: EnvEslintOptions): TSESLint.FlatConfig.ConfigArray;
@@ -1,36 +1,29 @@
1
-
2
1
  import eslintPlugin from "eslint-plugin-eslint-plugin";
3
-
4
2
  // exports ====================================================================
5
-
6
3
  /**
7
4
  * Adds linter rules for ESLint plugin implementations.
8
5
  *
9
6
  * Wraps the following packages:
10
7
  * - `eslint-plugin-eslint-plugin`
11
8
  *
12
- * @param {import("./eslint").EnvEslintOptions} options
9
+ * @param options
13
10
  * Configuration options for the environment.
14
11
  *
15
- * @returns {import("../shared/types").FlatConfigArray}
12
+ * @returns
16
13
  * An array of configuration objects to be added to the flat configuration.
17
14
  */
18
15
  export default function eslint(options) {
19
-
20
16
  // configuration properties
21
17
  const { files, ignores = [], rules = {} } = options;
22
18
  // the plugin configuration
23
19
  const pluginConfig = eslintPlugin.configs["flat/rules-recommended"];
24
-
25
20
  return [
26
-
27
21
  // register rule implementations and recommended rules
28
22
  {
29
23
  files,
30
24
  ignores,
31
25
  ...pluginConfig,
32
26
  },
33
-
34
27
  // reconfigure plugin rules
35
28
  {
36
29
  files,
@@ -0,0 +1,21 @@
1
+ import type { TSESLint } from "@typescript-eslint/utils";
2
+ import type { EnvBaseOptions } from "../shared/env-utils.js";
3
+ /**
4
+ * Configuration options for the environment preset "env.jest".
5
+ */
6
+ export interface EnvJestOptions extends EnvBaseOptions {
7
+ }
8
+ /**
9
+ * Creates configuration objects with global symbols and linter rules for unit
10
+ * tests using Jest.
11
+ *
12
+ * Wraps the following packages:
13
+ * - `eslint-plugin-jest`
14
+ *
15
+ * @param options
16
+ * Configuration options for the environment.
17
+ *
18
+ * @returns
19
+ * An array of configuration objects to be added to the flat configuration.
20
+ */
21
+ export default function jest(options: EnvJestOptions): TSESLint.FlatConfig.ConfigArray;
@@ -0,0 +1,49 @@
1
+ import jestPlugin from "eslint-plugin-jest";
2
+ // functions ==================================================================
3
+ /**
4
+ * Creates configuration objects with global symbols and linter rules for unit
5
+ * tests using Jest.
6
+ *
7
+ * Wraps the following packages:
8
+ * - `eslint-plugin-jest`
9
+ *
10
+ * @param options
11
+ * Configuration options for the environment.
12
+ *
13
+ * @returns
14
+ * An array of configuration objects to be added to the flat configuration.
15
+ */
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
+ }];
49
+ }
@@ -0,0 +1,30 @@
1
+ import type { TSESLint } from "@typescript-eslint/utils";
2
+ import type { LanguageOptions, EnvBaseOptions, EnvRestrictedOptions } from "../shared/env-utils.js";
3
+ /**
4
+ * Configuration options for the environment preset "env.node".
5
+ */
6
+ export interface EnvNodeOptions extends EnvBaseOptions {
7
+ /**
8
+ * The module mode used by the linted files. Default value is "module".
9
+ */
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
+ }
17
+ /**
18
+ * Creates configuration objects with global symbols and linter rules for
19
+ * NodeJS modules.
20
+ *
21
+ * Wraps the following packages:
22
+ * - `eslint-plugin-n`
23
+ *
24
+ * @param options
25
+ * Configuration options for the environment.
26
+ *
27
+ * @returns
28
+ * An array of configuration objects to be added to the flat configuration.
29
+ */
30
+ export default function node(options: EnvNodeOptions): TSESLint.FlatConfig.ConfigArray;
@@ -1,12 +1,6 @@
1
-
2
- // replacement for abandoned "eslint-plugin-node"
3
- // - https://github.com/mysticatea/eslint-plugin-node/issues/341
4
1
  import nodePlugin from "eslint-plugin-n";
5
-
6
2
  import { generateRestrictedRules } from "../shared/env-utils.js";
7
-
8
3
  // functions ==================================================================
9
-
10
4
  /**
11
5
  * Creates configuration objects with global symbols and linter rules for
12
6
  * NodeJS modules.
@@ -14,25 +8,21 @@ import { generateRestrictedRules } from "../shared/env-utils.js";
14
8
  * Wraps the following packages:
15
9
  * - `eslint-plugin-n`
16
10
  *
17
- * @param {import("./node").EnvNodeOptions} options
11
+ * @param options
18
12
  * Configuration options for the environment.
19
13
  *
20
- * @returns {import("../shared/types").FlatConfigArray}
14
+ * @returns
21
15
  * An array of configuration objects to be added to the flat configuration.
22
16
  */
23
17
  export default function node(options) {
24
-
25
18
  // configuration properties
26
19
  const { files, ignores = [], sourceType = "module", rules } = options;
27
20
  // the plugin configuration
28
21
  const configKey = (sourceType === "commonjs") ? "flat/recommended-script" : "flat/recommended-module";
29
22
  const nodeConfig = nodePlugin.configs[configKey];
30
-
31
23
  // generate the "no-restricted-?" rules according to passed configuration
32
24
  const restricted = generateRestrictedRules({}, options?.restricted);
33
-
34
25
  return [
35
-
36
26
  // register rule implementations
37
27
  {
38
28
  files,
@@ -44,7 +34,6 @@ export default function node(options) {
44
34
  },
45
35
  },
46
36
  },
47
-
48
37
  // reconfigure plugin rules
49
38
  {
50
39
  files,
@@ -56,7 +45,6 @@ export default function node(options) {
56
45
  ...rules,
57
46
  },
58
47
  },
59
-
60
48
  // "no-restricted-?" rules overrides for specific files
61
49
  ...restricted.overrides,
62
50
  ];
@@ -0,0 +1,18 @@
1
+ import type { TSESLint } from "@typescript-eslint/utils";
2
+ import type { EnvBaseOptions } from "../shared/env-utils.js";
3
+ import { type RuleNoInvalidModulesOptions } from "../rules/no-invalid-modules.js";
4
+ /**
5
+ * Configuration options for the environment preset "env.project".
6
+ */
7
+ export interface EnvProjectOptions extends EnvBaseOptions, RuleNoInvalidModulesOptions {
8
+ }
9
+ /**
10
+ * Adds custom linter rules for checking project setup and module hierarchy.
11
+ *
12
+ * @param options
13
+ * Configuration options for the environment.
14
+ *
15
+ * @returns
16
+ * An array of configuration objects to be added to the flat configuration.
17
+ */
18
+ export default function project(options: EnvProjectOptions): TSESLint.FlatConfig.ConfigArray;
@@ -18,45 +18,38 @@
18
18
  * Any use of the work other than as authorized under this license or copyright law is prohibited.
19
19
  *
20
20
  */
21
-
22
21
  import noAmdModuleDirective from "../rules/no-amd-module-directive.js";
23
22
  import noInvalidModules from "../rules/no-invalid-modules.js";
24
-
25
23
  // exports ====================================================================
26
-
27
24
  /**
28
25
  * Adds custom linter rules for checking project setup and module hierarchy.
29
26
  *
30
- * @param {import("./project").EnvProjectOptions} options
27
+ * @param options
31
28
  * Configuration options for the environment.
32
29
  *
33
- * @returns {import("../shared/types").FlatConfigArray}
30
+ * @returns
34
31
  * An array of configuration objects to be added to the flat configuration.
35
32
  */
36
33
  export default function project(options) {
37
-
38
34
  // configuration properties
39
35
  const { files, ignores = [], rules, ...rest } = options;
40
-
41
36
  return [{
42
- files,
43
- ignores,
44
-
45
- // register rule implementations
46
- plugins: {
47
- "env-project": {
48
- rules: {
49
- "no-amd-module-directive": noAmdModuleDirective,
50
- "no-invalid-modules": noInvalidModules,
37
+ files,
38
+ ignores,
39
+ // register rule implementations
40
+ plugins: {
41
+ "env-project": {
42
+ rules: {
43
+ "no-amd-module-directive": noAmdModuleDirective,
44
+ "no-invalid-modules": noInvalidModules,
45
+ },
51
46
  },
52
47
  },
53
- },
54
-
55
- // configure rules
56
- rules: {
57
- "env-project/no-amd-module-directive": "error",
58
- "env-project/no-invalid-modules": ["error", rest],
59
- ...rules,
60
- },
61
- }];
48
+ // configure rules
49
+ rules: {
50
+ "env-project/no-amd-module-directive": "error",
51
+ "env-project/no-invalid-modules": ["error", rest],
52
+ ...rules,
53
+ },
54
+ }];
62
55
  }