@typescript-eslint/eslint-plugin 8.21.1-alpha.11 → 8.21.1-alpha.3

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.
@@ -12,11 +12,7 @@ import TabItem from '@theme/TabItem';
12
12
  This rule extends the base [`eslint/no-unused-vars`](https://eslint.org/docs/rules/no-unused-vars) rule.
13
13
  It adds support for TypeScript features, such as types.
14
14
 
15
- ## Options
16
-
17
- ## FAQs
18
-
19
- ### What benefits does this rule have over TypeScript?
15
+ ## Benefits Over TypeScript
20
16
 
21
17
  TypeScript provides [`noUnusedLocals`](https://www.typescriptlang.org/tsconfig#noUnusedLocals) and [`noUnusedParameters`](https://www.typescriptlang.org/tsconfig#noUnusedParameters) compiler options that can report errors on unused local variables or parameters, respectively.
22
18
  Those compiler options can be convenient to use if you don't want to set up ESLint and typescript-eslint.
@@ -56,66 +52,3 @@ Also see similar rules provided by ESLint:
56
52
 
57
53
  - [`no-unused-private-class-members`](https://eslint.org/docs/latest/rules/no-unused-private-class-members)
58
54
  - [`no-unused-labels`](https://eslint.org/docs/latest/rules/no-unused-labels)
59
-
60
- ### Why does this rule report variables used only for types?
61
-
62
- This rule does not count type-only uses when determining whether a variable is used.
63
- Declaring variables only to use them for types adds code and runtime complexity.
64
- The variables are never actually used at runtime.
65
- They can be misleading to readers of the code.
66
-
67
- <Tabs>
68
-
69
- <TabItem value="typeof Variables">
70
-
71
- For example, if a variable is only used for `typeof`, this rule will report:
72
-
73
- ```ts
74
- const box = {
75
- // ~~~
76
- // 'box' is assigned a value but only used as a type.
77
- value: 123,
78
- };
79
-
80
- export type Box = typeof box;
81
- ```
82
-
83
- Instead, it's often cleaner and less code to write out the types directly:
84
-
85
- ```ts
86
- export interface Box {
87
- value: number;
88
- }
89
- ```
90
-
91
- </TabItem>
92
-
93
- <TabItem value="Zod Schemas">
94
-
95
- For example, if a Zod schema variable is only used for `typeof`, this rule will report:
96
-
97
- ```ts
98
- import { z } from 'zod';
99
-
100
- const schema = z.object({
101
- // ~~~~~~
102
- // 'schema' is assigned a value but only used as a type.
103
- value: z.number(),
104
- });
105
-
106
- export type Box = z.infer<typeof schema>;
107
- ```
108
-
109
- Instead, it's often cleaner and less code to write out the types directly:
110
-
111
- ```ts
112
- export interface Box {
113
- value: number;
114
- }
115
- ```
116
-
117
- </TabItem>
118
-
119
- </Tabs>
120
-
121
- If you find yourself writing runtime values only for types, consider refactoring your code to declare types directly.
@@ -16,7 +16,6 @@ This rule reports when you may consider replacing:
16
16
 
17
17
  - An `||` operator with `??`
18
18
  - An `||=` operator with `??=`
19
- - Ternary expressions (`?:`) that are equivalent to `||` or `??` with `??`
20
19
 
21
20
  :::caution
22
21
  This rule will not work as expected if [`strictNullChecks`](https://www.typescriptlang.org/tsconfig#strictNullChecks) is not enabled.
@@ -43,9 +42,7 @@ foo === undefined ? 'a string' : foo;
43
42
 
44
43
  const foo: string | null = 'bar';
45
44
  foo !== null ? foo : 'a string';
46
- foo ? foo : 'a string';
47
45
  foo === null ? 'a string' : foo;
48
- !foo ? 'a string' : foo;
49
46
  ```
50
47
 
51
48
  Correct code for `ignoreTernaryTests: false`:
@@ -64,8 +61,6 @@ foo ?? 'a string';
64
61
  const foo: string | null = 'bar';
65
62
  foo ?? 'a string';
66
63
  foo ?? 'a string';
67
- foo ?? 'a string';
68
- foo ?? 'a string';
69
64
  ```
70
65
 
71
66
  ### `ignoreConditionalTests`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typescript-eslint/eslint-plugin",
3
- "version": "8.21.1-alpha.11",
3
+ "version": "8.21.1-alpha.3",
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.10.0",
64
- "@typescript-eslint/scope-manager": "8.21.1-alpha.11",
65
- "@typescript-eslint/type-utils": "8.21.1-alpha.11",
66
- "@typescript-eslint/utils": "8.21.1-alpha.11",
67
- "@typescript-eslint/visitor-keys": "8.21.1-alpha.11",
64
+ "@typescript-eslint/scope-manager": "8.21.1-alpha.3",
65
+ "@typescript-eslint/type-utils": "8.21.1-alpha.3",
66
+ "@typescript-eslint/utils": "8.21.1-alpha.3",
67
+ "@typescript-eslint/visitor-keys": "8.21.1-alpha.3",
68
68
  "graphemer": "^1.4.0",
69
69
  "ignore": "^5.3.1",
70
70
  "natural-compare": "^1.4.0",
@@ -75,8 +75,8 @@
75
75
  "@types/marked": "^5.0.2",
76
76
  "@types/mdast": "^4.0.3",
77
77
  "@types/natural-compare": "*",
78
- "@typescript-eslint/rule-schema-to-typescript-types": "8.21.1-alpha.11",
79
- "@typescript-eslint/rule-tester": "8.21.1-alpha.11",
78
+ "@typescript-eslint/rule-schema-to-typescript-types": "8.21.1-alpha.3",
79
+ "@typescript-eslint/rule-tester": "8.21.1-alpha.3",
80
80
  "ajv": "^6.12.6",
81
81
  "cross-env": "^7.0.3",
82
82
  "cross-fetch": "*",
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getValueOfLiteralType = void 0;
4
- const valueIsPseudoBigInt = (value) => {
5
- return typeof value === 'object';
6
- };
7
- const pseudoBigIntToBigInt = (value) => {
8
- return BigInt((value.negative ? '-' : '') + value.base10Value);
9
- };
10
- const getValueOfLiteralType = (type) => {
11
- if (valueIsPseudoBigInt(type.value)) {
12
- return pseudoBigIntToBigInt(type.value);
13
- }
14
- return type.value;
15
- };
16
- exports.getValueOfLiteralType = getValueOfLiteralType;
17
- //# sourceMappingURL=getValueOfLiteralType.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getValueOfLiteralType.js","sourceRoot":"","sources":["../../src/util/getValueOfLiteralType.ts"],"names":[],"mappings":";;;AAEA,MAAM,mBAAmB,GAAG,CAC1B,KAAwC,EACd,EAAE;IAC5B,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACnC,CAAC,CAAC;AAEF,MAAM,oBAAoB,GAAG,CAAC,KAAsB,EAAU,EAAE;IAC9D,OAAO,MAAM,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC;AACjE,CAAC,CAAC;AAEK,MAAM,qBAAqB,GAAG,CACnC,IAAoB,EACM,EAAE;IAC5B,IAAI,mBAAmB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACpC,OAAO,oBAAoB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,IAAI,CAAC,KAAK,CAAC;AACpB,CAAC,CAAC;AAPW,QAAA,qBAAqB,yBAOhC"}
@@ -1,68 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.isAlwaysNullish = exports.isPossiblyNullish = exports.isPossiblyTruthy = exports.isPossiblyFalsy = void 0;
37
- const tsutils = __importStar(require("ts-api-utils"));
38
- const ts = __importStar(require("typescript"));
39
- const getValueOfLiteralType_1 = require("./getValueOfLiteralType");
40
- // Truthiness utilities
41
- const isTruthyLiteral = (type) => tsutils.isTrueLiteralType(type) ||
42
- (type.isLiteral() && !!(0, getValueOfLiteralType_1.getValueOfLiteralType)(type));
43
- const isPossiblyFalsy = (type) => tsutils
44
- .unionTypeParts(type)
45
- // Intersections like `string & {}` can also be possibly falsy,
46
- // requiring us to look into the intersection.
47
- .flatMap(type => tsutils.intersectionTypeParts(type))
48
- // PossiblyFalsy flag includes literal values, so exclude ones that
49
- // are definitely truthy
50
- .filter(t => !isTruthyLiteral(t))
51
- .some(type => tsutils.isTypeFlagSet(type, ts.TypeFlags.PossiblyFalsy));
52
- exports.isPossiblyFalsy = isPossiblyFalsy;
53
- const isPossiblyTruthy = (type) => tsutils
54
- .unionTypeParts(type)
55
- .map(type => tsutils.intersectionTypeParts(type))
56
- .some(intersectionParts =>
57
- // It is possible to define intersections that are always falsy,
58
- // like `"" & { __brand: string }`.
59
- intersectionParts.every(type => !tsutils.isFalsyType(type)));
60
- exports.isPossiblyTruthy = isPossiblyTruthy;
61
- // Nullish utilities
62
- const nullishFlag = ts.TypeFlags.Undefined | ts.TypeFlags.Null;
63
- const isNullishType = (type) => tsutils.isTypeFlagSet(type, nullishFlag);
64
- const isPossiblyNullish = (type) => tsutils.unionTypeParts(type).some(isNullishType);
65
- exports.isPossiblyNullish = isPossiblyNullish;
66
- const isAlwaysNullish = (type) => tsutils.unionTypeParts(type).every(isNullishType);
67
- exports.isAlwaysNullish = isAlwaysNullish;
68
- //# sourceMappingURL=truthinessAndNullishUtils.js.map
@@ -1 +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