Skip to content

Commit

Permalink
review eslint core rules: enforce the use of variables within the s…
Browse files Browse the repository at this point in the history
…cope they are defined
  • Loading branch information
zloirock committed Aug 17, 2023
1 parent acaadf7 commit 98994ff
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
3 changes: 2 additions & 1 deletion packages/core-js/internals/array-slice-simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ module.exports = function (O, start, end) {
var k = toAbsoluteIndex(start, length);
var fin = toAbsoluteIndex(end === undefined ? length : end, length);
var result = $Array(max(fin - k, 0));
for (var n = 0; k < fin; k++, n++) createProperty(result, n, O[k]);
var n = 0;
for (; k < fin; k++, n++) createProperty(result, n, O[k]);
result.length = n;
return result;
};
4 changes: 3 additions & 1 deletion packages/core-js/internals/function-bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ var factories = {};

var construct = function (C, argsLength, args) {
if (!hasOwn(factories, argsLength)) {
for (var list = [], i = 0; i < argsLength; i++) list[i] = 'a[' + i + ']';
var list = [];
var i = 0;
for (; i < argsLength; i++) list[i] = 'a[' + i + ']';
factories[argsLength] = $Function('C,a', 'return new C(' + join(list, ',') + ')');
} return factories[argsLength](C, args);
};
Expand Down
11 changes: 8 additions & 3 deletions packages/core-js/modules/es.string.replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,16 @@ fixRegExpWellKnownSymbolLogic('replace', function (_, nativeReplace, maybeCallNa
if (!functionalReplace) replaceValue = toString(replaceValue);

var global = rx.global;
var fullUnicode;
if (global) {
var fullUnicode = rx.unicode;
fullUnicode = rx.unicode;
rx.lastIndex = 0;
}

var results = [];
var result;
while (true) {
var result = regExpExec(rx, S);
result = regExpExec(rx, S);
if (result === null) break;

push(results, result);
Expand All @@ -112,6 +115,7 @@ fixRegExpWellKnownSymbolLogic('replace', function (_, nativeReplace, maybeCallNa
var matched = toString(result[0]);
var position = max(min(toIntegerOrInfinity(result.index), S.length), 0);
var captures = [];
var replacement;
// NOTE: This is equivalent to
// captures = result.slice(1).map(maybeToString)
// but for some reason `nativeSlice.call(result, 1, result.length)` (called in
Expand All @@ -122,7 +126,7 @@ fixRegExpWellKnownSymbolLogic('replace', function (_, nativeReplace, maybeCallNa
if (functionalReplace) {
var replacerArgs = concat([matched], captures, position, S);
if (namedCaptures !== undefined) push(replacerArgs, namedCaptures);
var replacement = toString(apply(replaceValue, undefined, replacerArgs));
replacement = toString(apply(replaceValue, undefined, replacerArgs));
} else {
replacement = getSubstitution(matched, S, position, captures, namedCaptures, replaceValue);
}
Expand All @@ -131,6 +135,7 @@ fixRegExpWellKnownSymbolLogic('replace', function (_, nativeReplace, maybeCallNa
nextSourcePosition = position + matched.length;
}
}

return accumulatedResult + stringSlice(S, nextSourcePosition);
}
];
Expand Down
11 changes: 8 additions & 3 deletions packages/core-js/modules/esnext.string.dedent.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var dedentStringsArray = function (template) {
var blocks = $Array(length);
var dedented = $Array(length);
var i = 0;
var lines, common;
var lines, common, quasi, k;

if (!length) throw $TypeError(INVALID_TAG);

Expand Down Expand Up @@ -107,7 +107,9 @@ var dedentStringsArray = function (template) {

for (i = 0; i < length; i++) {
lines = blocks[i];
for (var quasi = lines[0], k = 1; k < lines.length; k += 2) {
quasi = lines[0];
k = 1;
for (; k < lines.length; k += 2) {
quasi += lines[k] + stringSlice(lines[k + 1], count);
}
dedented[i] = quasi;
Expand All @@ -126,7 +128,10 @@ var commonLeadingIndentation = function (a, b) {
};

var cookStrings = function (raw) {
for (var i = 0, length = raw.length, result = $Array(length); i < length; i++) {
var i = 0;
var length = raw.length;
var result = $Array(length);
for (; i < length; i++) {
result[i] = parse(raw[i]);
} return result;
};
Expand Down
2 changes: 2 additions & 0 deletions tests/eslint/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ const base = {
'valid-typeof': ERROR,

// suggestions:
// enforce the use of variables within the scope they are defined
'block-scoped-var': ERROR,
// require camel case names
camelcase: [ERROR, { properties: NEVER }],
// enforce default clauses in switch statements to be last
Expand Down

0 comments on commit 98994ff

Please sign in to comment.