@bigbinary/eslint-plugin-neeto 1.13.2 → 2.0.1
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/dist/index.js +660 -203
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -286,7 +286,7 @@
|
|
|
286
286
|
}
|
|
287
287
|
});
|
|
288
288
|
|
|
289
|
-
var version = "
|
|
289
|
+
var version = "2.0.0";
|
|
290
290
|
var packageJson = {
|
|
291
291
|
version: version};
|
|
292
292
|
|
|
@@ -567,7 +567,7 @@
|
|
|
567
567
|
});
|
|
568
568
|
|
|
569
569
|
const getIndentation = (node, context) => {
|
|
570
|
-
const indentLevel = context.
|
|
570
|
+
const indentLevel = context.sourceCode.getFirstToken(node).loc.start.column;
|
|
571
571
|
return " ".repeat(indentLevel);
|
|
572
572
|
};
|
|
573
573
|
|
|
@@ -582,7 +582,7 @@
|
|
|
582
582
|
},
|
|
583
583
|
create: context => ({
|
|
584
584
|
Property(node) {
|
|
585
|
-
if (!context.
|
|
585
|
+
if (!context.filename.endsWith("package.json") || node.key.value !== "devDependencies") {
|
|
586
586
|
return;
|
|
587
587
|
}
|
|
588
588
|
PACKAGES_TO_CHECK.forEach(packageName => {
|
|
@@ -679,7 +679,7 @@
|
|
|
679
679
|
* @param {Object} node - AST node
|
|
680
680
|
* @returns the source code corresponding to the supplied node.
|
|
681
681
|
*/
|
|
682
|
-
const getCode$1 = (context, node) => context.
|
|
682
|
+
const getCode$1 = (context, node) => context.sourceCode.text.substr(node.range[0], node.range[1] - node.range[0]);
|
|
683
683
|
|
|
684
684
|
/**
|
|
685
685
|
* Checks if the specified package is imported or not
|
|
@@ -687,8 +687,25 @@
|
|
|
687
687
|
* @param {Object} context eslint context
|
|
688
688
|
* @returns an array containing the filename and the extension
|
|
689
689
|
*/
|
|
690
|
+
/**
|
|
691
|
+
* Location for a problem reported on the whole file (the Program node).
|
|
692
|
+
* ESLint 10 makes Program span the entire source, leading comments included,
|
|
693
|
+
* so a report on it lands on line 1 and a `// eslint-disable-next-line` above
|
|
694
|
+
* the first statement stops covering it. Starting at the first token keeps the
|
|
695
|
+
* ESLint 9 location on both versions.
|
|
696
|
+
* @param {Object} context eslint context
|
|
697
|
+
* @param {Object} programNode the Program node
|
|
698
|
+
* @returns {Object} loc to pass to context.report
|
|
699
|
+
*/
|
|
700
|
+
const getFileReportLoc = (context, programNode) => {
|
|
701
|
+
const [firstToken] = context.sourceCode.ast.tokens;
|
|
702
|
+
return firstToken ? {
|
|
703
|
+
start: firstToken.loc.start,
|
|
704
|
+
end: programNode.loc.end
|
|
705
|
+
} : programNode.loc;
|
|
706
|
+
};
|
|
690
707
|
const getFilenameAndExtension = context => {
|
|
691
|
-
const fullFilename = context.
|
|
708
|
+
const fullFilename = context.filename.replace(/.*\//, "");
|
|
692
709
|
const splitFilename = fullFilename.split(".");
|
|
693
710
|
const extension = splitFilename.pop();
|
|
694
711
|
return [splitFilename.join("."), extension];
|
|
@@ -708,7 +725,7 @@
|
|
|
708
725
|
* @returns true if file is inside the `apis` directory
|
|
709
726
|
*/
|
|
710
727
|
const isInsideApisDirectory = context => {
|
|
711
|
-
const filename = context.
|
|
728
|
+
const filename = context.filename;
|
|
712
729
|
const apisDirectory = path$1.resolve(APIS_DIRECTORY);
|
|
713
730
|
return filename.startsWith(apisDirectory) && filename !== `${apisDirectory}/axios.js`;
|
|
714
731
|
};
|
|
@@ -719,7 +736,7 @@
|
|
|
719
736
|
* @returns true if file is inside the `components` directory
|
|
720
737
|
*/
|
|
721
738
|
const isInsideComponentsDirectory = context => {
|
|
722
|
-
const filename = context.
|
|
739
|
+
const filename = context.filename;
|
|
723
740
|
const componentsDirectory = path$1.resolve(COMPONENTS_DIRECTORY);
|
|
724
741
|
return filename.startsWith(componentsDirectory);
|
|
725
742
|
};
|
|
@@ -734,7 +751,7 @@
|
|
|
734
751
|
const isGeneratedTranslationFile = context => {
|
|
735
752
|
const [filename, extension] = getFilenameAndExtension(context);
|
|
736
753
|
const translationsDirectory = path$1.resolve(TRANSLATIONS_DIRECTORY);
|
|
737
|
-
return context.
|
|
754
|
+
return context.filename.startsWith(translationsDirectory) && extension === "json" && filename !== TRANSLATION_SOURCE_LOCALE;
|
|
738
755
|
};
|
|
739
756
|
|
|
740
757
|
/**
|
|
@@ -1153,7 +1170,7 @@
|
|
|
1153
1170
|
};
|
|
1154
1171
|
|
|
1155
1172
|
const isInsideRoutesFile$1 = context => {
|
|
1156
|
-
const filename = context.
|
|
1173
|
+
const filename = context.filename;
|
|
1157
1174
|
return filename.endsWith(ROUTES_FILE_PATH);
|
|
1158
1175
|
};
|
|
1159
1176
|
var routesShouldBeDeclaredAndDefaultExported = {
|
|
@@ -1171,9 +1188,17 @@
|
|
|
1171
1188
|
if (isDeclarationPresent) {
|
|
1172
1189
|
const isDefaultExportPresent = node.body.some(neetoCist.matches(DEFAULT_EXPORT_PATTERN));
|
|
1173
1190
|
if (isDefaultExportPresent) return;
|
|
1174
|
-
context.report(
|
|
1191
|
+
context.report({
|
|
1192
|
+
node,
|
|
1193
|
+
loc: getFileReportLoc(context, node),
|
|
1194
|
+
message: ROUTES_SHOULD_USE_DEFAULT_EXPORT
|
|
1195
|
+
});
|
|
1175
1196
|
} else {
|
|
1176
|
-
context.report(
|
|
1197
|
+
context.report({
|
|
1198
|
+
node,
|
|
1199
|
+
loc: getFileReportLoc(context, node),
|
|
1200
|
+
message: ROUTES_CONSTANT_SHOULD_BE_DECLARED
|
|
1201
|
+
});
|
|
1177
1202
|
}
|
|
1178
1203
|
}
|
|
1179
1204
|
})
|
|
@@ -1184,7 +1209,7 @@
|
|
|
1184
1209
|
return text.substring(0, 1).toLowerCase() + text.substring(1);
|
|
1185
1210
|
};
|
|
1186
1211
|
const isInsideRoutesFile = context => {
|
|
1187
|
-
const filename = context.
|
|
1212
|
+
const filename = context.filename;
|
|
1188
1213
|
return filename.endsWith(ROUTES_FILE_PATH);
|
|
1189
1214
|
};
|
|
1190
1215
|
const isParam = e => e?.startsWith(":");
|
|
@@ -1268,7 +1293,7 @@
|
|
|
1268
1293
|
},
|
|
1269
1294
|
create: context => ({
|
|
1270
1295
|
VariableDeclaration(node) {
|
|
1271
|
-
if (!context.
|
|
1296
|
+
if (!context.filename.endsWith(ROUTES_FILE_PATH)) return;
|
|
1272
1297
|
if (neetoCist.matches(DECALARATION_PATTERN$1, node)) {
|
|
1273
1298
|
checkRoutes(context, node.declarations[0].init);
|
|
1274
1299
|
}
|
|
@@ -1276,7 +1301,7 @@
|
|
|
1276
1301
|
})
|
|
1277
1302
|
};
|
|
1278
1303
|
|
|
1279
|
-
const getCode = (context, start, length) => context.
|
|
1304
|
+
const getCode = (context, start, length) => context.sourceCode.text.substr(start, length);
|
|
1280
1305
|
const replacer$2 = nodeReplacerWithImports(ramda.assocPath(["source", "value"], "neetocommons/utils", IMPORT_DECLARATION));
|
|
1281
1306
|
var useCommonRoutes = {
|
|
1282
1307
|
meta: {
|
|
@@ -1539,7 +1564,7 @@
|
|
|
1539
1564
|
},
|
|
1540
1565
|
create: context => ({
|
|
1541
1566
|
VariableDeclaration(node) {
|
|
1542
|
-
if (!isExcludedFile(CONSTANTS_FILES, context.
|
|
1567
|
+
if (!isExcludedFile(CONSTANTS_FILES, context.filename) && neetoCist.matches(CONSTANT_DECLARATION_PATTERN, node)) {
|
|
1543
1568
|
const constantName = node.declarations[0].id.name;
|
|
1544
1569
|
context.report(node, moveToConstantsJs(constantName));
|
|
1545
1570
|
}
|
|
@@ -1575,12 +1600,12 @@
|
|
|
1575
1600
|
fixable: "whitespace"
|
|
1576
1601
|
},
|
|
1577
1602
|
create: context => {
|
|
1578
|
-
const prettierConfig = getPrettierConfig(context.
|
|
1603
|
+
const prettierConfig = getPrettierConfig(context.filename);
|
|
1579
1604
|
return {
|
|
1580
1605
|
ObjectExpression(node) {
|
|
1581
|
-
if (isExcludedFile(EXCLUDED_FILES, context.
|
|
1606
|
+
if (isExcludedFile(EXCLUDED_FILES, context.filename)) return;
|
|
1582
1607
|
if (!neetoCist.matches(OBJECT_EXPRESSION_PATTERN$1, node)) return;
|
|
1583
|
-
const sourceCode = context.
|
|
1608
|
+
const sourceCode = context.sourceCode;
|
|
1584
1609
|
const hasComments = neetoCist.isNotEmpty(sourceCode.getCommentsInside(node));
|
|
1585
1610
|
if (hasComments) return;
|
|
1586
1611
|
const openingBraceLine = node.loc.start.line;
|
|
@@ -1784,7 +1809,7 @@
|
|
|
1784
1809
|
}
|
|
1785
1810
|
},
|
|
1786
1811
|
create: context => {
|
|
1787
|
-
const allImports = getAllImports(context.
|
|
1812
|
+
const allImports = getAllImports(context.sourceCode.ast);
|
|
1788
1813
|
const neetouiFormName = getLocalNameOfImport(allImports, "NEETOUI_FORM");
|
|
1789
1814
|
const formikName = getLocalNameOfImport(allImports, "FORMIK");
|
|
1790
1815
|
const useFormikName = getLocalNameOfImport(allImports, "USE_FORMIK");
|
|
@@ -3523,7 +3548,7 @@
|
|
|
3523
3548
|
},
|
|
3524
3549
|
create: context => ({
|
|
3525
3550
|
Property(node) {
|
|
3526
|
-
if (!context.
|
|
3551
|
+
if (!context.filename.endsWith("package.json") || node.key.value !== DEPENDENCY_TYPE.peerDependencies) {
|
|
3527
3552
|
return;
|
|
3528
3553
|
}
|
|
3529
3554
|
const peerDependencies = findDependencies(node, DEPENDENCY_TYPE.peerDependencies);
|
|
@@ -3656,68 +3681,256 @@
|
|
|
3656
3681
|
|
|
3657
3682
|
var braceExpansion = expandTop;
|
|
3658
3683
|
|
|
3659
|
-
var escSlash = '\0SLASH'+Math.random()+'\0';
|
|
3660
|
-
var escOpen = '\0OPEN'+Math.random()+'\0';
|
|
3661
|
-
var escClose = '\0CLOSE'+Math.random()+'\0';
|
|
3662
|
-
var escComma = '\0COMMA'+Math.random()+'\0';
|
|
3663
|
-
var escPeriod = '\0PERIOD'+Math.random()+'\0';
|
|
3684
|
+
var escSlash = '\0SLASH' + Math.random().toFixed(16) + '\0';
|
|
3685
|
+
var escOpen = '\0OPEN' + Math.random().toFixed(16) + '\0';
|
|
3686
|
+
var escClose = '\0CLOSE' + Math.random().toFixed(16) + '\0';
|
|
3687
|
+
var escComma = '\0COMMA' + Math.random().toFixed(16) + '\0';
|
|
3688
|
+
var escPeriod = '\0PERIOD' + Math.random().toFixed(16) + '\0';
|
|
3689
|
+
|
|
3690
|
+
var EXPANSION_MAX = 100000;
|
|
3691
|
+
|
|
3692
|
+
// `EXPANSION_MAX` caps the *number* of expansions, but not their length. An
|
|
3693
|
+
// input like `'{a,b}'.repeat(1500)` stays under that count - its output is
|
|
3694
|
+
// truncated to 100k results - while making every result ~1500 characters
|
|
3695
|
+
// long. The result set, and the intermediate arrays built while combining
|
|
3696
|
+
// brace sets, then grow large enough to exhaust memory and crash the process
|
|
3697
|
+
// (CVE-2026-14257). `EXPANSION_MAX_LENGTH` bounds the total number of
|
|
3698
|
+
// characters the accumulator may hold at any point, so memory stays flat no
|
|
3699
|
+
// matter how many brace groups are chained. The limit sits well above any
|
|
3700
|
+
// realistic expansion (100k results hitting `EXPANSION_MAX` measure ~1M
|
|
3701
|
+
// characters) so legitimate input is unaffected.
|
|
3702
|
+
var EXPANSION_MAX_LENGTH = 4000000;
|
|
3703
|
+
|
|
3704
|
+
// `expand` recurses once per level of brace *nesting* - both when expanding a
|
|
3705
|
+
// set's comma members and when re-wrapping a set whose body is a single part.
|
|
3706
|
+
// The CVE-2026-14257 fix made the *tail* iterative (recursion on `m.post`, one
|
|
3707
|
+
// level per chained group), which left nesting depth unbounded: about 3,100
|
|
3708
|
+
// levels of `{{{...a,b...}}}` - only ~6KB of input - exhausted the native stack
|
|
3709
|
+
// and crashed the process. `EXPANSION_MAX_DEPTH` bounds how deep the parser
|
|
3710
|
+
// will follow nesting. It sits far above any realistic pattern and well below
|
|
3711
|
+
// the depth at which the stack runs out.
|
|
3712
|
+
var EXPANSION_MAX_DEPTH = 1000;
|
|
3713
|
+
|
|
3714
|
+
// Bash keeps a quirk where a brace group followed by a comma set still expands
|
|
3715
|
+
// (`{a},b}`). The parser implements it by rewriting the string and restarting
|
|
3716
|
+
// the scan, absorbing one `}` per pass. `n` trailing braces therefore cost `n`
|
|
3717
|
+
// full passes over a string that itself grows by one `escClose` sentinel each
|
|
3718
|
+
// time - quadratic in `n`, with a ~26x constant from the sentinel's length.
|
|
3719
|
+
// 128KB of `'{a}' + '}'.repeat(n) + ',z}'` blocked the event loop for 27
|
|
3720
|
+
// seconds to produce two results. `EXPANSION_MAX_REWRITES` bounds how many
|
|
3721
|
+
// times the scan may restart. Real `{a},b}` input needs a handful.
|
|
3722
|
+
var EXPANSION_MAX_REWRITES = 1000;
|
|
3723
|
+
|
|
3724
|
+
// `EXPANSION_MAX_STEPS` bounds the work one `expandTop` call does, which `max`,
|
|
3725
|
+
// `maxLength` and `maxDepth` don't: nested sets are rescanned at every level
|
|
3726
|
+
// and chained groups each rebuild up to `max` results, so 2KB of input could
|
|
3727
|
+
// block the event loop for over 30 seconds. Each character scanned, result
|
|
3728
|
+
// built and sequence value generated is a step, and each `expand` call costs
|
|
3729
|
+
// `CALL_STEPS` more. Past the budget, the set being expanded and everything
|
|
3730
|
+
// after it stay literal. A glob needs a few hundred steps, and nesting all the
|
|
3731
|
+
// way to `EXPANSION_MAX_DEPTH` about 4M.
|
|
3732
|
+
var EXPANSION_MAX_STEPS = 20000000;
|
|
3733
|
+
|
|
3734
|
+
// What one `expand` call costs on top of what it scans and builds. Setting
|
|
3735
|
+
// one up takes about as long as scanning 16 characters, and a set whose
|
|
3736
|
+
// results are wrapped to be expanded again makes one call per result, each
|
|
3737
|
+
// scanning and building next to nothing: 64KB of
|
|
3738
|
+
// `('{{' + ','.repeat(316) + '}{' + ','.repeat(316) + '}}').repeat(n)` made
|
|
3739
|
+
// 4M such calls, which spent the budget three times as slowly as anything
|
|
3740
|
+
// else.
|
|
3741
|
+
var CALL_STEPS = 16;
|
|
3664
3742
|
|
|
3665
3743
|
function numeric(str) {
|
|
3666
|
-
return parseInt(str, 10) == str
|
|
3667
|
-
? parseInt(str, 10)
|
|
3668
|
-
: str.charCodeAt(0);
|
|
3744
|
+
return parseInt(str, 10) == str ? parseInt(str, 10) : str.charCodeAt(0)
|
|
3669
3745
|
}
|
|
3670
3746
|
|
|
3671
3747
|
function escapeBraces(str) {
|
|
3672
|
-
return str
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3748
|
+
return str
|
|
3749
|
+
.split('\\\\')
|
|
3750
|
+
.join(escSlash)
|
|
3751
|
+
.split('\\{')
|
|
3752
|
+
.join(escOpen)
|
|
3753
|
+
.split('\\}')
|
|
3754
|
+
.join(escClose)
|
|
3755
|
+
.split('\\,')
|
|
3756
|
+
.join(escComma)
|
|
3757
|
+
.split('\\.')
|
|
3758
|
+
.join(escPeriod)
|
|
3677
3759
|
}
|
|
3678
3760
|
|
|
3679
3761
|
function unescapeBraces(str) {
|
|
3680
|
-
return str
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3762
|
+
return str
|
|
3763
|
+
.split(escSlash)
|
|
3764
|
+
.join('\\')
|
|
3765
|
+
.split(escOpen)
|
|
3766
|
+
.join('{')
|
|
3767
|
+
.split(escClose)
|
|
3768
|
+
.join('}')
|
|
3769
|
+
.split(escComma)
|
|
3770
|
+
.join(',')
|
|
3771
|
+
.split(escPeriod)
|
|
3772
|
+
.join('.')
|
|
3685
3773
|
}
|
|
3686
3774
|
|
|
3775
|
+
// Like `target.push(...items)` but doesn't overflow the stack
|
|
3776
|
+
function pushAll(target, items) {
|
|
3777
|
+
for (var i = 0; i < items.length; i++) {
|
|
3778
|
+
target.push(items[i]);
|
|
3779
|
+
}
|
|
3780
|
+
}
|
|
3781
|
+
|
|
3782
|
+
// `budget` is `{ remaining }`, one counter shared by every level and group of
|
|
3783
|
+
// an `expandTop` call, so the bound holds for the call as a whole.
|
|
3784
|
+
//
|
|
3785
|
+
// `balanced`, run on `masked` (see `maskUnmatchedOpens`), sliced from `str`
|
|
3786
|
+
// and charged for the characters it walks: up to the group's `}`, or the
|
|
3787
|
+
// whole string when there is no match or unmatched `{` come first, which
|
|
3788
|
+
// `unmatched` then flags for masking. Once a call overdraws the budget, it
|
|
3789
|
+
// and every later one return undefined, so the rest stays literal.
|
|
3790
|
+
function balancedWithBudget(str, masked, budget) {
|
|
3791
|
+
if (budget.remaining < 0) {
|
|
3792
|
+
return undefined
|
|
3793
|
+
}
|
|
3794
|
+
var r = balanced.range('{', '}', masked);
|
|
3795
|
+
var unmatched = r !== undefined && masked.indexOf('{') < r[0];
|
|
3796
|
+
budget.remaining -= r && !unmatched ? r[1] + 1 : str.length;
|
|
3797
|
+
if (!r || budget.remaining < 0) {
|
|
3798
|
+
return undefined
|
|
3799
|
+
}
|
|
3800
|
+
return {
|
|
3801
|
+
end: r[1],
|
|
3802
|
+
pre: str.slice(0, r[0]),
|
|
3803
|
+
body: str.slice(r[0] + 1, r[1]),
|
|
3804
|
+
post: str.slice(r[1] + 1),
|
|
3805
|
+
unmatched: unmatched,
|
|
3806
|
+
}
|
|
3807
|
+
}
|
|
3808
|
+
|
|
3809
|
+
// `masked` with every `{` that has no matching `}` swapped for a `\0`, which
|
|
3810
|
+
// keeps the length, so a scan of it still lines up with the string it was
|
|
3811
|
+
// made from. Such a `{` is literal either way, but `balanced` only learns that
|
|
3812
|
+
// one is unmatched by reading to the end of the string, so with one at the
|
|
3813
|
+
// head of every group (`'{a,{b,c}'.repeat(n)`) each scan read the rest of the
|
|
3814
|
+
// input. That was quadratic, and once the step budget charged for it, it ran
|
|
3815
|
+
// out partway through and left the rest literal. A scan of the masked copy
|
|
3816
|
+
// stops at the group's `}`. It is one pass, charged as such.
|
|
3817
|
+
function maskUnmatchedOpens(masked, budget) {
|
|
3818
|
+
budget.remaining -= masked.length;
|
|
3819
|
+
var open = [];
|
|
3820
|
+
for (var i = 0; i < masked.length; i++) {
|
|
3821
|
+
var c = masked.charCodeAt(i);
|
|
3822
|
+
if (c === 0x7b) {
|
|
3823
|
+
open.push(i);
|
|
3824
|
+
} else if (c === 0x7d && open.length) {
|
|
3825
|
+
open.pop();
|
|
3826
|
+
}
|
|
3827
|
+
}
|
|
3828
|
+
var out = '';
|
|
3829
|
+
var last = 0;
|
|
3830
|
+
for (var j = 0; j < open.length; j++) {
|
|
3831
|
+
out += masked.slice(last, open[j]) + '\0';
|
|
3832
|
+
last = open[j] + 1;
|
|
3833
|
+
}
|
|
3834
|
+
return out + masked.slice(last)
|
|
3835
|
+
}
|
|
3836
|
+
|
|
3837
|
+
// Whether `str` has a `,` not followed by another `,`, with a `}` after it on
|
|
3838
|
+
// the same line - what `/,(?!,).*\}/.test(str)` asks, answered in one pass from
|
|
3839
|
+
// the end. The regex tries every `,` and backtracks through the rest of its
|
|
3840
|
+
// line from each, which is quadratic, and the `{a},b}` rewrite asks again on
|
|
3841
|
+
// every pass. Like a scan, it is charged for the whole string and refused if
|
|
3842
|
+
// that overdraws the budget.
|
|
3843
|
+
function commaSetFollows(str, budget) {
|
|
3844
|
+
budget.remaining -= str.length;
|
|
3845
|
+
if (budget.remaining < 0) {
|
|
3846
|
+
return false
|
|
3847
|
+
}
|
|
3848
|
+
// Whether a `}` follows the current position before the line ends
|
|
3849
|
+
var close = false;
|
|
3850
|
+
for (var i = str.length - 1; i >= 0; i--) {
|
|
3851
|
+
var c = str.charCodeAt(i);
|
|
3852
|
+
if (c === 0x7d) {
|
|
3853
|
+
close = true;
|
|
3854
|
+
} else if (c === 0x0a || c === 0x0d || c === 0x2028 || c === 0x2029) {
|
|
3855
|
+
// A line terminator, which `.` does not match
|
|
3856
|
+
close = false;
|
|
3857
|
+
} else if (c === 0x2c && close && str.charCodeAt(i + 1) !== 0x2c) {
|
|
3858
|
+
return true
|
|
3859
|
+
}
|
|
3860
|
+
}
|
|
3861
|
+
return false
|
|
3862
|
+
}
|
|
3687
3863
|
|
|
3688
3864
|
// Basically just str.split(","), but handling cases
|
|
3689
3865
|
// where we have nested braced sections, which should be
|
|
3690
3866
|
// treated as individual members, like {a,{b,c},d}
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3867
|
+
//
|
|
3868
|
+
// Returns `undefined` if the step budget runs out before the whole set is
|
|
3869
|
+
// split, since splitting what is left on every comma would tear apart the
|
|
3870
|
+
// nested sets it still holds.
|
|
3871
|
+
function parseCommaParts(str, budget) {
|
|
3695
3872
|
var parts = [];
|
|
3696
|
-
var m = balanced('{', '}', str);
|
|
3697
3873
|
|
|
3698
|
-
|
|
3699
|
-
|
|
3874
|
+
// Walk the brace groups iteratively. Recursing on `post` once per group let a
|
|
3875
|
+
// chain of them exhaust the stack - the parsing-side counterpart to
|
|
3876
|
+
// the `expand` overflow fixed for CVE-2026-14257, and not something `max` or
|
|
3877
|
+
// `maxLength` can bound, since it happens before expansion.
|
|
3878
|
+
//
|
|
3879
|
+
// The part the next chunk continues
|
|
3880
|
+
var carry = '';
|
|
3700
3881
|
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
var p = pre.split(',');
|
|
3882
|
+
for (;;) {
|
|
3883
|
+
// A set's body holds no unmatched `{`, so there is nothing to mask.
|
|
3884
|
+
var m = balancedWithBudget(str, str, budget);
|
|
3705
3885
|
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
p[p.length-1] += postParts.shift();
|
|
3710
|
-
p.push.apply(p, postParts);
|
|
3711
|
-
}
|
|
3886
|
+
if (budget.remaining < 0) {
|
|
3887
|
+
return undefined
|
|
3888
|
+
}
|
|
3712
3889
|
|
|
3713
|
-
|
|
3890
|
+
if (!m) {
|
|
3891
|
+
var tail = str.split(',');
|
|
3892
|
+
tail[0] = carry + tail[0];
|
|
3893
|
+
pushAll(parts, tail);
|
|
3894
|
+
return parts
|
|
3895
|
+
}
|
|
3896
|
+
|
|
3897
|
+
var pre = m.pre;
|
|
3898
|
+
var body = m.body;
|
|
3899
|
+
var post = m.post;
|
|
3900
|
+
var p = pre.split(',');
|
|
3901
|
+
|
|
3902
|
+
p[0] = carry + p[0];
|
|
3903
|
+
p[p.length - 1] += '{' + body + '}';
|
|
3904
|
+
|
|
3905
|
+
if (!post.length) {
|
|
3906
|
+
pushAll(parts, p);
|
|
3907
|
+
return parts
|
|
3908
|
+
}
|
|
3714
3909
|
|
|
3715
|
-
|
|
3910
|
+
carry = p.pop();
|
|
3911
|
+
pushAll(parts, p);
|
|
3912
|
+
str = post;
|
|
3913
|
+
}
|
|
3914
|
+
}
|
|
3915
|
+
|
|
3916
|
+
// An option that is left out or null, or that is NaN, gets its default. Every
|
|
3917
|
+
// comparison against NaN is false, so a NaN bound would never be reached:
|
|
3918
|
+
// `{ maxSteps: NaN }` let 15KB of input block the event loop for 16 seconds,
|
|
3919
|
+
// and `{ maxDepth: NaN }` overflowed the stack again (CVE-2026-102278). Pass
|
|
3920
|
+
// `Infinity` to lift a bound.
|
|
3921
|
+
function bound(value, fallback) {
|
|
3922
|
+
return value == null || isNaN(value) ? fallback : value
|
|
3716
3923
|
}
|
|
3717
3924
|
|
|
3718
|
-
function expandTop(str) {
|
|
3719
|
-
if (!str)
|
|
3720
|
-
|
|
3925
|
+
function expandTop(str, options) {
|
|
3926
|
+
if (!str) return []
|
|
3927
|
+
|
|
3928
|
+
options = options || {};
|
|
3929
|
+
var max = bound(options.max, EXPANSION_MAX);
|
|
3930
|
+
var maxLength = bound(options.maxLength, EXPANSION_MAX_LENGTH);
|
|
3931
|
+
var maxDepth = bound(options.maxDepth, EXPANSION_MAX_DEPTH);
|
|
3932
|
+
var maxRewrites = bound(options.maxRewrites, EXPANSION_MAX_REWRITES);
|
|
3933
|
+
var maxSteps = bound(options.maxSteps, EXPANSION_MAX_STEPS);
|
|
3721
3934
|
|
|
3722
3935
|
// I don't know why Bash 4.3 does this, but it does.
|
|
3723
3936
|
// Anything starting with {} will have the first two bytes preserved
|
|
@@ -3729,130 +3942,373 @@
|
|
|
3729
3942
|
str = '\\{\\}' + str.substr(2);
|
|
3730
3943
|
}
|
|
3731
3944
|
|
|
3732
|
-
return expand(
|
|
3945
|
+
return expand(
|
|
3946
|
+
escapeBraces(str),
|
|
3947
|
+
max,
|
|
3948
|
+
maxLength,
|
|
3949
|
+
maxDepth,
|
|
3950
|
+
0,
|
|
3951
|
+
maxRewrites,
|
|
3952
|
+
{ remaining: maxSteps },
|
|
3953
|
+
true
|
|
3954
|
+
).map(unescapeBraces)
|
|
3733
3955
|
}
|
|
3734
3956
|
|
|
3735
3957
|
function embrace(str) {
|
|
3736
|
-
return '{' + str + '}'
|
|
3958
|
+
return '{' + str + '}'
|
|
3737
3959
|
}
|
|
3738
3960
|
function isPadded(el) {
|
|
3739
|
-
return /^-?0\d/.test(el)
|
|
3961
|
+
return /^-?0\d/.test(el)
|
|
3740
3962
|
}
|
|
3741
3963
|
|
|
3742
3964
|
function lte(i, y) {
|
|
3743
|
-
return i <= y
|
|
3965
|
+
return i <= y
|
|
3744
3966
|
}
|
|
3745
3967
|
function gte(i, y) {
|
|
3746
|
-
return i >= y
|
|
3968
|
+
return i >= y
|
|
3747
3969
|
}
|
|
3748
3970
|
|
|
3749
|
-
|
|
3750
|
-
|
|
3971
|
+
// Build `{ acc[a] + pre + values[v] }` for every combination, capping the
|
|
3972
|
+
// number of results at `max` and the total number of characters at `maxLength`.
|
|
3973
|
+
// This is the one place output grows, so bounding it here keeps the single
|
|
3974
|
+
// accumulator - and therefore memory - flat regardless of how many brace groups
|
|
3975
|
+
// are combined (CVE-2026-14257). Each result built is a step, since `max` and
|
|
3976
|
+
// `maxLength` bound one combination, not how many brace groups are combined.
|
|
3977
|
+
function combine(acc, pre, values, max, maxLength, dropEmpties, budget) {
|
|
3978
|
+
var out = [];
|
|
3979
|
+
var length = 0;
|
|
3980
|
+
// Bash drops empty results at the top level, and they don't count against
|
|
3981
|
+
// `max`, so `max` bounds the number of *kept* results. Only an empty
|
|
3982
|
+
// `acc[a] + pre` can make one, so for those the empty values are skipped
|
|
3983
|
+
// without being visited. Visiting them one at a time let a set of empties
|
|
3984
|
+
// cost `acc.length * values.length` while keeping nothing.
|
|
3985
|
+
var nonEmpty;
|
|
3986
|
+
outer: for (var a = 0; a < acc.length; a++) {
|
|
3987
|
+
var prefix = acc[a] + pre;
|
|
3988
|
+
var vs = values;
|
|
3989
|
+
if (dropEmpties && !prefix) {
|
|
3990
|
+
if (!nonEmpty) nonEmpty = values.filter(Boolean);
|
|
3991
|
+
vs = nonEmpty;
|
|
3992
|
+
}
|
|
3993
|
+
for (var v = 0; v < vs.length; v++) {
|
|
3994
|
+
if (out.length >= max) break outer
|
|
3995
|
+
var expansion = prefix + vs[v];
|
|
3996
|
+
if (length + expansion.length > maxLength) break outer
|
|
3997
|
+
out.push(expansion);
|
|
3998
|
+
length += expansion.length;
|
|
3999
|
+
}
|
|
4000
|
+
}
|
|
4001
|
+
budget.remaining -= out.length;
|
|
4002
|
+
return out
|
|
4003
|
+
}
|
|
3751
4004
|
|
|
3752
|
-
|
|
3753
|
-
|
|
4005
|
+
// The expansion values of a single numeric (`1..5`) or alphabetic (`a..e..2`)
|
|
4006
|
+
// sequence body, or `undefined` if the step budget runs out generating them.
|
|
4007
|
+
function expandSequence(body, isAlphaSequence, max, maxLength, budget) {
|
|
4008
|
+
var n = body.split(/\.\./);
|
|
4009
|
+
var N = [];
|
|
4010
|
+
// A sequence body always splits into two or three parts, but the compiler
|
|
4011
|
+
// can't know that.
|
|
4012
|
+
/* c8 ignore start */
|
|
4013
|
+
if (n[0] === undefined || n[1] === undefined) {
|
|
4014
|
+
return N
|
|
4015
|
+
}
|
|
4016
|
+
/* c8 ignore stop */
|
|
4017
|
+
var x = numeric(n[0]);
|
|
4018
|
+
var y = numeric(n[1]);
|
|
4019
|
+
var width = Math.max(n[0].length, n[1].length);
|
|
4020
|
+
var incr =
|
|
4021
|
+
n.length === 3 && n[2] !== undefined ?
|
|
4022
|
+
Math.max(Math.abs(numeric(n[2])), 1)
|
|
4023
|
+
: 1;
|
|
4024
|
+
var test = lte;
|
|
4025
|
+
var reverse = y < x;
|
|
4026
|
+
if (reverse) {
|
|
4027
|
+
incr *= -1;
|
|
4028
|
+
test = gte;
|
|
4029
|
+
}
|
|
4030
|
+
var pad = n.some(isPadded);
|
|
4031
|
+
// A padded value is built a character at a time to `width`, which the input
|
|
4032
|
+
// sets, so it costs one step per character: 64KB of
|
|
4033
|
+
// `('{' + '0'.repeat(100) + '..99999}').repeat(n)` took 7 seconds charged
|
|
4034
|
+
// one step per value.
|
|
4035
|
+
var cost = pad ? width : 1;
|
|
4036
|
+
|
|
4037
|
+
var length = 0;
|
|
4038
|
+
for (var i = x; test(i, y) && N.length < max; i += incr) {
|
|
4039
|
+
// Each value is a step. `max` and `maxLength` bound one sequence, but a
|
|
4040
|
+
// chain of them still generated up to `max` values each, however few
|
|
4041
|
+
// combining could keep.
|
|
4042
|
+
budget.remaining -= cost;
|
|
4043
|
+
if (budget.remaining < 0) {
|
|
4044
|
+
return undefined
|
|
4045
|
+
}
|
|
4046
|
+
var c;
|
|
4047
|
+
if (isAlphaSequence) {
|
|
4048
|
+
c = String.fromCharCode(i);
|
|
4049
|
+
if (c === '\\') {
|
|
4050
|
+
c = '';
|
|
4051
|
+
}
|
|
4052
|
+
} else {
|
|
4053
|
+
c = String(i);
|
|
4054
|
+
if (pad) {
|
|
4055
|
+
var need = width - c.length;
|
|
4056
|
+
if (need > 0) {
|
|
4057
|
+
var z = new Array(need + 1).join('0');
|
|
4058
|
+
if (i < 0) {
|
|
4059
|
+
c = '-' + z + c.slice(1);
|
|
4060
|
+
} else {
|
|
4061
|
+
c = z + c;
|
|
4062
|
+
}
|
|
4063
|
+
}
|
|
4064
|
+
}
|
|
4065
|
+
}
|
|
4066
|
+
if (length + c.length > maxLength) break
|
|
4067
|
+
N.push(c);
|
|
4068
|
+
length += c.length;
|
|
4069
|
+
}
|
|
4070
|
+
return N
|
|
4071
|
+
}
|
|
3754
4072
|
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
|
|
3759
|
-
|
|
4073
|
+
function expand(
|
|
4074
|
+
str,
|
|
4075
|
+
max,
|
|
4076
|
+
maxLength,
|
|
4077
|
+
maxDepth,
|
|
4078
|
+
depth,
|
|
4079
|
+
maxRewrites,
|
|
4080
|
+
budget,
|
|
4081
|
+
isTop
|
|
4082
|
+
) {
|
|
4083
|
+
// An overdraft here makes the first scan refuse, so `str` stays literal.
|
|
4084
|
+
budget.remaining -= CALL_STEPS;
|
|
4085
|
+
|
|
4086
|
+
// Too deeply nested to keep following: treat the rest as literal, the same
|
|
4087
|
+
// way a group that cannot expand is already handled. Truncating rather than
|
|
4088
|
+
// throwing keeps expansion total, matching `max` and `maxLength`.
|
|
4089
|
+
if (depth > maxDepth) {
|
|
4090
|
+
return [str]
|
|
4091
|
+
}
|
|
4092
|
+
|
|
4093
|
+
// Consume the string's top-level brace groups left to right, threading a
|
|
4094
|
+
// running set of combined prefixes (`acc`). Expanding the tail iteratively -
|
|
4095
|
+
// rather than recursing on `m.post` once per group - keeps the native stack
|
|
4096
|
+
// depth constant, so deeply chained input (`'{a,b}'.repeat(3000)`) can no
|
|
4097
|
+
// longer overflow the stack, and leaves a single accumulator whose size
|
|
4098
|
+
// `maxLength` bounds directly (CVE-2026-14257).
|
|
4099
|
+
var acc = [''];
|
|
4100
|
+
|
|
4101
|
+
// Bash drops empty results, but only when the *first* top-level group is a
|
|
4102
|
+
// comma set - a sequence like `{a..\}` may legitimately yield ''. The drop
|
|
4103
|
+
// is on the final strings, so it is applied to whichever `combine` produces
|
|
4104
|
+
// them (the one with no brace set left in the tail).
|
|
4105
|
+
// How many times the `{a},b}` rewrite below has restarted the scan. Each pass
|
|
4106
|
+
// re-reads the whole string, so leaving this unbounded is quadratic.
|
|
4107
|
+
var rewrites = 0;
|
|
4108
|
+
var dropEmpties = false;
|
|
4109
|
+
var firstGroup = true;
|
|
4110
|
+
// `str` with its unmatched `{` masked, once a scan has run into them
|
|
4111
|
+
var masked = str;
|
|
4112
|
+
|
|
4113
|
+
for (;;) {
|
|
4114
|
+
const m = balancedWithBudget(str, masked, budget);
|
|
4115
|
+
|
|
4116
|
+
// No brace set left, or no step budget left to look for one: the rest of
|
|
4117
|
+
// the string is literal.
|
|
4118
|
+
if (!m) {
|
|
4119
|
+
return combine(acc, str, [''], max, maxLength, dropEmpties, budget)
|
|
4120
|
+
}
|
|
4121
|
+
if (m.unmatched) {
|
|
4122
|
+
masked = maskUnmatchedOpens(masked, budget);
|
|
4123
|
+
}
|
|
4124
|
+
|
|
4125
|
+
// no need to expand pre, since it is guaranteed to be free of brace-sets
|
|
4126
|
+
const pre = m.pre;
|
|
4127
|
+
|
|
4128
|
+
// This set and the rest of the string, literal: for a set that cannot
|
|
4129
|
+
// expand, and for one the step budget runs out on. Once it is overdrawn,
|
|
4130
|
+
// every set still being expanded, at every level, stays literal like this -
|
|
4131
|
+
// otherwise each level above would go on combining, and wrapping and
|
|
4132
|
+
// expanding again, results the budget was too small for.
|
|
4133
|
+
var literal = function () {
|
|
4134
|
+
return combine(
|
|
4135
|
+
acc,
|
|
4136
|
+
pre + '{' + m.body + '}' + m.post,
|
|
4137
|
+
[''],
|
|
4138
|
+
max,
|
|
4139
|
+
maxLength,
|
|
4140
|
+
dropEmpties,
|
|
4141
|
+
budget
|
|
4142
|
+
)
|
|
4143
|
+
};
|
|
3760
4144
|
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
|
|
4145
|
+
if (/\$$/.test(pre)) {
|
|
4146
|
+
acc = combine(
|
|
4147
|
+
acc,
|
|
4148
|
+
pre + '{' + m.body + '}',
|
|
4149
|
+
[''],
|
|
4150
|
+
max,
|
|
4151
|
+
maxLength,
|
|
4152
|
+
dropEmpties && !m.post.length,
|
|
4153
|
+
budget
|
|
4154
|
+
);
|
|
4155
|
+
firstGroup = false;
|
|
4156
|
+
if (!m.post.length) break
|
|
4157
|
+
str = m.post;
|
|
4158
|
+
masked = masked.slice(m.end + 1);
|
|
4159
|
+
continue
|
|
3765
4160
|
}
|
|
3766
|
-
|
|
4161
|
+
|
|
3767
4162
|
var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
|
|
3768
|
-
var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(
|
|
4163
|
+
var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(
|
|
4164
|
+
m.body
|
|
4165
|
+
);
|
|
3769
4166
|
var isSequence = isNumericSequence || isAlphaSequence;
|
|
3770
4167
|
var isOptions = m.body.indexOf(',') >= 0;
|
|
3771
4168
|
if (!isSequence && !isOptions) {
|
|
3772
4169
|
// {a},b}
|
|
3773
|
-
if (m.post
|
|
4170
|
+
if (rewrites < maxRewrites && commaSetFollows(m.post, budget)) {
|
|
4171
|
+
rewrites++;
|
|
3774
4172
|
str = m.pre + '{' + m.body + escClose + m.post;
|
|
3775
|
-
|
|
4173
|
+
// Taking a `}` away never gives an unmatched `{` a partner, so what
|
|
4174
|
+
// is masked stays unmatched. The `{` it closed can be left without
|
|
4175
|
+
// one, and the next scan masks it.
|
|
4176
|
+
masked =
|
|
4177
|
+
masked.slice(0, m.end) + escClose + masked.slice(m.end + 1);
|
|
4178
|
+
isTop = true;
|
|
4179
|
+
continue
|
|
3776
4180
|
}
|
|
3777
|
-
|
|
4181
|
+
// Nothing here expands, so the whole remaining string is literal.
|
|
4182
|
+
return literal()
|
|
3778
4183
|
}
|
|
3779
4184
|
|
|
3780
|
-
|
|
4185
|
+
if (firstGroup) {
|
|
4186
|
+
dropEmpties = isTop && !isSequence;
|
|
4187
|
+
firstGroup = false;
|
|
4188
|
+
}
|
|
4189
|
+
|
|
4190
|
+
var values;
|
|
3781
4191
|
if (isSequence) {
|
|
3782
|
-
|
|
4192
|
+
values = expandSequence(
|
|
4193
|
+
m.body,
|
|
4194
|
+
isAlphaSequence,
|
|
4195
|
+
max,
|
|
4196
|
+
maxLength,
|
|
4197
|
+
budget
|
|
4198
|
+
);
|
|
4199
|
+
if (!values) {
|
|
4200
|
+
return literal()
|
|
4201
|
+
}
|
|
3783
4202
|
} else {
|
|
3784
|
-
n = parseCommaParts(m.body);
|
|
3785
|
-
|
|
4203
|
+
var n = parseCommaParts(m.body, budget);
|
|
4204
|
+
// The step budget ran out partway through the set.
|
|
4205
|
+
if (!n) {
|
|
4206
|
+
return literal()
|
|
4207
|
+
}
|
|
4208
|
+
if (n.length === 1 && n[0] !== undefined) {
|
|
3786
4209
|
// x{{a,b}}y ==> x{a}y x{b}y
|
|
3787
|
-
n = expand(
|
|
4210
|
+
n = expand(
|
|
4211
|
+
n[0],
|
|
4212
|
+
max,
|
|
4213
|
+
maxLength,
|
|
4214
|
+
maxDepth,
|
|
4215
|
+
depth + 1,
|
|
4216
|
+
maxRewrites,
|
|
4217
|
+
budget,
|
|
4218
|
+
false
|
|
4219
|
+
).map(embrace);
|
|
4220
|
+
// The step budget ran out expanding the set's only part.
|
|
4221
|
+
if (budget.remaining < 0) {
|
|
4222
|
+
return literal()
|
|
4223
|
+
}
|
|
4224
|
+
//XXX is this necessary? Can't seem to hit it in tests.
|
|
4225
|
+
/* c8 ignore start */
|
|
3788
4226
|
if (n.length === 1) {
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
4227
|
+
var single = combine(
|
|
4228
|
+
acc,
|
|
4229
|
+
pre + n[0],
|
|
4230
|
+
[''],
|
|
4231
|
+
max,
|
|
4232
|
+
maxLength,
|
|
4233
|
+
dropEmpties && !m.post.length,
|
|
4234
|
+
budget
|
|
4235
|
+
);
|
|
4236
|
+
if (budget.remaining < 0) {
|
|
4237
|
+
return literal()
|
|
4238
|
+
}
|
|
4239
|
+
acc = single;
|
|
4240
|
+
if (!m.post.length) break
|
|
4241
|
+
str = m.post;
|
|
4242
|
+
masked = masked.slice(m.end + 1);
|
|
4243
|
+
continue
|
|
3792
4244
|
}
|
|
4245
|
+
/* c8 ignore stop */
|
|
3793
4246
|
}
|
|
3794
|
-
}
|
|
3795
|
-
|
|
3796
|
-
// at this point, n is the parts, and we know it's not a comma set
|
|
3797
|
-
// with a single entry.
|
|
3798
|
-
var N;
|
|
3799
4247
|
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
incr *= -1;
|
|
3811
|
-
test = gte;
|
|
4248
|
+
// Values that `combine` is going to drop as empty produce no result, so
|
|
4249
|
+
// they must not count against `max` - otherwise `{a,,b}` with `max: 2`
|
|
4250
|
+
// would stop at `['a', '']` and yield one result instead of two. Skipping
|
|
4251
|
+
// them outright keeps `values` bounded while leaving `max` a bound on
|
|
4252
|
+
// *kept* results.
|
|
4253
|
+
var dropsEmpties = dropEmpties && !m.post.length && !pre;
|
|
4254
|
+
for (var d = 0; dropsEmpties && d < acc.length; d++) {
|
|
4255
|
+
if (acc[d]) {
|
|
4256
|
+
dropsEmpties = false;
|
|
4257
|
+
}
|
|
3812
4258
|
}
|
|
3813
|
-
var pad = n.some(isPadded);
|
|
3814
4259
|
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
for (var
|
|
3818
|
-
var
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
4260
|
+
values = [];
|
|
4261
|
+
var valuesLength = 0;
|
|
4262
|
+
outer: for (var j = 0; j < n.length; j++) {
|
|
4263
|
+
var expanded = expand(
|
|
4264
|
+
n[j],
|
|
4265
|
+
max,
|
|
4266
|
+
maxLength,
|
|
4267
|
+
maxDepth,
|
|
4268
|
+
depth + 1,
|
|
4269
|
+
maxRewrites,
|
|
4270
|
+
budget,
|
|
4271
|
+
false
|
|
4272
|
+
);
|
|
4273
|
+
// The step budget ran out expanding a member.
|
|
4274
|
+
if (budget.remaining < 0) {
|
|
4275
|
+
return literal()
|
|
4276
|
+
}
|
|
4277
|
+
for (var k = 0; k < expanded.length; k++) {
|
|
4278
|
+
var v = expanded[k];
|
|
4279
|
+
if (dropsEmpties && !v) continue
|
|
4280
|
+
if (
|
|
4281
|
+
values.length >= max ||
|
|
4282
|
+
valuesLength + v.length > maxLength
|
|
4283
|
+
) {
|
|
4284
|
+
break outer
|
|
3834
4285
|
}
|
|
4286
|
+
values.push(v);
|
|
4287
|
+
valuesLength += v.length;
|
|
3835
4288
|
}
|
|
3836
|
-
N.push(c);
|
|
3837
|
-
}
|
|
3838
|
-
} else {
|
|
3839
|
-
N = [];
|
|
3840
|
-
|
|
3841
|
-
for (var j = 0; j < n.length; j++) {
|
|
3842
|
-
N.push.apply(N, expand(n[j], false));
|
|
3843
4289
|
}
|
|
3844
4290
|
}
|
|
3845
4291
|
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
4292
|
+
var next = combine(
|
|
4293
|
+
acc,
|
|
4294
|
+
pre,
|
|
4295
|
+
values,
|
|
4296
|
+
max,
|
|
4297
|
+
maxLength,
|
|
4298
|
+
dropEmpties && !m.post.length,
|
|
4299
|
+
budget
|
|
4300
|
+
);
|
|
4301
|
+
// The step budget ran out combining the set's values in.
|
|
4302
|
+
if (budget.remaining < 0) {
|
|
4303
|
+
return literal()
|
|
3852
4304
|
}
|
|
4305
|
+
acc = next;
|
|
4306
|
+
if (!m.post.length) break
|
|
4307
|
+
str = m.post;
|
|
4308
|
+
masked = masked.slice(m.end + 1);
|
|
3853
4309
|
}
|
|
3854
4310
|
|
|
3855
|
-
return
|
|
4311
|
+
return acc
|
|
3856
4312
|
}
|
|
3857
4313
|
|
|
3858
4314
|
const minimatch = (p, pattern, options = {}) => {
|
|
@@ -4257,8 +4713,8 @@
|
|
|
4257
4713
|
}
|
|
4258
4714
|
}
|
|
4259
4715
|
const head = pattern.slice(patternIndex, firstgs);
|
|
4260
|
-
const body = pattern.slice(firstgs + 1, lastgs);
|
|
4261
|
-
const tail = pattern.slice(lastgs + 1);
|
|
4716
|
+
const body = partial ? pattern.slice(firstgs + 1) : pattern.slice(firstgs + 1, lastgs);
|
|
4717
|
+
const tail = partial ? [] : pattern.slice(lastgs + 1);
|
|
4262
4718
|
// check the head
|
|
4263
4719
|
if (head.length) {
|
|
4264
4720
|
const fileHead = file.slice(fileIndex, fileIndex + head.length);
|
|
@@ -4300,7 +4756,7 @@
|
|
|
4300
4756
|
return false;
|
|
4301
4757
|
}
|
|
4302
4758
|
}
|
|
4303
|
-
return sawSome;
|
|
4759
|
+
return partial || sawSome;
|
|
4304
4760
|
}
|
|
4305
4761
|
// split body into segments at each GLOBSTAR
|
|
4306
4762
|
const bodySegments = [[[], 0]];
|
|
@@ -4361,7 +4817,7 @@
|
|
|
4361
4817
|
}
|
|
4362
4818
|
fileIndex++;
|
|
4363
4819
|
}
|
|
4364
|
-
return null;
|
|
4820
|
+
return partial || null;
|
|
4365
4821
|
}
|
|
4366
4822
|
_matchOne(file, pattern, partial, fileIndex, patternIndex) {
|
|
4367
4823
|
let fi;
|
|
@@ -4998,7 +5454,7 @@
|
|
|
4998
5454
|
[CASE_STYLES.snake]: SNAKE_CASE_REGEX
|
|
4999
5455
|
};
|
|
5000
5456
|
|
|
5001
|
-
const isInsideBaseDirectory = context => context.
|
|
5457
|
+
const isInsideBaseDirectory = context => context.filename.startsWith(context.options[0].basePath);
|
|
5002
5458
|
const asArray = item => {
|
|
5003
5459
|
if (!item) return [];
|
|
5004
5460
|
return Array.isArray(item) ? item : new Array(item);
|
|
@@ -5008,7 +5464,7 @@
|
|
|
5008
5464
|
return CASE_REGEXES[caseStyle]?.test(text) ?? true;
|
|
5009
5465
|
};
|
|
5010
5466
|
const findMatchedConfig = (context, configs) => {
|
|
5011
|
-
const fullFilePath = context.
|
|
5467
|
+
const fullFilePath = context.filename;
|
|
5012
5468
|
const basePath = context.options[0].basePath;
|
|
5013
5469
|
return configs.find(config => {
|
|
5014
5470
|
const isIncluded = asArray(config.includes).some(pathPattern => minimatch(fullFilePath, basePath + pathPattern));
|
|
@@ -5023,6 +5479,7 @@
|
|
|
5023
5479
|
if (!isCaseMatching(filename, filenameCase)) {
|
|
5024
5480
|
context.report({
|
|
5025
5481
|
node,
|
|
5482
|
+
loc: getFileReportLoc(context, node),
|
|
5026
5483
|
message: filenameShouldBe(filenameCase)
|
|
5027
5484
|
});
|
|
5028
5485
|
}
|
|
@@ -5121,7 +5578,7 @@
|
|
|
5121
5578
|
if (!defaultExportNode) return;
|
|
5122
5579
|
const exportedObjectName = defaultExportNode.declaration?.name;
|
|
5123
5580
|
if (!exportedObjectName) return;
|
|
5124
|
-
const pathKeys = context.
|
|
5581
|
+
const pathKeys = context.filename.split(/\.|\//g).slice(0, -1);
|
|
5125
5582
|
const pathString = filename === "index" ? pathKeys.slice(0, -1).join("") : pathKeys.join("");
|
|
5126
5583
|
const isNameMatches = pathString.endsWith(exportedObjectName);
|
|
5127
5584
|
if (isNameMatches) return;
|
|
@@ -6097,7 +6554,6 @@
|
|
|
6097
6554
|
type: TYPES.BINARY_EXPRESSION,
|
|
6098
6555
|
operator: operators.compare // ===, !==
|
|
6099
6556
|
};
|
|
6100
|
-
|
|
6101
6557
|
return neetoCist.matches(binaryExpressionPattern, expression) && (neetoCist.matches(pattern, expression.left) || neetoCist.matches(pattern, expression.right));
|
|
6102
6558
|
};
|
|
6103
6559
|
const logicalExpressionPattern = {
|
|
@@ -6906,7 +7362,7 @@
|
|
|
6906
7362
|
context,
|
|
6907
7363
|
node
|
|
6908
7364
|
}) => {
|
|
6909
|
-
const sourceCode = context.
|
|
7365
|
+
const sourceCode = context.sourceCode;
|
|
6910
7366
|
const historyMethodCalls = findMatchingNodesDeep(node, HISTORY_METHODS_PATTERN);
|
|
6911
7367
|
const historyMethodCall = historyMethodCalls[0];
|
|
6912
7368
|
const historyMethodArguments = historyMethodCall.arguments;
|
|
@@ -6970,7 +7426,7 @@
|
|
|
6970
7426
|
return;
|
|
6971
7427
|
}
|
|
6972
7428
|
if (isNotPartOfOnClickHandler(node)) return;
|
|
6973
|
-
const sourceCode = context.
|
|
7429
|
+
const sourceCode = context.sourceCode;
|
|
6974
7430
|
reportSuggestion$1({
|
|
6975
7431
|
context,
|
|
6976
7432
|
historyMethodCall,
|
|
@@ -7266,7 +7722,7 @@
|
|
|
7266
7722
|
// Do not replace this with `isInsideApisDirectory` since this rule should include axios.js
|
|
7267
7723
|
// `isInsideApisDirectory` returns false for apis/axios.js
|
|
7268
7724
|
const apisFolder = path$1.resolve(aliases?.apis || APIS_DIRECTORY);
|
|
7269
|
-
if (context.
|
|
7725
|
+
if (context.filename.startsWith(apisFolder)) return;
|
|
7270
7726
|
if (!isPackageImported(context, node, "axios")) return;
|
|
7271
7727
|
context.report(node, NO_AXIOS_IMPORT_OUTSIDE_APIS_MESSAGE);
|
|
7272
7728
|
}
|
|
@@ -7346,7 +7802,7 @@
|
|
|
7346
7802
|
node,
|
|
7347
7803
|
message: NO_BUILD_URL_CALL_WITH_EMPTY_PARAMS,
|
|
7348
7804
|
fix(fixer) {
|
|
7349
|
-
const sourceCode = context.
|
|
7805
|
+
const sourceCode = context.sourceCode;
|
|
7350
7806
|
const firstArgText = sourceCode.getText(node.arguments[0]);
|
|
7351
7807
|
return fixer.replaceText(node, firstArgText);
|
|
7352
7808
|
}
|
|
@@ -7409,7 +7865,7 @@
|
|
|
7409
7865
|
},
|
|
7410
7866
|
value: {
|
|
7411
7867
|
type: TYPES.JSX_EXPRESSION_CONTAINER,
|
|
7412
|
-
expression: expression => isConditionAndIsOpenValueSame(context.
|
|
7868
|
+
expression: expression => isConditionAndIsOpenValueSame(context.sourceCode.getTokens(expression), context.sourceCode.getTokens(conditionalExpression))
|
|
7413
7869
|
}
|
|
7414
7870
|
});
|
|
7415
7871
|
const isOpenValueInSpreadPropsPattern = (context, conditionalExpression) => ({
|
|
@@ -7422,7 +7878,7 @@
|
|
|
7422
7878
|
type: TYPES.IDENTIFIER,
|
|
7423
7879
|
name: "isOpen"
|
|
7424
7880
|
},
|
|
7425
|
-
value: value => isConditionAndIsOpenValueSame(context.
|
|
7881
|
+
value: value => isConditionAndIsOpenValueSame(context.sourceCode.getTokens(value), context.sourceCode.getTokens(conditionalExpression))
|
|
7426
7882
|
})
|
|
7427
7883
|
}
|
|
7428
7884
|
});
|
|
@@ -7590,6 +8046,7 @@
|
|
|
7590
8046
|
if (isGeneratedTranslationFile(context)) {
|
|
7591
8047
|
context.report({
|
|
7592
8048
|
node,
|
|
8049
|
+
loc: getFileReportLoc(context, node),
|
|
7593
8050
|
message: NO_EDITS_TO_GENERATED_TRANSLATION_FILES
|
|
7594
8051
|
});
|
|
7595
8052
|
}
|
|
@@ -8086,7 +8543,7 @@
|
|
|
8086
8543
|
message: NO_UNNECESSARY_CLASSNAMES,
|
|
8087
8544
|
fix(fixer) {
|
|
8088
8545
|
const singleClass = node.value.expression.arguments[0];
|
|
8089
|
-
let classText = context.
|
|
8546
|
+
let classText = context.sourceCode.getText(singleClass);
|
|
8090
8547
|
if (singleClass.type === TYPES.TEMPLATE_LITERAL) {
|
|
8091
8548
|
classText = `{${classText}}`;
|
|
8092
8549
|
}
|
|
@@ -8162,7 +8619,7 @@
|
|
|
8162
8619
|
if (!isFinalIfBeforeBooleanReturn(ifConditionNode, lastStatement, !value)) {
|
|
8163
8620
|
return;
|
|
8164
8621
|
}
|
|
8165
|
-
const condition = context.
|
|
8622
|
+
const condition = context.sourceCode.getText(ifConditionNode.test);
|
|
8166
8623
|
const returnStatementWithCondition = value ? `return ${condition};` : `return !(${condition});`;
|
|
8167
8624
|
const commonDescriptor = {
|
|
8168
8625
|
message: canBeReplacedWith(returnStatementWithCondition),
|
|
@@ -8597,14 +9054,14 @@
|
|
|
8597
9054
|
const prop = properties[index];
|
|
8598
9055
|
const propType = prop.type;
|
|
8599
9056
|
if (propType === TYPES.PROPERTY) {
|
|
8600
|
-
const propText = context.
|
|
9057
|
+
const propText = context.sourceCode.getText(prop);
|
|
8601
9058
|
propsToSort.push(propText);
|
|
8602
9059
|
} else if (propType === TYPES.SPREAD_ELEMENT) {
|
|
8603
9060
|
if (neetoCist.isNotEmpty(propsToSort)) {
|
|
8604
9061
|
sortedProps.push(propsToSort.sort());
|
|
8605
9062
|
propsToSort = [];
|
|
8606
9063
|
}
|
|
8607
|
-
const spreadElement = context.
|
|
9064
|
+
const spreadElement = context.sourceCode.getText(prop.argument);
|
|
8608
9065
|
sortedProps.push(spreadElement);
|
|
8609
9066
|
}
|
|
8610
9067
|
}
|
|
@@ -8647,10 +9104,10 @@
|
|
|
8647
9104
|
} else {
|
|
8648
9105
|
previousNode = node.name;
|
|
8649
9106
|
}
|
|
8650
|
-
return fixer.removeRange([context.
|
|
9107
|
+
return fixer.removeRange([context.sourceCode.getIndexFromLoc({
|
|
8651
9108
|
line: previousNode.loc.end.line,
|
|
8652
9109
|
column: previousNode.loc.end.column
|
|
8653
|
-
}), context.
|
|
9110
|
+
}), context.sourceCode.getIndexFromLoc({
|
|
8654
9111
|
line: endNode.loc.end.line,
|
|
8655
9112
|
column: endNode.loc.end.column
|
|
8656
9113
|
})]);
|
|
@@ -8698,9 +9155,9 @@
|
|
|
8698
9155
|
fix: fixer => {
|
|
8699
9156
|
const mergedProperties = adjacentSpreadAttributes.map(item => {
|
|
8700
9157
|
if (neetoCist.matches(OTHER_PROPS, item)) {
|
|
8701
|
-
return `...${context.
|
|
9158
|
+
return `...${context.sourceCode.getText(item.argument)}`;
|
|
8702
9159
|
}
|
|
8703
|
-
return item.argument.properties.map(item => context.
|
|
9160
|
+
return item.argument.properties.map(item => context.sourceCode.getText(item)).join(", ");
|
|
8704
9161
|
}).join(", ");
|
|
8705
9162
|
const fixToAddProperties = fixer.insertTextAfter(ramda.last(adjacentSpreadAttributes), `\n{...{ ${mergedProperties} }}`);
|
|
8706
9163
|
isAdjacentAttributesFixApplied = true;
|
|
@@ -8742,7 +9199,7 @@
|
|
|
8742
9199
|
fix: fixer => {
|
|
8743
9200
|
const fix = spreadAttributesWithoutOtherProps.flatMap(errorNode => {
|
|
8744
9201
|
let fixToAddProperties = null;
|
|
8745
|
-
const properties = errorNode.argument.properties.map(item => context.
|
|
9202
|
+
const properties = errorNode.argument.properties.map(item => context.sourceCode.getText(item)).join(", ");
|
|
8746
9203
|
let closestNode = getClosestNode(errorNode, spreadAttributes);
|
|
8747
9204
|
const isClosestNodeNotAdjacent = closestNode && errorNode.range[1] !== closestNode.range[0];
|
|
8748
9205
|
if (isClosestNodeNotAdjacent) {
|
|
@@ -8803,13 +9260,13 @@
|
|
|
8803
9260
|
}, attributes);
|
|
8804
9261
|
const indexToInsert = findIndexToInsert(nodeIndex, attributes);
|
|
8805
9262
|
if (indexToInsert === nodeIndex) return;
|
|
8806
|
-
const indentLevel = context.
|
|
9263
|
+
const indentLevel = context.sourceCode.getFirstToken(attributes[0]).loc.start.column;
|
|
8807
9264
|
context.report({
|
|
8808
9265
|
node,
|
|
8809
9266
|
message: MOVE_SPREAD_ATTRIBUTES_TO_TOP,
|
|
8810
9267
|
fix: fixer => {
|
|
8811
9268
|
const removeNode = fixer.remove(node);
|
|
8812
|
-
const moveNode = fixer.insertTextBefore(attributes[indexToInsert], `${context.
|
|
9269
|
+
const moveNode = fixer.insertTextBefore(attributes[indexToInsert], `${context.sourceCode.getText(node)}\n${" ".repeat(indentLevel)}`);
|
|
8813
9270
|
return [moveNode, removeNode];
|
|
8814
9271
|
}
|
|
8815
9272
|
});
|
|
@@ -8942,8 +9399,8 @@
|
|
|
8942
9399
|
} else {
|
|
8943
9400
|
fixToRemoveErrorNode = fixer.remove(node);
|
|
8944
9401
|
}
|
|
8945
|
-
const indentLevel = context.
|
|
8946
|
-
const propertyValue = context.
|
|
9402
|
+
const indentLevel = context.sourceCode.getFirstToken(node.parent.attributes[0]).loc.start.column;
|
|
9403
|
+
const propertyValue = context.sourceCode.getText(property.value);
|
|
8947
9404
|
const fixToAddProperty = positionToInsert === "below" ? fixer.insertTextAfter(node, `\n${" ".repeat(indentLevel)}${property.key.name}={${propertyValue}}`) : fixer.insertTextBefore(node, `${property.key.name}={${propertyValue}}\n${" ".repeat(indentLevel)}`);
|
|
8948
9405
|
return [fixToRemoveComma, fixToRemoveErrorNode, fixToAddProperty].filter(Boolean);
|
|
8949
9406
|
}
|
|
@@ -9742,7 +10199,7 @@
|
|
|
9742
10199
|
},
|
|
9743
10200
|
create: context => ({
|
|
9744
10201
|
Program(node) {
|
|
9745
|
-
const filePath = context.
|
|
10202
|
+
const filePath = context.filename;
|
|
9746
10203
|
if (!filePath.includes(REACT_QUERY_DIRECTORY)) return;
|
|
9747
10204
|
if (filePath.endsWith(FILENAME_SUFFIX)) return;
|
|
9748
10205
|
if (WHITELISTED_FOLDER_NAMES.includes(getFolderName(filePath))) return;
|
|
@@ -9750,6 +10207,7 @@
|
|
|
9750
10207
|
if (WHITELISTED_FILE_NAMES.includes(fileName)) return;
|
|
9751
10208
|
context.report({
|
|
9752
10209
|
node,
|
|
10210
|
+
loc: getFileReportLoc(context, node),
|
|
9753
10211
|
message: FILES_INSIDE_REACT_QUERY_FOLDER_SHOULD_END_WITH_API
|
|
9754
10212
|
});
|
|
9755
10213
|
}
|
|
@@ -9762,7 +10220,7 @@
|
|
|
9762
10220
|
return false;
|
|
9763
10221
|
};
|
|
9764
10222
|
const isInsideReactQueryDirectory = context => {
|
|
9765
|
-
const filename = context.
|
|
10223
|
+
const filename = context.filename;
|
|
9766
10224
|
const reactQueryDirectory = path$1.resolve(REACT_QUERY_DIRECTORY);
|
|
9767
10225
|
return filename.startsWith(reactQueryDirectory);
|
|
9768
10226
|
};
|
|
@@ -9867,6 +10325,7 @@
|
|
|
9867
10325
|
if (!declarator) {
|
|
9868
10326
|
context.report({
|
|
9869
10327
|
node: programNode,
|
|
10328
|
+
loc: getFileReportLoc(context, programNode),
|
|
9870
10329
|
message: helpUrlsFileMustExportBaseUrl(HELP_URLS_FILENAME, HELP_DOCS_BASE_URL_CONSTANT_NAME)
|
|
9871
10330
|
});
|
|
9872
10331
|
return false;
|
|
@@ -9972,7 +10431,7 @@
|
|
|
9972
10431
|
|
|
9973
10432
|
// Check 3: If it's a template literal, it must use permalinks.
|
|
9974
10433
|
if (init.type === TYPES.TEMPLATE_LITERAL) {
|
|
9975
|
-
const fullUrlString = context.
|
|
10434
|
+
const fullUrlString = context.sourceCode.getText(init);
|
|
9976
10435
|
if (ARTICLE_LINK_REGEX.test(fullUrlString)) {
|
|
9977
10436
|
context.report({
|
|
9978
10437
|
node: declarator,
|
|
@@ -9997,7 +10456,6 @@
|
|
|
9997
10456
|
if (!validateBaseUrlConstant(context, baseUrlDeclarator, programNode)) {
|
|
9998
10457
|
return; // Stop further checks if base URL is invalid.
|
|
9999
10458
|
}
|
|
10000
|
-
|
|
10001
10459
|
for (const declarator of topLevelDeclarations) {
|
|
10002
10460
|
if (declarator.id.name === HELP_DOCS_BASE_URL_CONSTANT_NAME) {
|
|
10003
10461
|
// Check for the old, incorrect URL format first for base constant.
|
|
@@ -10008,7 +10466,6 @@
|
|
|
10008
10466
|
});
|
|
10009
10467
|
return; // Report this error and stop, as it's a format issue.
|
|
10010
10468
|
}
|
|
10011
|
-
|
|
10012
10469
|
continue;
|
|
10013
10470
|
}
|
|
10014
10471
|
if (declarator.id.type !== TYPES.IDENTIFIER) continue;
|
|
@@ -10040,7 +10497,7 @@
|
|
|
10040
10497
|
* e.g., `const link = "https://neetochathelp.neetokb.com/p/123";`
|
|
10041
10498
|
*/
|
|
10042
10499
|
const checkForHardcodedHelpUrls = (context, node) => {
|
|
10043
|
-
const value = node.type === TYPES.LITERAL ? node.value : context.
|
|
10500
|
+
const value = node.type === TYPES.LITERAL ? node.value : context.sourceCode.getText(node);
|
|
10044
10501
|
if (typeof value !== "string") {
|
|
10045
10502
|
return;
|
|
10046
10503
|
}
|
|
@@ -10077,7 +10534,7 @@
|
|
|
10077
10534
|
fixable: "code"
|
|
10078
10535
|
},
|
|
10079
10536
|
create(context) {
|
|
10080
|
-
const filename = context.
|
|
10537
|
+
const filename = context.filename;
|
|
10081
10538
|
if (filename.endsWith(HELP_URLS_FILENAME)) {
|
|
10082
10539
|
return {
|
|
10083
10540
|
"Program:exit"(programNode) {
|
|
@@ -10237,7 +10694,7 @@
|
|
|
10237
10694
|
node,
|
|
10238
10695
|
fixer
|
|
10239
10696
|
}) => {
|
|
10240
|
-
const urlString = context.
|
|
10697
|
+
const urlString = context.sourceCode.getText(urlNode);
|
|
10241
10698
|
const fixForParams = getFixForParams({
|
|
10242
10699
|
urlNode,
|
|
10243
10700
|
urlString,
|
|
@@ -10434,13 +10891,13 @@
|
|
|
10434
10891
|
|
|
10435
10892
|
const getFixString = (context, expressionNode) => {
|
|
10436
10893
|
if (expressionNode.type === TYPES.LOGICAL_EXPRESSION) {
|
|
10437
|
-
const left = context.
|
|
10438
|
-
const right = context.
|
|
10894
|
+
const left = context.sourceCode.getText(expressionNode.left);
|
|
10895
|
+
const right = context.sourceCode.getText(expressionNode.right);
|
|
10439
10896
|
return `classnames({ ${right}: ${left} })`;
|
|
10440
10897
|
}
|
|
10441
|
-
const test = context.
|
|
10442
|
-
const consequent = context.
|
|
10443
|
-
const alternate = context.
|
|
10898
|
+
const test = context.sourceCode.getText(expressionNode.test);
|
|
10899
|
+
const consequent = context.sourceCode.getText(expressionNode.consequent);
|
|
10900
|
+
const alternate = context.sourceCode.getText(expressionNode.alternate);
|
|
10444
10901
|
return `classnames({${consequent}: ${test}, ${alternate}: !(${test})})`;
|
|
10445
10902
|
};
|
|
10446
10903
|
|
|
@@ -10693,7 +11150,7 @@
|
|
|
10693
11150
|
}]))
|
|
10694
11151
|
});
|
|
10695
11152
|
const importExists = (context, functionName) => {
|
|
10696
|
-
const ast = context.
|
|
11153
|
+
const ast = context.sourceCode.ast;
|
|
10697
11154
|
return neetoCist.existsBy(createSubscriptionImportPattern(functionName), ast.body);
|
|
10698
11155
|
};
|
|
10699
11156
|
|
|
@@ -10735,7 +11192,7 @@
|
|
|
10735
11192
|
});
|
|
10736
11193
|
}
|
|
10737
11194
|
if (neetoCist.matches(SUBSCRIPTION_REMOVE_PATTERN, node)) {
|
|
10738
|
-
const replacerText = context.
|
|
11195
|
+
const replacerText = context.sourceCode.getText(node.arguments[0]);
|
|
10739
11196
|
const replacerRange = node.range.splice(0, 2);
|
|
10740
11197
|
return context.report({
|
|
10741
11198
|
node: node.callee,
|
|
@@ -10828,11 +11285,11 @@
|
|
|
10828
11285
|
return;
|
|
10829
11286
|
}
|
|
10830
11287
|
const fix = fixer => {
|
|
10831
|
-
const condition = context.
|
|
10832
|
-
const consequent = context.
|
|
11288
|
+
const condition = context.sourceCode.getText(node.test);
|
|
11289
|
+
const consequent = context.sourceCode.getText(node.consequent).replace(/^\{|\}$/g, "");
|
|
10833
11290
|
let alternate = "return;";
|
|
10834
11291
|
if (node.alternate && isReturnBlock(node.alternate)) {
|
|
10835
|
-
alternate = context.
|
|
11292
|
+
alternate = context.sourceCode.getText(node.alternate);
|
|
10836
11293
|
if (node.alternate.type === TYPES.RETURN_STATEMENT) {
|
|
10837
11294
|
alternate = ensurePunctuation(alternate);
|
|
10838
11295
|
}
|
|
@@ -11076,7 +11533,7 @@
|
|
|
11076
11533
|
context,
|
|
11077
11534
|
loc
|
|
11078
11535
|
}) => {
|
|
11079
|
-
const sourceCode = context.
|
|
11536
|
+
const sourceCode = context.sourceCode;
|
|
11080
11537
|
return [sourceCode.getIndexFromLoc(loc.start), sourceCode.getIndexFromLoc(loc.end)];
|
|
11081
11538
|
};
|
|
11082
11539
|
const getCssProperty = cssClass => {
|
|
@@ -11188,7 +11645,7 @@
|
|
|
11188
11645
|
if (!neetoCist.matches(PRIVATE_ROUTE_PATTERN, node)) return;
|
|
11189
11646
|
const errorNode = neetoCist.findBy(CONDITION_ATTRIBUTE_PATTERN, node.attributes);
|
|
11190
11647
|
const functionArguments = errorNode.value.expression.arguments;
|
|
11191
|
-
const arrayFormat = functionArguments.map(argument => argument.type === TYPES.ARRAY_EXPRESSION ? context.
|
|
11648
|
+
const arrayFormat = functionArguments.map(argument => argument.type === TYPES.ARRAY_EXPRESSION ? context.sourceCode.getText(argument).slice(1, -1) : context.sourceCode.getText(argument)).join(", ");
|
|
11192
11649
|
context.report({
|
|
11193
11650
|
node: errorNode,
|
|
11194
11651
|
message: USE_PERMISSIONS_PROP_IN_PRIVATE_ROUTE,
|
|
@@ -11300,7 +11757,7 @@
|
|
|
11300
11757
|
}
|
|
11301
11758
|
},
|
|
11302
11759
|
create(context) {
|
|
11303
|
-
const sourceCode = context.
|
|
11760
|
+
const sourceCode = context.sourceCode;
|
|
11304
11761
|
return {
|
|
11305
11762
|
CallExpression(node) {
|
|
11306
11763
|
const {
|
|
@@ -11483,7 +11940,7 @@
|
|
|
11483
11940
|
importExists
|
|
11484
11941
|
}) => {
|
|
11485
11942
|
const replaceCallee = fixer.replaceText(node.callee, "useMutationWithInvalidation");
|
|
11486
|
-
const indentLevel = context.
|
|
11943
|
+
const indentLevel = context.sourceCode.getFirstToken(mutationOptions.properties[0]).loc.start.column;
|
|
11487
11944
|
let addKeysToInvalidate;
|
|
11488
11945
|
if (existingKeysToInvalidate) {
|
|
11489
11946
|
addKeysToInvalidate = fixer.insertTextAfter(ramda.last(existingKeysToInvalidate.value.elements), `,${keys}`);
|
|
@@ -11508,8 +11965,8 @@
|
|
|
11508
11965
|
return tokenAfter.value === "," ? fixer.remove(tokenAfter) : null;
|
|
11509
11966
|
};
|
|
11510
11967
|
const getVariables = (context, params) => {
|
|
11511
|
-
let variables = params.arguments[0].elements?.filter(element => element.type !== TYPES.LITERAL && /[a-z]/.test(context.
|
|
11512
|
-
if (!params.arguments[0].elements && /[a-z]/.test(context.
|
|
11968
|
+
let variables = params.arguments[0].elements?.filter(element => element.type !== TYPES.LITERAL && /[a-z]/.test(context.sourceCode.getText(element)));
|
|
11969
|
+
if (!params.arguments[0].elements && /[a-z]/.test(context.sourceCode.getText(params.arguments[0]))) {
|
|
11513
11970
|
variables = params.arguments[0];
|
|
11514
11971
|
}
|
|
11515
11972
|
return variables;
|
|
@@ -11553,7 +12010,7 @@
|
|
|
11553
12010
|
fixer,
|
|
11554
12011
|
mutationOptions,
|
|
11555
12012
|
existingKeysToInvalidate,
|
|
11556
|
-
keys: context.
|
|
12013
|
+
keys: context.sourceCode.getText(params.arguments[0]),
|
|
11557
12014
|
importExists
|
|
11558
12015
|
});
|
|
11559
12016
|
const removeInvalidations = fixer.remove(onSuccess);
|
|
@@ -11571,7 +12028,7 @@
|
|
|
11571
12028
|
return;
|
|
11572
12029
|
}
|
|
11573
12030
|
const otherOptions = neetoCist._removeBy(INVALIDATION_PATTERN, params);
|
|
11574
|
-
const queryClientInOtherOptions = otherOptions?.find(item => context.
|
|
12031
|
+
const queryClientInOtherOptions = otherOptions?.find(item => context.sourceCode.getText(item).includes("queryClient"));
|
|
11575
12032
|
if (queryClientInOtherOptions || neetoCist.findBy(OTHER_QUERY_CLIENT_USAGE_PATTERN, ramda.pluck("expression", invalidations))) {
|
|
11576
12033
|
return;
|
|
11577
12034
|
}
|
|
@@ -11582,7 +12039,7 @@
|
|
|
11582
12039
|
if (neetoCist.isNotPresent(invalidationsWithoutVariables)) {
|
|
11583
12040
|
reportError(context, node);
|
|
11584
12041
|
} else {
|
|
11585
|
-
const keys = ramda.pluck("expression", invalidationsWithoutVariables).flatMap(item => item.arguments.map(arg => context.
|
|
12042
|
+
const keys = ramda.pluck("expression", invalidationsWithoutVariables).flatMap(item => item.arguments.map(arg => context.sourceCode.getText(arg)));
|
|
11586
12043
|
context.report({
|
|
11587
12044
|
node,
|
|
11588
12045
|
message: USE_USE_MUTATION_WITH_INVALIDATION,
|
|
@@ -11656,10 +12113,10 @@
|
|
|
11656
12113
|
|
|
11657
12114
|
const getQueryClientInitializationFix = (context, fixer, body) => {
|
|
11658
12115
|
if (body.type === TYPES.BLOCK_STATEMENT) {
|
|
11659
|
-
const indentLevel = context.
|
|
12116
|
+
const indentLevel = context.sourceCode.getFirstToken(body.body[0]).loc.start.column;
|
|
11660
12117
|
return fixer.insertTextBefore(body.body[0], `const queryClient = useQueryClient();\n${" ".repeat(indentLevel)}`);
|
|
11661
12118
|
}
|
|
11662
|
-
return fixer.replaceText(body, `{ const queryClient = useQueryClient(); return (${context.
|
|
12119
|
+
return fixer.replaceText(body, `{ const queryClient = useQueryClient(); return (${context.sourceCode.getText(body)}) }`);
|
|
11663
12120
|
};
|
|
11664
12121
|
|
|
11665
12122
|
var useUseQueryClientHook = {
|
|
@@ -11674,7 +12131,7 @@
|
|
|
11674
12131
|
create: context => ({
|
|
11675
12132
|
VariableDeclarator(node) {
|
|
11676
12133
|
if (node.parent?.parent.type !== TYPES.PROGRAM) return;
|
|
11677
|
-
const text = context.
|
|
12134
|
+
const text = context.sourceCode.getText(node);
|
|
11678
12135
|
if (!text.includes("queryClient.") || text.includes("const queryClient = useQueryClient();")) {
|
|
11679
12136
|
return;
|
|
11680
12137
|
}
|
|
@@ -11737,7 +12194,7 @@
|
|
|
11737
12194
|
const aliases = context.options[0];
|
|
11738
12195
|
if (ramda.isEmpty(aliases) || ramda.isNil(aliases)) return;
|
|
11739
12196
|
const importPath = node.source.value;
|
|
11740
|
-
const importFullPath = importPath.startsWith("../") ? path$1.resolve(context.
|
|
12197
|
+
const importFullPath = importPath.startsWith("../") ? path$1.resolve(context.filename, "../", importPath) : importPath;
|
|
11741
12198
|
const matches = Object.entries(aliases).filter(([, path]) => importFullPath.startsWith(path) && ["/", undefined].includes(importFullPath.split(path)[1][0])).sort((first, second) => first.length - second.length);
|
|
11742
12199
|
if (matches.length === 0) return;
|
|
11743
12200
|
const aliasMatch = matches[matches.length - 1];
|
|
@@ -11785,7 +12242,7 @@
|
|
|
11785
12242
|
if (!watcher) watchJsConfigFile(context.options?.[0]?.jsconfigFilePath);
|
|
11786
12243
|
return {
|
|
11787
12244
|
Property(node) {
|
|
11788
|
-
const filename = context.
|
|
12245
|
+
const filename = context.filename;
|
|
11789
12246
|
const isInsideAliasFile = filename === context.options?.[0]?.aliasFilePath;
|
|
11790
12247
|
if (!isInsideAliasFile) return;
|
|
11791
12248
|
const isInsideAliasProperty = node.parent?.parent?.key?.name === "alias";
|
|
@@ -12444,7 +12901,7 @@
|
|
|
12444
12901
|
const programNode = findProgramNode(node);
|
|
12445
12902
|
const importSpecifierNode = findRamdaSpecifiers(programNode);
|
|
12446
12903
|
const comparatorFunctionNode = node.init.arguments[1];
|
|
12447
|
-
const propImportNode = findMatchingNodesDeep(context.
|
|
12904
|
+
const propImportNode = findMatchingNodesDeep(context.sourceCode.ast.body, PROP_IMPORT_PATTERN);
|
|
12448
12905
|
context.report({
|
|
12449
12906
|
node,
|
|
12450
12907
|
message: USE_PROP_FOR_PICKING_SINGLE_ITEM,
|
|
@@ -12484,7 +12941,7 @@
|
|
|
12484
12941
|
node,
|
|
12485
12942
|
message: USE_WITH_IMMUTABLE_ACTIONS_WRAPPER,
|
|
12486
12943
|
fix: fixer => {
|
|
12487
|
-
const argumentsString = argumentsInsideCreate.map(argument => context.
|
|
12944
|
+
const argumentsString = argumentsInsideCreate.map(argument => context.sourceCode.getText(argument)).join(", ");
|
|
12488
12945
|
const fixerArray = [];
|
|
12489
12946
|
const addWrapperFixer = `create(withImmutableActions(${argumentsString}))`;
|
|
12490
12947
|
fixerArray.push(fixer.replaceText(createUsageWithoutWrapper.init, addWrapperFixer));
|