0

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?

cdmckay
  • 31,832
  • 25
  • 83
  • 114

2 Answers2

2

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.

GJK
  • 37,023
  • 8
  • 55
  • 74
  • I found that if I add a body to the `FooCtrl` function, then it passes the JSHint check... I just don't know why. – cdmckay Jun 18 '13 at 16:38
  • I don't use JSHint or JSLint, but I imagine that it has special rules for callback functions. Without a function body, JSHint probably doesn't recognize it as a callback function. – GJK Jun 18 '13 at 16:41
1

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.

zmo
  • 24,463
  • 4
  • 54
  • 90
  • I think this can be considered as a bug that you can report on jshint's github. – zmo Jun 18 '13 at 16:43