3

In our angularjs project, after up-gradation of gulp3 to 4 and when i run : gulp lint

C:\filepath>gulp lint
[12:59:30] Using gulpfile ~\filepath\gulpfile.js
[12:59:30] Starting 'lint'...
app\js\app.config.js: line 4, col 1, Use the function form of "use strict".

1 error
Illegal space before opening round brace at C:\filepath\app\js\app.config.js :
     7 |angular
     8 |    .module('test')
     9 |    .config(['localStorageServiceProvider', function (localStorageServiceProvider) {
C:\filepath>gulp lint
[12:59:30] Using gulpfile ~\filepath\gulpfile.js
[12:59:30] Starting 'lint'...
app\js\app.config.js: line 4, col 1, Use the function form of "use strict".

1 error
Illegal space before opening round brace at C:\filepath\app\js\app.config.js :
     7 |angular
     8 |    .module('test')
     9 |    .config(['localStorageServiceProvider', function (localStorageServiceProvider) {

I am not able to figure out, everything was working fine earlier. Only after the gulp upgradation to latest one, build is failing. Can anybody please assist me with this.

I also followed this link : How can I suppress the JSHint "JSCS: Illegal Space" warnings in Visual Studio 2013?.

According to the link above, i tried adding below lines inside .jshintrc file:

"requireSpacesInAnonymousFunctionExpression": {
    "beforeOpeningCurlyBrace": false
},
"disallowSpacesInNamedFunctionExpression": {
    "beforeOpeningRoundBrace": false
},
"disallowSpacesInFunctionDeclaration": {
    "beforeOpeningRoundBrace": false
}

Its throwing more error following the previous:

6 code style errors found.
app\js\app.module.js: line 0, col 0, Bad option: 'requireSpacesInAnonymousFunctionExpression'.
app\js\app.module.js: line 0, col 0, Bad option: 'disallowSpacesInNamedFunctionExpression'.
app\js\app.module.js: line 0, col 0, Bad option: 'disallowSpacesInFunctionDeclaration'.
app\js\app.module.js: line 4, col 1, Use the function form of "use strict".

What i require here is:

My Editor webstorm automatically applying space for alignments as mentioned below:

function (localStorageServiceProvider) // with space

But, it should be:

function(localStorageServiceProvider) // without space

What is the exact rule i need to apply in .jshintrc file or any other places which fixes...?

Community
  • 1
  • 1
Mithun Shreevatsa
  • 3,588
  • 9
  • 50
  • 95

3 Answers3

2

If you would prefer, you can configure Webstorm not to insert the spaces. I don't have Webstorm here, but in IntelliJ IDEA (same underlying IDE) the option is under

Preferences->Editor->Code Style->Javascript->Spaces->Before Parentheses->In function expression

enter image description here

CupawnTae
  • 14,192
  • 3
  • 29
  • 60
  • Thank you so much for your response @CupawnTae. But there are so many files, we did not face such kind of issue till date. More than 100 people working in our project and i cant say them to change the settings in webstorm which sounds ackward now. And i am also facing error as: `Line must be at most 120 characters at C:\filepath\somanyfiles.js`. Any help w.r.to jshint global suppression will be much appreciated and thank u once again – Mithun Shreevatsa Mar 03 '16 at 09:21
0

The lint rules you need to configure are:

"requireSpacesInAnonymousFunctionExpression": {
    "beforeOpeningRoundBrace": true,
    "beforeOpeningCurlyBrace": true
}

and

"requireSpacesInFunctionExpression": {
    "beforeOpeningRoundBrace": true,
    "beforeOpeningCurlyBrace": true
}
Bruno Garcia
  • 6,029
  • 3
  • 25
  • 38
  • Error: `2 errors filepath\file.js: line 0, col 0, Bad option: 'requireSpacesInAnonymousFunctionExpression'. filepath\file.js: line 0, col 0, Bad option: 'requireSpacesInFunctionExpression'. ` – Mithun Shreevatsa Mar 03 '16 at 09:25
  • You have to load these rules.You can find the rules here: https://github.com/jscs-dev/node-jscs/tree/master/lib/rules – Bruno Garcia Mar 06 '16 at 11:28
-2

I resolved this adding : "excludeFiles": ["**/*"] in .jscrc file. Final version of .jscrc file looks like :

{
  "preset": "google",
  "fileExtensions": [ ".js" ],

  "maximumLineLength": 120,
  "validateIndentation": 4,

  "disallowSpacesInAnonymousFunctionExpression": null,

  "excludeFiles": ["**/*"]
}
Mithun Shreevatsa
  • 3,588
  • 9
  • 50
  • 95