@open-turo/eslint-config-typescript 16.0.0-pr-373.7.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/index.cjs CHANGED
@@ -10,23 +10,31 @@ 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
- module.exports = tseslint.config(
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
- languageOptions: {
27
- parser: tsParser,
28
- parserOptions: {
29
- projectService: true,
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
+ },
30
38
  },
31
39
  },
32
40
  rules: {
@@ -36,17 +44,31 @@ module.exports = tseslint.config(
36
44
  "import/no-default-export": "error",
37
45
  "import/no-extraneous-dependencies": [
38
46
  "error",
39
- { devDependencies: ["test/**"] },
47
+ { devDependencies: [`eslint.config.${FILES_SRC_EXTENSION}`] },
40
48
  ],
41
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: {
42
57
  "n/no-unpublished-import": [
43
58
  "error",
44
59
  {
45
- allowModules: ["@jest/globals", "nock"],
60
+ allowModules,
46
61
  },
47
62
  ],
48
63
  "n/no-unsupported-features/es-syntax": "off",
49
64
  "n/no-missing-import": "off",
65
+ },
66
+ });
67
+
68
+ const sonarJsConfig = () =>
69
+ tseslint.config({
70
+ extends: [sonarjsPlugin.configs.recommended],
71
+ rules: {
50
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.
51
73
  "sonarjs/deprecation": "off",
52
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.
@@ -67,6 +89,18 @@ module.exports = tseslint.config(
67
89
  "sonarjs/todo-tag": "off",
68
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)
69
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: {
70
104
  /**
71
105
  * {@link https://typescript-eslint.io/rules/consistent-type-imports | TypeScript ESLint: consistent-type-imports docs}
72
106
  */
@@ -102,18 +136,15 @@ module.exports = tseslint.config(
102
136
  "@typescript-eslint/prefer-ts-expect-error": "error",
103
137
  "@typescript-eslint/unbound-method": "error",
104
138
  },
105
- },
106
- prettierPluginRecommended,
107
- jsonPlugin.configs["recommended"],
108
- {
109
- files: ["test/**"],
139
+ });
140
+
141
+ const testConfig = () =>
142
+ tseslint.config({
143
+ files: FILES_TEST,
110
144
  plugins: { jest: jestPlugin },
111
145
  languageOptions: {
112
146
  globals: jestPlugin.environments.globals.globals,
113
- parser: tsParser,
114
- parserOptions: {
115
- projectService: true,
116
- },
147
+ ...typescriptLanguageOptions(),
117
148
  },
118
149
  extends: [jestPlugin.configs["flat/recommended"]],
119
150
  rules: {
@@ -122,15 +153,36 @@ module.exports = tseslint.config(
122
153
  "@typescript-eslint/unbound-method": "off",
123
154
  "jest/no-jest-import": "off",
124
155
  "jest/unbound-method": "error",
156
+ "import/no-extraneous-dependencies": [
157
+ "error",
158
+ { devDependencies: FILES_TEST },
159
+ ],
125
160
  },
126
- },
127
- {
128
- settings: {
129
- "import/resolver": {
130
- typescript: {
131
- alwaysTryTypes: true,
132
- },
133
- },
134
- },
135
- },
136
- );
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,136 +1,3 @@
1
- import jestPlugin from "eslint-plugin-jest";
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 tseslint.config(
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
- languageOptions: {
27
- parser: tsParser,
28
- parserOptions: {
29
- projectService: true,
30
- },
31
- },
32
- rules: {
33
- "import/default": "off",
34
- "import/named": "off",
35
- "import/namespace": "off",
36
- "import/no-default-export": "error",
37
- "import/no-extraneous-dependencies": [
38
- "error",
39
- { devDependencies: ["test/**"] },
40
- ],
41
- "import/prefer-default-export": "off",
42
- "n/no-unpublished-import": [
43
- "error",
44
- {
45
- allowModules: ["@jest/globals", "nock"],
46
- },
47
- ],
48
- "n/no-unsupported-features/es-syntax": "off",
49
- "n/no-missing-import": "off",
50
- // 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.
51
- "sonarjs/deprecation": "off",
52
- // 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.
53
- "sonarjs/function-return-type": "off",
54
- // We may want to catch errors but not use the error object directly, just trigger error handling fallbacks within the catch block.
55
- "sonarjs/no-ignored-exceptions": "off",
56
- "sonarjs/no-nested-functions": ["warn", { threshold: 5 }],
57
- "sonarjs/no-small-switch": "off",
58
- // Overlaps with @typescript-eslint/prefer-nullish-coalescing
59
- "sonarjs/prefer-nullish-coalescing": "off",
60
- // Overlaps with @typescript-eslint/no-unused-vars
61
- "sonarjs/no-unused-vars": "off",
62
- // Overlaps with @typescript-eslint/prefer-optional-chain
63
- "sonarjs/prefer-optional-chain": "off",
64
- // 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
65
- "sonarjs/prefer-read-only-props": "off",
66
- // Noisy rule: if we wanted stricter linting of TODOs, we could use unicorn/expiring-todo-comments
67
- "sonarjs/todo-tag": "off",
68
- // A useful rule to consider for libraries to better document (and export) type definitions, but noisy in app usages (especially around redux type definitions)
69
- "sonarjs/use-type-alias": "off",
70
- /**
71
- * {@link https://typescript-eslint.io/rules/consistent-type-imports | TypeScript ESLint: consistent-type-imports docs}
72
- */
73
- "@typescript-eslint/consistent-type-imports": [
74
- "error",
75
- {
76
- disallowTypeAnnotations: true,
77
- fixStyle: "inline-type-imports",
78
- prefer: "type-imports",
79
- },
80
- ],
81
- /** 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`. */
82
- "@typescript-eslint/no-confusing-void-expression": "off",
83
- /** Included as part of `strict-type-checked`, but nothing we want to enforce. */
84
- "@typescript-eslint/no-deprecated": "off",
85
- /** Prefers `import type {}` syntax over `import { type }` if all imports are type-only */
86
- "@typescript-eslint/no-import-type-side-effects": "error",
87
- /** A relatively stylistic rule, downgraded to "off" to limit breaking changes in the update that includes `strict-type-checked`. */
88
- "@typescript-eslint/no-unnecessary-boolean-literal-compare": "off",
89
- /** 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. */
90
- "@typescript-eslint/no-unnecessary-condition": "off",
91
- /** 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. */
92
- "@typescript-eslint/no-unnecessary-type-arguments": "off",
93
- /** Errors on generic type parameters that are only used once, even though that helps with return type inference. */
94
- "@typescript-eslint/no-unnecessary-type-parameters": "off",
95
- "@typescript-eslint/no-unused-vars": [
96
- "error",
97
- {
98
- // Allow to name unused vars with _
99
- argsIgnorePattern: "^_",
100
- },
101
- ],
102
- "@typescript-eslint/prefer-ts-expect-error": "error",
103
- "@typescript-eslint/unbound-method": "error",
104
- },
105
- },
106
- prettierPluginRecommended,
107
- jsonPlugin.configs["recommended"],
108
- {
109
- files: ["test/**/*.{ts,tsx}"],
110
- plugins: { jest: jestPlugin },
111
- languageOptions: {
112
- globals: jestPlugin.environments.globals.globals,
113
- parser: tsParser,
114
- parserOptions: {
115
- projectService: true,
116
- },
117
- },
118
- extends: [jestPlugin.configs["flat/recommended"]],
119
- rules: {
120
- ...jestPlugin.configs["flat/recommended"].rules,
121
- // this turns the original rule off *only* for test files, for jestPlugin compatibility
122
- "@typescript-eslint/unbound-method": "off",
123
- "jest/no-jest-import": "off",
124
- "jest/unbound-method": "error",
125
- },
126
- },
127
- {
128
- settings: {
129
- "import/resolver": {
130
- typescript: {
131
- alwaysTryTypes: true,
132
- },
133
- },
134
- },
135
- },
136
- );
3
+ export default config;
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.7.1.1"
57
+ "version": "16.0.0-pr-373.8.1.1"
58
58
  }