Grunt found 51 problems in javascript file - Warning: Task "jshint:all" failed.

I am using webstorm 7.0.3. I have added a 3rd party javascript file to the project folder.

Then I was running Grunt and get these errors:

Running "jshint:all" (jshint) task

app/scripts/vendor/linq.js
  line 12  col 5   Missing "use strict" statement.
  line 15  col 9   Expected '}' to have an indentation at 11 instead at 9.
  line 18  col 9   Expected '}' to have an indentation at 11 instead at 9.
  line 21  col 5   Expected '}' to have an indentation at 7 instead at 5.
  line 27  col 26  Strings must use singlequote.
  line 32  col 5   Expected '}' to have an indentation at 7 instead at 5.
  line 35  col 25  Strings must use singlequote.
  line 41  col 28  Expected '===' and instead saw '=='.
  line 41  col 37  Expected '{' and instead saw 'return'.
  line 44  col 17  Expected 'var' to have an indentation at 15 instead at 17.
  line 45  col 17  Expected 'if' to have an indentation at 15 instead at 17.
  line 45  col 23  Expected '!==' and instead saw '!='.
  line 46  col 21  Expected 'return' to have an indentation at 17 instead at 21.
  line 47  col 17  Expected '}' to have an indentation at 15 instead at 17.
  line 49  col 17  Expected 'if' to have an indentation at 15 instead at 17.
  line 49  col 44  Strings must use singlequote.
  line 50  col 21  Expected 'var' to have an indentation at 17 instead at 21.
  line 50  col 51  Strings must use singlequote.
  line 50  col 56  Strings must use singlequote.
  line 52  col 21  Expected 'var' to have an indentation at 17 instead at 21.
  line 53  col 21  Expected 'var' to have an indentation at 17 instead at 21.
  line 54  col 21  Expected 'while' to have an indentation at 17 instead at 21.
  line 54  col 62  Expected '!==' and instead saw '!='.
  line 55  col 25  Expected 'var' to have an indentation at 19 instead at 25.
  line 56  col 25  Expected 'if' to have an indentation at 19 instead at 25.
  line 57  col 29  Expected 'maxLength' to have an indentation at 21 instead at 29.
  line 58  col 25  Expected '}' to have an indentation at 19 instead at 25.
  line 59  col 21  Expected '}' to have an indentation at 17 instead at 21.
  line 61  col 21  Expected 'var' to have an indentation at 17 instead at 21.
  line 62  col 21  Expected 'for' to have an indentation at 17 instead at 21.
  line 63  col 25  Expected 'var' to have an indentation at 19 instead at 25.
  line 63  col 40  Strings must use singlequote.
  line 64  col 25  Expected 'for' to have an indentation at 19 instead at 25.
  line 65  col 29  Expected 'dollar' to have an indentation at 21 instead at 29.
  line 65  col 42  Strings must use singlequote.
  line 66  col 25  Expected '}' to have an indentation at 19 instead at 25.
  line 67  col 25  Expected 'argArray' to have an indentation at 19 instead at 25.
  line 68  col 21  Expected '}' to have an indentation at 17 instead at 21.
  line 70  col 21  Expected 'var' to have an indentation at 17 instead at 21.
  line 70  col 71  Strings must use singlequote.
  line 72  col 21  Expected 'f' to have an indentation at 17 instead at 21.
  line 72  col 37  The Function constructor is a form of eval.
  line 72  col 53  Strings must use singlequote.
  line 73  col 21  Expected 'funcCache' to have an indentation at 17 instead at 21.
  line 74  col 21  Expected 'return' to have an indentation at 17 instead at 21.
  line 75  col 17  Expected '}' to have an indentation at 15 instead at 17.
  line 77  col 21  Expected 'var' to have an indentation at 17 instead at 21.
  line 78  col 21  Expected 'f' to have an indentation at 17 instead at 21.
  line 78  col 37  The Function constructor is a form of eval.
  line 78  col 56  Strings must use singlequote.
  line 78  col 56  Too many errors. (2% scanned).

51 problems

Warning: Task "jshint:all" failed. Use --force to continue.

Aborted due to warnings.

-------------------------------------

My .jshintrc file contains this:

{
  "node": true,
  "browser": true,
  "esnext": true,
  "bitwise": true,
  "camelcase": 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
  }
}


You see the indent is set to 2 and in my WebStorm IDE I have under the JSLint setting an indentation of 4.

Now I do not really care about the WebSorm vs Grunt conflict and who is using what.

What I really care about is when ANY 3rd party library which I add to the project will break Grunt.

I can not change any external javascript file`s syntax just to please the code settings of WebStorm/Grunt.

How I am supposed to behave in such a situation?
16 comments
Comment actions Permalink

Hmm... Grunt doesn't care about WebStorm settings - it uses the .jshintrc file you pass to it. I'm not sure why your settings there differ from the ones you set in WebStorm - is there any reason for this?
What does you task look like? Are you using grunt-contrib-jshin? And, if you can't change the code of third-party files, why not excluding them from JSHint validation?

0
Comment actions Permalink

"if you can't change the code of third-party files, why not excluding them from JSHint validation?"

How can I exclude a file from JSHint?

0
Comment actions Permalink

No it did not help:

I tried this:

'<!%= yeoman.app %>/scripts/vendor/*.js'

and this:

        '!app/scripts/vendor/linq.js',


When I redid the Grunt in the terminal I still get the 51 errors so my above entry does actually not work at all...

see below:

  jshint: {       options: {         jshintrc: '.jshintrc',         reporter: require('jshint-stylish')       },       all: [         'Gruntfile.js',         '!<%= yeoman.app %>/scripts/vendor/*.js',         '<%= yeoman.app %>/scripts/{,*/}*.js'       ],       test: {         options: {           jshintrc: 'test/.jshintrc'         },         src: ['test/spec/{,*/}*.js']       }     },

0
Comment actions Permalink

Against the opinion of the SO thread you showed me I tried the ignores option to exclude a whole directory (should work only for a specific file...):

   jshint: {
      options: {
        ignores: ['app/scripts/vendor/{,*/}*.js']
      },


That worked!

0
Comment actions Permalink

But still my other created javascript files fail with grunt because of the wrong indentation etc... why does a new created file not use the format settings which grunt is expecting/testing?

These are my jshint settings which point to the .jshintrc file but still grunt is bothering about the indentation 9 which is expected at 11. That means 2 too much and my .jshintrc has indent 2 but my jsLINT has an indent setting of 4 but the whole jsLint is not activated so I have no idea why indentation 9 is expected at 11 !!!

You guys understand me?

jshint_settings.PNG

0
Comment actions Permalink

>why does a new created file not use the format settings which grunt is expecting/testing?

May be because you haven't set up the jacascript code style (Settings/Code Style/JavaScript) accordingly? The IDE doesn't take the formatting options from the JSHint config, it's only used for code validation, not for code generation/formatting

>These are my jshint settings which point to the .jshintrc file but still  grunt is bothering about the indentation 9 which is expected at 11

Not sure I follow you. Do you have JSHint errors shown for your code in WebStorm editor? Is the .jshintrc file in screenshot the only .jshintrc file in your project? Do you pass it to Grunt?

>You guys understand me?

No:(
Seems I need your project (Gruntfile.js, .jshintrc file, source file errors are reported against)

0
Comment actions Permalink

I have attached the project for you thats probably the easiest way to help.

The bower_components + node_modules are not in the project but the bower.json and package.json. So I guess you should be able to download those components :)

I much appreciate your help and even think about buying webStorm 8 with features I also wanted. Do you work for jetbrains?



Attachment(s):
client.7z.zip
0
Comment actions Permalink

Thanks!
How do you run Grunt? What file the problems are reported for? I can't see any problems:

"C:\JetBrains\WebStorm Trunk\bin\runnerw.exe" "C:\Program Files\nodejs\node.exe" C:\Users\Elena.Pogorelova\AppData\Roaming\npm\node_modules\grunt-cli\bin\grunt

Running "newer:jshint" (newer) task

Running "newer:jshint:all" (newer) task

Running "jshint:all" (jshint) task

No problems


Running "newer-timestamp:jshint:all:C:\downloads\client\client\client\node_modules\grunt-newer\.cache" (newer-timestamp) task

Running "newer-reconfigure:jshint:all:1" (newer-reconfigure) task

Running "newer:jshint:test" (newer) task

Running "jshint:test" (jshint) task

No problems


Running "newer-timestamp:jshint:test:C:\downloads\client\client\client\node_modules\grunt-newer\.cache" (newer-timestamp) task

Running "clean:server" (clean) task

Running "concurrent:test" (concurrent) task
    
Running "compass:dist" (compass) task
directory .tmp/styles/
       create .tmp/styles/main.css (2.581s)
    Compilation took 2.595s
    
Running "compass:server" (compass) task
unchanged app/styles/main.scss
    Compilation took 0.19s
    
Done, without errors.

...

Full log attached for your reference (too long to paste it here)



Attachment(s):
grunt_out.txt.zip
0
Comment actions Permalink

weird... normally I get errors about wrong indentation in the lessonPlannerFactory.js
file when grunt is run around the jshint stuff. I have changed some things yesterday...I will have to check again when I am at home. :)

0
Comment actions Permalink

I just tested it again by opening the project and run "grunt" in the terminal then I get this:

The lessonPlannerFactory.js file is RED on the left solution explorer window. This is not normal. Do you maybe need my webstorm settings ? I have exported those and attached to this post!

gruntfails.PNG



Attachment(s):
settings.jar
0
Comment actions Permalink

Ok I have now run my unit tests again also one for the lessonPlannerFactory and and saw that one defined function in the app\...\lessonPlannerFactory.js has had not "()" which I should use for a function...
Now I run the unit tests again and at least they are fine.

Now I did Grunt again and due to the former fix I could reduce the errors to 4 from 12:

Only 3 identation errors and 1 unused variable error are left due to the lessonPlannerFactory.js

Now I edited the .jshitnrc file at the root unter client\ and set "unused" to true to see wether the one error disappears.

Did Grunt again and yes 3 errors are left.

Now I edited jshintrc again and set indent from 2 to 4.

Did Grunt again.

NOw comes the best I got 60 errors suddenly in app.js, main.js etc.. AND the gruntjs file ??? Why this suddenly that file is actually excluded...

Now I edited jshintrc again and set "unused" to true and now I have 4 errors again
Now I edited jshintrc again and set "unused" to false and now I have 3 errors again.

What the heck was this 60 errors happening???

Instead of getting 60 errors again when I set the indent from 2 to 4 again because thats my error:

---------------------------------------------------------
app/scripts/services/lessonplannerfactory.js
  line 10  col 9  Expected '}' to have an indentation at 11 instead at 9.
  line 30  col 9  Expected '}' to have an indentation at 11 instead at 9.
  line 31  col 5  Expected '}' to have an indentation at 7 instead at 5.

3 problems
Warning: Task "jshint:all" failed. Use --force to continue.
Aborted due to warnings.
------------------------------------------------------------

I fix the indentation bug manually in the lessonPlannerFactory file and then Do Grunt again =>

Now the errors in the lessonPlannerFactory.js are gone and its name is not RED anymore in the solution explorer.

NOW comes the big BUT... All my indetations are messed up due to my manual changes that means why does jshint/grunt complain about indentations which look silly when used in a correct way?

See the screenshot: Look at the vertical lines they are not aligned with the curl braces... pffhhhhh

TotalMessedIndentationLines.PNG

When I create new files with "YO angular:service lessonPlannerService" then this file has code which does not aline with my settings.

- So what I did is set the indent property in both .jshintrc (app and test)  files to 4 instead of 2.
- Then I click into both files and to ALT+F8 to reformat the code.
So just the YO generators are giving me a bad output... Do you know wether I can tell yo to use my jshintrc settings?

0
Comment actions Permalink

>normally I get errors about wrong indentation in the lessonPlannerFactory.js

You forgot to include the lessonPlannerFactory.js in the zip you have provided to me:) So it's not surprising that I don't see any errors:)

0
Comment actions Permalink

Now I edited jshintrc again and set indent from 2 to 4.
Did Grunt again.
NOw comes the best I got 60 errors suddenly in app.js, main.js etc..


Your files are formatted with indentation=2; so they violate JSHint rules, as you have set the indentation to 4 there. No surprise:)

AND the gruntjs file ??? Why this suddenly that file is actually excluded...


Is it? :) It is included, as far as I can see:

all: [
        'Gruntfile.js',
        '<%= yeoman.app %>/scripts/{,*/}*.js'
      ],

with such settings running  grunt jshint:all will lint the project's Gruntfile as well as JavaScript files in the <%= yeoman.app %>/scripts folder


All my indetations are messed up due to my manual changes that means why does jshint/grunt complain about indentations which look silly when used in a correct way?



Well, as you didn't provide the file to me, I'm not sure what problems JSHint is complaining aboiut exactly. Can you attach it? I'd check if JSHint can be configured to accept your indentation style then


So just the YO generators are giving me a bad output... Do you know wether I can tell yo to use my jshintrc settings?



I'm not aware of any way to do this
0
Comment actions Permalink

You are right the Gruntjs is included in the linting. :)

Everything is fine now.

Btw. Do you know why my my main.js file and the mainnavigationController.js file has different colors? That looks wrong to me.

wrongcolors.PNG

0
Comment actions Permalink

Because they have different VCS statuses. Seems the main.js is 'modified', and mainnavigationController.js- 'unknown'

0

Please sign in to leave a comment.