Skip to content

Commit

Permalink
Resolves some ESLint no-shadow violations (#5152)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattxwang committed Feb 22, 2021
1 parent ae67767 commit 9322f0c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 50 deletions.
8 changes: 3 additions & 5 deletions lib/formatters/stringFormatter.js
Expand Up @@ -195,9 +195,7 @@ module.exports = function (results) {

output += deprecationsFormatter(results);

// TODO: Issue #4985
// eslint-disable-next-line no-shadow
output = results.reduce((output, result) => {
output = results.reduce((accum, result) => {
// Treat parseErrors as warnings
if (result.parseErrors) {
result.parseErrors.forEach((error) =>
Expand All @@ -211,9 +209,9 @@ module.exports = function (results) {
);
}

output += formatter(result.warnings, result.source || '');
accum += formatter(result.warnings, result.source || '');

return output;
return accum;
}, output);

// Ensure consistent padding
Expand Down
36 changes: 16 additions & 20 deletions lib/rules/comment-whitespace-inside/index.js
Expand Up @@ -18,6 +18,22 @@ const messages = ruleMessages(ruleName, {
rejectedClosing: 'Unexpected whitespace before "*/"',
});

function addWhitespaceBefore(comment) {
if (comment.text.startsWith('*')) {
comment.text = comment.text.replace(/^(\*+)/, `$1 `);
} else {
comment.raws.left = ' ';
}
}

function addWhitespaceAfter(comment) {
if (_.last(comment.text) === '*') {
comment.text = comment.text.replace(/(\*+)$/, ` $1`);
} else {
comment.raws.right = ' ';
}
}

function rule(expectation, options, context) {
return function (root, result) {
const validOptions = validateOptions(result, ruleName, {
Expand Down Expand Up @@ -65,26 +81,6 @@ function rule(expectation, options, context) {
complain(messages.expectedClosing, comment.toString().length - closer.length - 1);
}

// TODO: Issue #4985
// eslint-disable-next-line no-shadow
function addWhitespaceBefore(comment) {
if (comment.text.startsWith('*')) {
comment.text = comment.text.replace(/^(\*+)/, `$1 `);
} else {
comment.raws.left = ' ';
}
}

// TODO: Issue #4985
// eslint-disable-next-line no-shadow
function addWhitespaceAfter(comment) {
if (_.last(comment.text) === '*') {
comment.text = comment.text.replace(/(\*+)$/, ` $1`);
} else {
comment.raws.right = ' ';
}
}

function complain(message, index) {
if (context.fix) {
if (expectation === 'never') {
Expand Down
14 changes: 5 additions & 9 deletions lib/rules/declaration-bang-space-before/index.js
Expand Up @@ -42,22 +42,18 @@ function rule(expectation, options, context) {

if (bangIndex < value.length) {
target = value;
// TODO: Issue #4985
// eslint-disable-next-line no-shadow
setFixed = (value) => {
setFixed = (val) => {
if (decl.raws.value) {
decl.raws.value.raw = value;
decl.raws.value.raw = val;
} else {
decl.value = value;
decl.value = val;
}
};
} else if (decl.important) {
target = decl.raws.important || ' !important';
bangIndex -= value.length;
// TODO: Issue #4985
// eslint-disable-next-line no-shadow
setFixed = (value) => {
decl.raws.important = value;
setFixed = (val) => {
decl.raws.important = val;
};
} else {
return false; // not standard
Expand Down
6 changes: 2 additions & 4 deletions lib/rules/max-line-length/index.js
Expand Up @@ -72,15 +72,13 @@ function rule(maxLength, options, context) {
checkNewline(rootString, match, root),
);

// TODO: Issue #4985
// eslint-disable-next-line no-shadow
function complain(index, root) {
function complain(index, rootNode) {
report({
index,
result,
ruleName,
message: messages.expected(maxLength),
node: root,
node: rootNode,
});
}

Expand Down
23 changes: 11 additions & 12 deletions lib/rules/no-eol-whitespace/index.js
Expand Up @@ -131,12 +131,10 @@ function rule(on, options, context) {
);
}

// TODO: Issue #4985
// eslint-disable-next-line no-shadow
function fix(root) {
function fix(rootNode) {
let isRootFirst = true;

root.walk((node) => {
rootNode.walk((node) => {
fixText(
node.raws.before,
(fixed) => {
Expand Down Expand Up @@ -211,22 +209,23 @@ function rule(on, options, context) {
});

fixText(
root.raws.after,
rootNode.raws.after,
(fixed) => {
root.raws.after = fixed;
rootNode.raws.after = fixed;
},
isRootFirst,
);

if (typeof root.raws.after === 'string') {
if (typeof rootNode.raws.after === 'string') {
const lastEOL = Math.max(
root.raws.after.lastIndexOf('\n'),
root.raws.after.lastIndexOf('\r'),
rootNode.raws.after.lastIndexOf('\n'),
rootNode.raws.after.lastIndexOf('\r'),
);

if (lastEOL !== root.raws.after.length - 1) {
root.raws.after =
root.raws.after.slice(0, lastEOL + 1) + fixString(root.raws.after.slice(lastEOL + 1));
if (lastEOL !== rootNode.raws.after.length - 1) {
rootNode.raws.after =
rootNode.raws.after.slice(0, lastEOL + 1) +
fixString(rootNode.raws.after.slice(lastEOL + 1));
}
}
}
Expand Down

0 comments on commit 9322f0c

Please sign in to comment.