@open-turo/eslint-config-typescript 16.0.0-pr-373.8.1.1 → 16.0.0-pr-373.9.1.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/eslint.config.mjs CHANGED
@@ -1,3 +1,4 @@
1
1
  import openTuroTypescriptConfig from "./index.mjs";
2
2
 
3
- export default openTuroTypescriptConfig;
3
+ // eslint-disable-next-line import/no-default-export
4
+ export default openTuroTypescriptConfig({ typescript: false });
package/index.cjs CHANGED
@@ -1,14 +1,14 @@
1
- const jestPlugin = require("eslint-plugin-jest");
2
- const nPlugin = require("eslint-plugin-n");
1
+ const eslint = require("@eslint/js");
2
+ const tsParser = require("@typescript-eslint/parser");
3
3
  const importPlugin = require("eslint-plugin-import");
4
+ const jestPlugin = require("eslint-plugin-jest");
4
5
  const jsonPlugin = require("eslint-plugin-json");
5
- const eslint = require("@eslint/js");
6
+ const nPlugin = require("eslint-plugin-n");
6
7
  const perfectionistPlugin = require("eslint-plugin-perfectionist");
7
8
  const prettierPluginRecommended = require("eslint-plugin-prettier/recommended");
8
- const tseslint = require("typescript-eslint");
9
9
  const sonarjsPlugin = require("eslint-plugin-sonarjs");
10
10
  const unicornPlugin = require("eslint-plugin-unicorn");
11
- const tsParser = require("@typescript-eslint/parser");
11
+ const tseslint = require("typescript-eslint");
12
12
 
13
13
  const FILES_SRC_EXTENSION = "?([cm])[jt]s?(x)";
14
14
  const FILES_TS = "**/*.?([cm])ts";
@@ -30,13 +30,6 @@ const typescriptLanguageOptions = () => ({
30
30
  const importConfig = () =>
31
31
  tseslint.config({
32
32
  extends: [importPlugin.flatConfigs.recommended],
33
- settings: {
34
- "import/resolver": {
35
- typescript: {
36
- alwaysTryTypes: true,
37
- },
38
- },
39
- },
40
33
  rules: {
41
34
  "import/default": "off",
42
35
  "import/named": "off",
@@ -48,12 +41,23 @@ const importConfig = () =>
48
41
  ],
49
42
  "import/prefer-default-export": "off",
50
43
  },
44
+ settings: {
45
+ "import/resolver": {
46
+ typescript: {
47
+ alwaysTryTypes: true,
48
+ },
49
+ },
50
+ },
51
51
  });
52
52
 
53
53
  const nPluginConfig = (allowModules = ["@jest/globals", "nock"]) =>
54
54
  tseslint.config({
55
- extends: [nPlugin.configs["flat/recommended"]],
55
+ extends: [
56
+ nPlugin.configs["flat/recommended"],
57
+ nPlugin.configs["flat/mixed-esm-and-cjs"],
58
+ ],
56
59
  rules: {
60
+ "n/no-missing-import": "off",
57
61
  "n/no-unpublished-import": [
58
62
  "error",
59
63
  {
@@ -61,7 +65,6 @@ const nPluginConfig = (allowModules = ["@jest/globals", "nock"]) =>
61
65
  },
62
66
  ],
63
67
  "n/no-unsupported-features/es-syntax": "off",
64
- "n/no-missing-import": "off",
65
68
  },
66
69
  });
67
70
 
@@ -77,10 +80,10 @@ const sonarJsConfig = () =>
77
80
  "sonarjs/no-ignored-exceptions": "off",
78
81
  "sonarjs/no-nested-functions": ["warn", { threshold: 5 }],
79
82
  "sonarjs/no-small-switch": "off",
80
- // Overlaps with @typescript-eslint/prefer-nullish-coalescing
81
- "sonarjs/prefer-nullish-coalescing": "off",
82
83
  // Overlaps with @typescript-eslint/no-unused-vars
83
84
  "sonarjs/no-unused-vars": "off",
85
+ // Overlaps with @typescript-eslint/prefer-nullish-coalescing
86
+ "sonarjs/prefer-nullish-coalescing": "off",
84
87
  // Overlaps with @typescript-eslint/prefer-optional-chain
85
88
  "sonarjs/prefer-optional-chain": "off",
86
89
  // Useful for guarding against prop mutation in React, but too much of a lift as very rarely do we apply readonly/ReadonlyArray<T> to type definitions
@@ -94,11 +97,11 @@ const sonarJsConfig = () =>
94
97
 
95
98
  const typescriptConfig = () =>
96
99
  tseslint.config({
97
- files: [FILES_TS, FILES_TSX],
98
100
  extends: [
99
101
  tseslint.configs.recommendedTypeChecked,
100
102
  importPlugin.flatConfigs.typescript,
101
103
  ],
104
+ files: [FILES_TS, FILES_TSX],
102
105
  languageOptions: typescriptLanguageOptions(),
103
106
  rules: {
104
107
  /**
@@ -138,31 +141,43 @@ const typescriptConfig = () =>
138
141
  },
139
142
  });
140
143
 
141
- const testConfig = () =>
142
- tseslint.config({
144
+ /**
145
+ *
146
+ * @param options Configuration options
147
+ * @param options.typescript Whether to include typescript rules
148
+ * @returns {ConfigArray}
149
+ */
150
+ const testConfig = (options) => {
151
+ const typescriptRules = options.typescript
152
+ ? {
153
+ // this turns the original rule off *only* for test files, for jestPlugin compatibility
154
+ "@typescript-eslint/unbound-method": "off",
155
+ "jest/unbound-method": "error",
156
+ }
157
+ : {};
158
+ return tseslint.config({
159
+ extends: [jestPlugin.configs["flat/recommended"]],
143
160
  files: FILES_TEST,
144
- plugins: { jest: jestPlugin },
145
161
  languageOptions: {
146
162
  globals: jestPlugin.environments.globals.globals,
147
- ...typescriptLanguageOptions(),
163
+ ...(options.typescript ? typescriptLanguageOptions() : {}),
148
164
  },
149
- extends: [jestPlugin.configs["flat/recommended"]],
165
+ plugins: { jest: jestPlugin },
150
166
  rules: {
151
167
  ...jestPlugin.configs["flat/recommended"].rules,
152
- // this turns the original rule off *only* for test files, for jestPlugin compatibility
153
- "@typescript-eslint/unbound-method": "off",
154
- "jest/no-jest-import": "off",
155
- "jest/unbound-method": "error",
168
+ ...typescriptRules,
156
169
  "import/no-extraneous-dependencies": [
157
170
  "error",
158
171
  { devDependencies: FILES_TEST },
159
172
  ],
173
+ "jest/no-jest-import": "off",
160
174
  },
161
175
  });
176
+ };
162
177
 
163
178
  const ignoresConfig = (ignores = []) =>
164
179
  tseslint.config({
165
- ignores: ["**/.yalc", "**/dist"].concat(ignores),
180
+ ignores: ["**/.yalc", "**/dist", ...ignores],
166
181
  });
167
182
 
168
183
  /**
@@ -170,10 +185,13 @@ const ignoresConfig = (ignores = []) =>
170
185
  * @param [options] - Eslint config options
171
186
  * @param [options.allowModules] - List of modules to allow in the n/no-unpublished-import rule
172
187
  * @param [options.ignores] - List of patterns to ignore
188
+ * @param [options.typescript] - Whether to include typescript rules
173
189
  * @returns {ConfigArray}
174
190
  */
175
- module.exports = (options = {}) =>
176
- tseslint.config(
191
+ module.exports = function config(options = {}) {
192
+ const useTypescript =
193
+ options.typescript === undefined ? true : options.typescript;
194
+ return tseslint.config(
177
195
  eslint.configs.recommended,
178
196
  importConfig(),
179
197
  nPluginConfig(options.allowModules),
@@ -182,7 +200,8 @@ module.exports = (options = {}) =>
182
200
  unicornPlugin.configs["flat/recommended"],
183
201
  prettierPluginRecommended,
184
202
  jsonPlugin.configs["recommended"],
185
- typescriptConfig(),
186
- testConfig(),
203
+ useTypescript ? typescriptConfig() : {},
204
+ testConfig({ typescript: useTypescript }),
187
205
  ignoresConfig(options.ignores),
188
206
  );
207
+ };
package/index.mjs CHANGED
@@ -1,3 +1,2 @@
1
- import config from "./index.cjs";
2
-
3
- export default config;
1
+ // eslint-disable-next-line import/no-default-export
2
+ export { default } from "./index.cjs";
package/package.json CHANGED
@@ -54,5 +54,5 @@
54
54
  "access": "public"
55
55
  },
56
56
  "repository": "https://github.com/open-turo/eslint-config-typescript",
57
- "version": "16.0.0-pr-373.8.1.1"
57
+ "version": "16.0.0-pr-373.9.1.1"
58
58
  }
package/recommended.cjs CHANGED
@@ -1,22 +1,8 @@
1
1
  module.exports = {
2
- root: true,
3
2
  env: {
4
3
  es2022: true,
5
4
  jest: true,
6
5
  },
7
- parser: "@typescript-eslint/parser",
8
- plugins: [
9
- "@typescript-eslint",
10
- "eslint-plugin-jest",
11
- "import",
12
- "jest",
13
- "json",
14
- "n",
15
- "perfectionist",
16
- "prettier",
17
- "sonarjs",
18
- "unicorn",
19
- ],
20
6
  extends: [
21
7
  "eslint:recommended",
22
8
  "plugin:@typescript-eslint/recommended-type-checked",
@@ -31,11 +17,6 @@ module.exports = {
31
17
  "plugin:sonarjs/recommended-legacy",
32
18
  "plugin:unicorn/recommended",
33
19
  ],
34
- parserOptions: {
35
- ecmaVersion: "latest",
36
- project: "./tsconfig.json",
37
- sourceType: "module",
38
- },
39
20
  overrides: [
40
21
  {
41
22
  files: ["test/**"],
@@ -47,7 +28,60 @@ module.exports = {
47
28
  },
48
29
  },
49
30
  ],
31
+ parser: "@typescript-eslint/parser",
32
+ parserOptions: {
33
+ ecmaVersion: "latest",
34
+ project: "./tsconfig.json",
35
+ sourceType: "module",
36
+ },
37
+ plugins: [
38
+ "@typescript-eslint",
39
+ "eslint-plugin-jest",
40
+ "import",
41
+ "jest",
42
+ "json",
43
+ "n",
44
+ "perfectionist",
45
+ "prettier",
46
+ "sonarjs",
47
+ "unicorn",
48
+ ],
49
+ root: true,
50
50
  rules: {
51
+ /**
52
+ * {@link https://typescript-eslint.io/rules/consistent-type-imports | TypeScript ESLint: consistent-type-imports docs}
53
+ */
54
+ "@typescript-eslint/consistent-type-imports": [
55
+ "error",
56
+ {
57
+ disallowTypeAnnotations: true,
58
+ fixStyle: "inline-type-imports",
59
+ prefer: "type-imports",
60
+ },
61
+ ],
62
+ /** We do not need to force people to wrap `void`-return implicit arrow returns with braces just for a lint rule. TypeScript alone covers functionality, by the return type being `void`. */
63
+ "@typescript-eslint/no-confusing-void-expression": "off",
64
+ /** Included as part of `strict-type-checked`, but nothing we want to enforce. */
65
+ "@typescript-eslint/no-deprecated": "off",
66
+ /** Prefers `import type {}` syntax over `import { type }` if all imports are type-only */
67
+ "@typescript-eslint/no-import-type-side-effects": "error",
68
+ /** A relatively stylistic rule, downgraded to "off" to limit breaking changes in the update that includes `strict-type-checked`. */
69
+ "@typescript-eslint/no-unnecessary-boolean-literal-compare": "off",
70
+ /** This rule can help us identify syntax that is more defensive than the types suggest. Unfortunately, it may be protecting us from runtime errors where the type definitions are incorrect. As such, it is turned "off", as even "warn" auto-fixes source code. */
71
+ "@typescript-eslint/no-unnecessary-condition": "off",
72
+ /** There is readability benefit to passing in type arguments that match defaults. If defaults change, we may prefer the manual inspection of all the types changed, too. */
73
+ "@typescript-eslint/no-unnecessary-type-arguments": "off",
74
+ /** Errors on generic type parameters that are only used once, even though that helps with return type inference. */
75
+ "@typescript-eslint/no-unnecessary-type-parameters": "off",
76
+ "@typescript-eslint/no-unused-vars": [
77
+ "error",
78
+ {
79
+ // Allow to name unused vars with _
80
+ argsIgnorePattern: "^_",
81
+ },
82
+ ],
83
+ "@typescript-eslint/prefer-ts-expect-error": "error",
84
+ "@typescript-eslint/unbound-method": "error",
51
85
  "import/default": "off",
52
86
  "import/named": "off",
53
87
  "import/namespace": "off",
@@ -59,6 +93,7 @@ module.exports = {
59
93
  "import/prefer-default-export": "off",
60
94
  "jest/no-jest-import": "off",
61
95
  "json/*": "error",
96
+ "n/no-missing-import": "off",
62
97
  "n/no-unpublished-import": [
63
98
  "error",
64
99
  {
@@ -66,7 +101,6 @@ module.exports = {
66
101
  },
67
102
  ],
68
103
  "n/no-unsupported-features/es-syntax": "off",
69
- "n/no-missing-import": "off",
70
104
  // Noisy rule - we may have helpers/methods that we mark as @deprecated but aren't planning to remove in the near future. This rule also significantly adds to eslint running time, which slows down both local development and CI.
71
105
  "sonarjs/deprecation": "off",
72
106
  // This rule is not helpful in TypeScript files, and in JavaScript we often return different types from functions, so this is not a strictness level we want to enforce.
@@ -75,10 +109,10 @@ module.exports = {
75
109
  "sonarjs/no-ignored-exceptions": "off",
76
110
  "sonarjs/no-nested-functions": ["warn", { threshold: 5 }],
77
111
  "sonarjs/no-small-switch": "off",
78
- // Overlaps with @typescript-eslint/prefer-nullish-coalescing
79
- "sonarjs/prefer-nullish-coalescing": "off",
80
112
  // Overlaps with @typescript-eslint/no-unused-vars
81
113
  "sonarjs/no-unused-vars": "off",
114
+ // Overlaps with @typescript-eslint/prefer-nullish-coalescing
115
+ "sonarjs/prefer-nullish-coalescing": "off",
82
116
  // Overlaps with @typescript-eslint/prefer-optional-chain
83
117
  "sonarjs/prefer-optional-chain": "off",
84
118
  // Useful for guarding against prop mutation in React, but too much of a lift as very rarely do we apply readonly/ReadonlyArray<T> to type definitions
@@ -87,40 +121,6 @@ module.exports = {
87
121
  "sonarjs/todo-tag": "off",
88
122
  // A useful rule to consider for libraries to better document (and export) type definitions, but noisy in app usages (especially around redux type definitions)
89
123
  "sonarjs/use-type-alias": "off",
90
- /**
91
- * {@link https://typescript-eslint.io/rules/consistent-type-imports | TypeScript ESLint: consistent-type-imports docs}
92
- */
93
- "@typescript-eslint/consistent-type-imports": [
94
- "error",
95
- {
96
- disallowTypeAnnotations: true,
97
- fixStyle: "inline-type-imports",
98
- prefer: "type-imports",
99
- },
100
- ],
101
- /** We do not need to force people to wrap `void`-return implicit arrow returns with braces just for a lint rule. TypeScript alone covers functionality, by the return type being `void`. */
102
- "@typescript-eslint/no-confusing-void-expression": "off",
103
- /** Included as part of `strict-type-checked`, but nothing we want to enforce. */
104
- "@typescript-eslint/no-deprecated": "off",
105
- /** Prefers `import type {}` syntax over `import { type }` if all imports are type-only */
106
- "@typescript-eslint/no-import-type-side-effects": "error",
107
- /** A relatively stylistic rule, downgraded to "off" to limit breaking changes in the update that includes `strict-type-checked`. */
108
- "@typescript-eslint/no-unnecessary-boolean-literal-compare": "off",
109
- /** This rule can help us identify syntax that is more defensive than the types suggest. Unfortunately, it may be protecting us from runtime errors where the type definitions are incorrect. As such, it is turned "off", as even "warn" auto-fixes source code. */
110
- "@typescript-eslint/no-unnecessary-condition": "off",
111
- /** There is readability benefit to passing in type arguments that match defaults. If defaults change, we may prefer the manual inspection of all the types changed, too. */
112
- "@typescript-eslint/no-unnecessary-type-arguments": "off",
113
- /** Errors on generic type parameters that are only used once, even though that helps with return type inference. */
114
- "@typescript-eslint/no-unnecessary-type-parameters": "off",
115
- "@typescript-eslint/no-unused-vars": [
116
- "error",
117
- {
118
- // Allow to name unused vars with _
119
- argsIgnorePattern: "^_",
120
- },
121
- ],
122
- "@typescript-eslint/prefer-ts-expect-error": "error",
123
- "@typescript-eslint/unbound-method": "error",
124
124
  },
125
125
  settings: {
126
126
  "import/parsers": {
package/test/test.spec.js CHANGED
@@ -1,6 +1,4 @@
1
1
  import { loadESLint } from "eslint";
2
- import { fileURLToPath } from "node:url";
3
- import path from "node:path";
4
2
 
5
3
  describe("validate config", () => {
6
4
  test.each(["./index.mjs", "./index.cjs", "./recommended.cjs"])(
@@ -12,8 +10,6 @@ describe("validate config", () => {
12
10
  useFlatConfig,
13
11
  });
14
12
  const linter = new ESLint({
15
- // cwd: cwd,
16
- overrideConfigFile: config,
17
13
  overrideConfig: useFlatConfig
18
14
  ? [
19
15
  {
@@ -34,6 +30,8 @@ describe("validate config", () => {
34
30
  },
35
31
  },
36
32
  },
33
+ // cwd: cwd,
34
+ overrideConfigFile: config,
37
35
  });
38
36
  const messages = await linter.lintText(
39
37
  `const foo = 1;\nconsole.log(foo);\n`,