Search code examples
gruntjsjshintgrunt-jsbeautifier

jshint conflicting with jsbeautifier and complaining about indentation of square bracket in array


I have a jsbeautifer followed by a jshint task in my Gruntfile, but they seem to have different ideas about where my closing braces should be.

I agree with what jsbeautifer produces, but jshint complains. Here is a sample file I have and the error message below:

    0   $scope.awesomeThings = [                                                                       
    1       'HTML5 Boilerplate',                                                                       
    2       'AngularJS',                                                                               
    3       'Karma'                                                                                    
>>  4   ];         


Expected ']' to have an indentation at 5 instead at 3.

This is my .jshintc file:

{
  "node": true,
  "browser": true,
  "es5": true,
  "esnext": true,
  "bitwise": true,
  "curly": true,
  "eqeqeq": true,
  "immed": true,
  "indent": 2,
  "latedef": true,
  "newcap": true,
  "noarg": true,
  "quotmark": "single",
  "regexp": true,
  "undef": true,
  "unused": true,
  "strict": true,
  "trailing": true,
  "smarttabs": true,
  "globals": {
    "angular": false
  }
}

Solution

  • your jsbeautifier seems to indent 4 spaces, your jshintrc-file is set to check indentation for 2 spaces. just set it there to 4 spaces if you think 4 spaces is what you want:

    "indent": 4,
    

    edit:

    if you use this grunt-beautifier-plugin there is an option called keep_array_indentation which by default is set default. i would expect that to fix your problem.