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

Getting "AssertionError [ERR_ASSERTION]: Function should only be called on a CallExpression (classic class) or ClassDeclaration (native class)`" #1257

Closed
BillyRayPreachersSon opened this issue Jul 20, 2021 · 2 comments

Comments

@BillyRayPreachersSon
Copy link

BillyRayPreachersSon commented Jul 20, 2021

We've got a really complex Ember project based on a monorepo structure. It's currently using Ember 3.12, and we're in the process of upgrading to Ember 3.16 (we only use LTS versions).

After upgrading Ember and some other unrelated / non-Ember packages, we're seeing an odd message while running linting.

The error is as follows:

AssertionError [ERR_ASSERTION]: Function should only be called on a `CallExpression` (classic class) or `ClassDeclaration` (native class)
Occurred while linting /Users/me/code/app3/packages/theapp/app/components/new-component/component.js:5
    at isEmberCoreModule (/Users/me/code/app3/node_modules/eslint-plugin-ember/lib/utils/ember.js:227:5)
    at isEmberObject (/Users/me/code/app3/node_modules/eslint-plugin-ember/lib/utils/ember.js:283:10)
    at Property (/Users/me/code/app3/node_modules/eslint-plugin-custom-ember/lib/rules/require-super-call-on-destroy-methods.js:66:14)
    at listeners.(anonymous function).forEach.listener (/Users/me/code/app3/node_modules/eslint/lib/linter/safe-emitter.js:45:58)
    at Array.forEach (<anonymous>)
    at Object.emit (/Users/me/code/app3/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/Users/me/code/app3/node_modules/eslint/lib/linter/node-event-generator.js:254:26)
    at NodeEventGenerator.applySelectors (/Users/me/code/app3/node_modules/eslint/lib/linter/node-event-generator.js:283:22)
    at NodeEventGenerator.enterNode (/Users/me/code/app3/node_modules/eslint/lib/linter/node-event-generator.js:297:14)
    at CodePathAnalyzer.enterNode (/Users/me/code/app3/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:634:23)
error: --------------------------------------------------------------------------
error: An uncaught YUIDoc error has occurred, stack trace given below
error: --------------------------------------------------------------------------
error: AssertionError [ERR_ASSERTION]: Function should only be called on a `CallExpression` (classic class) or `ClassDeclaration` (native class)
Occurred while linting /Users/me/code/app3/packages/theapp/app/components/new-component/component.js:5
    at isEmberCoreModule (/Users/me/code/app3/node_modules/eslint-plugin-ember/lib/utils/ember.js:227:5)
    at isEmberObject (/Users/me/code/app3/node_modules/eslint-plugin-ember/lib/utils/ember.js:283:10)
    at Property (/Users/me/code/app3/node_modules/eslint-plugin-custom-ember/lib/rules/require-super-call-on-destroy-methods.js:66:14)
    at listeners.(anonymous function).forEach.listener (/Users/me/code/app3/node_modules/eslint/lib/linter/safe-emitter.js:45:58)
    at Array.forEach (<anonymous>)
    at Object.emit (/Users/me/code/app3/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/Users/me/code/app3/node_modules/eslint/lib/linter/node-event-generator.js:254:26)
    at NodeEventGenerator.applySelectors (/Users/me/code/app3/node_modules/eslint/lib/linter/node-event-generator.js:283:22)
    at NodeEventGenerator.enterNode (/Users/me/code/app3/node_modules/eslint/lib/linter/node-event-generator.js:297:14)
    at CodePathAnalyzer.enterNode (/Users/me/code/app3/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:634:23)
error: --------------------------------------------------------------------------
error: Node.js version: v10.14.2
error: YUI version: 3.18.1
error: YUIDoc version: 0.10.2
error: Please file all tickets here: http://github.com/yui/yuidoc/issues
error: --------------------------------------------------------------------------
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! theapp@0.1234.0 lint:js: `eslint .`
npm ERR! Exit status 1

In terms of linting packages, we're using:

"eslint": "6.8.0",
"eslint-plugin-ember": "7.13.0",
"eslint-plugin-ember-suave": "2.0.1",

However, I've also tried eslint-plugin-ember 8.14.0 and 9.6.0, but they both give the same error.

This seems to be a similar error to the one shown in issue #905, which is why I tried upgrading to 8.14.0 (as #905 was fixed in 8.10.1)... but all that happens is the line number in eslint-plugin-ember/lib/utils/ember.js for the isEmberCoreModule function that throws the assertion has changed. Pretty much everything else remains the same.

I've added some logging to the ember.js file in the isEmberCoreModule function, and at the time the error is thrown, I can see that the three parameters are possibly not as expected:

  • context logs out as a Node object, with many properties - the most salient possibly being type: 'CallExpression' (see below for the full content from logging context)
  • node logs out as the filename being linted (new-component/component.js, in my case)
  • moduleName logs out as 'EmberObject'

Given the first thing that the isEmberCoreModule function tries to do is determine the truthiness of isCallExpression(node), yet it's isCallExpression(context) that would pass that check, I'm a bit lost as to what's going on.

I've cut down both the file being linted, as well as the class it extends, to the bare minimum - but the error still persists. My components/new-component/component.js file is as follows:

import BaseComponent from '../base-component/component';

export default BaseComponent.extend({

  someProp: true,

});

And my components/base-component/component.js file is just as bare:

import Component from '@ember/component';

export default Component.extend({

  someProp: false,

});

As I mentioned, it's an extremely complex Ember project and there's no way I can share or upload the source. However, based on what I have provided, would anyone have an inkling what might be happening or how I might start to resolve it?

I'm happy to try any steps, and suggestions, or provide more logging if it helps.

Thanks!

The full log of what the context parameter contains is as follows:

Node {
  type: 'CallExpression',
  start: 67,
  end: 109,
  loc:
   SourceLocation {
     start: Position { line: 3, column: 15 },
     end: Position { line: 7, column: 2 } },
  range: [ 67, 109 ],
  callee:
   Node {
     type: 'MemberExpression',
     start: 67,
     end: 84,
     loc: SourceLocation { start: [Position], end: [Position] },
     range: [ 67, 84 ],
     object:
      Node {
        type: 'Identifier',
        start: 67,
        end: 77,
        loc: [SourceLocation],
        range: [Array],
        name: 'BaseFlyout',
        _babelType: 'Identifier',
        parent: [Circular] },
     property:
      Node {
        type: 'Identifier',
        start: 78,
        end: 84,
        loc: [SourceLocation],
        range: [Array],
        name: 'extend',
        _babelType: 'Identifier',
        parent: [Circular] },
     computed: false,
     _babelType: 'MemberExpression',
     parent: [Circular] },
  arguments:
   [ Node {
       type: 'ObjectExpression',
       start: 85,
       end: 108,
       loc: [SourceLocation],
       range: [Array],
       properties: [Array],
       extra: [Object],
       _babelType: 'ObjectExpression',
       parent: [Circular] } ],
  _babelType: 'CallExpression',
  parent:
   Node {
     type: 'ExportDefaultDeclaration',
     start: 52,
     end: 110,
     loc: SourceLocation { start: [Position], end: [Position] },
     range: [ 52, 110 ],
     declaration: [Circular],
     _babelType: 'ExportDefaultDeclaration',
     parent:
      Node {
        type: 'Program',
        start: 0,
        end: 111,
        loc: [SourceLocation],
        range: [Array],
        errors: [],
        comments: [],
        tokens: [Array],
        sourceType: 'module',
        directives: undefined,
        body: [Array],
        parent: null } } }
@BillyRayPreachersSon
Copy link
Author

Righty-ho, it turns out that there was an extra plugin in play that I had not spotted. Disabling that resolved the issue, so I suspect I can direct my search elsewhere.

Happy days 😄 !

@bmish
Copy link
Member

bmish commented Jul 20, 2021

FYI eslint-plugin-ember-suave is highly outdated, I would recommend removing that.

And you'll want to make sure you only have the latest version of eslint-plugin-ember (check your lockfile to ensure no old versions are present).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants