简体   繁体   中英

JSHint chaining method calls

I have the following code in an Angular app:

'use strict';

angular.module('fooApp')
    .controller('FooCtrl', function ($scope) {

    });

When I run JSHint (with indent set to 4) on this code, I get the following error:

[L6:C5] W015: Expected '}' to have an indentation at 1 instead at 5.
    });

How do I get JSHint to allow me to keep my chaining indentation?

Update

I found that if I add a body to the FooCtrl function like this:

'use strict';

angular.module('fooApp')
    .controller('FooCtrl', function ($scope) {
        $scope.foo = {};
    });

Then it does pass JSHint. Anyone know why?

I don't believe there is a way to do it. The whitespace checking in JSHint is fairly static, you get on or off, no configuration. There's an open bounty to add some configuration, but nothing seems to be in the works (at least for your situation).

https://github.com/jshint/jshint/issues/28

You'll either have to just ignore it or turn off the whitespace check.

simply said: you don't. Either you remove all indentation checking from your config file, or you match the crockford's recommandation. There's an open bug about giving more flexible rules, but it has to be implemented.

Having submitted code to JSHint, it would not be hard to implement a more flexible way to check whitespaces. Except that there are a lot of cases where it has to be checked... The main problem is to find an intelligent way to fine tune your indentation preferences.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM