Skip to content
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

Merged
merged 5 commits into from
Oct 13, 2019
Merged

Refactor null checks for new-module-imports and use-ember-data-rfc-395-imports rules #462

merged 5 commits into from
Oct 13, 2019

Conversation

dcyriller
Copy link
Contributor

@dcyriller dcyriller commented Aug 9, 2019

Refactor #460 and #461 to check against node types.

Updated fix for #459.

@bmish bmish added the bug label Aug 9, 2019
Copy link
Member

@bmish bmish left a 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.

@bmish bmish changed the title Refactor new modules null checks Refactor null checks for new-module-imports and use-ember-data-rfc-395-imports rules Aug 9, 2019
Copy link
Member

@bmish bmish left a 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)

@dcyriller
Copy link
Contributor Author

Looks like it’s not ready! I will reopen when I’ll be able to move it forward.

@dcyriller dcyriller closed this Aug 9, 2019
@dcyriller dcyriller reopened this Aug 26, 2019
@dcyriller
Copy link
Contributor Author

dcyriller commented Aug 26, 2019

@bmish I've applied your suggestion (+ rebased). I've manually tested it against an app and and addon. It should be good now!

@bmish
Copy link
Member

bmish commented Sep 1, 2019

@dcyriller thanks! Could you add some test cases in the following files so that we can be confident all of this logic works correctly?

  • tests/lib/rules/new-module-imports.js
  • tests/lib/rules/use-ember-data-rfc-395-imports.js
  • tests/lib/utils/new-module-test.js (new test file)

@dcyriller
Copy link
Contributor Author

dcyriller commented Sep 26, 2019

While adding tests for these utils, I’ve learnt something worth sharing.

A visitor’s node (as in this snippet:)

module.exports = {
    meta: { ... },
    create(context) {
        return {
            ReturnStatement(node) {
            },
        }
    }
};

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 parent key. Yet, this one is decorated with its parent. Which means the visitor's node has actually been post processed (during the visitor instanciation?).

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!

@dcyriller
Copy link
Contributor Author

I've just fixed the rebase conflicts.

@bmish bmish merged commit 92c6541 into ember-cli:master Oct 13, 2019
@dcyriller dcyriller deleted the refact-new-modules branch October 14, 2019 06:18
@bmish bmish added internal and removed bug labels Oct 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants