Skip to content

Commit

Permalink
Reuse removeParentheses (#1592)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Nov 10, 2021
1 parent 579d05d commit 5584983
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 16 deletions.
8 changes: 2 additions & 6 deletions rules/no-useless-fallback-in-spread.js
Expand Up @@ -3,8 +3,8 @@ const {matches} = require('./selectors/index.js');
const {
isParenthesized,
getParenthesizedRange,
getParentheses,
} = require('./utils/parentheses.js');
const {removeParentheses} = require('./fix/index.js');
const shouldAddParenthesesToSpreadElementArgument = require('./utils/should-add-parentheses-to-spread-element-argument.js');

const MESSAGE_ID = 'no-useless-fallback-in-spread';
Expand Down Expand Up @@ -49,11 +49,7 @@ const create = context => ({
isLeftObjectParenthesized
|| !shouldAddParenthesesToSpreadElementArgument(left)
) {
const parentheses = getParentheses(logicalExpression, sourceCode);

for (const token of parentheses) {
yield fixer.remove(token);
}
yield * removeParentheses(logicalExpression, fixer, sourceCode);
}
},
};
Expand Down
8 changes: 2 additions & 6 deletions rules/no-useless-spread.js
Expand Up @@ -5,9 +5,8 @@ const {
newExpressionSelector,
methodCallSelector,
} = require('./selectors/index.js');
const {getParentheses} = require('./utils/parentheses.js');
const typedArray = require('./shared/typed-array.js');
const {fixSpaceAroundKeyword} = require('./fix/index.js');
const {removeParentheses, fixSpaceAroundKeyword} = require('./fix/index.js');

const SPREAD_IN_LIST = 'spread-in-list';
const ITERABLE_TO_ARRAY = 'iterable-to-array';
Expand Down Expand Up @@ -107,10 +106,7 @@ const create = context => {

// `[...(( [foo] ))]`
// ^^ ^^
const parentheses = getParentheses(spreadObject, sourceCode);
for (const parenthesis of parentheses) {
yield fixer.remove(parenthesis);
}
yield * removeParentheses(spreadObject, fixer, sourceCode);

// `[...[foo]]`
// ^
Expand Down
6 changes: 2 additions & 4 deletions rules/prefer-object-from-entries.js
Expand Up @@ -2,6 +2,7 @@
const {isCommaToken, isArrowToken, isClosingParenToken} = require('eslint-utils');
const getDocumentationUrl = require('./utils/get-documentation-url.js');
const {matches, methodCallSelector} = require('./selectors/index.js');
const {removeParentheses} = require('./fix/index.js');
const {getParentheses, getParenthesizedText} = require('./utils/parentheses.js');
const {isNodeMatches, isNodeMatchesNameOrPath} = require('./utils/is-node-matches.js');

Expand Down Expand Up @@ -147,10 +148,7 @@ function fixReduceAssignOrSpread({sourceCode, node, property}) {
const functionBody = node.arguments[0].body;
const {keyText, valueText} = getKeyValueText();
yield fixer.replaceText(functionBody, `[${keyText}, ${valueText}]`);

for (const parentheses of getParentheses(functionBody, sourceCode)) {
yield fixer.remove(parentheses);
}
yield * removeParentheses(functionBody, fixer, sourceCode);
}

return function * (fixer) {
Expand Down

0 comments on commit 5584983

Please sign in to comment.