eslint-plugin-ember icon indicating copy to clipboard operation
eslint-plugin-ember copied to clipboard

Error While Linting - new-module-imports

Open Alonski opened this issue 8 years ago • 7 comments

Hey friends, I just updated to "^5.0.1" from "^4.6.1"

When linting I now get this error (causes Ember Build to also fail):

$ eslint app
Cannot read property 'forEach' of undefined
TypeError: Cannot read property 'forEach' of undefined
    at VariableDeclarator (D:\Projects\myApp\node_modules\eslint-plugin-ember\lib\rules\new-module-imports.js:27:27)
    at listeners.(anonymous function).forEach.listener (D:\Projects\myApp\node_modules\eslint\lib\util\safe-emitter.js:47:58)
    at Array.forEach (native)
    at Object.emit (D:\Projects\myApp\node_modules\eslint\lib\util\safe-emitter.js:47:38)
    at NodeEventGenerator.applySelector (D:\Projects\myApp\node_modules\eslint\lib\util\node-event-generator.js:251:26)
    at NodeEventGenerator.applySelectors (D:\Projects\myApp\node_modules\eslint\lib\util\node-event-generator.js:280:22)
    at NodeEventGenerator.enterNode (D:\Projects\myApp\node_modules\eslint\lib\util\node-event-generator.js:294:14)
    at CodePathAnalyzer.enterNode (D:\Projects\myApp\node_modules\eslint\lib\code-path-analysis\code-path-analyzer.js:608:23)
    at Traverser.enter (D:\Projects\myApp\node_modules\eslint\lib\linter.js:956:32)
    at Traverser.__execute (D:\Projects\myApp\node_modules\estraverse\estraverse.js:397:31)
    at Traverser.traverse (D:\Projects\myApp\node_modules\estraverse\estraverse.js:501:28)

Seems to fail here:

const properties = node.id.properties;
        // Iterate through the destructured properties and report them
        properties.forEach((item) => {

properties is undefined

When I set the rule to Off in eslintrc I get another error with require-super-in-init

"eslint": "v4.2.0"
"ember-cli": "2.12.2",
"ember-cli-eslint": "^4.2.2",

Alonski avatar Nov 26 '17 09:11 Alonski

It seems the issue was with this:

    init: Ember.on("init", function() {
        setInterval(function() {
            if (Ember.$(window).width() < 1040) {
                Ember.$(".listings-management").css("width", Ember.$(window).width());
            } else {
                Ember.$(".listings-management").css("width", "100%");
            }
        }, 1000);
    }),

Changing this fixed the issue:

    init() {
        this._super(...arguments);
        setInterval(function() {
            if (Ember.$(window).width() < 1040) {
                Ember.$(".listings-management").css("width", Ember.$(window).width());
            } else {
                Ember.$(".listings-management").css("width", "100%");
            }
        }, 1000);
    },

I ended up debugging the Node instance running ESLint app and figured this out.

Thanks

Alonski avatar Feb 22 '18 10:02 Alonski

I'm getting Cannot read property 'forEach' of undefined as well now.

RobbieTheWagner avatar Nov 18 '18 15:11 RobbieTheWagner

@rwwagner90 Any idea what code is causing the error?

Alonski avatar Nov 18 '18 16:11 Alonski

@rwwagner90 can you share the full stack trace and possibly an example snippet that reproduces the issue?

Turbo87 avatar Nov 19 '18 08:11 Turbo87

I think it was potentially caused by not ignoring the concat-stats-for directory. I'm not seeing the issue anymore. If it comes back, I will let you know.

RobbieTheWagner avatar Nov 19 '18 13:11 RobbieTheWagner

Thanks @rwwagner90 for the direction... I ran into the same issue with an addon with no .eslintignore file. Re-generating the file with ember init command fixed the issue. Indeed, eslint was running inside the dist directory (with ie9-transpiled files inside)...

To reproduce the issue (though I have to say it's not really standard):

  • ember addon new-addon
  • in .eslintignore remove the line about dist
  • add ie9 to targets `config/targets.js
  • `ember install ember-cli-babel' (to get the ember-cli-babel@7)
  • `ember install ember-cli-flash' (<- seems the issue was with this transpiled file: https://github.com/poteto/ember-cli-flash/blob/master/app/initializers/flash-messages.js)
  • yarn build
  • yarn lint:js

dcyriller avatar Dec 31 '18 16:12 dcyriller

In case it is helpful to others... I was seeing this same error and stack trace but it was because I needed to add /electron-out/ to .eslintignore

chbonser avatar Jul 02 '20 13:07 chbonser