@open-turo/eslint-config-typescript 16.0.8 → 17.0.0-pr-382.72.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.
@@ -0,0 +1,3 @@
1
+ # Breaking changes in v17
2
+
3
+ Adds `@typescript-eslint/consistent-type-assertions` configuration, which will raise errors in consumer repos. We have multiple years of relying on `as` casting as a TypeScript work-around (which is dangerous, compared to type-narrowing in runtime code) in our code, so this specific rule change will require a large amount of effort for compliance--even if adding `// eslint-disable` to all existing instances, or adding [eslint-seatbelt](https://www.notion.com/blog/how-we-evolved-our-code-notions-ratcheting-system-using-custom-eslint-rules)--and so we are marking it as a new major version.
package/index.cjs CHANGED
@@ -1,6 +1,3 @@
1
- // @ts-check
2
-
3
- /** @import { ConfigWithExtends } from "typescript-eslint" */
4
1
  const eslint = require("@eslint/js");
5
2
  const tsParser = require("@typescript-eslint/parser");
6
3
  const importPlugin = require("eslint-plugin-import");
@@ -31,13 +28,6 @@ const typescriptLanguageOptions = () => ({
31
28
  },
32
29
  });
33
30
 
34
- /**
35
- * @typedef {NonNullable<NonNullable<ConfigWithExtends['languageOptions']>['parserOptions']>['ecmaVersion']} EcmaVersion
36
- */
37
-
38
- /**
39
- * @param {EcmaVersion} [ecmaVersion]
40
- */
41
31
  const javascriptConfig = (ecmaVersion = "latest") =>
42
32
  tseslint.config(eslint.configs.recommended, {
43
33
  files: [FILES_JS],
@@ -48,19 +38,9 @@ const javascriptConfig = (ecmaVersion = "latest") =>
48
38
  },
49
39
  });
50
40
 
51
- const getImportPluginFlatConfigs = () => {
52
- if (!importPlugin.flatConfigs) {
53
- throw new Error(
54
- "Unexpected value from eslint-plugin-import. You will need to upgrade the plugin.",
55
- );
56
- }
57
-
58
- return importPlugin.flatConfigs;
59
- };
60
-
61
41
  const importConfig = () =>
62
42
  tseslint.config({
63
- extends: [getImportPluginFlatConfigs().recommended],
43
+ extends: [importPlugin.flatConfigs.recommended],
64
44
  rules: {
65
45
  "import/default": "off",
66
46
  "import/named": "off",
@@ -130,12 +110,16 @@ const typescriptConfig = () =>
130
110
  tseslint.config({
131
111
  extends: [
132
112
  tseslint.configs.recommendedTypeChecked,
133
- // @ts-expect-error -- We are inferring the types of this import from runtime, but the rule values are inferred as `string` instead of `RuleEntry` ("off" | "warn" | "error")
134
- getImportPluginFlatConfigs().typescript,
113
+ importPlugin.flatConfigs.typescript,
135
114
  ],
136
115
  files: [FILES_TS, FILES_TSX],
137
116
  languageOptions: typescriptLanguageOptions(),
138
117
  rules: {
118
+ /** Forbids `as` casting (that excludes `as const`) to prevent unsafe type casts */
119
+ "@typescript-eslint/consistent-type-assertions": [
120
+ "error",
121
+ { assertionStyle: "never" },
122
+ ],
139
123
  /**
140
124
  * {@link https://typescript-eslint.io/rules/consistent-type-imports | TypeScript ESLint: consistent-type-imports docs}
141
125
  */
@@ -175,16 +159,17 @@ const typescriptConfig = () =>
175
159
 
176
160
  /**
177
161
  *
178
- * @param {object} options Configuration options
179
- * @param {boolean} options.typescript Whether to include typescript rules
162
+ * @param options Configuration options
163
+ * @param options.typescript Whether to include typescript rules
164
+ * @returns {ConfigArray}
180
165
  */
181
166
  const testConfig = (options) => {
182
167
  const typescriptRules = options.typescript
183
- ? /** @type {const} */ ({
168
+ ? {
184
169
  // this turns the original rule off *only* for test files, for jestPlugin compatibility
185
170
  "@typescript-eslint/unbound-method": "off",
186
171
  "jest/unbound-method": "error",
187
- })
172
+ }
188
173
  : {};
189
174
  return tseslint.config({
190
175
  extends: [jestPlugin.configs["flat/recommended"]],
@@ -206,9 +191,6 @@ const testConfig = (options) => {
206
191
  });
207
192
  };
208
193
 
209
- /**
210
- * @param {string[]} ignores
211
- */
212
194
  const ignoresConfig = (ignores = []) =>
213
195
  tseslint.config({
214
196
  ignores: ["**/.yalc", "**/dist", ...ignores],
@@ -216,16 +198,16 @@ const ignoresConfig = (ignores = []) =>
216
198
 
217
199
  /**
218
200
  * Turo eslint configuration for typescript
219
- * @param {object} [options] - Eslint config options
220
- * @param {string[]} [options.allowModules] - List of modules to allow in the n/no-unpublished-import rule
221
- * @param {string[]} [options.ignores] - List of patterns to ignore
222
- * @param {boolean} [options.typescript] - Whether to include typescript rules
223
- * @param {EcmaVersion} [options.ecmaVersion] - The ECMAScript version to use
201
+ * @param [options] - Eslint config options
202
+ * @param [options.allowModules] - List of modules to allow in the n/no-unpublished-import rule
203
+ * @param [options.ignores] - List of patterns to ignore
204
+ * @param [options.typescript] - Whether to include typescript rules
205
+ * @param [options.ecmaVersion] - The ECMAScript version to use
206
+ * @returns {ConfigArray}
224
207
  */
225
208
  module.exports = function config(options = {}) {
226
209
  const useTypescript =
227
210
  options.typescript === undefined ? true : options.typescript;
228
-
229
211
  return tseslint.config(
230
212
  javascriptConfig(options.ecmaVersion),
231
213
  importConfig(),
package/package.json CHANGED
@@ -4,8 +4,9 @@
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "@eslint/js": "9.29.0",
7
- "@typescript-eslint/eslint-plugin": "8.34.1",
8
- "@typescript-eslint/parser": "8.34.1",
7
+ "typescript-eslint": "8.34.0",
8
+ "@typescript-eslint/eslint-plugin": "8.34.0",
9
+ "@typescript-eslint/parser": "8.34.0",
9
10
  "eslint-config-prettier": "10.1.5",
10
11
  "eslint-import-resolver-typescript": "4.4.3",
11
12
  "eslint-plugin-import": "2.31.0",
@@ -15,8 +16,7 @@
15
16
  "eslint-plugin-perfectionist": "4.14.0",
16
17
  "eslint-plugin-prettier": "5.4.1",
17
18
  "eslint-plugin-sonarjs": "3.0.2",
18
- "eslint-plugin-unicorn": "56.0.1",
19
- "typescript-eslint": "8.34.1"
19
+ "eslint-plugin-unicorn": "56.0.1"
20
20
  },
21
21
  "devDependencies": {
22
22
  "eslint": "9.29.0",
@@ -54,6 +54,6 @@
54
54
  "access": "public"
55
55
  },
56
56
  "repository": "https://github.com/open-turo/eslint-config-typescript",
57
- "version": "16.0.8",
57
+ "version": "17.0.0-pr-382.72.1.1",
58
58
  "packageManager": "npm@11.4.2+sha512.f90c1ec8b207b625d6edb6693aef23dacb39c38e4217fe8c46a973f119cab392ac0de23fe3f07e583188dae9fd9108b3845ad6f525b598742bd060ebad60bff3"
59
59
  }
package/recommended.cjs CHANGED
@@ -48,6 +48,11 @@ module.exports = {
48
48
  ],
49
49
  root: true,
50
50
  rules: {
51
+ /** Forbids `as` casting (that excludes `as const`) to prevent unsafe type casts */
52
+ "@typescript-eslint/consistent-type-assertions": [
53
+ "error",
54
+ { assertionStyle: "never" },
55
+ ],
51
56
  /**
52
57
  * {@link https://typescript-eslint.io/rules/consistent-type-imports | TypeScript ESLint: consistent-type-imports docs}
53
58
  */
@@ -1,4 +1,4 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
1
+ // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2
2
 
3
3
  exports[`validate config the flat config is correct for index.cjs 1`] = `
4
4
  {
@@ -566,6 +566,12 @@ exports[`validate config the flat config is correct for index.cjs 1`] = `
566
566
  "@typescript-eslint/comma-spacing": [
567
567
  0,
568
568
  ],
569
+ "@typescript-eslint/consistent-type-assertions": [
570
+ 2,
571
+ {
572
+ "assertionStyle": "never",
573
+ },
574
+ ],
569
575
  "@typescript-eslint/consistent-type-imports": [
570
576
  2,
571
577
  {
@@ -3535,6 +3541,12 @@ exports[`validate config the flat config is correct for index.mjs 1`] = `
3535
3541
  "@typescript-eslint/comma-spacing": [
3536
3542
  0,
3537
3543
  ],
3544
+ "@typescript-eslint/consistent-type-assertions": [
3545
+ 2,
3546
+ {
3547
+ "assertionStyle": "never",
3548
+ },
3549
+ ],
3538
3550
  "@typescript-eslint/consistent-type-imports": [
3539
3551
  2,
3540
3552
  {
@@ -6507,6 +6519,12 @@ exports[`validate config the legacy recommended config is correct 1`] = `
6507
6519
  "@typescript-eslint/comma-spacing": [
6508
6520
  "off",
6509
6521
  ],
6522
+ "@typescript-eslint/consistent-type-assertions": [
6523
+ "error",
6524
+ {
6525
+ "assertionStyle": "never",
6526
+ },
6527
+ ],
6510
6528
  "@typescript-eslint/consistent-type-imports": [
6511
6529
  "error",
6512
6530
  {