How to supress the error : Illegal space before opening round brace at from jsrc?

How to supress the error : Illegal space before opening round brace at from jsrc?

在我们的 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 升级到最新版本后,构建才会失败。谁能帮我解决这个问题。

我也关注了这个 link : .

根据上面的 link,我尝试在 .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".

我这里要求的是:

My Editor webstorm 自动应用 space 进行对齐,如下所述:

function (localStorageServiceProvider) // with space

但是,应该是:

function(localStorageServiceProvider) // without space

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

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

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

您需要配置的 lint 规则是:

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

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

我解决了这个添加:"excludeFiles": ["**/*"].jscrc 文件中。 .jscrc 文件的最终版本如下所示:

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

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

  "disallowSpacesInAnonymousFunctionExpression": null,

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