@open-turo/eslint-config-typescript 16.0.0-pr-373.6.1.1 → 16.0.0-pr-373.8.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/README.md
CHANGED
|
@@ -24,7 +24,7 @@ npx install-peerdeps --dev @open-turo/eslint-config-typescript
|
|
|
24
24
|
```js
|
|
25
25
|
const turoConfig = require("@open-turo/eslint-config-typescript");
|
|
26
26
|
|
|
27
|
-
module.exports = turoConfig;
|
|
27
|
+
module.exports = turoConfig();
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
### **[.eslintrc](https://eslint.org/docs/latest/use/configure/configuration-files)** (legacy example)
|
package/eslint.config.mjs
CHANGED
|
@@ -1,23 +1,3 @@
|
|
|
1
1
|
import openTuroTypescriptConfig from "./index.mjs";
|
|
2
|
-
import jestPlugin from "eslint-plugin-jest";
|
|
3
2
|
|
|
4
|
-
export default
|
|
5
|
-
...openTuroTypescriptConfig,
|
|
6
|
-
{
|
|
7
|
-
files: ["*.cjs", "*.mjs", "test/**/*.js"],
|
|
8
|
-
languageOptions: {
|
|
9
|
-
parserOptions: {
|
|
10
|
-
projectService: {
|
|
11
|
-
// This project doesn't use Typescript and a lot of our rules require type checking
|
|
12
|
-
allowDefaultProject: [
|
|
13
|
-
"index.mjs",
|
|
14
|
-
"index.cjs",
|
|
15
|
-
"eslint.config.mjs",
|
|
16
|
-
"recommended.cjs",
|
|
17
|
-
"test/test.spec.js",
|
|
18
|
-
],
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
];
|
|
3
|
+
export default openTuroTypescriptConfig;
|
package/index.cjs
CHANGED
|
@@ -10,19 +10,33 @@ const sonarjsPlugin = require("eslint-plugin-sonarjs");
|
|
|
10
10
|
const unicornPlugin = require("eslint-plugin-unicorn");
|
|
11
11
|
const tsParser = require("@typescript-eslint/parser");
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
13
|
+
const FILES_SRC_EXTENSION = "?([cm])[jt]s?(x)";
|
|
14
|
+
const FILES_TS = "**/*.?([cm])ts";
|
|
15
|
+
const FILES_TSX = "**/*.?([cm])tsx";
|
|
16
|
+
const FILES_TEST = [
|
|
17
|
+
`**/__tests__/**/*.${FILES_SRC_EXTENSION}`,
|
|
18
|
+
`**/*.spec.${FILES_SRC_EXTENSION}`,
|
|
19
|
+
`**/*.test.${FILES_SRC_EXTENSION}`,
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
const typescriptLanguageOptions = () => ({
|
|
23
|
+
parser: tsParser,
|
|
24
|
+
parserOptions: {
|
|
25
|
+
projectService: true,
|
|
26
|
+
tsconfigRootDir: process.cwd(),
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const importConfig = () =>
|
|
31
|
+
tseslint.config({
|
|
32
|
+
extends: [importPlugin.flatConfigs.recommended],
|
|
33
|
+
settings: {
|
|
34
|
+
"import/resolver": {
|
|
35
|
+
typescript: {
|
|
36
|
+
alwaysTryTypes: true,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
26
40
|
rules: {
|
|
27
41
|
"import/default": "off",
|
|
28
42
|
"import/named": "off",
|
|
@@ -30,17 +44,31 @@ module.exports = tseslint.config(
|
|
|
30
44
|
"import/no-default-export": "error",
|
|
31
45
|
"import/no-extraneous-dependencies": [
|
|
32
46
|
"error",
|
|
33
|
-
{ devDependencies: [
|
|
47
|
+
{ devDependencies: [`eslint.config.${FILES_SRC_EXTENSION}`] },
|
|
34
48
|
],
|
|
35
49
|
"import/prefer-default-export": "off",
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const nPluginConfig = (allowModules = ["@jest/globals", "nock"]) =>
|
|
54
|
+
tseslint.config({
|
|
55
|
+
extends: [nPlugin.configs["flat/recommended"]],
|
|
56
|
+
rules: {
|
|
36
57
|
"n/no-unpublished-import": [
|
|
37
58
|
"error",
|
|
38
59
|
{
|
|
39
|
-
allowModules
|
|
60
|
+
allowModules,
|
|
40
61
|
},
|
|
41
62
|
],
|
|
42
63
|
"n/no-unsupported-features/es-syntax": "off",
|
|
43
64
|
"n/no-missing-import": "off",
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const sonarJsConfig = () =>
|
|
69
|
+
tseslint.config({
|
|
70
|
+
extends: [sonarjsPlugin.configs.recommended],
|
|
71
|
+
rules: {
|
|
44
72
|
// 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.
|
|
45
73
|
"sonarjs/deprecation": "off",
|
|
46
74
|
// 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.
|
|
@@ -61,6 +89,18 @@ module.exports = tseslint.config(
|
|
|
61
89
|
"sonarjs/todo-tag": "off",
|
|
62
90
|
// A useful rule to consider for libraries to better document (and export) type definitions, but noisy in app usages (especially around redux type definitions)
|
|
63
91
|
"sonarjs/use-type-alias": "off",
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const typescriptConfig = () =>
|
|
96
|
+
tseslint.config({
|
|
97
|
+
files: [FILES_TS, FILES_TSX],
|
|
98
|
+
extends: [
|
|
99
|
+
tseslint.configs.recommendedTypeChecked,
|
|
100
|
+
importPlugin.flatConfigs.typescript,
|
|
101
|
+
],
|
|
102
|
+
languageOptions: typescriptLanguageOptions(),
|
|
103
|
+
rules: {
|
|
64
104
|
/**
|
|
65
105
|
* {@link https://typescript-eslint.io/rules/consistent-type-imports | TypeScript ESLint: consistent-type-imports docs}
|
|
66
106
|
*/
|
|
@@ -96,14 +136,15 @@ module.exports = tseslint.config(
|
|
|
96
136
|
"@typescript-eslint/prefer-ts-expect-error": "error",
|
|
97
137
|
"@typescript-eslint/unbound-method": "error",
|
|
98
138
|
},
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
{
|
|
103
|
-
files:
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
const testConfig = () =>
|
|
142
|
+
tseslint.config({
|
|
143
|
+
files: FILES_TEST,
|
|
104
144
|
plugins: { jest: jestPlugin },
|
|
105
145
|
languageOptions: {
|
|
106
146
|
globals: jestPlugin.environments.globals.globals,
|
|
147
|
+
...typescriptLanguageOptions(),
|
|
107
148
|
},
|
|
108
149
|
extends: [jestPlugin.configs["flat/recommended"]],
|
|
109
150
|
rules: {
|
|
@@ -112,22 +153,36 @@ module.exports = tseslint.config(
|
|
|
112
153
|
"@typescript-eslint/unbound-method": "off",
|
|
113
154
|
"jest/no-jest-import": "off",
|
|
114
155
|
"jest/unbound-method": "error",
|
|
156
|
+
"import/no-extraneous-dependencies": [
|
|
157
|
+
"error",
|
|
158
|
+
{ devDependencies: FILES_TEST },
|
|
159
|
+
],
|
|
115
160
|
},
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
)
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
const ignoresConfig = (ignores = []) =>
|
|
164
|
+
tseslint.config({
|
|
165
|
+
ignores: ["**/.yalc", "**/dist"].concat(ignores),
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Turo eslint configuration for typescript
|
|
170
|
+
* @param [options] - Eslint config options
|
|
171
|
+
* @param [options.allowModules] - List of modules to allow in the n/no-unpublished-import rule
|
|
172
|
+
* @param [options.ignores] - List of patterns to ignore
|
|
173
|
+
* @returns {ConfigArray}
|
|
174
|
+
*/
|
|
175
|
+
module.exports = (options = {}) =>
|
|
176
|
+
tseslint.config(
|
|
177
|
+
eslint.configs.recommended,
|
|
178
|
+
importConfig(),
|
|
179
|
+
nPluginConfig(options.allowModules),
|
|
180
|
+
perfectionistPlugin.configs["recommended-alphabetical"],
|
|
181
|
+
sonarJsConfig(),
|
|
182
|
+
unicornPlugin.configs["flat/recommended"],
|
|
183
|
+
prettierPluginRecommended,
|
|
184
|
+
jsonPlugin.configs["recommended"],
|
|
185
|
+
typescriptConfig(),
|
|
186
|
+
testConfig(),
|
|
187
|
+
ignoresConfig(options.ignores),
|
|
188
|
+
);
|
package/index.mjs
CHANGED
|
@@ -1,133 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import nPlugin from "eslint-plugin-n";
|
|
3
|
-
import importPlugin from "eslint-plugin-import";
|
|
4
|
-
import jsonPlugin from "eslint-plugin-json";
|
|
5
|
-
import eslint from "@eslint/js";
|
|
6
|
-
import perfectionistPlugin from "eslint-plugin-perfectionist";
|
|
7
|
-
import prettierPluginRecommended from "eslint-plugin-prettier/recommended";
|
|
8
|
-
import tseslint from "typescript-eslint";
|
|
9
|
-
import sonarjsPlugin from "eslint-plugin-sonarjs";
|
|
10
|
-
import unicornPlugin from "eslint-plugin-unicorn";
|
|
11
|
-
import tsParser from "@typescript-eslint/parser";
|
|
1
|
+
import config from "./index.cjs";
|
|
12
2
|
|
|
13
|
-
export default
|
|
14
|
-
{
|
|
15
|
-
files: ["**/*.ts", "**/*.tsx"],
|
|
16
|
-
extends: [
|
|
17
|
-
eslint.configs.recommended,
|
|
18
|
-
tseslint.configs.recommendedTypeChecked,
|
|
19
|
-
importPlugin.flatConfigs.recommended,
|
|
20
|
-
importPlugin.flatConfigs.typescript,
|
|
21
|
-
nPlugin.configs["flat/recommended-script"],
|
|
22
|
-
perfectionistPlugin.configs["recommended-alphabetical"],
|
|
23
|
-
sonarjsPlugin.configs.recommended,
|
|
24
|
-
unicornPlugin.configs["flat/recommended"],
|
|
25
|
-
],
|
|
26
|
-
rules: {
|
|
27
|
-
"import/default": "off",
|
|
28
|
-
"import/named": "off",
|
|
29
|
-
"import/namespace": "off",
|
|
30
|
-
"import/no-default-export": "error",
|
|
31
|
-
"import/no-extraneous-dependencies": [
|
|
32
|
-
"error",
|
|
33
|
-
{ devDependencies: ["test/**"] },
|
|
34
|
-
],
|
|
35
|
-
"import/prefer-default-export": "off",
|
|
36
|
-
"n/no-unpublished-import": [
|
|
37
|
-
"error",
|
|
38
|
-
{
|
|
39
|
-
allowModules: ["@jest/globals", "nock"],
|
|
40
|
-
},
|
|
41
|
-
],
|
|
42
|
-
"n/no-unsupported-features/es-syntax": "off",
|
|
43
|
-
"n/no-missing-import": "off",
|
|
44
|
-
// 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.
|
|
45
|
-
"sonarjs/deprecation": "off",
|
|
46
|
-
// 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.
|
|
47
|
-
"sonarjs/function-return-type": "off",
|
|
48
|
-
// We may want to catch errors but not use the error object directly, just trigger error handling fallbacks within the catch block.
|
|
49
|
-
"sonarjs/no-ignored-exceptions": "off",
|
|
50
|
-
"sonarjs/no-nested-functions": ["warn", { threshold: 5 }],
|
|
51
|
-
"sonarjs/no-small-switch": "off",
|
|
52
|
-
// Overlaps with @typescript-eslint/prefer-nullish-coalescing
|
|
53
|
-
"sonarjs/prefer-nullish-coalescing": "off",
|
|
54
|
-
// Overlaps with @typescript-eslint/no-unused-vars
|
|
55
|
-
"sonarjs/no-unused-vars": "off",
|
|
56
|
-
// Overlaps with @typescript-eslint/prefer-optional-chain
|
|
57
|
-
"sonarjs/prefer-optional-chain": "off",
|
|
58
|
-
// 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
|
|
59
|
-
"sonarjs/prefer-read-only-props": "off",
|
|
60
|
-
// Noisy rule: if we wanted stricter linting of TODOs, we could use unicorn/expiring-todo-comments
|
|
61
|
-
"sonarjs/todo-tag": "off",
|
|
62
|
-
// A useful rule to consider for libraries to better document (and export) type definitions, but noisy in app usages (especially around redux type definitions)
|
|
63
|
-
"sonarjs/use-type-alias": "off",
|
|
64
|
-
/**
|
|
65
|
-
* {@link https://typescript-eslint.io/rules/consistent-type-imports | TypeScript ESLint: consistent-type-imports docs}
|
|
66
|
-
*/
|
|
67
|
-
"@typescript-eslint/consistent-type-imports": [
|
|
68
|
-
"error",
|
|
69
|
-
{
|
|
70
|
-
disallowTypeAnnotations: true,
|
|
71
|
-
fixStyle: "inline-type-imports",
|
|
72
|
-
prefer: "type-imports",
|
|
73
|
-
},
|
|
74
|
-
],
|
|
75
|
-
/** 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`. */
|
|
76
|
-
"@typescript-eslint/no-confusing-void-expression": "off",
|
|
77
|
-
/** Included as part of `strict-type-checked`, but nothing we want to enforce. */
|
|
78
|
-
"@typescript-eslint/no-deprecated": "off",
|
|
79
|
-
/** Prefers `import type {}` syntax over `import { type }` if all imports are type-only */
|
|
80
|
-
"@typescript-eslint/no-import-type-side-effects": "error",
|
|
81
|
-
/** A relatively stylistic rule, downgraded to "off" to limit breaking changes in the update that includes `strict-type-checked`. */
|
|
82
|
-
"@typescript-eslint/no-unnecessary-boolean-literal-compare": "off",
|
|
83
|
-
/** 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. */
|
|
84
|
-
"@typescript-eslint/no-unnecessary-condition": "off",
|
|
85
|
-
/** 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. */
|
|
86
|
-
"@typescript-eslint/no-unnecessary-type-arguments": "off",
|
|
87
|
-
/** Errors on generic type parameters that are only used once, even though that helps with return type inference. */
|
|
88
|
-
"@typescript-eslint/no-unnecessary-type-parameters": "off",
|
|
89
|
-
"@typescript-eslint/no-unused-vars": [
|
|
90
|
-
"error",
|
|
91
|
-
{
|
|
92
|
-
// Allow to name unused vars with _
|
|
93
|
-
argsIgnorePattern: "^_",
|
|
94
|
-
},
|
|
95
|
-
],
|
|
96
|
-
"@typescript-eslint/prefer-ts-expect-error": "error",
|
|
97
|
-
"@typescript-eslint/unbound-method": "error",
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
prettierPluginRecommended,
|
|
101
|
-
jsonPlugin.configs["recommended"],
|
|
102
|
-
{
|
|
103
|
-
files: ["test/**"],
|
|
104
|
-
plugins: { jest: jestPlugin },
|
|
105
|
-
languageOptions: {
|
|
106
|
-
globals: jestPlugin.environments.globals.globals,
|
|
107
|
-
},
|
|
108
|
-
extends: [jestPlugin.configs["flat/recommended"]],
|
|
109
|
-
rules: {
|
|
110
|
-
...jestPlugin.configs["flat/recommended"].rules,
|
|
111
|
-
// this turns the original rule off *only* for test files, for jestPlugin compatibility
|
|
112
|
-
"@typescript-eslint/unbound-method": "off",
|
|
113
|
-
"jest/no-jest-import": "off",
|
|
114
|
-
"jest/unbound-method": "error",
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
languageOptions: {
|
|
119
|
-
parser: tsParser,
|
|
120
|
-
parserOptions: {
|
|
121
|
-
projectService: true,
|
|
122
|
-
tsconfigRootDir: import.meta.dirname,
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
settings: {
|
|
126
|
-
"import/resolver": {
|
|
127
|
-
typescript: {
|
|
128
|
-
alwaysTryTypes: true,
|
|
129
|
-
},
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
|
-
);
|
|
3
|
+
export default config;
|
|
Binary file
|
package/package.json
CHANGED
|
Binary file
|