Skip to content

Commit 36a6603

Browse files
authored
Improve performance of parentheses related check (#2794)
1 parent 30f0847 commit 36a6603

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+392
-183
lines changed

rules/explicit-length-check.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
import {isParenthesized, getStaticValue} from '@eslint-community/eslint-utils';
2-
import {checkVueTemplate} from './utils/rule.js';
3-
import isLogicalExpression from './utils/is-logical-expression.js';
4-
import {isBooleanNode, getBooleanAncestor} from './utils/boolean.js';
1+
import {getStaticValue} from '@eslint-community/eslint-utils';
2+
import {
3+
isParenthesized,
4+
checkVueTemplate,
5+
isLogicalExpression,
6+
isBooleanNode,
7+
getBooleanAncestor,
8+
} from './utils/index.js';
59
import {fixSpaceAroundKeyword} from './fix/index.js';
610
import {isLiteral, isMemberExpression, isNumericLiteral} from './ast/index.js';
711

@@ -114,7 +118,7 @@ function create(context) {
114118

115119
let fixed = `${sourceCode.getText(lengthNode)} ${code}`;
116120
if (
117-
!isParenthesized(node, sourceCode)
121+
!isParenthesized(node, context)
118122
&& node.type === 'UnaryExpression'
119123
&& (node.parent.type === 'UnaryExpression' || node.parent.type === 'AwaitExpression')
120124
) {

rules/fix/fix-space-around-keywords.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {getParenthesizedRange} from '../utils/parentheses.js';
1+
import {getParenthesizedRange} from '../utils/index.js';
22

33
/**
44
@import {TSESTree as ESTree} from '@typescript-eslint/types';

rules/fix/remove-argument.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {isCommaToken} from '@eslint-community/eslint-utils';
2-
import {getParentheses} from '../utils/parentheses.js';
2+
import {getParentheses} from '../utils/index.js';
33

44
/**
55
@import {TSESTree as ESTree} from '@typescript-eslint/types';

rules/fix/remove-method-call.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {getParenthesizedRange} from '../utils/parentheses.js';
1+
import {getParenthesizedRange} from '../utils/index.js';
22
import {removeMemberExpressionProperty} from './replace-member-expression-property.js';
33

44
/**

rules/fix/remove-parentheses.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {getParentheses} from '../utils/parentheses.js';
1+
import {getParentheses} from '../utils/index.js';
22

33
/**
44
@import {TSESTree as ESTree} from '@typescript-eslint/types';

rules/fix/replace-argument.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {getParenthesizedRange} from '../utils/parentheses.js';
1+
import {getParenthesizedRange} from '../utils/index.js';
22

33
/**
44
@import {TSESTree as ESTree} from '@typescript-eslint/types';

rules/fix/replace-member-expression-property.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {getParenthesizedRange} from '../utils/parentheses.js';
1+
import {getParenthesizedRange} from '../utils/index.js';
22

33
/**
44
@import {TSESTree as ESTree} from '@typescript-eslint/types';

rules/fix/replace-node-or-token-and-spaces-before.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {getParentheses} from '../utils/parentheses.js';
1+
import {getParentheses} from '../utils/index.js';
22
/**
33
@import {TSESTree as ESTree} from '@typescript-eslint/types';
44
@import * as ESLint from 'eslint';

rules/fix/switch-call-expression-to-new-expression.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import {isParenthesized} from '../utils/parentheses.js';
2-
import shouldAddParenthesesToNewExpressionCallee from '../utils/should-add-parentheses-to-new-expression-callee.js';
1+
import {
2+
isParenthesized,
3+
shouldAddParenthesesToNewExpressionCallee,
4+
} from '../utils/index.js';
35
import fixSpaceAroundKeyword from './fix-space-around-keywords.js';
46

57
/**
@@ -20,7 +22,7 @@ export default function * switchCallExpressionToNewExpression(node, context, fix
2022

2123
const {callee} = node;
2224
if (
23-
!isParenthesized(callee, context.sourceCode)
25+
!isParenthesized(callee, context)
2426
&& shouldAddParenthesesToNewExpressionCallee(callee)
2527
) {
2628
yield fixer.insertTextBefore(callee, '(');

rules/fix/switch-new-expression-to-call-expression.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import isNewExpressionWithParentheses from '../utils/is-new-expression-with-parentheses.js';
2-
import {isParenthesized} from '../utils/parentheses.js';
3-
import isOnSameLine from '../utils/is-on-same-line.js';
1+
import {
2+
isNewExpressionWithParentheses,
3+
isParenthesized,
4+
isOnSameLine,
5+
} from '../utils/index.js';
46
import addParenthesizesToReturnOrThrowExpression from './add-parenthesizes-to-return-or-throw-expression.js';
57
import removeSpaceAfter from './remove-spaces-after.js';
68

@@ -34,7 +36,7 @@ export default function * switchNewExpressionToCallExpression(newExpression, con
3436
}
3537
```
3638
*/
37-
if (!isOnSameLine(newToken, newExpression.callee, context) && !isParenthesized(newExpression, context.sourceCode)) {
39+
if (!isOnSameLine(newToken, newExpression.callee, context) && !isParenthesized(newExpression, context)) {
3840
// Ideally, we should use first parenthesis of the `callee`, and should check spaces after the `new` token
3941
// But adding extra parentheses is harmless, no need to be too complicated
4042
yield addParenthesizesToReturnOrThrowExpression(fixer, newExpression.parent, context);

0 commit comments

Comments
 (0)