@typescript-eslint/eslint-plugin 7.3.2-alpha.1 → 7.3.2-alpha.11

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 (31) hide show
  1. package/dist/configs/all.js +2 -2
  2. package/dist/configs/all.js.map +1 -1
  3. package/dist/configs/disable-type-checked.js +1 -0
  4. package/dist/configs/disable-type-checked.js.map +1 -1
  5. package/dist/configs/strict-type-checked-only.js +2 -2
  6. package/dist/configs/strict-type-checked-only.js.map +1 -1
  7. package/dist/configs/strict-type-checked.js +2 -2
  8. package/dist/configs/strict-type-checked.js.map +1 -1
  9. package/dist/rules/consistent-type-imports.js +247 -277
  10. package/dist/rules/consistent-type-imports.js.map +1 -1
  11. package/dist/rules/index.js +2 -0
  12. package/dist/rules/index.js.map +1 -1
  13. package/dist/rules/no-throw-literal.js +2 -1
  14. package/dist/rules/no-throw-literal.js.map +1 -1
  15. package/dist/rules/no-unnecessary-type-arguments.js +3 -1
  16. package/dist/rules/no-unnecessary-type-arguments.js.map +1 -1
  17. package/dist/rules/no-unnecessary-type-assertion.js +14 -5
  18. package/dist/rules/no-unnecessary-type-assertion.js.map +1 -1
  19. package/dist/rules/only-throw-error.js +96 -0
  20. package/dist/rules/only-throw-error.js.map +1 -0
  21. package/dist/rules/prefer-optional-chain-utils/analyzeChain.js +8 -5
  22. package/dist/rules/prefer-optional-chain-utils/analyzeChain.js.map +1 -1
  23. package/dist/rules/prefer-optional-chain-utils/gatherLogicalOperands.js +4 -5
  24. package/dist/rules/prefer-optional-chain-utils/gatherLogicalOperands.js.map +1 -1
  25. package/docs/rules/consistent-type-imports.mdx +26 -3
  26. package/docs/rules/no-throw-literal.mdx +7 -97
  27. package/docs/rules/only-throw-error.mdx +115 -0
  28. package/docs/rules/restrict-template-expressions.mdx +1 -1
  29. package/docs/rules/switch-exhaustiveness-check.mdx +1 -1
  30. package/docs/rules/unbound-method.mdx +2 -2
  31. package/package.json +6 -6
@@ -12,104 +12,14 @@ import TabItem from '@theme/TabItem';
12
12
  It is considered good practice to only `throw` the `Error` object itself or an object using the `Error` object as base objects for user-defined exceptions.
13
13
  The fundamental benefit of `Error` objects is that they automatically keep track of where they were built and originated.
14
14
 
15
- This rule restricts what can be thrown as an exception. When it was first created, it only prevented literals from being thrown (hence the name), but it has now been expanded to only allow expressions which have a possibility of being an `Error` object. With the `allowThrowingAny` and `allowThrowingUnknown`, it can be configured to only allow throwing values which are guaranteed to be an instance of `Error`.
15
+ This rule restricts what can be thrown as an exception.
16
16
 
17
- ## Examples
17
+ :::warning
18
+ This rule is being renamed to [`only-throw-error`](./only-throw-error.mdx).
19
+ When it was first created, it only prevented literals from being thrown (hence the name), but it has now been expanded to only allow expressions which have a possibility of being an `Error` object.
20
+ With the `allowThrowingAny` and `allowThrowingUnknown` options, it can be configured to only allow throwing values which are guaranteed to be an instance of `Error`.
18
21
 
19
- This rule is aimed at maintaining consistency when throwing exception by disallowing to throw literals and other expressions which cannot possibly be an `Error` object.
20
-
21
- <Tabs>
22
- <TabItem value="❌ Incorrect">
23
-
24
- ```ts
25
- throw 'error';
26
-
27
- throw 0;
28
-
29
- throw undefined;
30
-
31
- throw null;
32
-
33
- const err = new Error();
34
- throw 'an ' + err;
35
-
36
- const err = new Error();
37
- throw `${err}`;
38
-
39
- const err = '';
40
- throw err;
41
-
42
- function err() {
43
- return '';
44
- }
45
- throw err();
46
-
47
- const foo = {
48
- bar: '',
49
- };
50
- throw foo.bar;
51
- ```
52
-
53
- </TabItem>
54
- <TabItem value="✅ Correct">
55
-
56
- ```ts
57
- throw new Error();
58
-
59
- throw new Error('error');
60
-
61
- const e = new Error('error');
62
- throw e;
63
-
64
- try {
65
- throw new Error('error');
66
- } catch (e) {
67
- throw e;
68
- }
69
-
70
- const err = new Error();
71
- throw err;
72
-
73
- function err() {
74
- return new Error();
75
- }
76
- throw err();
77
-
78
- const foo = {
79
- bar: new Error(),
80
- };
81
- throw foo.bar;
82
-
83
- class CustomError extends Error {
84
- // ...
85
- }
86
- throw new CustomError();
87
- ```
88
-
89
- </TabItem>
90
- </Tabs>
91
-
92
- ## Options
93
-
94
- This rule adds the following options:
95
-
96
- ```ts
97
- interface Options {
98
- /**
99
- * Whether to always allow throwing values typed as `any`.
100
- */
101
- allowThrowingAny?: boolean;
102
-
103
- /**
104
- * Whether to always allow throwing values typed as `unknown`.
105
- */
106
- allowThrowingUnknown?: boolean;
107
- }
108
-
109
- const defaultOptions: Options = {
110
- allowThrowingAny: false,
111
- allowThrowingUnknown: false,
112
- };
113
- ```
22
+ The current name `no-throw-literal` will be removed in a future major version of typescript-eslint.
23
+ :::
114
24
 
115
25
  {/* Intentionally Omitted: When Not To Use It */}
@@ -0,0 +1,115 @@
1
+ ---
2
+ description: 'Disallow throwing non-`Error` values as exceptions.'
3
+ ---
4
+
5
+ import Tabs from '@theme/Tabs';
6
+ import TabItem from '@theme/TabItem';
7
+
8
+ > 🛑 This file is source code, not the primary documentation location! 🛑
9
+ >
10
+ > See **https://typescript-eslint.io/rules/only-throw-error** for documentation.
11
+
12
+ It is considered good practice to only `throw` the `Error` object itself or an object using the `Error` object as base objects for user-defined exceptions.
13
+ The fundamental benefit of `Error` objects is that they automatically keep track of where they were built and originated.
14
+
15
+ This rule restricts what can be thrown as an exception.
16
+
17
+ ## Examples
18
+
19
+ This rule is aimed at maintaining consistency when throwing exception by disallowing to throw literals and other expressions which cannot possibly be an `Error` object.
20
+
21
+ <Tabs>
22
+ <TabItem value="❌ Incorrect">
23
+
24
+ ```ts
25
+ throw 'error';
26
+
27
+ throw 0;
28
+
29
+ throw undefined;
30
+
31
+ throw null;
32
+
33
+ const err = new Error();
34
+ throw 'an ' + err;
35
+
36
+ const err = new Error();
37
+ throw `${err}`;
38
+
39
+ const err = '';
40
+ throw err;
41
+
42
+ function err() {
43
+ return '';
44
+ }
45
+ throw err();
46
+
47
+ const foo = {
48
+ bar: '',
49
+ };
50
+ throw foo.bar;
51
+ ```
52
+
53
+ </TabItem>
54
+ <TabItem value="✅ Correct">
55
+
56
+ ```ts
57
+ throw new Error();
58
+
59
+ throw new Error('error');
60
+
61
+ const e = new Error('error');
62
+ throw e;
63
+
64
+ try {
65
+ throw new Error('error');
66
+ } catch (e) {
67
+ throw e;
68
+ }
69
+
70
+ const err = new Error();
71
+ throw err;
72
+
73
+ function err() {
74
+ return new Error();
75
+ }
76
+ throw err();
77
+
78
+ const foo = {
79
+ bar: new Error(),
80
+ };
81
+ throw foo.bar;
82
+
83
+ class CustomError extends Error {
84
+ // ...
85
+ }
86
+ throw new CustomError();
87
+ ```
88
+
89
+ </TabItem>
90
+ </Tabs>
91
+
92
+ ## Options
93
+
94
+ This rule adds the following options:
95
+
96
+ ```ts
97
+ interface Options {
98
+ /**
99
+ * Whether to always allow throwing values typed as `any`.
100
+ */
101
+ allowThrowingAny?: boolean;
102
+
103
+ /**
104
+ * Whether to always allow throwing values typed as `unknown`.
105
+ */
106
+ allowThrowingUnknown?: boolean;
107
+ }
108
+
109
+ const defaultOptions: Options = {
110
+ allowThrowingAny: false,
111
+ allowThrowingUnknown: false,
112
+ };
113
+ ```
114
+
115
+ {/* Intentionally Omitted: When Not To Use It */}
@@ -11,7 +11,7 @@ import TabItem from '@theme/TabItem';
11
11
 
12
12
  JavaScript automatically [converts an object to a string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#string_coercion) in a string context, such as when concatenating it with a string using `+` or embedding it in a template literal using `${}`.
13
13
  The default `toString()` method of objects returns `"[object Object]"`, which is often not what was intended.
14
- This rule reports on values used in a template literal string that aren't strings, numbers, or BigInts, optionally allowing other data types that provide useful stringification results.
14
+ This rule reports on values used in a template literal string that aren't strings, optionally allowing other data types that provide useful stringification results.
15
15
 
16
16
  :::note
17
17
 
@@ -34,7 +34,7 @@ If your project has many intentionally redundant `default` cases, you may want t
34
34
 
35
35
  ### `requireDefaultForNonUnion`
36
36
 
37
- Defaults to false. It set to true, this rule will also report when a `switch` statement switches over a non-union type (like a `number` or `string`, for example) and that `switch` statement does not have a `default` case. Thus, by setting this option to true, the rule becomes stricter.
37
+ Defaults to false. If set to true, this rule will also report when a `switch` statement switches over a non-union type (like a `number` or `string`, for example) and that `switch` statement does not have a `default` case. Thus, by setting this option to true, the rule becomes stricter.
38
38
 
39
39
  This is generally desirable so that `number` and `string` switches will be subject to the same exhaustive checks that your other switches are.
40
40
 
@@ -68,8 +68,8 @@ const { logBound } = instance;
68
68
  logBound();
69
69
 
70
70
  // .bind and lambdas will also add a correct scope
71
- const dotBindLog = instance.logBound.bind(instance);
72
- const innerLog = () => instance.logBound();
71
+ const dotBindLog = instance.logUnbound.bind(instance);
72
+ const innerLog = () => instance.logUnbound();
73
73
 
74
74
  // arith.double explicitly declares that it does not refer to `this` internally
75
75
  const arith = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typescript-eslint/eslint-plugin",
3
- "version": "7.3.2-alpha.1",
3
+ "version": "7.3.2-alpha.11",
4
4
  "description": "TypeScript plugin for ESLint",
5
5
  "files": [
6
6
  "dist",
@@ -61,10 +61,10 @@
61
61
  },
62
62
  "dependencies": {
63
63
  "@eslint-community/regexpp": "^4.5.1",
64
- "@typescript-eslint/scope-manager": "7.3.2-alpha.1",
65
- "@typescript-eslint/type-utils": "7.3.2-alpha.1",
66
- "@typescript-eslint/utils": "7.3.2-alpha.1",
67
- "@typescript-eslint/visitor-keys": "7.3.2-alpha.1",
64
+ "@typescript-eslint/scope-manager": "7.3.2-alpha.11",
65
+ "@typescript-eslint/type-utils": "7.3.2-alpha.11",
66
+ "@typescript-eslint/utils": "7.3.2-alpha.11",
67
+ "@typescript-eslint/visitor-keys": "7.3.2-alpha.11",
68
68
  "debug": "^4.3.4",
69
69
  "graphemer": "^1.4.0",
70
70
  "ignore": "^5.2.4",
@@ -77,7 +77,7 @@
77
77
  "@types/marked": "*",
78
78
  "@types/natural-compare": "*",
79
79
  "@typescript-eslint/rule-schema-to-typescript-types": "7.3.1",
80
- "@typescript-eslint/rule-tester": "7.3.2-alpha.1",
80
+ "@typescript-eslint/rule-tester": "7.3.2-alpha.11",
81
81
  "ajv": "^6.12.6",
82
82
  "chalk": "^5.3.0",
83
83
  "cross-env": "^7.0.3",