eslint-linter-browserify 10.6.0 → 10.7.0
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.
- package/linter.cjs +537 -242
- package/linter.js +537 -242
- package/linter.min.js +3 -3
- package/linter.mjs +537 -242
- package/package.json +2 -2
package/linter.cjs
CHANGED
|
@@ -4216,7 +4216,7 @@ function requireEslintVisitorKeys$2 () {
|
|
|
4216
4216
|
return eslintVisitorKeys$2;
|
|
4217
4217
|
}
|
|
4218
4218
|
|
|
4219
|
-
var version = "10.
|
|
4219
|
+
var version = "10.7.0";
|
|
4220
4220
|
var require$$3$1 = {
|
|
4221
4221
|
version: version};
|
|
4222
4222
|
|
|
@@ -47526,7 +47526,7 @@ function requireAstUtils () {
|
|
|
47526
47526
|
* @returns {boolean} Whether the node is inside a TypeScript type context.
|
|
47527
47527
|
*/
|
|
47528
47528
|
function isInType(node) {
|
|
47529
|
-
for (let currNode = node; ;
|
|
47529
|
+
for (let currNode = node; ;) {
|
|
47530
47530
|
const { parent } = currNode;
|
|
47531
47531
|
if (!parent) {
|
|
47532
47532
|
break;
|
|
@@ -53661,7 +53661,8 @@ function requireClassMethodsUseThis () {
|
|
|
53661
53661
|
function hasImplements(node) {
|
|
53662
53662
|
const classNode = node.parent.parent;
|
|
53663
53663
|
return (
|
|
53664
|
-
classNode?.type === "ClassDeclaration"
|
|
53664
|
+
(classNode?.type === "ClassDeclaration" ||
|
|
53665
|
+
classNode?.type === "ClassExpression") &&
|
|
53665
53666
|
classNode.implements?.length > 0
|
|
53666
53667
|
);
|
|
53667
53668
|
}
|
|
@@ -57617,6 +57618,24 @@ function requireEqeqeq () {
|
|
|
57617
57618
|
return isTypeOf(node.left) || isTypeOf(node.right);
|
|
57618
57619
|
}
|
|
57619
57620
|
|
|
57621
|
+
/**
|
|
57622
|
+
* Gets the type of a literal node.
|
|
57623
|
+
* @param {ASTNode} node The node to check
|
|
57624
|
+
* @returns {string|null} The type of the literal
|
|
57625
|
+
* @private
|
|
57626
|
+
*/
|
|
57627
|
+
function getLiteralType(node) {
|
|
57628
|
+
if (node.type === "Literal") {
|
|
57629
|
+
return typeof node.value;
|
|
57630
|
+
}
|
|
57631
|
+
|
|
57632
|
+
if (astUtils.isStaticTemplateLiteral(node)) {
|
|
57633
|
+
return "string";
|
|
57634
|
+
}
|
|
57635
|
+
|
|
57636
|
+
return null;
|
|
57637
|
+
}
|
|
57638
|
+
|
|
57620
57639
|
/**
|
|
57621
57640
|
* Checks if operands are literals of the same type (via typeof)
|
|
57622
57641
|
* @param {ASTNode} node The node to check
|
|
@@ -57624,11 +57643,9 @@ function requireEqeqeq () {
|
|
|
57624
57643
|
* @private
|
|
57625
57644
|
*/
|
|
57626
57645
|
function areLiteralsAndSameType(node) {
|
|
57627
|
-
|
|
57628
|
-
|
|
57629
|
-
|
|
57630
|
-
typeof node.left.value === typeof node.right.value
|
|
57631
|
-
);
|
|
57646
|
+
const leftType = getLiteralType(node.left);
|
|
57647
|
+
|
|
57648
|
+
return leftType !== null && leftType === getLiteralType(node.right);
|
|
57632
57649
|
}
|
|
57633
57650
|
|
|
57634
57651
|
/**
|
|
@@ -57701,7 +57718,11 @@ function requireEqeqeq () {
|
|
|
57701
57718
|
const isNull = isNullCheck(node);
|
|
57702
57719
|
|
|
57703
57720
|
if (node.operator !== "==" && node.operator !== "!=") {
|
|
57704
|
-
if (
|
|
57721
|
+
if (
|
|
57722
|
+
enforceInverseRuleForNull &&
|
|
57723
|
+
isNull &&
|
|
57724
|
+
(node.operator === "===" || node.operator === "!==")
|
|
57725
|
+
) {
|
|
57705
57726
|
report(node, node.operator.slice(0, -1));
|
|
57706
57727
|
}
|
|
57707
57728
|
return;
|
|
@@ -58494,9 +58515,9 @@ function requireFuncNameMatching () {
|
|
|
58494
58515
|
},
|
|
58495
58516
|
|
|
58496
58517
|
"Property, PropertyDefinition[value]"(node) {
|
|
58497
|
-
if (
|
|
58498
|
-
|
|
58499
|
-
) {
|
|
58518
|
+
if (!(
|
|
58519
|
+
node.value.type === "FunctionExpression" && node.value.id
|
|
58520
|
+
)) {
|
|
58500
58521
|
return;
|
|
58501
58522
|
}
|
|
58502
58523
|
|
|
@@ -59810,12 +59831,10 @@ function requireGeneratorStarSpacing () {
|
|
|
59810
59831
|
}
|
|
59811
59832
|
|
|
59812
59833
|
// Only check before when preceded by `function`|`static` keyword
|
|
59813
|
-
if (
|
|
59814
|
-
|
|
59815
|
-
|
|
59816
|
-
|
|
59817
|
-
)
|
|
59818
|
-
) {
|
|
59834
|
+
if (!(
|
|
59835
|
+
kind === "method" &&
|
|
59836
|
+
starToken === sourceCode.getFirstToken(node.parent)
|
|
59837
|
+
)) {
|
|
59819
59838
|
checkSpacing(kind, "before", prevToken, starToken);
|
|
59820
59839
|
}
|
|
59821
59840
|
|
|
@@ -63780,12 +63799,10 @@ function requireIndent () {
|
|
|
63780
63799
|
},
|
|
63781
63800
|
|
|
63782
63801
|
SwitchCase(node) {
|
|
63783
|
-
if (
|
|
63784
|
-
|
|
63785
|
-
|
|
63786
|
-
|
|
63787
|
-
)
|
|
63788
|
-
) {
|
|
63802
|
+
if (!(
|
|
63803
|
+
node.consequent.length === 1 &&
|
|
63804
|
+
node.consequent[0].type === "BlockStatement"
|
|
63805
|
+
)) {
|
|
63789
63806
|
const caseKeyword = sourceCode.getFirstToken(node);
|
|
63790
63807
|
const tokenAfterCurrentCase =
|
|
63791
63808
|
sourceCode.getTokenAfter(node);
|
|
@@ -66312,12 +66329,10 @@ function requireKeySpacing () {
|
|
|
66312
66329
|
*/
|
|
66313
66330
|
function isKeyValueProperty(property) {
|
|
66314
66331
|
return !(
|
|
66315
|
-
|
|
66316
|
-
|
|
66317
|
-
|
|
66318
|
-
|
|
66319
|
-
property.type !== "Property"
|
|
66320
|
-
) // Could be "ExperimentalSpreadProperty" or "SpreadElement"
|
|
66332
|
+
property.method ||
|
|
66333
|
+
property.shorthand ||
|
|
66334
|
+
property.kind !== "init" ||
|
|
66335
|
+
property.type !== "Property" // Could be "ExperimentalSpreadProperty" or "SpreadElement"
|
|
66321
66336
|
);
|
|
66322
66337
|
}
|
|
66323
66338
|
|
|
@@ -70989,6 +71004,9 @@ function requireMaxNestedCallbacks () {
|
|
|
70989
71004
|
type: "integer",
|
|
70990
71005
|
minimum: 0,
|
|
70991
71006
|
},
|
|
71007
|
+
checkConstructorCallCallbacks: {
|
|
71008
|
+
type: "boolean",
|
|
71009
|
+
},
|
|
70992
71010
|
},
|
|
70993
71011
|
additionalProperties: false,
|
|
70994
71012
|
},
|
|
@@ -71036,7 +71054,14 @@ function requireMaxNestedCallbacks () {
|
|
|
71036
71054
|
function checkFunction(node) {
|
|
71037
71055
|
const parent = node.parent;
|
|
71038
71056
|
|
|
71039
|
-
if (
|
|
71057
|
+
if (
|
|
71058
|
+
(parent.type !== "CallExpression" &&
|
|
71059
|
+
!(
|
|
71060
|
+
option.checkConstructorCallCallbacks &&
|
|
71061
|
+
parent.type === "NewExpression"
|
|
71062
|
+
)) ||
|
|
71063
|
+
parent.callee === node
|
|
71064
|
+
) {
|
|
71040
71065
|
return;
|
|
71041
71066
|
}
|
|
71042
71067
|
|
|
@@ -74864,6 +74889,12 @@ function requireNoCompareNegZero () {
|
|
|
74864
74889
|
if (hasRequiredNoCompareNegZero) return noCompareNegZero;
|
|
74865
74890
|
hasRequiredNoCompareNegZero = 1;
|
|
74866
74891
|
|
|
74892
|
+
//------------------------------------------------------------------------------
|
|
74893
|
+
// Requirements
|
|
74894
|
+
//------------------------------------------------------------------------------
|
|
74895
|
+
|
|
74896
|
+
const { getVariableByName } = requireAstUtils();
|
|
74897
|
+
|
|
74867
74898
|
//------------------------------------------------------------------------------
|
|
74868
74899
|
// Rule Definition
|
|
74869
74900
|
//------------------------------------------------------------------------------
|
|
@@ -74880,15 +74911,24 @@ function requireNoCompareNegZero () {
|
|
|
74880
74911
|
},
|
|
74881
74912
|
|
|
74882
74913
|
fixable: null,
|
|
74914
|
+
hasSuggestions: true,
|
|
74883
74915
|
schema: [],
|
|
74884
74916
|
|
|
74885
74917
|
messages: {
|
|
74886
74918
|
unexpected:
|
|
74887
74919
|
"Do not use the '{{operator}}' operator to compare against -0.",
|
|
74920
|
+
suggestRemoveMinus:
|
|
74921
|
+
"Replace '-0' with '0' (keeps the current comparison behavior).",
|
|
74922
|
+
suggestObjectIs:
|
|
74923
|
+
"Replace with 'Object.is()' (changes the comparison to distinguish -0 from +0).",
|
|
74924
|
+
suggestNotObjectIs:
|
|
74925
|
+
"Replace with '!Object.is()' (changes the comparison to distinguish -0 from +0).",
|
|
74888
74926
|
},
|
|
74889
74927
|
},
|
|
74890
74928
|
|
|
74891
74929
|
create(context) {
|
|
74930
|
+
const sourceCode = context.sourceCode;
|
|
74931
|
+
|
|
74892
74932
|
//--------------------------------------------------------------------------
|
|
74893
74933
|
// Helpers
|
|
74894
74934
|
//--------------------------------------------------------------------------
|
|
@@ -74906,6 +74946,18 @@ function requireNoCompareNegZero () {
|
|
|
74906
74946
|
node.argument.value === 0
|
|
74907
74947
|
);
|
|
74908
74948
|
}
|
|
74949
|
+
|
|
74950
|
+
/**
|
|
74951
|
+
* Gets the source text of an operand, keeping parentheses where required.
|
|
74952
|
+
* @param {ASTNode} operand A comparison operand node.
|
|
74953
|
+
* @returns {string} The source text of the operand.
|
|
74954
|
+
*/
|
|
74955
|
+
function getOperandText(operand) {
|
|
74956
|
+
const text = sourceCode.getText(operand);
|
|
74957
|
+
|
|
74958
|
+
return operand.type === "SequenceExpression" ? `(${text})` : text;
|
|
74959
|
+
}
|
|
74960
|
+
|
|
74909
74961
|
const OPERATORS_TO_CHECK = new Set([
|
|
74910
74962
|
">",
|
|
74911
74963
|
">=",
|
|
@@ -74919,15 +74971,71 @@ function requireNoCompareNegZero () {
|
|
|
74919
74971
|
|
|
74920
74972
|
return {
|
|
74921
74973
|
BinaryExpression(node) {
|
|
74922
|
-
if (OPERATORS_TO_CHECK.has(node.operator)) {
|
|
74923
|
-
|
|
74924
|
-
|
|
74925
|
-
|
|
74926
|
-
|
|
74927
|
-
|
|
74928
|
-
|
|
74929
|
-
|
|
74974
|
+
if (!OPERATORS_TO_CHECK.has(node.operator)) {
|
|
74975
|
+
return;
|
|
74976
|
+
}
|
|
74977
|
+
|
|
74978
|
+
const leftIsNegZero = isNegZero(node.left);
|
|
74979
|
+
const rightIsNegZero = isNegZero(node.right);
|
|
74980
|
+
|
|
74981
|
+
if (!leftIsNegZero && !rightIsNegZero) {
|
|
74982
|
+
return;
|
|
74930
74983
|
}
|
|
74984
|
+
|
|
74985
|
+
context.report({
|
|
74986
|
+
node,
|
|
74987
|
+
messageId: "unexpected",
|
|
74988
|
+
data: { operator: node.operator },
|
|
74989
|
+
suggest: [
|
|
74990
|
+
{
|
|
74991
|
+
messageId: "suggestRemoveMinus",
|
|
74992
|
+
*fix(fixer) {
|
|
74993
|
+
if (leftIsNegZero) {
|
|
74994
|
+
yield fixer.replaceText(node.left, "0");
|
|
74995
|
+
}
|
|
74996
|
+
if (rightIsNegZero) {
|
|
74997
|
+
yield fixer.replaceText(node.right, "0");
|
|
74998
|
+
}
|
|
74999
|
+
},
|
|
75000
|
+
},
|
|
75001
|
+
{
|
|
75002
|
+
messageId:
|
|
75003
|
+
node.operator === "==="
|
|
75004
|
+
? "suggestObjectIs"
|
|
75005
|
+
: "suggestNotObjectIs",
|
|
75006
|
+
fix(fixer) {
|
|
75007
|
+
if (
|
|
75008
|
+
(node.operator !== "===" &&
|
|
75009
|
+
node.operator !== "!==") ||
|
|
75010
|
+
sourceCode.getCommentsInside(node).length >
|
|
75011
|
+
0
|
|
75012
|
+
) {
|
|
75013
|
+
return null;
|
|
75014
|
+
}
|
|
75015
|
+
|
|
75016
|
+
const objectVariable = getVariableByName(
|
|
75017
|
+
sourceCode.getScope(node),
|
|
75018
|
+
"Object",
|
|
75019
|
+
);
|
|
75020
|
+
|
|
75021
|
+
if (
|
|
75022
|
+
!objectVariable ||
|
|
75023
|
+
objectVariable.identifiers.length > 0
|
|
75024
|
+
) {
|
|
75025
|
+
return null;
|
|
75026
|
+
}
|
|
75027
|
+
|
|
75028
|
+
const negation =
|
|
75029
|
+
node.operator === "===" ? "" : "!";
|
|
75030
|
+
|
|
75031
|
+
return fixer.replaceText(
|
|
75032
|
+
node,
|
|
75033
|
+
`${negation}Object.is(${getOperandText(node.left)}, ${getOperandText(node.right)})`,
|
|
75034
|
+
);
|
|
75035
|
+
},
|
|
75036
|
+
},
|
|
75037
|
+
],
|
|
75038
|
+
});
|
|
74931
75039
|
},
|
|
74932
75040
|
};
|
|
74933
75041
|
},
|
|
@@ -79686,6 +79794,8 @@ function requireNoControlRegex () {
|
|
|
79686
79794
|
},
|
|
79687
79795
|
|
|
79688
79796
|
create(context) {
|
|
79797
|
+
const sourceCode = context.sourceCode;
|
|
79798
|
+
|
|
79689
79799
|
/**
|
|
79690
79800
|
* Get the regex expression
|
|
79691
79801
|
* @param {ASTNode} node `Literal` node to evaluate
|
|
@@ -79704,6 +79814,7 @@ function requireNoControlRegex () {
|
|
|
79704
79814
|
node.parent.type === "CallExpression") &&
|
|
79705
79815
|
node.parent.callee.type === "Identifier" &&
|
|
79706
79816
|
node.parent.callee.name === "RegExp" &&
|
|
79817
|
+
sourceCode.isGlobalReference(node.parent.callee) &&
|
|
79707
79818
|
node.parent.arguments[0] === node
|
|
79708
79819
|
) {
|
|
79709
79820
|
const pattern = node.value;
|
|
@@ -86320,6 +86431,21 @@ function requireNoImplicitCoercion () {
|
|
|
86320
86431
|
const [options] = context.options;
|
|
86321
86432
|
const sourceCode = context.sourceCode;
|
|
86322
86433
|
|
|
86434
|
+
/**
|
|
86435
|
+
* Gets the source text of a node to be used as the argument of a
|
|
86436
|
+
* `Boolean()`, `Number()`, or `String()` call in a recommendation. A
|
|
86437
|
+
* `SequenceExpression` operand must be parenthesized, otherwise its commas
|
|
86438
|
+
* would be parsed as argument separators, which changes the evaluated
|
|
86439
|
+
* operand (for example `!!(a, b)` becomes `Boolean(a, b)`).
|
|
86440
|
+
* @param {ASTNode} node The operand node.
|
|
86441
|
+
* @returns {string} The source text, parenthesized if needed.
|
|
86442
|
+
*/
|
|
86443
|
+
function getOperandText(node) {
|
|
86444
|
+
const text = sourceCode.getText(node);
|
|
86445
|
+
|
|
86446
|
+
return node.type === "SequenceExpression" ? `(${text})` : text;
|
|
86447
|
+
}
|
|
86448
|
+
|
|
86323
86449
|
/**
|
|
86324
86450
|
* Reports an error and autofixes the node
|
|
86325
86451
|
* @param {ASTNode} node An ast node to report the error on.
|
|
@@ -86385,7 +86511,7 @@ function requireNoImplicitCoercion () {
|
|
|
86385
86511
|
options.boolean &&
|
|
86386
86512
|
isDoubleLogicalNegating(node)
|
|
86387
86513
|
) {
|
|
86388
|
-
const recommendation = `Boolean(${
|
|
86514
|
+
const recommendation = `Boolean(${getOperandText(node.argument.argument)})`;
|
|
86389
86515
|
const variable = astUtils.getVariableByName(
|
|
86390
86516
|
sourceCode.getScope(node),
|
|
86391
86517
|
"Boolean",
|
|
@@ -86420,7 +86546,7 @@ function requireNoImplicitCoercion () {
|
|
|
86420
86546
|
node.operator === "+" &&
|
|
86421
86547
|
!isNumeric(node.argument)
|
|
86422
86548
|
) {
|
|
86423
|
-
const recommendation = `Number(${
|
|
86549
|
+
const recommendation = `Number(${getOperandText(node.argument)})`;
|
|
86424
86550
|
|
|
86425
86551
|
report(node, recommendation, true, false);
|
|
86426
86552
|
}
|
|
@@ -86435,7 +86561,7 @@ function requireNoImplicitCoercion () {
|
|
|
86435
86561
|
node.argument.operator === "-" &&
|
|
86436
86562
|
!isNumeric(node.argument.argument)
|
|
86437
86563
|
) {
|
|
86438
|
-
const recommendation = `Number(${
|
|
86564
|
+
const recommendation = `Number(${getOperandText(node.argument.argument)})`;
|
|
86439
86565
|
|
|
86440
86566
|
report(node, recommendation, true, false);
|
|
86441
86567
|
}
|
|
@@ -86455,7 +86581,7 @@ function requireNoImplicitCoercion () {
|
|
|
86455
86581
|
getNonNumericOperand(node);
|
|
86456
86582
|
|
|
86457
86583
|
if (nonNumericOperand) {
|
|
86458
|
-
const recommendation = `Number(${
|
|
86584
|
+
const recommendation = `Number(${getOperandText(nonNumericOperand)})`;
|
|
86459
86585
|
|
|
86460
86586
|
report(node, recommendation, true, false);
|
|
86461
86587
|
}
|
|
@@ -86470,7 +86596,7 @@ function requireNoImplicitCoercion () {
|
|
|
86470
86596
|
node.right.value === 0 &&
|
|
86471
86597
|
!isNumeric(node.left)
|
|
86472
86598
|
) {
|
|
86473
|
-
const recommendation = `Number(${
|
|
86599
|
+
const recommendation = `Number(${getOperandText(node.left)})`;
|
|
86474
86600
|
|
|
86475
86601
|
report(node, recommendation, true, false);
|
|
86476
86602
|
}
|
|
@@ -86482,7 +86608,7 @@ function requireNoImplicitCoercion () {
|
|
|
86482
86608
|
options.string &&
|
|
86483
86609
|
isConcatWithEmptyString(node)
|
|
86484
86610
|
) {
|
|
86485
|
-
const recommendation = `String(${
|
|
86611
|
+
const recommendation = `String(${getOperandText(getNonEmptyOperand(node))})`;
|
|
86486
86612
|
|
|
86487
86613
|
report(node, recommendation, true, false);
|
|
86488
86614
|
}
|
|
@@ -86534,8 +86660,7 @@ function requireNoImplicitCoercion () {
|
|
|
86534
86660
|
return;
|
|
86535
86661
|
}
|
|
86536
86662
|
|
|
86537
|
-
const
|
|
86538
|
-
const recommendation = `String(${code})`;
|
|
86663
|
+
const recommendation = `String(${getOperandText(node.expressions[0])})`;
|
|
86539
86664
|
|
|
86540
86665
|
report(node, recommendation, true, false);
|
|
86541
86666
|
},
|
|
@@ -87494,6 +87619,7 @@ function requireNoInvalidRegexp () {
|
|
|
87494
87619
|
},
|
|
87495
87620
|
|
|
87496
87621
|
create(context) {
|
|
87622
|
+
const sourceCode = context.sourceCode;
|
|
87497
87623
|
const [{ allowConstructorFlags }] = context.options;
|
|
87498
87624
|
let allowedFlags = [];
|
|
87499
87625
|
|
|
@@ -87621,7 +87747,8 @@ function requireNoInvalidRegexp () {
|
|
|
87621
87747
|
"CallExpression, NewExpression"(node) {
|
|
87622
87748
|
if (
|
|
87623
87749
|
node.callee.type !== "Identifier" ||
|
|
87624
|
-
node.callee.name !== "RegExp"
|
|
87750
|
+
node.callee.name !== "RegExp" ||
|
|
87751
|
+
!sourceCode.isGlobalReference(node.callee)
|
|
87625
87752
|
) {
|
|
87626
87753
|
return;
|
|
87627
87754
|
}
|
|
@@ -91381,14 +91508,12 @@ function requireNoMixedSpacesAndTabs () {
|
|
|
91381
91508
|
sourceCode.getIndexFromLoc(loc.start),
|
|
91382
91509
|
);
|
|
91383
91510
|
|
|
91384
|
-
if (
|
|
91385
|
-
|
|
91386
|
-
|
|
91387
|
-
|
|
91388
|
-
containingNode.type,
|
|
91389
|
-
)
|
|
91511
|
+
if (!(
|
|
91512
|
+
containingNode &&
|
|
91513
|
+
["Literal", "TemplateElement"].includes(
|
|
91514
|
+
containingNode.type,
|
|
91390
91515
|
)
|
|
91391
|
-
) {
|
|
91516
|
+
)) {
|
|
91392
91517
|
context.report({
|
|
91393
91518
|
node,
|
|
91394
91519
|
loc,
|
|
@@ -94211,13 +94336,11 @@ function requireNoPromiseExecutorReturn () {
|
|
|
94211
94336
|
}
|
|
94212
94337
|
|
|
94213
94338
|
// Do not suggest wrapping an unnamed function or class expression in braces as that would be invalid syntax.
|
|
94214
|
-
if (
|
|
94215
|
-
|
|
94216
|
-
|
|
94217
|
-
|
|
94218
|
-
|
|
94219
|
-
)
|
|
94220
|
-
) {
|
|
94339
|
+
if (!(
|
|
94340
|
+
(node.body.type === "FunctionExpression" ||
|
|
94341
|
+
node.body.type === "ClassExpression") &&
|
|
94342
|
+
!node.body.id
|
|
94343
|
+
)) {
|
|
94221
94344
|
suggest.push({
|
|
94222
94345
|
messageId: "wrapBraces",
|
|
94223
94346
|
fix(fixer) {
|
|
@@ -97895,12 +98018,10 @@ function requireNoScriptUrl () {
|
|
|
97895
98018
|
}
|
|
97896
98019
|
},
|
|
97897
98020
|
TemplateLiteral(node) {
|
|
97898
|
-
if (
|
|
97899
|
-
|
|
97900
|
-
|
|
97901
|
-
|
|
97902
|
-
)
|
|
97903
|
-
) {
|
|
98021
|
+
if (!(
|
|
98022
|
+
node.parent &&
|
|
98023
|
+
node.parent.type === "TaggedTemplateExpression"
|
|
98024
|
+
)) {
|
|
97904
98025
|
check(node);
|
|
97905
98026
|
}
|
|
97906
98027
|
},
|
|
@@ -98867,12 +98988,10 @@ function requireNoShadow () {
|
|
|
98867
98988
|
|
|
98868
98989
|
const { variableScope } = variable.scope;
|
|
98869
98990
|
|
|
98870
|
-
if (
|
|
98871
|
-
|
|
98872
|
-
|
|
98873
|
-
|
|
98874
|
-
)
|
|
98875
|
-
) {
|
|
98991
|
+
if (!(
|
|
98992
|
+
FUNC_EXPR_NODE_TYPES.has(variableScope.block.type) &&
|
|
98993
|
+
getOuterScope(variableScope) === shadowedVariable.scope
|
|
98994
|
+
)) {
|
|
98876
98995
|
return false;
|
|
98877
98996
|
}
|
|
98878
98997
|
|
|
@@ -98997,14 +99116,12 @@ function requireNoShadow () {
|
|
|
98997
99116
|
return false;
|
|
98998
99117
|
}
|
|
98999
99118
|
|
|
99000
|
-
if (
|
|
99001
|
-
|
|
99002
|
-
|
|
99003
|
-
|
|
99004
|
-
|
|
99005
|
-
|
|
99006
|
-
)
|
|
99007
|
-
) {
|
|
99119
|
+
if (!(
|
|
99120
|
+
(innerDef.type === "FunctionName" &&
|
|
99121
|
+
innerDef.node.type === "FunctionExpression") ||
|
|
99122
|
+
(innerDef.type === "ClassName" &&
|
|
99123
|
+
innerDef.node.type === "ClassExpression")
|
|
99124
|
+
)) {
|
|
99008
99125
|
return false;
|
|
99009
99126
|
}
|
|
99010
99127
|
|
|
@@ -99024,12 +99141,10 @@ function requireNoShadow () {
|
|
|
99024
99141
|
const nodeToCheck = innerDef.node; // FunctionExpression or ClassExpression node
|
|
99025
99142
|
|
|
99026
99143
|
// Exit early if the node to check isn't inside the initializer
|
|
99027
|
-
if (
|
|
99028
|
-
|
|
99029
|
-
|
|
99030
|
-
|
|
99031
|
-
)
|
|
99032
|
-
) {
|
|
99144
|
+
if (!(
|
|
99145
|
+
initializerNode.range[0] <= nodeToCheck.range[0] &&
|
|
99146
|
+
nodeToCheck.range[1] <= initializerNode.range[1]
|
|
99147
|
+
)) {
|
|
99033
99148
|
return false;
|
|
99034
99149
|
}
|
|
99035
99150
|
|
|
@@ -115903,14 +116018,22 @@ function requirePreferNumericLiterals () {
|
|
|
115903
116018
|
* Checks to see if a CallExpression's callee node is `parseInt` or
|
|
115904
116019
|
* `Number.parseInt`.
|
|
115905
116020
|
* @param {ASTNode} calleeNode The callee node to evaluate.
|
|
116021
|
+
* @param {SourceCode} sourceCode The source code object.
|
|
115906
116022
|
* @returns {boolean} True if the callee is `parseInt` or `Number.parseInt`,
|
|
115907
116023
|
* false otherwise.
|
|
115908
116024
|
*/
|
|
115909
|
-
function isParseInt(calleeNode) {
|
|
115910
|
-
|
|
115911
|
-
|
|
115912
|
-
|
|
115913
|
-
|
|
116025
|
+
function isParseInt(calleeNode, sourceCode) {
|
|
116026
|
+
if (astUtils.isSpecificId(calleeNode, "parseInt")) {
|
|
116027
|
+
return sourceCode.isGlobalReference(calleeNode);
|
|
116028
|
+
}
|
|
116029
|
+
|
|
116030
|
+
if (astUtils.isSpecificMemberAccess(calleeNode, "Number", "parseInt")) {
|
|
116031
|
+
const objectNode = astUtils.skipChainExpression(calleeNode).object;
|
|
116032
|
+
|
|
116033
|
+
return sourceCode.isGlobalReference(objectNode);
|
|
116034
|
+
}
|
|
116035
|
+
|
|
116036
|
+
return false;
|
|
115914
116037
|
}
|
|
115915
116038
|
|
|
115916
116039
|
//------------------------------------------------------------------------------
|
|
@@ -115959,7 +116082,7 @@ function requirePreferNumericLiterals () {
|
|
|
115959
116082
|
radixNode.type === "Literal" &&
|
|
115960
116083
|
typeof radix === "number" &&
|
|
115961
116084
|
radixMap.has(radix) &&
|
|
115962
|
-
isParseInt(node.callee)
|
|
116085
|
+
isParseInt(node.callee, sourceCode)
|
|
115963
116086
|
) {
|
|
115964
116087
|
const { system, literalPrefix } = radixMap.get(radix);
|
|
115965
116088
|
|
|
@@ -116118,12 +116241,10 @@ function requirePreferObjectHasOwn () {
|
|
|
116118
116241
|
|
|
116119
116242
|
return {
|
|
116120
116243
|
CallExpression(node) {
|
|
116121
|
-
if (
|
|
116122
|
-
|
|
116123
|
-
|
|
116124
|
-
|
|
116125
|
-
)
|
|
116126
|
-
) {
|
|
116244
|
+
if (!(
|
|
116245
|
+
node.callee.type === "MemberExpression" &&
|
|
116246
|
+
node.callee.object.type === "MemberExpression"
|
|
116247
|
+
)) {
|
|
116127
116248
|
return;
|
|
116128
116249
|
}
|
|
116129
116250
|
|
|
@@ -118099,18 +118220,13 @@ function requirePreserveCaughtError () {
|
|
|
118099
118220
|
/**
|
|
118100
118221
|
* Finds and returns information about the `cause` property of an error being thrown.
|
|
118101
118222
|
* @param {ASTNode} throwStatement `ThrowStatement` to be checked.
|
|
118223
|
+
* @param {number} optionsIndex The index of the options argument in the error constructor.
|
|
118102
118224
|
* @returns {{ value: ASTNode; multipleDefinitions: boolean; } | UNKNOWN_CAUSE | null}
|
|
118103
118225
|
* Information about the `cause` of the error being thrown, such as the value node and
|
|
118104
118226
|
* whether there are multiple definitions of `cause`. `null` if there is no `cause`.
|
|
118105
118227
|
*/
|
|
118106
|
-
function getErrorCause(throwStatement) {
|
|
118228
|
+
function getErrorCause(throwStatement, optionsIndex) {
|
|
118107
118229
|
const throwExpression = throwStatement.argument;
|
|
118108
|
-
/*
|
|
118109
|
-
* Determine which argument index holds the options object
|
|
118110
|
-
* `AggregateError` is a special case as it accepts the `options` object as third argument.
|
|
118111
|
-
*/
|
|
118112
|
-
const optionsIndex =
|
|
118113
|
-
throwExpression.callee.name === "AggregateError" ? 2 : 1;
|
|
118114
118230
|
|
|
118115
118231
|
/*
|
|
118116
118232
|
* Make sure there is no `SpreadElement` at or before the `optionsIndex`
|
|
@@ -118211,6 +118327,7 @@ function requirePreserveCaughtError () {
|
|
|
118211
118327
|
defaultOptions: [
|
|
118212
118328
|
{
|
|
118213
118329
|
requireCatchParameter: false,
|
|
118330
|
+
errorClassNames: [],
|
|
118214
118331
|
},
|
|
118215
118332
|
],
|
|
118216
118333
|
|
|
@@ -118220,14 +118337,6 @@ function requirePreserveCaughtError () {
|
|
|
118220
118337
|
recommended: true,
|
|
118221
118338
|
url: "https://eslint.org/docs/latest/rules/preserve-caught-error", // URL to the documentation page for this rule
|
|
118222
118339
|
},
|
|
118223
|
-
/*
|
|
118224
|
-
* TODO: We should allow passing `customErrorTypes` option once something like `typescript-eslint`'s
|
|
118225
|
-
* `TypeOrValueSpecifier` is implemented in core Eslint.
|
|
118226
|
-
* See:
|
|
118227
|
-
* 1. https://typescript-eslint.io/packages/type-utils/type-or-value-specifier/
|
|
118228
|
-
* 2. https://github.com/eslint/eslint/pull/19913#discussion_r2192608593
|
|
118229
|
-
* 3. https://github.com/eslint/eslint/discussions/16540
|
|
118230
|
-
*/
|
|
118231
118340
|
schema: [
|
|
118232
118341
|
{
|
|
118233
118342
|
type: "object",
|
|
@@ -118237,6 +118346,33 @@ function requirePreserveCaughtError () {
|
|
|
118237
118346
|
description:
|
|
118238
118347
|
"Requires the catch blocks to always have the caught error parameter so it is not discarded.",
|
|
118239
118348
|
},
|
|
118349
|
+
errorClassNames: {
|
|
118350
|
+
type: "array",
|
|
118351
|
+
description:
|
|
118352
|
+
"Additional error class names to check for cause preservation.",
|
|
118353
|
+
items: {
|
|
118354
|
+
oneOf: [
|
|
118355
|
+
{
|
|
118356
|
+
type: "string",
|
|
118357
|
+
},
|
|
118358
|
+
{
|
|
118359
|
+
type: "object",
|
|
118360
|
+
required: ["name", "argumentPosition"],
|
|
118361
|
+
properties: {
|
|
118362
|
+
name: {
|
|
118363
|
+
type: "string",
|
|
118364
|
+
},
|
|
118365
|
+
argumentPosition: {
|
|
118366
|
+
type: "integer",
|
|
118367
|
+
minimum: 1,
|
|
118368
|
+
},
|
|
118369
|
+
},
|
|
118370
|
+
additionalProperties: false,
|
|
118371
|
+
},
|
|
118372
|
+
],
|
|
118373
|
+
},
|
|
118374
|
+
uniqueItems: true,
|
|
118375
|
+
},
|
|
118240
118376
|
},
|
|
118241
118377
|
additionalProperties: false,
|
|
118242
118378
|
},
|
|
@@ -118260,12 +118396,34 @@ function requirePreserveCaughtError () {
|
|
|
118260
118396
|
|
|
118261
118397
|
create(context) {
|
|
118262
118398
|
const sourceCode = context.sourceCode;
|
|
118263
|
-
const [{ requireCatchParameter }] = context.options;
|
|
118399
|
+
const [{ requireCatchParameter, errorClassNames }] = context.options;
|
|
118400
|
+
|
|
118401
|
+
const errorClassNamesMap = new Map();
|
|
118402
|
+
for (const item of errorClassNames) {
|
|
118403
|
+
const name = typeof item === "string" ? item : item.name;
|
|
118404
|
+
const argumentPosition =
|
|
118405
|
+
typeof item === "string" ? 2 : item.argumentPosition;
|
|
118406
|
+
|
|
118407
|
+
errorClassNamesMap.set(name, argumentPosition);
|
|
118408
|
+
}
|
|
118264
118409
|
|
|
118265
118410
|
//----------------------------------------------------------------------
|
|
118266
118411
|
// Helpers
|
|
118267
118412
|
//----------------------------------------------------------------------
|
|
118268
118413
|
|
|
118414
|
+
/**
|
|
118415
|
+
* Checks if the given callee refers to a built-in global Error constructor.
|
|
118416
|
+
* @param {ASTNode} callee The callee node.
|
|
118417
|
+
* @returns {boolean} `true` if the callee is a built-in global Error constructor.
|
|
118418
|
+
*/
|
|
118419
|
+
function isBuiltInGlobalError(callee) {
|
|
118420
|
+
return (
|
|
118421
|
+
callee.type === "Identifier" &&
|
|
118422
|
+
BUILT_IN_ERROR_TYPES.has(callee.name) &&
|
|
118423
|
+
sourceCode.isGlobalReference(callee)
|
|
118424
|
+
);
|
|
118425
|
+
}
|
|
118426
|
+
|
|
118269
118427
|
/**
|
|
118270
118428
|
* Checks if a `ThrowStatement` is constructing and throwing a new `Error` object.
|
|
118271
118429
|
*
|
|
@@ -118275,18 +118433,33 @@ function requirePreserveCaughtError () {
|
|
|
118275
118433
|
* @returns {boolean} `true` if a new "Error" is being thrown, else `false`.
|
|
118276
118434
|
*/
|
|
118277
118435
|
function isThrowingNewError(throwStatement) {
|
|
118436
|
+
if (!(
|
|
118437
|
+
throwStatement.argument.type === "NewExpression" ||
|
|
118438
|
+
throwStatement.argument.type === "CallExpression"
|
|
118439
|
+
)) {
|
|
118440
|
+
return false;
|
|
118441
|
+
}
|
|
118442
|
+
|
|
118443
|
+
const callee = throwStatement.argument.callee;
|
|
118444
|
+
|
|
118445
|
+
/*
|
|
118446
|
+
* Make sure the thrown Error instance is one of the built-in global error types.
|
|
118447
|
+
* Custom imports could shadow this, which would lead to false positives.
|
|
118448
|
+
* e.g. import { Error } from "./my-custom-error.js";
|
|
118449
|
+
* throw Error("Failed to perform error prone operations");
|
|
118450
|
+
*/
|
|
118451
|
+
if (isBuiltInGlobalError(callee)) {
|
|
118452
|
+
return true;
|
|
118453
|
+
}
|
|
118454
|
+
|
|
118455
|
+
const target =
|
|
118456
|
+
callee.type === "MemberExpression" && !callee.computed
|
|
118457
|
+
? callee.property
|
|
118458
|
+
: callee;
|
|
118459
|
+
|
|
118278
118460
|
return (
|
|
118279
|
-
|
|
118280
|
-
|
|
118281
|
-
throwStatement.argument.callee.type === "Identifier" &&
|
|
118282
|
-
BUILT_IN_ERROR_TYPES.has(throwStatement.argument.callee.name) &&
|
|
118283
|
-
/*
|
|
118284
|
-
* Make sure the thrown Error is instance is one of the built-in global error types.
|
|
118285
|
-
* Custom imports could shadow this, which would lead to false positives.
|
|
118286
|
-
* e.g. import { Error } from "./my-custom-error.js";
|
|
118287
|
-
* throw Error("Failed to perform error prone operations");
|
|
118288
|
-
*/
|
|
118289
|
-
sourceCode.isGlobalReference(throwStatement.argument.callee)
|
|
118461
|
+
target.type === "Identifier" &&
|
|
118462
|
+
errorClassNamesMap.has(target.name)
|
|
118290
118463
|
);
|
|
118291
118464
|
}
|
|
118292
118465
|
|
|
@@ -118315,6 +118488,30 @@ function requirePreserveCaughtError () {
|
|
|
118315
118488
|
);
|
|
118316
118489
|
}
|
|
118317
118490
|
|
|
118491
|
+
/**
|
|
118492
|
+
* Gets the token after which new arguments should be inserted for the
|
|
118493
|
+
* given argument, accounting for parentheses wrapping the argument so
|
|
118494
|
+
* that insertions land outside them (e.g. `new Error(("msg"))`).
|
|
118495
|
+
* @param {ASTNode} argNode The argument node.
|
|
118496
|
+
* @param {ASTNode} callNode The enclosing call or new expression.
|
|
118497
|
+
* @returns {Token} The token to insert after.
|
|
118498
|
+
*/
|
|
118499
|
+
function getLastArgumentToken(argNode, callNode) {
|
|
118500
|
+
const callLastToken = sourceCode.getLastToken(callNode);
|
|
118501
|
+
let token = sourceCode.getLastToken(argNode);
|
|
118502
|
+
let nextToken = sourceCode.getTokenAfter(token);
|
|
118503
|
+
|
|
118504
|
+
while (
|
|
118505
|
+
nextToken &&
|
|
118506
|
+
nextToken !== callLastToken &&
|
|
118507
|
+
astUtils.isClosingParenToken(nextToken)
|
|
118508
|
+
) {
|
|
118509
|
+
token = nextToken;
|
|
118510
|
+
nextToken = sourceCode.getTokenAfter(token);
|
|
118511
|
+
}
|
|
118512
|
+
return token;
|
|
118513
|
+
}
|
|
118514
|
+
|
|
118318
118515
|
//----------------------------------------------------------------------
|
|
118319
118516
|
// Public
|
|
118320
118517
|
//----------------------------------------------------------------------
|
|
@@ -118358,8 +118555,30 @@ function requirePreserveCaughtError () {
|
|
|
118358
118555
|
return;
|
|
118359
118556
|
}
|
|
118360
118557
|
|
|
118558
|
+
// Determine the options argument index
|
|
118559
|
+
const callee = throwStatement.argument.callee;
|
|
118560
|
+
const errorClassName =
|
|
118561
|
+
callee.type === "Identifier"
|
|
118562
|
+
? callee.name
|
|
118563
|
+
: callee.property.name;
|
|
118564
|
+
|
|
118565
|
+
const builtInGlobalError = isBuiltInGlobalError(callee);
|
|
118566
|
+
|
|
118567
|
+
let optionsIndex;
|
|
118568
|
+
if (builtInGlobalError) {
|
|
118569
|
+
optionsIndex =
|
|
118570
|
+
errorClassName === "AggregateError" ? 2 : 1;
|
|
118571
|
+
} else {
|
|
118572
|
+
const argumentPosition =
|
|
118573
|
+
errorClassNamesMap.get(errorClassName);
|
|
118574
|
+
optionsIndex = argumentPosition - 1;
|
|
118575
|
+
}
|
|
118576
|
+
|
|
118361
118577
|
// Check if there is a cause attached to the new error
|
|
118362
|
-
const errorCauseInfo = getErrorCause(
|
|
118578
|
+
const errorCauseInfo = getErrorCause(
|
|
118579
|
+
throwStatement,
|
|
118580
|
+
optionsIndex,
|
|
118581
|
+
);
|
|
118363
118582
|
|
|
118364
118583
|
if (errorCauseInfo === UNKNOWN_CAUSE) {
|
|
118365
118584
|
// Error options exist, but too complicated to be analyzed/fixed
|
|
@@ -118378,11 +118597,33 @@ function requirePreserveCaughtError () {
|
|
|
118378
118597
|
const throwExpression =
|
|
118379
118598
|
throwStatement.argument;
|
|
118380
118599
|
const args = throwExpression.arguments;
|
|
118381
|
-
|
|
118382
|
-
|
|
118600
|
+
|
|
118601
|
+
/**
|
|
118602
|
+
* Inserts `cause` into the options argument if it is an `ObjectExpression`.
|
|
118603
|
+
* @param {ASTNode} optionsArg The options argument node.
|
|
118604
|
+
* @returns {Fix | null} The fix, or `null` if the argument is not an object.
|
|
118605
|
+
*/
|
|
118606
|
+
function fixExistingOptions(
|
|
118607
|
+
optionsArg,
|
|
118608
|
+
) {
|
|
118609
|
+
if (
|
|
118610
|
+
optionsArg.type ===
|
|
118611
|
+
"ObjectExpression"
|
|
118612
|
+
) {
|
|
118613
|
+
return insertCauseIntoOptions(
|
|
118614
|
+
fixer,
|
|
118615
|
+
optionsArg,
|
|
118616
|
+
caughtError.name,
|
|
118617
|
+
);
|
|
118618
|
+
}
|
|
118619
|
+
return null;
|
|
118620
|
+
}
|
|
118383
118621
|
|
|
118384
118622
|
// AggregateError: errors, message, options
|
|
118385
|
-
if (
|
|
118623
|
+
if (
|
|
118624
|
+
builtInGlobalError &&
|
|
118625
|
+
errorClassName === "AggregateError"
|
|
118626
|
+
) {
|
|
118386
118627
|
const errorsArg = args[0];
|
|
118387
118628
|
const messageArg = args[1];
|
|
118388
118629
|
const optionsArg = args[2];
|
|
@@ -118419,7 +118660,10 @@ function requirePreserveCaughtError () {
|
|
|
118419
118660
|
if (!messageArg) {
|
|
118420
118661
|
// Case: `throw new AggregateError([])` → insert message and options
|
|
118421
118662
|
return fixer.insertTextAfter(
|
|
118422
|
-
|
|
118663
|
+
getLastArgumentToken(
|
|
118664
|
+
errorsArg,
|
|
118665
|
+
throwExpression,
|
|
118666
|
+
),
|
|
118423
118667
|
`, "", { cause: ${caughtError.name} }`,
|
|
118424
118668
|
);
|
|
118425
118669
|
}
|
|
@@ -118427,32 +118671,94 @@ function requirePreserveCaughtError () {
|
|
|
118427
118671
|
if (!optionsArg) {
|
|
118428
118672
|
// Case: `throw new AggregateError([], "")` → insert error options only
|
|
118429
118673
|
return fixer.insertTextAfter(
|
|
118430
|
-
|
|
118674
|
+
getLastArgumentToken(
|
|
118675
|
+
messageArg,
|
|
118676
|
+
throwExpression,
|
|
118677
|
+
),
|
|
118431
118678
|
`, { cause: ${caughtError.name} }`,
|
|
118432
118679
|
);
|
|
118433
118680
|
}
|
|
118434
118681
|
|
|
118435
|
-
|
|
118436
|
-
optionsArg
|
|
118437
|
-
|
|
118438
|
-
|
|
118439
|
-
|
|
118440
|
-
|
|
118441
|
-
|
|
118442
|
-
|
|
118682
|
+
return fixExistingOptions(
|
|
118683
|
+
optionsArg,
|
|
118684
|
+
);
|
|
118685
|
+
}
|
|
118686
|
+
|
|
118687
|
+
// Normal Error types
|
|
118688
|
+
if (builtInGlobalError) {
|
|
118689
|
+
const messageArg = args[0];
|
|
118690
|
+
const optionsArg = args[1];
|
|
118691
|
+
|
|
118692
|
+
if (!messageArg) {
|
|
118693
|
+
// Case: `throw new Error()` → insert both message and options
|
|
118694
|
+
const lastToken =
|
|
118695
|
+
sourceCode.getLastToken(
|
|
118696
|
+
throwExpression,
|
|
118697
|
+
);
|
|
118698
|
+
const lastCalleeToken =
|
|
118699
|
+
sourceCode.getLastToken(
|
|
118700
|
+
throwExpression.callee,
|
|
118701
|
+
);
|
|
118702
|
+
const parenToken =
|
|
118703
|
+
sourceCode.getFirstTokenBetween(
|
|
118704
|
+
lastCalleeToken,
|
|
118705
|
+
lastToken,
|
|
118706
|
+
astUtils.isOpeningParenToken,
|
|
118707
|
+
);
|
|
118708
|
+
|
|
118709
|
+
if (parenToken) {
|
|
118710
|
+
return fixer.insertTextAfter(
|
|
118711
|
+
parenToken,
|
|
118712
|
+
`"", { cause: ${caughtError.name} }`,
|
|
118713
|
+
);
|
|
118714
|
+
}
|
|
118715
|
+
return fixer.insertTextAfter(
|
|
118716
|
+
throwExpression.callee,
|
|
118717
|
+
`("", { cause: ${caughtError.name} })`,
|
|
118443
118718
|
);
|
|
118444
118719
|
}
|
|
118720
|
+
if (!optionsArg) {
|
|
118721
|
+
// Case: `throw new Error("Some message")` → insert only options
|
|
118722
|
+
return fixer.insertTextAfter(
|
|
118723
|
+
getLastArgumentToken(
|
|
118724
|
+
messageArg,
|
|
118725
|
+
throwExpression,
|
|
118726
|
+
),
|
|
118727
|
+
`, { cause: ${caughtError.name} }`,
|
|
118728
|
+
);
|
|
118729
|
+
}
|
|
118730
|
+
|
|
118731
|
+
return fixExistingOptions(
|
|
118732
|
+
optionsArg,
|
|
118733
|
+
);
|
|
118734
|
+
}
|
|
118735
|
+
|
|
118736
|
+
// Custom error types
|
|
118737
|
+
const optionsArg = args[optionsIndex];
|
|
118445
118738
|
|
|
118446
|
-
|
|
118739
|
+
/*
|
|
118740
|
+
* Custom error signature is unknown, so skip the suggestion rather
|
|
118741
|
+
* than synthesize placeholder values for missing positional args.
|
|
118742
|
+
*/
|
|
118743
|
+
if (args.length < optionsIndex) {
|
|
118447
118744
|
return null;
|
|
118448
118745
|
}
|
|
118449
118746
|
|
|
118450
|
-
|
|
118451
|
-
|
|
118452
|
-
|
|
118747
|
+
if (!optionsArg) {
|
|
118748
|
+
const lastProvidedArg = args.at(-1);
|
|
118749
|
+
|
|
118750
|
+
if (lastProvidedArg) {
|
|
118751
|
+
// Options slot missing, all prior args provided → append options
|
|
118752
|
+
return fixer.insertTextAfter(
|
|
118753
|
+
getLastArgumentToken(
|
|
118754
|
+
lastProvidedArg,
|
|
118755
|
+
throwExpression,
|
|
118756
|
+
),
|
|
118757
|
+
`, { cause: ${caughtError.name} }`,
|
|
118758
|
+
);
|
|
118759
|
+
}
|
|
118453
118760
|
|
|
118454
|
-
|
|
118455
|
-
// Case: `throw new Error()` → insert both message and options
|
|
118761
|
+
// argumentPosition: 1 and no args → insert `{ cause: err }` inside parens
|
|
118456
118762
|
const lastToken =
|
|
118457
118763
|
sourceCode.getLastToken(
|
|
118458
118764
|
throwExpression,
|
|
@@ -118471,34 +118777,16 @@ function requirePreserveCaughtError () {
|
|
|
118471
118777
|
if (parenToken) {
|
|
118472
118778
|
return fixer.insertTextAfter(
|
|
118473
118779
|
parenToken,
|
|
118474
|
-
`
|
|
118780
|
+
`{ cause: ${caughtError.name} }`,
|
|
118475
118781
|
);
|
|
118476
118782
|
}
|
|
118477
118783
|
return fixer.insertTextAfter(
|
|
118478
118784
|
throwExpression.callee,
|
|
118479
|
-
`(
|
|
118480
|
-
);
|
|
118481
|
-
}
|
|
118482
|
-
if (!optionsArg) {
|
|
118483
|
-
// Case: `throw new Error("Some message")` → insert only options
|
|
118484
|
-
return fixer.insertTextAfter(
|
|
118485
|
-
messageArg,
|
|
118486
|
-
`, { cause: ${caughtError.name} }`,
|
|
118487
|
-
);
|
|
118488
|
-
}
|
|
118489
|
-
|
|
118490
|
-
if (
|
|
118491
|
-
optionsArg.type ===
|
|
118492
|
-
"ObjectExpression"
|
|
118493
|
-
) {
|
|
118494
|
-
return insertCauseIntoOptions(
|
|
118495
|
-
fixer,
|
|
118496
|
-
optionsArg,
|
|
118497
|
-
caughtError.name,
|
|
118785
|
+
`({ cause: ${caughtError.name} })`,
|
|
118498
118786
|
);
|
|
118499
118787
|
}
|
|
118500
118788
|
|
|
118501
|
-
return
|
|
118789
|
+
return fixExistingOptions(optionsArg);
|
|
118502
118790
|
},
|
|
118503
118791
|
},
|
|
118504
118792
|
],
|
|
@@ -118511,12 +118799,10 @@ function requirePreserveCaughtError () {
|
|
|
118511
118799
|
const { value: thrownErrorCause } = errorCauseInfo;
|
|
118512
118800
|
|
|
118513
118801
|
// If there is an attached cause, verify that it matches the caught error
|
|
118514
|
-
if (
|
|
118515
|
-
|
|
118516
|
-
|
|
118517
|
-
|
|
118518
|
-
)
|
|
118519
|
-
) {
|
|
118802
|
+
if (!(
|
|
118803
|
+
thrownErrorCause.type === "Identifier" &&
|
|
118804
|
+
thrownErrorCause.name === caughtError.name
|
|
118805
|
+
)) {
|
|
118520
118806
|
const suggest = errorCauseInfo.multipleDefinitions
|
|
118521
118807
|
? null // If there are multiple `cause` definitions, a suggestion could be confusing.
|
|
118522
118808
|
: [
|
|
@@ -119463,21 +119749,6 @@ function requireRadix () {
|
|
|
119463
119749
|
return variable.defs.length >= 1;
|
|
119464
119750
|
}
|
|
119465
119751
|
|
|
119466
|
-
/**
|
|
119467
|
-
* Checks whether a given node is a MemberExpression of `parseInt` method or not.
|
|
119468
|
-
* @param {ASTNode} node A node to check.
|
|
119469
|
-
* @returns {boolean} `true` if the node is a MemberExpression of `parseInt`
|
|
119470
|
-
* method.
|
|
119471
|
-
*/
|
|
119472
|
-
function isParseIntMethod(node) {
|
|
119473
|
-
return (
|
|
119474
|
-
node.type === "MemberExpression" &&
|
|
119475
|
-
!node.computed &&
|
|
119476
|
-
node.property.type === "Identifier" &&
|
|
119477
|
-
node.property.name === "parseInt"
|
|
119478
|
-
);
|
|
119479
|
-
}
|
|
119480
|
-
|
|
119481
119752
|
/**
|
|
119482
119753
|
* Checks whether a given node is a valid value of radix or not.
|
|
119483
119754
|
*
|
|
@@ -119490,6 +119761,20 @@ function requireRadix () {
|
|
|
119490
119761
|
* @returns {boolean} `true` if the node is valid.
|
|
119491
119762
|
*/
|
|
119492
119763
|
function isValidRadix(radix, sourceCode) {
|
|
119764
|
+
if (
|
|
119765
|
+
radix.type === "UnaryExpression" &&
|
|
119766
|
+
(radix.operator === "-" || radix.operator === "+") &&
|
|
119767
|
+
radix.argument.type === "Literal" &&
|
|
119768
|
+
typeof radix.argument.value === "number"
|
|
119769
|
+
) {
|
|
119770
|
+
const value =
|
|
119771
|
+
radix.operator === "-"
|
|
119772
|
+
? -radix.argument.value
|
|
119773
|
+
: radix.argument.value;
|
|
119774
|
+
|
|
119775
|
+
return validRadixValues.has(value);
|
|
119776
|
+
}
|
|
119777
|
+
|
|
119493
119778
|
return !(
|
|
119494
119779
|
(radix.type === "Literal" && !validRadixValues.has(radix.value)) ||
|
|
119495
119780
|
(radix.type === "Identifier" &&
|
|
@@ -119544,49 +119829,47 @@ function requireRadix () {
|
|
|
119544
119829
|
*/
|
|
119545
119830
|
function checkArguments(node) {
|
|
119546
119831
|
const args = node.arguments;
|
|
119832
|
+
const spreadIndex = args.findIndex(
|
|
119833
|
+
arg => arg.type === "SpreadElement",
|
|
119834
|
+
);
|
|
119547
119835
|
|
|
119548
|
-
|
|
119549
|
-
|
|
119550
|
-
|
|
119551
|
-
node,
|
|
119552
|
-
messageId: "missingParameters",
|
|
119553
|
-
});
|
|
119554
|
-
break;
|
|
119836
|
+
if (spreadIndex !== -1 && spreadIndex < 2) {
|
|
119837
|
+
return;
|
|
119838
|
+
}
|
|
119555
119839
|
|
|
119556
|
-
|
|
119557
|
-
|
|
119558
|
-
|
|
119559
|
-
|
|
119560
|
-
|
|
119561
|
-
|
|
119562
|
-
|
|
119563
|
-
|
|
119564
|
-
|
|
119565
|
-
|
|
119566
|
-
|
|
119567
|
-
|
|
119568
|
-
|
|
119569
|
-
|
|
119570
|
-
|
|
119571
|
-
|
|
119572
|
-
return fixer.insertTextBefore(
|
|
119573
|
-
lastToken,
|
|
119574
|
-
hasTrailingComma ? " 10," : ", 10",
|
|
119575
|
-
);
|
|
119576
|
-
},
|
|
119577
|
-
},
|
|
119578
|
-
],
|
|
119579
|
-
});
|
|
119580
|
-
break;
|
|
119840
|
+
if (args.length === 0) {
|
|
119841
|
+
context.report({
|
|
119842
|
+
node,
|
|
119843
|
+
messageId: "missingParameters",
|
|
119844
|
+
});
|
|
119845
|
+
} else if (args.length === 1) {
|
|
119846
|
+
context.report({
|
|
119847
|
+
node,
|
|
119848
|
+
messageId: "missingRadix",
|
|
119849
|
+
suggest: [
|
|
119850
|
+
{
|
|
119851
|
+
messageId: "addRadixParameter10",
|
|
119852
|
+
fix(fixer) {
|
|
119853
|
+
const lastToken = sourceCode.getLastToken(node);
|
|
119854
|
+
const prevToken =
|
|
119855
|
+
sourceCode.getTokenBefore(lastToken);
|
|
119581
119856
|
|
|
119582
|
-
|
|
119583
|
-
|
|
119584
|
-
|
|
119585
|
-
|
|
119586
|
-
|
|
119587
|
-
|
|
119588
|
-
|
|
119589
|
-
|
|
119857
|
+
const hasTrailingComma =
|
|
119858
|
+
astUtils.isCommaToken(prevToken);
|
|
119859
|
+
|
|
119860
|
+
return fixer.insertTextBefore(
|
|
119861
|
+
lastToken,
|
|
119862
|
+
hasTrailingComma ? " 10," : ", 10",
|
|
119863
|
+
);
|
|
119864
|
+
},
|
|
119865
|
+
},
|
|
119866
|
+
],
|
|
119867
|
+
});
|
|
119868
|
+
} else if (!isValidRadix(args[1], sourceCode)) {
|
|
119869
|
+
context.report({
|
|
119870
|
+
node,
|
|
119871
|
+
messageId: "invalidRadix",
|
|
119872
|
+
});
|
|
119590
119873
|
}
|
|
119591
119874
|
}
|
|
119592
119875
|
|
|
@@ -119618,7 +119901,11 @@ function requireRadix () {
|
|
|
119618
119901
|
: parentNode;
|
|
119619
119902
|
|
|
119620
119903
|
if (
|
|
119621
|
-
|
|
119904
|
+
astUtils.isSpecificMemberAccess(
|
|
119905
|
+
parentNode,
|
|
119906
|
+
"Number",
|
|
119907
|
+
"parseInt",
|
|
119908
|
+
) &&
|
|
119622
119909
|
astUtils.isCallee(maybeCallee)
|
|
119623
119910
|
) {
|
|
119624
119911
|
checkArguments(maybeCallee.parent);
|
|
@@ -125553,9 +125840,10 @@ function requireUseIsnan () {
|
|
|
125553
125840
|
/**
|
|
125554
125841
|
* Determines if the given node is a NaN `Identifier` node.
|
|
125555
125842
|
* @param {ASTNode|null} node The node to check.
|
|
125556
|
-
* @
|
|
125843
|
+
* @param {SourceCode} sourceCode The source code object.
|
|
125844
|
+
* @returns {boolean} `true` if the node is a global 'NaN' identifier.
|
|
125557
125845
|
*/
|
|
125558
|
-
function isNaNIdentifier(node) {
|
|
125846
|
+
function isNaNIdentifier(node, sourceCode) {
|
|
125559
125847
|
if (!node) {
|
|
125560
125848
|
return false;
|
|
125561
125849
|
}
|
|
@@ -125563,10 +125851,16 @@ function requireUseIsnan () {
|
|
|
125563
125851
|
const nodeToCheck =
|
|
125564
125852
|
node.type === "SequenceExpression" ? node.expressions.at(-1) : node;
|
|
125565
125853
|
|
|
125566
|
-
|
|
125567
|
-
|
|
125568
|
-
|
|
125569
|
-
|
|
125854
|
+
if (astUtils.isSpecificId(nodeToCheck, "NaN")) {
|
|
125855
|
+
return sourceCode.isGlobalReference(nodeToCheck);
|
|
125856
|
+
}
|
|
125857
|
+
|
|
125858
|
+
if (astUtils.isSpecificMemberAccess(nodeToCheck, "Number", "NaN")) {
|
|
125859
|
+
const objectNode = astUtils.skipChainExpression(nodeToCheck).object;
|
|
125860
|
+
return sourceCode.isGlobalReference(objectNode);
|
|
125861
|
+
}
|
|
125862
|
+
|
|
125863
|
+
return false;
|
|
125570
125864
|
}
|
|
125571
125865
|
|
|
125572
125866
|
//------------------------------------------------------------------------------
|
|
@@ -125638,7 +125932,7 @@ function requireUseIsnan () {
|
|
|
125638
125932
|
*/
|
|
125639
125933
|
function getBinaryExpressionFixer(node, wrapValue) {
|
|
125640
125934
|
return fixer => {
|
|
125641
|
-
const comparedValue = isNaNIdentifier(node.left)
|
|
125935
|
+
const comparedValue = isNaNIdentifier(node.left, sourceCode)
|
|
125642
125936
|
? node.right
|
|
125643
125937
|
: node.left;
|
|
125644
125938
|
const shouldWrap = comparedValue.type === "SequenceExpression";
|
|
@@ -125665,10 +125959,11 @@ function requireUseIsnan () {
|
|
|
125665
125959
|
function checkBinaryExpression(node) {
|
|
125666
125960
|
if (
|
|
125667
125961
|
/^(?:[<>]|[!=]=)=?$/u.test(node.operator) &&
|
|
125668
|
-
(isNaNIdentifier(node.left) ||
|
|
125962
|
+
(isNaNIdentifier(node.left, sourceCode) ||
|
|
125963
|
+
isNaNIdentifier(node.right, sourceCode))
|
|
125669
125964
|
) {
|
|
125670
125965
|
const suggestedFixes = [];
|
|
125671
|
-
const NaNNode = isNaNIdentifier(node.left)
|
|
125966
|
+
const NaNNode = isNaNIdentifier(node.left, sourceCode)
|
|
125672
125967
|
? node.left
|
|
125673
125968
|
: node.right;
|
|
125674
125969
|
|
|
@@ -125713,12 +126008,12 @@ function requireUseIsnan () {
|
|
|
125713
126008
|
* @returns {void}
|
|
125714
126009
|
*/
|
|
125715
126010
|
function checkSwitchStatement(node) {
|
|
125716
|
-
if (isNaNIdentifier(node.discriminant)) {
|
|
126011
|
+
if (isNaNIdentifier(node.discriminant, sourceCode)) {
|
|
125717
126012
|
context.report({ node, messageId: "switchNaN" });
|
|
125718
126013
|
}
|
|
125719
126014
|
|
|
125720
126015
|
for (const switchCase of node.cases) {
|
|
125721
|
-
if (isNaNIdentifier(switchCase.test)) {
|
|
126016
|
+
if (isNaNIdentifier(switchCase.test, sourceCode)) {
|
|
125722
126017
|
context.report({ node: switchCase, messageId: "caseNaN" });
|
|
125723
126018
|
}
|
|
125724
126019
|
}
|
|
@@ -125739,7 +126034,7 @@ function requireUseIsnan () {
|
|
|
125739
126034
|
(methodName === "indexOf" ||
|
|
125740
126035
|
methodName === "lastIndexOf") &&
|
|
125741
126036
|
node.arguments.length <= 2 &&
|
|
125742
|
-
isNaNIdentifier(node.arguments[0])
|
|
126037
|
+
isNaNIdentifier(node.arguments[0], sourceCode)
|
|
125743
126038
|
) {
|
|
125744
126039
|
/*
|
|
125745
126040
|
* To retain side effects, it's essential to address `NaN` beforehand, which
|