-
-
Notifications
You must be signed in to change notification settings - Fork 204
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
Refactor null checks for new-module-imports
and use-ember-data-rfc-395-imports
rules
#462
Conversation
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.
Thanks! Checking node types is much better than adding arbitrary null checks.
new-module-imports
and use-ember-data-rfc-395-imports
rules
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 tested this out on my codebase and found that it causes it at least one new bug that must be fixed before merging:
new-module-imports › valid › function myFunction(list) { for (const item in list) { } }
TypeError: Cannot read property 'type' of null
Occurred while linting <input>:1
155 |
156 | function isDestructuring(node) {
> 157 | return node.type === 'VariableDeclarator' && node.init.type === 'Identifier';
| ^
158 | }
159 |
160 | function isIdentifierImportedFrom(node, module) {
at type (lib/utils/new-module.js:157:58)
at isDestructuring (lib/rules/new-module-imports.js:61:14)
Looks like it’s not ready! I will reopen when I’ll be able to move it forward. |
@bmish I've applied your suggestion (+ rebased). I've manually tested it against an app and and addon. It should be good now! |
@dcyriller thanks! Could you add some test cases in the following files so that we can be confident all of this logic works correctly?
|
While adding tests for these utils, I’ve learnt something worth sharing. A visitor’s node (as in this snippet:)
is not a bare node. I mean: it is not a node as parsed by espree or babel-eslint. A node parsed by espree doesn't have a This observation has a consequence: a lot of utils are implicitely tied to the visitor. This makes them pretty hard to test on their own. I guess this is why an util like getParent is not tested. And this is why I can't add most of the test files you're asking. I mean these utils are covered by the rules tests which are higher level. But we can't test them at a lower level as bare function. Because these functions implicitely rely on a visitor scope. If, with this explanation, you have some more ideas @bmish, let me know! |
I've just fixed the rebase conflicts. |
Refactor #460 and #461 to check against node types.
Updated fix for #459.