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

no-new-mixins: getSourceModuleName should only be called on a CallExpression, MemberExpression or Identifier #905

Closed
buschtoens opened this issue Aug 3, 2020 · 5 comments · Fixed by #906
Labels

Comments

@buschtoens
Copy link
Contributor

AssertionError [ERR_ASSERTION]: `getSourceModuleName` should only be called on a `CallExpression`, `MemberExpression` or `Identifier`
    at getSourceModuleName (/Users/jan/open-source/decorators/node_modules/eslint-plugin-ember/lib/utils/import.js:46:5)
    at getSourceModuleName (/Users/jan/open-source/decorators/node_modules/eslint-plugin-ember/lib/utils/import.js:42:12)
    at /Users/jan/open-source/decorators/node_modules/eslint-plugin-ember/lib/utils/import.js:31:49
    at Array.some (<anonymous>)
    at /Users/jan/open-source/decorators/node_modules/eslint-plugin-ember/lib/utils/import.js:30:36
    at Array.find (<anonymous>)
    at Object.getSourceModuleNameForIdentifier (/Users/jan/open-source/decorators/node_modules/eslint-plugin-ember/lib/utils/import.js:29:6)
    at isEmberCoreModule (/Users/jan/open-source/decorators/node_modules/eslint-plugin-ember/lib/utils/ember.js:213:46)
    at Object.isEmberMixin (/Users/jan/open-source/decorators/node_modules/eslint-plugin-ember/lib/utils/ember.js:259:10)
    at ClassDeclaration (/Users/jan/open-source/decorators/node_modules/eslint-plugin-ember/lib/rules/no-new-mixins.js:36:19)

The above error appears to be triggered by code like:

test('basic functionality', function(this: TestContext, assert) {
  class TestObject extends this.ContainerObject {
    // ...
  }
});
@buschtoens
Copy link
Contributor Author

Same for no-attrs-in-components.

AssertionError [ERR_ASSERTION]: `getSourceModuleName` should only be called on a `CallExpression`, `MemberExpression` or `Identifier`
    at getSourceModuleName (/Users/jan/open-source/decorators/node_modules/eslint-plugin-ember/lib/utils/import.js:46:5)
    at getSourceModuleName (/Users/jan/open-source/decorators/node_modules/eslint-plugin-ember/lib/utils/import.js:42:12)
    at /Users/jan/open-source/decorators/node_modules/eslint-plugin-ember/lib/utils/import.js:31:49
    at Array.some (<anonymous>)
    at /Users/jan/open-source/decorators/node_modules/eslint-plugin-ember/lib/utils/import.js:30:36
    at Array.find (<anonymous>)
    at Object.getSourceModuleNameForIdentifier (/Users/jan/open-source/decorators/node_modules/eslint-plugin-ember/lib/utils/import.js:29:6)
    at isEmberCoreModule (/Users/jan/open-source/decorators/node_modules/eslint-plugin-ember/lib/utils/ember.js:213:46)
    at isEmberComponent (/Users/jan/open-source/decorators/node_modules/eslint-plugin-ember/lib/utils/ember.js:246:10)
    at ClassDeclaration (/Users/jan/open-source/decorators/node_modules/eslint-plugin-ember/lib/rules/no-attrs-in-components.js:34:13)

@buschtoens
Copy link
Contributor Author

no-get is affected as well.

AssertionError [ERR_ASSERTION]: `getSourceModuleName` should only be called on a `CallExpression`, `MemberExpression` or `Identifier`
    at getSourceModuleName (/Users/jan/open-source/decorators/node_modules/eslint-plugin-ember/lib/utils/import.js:46:5)
    at getSourceModuleName (/Users/jan/open-source/decorators/node_modules/eslint-plugin-ember/lib/utils/import.js:42:12)
    at /Users/jan/open-source/decorators/node_modules/eslint-plugin-ember/lib/utils/import.js:31:49
    at Array.some (<anonymous>)
    at /Users/jan/open-source/decorators/node_modules/eslint-plugin-ember/lib/utils/import.js:30:36
    at Array.find (<anonymous>)
    at Object.getSourceModuleNameForIdentifier (/Users/jan/open-source/decorators/node_modules/eslint-plugin-ember/lib/utils/import.js:29:6)
    at isEmberCoreModule (/Users/jan/open-source/decorators/node_modules/eslint-plugin-ember/lib/utils/ember.js:213:46)
    at isEmberArrayProxy (/Users/jan/open-source/decorators/node_modules/eslint-plugin-ember/lib/utils/ember.js:271:10)
    at Object.isEmberProxy (/Users/jan/open-source/decorators/node_modules/eslint-plugin-ember/lib/utils/ember.js:288:10)

I guess the issue is that isEmberCoreModule incorrectly passes the node through to getSourceModuleNameForIdentifier?

@rwjblue
Copy link
Member

rwjblue commented Aug 3, 2020

@buschtoens - Can you check what node type is being passed (also we should update that assertion to tell you what was passed in addition to what is allowed, the message as it stands is a bit hard to debug)?

@rwjblue
Copy link
Member

rwjblue commented Aug 3, 2020

In general, getSourceModuleNameForIdentifier is only going to call getSourceModuleName on an import specifier, but when the node.superClass is not itself an Identifier (in this case its a member expression) there is an issue.

https://astexplorer.net/#/gist/b736a0d02d00957083b4a0118403fd7d/38043d9bc98eba1ab831d7ca16ddf57435504583

getSourceModuleNameForIdentifier is passed the node.superClass (which normally is an Identifier, but in this case is a MemberExpression):

const superClassImportPath = importUtils.getSourceModuleNameForIdentifier(
context,
node.superClass
);

Then getSourceModuleNameForIdentifier calls getSourceModuleName(node) with that MemberExpression and causes the error you are seeing:

importDeclaration.specifiers.some(
(specifier) => specifier.local.name === getSourceModuleName(node)
)

Ultimately, I think we should update isEmberCoreModule to return false when we spot a non Identifier as node.superClass.

@bmish
Copy link
Member

bmish commented Aug 6, 2020

Opened fix in #906.

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 a pull request may close this issue.

3 participants