@bigbinary/eslint-plugin-neeto 1.13.1 → 2.0.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/dist/index.js +671 -139
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -286,7 +286,7 @@
|
|
|
286
286
|
}
|
|
287
287
|
});
|
|
288
288
|
|
|
289
|
-
var version = "1.13.
|
|
289
|
+
var version = "1.13.2";
|
|
290
290
|
var packageJson = {
|
|
291
291
|
version: version};
|
|
292
292
|
|
|
@@ -550,8 +550,9 @@
|
|
|
550
550
|
const INVALID_SWITCH_CHILD_MESSAGE = "Switch component can only contain Route, Redirect, or PrivateRoute as direct children";
|
|
551
551
|
const PREFER_RADIO_BUTTONS_FOR_FEW_OPTIONS = "Consider using Radio buttons instead of Dropdown/Select when there are fewer than 4 options.";
|
|
552
552
|
const NO_EDITS_TO_GENERATED_TRANSLATION_FILES = "This translation file is auto-generated. Only edit 'en.json'; translations for all other locales are generated from it automatically. Please revert your changes in this file.";
|
|
553
|
-
const YUP_WHEN_BRANCH_SHOULD_BE_FUNCTION = "yup 1 needs `then` and `otherwise` to be functions of the base schema. Use `schema => schema.concat(...)`, which
|
|
554
|
-
const
|
|
553
|
+
const YUP_WHEN_BRANCH_SHOULD_BE_FUNCTION = "yup 1 needs `then` and `otherwise` to be functions of the base schema. Use `schema => schema.concat(...)`, which is what yup 0.32 did with a schema branch.";
|
|
554
|
+
const YUP_WHEN_BUILDER_SHOULD_DESTRUCTURE_VALUES = "yup 1 passes a .when() builder the dependency values as one array, so a builder that reads them spread gets that array and its conditions silently stop matching. Destructure them: `([a, b], schema) =>`.";
|
|
555
|
+
const YUP_WHEN_VALUES_IS_NOT_NEEDED = "`whenValues` was a bridge for yup 0.32, and every product is on yup 1 now. Pass the builder to `.when()` directly and destructure its values: `([a, b], schema) =>`.";
|
|
555
556
|
|
|
556
557
|
const PACKAGES_TO_CHECK = ["@bigbinary/neeto-molecules", "@bigbinary/neetoui", "@bigbinary/neeto-commons-frontend"];
|
|
557
558
|
|
|
@@ -3655,68 +3656,256 @@
|
|
|
3655
3656
|
|
|
3656
3657
|
var braceExpansion = expandTop;
|
|
3657
3658
|
|
|
3658
|
-
var escSlash = '\0SLASH'+Math.random()+'\0';
|
|
3659
|
-
var escOpen = '\0OPEN'+Math.random()+'\0';
|
|
3660
|
-
var escClose = '\0CLOSE'+Math.random()+'\0';
|
|
3661
|
-
var escComma = '\0COMMA'+Math.random()+'\0';
|
|
3662
|
-
var escPeriod = '\0PERIOD'+Math.random()+'\0';
|
|
3659
|
+
var escSlash = '\0SLASH' + Math.random().toFixed(16) + '\0';
|
|
3660
|
+
var escOpen = '\0OPEN' + Math.random().toFixed(16) + '\0';
|
|
3661
|
+
var escClose = '\0CLOSE' + Math.random().toFixed(16) + '\0';
|
|
3662
|
+
var escComma = '\0COMMA' + Math.random().toFixed(16) + '\0';
|
|
3663
|
+
var escPeriod = '\0PERIOD' + Math.random().toFixed(16) + '\0';
|
|
3664
|
+
|
|
3665
|
+
var EXPANSION_MAX = 100000;
|
|
3666
|
+
|
|
3667
|
+
// `EXPANSION_MAX` caps the *number* of expansions, but not their length. An
|
|
3668
|
+
// input like `'{a,b}'.repeat(1500)` stays under that count - its output is
|
|
3669
|
+
// truncated to 100k results - while making every result ~1500 characters
|
|
3670
|
+
// long. The result set, and the intermediate arrays built while combining
|
|
3671
|
+
// brace sets, then grow large enough to exhaust memory and crash the process
|
|
3672
|
+
// (CVE-2026-14257). `EXPANSION_MAX_LENGTH` bounds the total number of
|
|
3673
|
+
// characters the accumulator may hold at any point, so memory stays flat no
|
|
3674
|
+
// matter how many brace groups are chained. The limit sits well above any
|
|
3675
|
+
// realistic expansion (100k results hitting `EXPANSION_MAX` measure ~1M
|
|
3676
|
+
// characters) so legitimate input is unaffected.
|
|
3677
|
+
var EXPANSION_MAX_LENGTH = 4000000;
|
|
3678
|
+
|
|
3679
|
+
// `expand` recurses once per level of brace *nesting* - both when expanding a
|
|
3680
|
+
// set's comma members and when re-wrapping a set whose body is a single part.
|
|
3681
|
+
// The CVE-2026-14257 fix made the *tail* iterative (recursion on `m.post`, one
|
|
3682
|
+
// level per chained group), which left nesting depth unbounded: about 3,100
|
|
3683
|
+
// levels of `{{{...a,b...}}}` - only ~6KB of input - exhausted the native stack
|
|
3684
|
+
// and crashed the process. `EXPANSION_MAX_DEPTH` bounds how deep the parser
|
|
3685
|
+
// will follow nesting. It sits far above any realistic pattern and well below
|
|
3686
|
+
// the depth at which the stack runs out.
|
|
3687
|
+
var EXPANSION_MAX_DEPTH = 1000;
|
|
3688
|
+
|
|
3689
|
+
// Bash keeps a quirk where a brace group followed by a comma set still expands
|
|
3690
|
+
// (`{a},b}`). The parser implements it by rewriting the string and restarting
|
|
3691
|
+
// the scan, absorbing one `}` per pass. `n` trailing braces therefore cost `n`
|
|
3692
|
+
// full passes over a string that itself grows by one `escClose` sentinel each
|
|
3693
|
+
// time - quadratic in `n`, with a ~26x constant from the sentinel's length.
|
|
3694
|
+
// 128KB of `'{a}' + '}'.repeat(n) + ',z}'` blocked the event loop for 27
|
|
3695
|
+
// seconds to produce two results. `EXPANSION_MAX_REWRITES` bounds how many
|
|
3696
|
+
// times the scan may restart. Real `{a},b}` input needs a handful.
|
|
3697
|
+
var EXPANSION_MAX_REWRITES = 1000;
|
|
3698
|
+
|
|
3699
|
+
// `EXPANSION_MAX_STEPS` bounds the work one `expandTop` call does, which `max`,
|
|
3700
|
+
// `maxLength` and `maxDepth` don't: nested sets are rescanned at every level
|
|
3701
|
+
// and chained groups each rebuild up to `max` results, so 2KB of input could
|
|
3702
|
+
// block the event loop for over 30 seconds. Each character scanned, result
|
|
3703
|
+
// built and sequence value generated is a step, and each `expand` call costs
|
|
3704
|
+
// `CALL_STEPS` more. Past the budget, the set being expanded and everything
|
|
3705
|
+
// after it stay literal. A glob needs a few hundred steps, and nesting all the
|
|
3706
|
+
// way to `EXPANSION_MAX_DEPTH` about 4M.
|
|
3707
|
+
var EXPANSION_MAX_STEPS = 20000000;
|
|
3708
|
+
|
|
3709
|
+
// What one `expand` call costs on top of what it scans and builds. Setting
|
|
3710
|
+
// one up takes about as long as scanning 16 characters, and a set whose
|
|
3711
|
+
// results are wrapped to be expanded again makes one call per result, each
|
|
3712
|
+
// scanning and building next to nothing: 64KB of
|
|
3713
|
+
// `('{{' + ','.repeat(316) + '}{' + ','.repeat(316) + '}}').repeat(n)` made
|
|
3714
|
+
// 4M such calls, which spent the budget three times as slowly as anything
|
|
3715
|
+
// else.
|
|
3716
|
+
var CALL_STEPS = 16;
|
|
3663
3717
|
|
|
3664
3718
|
function numeric(str) {
|
|
3665
|
-
return parseInt(str, 10) == str
|
|
3666
|
-
? parseInt(str, 10)
|
|
3667
|
-
: str.charCodeAt(0);
|
|
3719
|
+
return parseInt(str, 10) == str ? parseInt(str, 10) : str.charCodeAt(0)
|
|
3668
3720
|
}
|
|
3669
3721
|
|
|
3670
3722
|
function escapeBraces(str) {
|
|
3671
|
-
return str
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3723
|
+
return str
|
|
3724
|
+
.split('\\\\')
|
|
3725
|
+
.join(escSlash)
|
|
3726
|
+
.split('\\{')
|
|
3727
|
+
.join(escOpen)
|
|
3728
|
+
.split('\\}')
|
|
3729
|
+
.join(escClose)
|
|
3730
|
+
.split('\\,')
|
|
3731
|
+
.join(escComma)
|
|
3732
|
+
.split('\\.')
|
|
3733
|
+
.join(escPeriod)
|
|
3676
3734
|
}
|
|
3677
3735
|
|
|
3678
3736
|
function unescapeBraces(str) {
|
|
3679
|
-
return str
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3737
|
+
return str
|
|
3738
|
+
.split(escSlash)
|
|
3739
|
+
.join('\\')
|
|
3740
|
+
.split(escOpen)
|
|
3741
|
+
.join('{')
|
|
3742
|
+
.split(escClose)
|
|
3743
|
+
.join('}')
|
|
3744
|
+
.split(escComma)
|
|
3745
|
+
.join(',')
|
|
3746
|
+
.split(escPeriod)
|
|
3747
|
+
.join('.')
|
|
3684
3748
|
}
|
|
3685
3749
|
|
|
3750
|
+
// Like `target.push(...items)` but doesn't overflow the stack
|
|
3751
|
+
function pushAll(target, items) {
|
|
3752
|
+
for (var i = 0; i < items.length; i++) {
|
|
3753
|
+
target.push(items[i]);
|
|
3754
|
+
}
|
|
3755
|
+
}
|
|
3756
|
+
|
|
3757
|
+
// `budget` is `{ remaining }`, one counter shared by every level and group of
|
|
3758
|
+
// an `expandTop` call, so the bound holds for the call as a whole.
|
|
3759
|
+
//
|
|
3760
|
+
// `balanced`, run on `masked` (see `maskUnmatchedOpens`), sliced from `str`
|
|
3761
|
+
// and charged for the characters it walks: up to the group's `}`, or the
|
|
3762
|
+
// whole string when there is no match or unmatched `{` come first, which
|
|
3763
|
+
// `unmatched` then flags for masking. Once a call overdraws the budget, it
|
|
3764
|
+
// and every later one return undefined, so the rest stays literal.
|
|
3765
|
+
function balancedWithBudget(str, masked, budget) {
|
|
3766
|
+
if (budget.remaining < 0) {
|
|
3767
|
+
return undefined
|
|
3768
|
+
}
|
|
3769
|
+
var r = balanced.range('{', '}', masked);
|
|
3770
|
+
var unmatched = r !== undefined && masked.indexOf('{') < r[0];
|
|
3771
|
+
budget.remaining -= r && !unmatched ? r[1] + 1 : str.length;
|
|
3772
|
+
if (!r || budget.remaining < 0) {
|
|
3773
|
+
return undefined
|
|
3774
|
+
}
|
|
3775
|
+
return {
|
|
3776
|
+
end: r[1],
|
|
3777
|
+
pre: str.slice(0, r[0]),
|
|
3778
|
+
body: str.slice(r[0] + 1, r[1]),
|
|
3779
|
+
post: str.slice(r[1] + 1),
|
|
3780
|
+
unmatched: unmatched,
|
|
3781
|
+
}
|
|
3782
|
+
}
|
|
3783
|
+
|
|
3784
|
+
// `masked` with every `{` that has no matching `}` swapped for a `\0`, which
|
|
3785
|
+
// keeps the length, so a scan of it still lines up with the string it was
|
|
3786
|
+
// made from. Such a `{` is literal either way, but `balanced` only learns that
|
|
3787
|
+
// one is unmatched by reading to the end of the string, so with one at the
|
|
3788
|
+
// head of every group (`'{a,{b,c}'.repeat(n)`) each scan read the rest of the
|
|
3789
|
+
// input. That was quadratic, and once the step budget charged for it, it ran
|
|
3790
|
+
// out partway through and left the rest literal. A scan of the masked copy
|
|
3791
|
+
// stops at the group's `}`. It is one pass, charged as such.
|
|
3792
|
+
function maskUnmatchedOpens(masked, budget) {
|
|
3793
|
+
budget.remaining -= masked.length;
|
|
3794
|
+
var open = [];
|
|
3795
|
+
for (var i = 0; i < masked.length; i++) {
|
|
3796
|
+
var c = masked.charCodeAt(i);
|
|
3797
|
+
if (c === 0x7b) {
|
|
3798
|
+
open.push(i);
|
|
3799
|
+
} else if (c === 0x7d && open.length) {
|
|
3800
|
+
open.pop();
|
|
3801
|
+
}
|
|
3802
|
+
}
|
|
3803
|
+
var out = '';
|
|
3804
|
+
var last = 0;
|
|
3805
|
+
for (var j = 0; j < open.length; j++) {
|
|
3806
|
+
out += masked.slice(last, open[j]) + '\0';
|
|
3807
|
+
last = open[j] + 1;
|
|
3808
|
+
}
|
|
3809
|
+
return out + masked.slice(last)
|
|
3810
|
+
}
|
|
3811
|
+
|
|
3812
|
+
// Whether `str` has a `,` not followed by another `,`, with a `}` after it on
|
|
3813
|
+
// the same line - what `/,(?!,).*\}/.test(str)` asks, answered in one pass from
|
|
3814
|
+
// the end. The regex tries every `,` and backtracks through the rest of its
|
|
3815
|
+
// line from each, which is quadratic, and the `{a},b}` rewrite asks again on
|
|
3816
|
+
// every pass. Like a scan, it is charged for the whole string and refused if
|
|
3817
|
+
// that overdraws the budget.
|
|
3818
|
+
function commaSetFollows(str, budget) {
|
|
3819
|
+
budget.remaining -= str.length;
|
|
3820
|
+
if (budget.remaining < 0) {
|
|
3821
|
+
return false
|
|
3822
|
+
}
|
|
3823
|
+
// Whether a `}` follows the current position before the line ends
|
|
3824
|
+
var close = false;
|
|
3825
|
+
for (var i = str.length - 1; i >= 0; i--) {
|
|
3826
|
+
var c = str.charCodeAt(i);
|
|
3827
|
+
if (c === 0x7d) {
|
|
3828
|
+
close = true;
|
|
3829
|
+
} else if (c === 0x0a || c === 0x0d || c === 0x2028 || c === 0x2029) {
|
|
3830
|
+
// A line terminator, which `.` does not match
|
|
3831
|
+
close = false;
|
|
3832
|
+
} else if (c === 0x2c && close && str.charCodeAt(i + 1) !== 0x2c) {
|
|
3833
|
+
return true
|
|
3834
|
+
}
|
|
3835
|
+
}
|
|
3836
|
+
return false
|
|
3837
|
+
}
|
|
3686
3838
|
|
|
3687
3839
|
// Basically just str.split(","), but handling cases
|
|
3688
3840
|
// where we have nested braced sections, which should be
|
|
3689
3841
|
// treated as individual members, like {a,{b,c},d}
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3842
|
+
//
|
|
3843
|
+
// Returns `undefined` if the step budget runs out before the whole set is
|
|
3844
|
+
// split, since splitting what is left on every comma would tear apart the
|
|
3845
|
+
// nested sets it still holds.
|
|
3846
|
+
function parseCommaParts(str, budget) {
|
|
3694
3847
|
var parts = [];
|
|
3695
|
-
var m = balanced('{', '}', str);
|
|
3696
3848
|
|
|
3697
|
-
|
|
3698
|
-
|
|
3849
|
+
// Walk the brace groups iteratively. Recursing on `post` once per group let a
|
|
3850
|
+
// chain of them exhaust the stack - the parsing-side counterpart to
|
|
3851
|
+
// the `expand` overflow fixed for CVE-2026-14257, and not something `max` or
|
|
3852
|
+
// `maxLength` can bound, since it happens before expansion.
|
|
3853
|
+
//
|
|
3854
|
+
// The part the next chunk continues
|
|
3855
|
+
var carry = '';
|
|
3699
3856
|
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
var p = pre.split(',');
|
|
3857
|
+
for (;;) {
|
|
3858
|
+
// A set's body holds no unmatched `{`, so there is nothing to mask.
|
|
3859
|
+
var m = balancedWithBudget(str, str, budget);
|
|
3704
3860
|
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3861
|
+
if (budget.remaining < 0) {
|
|
3862
|
+
return undefined
|
|
3863
|
+
}
|
|
3864
|
+
|
|
3865
|
+
if (!m) {
|
|
3866
|
+
var tail = str.split(',');
|
|
3867
|
+
tail[0] = carry + tail[0];
|
|
3868
|
+
pushAll(parts, tail);
|
|
3869
|
+
return parts
|
|
3870
|
+
}
|
|
3871
|
+
|
|
3872
|
+
var pre = m.pre;
|
|
3873
|
+
var body = m.body;
|
|
3874
|
+
var post = m.post;
|
|
3875
|
+
var p = pre.split(',');
|
|
3876
|
+
|
|
3877
|
+
p[0] = carry + p[0];
|
|
3878
|
+
p[p.length - 1] += '{' + body + '}';
|
|
3879
|
+
|
|
3880
|
+
if (!post.length) {
|
|
3881
|
+
pushAll(parts, p);
|
|
3882
|
+
return parts
|
|
3883
|
+
}
|
|
3711
3884
|
|
|
3712
|
-
|
|
3885
|
+
carry = p.pop();
|
|
3886
|
+
pushAll(parts, p);
|
|
3887
|
+
str = post;
|
|
3888
|
+
}
|
|
3889
|
+
}
|
|
3713
3890
|
|
|
3714
|
-
|
|
3891
|
+
// An option that is left out or null, or that is NaN, gets its default. Every
|
|
3892
|
+
// comparison against NaN is false, so a NaN bound would never be reached:
|
|
3893
|
+
// `{ maxSteps: NaN }` let 15KB of input block the event loop for 16 seconds,
|
|
3894
|
+
// and `{ maxDepth: NaN }` overflowed the stack again (CVE-2026-102278). Pass
|
|
3895
|
+
// `Infinity` to lift a bound.
|
|
3896
|
+
function bound(value, fallback) {
|
|
3897
|
+
return value == null || isNaN(value) ? fallback : value
|
|
3715
3898
|
}
|
|
3716
3899
|
|
|
3717
|
-
function expandTop(str) {
|
|
3718
|
-
if (!str)
|
|
3719
|
-
|
|
3900
|
+
function expandTop(str, options) {
|
|
3901
|
+
if (!str) return []
|
|
3902
|
+
|
|
3903
|
+
options = options || {};
|
|
3904
|
+
var max = bound(options.max, EXPANSION_MAX);
|
|
3905
|
+
var maxLength = bound(options.maxLength, EXPANSION_MAX_LENGTH);
|
|
3906
|
+
var maxDepth = bound(options.maxDepth, EXPANSION_MAX_DEPTH);
|
|
3907
|
+
var maxRewrites = bound(options.maxRewrites, EXPANSION_MAX_REWRITES);
|
|
3908
|
+
var maxSteps = bound(options.maxSteps, EXPANSION_MAX_STEPS);
|
|
3720
3909
|
|
|
3721
3910
|
// I don't know why Bash 4.3 does this, but it does.
|
|
3722
3911
|
// Anything starting with {} will have the first two bytes preserved
|
|
@@ -3728,130 +3917,373 @@
|
|
|
3728
3917
|
str = '\\{\\}' + str.substr(2);
|
|
3729
3918
|
}
|
|
3730
3919
|
|
|
3731
|
-
return expand(
|
|
3920
|
+
return expand(
|
|
3921
|
+
escapeBraces(str),
|
|
3922
|
+
max,
|
|
3923
|
+
maxLength,
|
|
3924
|
+
maxDepth,
|
|
3925
|
+
0,
|
|
3926
|
+
maxRewrites,
|
|
3927
|
+
{ remaining: maxSteps },
|
|
3928
|
+
true
|
|
3929
|
+
).map(unescapeBraces)
|
|
3732
3930
|
}
|
|
3733
3931
|
|
|
3734
3932
|
function embrace(str) {
|
|
3735
|
-
return '{' + str + '}'
|
|
3933
|
+
return '{' + str + '}'
|
|
3736
3934
|
}
|
|
3737
3935
|
function isPadded(el) {
|
|
3738
|
-
return /^-?0\d/.test(el)
|
|
3936
|
+
return /^-?0\d/.test(el)
|
|
3739
3937
|
}
|
|
3740
3938
|
|
|
3741
3939
|
function lte(i, y) {
|
|
3742
|
-
return i <= y
|
|
3940
|
+
return i <= y
|
|
3743
3941
|
}
|
|
3744
3942
|
function gte(i, y) {
|
|
3745
|
-
return i >= y
|
|
3943
|
+
return i >= y
|
|
3746
3944
|
}
|
|
3747
3945
|
|
|
3748
|
-
|
|
3749
|
-
|
|
3946
|
+
// Build `{ acc[a] + pre + values[v] }` for every combination, capping the
|
|
3947
|
+
// number of results at `max` and the total number of characters at `maxLength`.
|
|
3948
|
+
// This is the one place output grows, so bounding it here keeps the single
|
|
3949
|
+
// accumulator - and therefore memory - flat regardless of how many brace groups
|
|
3950
|
+
// are combined (CVE-2026-14257). Each result built is a step, since `max` and
|
|
3951
|
+
// `maxLength` bound one combination, not how many brace groups are combined.
|
|
3952
|
+
function combine(acc, pre, values, max, maxLength, dropEmpties, budget) {
|
|
3953
|
+
var out = [];
|
|
3954
|
+
var length = 0;
|
|
3955
|
+
// Bash drops empty results at the top level, and they don't count against
|
|
3956
|
+
// `max`, so `max` bounds the number of *kept* results. Only an empty
|
|
3957
|
+
// `acc[a] + pre` can make one, so for those the empty values are skipped
|
|
3958
|
+
// without being visited. Visiting them one at a time let a set of empties
|
|
3959
|
+
// cost `acc.length * values.length` while keeping nothing.
|
|
3960
|
+
var nonEmpty;
|
|
3961
|
+
outer: for (var a = 0; a < acc.length; a++) {
|
|
3962
|
+
var prefix = acc[a] + pre;
|
|
3963
|
+
var vs = values;
|
|
3964
|
+
if (dropEmpties && !prefix) {
|
|
3965
|
+
if (!nonEmpty) nonEmpty = values.filter(Boolean);
|
|
3966
|
+
vs = nonEmpty;
|
|
3967
|
+
}
|
|
3968
|
+
for (var v = 0; v < vs.length; v++) {
|
|
3969
|
+
if (out.length >= max) break outer
|
|
3970
|
+
var expansion = prefix + vs[v];
|
|
3971
|
+
if (length + expansion.length > maxLength) break outer
|
|
3972
|
+
out.push(expansion);
|
|
3973
|
+
length += expansion.length;
|
|
3974
|
+
}
|
|
3975
|
+
}
|
|
3976
|
+
budget.remaining -= out.length;
|
|
3977
|
+
return out
|
|
3978
|
+
}
|
|
3750
3979
|
|
|
3751
|
-
|
|
3752
|
-
|
|
3980
|
+
// The expansion values of a single numeric (`1..5`) or alphabetic (`a..e..2`)
|
|
3981
|
+
// sequence body, or `undefined` if the step budget runs out generating them.
|
|
3982
|
+
function expandSequence(body, isAlphaSequence, max, maxLength, budget) {
|
|
3983
|
+
var n = body.split(/\.\./);
|
|
3984
|
+
var N = [];
|
|
3985
|
+
// A sequence body always splits into two or three parts, but the compiler
|
|
3986
|
+
// can't know that.
|
|
3987
|
+
/* c8 ignore start */
|
|
3988
|
+
if (n[0] === undefined || n[1] === undefined) {
|
|
3989
|
+
return N
|
|
3990
|
+
}
|
|
3991
|
+
/* c8 ignore stop */
|
|
3992
|
+
var x = numeric(n[0]);
|
|
3993
|
+
var y = numeric(n[1]);
|
|
3994
|
+
var width = Math.max(n[0].length, n[1].length);
|
|
3995
|
+
var incr =
|
|
3996
|
+
n.length === 3 && n[2] !== undefined ?
|
|
3997
|
+
Math.max(Math.abs(numeric(n[2])), 1)
|
|
3998
|
+
: 1;
|
|
3999
|
+
var test = lte;
|
|
4000
|
+
var reverse = y < x;
|
|
4001
|
+
if (reverse) {
|
|
4002
|
+
incr *= -1;
|
|
4003
|
+
test = gte;
|
|
4004
|
+
}
|
|
4005
|
+
var pad = n.some(isPadded);
|
|
4006
|
+
// A padded value is built a character at a time to `width`, which the input
|
|
4007
|
+
// sets, so it costs one step per character: 64KB of
|
|
4008
|
+
// `('{' + '0'.repeat(100) + '..99999}').repeat(n)` took 7 seconds charged
|
|
4009
|
+
// one step per value.
|
|
4010
|
+
var cost = pad ? width : 1;
|
|
4011
|
+
|
|
4012
|
+
var length = 0;
|
|
4013
|
+
for (var i = x; test(i, y) && N.length < max; i += incr) {
|
|
4014
|
+
// Each value is a step. `max` and `maxLength` bound one sequence, but a
|
|
4015
|
+
// chain of them still generated up to `max` values each, however few
|
|
4016
|
+
// combining could keep.
|
|
4017
|
+
budget.remaining -= cost;
|
|
4018
|
+
if (budget.remaining < 0) {
|
|
4019
|
+
return undefined
|
|
4020
|
+
}
|
|
4021
|
+
var c;
|
|
4022
|
+
if (isAlphaSequence) {
|
|
4023
|
+
c = String.fromCharCode(i);
|
|
4024
|
+
if (c === '\\') {
|
|
4025
|
+
c = '';
|
|
4026
|
+
}
|
|
4027
|
+
} else {
|
|
4028
|
+
c = String(i);
|
|
4029
|
+
if (pad) {
|
|
4030
|
+
var need = width - c.length;
|
|
4031
|
+
if (need > 0) {
|
|
4032
|
+
var z = new Array(need + 1).join('0');
|
|
4033
|
+
if (i < 0) {
|
|
4034
|
+
c = '-' + z + c.slice(1);
|
|
4035
|
+
} else {
|
|
4036
|
+
c = z + c;
|
|
4037
|
+
}
|
|
4038
|
+
}
|
|
4039
|
+
}
|
|
4040
|
+
}
|
|
4041
|
+
if (length + c.length > maxLength) break
|
|
4042
|
+
N.push(c);
|
|
4043
|
+
length += c.length;
|
|
4044
|
+
}
|
|
4045
|
+
return N
|
|
4046
|
+
}
|
|
3753
4047
|
|
|
3754
|
-
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
|
|
4048
|
+
function expand(
|
|
4049
|
+
str,
|
|
4050
|
+
max,
|
|
4051
|
+
maxLength,
|
|
4052
|
+
maxDepth,
|
|
4053
|
+
depth,
|
|
4054
|
+
maxRewrites,
|
|
4055
|
+
budget,
|
|
4056
|
+
isTop
|
|
4057
|
+
) {
|
|
4058
|
+
// An overdraft here makes the first scan refuse, so `str` stays literal.
|
|
4059
|
+
budget.remaining -= CALL_STEPS;
|
|
4060
|
+
|
|
4061
|
+
// Too deeply nested to keep following: treat the rest as literal, the same
|
|
4062
|
+
// way a group that cannot expand is already handled. Truncating rather than
|
|
4063
|
+
// throwing keeps expansion total, matching `max` and `maxLength`.
|
|
4064
|
+
if (depth > maxDepth) {
|
|
4065
|
+
return [str]
|
|
4066
|
+
}
|
|
4067
|
+
|
|
4068
|
+
// Consume the string's top-level brace groups left to right, threading a
|
|
4069
|
+
// running set of combined prefixes (`acc`). Expanding the tail iteratively -
|
|
4070
|
+
// rather than recursing on `m.post` once per group - keeps the native stack
|
|
4071
|
+
// depth constant, so deeply chained input (`'{a,b}'.repeat(3000)`) can no
|
|
4072
|
+
// longer overflow the stack, and leaves a single accumulator whose size
|
|
4073
|
+
// `maxLength` bounds directly (CVE-2026-14257).
|
|
4074
|
+
var acc = [''];
|
|
4075
|
+
|
|
4076
|
+
// Bash drops empty results, but only when the *first* top-level group is a
|
|
4077
|
+
// comma set - a sequence like `{a..\}` may legitimately yield ''. The drop
|
|
4078
|
+
// is on the final strings, so it is applied to whichever `combine` produces
|
|
4079
|
+
// them (the one with no brace set left in the tail).
|
|
4080
|
+
// How many times the `{a},b}` rewrite below has restarted the scan. Each pass
|
|
4081
|
+
// re-reads the whole string, so leaving this unbounded is quadratic.
|
|
4082
|
+
var rewrites = 0;
|
|
4083
|
+
var dropEmpties = false;
|
|
4084
|
+
var firstGroup = true;
|
|
4085
|
+
// `str` with its unmatched `{` masked, once a scan has run into them
|
|
4086
|
+
var masked = str;
|
|
4087
|
+
|
|
4088
|
+
for (;;) {
|
|
4089
|
+
const m = balancedWithBudget(str, masked, budget);
|
|
4090
|
+
|
|
4091
|
+
// No brace set left, or no step budget left to look for one: the rest of
|
|
4092
|
+
// the string is literal.
|
|
4093
|
+
if (!m) {
|
|
4094
|
+
return combine(acc, str, [''], max, maxLength, dropEmpties, budget)
|
|
4095
|
+
}
|
|
4096
|
+
if (m.unmatched) {
|
|
4097
|
+
masked = maskUnmatchedOpens(masked, budget);
|
|
4098
|
+
}
|
|
4099
|
+
|
|
4100
|
+
// no need to expand pre, since it is guaranteed to be free of brace-sets
|
|
4101
|
+
const pre = m.pre;
|
|
4102
|
+
|
|
4103
|
+
// This set and the rest of the string, literal: for a set that cannot
|
|
4104
|
+
// expand, and for one the step budget runs out on. Once it is overdrawn,
|
|
4105
|
+
// every set still being expanded, at every level, stays literal like this -
|
|
4106
|
+
// otherwise each level above would go on combining, and wrapping and
|
|
4107
|
+
// expanding again, results the budget was too small for.
|
|
4108
|
+
var literal = function () {
|
|
4109
|
+
return combine(
|
|
4110
|
+
acc,
|
|
4111
|
+
pre + '{' + m.body + '}' + m.post,
|
|
4112
|
+
[''],
|
|
4113
|
+
max,
|
|
4114
|
+
maxLength,
|
|
4115
|
+
dropEmpties,
|
|
4116
|
+
budget
|
|
4117
|
+
)
|
|
4118
|
+
};
|
|
3759
4119
|
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
4120
|
+
if (/\$$/.test(pre)) {
|
|
4121
|
+
acc = combine(
|
|
4122
|
+
acc,
|
|
4123
|
+
pre + '{' + m.body + '}',
|
|
4124
|
+
[''],
|
|
4125
|
+
max,
|
|
4126
|
+
maxLength,
|
|
4127
|
+
dropEmpties && !m.post.length,
|
|
4128
|
+
budget
|
|
4129
|
+
);
|
|
4130
|
+
firstGroup = false;
|
|
4131
|
+
if (!m.post.length) break
|
|
4132
|
+
str = m.post;
|
|
4133
|
+
masked = masked.slice(m.end + 1);
|
|
4134
|
+
continue
|
|
3764
4135
|
}
|
|
3765
|
-
|
|
4136
|
+
|
|
3766
4137
|
var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
|
|
3767
|
-
var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(
|
|
4138
|
+
var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(
|
|
4139
|
+
m.body
|
|
4140
|
+
);
|
|
3768
4141
|
var isSequence = isNumericSequence || isAlphaSequence;
|
|
3769
4142
|
var isOptions = m.body.indexOf(',') >= 0;
|
|
3770
4143
|
if (!isSequence && !isOptions) {
|
|
3771
4144
|
// {a},b}
|
|
3772
|
-
if (m.post
|
|
4145
|
+
if (rewrites < maxRewrites && commaSetFollows(m.post, budget)) {
|
|
4146
|
+
rewrites++;
|
|
3773
4147
|
str = m.pre + '{' + m.body + escClose + m.post;
|
|
3774
|
-
|
|
4148
|
+
// Taking a `}` away never gives an unmatched `{` a partner, so what
|
|
4149
|
+
// is masked stays unmatched. The `{` it closed can be left without
|
|
4150
|
+
// one, and the next scan masks it.
|
|
4151
|
+
masked =
|
|
4152
|
+
masked.slice(0, m.end) + escClose + masked.slice(m.end + 1);
|
|
4153
|
+
isTop = true;
|
|
4154
|
+
continue
|
|
3775
4155
|
}
|
|
3776
|
-
|
|
4156
|
+
// Nothing here expands, so the whole remaining string is literal.
|
|
4157
|
+
return literal()
|
|
4158
|
+
}
|
|
4159
|
+
|
|
4160
|
+
if (firstGroup) {
|
|
4161
|
+
dropEmpties = isTop && !isSequence;
|
|
4162
|
+
firstGroup = false;
|
|
3777
4163
|
}
|
|
3778
4164
|
|
|
3779
|
-
var
|
|
4165
|
+
var values;
|
|
3780
4166
|
if (isSequence) {
|
|
3781
|
-
|
|
4167
|
+
values = expandSequence(
|
|
4168
|
+
m.body,
|
|
4169
|
+
isAlphaSequence,
|
|
4170
|
+
max,
|
|
4171
|
+
maxLength,
|
|
4172
|
+
budget
|
|
4173
|
+
);
|
|
4174
|
+
if (!values) {
|
|
4175
|
+
return literal()
|
|
4176
|
+
}
|
|
3782
4177
|
} else {
|
|
3783
|
-
n = parseCommaParts(m.body);
|
|
3784
|
-
|
|
4178
|
+
var n = parseCommaParts(m.body, budget);
|
|
4179
|
+
// The step budget ran out partway through the set.
|
|
4180
|
+
if (!n) {
|
|
4181
|
+
return literal()
|
|
4182
|
+
}
|
|
4183
|
+
if (n.length === 1 && n[0] !== undefined) {
|
|
3785
4184
|
// x{{a,b}}y ==> x{a}y x{b}y
|
|
3786
|
-
n = expand(
|
|
4185
|
+
n = expand(
|
|
4186
|
+
n[0],
|
|
4187
|
+
max,
|
|
4188
|
+
maxLength,
|
|
4189
|
+
maxDepth,
|
|
4190
|
+
depth + 1,
|
|
4191
|
+
maxRewrites,
|
|
4192
|
+
budget,
|
|
4193
|
+
false
|
|
4194
|
+
).map(embrace);
|
|
4195
|
+
// The step budget ran out expanding the set's only part.
|
|
4196
|
+
if (budget.remaining < 0) {
|
|
4197
|
+
return literal()
|
|
4198
|
+
}
|
|
4199
|
+
//XXX is this necessary? Can't seem to hit it in tests.
|
|
4200
|
+
/* c8 ignore start */
|
|
3787
4201
|
if (n.length === 1) {
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
4202
|
+
var single = combine(
|
|
4203
|
+
acc,
|
|
4204
|
+
pre + n[0],
|
|
4205
|
+
[''],
|
|
4206
|
+
max,
|
|
4207
|
+
maxLength,
|
|
4208
|
+
dropEmpties && !m.post.length,
|
|
4209
|
+
budget
|
|
4210
|
+
);
|
|
4211
|
+
if (budget.remaining < 0) {
|
|
4212
|
+
return literal()
|
|
4213
|
+
}
|
|
4214
|
+
acc = single;
|
|
4215
|
+
if (!m.post.length) break
|
|
4216
|
+
str = m.post;
|
|
4217
|
+
masked = masked.slice(m.end + 1);
|
|
4218
|
+
continue
|
|
3791
4219
|
}
|
|
4220
|
+
/* c8 ignore stop */
|
|
3792
4221
|
}
|
|
3793
|
-
}
|
|
3794
|
-
|
|
3795
|
-
// at this point, n is the parts, and we know it's not a comma set
|
|
3796
|
-
// with a single entry.
|
|
3797
|
-
var N;
|
|
3798
4222
|
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
incr *= -1;
|
|
3810
|
-
test = gte;
|
|
4223
|
+
// Values that `combine` is going to drop as empty produce no result, so
|
|
4224
|
+
// they must not count against `max` - otherwise `{a,,b}` with `max: 2`
|
|
4225
|
+
// would stop at `['a', '']` and yield one result instead of two. Skipping
|
|
4226
|
+
// them outright keeps `values` bounded while leaving `max` a bound on
|
|
4227
|
+
// *kept* results.
|
|
4228
|
+
var dropsEmpties = dropEmpties && !m.post.length && !pre;
|
|
4229
|
+
for (var d = 0; dropsEmpties && d < acc.length; d++) {
|
|
4230
|
+
if (acc[d]) {
|
|
4231
|
+
dropsEmpties = false;
|
|
4232
|
+
}
|
|
3811
4233
|
}
|
|
3812
|
-
var pad = n.some(isPadded);
|
|
3813
|
-
|
|
3814
|
-
N = [];
|
|
3815
4234
|
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
4235
|
+
values = [];
|
|
4236
|
+
var valuesLength = 0;
|
|
4237
|
+
outer: for (var j = 0; j < n.length; j++) {
|
|
4238
|
+
var expanded = expand(
|
|
4239
|
+
n[j],
|
|
4240
|
+
max,
|
|
4241
|
+
maxLength,
|
|
4242
|
+
maxDepth,
|
|
4243
|
+
depth + 1,
|
|
4244
|
+
maxRewrites,
|
|
4245
|
+
budget,
|
|
4246
|
+
false
|
|
4247
|
+
);
|
|
4248
|
+
// The step budget ran out expanding a member.
|
|
4249
|
+
if (budget.remaining < 0) {
|
|
4250
|
+
return literal()
|
|
4251
|
+
}
|
|
4252
|
+
for (var k = 0; k < expanded.length; k++) {
|
|
4253
|
+
var v = expanded[k];
|
|
4254
|
+
if (dropsEmpties && !v) continue
|
|
4255
|
+
if (
|
|
4256
|
+
values.length >= max ||
|
|
4257
|
+
valuesLength + v.length > maxLength
|
|
4258
|
+
) {
|
|
4259
|
+
break outer
|
|
3833
4260
|
}
|
|
4261
|
+
values.push(v);
|
|
4262
|
+
valuesLength += v.length;
|
|
3834
4263
|
}
|
|
3835
|
-
N.push(c);
|
|
3836
|
-
}
|
|
3837
|
-
} else {
|
|
3838
|
-
N = [];
|
|
3839
|
-
|
|
3840
|
-
for (var j = 0; j < n.length; j++) {
|
|
3841
|
-
N.push.apply(N, expand(n[j], false));
|
|
3842
4264
|
}
|
|
3843
4265
|
}
|
|
3844
4266
|
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
4267
|
+
var next = combine(
|
|
4268
|
+
acc,
|
|
4269
|
+
pre,
|
|
4270
|
+
values,
|
|
4271
|
+
max,
|
|
4272
|
+
maxLength,
|
|
4273
|
+
dropEmpties && !m.post.length,
|
|
4274
|
+
budget
|
|
4275
|
+
);
|
|
4276
|
+
// The step budget ran out combining the set's values in.
|
|
4277
|
+
if (budget.remaining < 0) {
|
|
4278
|
+
return literal()
|
|
3851
4279
|
}
|
|
4280
|
+
acc = next;
|
|
4281
|
+
if (!m.post.length) break
|
|
4282
|
+
str = m.post;
|
|
4283
|
+
masked = masked.slice(m.end + 1);
|
|
3852
4284
|
}
|
|
3853
4285
|
|
|
3854
|
-
return
|
|
4286
|
+
return acc
|
|
3855
4287
|
}
|
|
3856
4288
|
|
|
3857
4289
|
const minimatch = (p, pattern, options = {}) => {
|
|
@@ -4256,8 +4688,8 @@
|
|
|
4256
4688
|
}
|
|
4257
4689
|
}
|
|
4258
4690
|
const head = pattern.slice(patternIndex, firstgs);
|
|
4259
|
-
const body = pattern.slice(firstgs + 1, lastgs);
|
|
4260
|
-
const tail = pattern.slice(lastgs + 1);
|
|
4691
|
+
const body = partial ? pattern.slice(firstgs + 1) : pattern.slice(firstgs + 1, lastgs);
|
|
4692
|
+
const tail = partial ? [] : pattern.slice(lastgs + 1);
|
|
4261
4693
|
// check the head
|
|
4262
4694
|
if (head.length) {
|
|
4263
4695
|
const fileHead = file.slice(fileIndex, fileIndex + head.length);
|
|
@@ -4299,7 +4731,7 @@
|
|
|
4299
4731
|
return false;
|
|
4300
4732
|
}
|
|
4301
4733
|
}
|
|
4302
|
-
return sawSome;
|
|
4734
|
+
return partial || sawSome;
|
|
4303
4735
|
}
|
|
4304
4736
|
// split body into segments at each GLOBSTAR
|
|
4305
4737
|
const bodySegments = [[[], 0]];
|
|
@@ -4360,7 +4792,7 @@
|
|
|
4360
4792
|
}
|
|
4361
4793
|
fileIndex++;
|
|
4362
4794
|
}
|
|
4363
|
-
return null;
|
|
4795
|
+
return partial || null;
|
|
4364
4796
|
}
|
|
4365
4797
|
_matchOne(file, pattern, partial, fileIndex, patternIndex) {
|
|
4366
4798
|
let fi;
|
|
@@ -6096,7 +6528,6 @@
|
|
|
6096
6528
|
type: TYPES.BINARY_EXPRESSION,
|
|
6097
6529
|
operator: operators.compare // ===, !==
|
|
6098
6530
|
};
|
|
6099
|
-
|
|
6100
6531
|
return neetoCist.matches(binaryExpressionPattern, expression) && (neetoCist.matches(pattern, expression.left) || neetoCist.matches(pattern, expression.right));
|
|
6101
6532
|
};
|
|
6102
6533
|
const logicalExpressionPattern = {
|
|
@@ -9996,7 +10427,6 @@
|
|
|
9996
10427
|
if (!validateBaseUrlConstant(context, baseUrlDeclarator, programNode)) {
|
|
9997
10428
|
return; // Stop further checks if base URL is invalid.
|
|
9998
10429
|
}
|
|
9999
|
-
|
|
10000
10430
|
for (const declarator of topLevelDeclarations) {
|
|
10001
10431
|
if (declarator.id.name === HELP_DOCS_BASE_URL_CONSTANT_NAME) {
|
|
10002
10432
|
// Check for the old, incorrect URL format first for base constant.
|
|
@@ -10007,7 +10437,6 @@
|
|
|
10007
10437
|
});
|
|
10008
10438
|
return; // Report this error and stop, as it's a format issue.
|
|
10009
10439
|
}
|
|
10010
|
-
|
|
10011
10440
|
continue;
|
|
10012
10441
|
}
|
|
10013
10442
|
if (declarator.id.type !== TYPES.IDENTIFIER) continue;
|
|
@@ -11814,7 +12243,10 @@
|
|
|
11814
12243
|
|
|
11815
12244
|
const isFunction = node => FUNCTION_TYPES.includes(node?.type);
|
|
11816
12245
|
const keyName = property => property.key?.name ?? property.key?.value;
|
|
11817
|
-
|
|
12246
|
+
|
|
12247
|
+
// `utils/yup` is where products and nanos keep their yup setup; some re-export
|
|
12248
|
+
// yup from it.
|
|
12249
|
+
const isYupSource = source => source === "yup" || source.startsWith("yup/") || source === "utils/yup";
|
|
11818
12250
|
const isWhenCall = node => node?.type === TYPES.CALL_EXPRESSION && node.callee.type === TYPES.MEMBER_EXPRESSION && !node.callee.computed && node.callee.property.name === "when";
|
|
11819
12251
|
const findVariable = (scope, name) => {
|
|
11820
12252
|
for (let current = scope; current; current = current.upper) {
|
|
@@ -11910,13 +12342,108 @@
|
|
|
11910
12342
|
});
|
|
11911
12343
|
});
|
|
11912
12344
|
};
|
|
12345
|
+
const isWhenValuesCall = node => node?.type === TYPES.CALL_EXPRESSION && node.callee.type === TYPES.IDENTIFIER && node.callee.name === WHEN_VALUES;
|
|
12346
|
+
|
|
12347
|
+
// How many dependency values `.when(keys, …)` passes, or null if unknown.
|
|
12348
|
+
const keyCount = keys => {
|
|
12349
|
+
if (keys?.type === "ArrayExpression") {
|
|
12350
|
+
return keys.elements.every(element => element?.type !== "SpreadElement") ? keys.elements.length : null;
|
|
12351
|
+
}
|
|
12352
|
+
return keys?.type === TYPES.LITERAL && typeof keys.value === "string" ? 1 : null;
|
|
12353
|
+
};
|
|
12354
|
+
|
|
12355
|
+
// `(a, b, schema) => …` as `([a, b], schema) => …`, the yup 1 builder form.
|
|
12356
|
+
const destructuredParamsText = (sourceCode, builder, count) => {
|
|
12357
|
+
const {
|
|
12358
|
+
params
|
|
12359
|
+
} = builder;
|
|
12360
|
+
if (count === null || params.length === 0) return null;
|
|
12361
|
+
const valueParams = params.slice(0, count);
|
|
12362
|
+
if (valueParams.some(param => param.type === "RestElement")) return null;
|
|
12363
|
+
const texts = params.map(param => sourceCode.getText(param));
|
|
12364
|
+
const rest = texts.slice(count);
|
|
12365
|
+
return [`[${texts.slice(0, count).join(", ")}]`, ...rest].join(", ");
|
|
12366
|
+
};
|
|
12367
|
+
|
|
12368
|
+
// The builder's source with its parameters destructured.
|
|
12369
|
+
const destructuredBuilderText = (sourceCode, builder, count) => {
|
|
12370
|
+
const paramsText = destructuredParamsText(sourceCode, builder, count);
|
|
12371
|
+
if (paramsText === null) return null;
|
|
12372
|
+
const {
|
|
12373
|
+
params
|
|
12374
|
+
} = builder;
|
|
12375
|
+
const text = sourceCode.getText(builder);
|
|
12376
|
+
const start = params[0].range[0] - builder.range[0];
|
|
12377
|
+
const end = params.at(-1).range[1] - builder.range[0];
|
|
12378
|
+
const isParenthesized = sourceCode.getTokenBefore(params[0]).value === "(" && sourceCode.getTokenBefore(params[0]).range[0] >= builder.range[0];
|
|
12379
|
+
const head = isParenthesized ? paramsText : `(${paramsText})`;
|
|
12380
|
+
return text.slice(0, start) + head + text.slice(end);
|
|
12381
|
+
};
|
|
12382
|
+
|
|
12383
|
+
// `[a, b]` or `[a, b] = []`: the builder already destructures yup 1's values.
|
|
12384
|
+
const isArrayPattern = param => param.type === "ArrayPattern" || param.type === "AssignmentPattern" && param.left.type === "ArrayPattern";
|
|
12385
|
+
|
|
12386
|
+
// Whether a builder's first parameter is used as the values array:
|
|
12387
|
+
// `values[0]`, `values.length`, `...values` or `const [a] = values`. Property
|
|
12388
|
+
// reads such as `field.value` are not counted, since a dependency value is often
|
|
12389
|
+
// an object, and reading it spread is exactly the mistake this rule reports.
|
|
12390
|
+
const readsAsValuesArray = (sourceCode, builder, param) => {
|
|
12391
|
+
if (param.type !== TYPES.IDENTIFIER) return false;
|
|
12392
|
+
const variable = sourceCode.getDeclaredVariables(builder).find(({
|
|
12393
|
+
name
|
|
12394
|
+
}) => name === param.name);
|
|
12395
|
+
return Boolean(variable?.references.some(({
|
|
12396
|
+
identifier
|
|
12397
|
+
}) => {
|
|
12398
|
+
const {
|
|
12399
|
+
parent
|
|
12400
|
+
} = identifier;
|
|
12401
|
+
if (parent.type === TYPES.MEMBER_EXPRESSION && parent.object === identifier) {
|
|
12402
|
+
return parent.computed ? parent.property.type === TYPES.LITERAL && typeof parent.property.value === "number" : parent.property.name === "length";
|
|
12403
|
+
}
|
|
12404
|
+
if (parent.type === "SpreadElement") return true;
|
|
12405
|
+
return parent.type === "VariableDeclarator" && parent.init === identifier && parent.id.type === "ArrayPattern";
|
|
12406
|
+
}));
|
|
12407
|
+
};
|
|
12408
|
+
const checkBuilder = (context, whenCall, builder) => {
|
|
12409
|
+
const [firstParam] = builder.params;
|
|
12410
|
+
if (!firstParam || isArrayPattern(firstParam)) return;
|
|
12411
|
+
const {
|
|
12412
|
+
sourceCode
|
|
12413
|
+
} = context;
|
|
12414
|
+
if (readsAsValuesArray(sourceCode, builder, firstParam)) return;
|
|
12415
|
+
const text = destructuredBuilderText(sourceCode, builder, keyCount(whenCall.arguments[0]));
|
|
12416
|
+
context.report({
|
|
12417
|
+
node: builder,
|
|
12418
|
+
message: YUP_WHEN_BUILDER_SHOULD_DESTRUCTURE_VALUES,
|
|
12419
|
+
fix: text === null ? null : fixer => fixer.replaceText(builder, text)
|
|
12420
|
+
});
|
|
12421
|
+
};
|
|
12422
|
+
const checkWhenValues = (context, whenCall, wrapper) => {
|
|
12423
|
+
const {
|
|
12424
|
+
sourceCode
|
|
12425
|
+
} = context;
|
|
12426
|
+
const [builder] = wrapper.arguments;
|
|
12427
|
+
let text = null;
|
|
12428
|
+
|
|
12429
|
+
// `whenValues` spreads the values, so every value parameter, even an array
|
|
12430
|
+
// pattern such as `[firstTag]`, moves inside the new outer array.
|
|
12431
|
+
if (wrapper.arguments.length === 1 && isFunction(builder)) {
|
|
12432
|
+
text = destructuredBuilderText(sourceCode, builder, keyCount(whenCall.arguments[0]));
|
|
12433
|
+
}
|
|
12434
|
+
context.report({
|
|
12435
|
+
node: wrapper,
|
|
12436
|
+
message: YUP_WHEN_VALUES_IS_NOT_NEEDED,
|
|
12437
|
+
fix: text === null ? null : fixer => fixer.replaceText(wrapper, text)
|
|
12438
|
+
});
|
|
12439
|
+
};
|
|
11913
12440
|
var useYup1CompatibleWhen = {
|
|
11914
12441
|
meta: {
|
|
11915
12442
|
type: "problem",
|
|
11916
12443
|
fixable: "code",
|
|
11917
12444
|
docs: {
|
|
11918
12445
|
url: "https://github.com/neetozone/eslint-plugin-neeto/blob/main/docs/src/rules/use-yup-1-compatible-when.md",
|
|
11919
|
-
description: "yup .when() conditions should use function branches and builders that
|
|
12446
|
+
description: "yup .when() conditions should use function branches and builders that destructure their values, as yup 1 needs."
|
|
11920
12447
|
}
|
|
11921
12448
|
},
|
|
11922
12449
|
create: context => {
|
|
@@ -11928,16 +12455,21 @@
|
|
|
11928
12455
|
},
|
|
11929
12456
|
CallExpression(node) {
|
|
11930
12457
|
if (!importsYup || !isWhenCall(node)) return;
|
|
11931
|
-
if (!isYupSchema(node.callee.object)) return;
|
|
11932
12458
|
const [, config] = node.arguments;
|
|
11933
12459
|
if (!config) return;
|
|
12460
|
+
|
|
12461
|
+
// `whenValues` only ever wraps a yup builder, so its receiver need not
|
|
12462
|
+
// be traced, which matters for schemas from helpers such as
|
|
12463
|
+
// `buildNullableSchema()`.
|
|
12464
|
+
if (isWhenValuesCall(config)) {
|
|
12465
|
+
checkWhenValues(context, node, config);
|
|
12466
|
+
return;
|
|
12467
|
+
}
|
|
12468
|
+
if (!isYupSchema(node.callee.object)) return;
|
|
11934
12469
|
if (config.type === TYPES.OBJECT_EXPRESSION) {
|
|
11935
12470
|
checkBranches(context, isYupSchema, config);
|
|
11936
12471
|
} else if (isFunction(config)) {
|
|
11937
|
-
context
|
|
11938
|
-
node: config,
|
|
11939
|
-
message: YUP_WHEN_BUILDER_SHOULD_USE_WHEN_VALUES
|
|
11940
|
-
});
|
|
12472
|
+
checkBuilder(context, node, config);
|
|
11941
12473
|
}
|
|
11942
12474
|
}
|
|
11943
12475
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bigbinary/eslint-plugin-neeto",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"scripts": {
|
|
@@ -30,13 +30,13 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@babel/core": "^7.
|
|
33
|
+
"@babel/core": "^7.29.6",
|
|
34
34
|
"@babel/eslint-parser": "^7.27.5",
|
|
35
35
|
"@babel/plugin-transform-runtime": "^7.19.1",
|
|
36
36
|
"@babel/preset-env": "7.17.10",
|
|
37
37
|
"@babel/preset-react": "7.16.7",
|
|
38
38
|
"@babel/preset-typescript": "^7.18.6",
|
|
39
|
-
"@babel/runtime": "^7.
|
|
39
|
+
"@babel/runtime": "^7.26.10",
|
|
40
40
|
"@bigbinary/babel-preset-neeto": "^1.0.3",
|
|
41
41
|
"@bigbinary/eslint-plugin-neeto": "^1.7.2",
|
|
42
42
|
"@bigbinary/neeto-cist": "^1.0.3",
|
|
@@ -73,10 +73,10 @@
|
|
|
73
73
|
"eslint-plugin-unused-imports": "^4.1.4",
|
|
74
74
|
"globals": "^16.0.0",
|
|
75
75
|
"husky": "7.0.4",
|
|
76
|
-
"i18next": "
|
|
76
|
+
"i18next": "26.3.4",
|
|
77
77
|
"jest": "27.5.1",
|
|
78
78
|
"lint-staged": "12.4.1",
|
|
79
|
-
"minimatch": "^6.2.
|
|
79
|
+
"minimatch": "^6.2.3",
|
|
80
80
|
"mock-fs": "^5.2.0",
|
|
81
81
|
"prettier": "2.6.2",
|
|
82
82
|
"ramda": "0.29.0",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"@bigbinary/neeto-cist": "^1.0.3",
|
|
92
92
|
"@bigbinary/neeto-commons-frontend": "4.13.38",
|
|
93
93
|
"eslint": "^9.25.1",
|
|
94
|
-
"i18next": "
|
|
94
|
+
"i18next": "26.3.4",
|
|
95
95
|
"ramda": "0.29.0"
|
|
96
96
|
}
|
|
97
97
|
}
|