New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix no-array-prototype extensions
undefined error from trying to access callee from non-CallExpression
#1788
Fix no-array-prototype extensions
undefined error from trying to access callee from non-CallExpression
#1788
Conversation
@@ -752,6 +752,7 @@ module.exports = { | |||
if ( | |||
node.type === 'CallExpression' && | |||
importedEmberArrayName && | |||
nodeInitializedTo.callee && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to check that nodeInitializedTo.type === 'CallExpression'
.
Also need a test of course.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lack of a test case is the reason I left this PR as a draft. I'm not sure how to reproduce this in a test.
Would I import from the same path like import { SOMETHING } from '@ember/array'
and make sure it doesn't have a callee?
What would that even look like?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think maybe this could reproduce the error?
import { A } from '@ember/array';
this.foo = A();
this.foo.toArray();
I think in this case, node.InitializedTo.type
is no longer a CallExpression
but rather a MemberExpression
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lin-ll when I add your test case,
without the fix above, I get the following error:
TypeError: Converting circular structure to JSON
--> starting at object with constructor 'Node'
| property 'object' -> object with constructor 'Node'
--- property 'parent' closes the circle
at stringify (<anonymous>)
with the fix above, I get a legitimate linting error:
Message:
Should have no errors but had 1: [
{
ruleId: 'no-array-prototype-extensions',
severity: 1,
message: "Don't use Ember's array prototype extensions",
line: 5,
column: 5,
nodeType: 'CallExpression',
messageId: 'main',
endLine: 5,
endColumn: 23,
fix: { range: [Array], text: '[...this.foo]' }
}
]
The linting error is a false positive. This rule probably should allow your test case but it currently doesn't.
So either way, it's not a valid test case for this fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm really? When I run that example (yarn test tests/lib/rules/no-array-prototype-extensions.js
), I get the correct undefined error:
● no-array-prototype-extensions › valid ›
import { A } from '@ember/array';
this.foo = A();
this.foo.toArray();
TypeError: Cannot read property 'type' of undefined
Occurred while linting <input>:5
Rule: "no-array-prototype-extensions"
753 | node.type === 'CallExpression' &&
754 | importedEmberArrayName &&
> 755 | nodeInitializedTo.callee.type === 'Identifier' &&
| ^
756 | importedEmberArrayName === nodeInitializedTo.callee.name
757 | ) {
758 | return;
Agreed that with your fix, it doesn't fix the false positive -- but it does seem like a valid way of reproducing this error
Hello @canrozanes ! Just following up - are you still working on this! I know a couple other teams who've started running into this error - would love to get this fix pushed out as soon as we can 😄 |
Hey @lin-ll. As soon as I figure out how to reproduce this in a test case, we can merge this PR. |
no-array-prototype extensions
no-array-prototype extensions
no-array-prototype extensions
undefined error from trying to access callee from non-CallExpression
Fixes #1771.
Note: At this time, we've identified a way to reproduce the issue, but it's also an existing false positive. We will push this fix out without a test case so that this error can be resolved. Meanwhile, a new issue has been created to track the existing false positive: #1807