如何压制错误:从jsrc打开圆括号前的非法空间?

时间:2016-03-03 07:49:38

标签: javascript angularjs gulp jshint lint

在我们的angularjs项目中,将gulp3升级为4并运行后: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) {

我无法弄清楚,一切都工作得很好。只有在gulp升级到最新版本之后,构建才会失败。任何人都可以帮助我。

我也点了这个链接:How can I suppress the JSHint "JSCS: Illegal Space" warnings in Visual Studio 2013?

根据上面的链接,我尝试在.jshintrc文件中添加以下行:

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

它在前一次抛出更多错误:

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".

我需要的是:

我的编辑器webstorm自动为对齐应用空间,如下所述:

function (localStorageServiceProvider) // with space

但是,它应该是:

function(localStorageServiceProvider) // without space

我需要在.jshintrc文件或任何其他修复的地方申请的确切规则是什么?

3 个答案:

答案 0 :(得分:2)

如果您愿意,可以将Webstorm配置为不插入空格。我这里没有Webstorm,但是在IntelliJ IDEA(相同的底层IDE)中,该选项位于

之下

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

enter image description here

答案 1 :(得分:0)

您需要配置的lint规则是:

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

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

答案 2 :(得分:-1)

我在"excludeFiles": ["**/*"]文件中解决了这个问题:.jscrc.jscrc文件的最终版本如下:

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

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

  "disallowSpacesInAnonymousFunctionExpression": null,

  "excludeFiles": ["**/*"]
}