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

di rule crashes on correct file #469

Open
LionC opened this issue Apr 11, 2017 · 1 comment
Open

di rule crashes on correct file #469

LionC opened this issue Apr 11, 2017 · 1 comment

Comments

@LionC
Copy link

LionC commented Apr 11, 2017

Configuring the di rule to array made eslint crash on me. The file is fine (and runs without problems), the error message looks like whatever it assumes to be an injection array is actually undefined. Setup:

Versions:

"eslint": "^3.19.0",
"eslint-config-angular": "^0.5.0",
"eslint-plugin-angular": "^2.2.1"

.eslintrc.json:

{
    "extends": "angular",

    "settings": {
        "angular": 1
    },

    "rules": {
        "angular/log": "warn",
        
        "angular/controller-as-vm": [ "error", "self" ],
        "angular/function-type": [ "error", "named" ],
        "angular/di": [ "error", "array" ],

        "angular/no-service-method": "off"
    }
}

the angular file:

angular.module('myapp')
    .provider('loadingInterceptor', [
        '$httpProvider',
        loadingInterceptorProvider
    ])

function loadingInterceptorProvider($httpProvider) {
    var self = this

    $httpProvider.interceptors.push('loadingInterceptor')

    self.$get = [
        'Loading',
        $get
    ]

    function $get(Loading) {
        function startLoading(config) {
            Loading.startLoading()

            return config
        }

        function stopLoading(response) {
            Loading.stopLoading()

            return response
        }

        return {
            request: startLoading,
            requestError: stopLoading,
            response: stopLoading,
            responseError: stopLoading
        }
    }

}

error:

$ ./node_modules/.bin/eslint -c ./.eslintrc.json ./scripts/components/loading/loading.interceptor.js

The rule `angular/service-name` will be split up to different rules in the next version. Please read the docs for more information
Cannot read property 'length' of undefined
TypeError: Cannot read property 'length' of undefined
    at checkDi (/Users/LionC/Projects/acomodeo/onboarding-webapp/node_modules/eslint-plugin-angular/rules/di.js:63:68)
    at Object.angular?provider (/Users/LionC/Projects/acomodeo/onboarding-webapp/node_modules/eslint-plugin-angular/rules/di.js:131:17)
    at /Users/LionC/Projects/acomodeo/onboarding-webapp/node_modules/eslint-plugin-angular/rules/utils/angular-rule.js:234:16
    at Array.forEach (native)
    at callAngularRules (/Users/LionC/Projects/acomodeo/onboarding-webapp/node_modules/eslint-plugin-angular/rules/utils/angular-rule.js:228:27)
    at EventEmitter.callBoth (/Users/LionC/Projects/acomodeo/onboarding-webapp/node_modules/eslint-plugin-angular/rules/utils/angular-rule.js:86:13)
    at emitOne (events.js:101:20)
    at EventEmitter.emit (events.js:188:7)
    at NodeEventGenerator.applySelector (/Users/LionC/Projects/acomodeo/onboarding-webapp/node_modules/eslint/lib/util/node-event-generator.js:265:26)
    at NodeEventGenerator.applySelectors (/Users/LionC/Projects/acomodeo/onboarding-webapp/node_modules/eslint/lib/util/node-event-generator.js:294:22)
@EmmanuelDemey
Copy link
Owner

Can you send a PR with unit test ?

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

No branches or pull requests

2 participants