javascript - 如何抑制错误 : Illegal space before opening round brace at from jsrc?

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

我这里需要的是:

My Editor webstorm 自动为对齐应用空间,如下所述:

function (localStorageServiceProvider) // with space

但是,它应该是:

function(localStorageServiceProvider) // without space

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

最佳答案

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

首选项->编辑器->代码风格->Javascript->Spaces->括号前->函数表达式中

enter image description here

关于javascript - 如何抑制错误 : Illegal space before opening round brace at from jsrc?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35766128/

相关文章:

javascript - jQuery ajax() 函数忽略 Firefox 中的 dataType 参数

javascript - ng-repeat 总是在指令模板中最后呈现

javascript - 我如何在 AngularJS 应用程序中使用 grunt-uncss?

angularjs - angular - 监听嵌入的变化

asp.net-mvc - 在 Nuget MVC 站点上使用 NPM/Bower 进行捆绑

javascript - this.moveImage 不是一个函数

javascript - 通过Id获取多个元素

node.js - 处理 gulp 代码中的 Promise 拒绝

azure - Azure DevOps 管道构建工件中缺少 Gulp 编译的 CSS 文件夹

javascript - 将 html 添加到文本区域时如何切换添加/删除?