Skip to content

Commit

Permalink
Simplify isMemberExpression and isMethodCall (#2100)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed May 15, 2023
1 parent 2a0b40f commit 8abd753
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 19 deletions.
24 changes: 16 additions & 8 deletions rules/ast/is-member-expression.js
Expand Up @@ -49,13 +49,7 @@ function isMemberExpression(node, options) {
}

if (
(computed === true && (node.computed !== computed))
|| (
computed === false
// `node.computed` can be `undefined` in some parsers
&& node.computed
)
|| (optional === true && (node.optional !== optional))
(optional === true && (node.optional !== optional))
|| (
optional === false
// `node.optional` can be `undefined` in some parsers
Expand All @@ -68,9 +62,23 @@ function isMemberExpression(node, options) {
if (
Array.isArray(properties)
&& properties.length > 0
&& (
) {
if (
node.property.type !== 'Identifier'
|| !properties.includes(node.property.name)
) {
return false;
}

computed ??= false;
}

if (
(computed === true && (node.computed !== computed))
|| (
computed === false
// `node.computed` can be `undefined` in some parsers
&& node.computed
)
) {
return false;
Expand Down
1 change: 0 additions & 1 deletion rules/explicit-length-check.js
Expand Up @@ -144,7 +144,6 @@ function create(context) {
!isMemberExpression(memberExpression, {
properties: ['length', 'size'],
optional: false,
computed: false,
})
|| memberExpression.object.type === 'ThisExpression'
) {
Expand Down
1 change: 0 additions & 1 deletion rules/no-array-for-each.js
Expand Up @@ -405,7 +405,6 @@ const create = context => {
if (
!isMethodCall(node, {
method: 'forEach',
computed: false,
})
|| isNodeMatches(node.callee.object, ignoredObjects)
) {
Expand Down
1 change: 0 additions & 1 deletion rules/no-array-method-this-argument.js
Expand Up @@ -122,7 +122,6 @@ const create = context => {
argumentsLength: 2,
optionalCall: false,
optionalMember: false,
computed: false,
})
|| isNodeMatches(callExpression.callee, ignored)
|| isNodeValueNotFunction(callExpression.arguments[0])
Expand Down
1 change: 0 additions & 1 deletion rules/no-array-push-push.js
Expand Up @@ -21,7 +21,6 @@ const isArrayPushCall = node =>
method: 'push',
optionalCall: false,
optionalMember: false,
computed: false,
});

function getFirstArrayPushCall(secondCall, sourceCode) {
Expand Down
1 change: 0 additions & 1 deletion rules/no-console-spaces.js
Expand Up @@ -45,7 +45,6 @@ const create = context => {
minimumArguments: 1,
optionalCall: false,
optionalMember: false,
computed: false,
})
) {
return;
Expand Down
1 change: 0 additions & 1 deletion rules/prefer-dom-node-append.js
Expand Up @@ -15,7 +15,6 @@ const create = () => ({
method: 'appendChild',
argumentsLength: 1,
optionalCall: false,
computed: false,
})
|| isNodeValueNotDomNode(node.callee.object)
|| isNodeValueNotDomNode(node.arguments[0])
Expand Down
1 change: 0 additions & 1 deletion rules/prefer-dom-node-remove.js
Expand Up @@ -36,7 +36,6 @@ const create = context => {
method: 'removeChild',
argumentsLength: 1,
optionalCall: false,
computed: false,
})
|| isNodeValueNotDomNode(node.callee.object)
|| isNodeValueNotDomNode(node.arguments[0])
Expand Down
1 change: 0 additions & 1 deletion rules/prefer-dom-node-text-content.js
Expand Up @@ -25,7 +25,6 @@ const create = () => ({
if (
!isMemberExpression(memberExpression, {
property: 'innerText',
computed: false,
})
) {
return;
Expand Down
1 change: 0 additions & 1 deletion rules/prefer-query-selector.js
Expand Up @@ -95,7 +95,6 @@ const create = () => ({
argumentsLength: 1,
optionalCall: false,
optionalMember: false,
computed: false,
})
|| isNodeValueNotDomNode(node.callee.object)
) {
Expand Down
1 change: 0 additions & 1 deletion rules/prefer-set-size.js
Expand Up @@ -67,7 +67,6 @@ const create = context => {
!isMemberExpression(node, {
property: 'length',
optional: false,
computed: false,
})
|| node.object.type !== 'ArrayExpression'
|| node.object.elements.length !== 1
Expand Down
1 change: 0 additions & 1 deletion rules/utils/is-node-value-not-function.js
Expand Up @@ -35,7 +35,6 @@ const isNodeValueNotFunction = node => (
method: 'bind',
optionalCall: false,
optionalMember: false,
computed: false,
}))
)
);
Expand Down

0 comments on commit 8abd753

Please sign in to comment.