@typescript-eslint/eslint-plugin 8.26.1-alpha.1 → 8.26.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.
@@ -1 +1 @@
1
- {"version":3,"file":"no-unnecessary-condition.d.ts","sourceRoot":"","sources":["../../src/rules/no-unnecessary-condition.ts"],"names":[],"mappings":"AAwGA,KAAK,iCAAiC,GAAG,OAAO,CAAC;AAEjD,KAAK,2BAA2B,GAAG,QAAQ,GAAG,OAAO,GAAG,uBAAuB,CAAC;AAShF,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,2BAA2B,CAAC,EACxB,2BAA2B,GAC3B,iCAAiC,CAAC;QACtC,sDAAsD,CAAC,EAAE,OAAO,CAAC;QACjE,mBAAmB,CAAC,EAAE,OAAO,CAAC;KAC/B;CACF,CAAC;AAEF,MAAM,MAAM,SAAS,GACjB,aAAa,GACb,iBAAiB,GACjB,eAAe,GACf,cAAc,GACd,kBAAkB,GAClB,+BAA+B,GAC/B,OAAO,GACP,cAAc,GACd,oBAAoB,GACpB,4BAA4B,GAC5B,mBAAmB,GACnB,wBAAwB,CAAC;;AAE7B,wBAgwBG"}
1
+ {"version":3,"file":"no-unnecessary-condition.d.ts","sourceRoot":"","sources":["../../src/rules/no-unnecessary-condition.ts"],"names":[],"mappings":"AAyHA,KAAK,iCAAiC,GAAG,OAAO,CAAC;AAEjD,KAAK,2BAA2B,GAAG,QAAQ,GAAG,OAAO,GAAG,uBAAuB,CAAC;AAShF,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,2BAA2B,CAAC,EACxB,2BAA2B,GAC3B,iCAAiC,CAAC;QACtC,sDAAsD,CAAC,EAAE,OAAO,CAAC;QACjE,mBAAmB,CAAC,EAAE,OAAO,CAAC;KAC/B;CACF,CAAC;AAEF,MAAM,MAAM,SAAS,GACjB,aAAa,GACb,iBAAiB,GACjB,eAAe,GACf,cAAc,GACd,kBAAkB,GAClB,+BAA+B,GAC/B,OAAO,GACP,cAAc,GACd,oBAAoB,GACpB,4BAA4B,GAC5B,mBAAmB,GACnB,wBAAwB,CAAC;;AAE7B,wBAgwBG"}
@@ -39,6 +39,20 @@ const ts = __importStar(require("typescript"));
39
39
  const util_1 = require("../util");
40
40
  const assertionFunctionUtils_1 = require("../util/assertionFunctionUtils");
41
41
  // #region
42
+ const nullishFlag = ts.TypeFlags.Undefined | ts.TypeFlags.Null;
43
+ function isNullishType(type) {
44
+ return tsutils.isTypeFlagSet(type, nullishFlag);
45
+ }
46
+ function isAlwaysNullish(type) {
47
+ return tsutils.unionTypeParts(type).every(isNullishType);
48
+ }
49
+ /**
50
+ * Note that this differs from {@link isNullableType} in that it doesn't consider
51
+ * `any` or `unknown` to be nullable.
52
+ */
53
+ function isPossiblyNullish(type) {
54
+ return tsutils.unionTypeParts(type).some(isNullishType);
55
+ }
42
56
  function toStaticValue(type) {
43
57
  // type.isLiteral() only covers numbers/bigints and strings, hence the rest of the branches.
44
58
  if (tsutils.isBooleanLiteralType(type)) {
@@ -288,7 +302,7 @@ exports.default = (0, util_1.createRule)({
288
302
  if ((0, util_1.isTypeFlagSet)(type, ts.TypeFlags.Never)) {
289
303
  messageId = 'never';
290
304
  }
291
- else if (!(0, util_1.isPossiblyNullish)(type) &&
305
+ else if (!isPossiblyNullish(type) &&
292
306
  !(node.type === utils_1.AST_NODE_TYPES.MemberExpression &&
293
307
  isNullableMemberExpression(node))) {
294
308
  // Since typescript array index signature types don't represent the
@@ -301,7 +315,7 @@ exports.default = (0, util_1.createRule)({
301
315
  messageId = 'neverNullish';
302
316
  }
303
317
  }
304
- else if ((0, util_1.isAlwaysNullish)(type)) {
318
+ else if (isAlwaysNullish(type)) {
305
319
  messageId = 'alwaysNullish';
306
320
  }
307
321
  if (messageId) {
@@ -1 +1 @@
1
- {"version":3,"file":"prefer-nullish-coalescing.d.ts","sourceRoot":"","sources":["../../src/rules/prefer-nullish-coalescing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAY,MAAM,0BAA0B,CAAC;AA8BnE,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,sDAAsD,CAAC,EAAE,OAAO,CAAC;QACjE,qBAAqB,CAAC,EAAE,OAAO,CAAC;QAChC,sBAAsB,CAAC,EAAE,OAAO,CAAC;QACjC,6BAA6B,CAAC,EAAE,OAAO,CAAC;QACxC,gBAAgB,CAAC,EACb;YACE,MAAM,CAAC,EAAE,OAAO,CAAC;YACjB,OAAO,CAAC,EAAE,OAAO,CAAC;YAClB,MAAM,CAAC,EAAE,OAAO,CAAC;YACjB,MAAM,CAAC,EAAE,OAAO,CAAC;SAClB,GACD,IAAI,CAAC;QACT,kBAAkB,CAAC,EAAE,OAAO,CAAC;KAC9B;CACF,CAAC;AAEF,MAAM,MAAM,UAAU,GAClB,mBAAmB,GACnB,qBAAqB,GACrB,0BAA0B,GAC1B,gBAAgB,CAAC;;AAErB,wBAmeG"}
1
+ {"version":3,"file":"prefer-nullish-coalescing.d.ts","sourceRoot":"","sources":["../../src/rules/prefer-nullish-coalescing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAY,MAAM,0BAA0B,CAAC;AA8BnE,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,sDAAsD,CAAC,EAAE,OAAO,CAAC;QACjE,qBAAqB,CAAC,EAAE,OAAO,CAAC;QAChC,sBAAsB,CAAC,EAAE,OAAO,CAAC;QACjC,6BAA6B,CAAC,EAAE,OAAO,CAAC;QACxC,gBAAgB,CAAC,EACb;YACE,MAAM,CAAC,EAAE,OAAO,CAAC;YACjB,OAAO,CAAC,EAAE,OAAO,CAAC;YAClB,MAAM,CAAC,EAAE,OAAO,CAAC;YACjB,MAAM,CAAC,EAAE,OAAO,CAAC;SAClB,GACD,IAAI,CAAC;QACT,kBAAkB,CAAC,EAAE,OAAO,CAAC;KAC9B;CACF,CAAC;AAEF,MAAM,MAAM,UAAU,GAClB,mBAAmB,GACnB,qBAAqB,GACrB,0BAA0B,GAC1B,gBAAgB,CAAC;;AAErB,wBAsfG"}
@@ -153,7 +153,7 @@ exports.default = (0, util_1.createRule)({
153
153
  * a nullishness check, taking into account the rule's configuration.
154
154
  */
155
155
  function isTypeEligibleForPreferNullish(type) {
156
- if (!(0, util_1.isPossiblyNullish)(type)) {
156
+ if (!(0, util_1.isNullableType)(type)) {
157
157
  return false;
158
158
  }
159
159
  const ignorableFlags = [
@@ -170,11 +170,25 @@ exports.default = (0, util_1.createRule)({
170
170
  ]
171
171
  .filter((flag) => typeof flag === 'number')
172
172
  .reduce((previous, flag) => previous | flag, 0);
173
- if (type.flags !== ts.TypeFlags.Null &&
174
- type.flags !== ts.TypeFlags.Undefined &&
175
- type.types.some(t => tsutils
176
- .intersectionTypeParts(t)
177
- .some(t => tsutils.isTypeFlagSet(t, ignorableFlags)))) {
173
+ if (ignorableFlags === 0) {
174
+ // any types are eligible for conversion.
175
+ return true;
176
+ }
177
+ // if the type is `any` or `unknown` we can't make any assumptions
178
+ // about the value, so it could be any primitive, even though the flags
179
+ // won't be set.
180
+ //
181
+ // technically, this is true of `void` as well, however, it's a TS error
182
+ // to test `void` for truthiness, so we don't need to bother checking for
183
+ // it in valid code.
184
+ if (tsutils.isTypeFlagSet(type, ts.TypeFlags.Any | ts.TypeFlags.Unknown)) {
185
+ return false;
186
+ }
187
+ if (tsutils
188
+ .typeParts(type)
189
+ .some(t => tsutils
190
+ .intersectionTypeParts(t)
191
+ .some(t => tsutils.isTypeFlagSet(t, ignorableFlags)))) {
178
192
  return false;
179
193
  }
180
194
  return true;
@@ -27,7 +27,7 @@ export * from './getConstraintInfo';
27
27
  export * from './getValueOfLiteralType';
28
28
  export * from './isHigherPrecedenceThanAwait';
29
29
  export * from './skipChainExpression';
30
- export * from './truthinessAndNullishUtils';
30
+ export * from './truthinessUtils';
31
31
  export * from '@typescript-eslint/type-utils';
32
32
  export declare const applyDefault: typeof ESLintUtils.applyDefault, deepMerge: typeof ESLintUtils.deepMerge, getParserServices: typeof ESLintUtils.getParserServices, isObjectNotArray: typeof ESLintUtils.isObjectNotArray, nullThrows: typeof ESLintUtils.nullThrows, NullThrowsReasons: {
33
33
  readonly MissingParent: "Expected node to have a parent.";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,cAAc,YAAY,CAAC;AAC3B,cAAc,0BAA0B,CAAC;AACzC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,kCAAkC,CAAC;AACjD,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AACxC,cAAc,QAAQ,CAAC;AACvB,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAG5C,cAAc,+BAA+B,CAAC;AAE9C,eAAO,MACL,YAAY,mCACZ,SAAS,gCACT,iBAAiB,wCACjB,gBAAgB,uCAChB,UAAU,iCACV,iBAAiB;;;CACJ,CAAC;AAChB,MAAM,MAAM,2BAA2B,CAAC,CAAC,IACvC,WAAW,CAAC,2BAA2B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,MAAM,MAAM,wBAAwB,CAAC,CAAC,IACpC,WAAW,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC"}
@@ -44,7 +44,7 @@ __exportStar(require("./getConstraintInfo"), exports);
44
44
  __exportStar(require("./getValueOfLiteralType"), exports);
45
45
  __exportStar(require("./isHigherPrecedenceThanAwait"), exports);
46
46
  __exportStar(require("./skipChainExpression"), exports);
47
- __exportStar(require("./truthinessAndNullishUtils"), exports);
47
+ __exportStar(require("./truthinessUtils"), exports);
48
48
  // this is done for convenience - saves migrating all of the old rules
49
49
  __exportStar(require("@typescript-eslint/type-utils"), exports);
50
50
  exports.applyDefault = utils_1.ESLintUtils.applyDefault, exports.deepMerge = utils_1.ESLintUtils.deepMerge, exports.getParserServices = utils_1.ESLintUtils.getParserServices, exports.isObjectNotArray = utils_1.ESLintUtils.isObjectNotArray, exports.nullThrows = utils_1.ESLintUtils.nullThrows, exports.NullThrowsReasons = utils_1.ESLintUtils.NullThrowsReasons;
@@ -0,0 +1,4 @@
1
+ import * as ts from 'typescript';
2
+ export declare const isPossiblyFalsy: (type: ts.Type) => boolean;
3
+ export declare const isPossiblyTruthy: (type: ts.Type) => boolean;
4
+ //# sourceMappingURL=truthinessUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"truthinessUtils.d.ts","sourceRoot":"","sources":["../../src/util/truthinessUtils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AASjC,eAAO,MAAM,eAAe,GAAI,MAAM,EAAE,CAAC,IAAI,KAAG,OAS0B,CAAC;AAE3E,eAAO,MAAM,gBAAgB,GAAI,MAAM,EAAE,CAAC,IAAI,KAAG,OAQ5C,CAAC"}
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.isAlwaysNullish = exports.isPossiblyNullish = exports.isPossiblyTruthy = exports.isPossiblyFalsy = void 0;
36
+ exports.isPossiblyTruthy = exports.isPossiblyFalsy = void 0;
37
37
  const tsutils = __importStar(require("ts-api-utils"));
38
38
  const ts = __importStar(require("typescript"));
39
39
  const getValueOfLiteralType_1 = require("./getValueOfLiteralType");
@@ -58,10 +58,3 @@ const isPossiblyTruthy = (type) => tsutils
58
58
  // like `"" & { __brand: string }`.
59
59
  intersectionParts.every(type => !tsutils.isFalsyType(type)));
60
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;
@@ -84,7 +84,7 @@ Examples of code for this rule with `{ ignoreConditionalTests: false }`:
84
84
  <TabItem value="❌ Incorrect">
85
85
 
86
86
  ```ts option='{ "ignoreConditionalTests": false }'
87
- declare const a: string | null;
87
+ declare let a: string | null;
88
88
  declare const b: string | null;
89
89
 
90
90
  if (a || b) {
@@ -102,7 +102,7 @@ a || b ? true : false;
102
102
  <TabItem value="✅ Correct">
103
103
 
104
104
  ```ts option='{ "ignoreConditionalTests": false }'
105
- declare const a: string | null;
105
+ declare let a: string | null;
106
106
  declare const b: string | null;
107
107
 
108
108
  if (a ?? b) {
@@ -133,7 +133,7 @@ Examples of code for this rule with `{ ignoreMixedLogicalExpressions: false }`:
133
133
  <TabItem value="❌ Incorrect">
134
134
 
135
135
  ```ts option='{ "ignoreMixedLogicalExpressions": false }'
136
- declare const a: string | null;
136
+ declare let a: string | null;
137
137
  declare const b: string | null;
138
138
  declare const c: string | null;
139
139
  declare const d: string | null;
@@ -149,7 +149,7 @@ a || (b && c && d);
149
149
  <TabItem value="✅ Correct">
150
150
 
151
151
  ```ts option='{ "ignoreMixedLogicalExpressions": false }'
152
- declare const a: string | null;
152
+ declare let a: string | null;
153
153
  declare const b: string | null;
154
154
  declare const c: string | null;
155
155
  declare const d: string | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typescript-eslint/eslint-plugin",
3
- "version": "8.26.1-alpha.1",
3
+ "version": "8.26.1-alpha.3",
4
4
  "description": "TypeScript plugin for ESLint",
5
5
  "files": [
6
6
  "dist",
@@ -62,10 +62,10 @@
62
62
  },
63
63
  "dependencies": {
64
64
  "@eslint-community/regexpp": "^4.10.0",
65
- "@typescript-eslint/scope-manager": "8.26.1-alpha.1",
66
- "@typescript-eslint/type-utils": "8.26.1-alpha.1",
67
- "@typescript-eslint/utils": "8.26.1-alpha.1",
68
- "@typescript-eslint/visitor-keys": "8.26.1-alpha.1",
65
+ "@typescript-eslint/scope-manager": "8.26.1-alpha.3",
66
+ "@typescript-eslint/type-utils": "8.26.1-alpha.3",
67
+ "@typescript-eslint/utils": "8.26.1-alpha.3",
68
+ "@typescript-eslint/visitor-keys": "8.26.1-alpha.3",
69
69
  "graphemer": "^1.4.0",
70
70
  "ignore": "^5.3.1",
71
71
  "natural-compare": "^1.4.0",
@@ -76,8 +76,8 @@
76
76
  "@types/marked": "^5.0.2",
77
77
  "@types/mdast": "^4.0.3",
78
78
  "@types/natural-compare": "*",
79
- "@typescript-eslint/rule-schema-to-typescript-types": "8.26.1-alpha.1",
80
- "@typescript-eslint/rule-tester": "8.26.1-alpha.1",
79
+ "@typescript-eslint/rule-schema-to-typescript-types": "8.26.1-alpha.3",
80
+ "@typescript-eslint/rule-tester": "8.26.1-alpha.3",
81
81
  "ajv": "^6.12.6",
82
82
  "cross-env": "^7.0.3",
83
83
  "cross-fetch": "*",
@@ -1,6 +0,0 @@
1
- import * as ts from 'typescript';
2
- export declare const isPossiblyFalsy: (type: ts.Type) => boolean;
3
- export declare const isPossiblyTruthy: (type: ts.Type) => boolean;
4
- export declare const isPossiblyNullish: (type: ts.Type) => boolean;
5
- export declare const isAlwaysNullish: (type: ts.Type) => boolean;
6
- //# sourceMappingURL=truthinessAndNullishUtils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"truthinessAndNullishUtils.d.ts","sourceRoot":"","sources":["../../src/util/truthinessAndNullishUtils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AASjC,eAAO,MAAM,eAAe,GAAI,MAAM,EAAE,CAAC,IAAI,KAAG,OAS0B,CAAC;AAE3E,eAAO,MAAM,gBAAgB,GAAI,MAAM,EAAE,CAAC,IAAI,KAAG,OAQ5C,CAAC;AAON,eAAO,MAAM,iBAAiB,GAAI,MAAM,EAAE,CAAC,IAAI,KAAG,OACA,CAAC;AAEnD,eAAO,MAAM,eAAe,GAAI,MAAM,EAAE,CAAC,IAAI,KAAG,OACG,CAAC"}