在我们的 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
->括号前
->函数表达式中
关于javascript - 如何抑制错误 : Illegal space before opening round brace at from jsrc?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35766128/