@typescript-eslint/eslint-plugin 8.31.2-alpha.5 → 8.31.2-alpha.7

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":"prefer-nullish-coalescing.d.ts","sourceRoot":"","sources":["../../src/rules/prefer-nullish-coalescing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAY,MAAM,0BAA0B,CAAC;AAqCnE,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,sDAAsD,CAAC,EAAE,OAAO,CAAC;QACjE,qBAAqB,CAAC,EAAE,OAAO,CAAC;QAChC,sBAAsB,CAAC,EAAE,OAAO,CAAC;QACjC,kBAAkB,CAAC,EAAE,OAAO,CAAC;QAC7B,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,6BAA6B,GAC7B,qBAAqB,GACrB,0BAA0B,GAC1B,gBAAgB,CAAC;;AAErB,wBA8jBG"}
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;AAyCnE,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,sDAAsD,CAAC,EAAE,OAAO,CAAC;QACjE,qBAAqB,CAAC,EAAE,OAAO,CAAC;QAChC,sBAAsB,CAAC,EAAE,OAAO,CAAC;QACjC,kBAAkB,CAAC,EAAE,OAAO,CAAC;QAC7B,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,6BAA6B,GAC7B,qBAAqB,GACrB,0BAA0B,GAC1B,gBAAgB,CAAC;;AAErB,wBA+kBG"}
@@ -37,6 +37,7 @@ const utils_1 = require("@typescript-eslint/utils");
37
37
  const tsutils = __importStar(require("ts-api-utils"));
38
38
  const ts = __importStar(require("typescript"));
39
39
  const util_1 = require("../util");
40
+ const getWrappedCode_1 = require("../util/getWrappedCode");
40
41
  const isMemberAccessLike = (0, util_1.isNodeOfTypes)([
41
42
  utils_1.AST_NODE_TYPES.ChainExpression,
42
43
  utils_1.AST_NODE_TYPES.Identifier,
@@ -354,7 +355,8 @@ exports.default = (0, util_1.createRule)({
354
355
  if (operator == null) {
355
356
  return;
356
357
  }
357
- const nullishCoalescingParams = getNullishCoalescingParams(node, getBranchNodes(node, operator).nonNullishBranch, nodesInsideTestExpression, operator);
358
+ const { nonNullishBranch, nullishBranch } = getBranchNodes(node, operator);
359
+ const nullishCoalescingParams = getNullishCoalescingParams(node, nonNullishBranch, nodesInsideTestExpression, operator);
358
360
  if (nullishCoalescingParams.isFixable) {
359
361
  context.report({
360
362
  node,
@@ -366,7 +368,11 @@ exports.default = (0, util_1.createRule)({
366
368
  messageId: 'suggestNullish',
367
369
  data: { equals: '' },
368
370
  fix(fixer) {
369
- return fixer.replaceText(node, `${(0, util_1.getTextWithParentheses)(context.sourceCode, nullishCoalescingParams.nullishCoalescingLeftNode)} ?? ${(0, util_1.getTextWithParentheses)(context.sourceCode, getBranchNodes(node, operator).nullishBranch)}`);
371
+ const nullishBranchText = (0, util_1.getTextWithParentheses)(context.sourceCode, nullishBranch);
372
+ const rightOperandReplacement = (0, util_1.isParenthesized)(nullishBranch, context.sourceCode)
373
+ ? nullishBranchText
374
+ : (0, getWrappedCode_1.getWrappedCode)(nullishBranchText, (0, util_1.getOperatorPrecedenceForNode)(nullishBranch), util_1.OperatorPrecedence.Coalesce);
375
+ return fixer.replaceText(node, `${(0, util_1.getTextWithParentheses)(context.sourceCode, nullishCoalescingParams.nullishCoalescingLeftNode)} ?? ${rightOperandReplacement}`);
370
376
  },
371
377
  },
372
378
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typescript-eslint/eslint-plugin",
3
- "version": "8.31.2-alpha.5",
3
+ "version": "8.31.2-alpha.7",
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.31.2-alpha.5",
66
- "@typescript-eslint/type-utils": "8.31.2-alpha.5",
67
- "@typescript-eslint/utils": "8.31.2-alpha.5",
68
- "@typescript-eslint/visitor-keys": "8.31.2-alpha.5",
65
+ "@typescript-eslint/scope-manager": "8.31.2-alpha.7",
66
+ "@typescript-eslint/type-utils": "8.31.2-alpha.7",
67
+ "@typescript-eslint/utils": "8.31.2-alpha.7",
68
+ "@typescript-eslint/visitor-keys": "8.31.2-alpha.7",
69
69
  "graphemer": "^1.4.0",
70
70
  "ignore": "^5.3.1",
71
71
  "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.31.2-alpha.5",
79
- "@typescript-eslint/rule-tester": "8.31.2-alpha.5",
78
+ "@typescript-eslint/rule-schema-to-typescript-types": "8.31.2-alpha.7",
79
+ "@typescript-eslint/rule-tester": "8.31.2-alpha.7",
80
80
  "@vitest/coverage-v8": "^3.1.1",
81
81
  "ajv": "^6.12.6",
82
82
  "cross-fetch": "*",