EmmanuelDemey/eslint-plugin-angular

timeout service fail on jasmine.getGlobal().setTimeout

yosiat opened this issue · 3 comments

Hi,

I have in my code jasmine.getGlobal().setTimeout = .. and I found out that the plugin crashes on this line -

Cannot read property 'type' of undefined
TypeError: Cannot read property 'type' of undefined
    at EventEmitter.MemberExpression (/Users/yosi/code/bringg-web/node_modules/eslint-plugin-angular/rules/timeout-service.js:38:38)
    at emitOne (events.js:101:20)
    at EventEmitter.emit (events.js:191:7)
    at NodeEventGenerator.applySelector (/Users/yosi/code/bringg-web/node_modules/eslint/lib/util/node-event-generator.js:265:26)
    at NodeEventGenerator.applySelectors (/Users/yosi/code/bringg-web/node_modules/eslint/lib/util/node-event-generator.js:294:22)
    at NodeEventGenerator.enterNode (/Users/yosi/code/bringg-web/node_modules/eslint/lib/util/node-event-generator.js:308:14)
    at CodePathAnalyzer.enterNode (/Users/yosi/code/bringg-web/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:602:23)
    at CommentEventGenerator.enterNode (/Users/yosi/code/bringg-web/node_modules/eslint/lib/util/comment-event-generator.js:98:23)
    at Traverser.enter (/Users/yosi/code/bringg-web/node_modules/eslint/lib/eslint.js:929:36)
    at Traverser.__execute (/Users/yosi/code/bringg-web/node_modules/estraverse/estraverse.js:397:31)

I am using version 1.6.3, and the failing line is -
https://github.com/Gillespie59/eslint-plugin-angular/blob/1.6.3/rules/timeout-service.js#L38

I can submit a fix that checks if there is parentNode.object before checking it's type.

Same thing when you try to create an Angular service that has a function named setTimeout as in:

angular
  .module('yourModule')
  .service('YourService', YourService);

function YourService() {
  var defaultTimeout = 15000;

  this.setTimeout = function (timeout) {
    defaultTimeout = timeout;
  };

  // ... rest of the service
}

Thanks for this issue. A fix has been pushed and will be available with the 2.4.1