2017-04-03 118 views
0

我試圖使用gulp build創建我的角度項目的分發版本,但是,當我運行該命令時,它失敗,出現146錯誤,其中許多似乎嚴格執行風格。強制吞噬生成?

有沒有辦法強制吞嚥忽略這些linting錯誤並強制創建dist版本?我正在使用gulp-cli 1.2.2

該應用程序使用yeoman腳手架。這是我的package.json和我的gulpfile.js

最後,運行gulp build後的輸出:

[21:56:28] Requiring external module babel-register 
[21:56:29] Using gulpfile ~/code/proverbial/client/gulpfile.babel.js 
[21:56:29] Starting 'lint'... 
[21:56:29] Starting 'styles'... 
[21:56:29] Starting 'scripts'... 
[21:56:29] Starting 'images'... 
[21:56:29] Starting 'fonts'... 
[21:56:29] Starting 'extras'... 
(node:12187) DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead. 
[21:56:30] Finished 'images' after 239 ms 
[21:56:31] Finished 'extras' after 1.01 s 
[21:56:31] Finished 'styles' after 1.51 s 
[21:56:31] Finished 'fonts' after 1.24 s 
[21:56:31] 
/home/james/code/proverbial/client/app/scripts/app.js 
    4:4 error "angular" is not defined      no-undef 
    19:35 error Unexpected trailing comma      comma-dangle 
    31:1 error Newline required at end of file but not found eol-last 

/home/james/code/proverbial/client/app/scripts/polyfills.js 
    1:0 error String prototype is read only, properties should not be added no-extend-native 
    1:28 error Missing "use strict" statement         strict 
    4:1 error Expected { after 'if' condition        curly 
    11:1 error Newline required at end of file but not found     eol-last 
    11:1 error Missing semicolon            semi 

/home/james/code/proverbial/client/app/scripts/routes.js 
    4:4 error "angular" is not defined      no-undef 
    52:22 error Missing semicolon        semi 
    54:1 error Newline required at end of file but not found eol-last 

/home/james/code/proverbial/client/app/scripts/shared/data.factory.js 
    4:4 error "angular" is not defined      no-undef 
    6:32 error Service was used before it was defined   no-use-before-define 
    8:4 error Service was used before it was defined   no-use-before-define 
    14:21 error getData was used before it was defined   no-use-before-define 
    14:28 error Unexpected trailing comma      comma-dangle 
    24:46 error Missing semicolon        semi 
    26:29 error Missing semicolon        semi 
    41:1 error Newline required at end of file but not found eol-last 

/home/james/code/proverbial/client/app/scripts/shared/firstLetter.filter.js 
    4:4 error "angular" is not defined      no-undef 
    6:31 error There should be no space before ','   comma-spacing 
    6:33 error Filter was used before it was defined   no-use-before-define 
    10:41 error Missing semicolon        semi 
    20:9 error Missing semicolon        semi 
    22:1 error Newline required at end of file but not found eol-last 

/home/james/code/proverbial/client/app/scripts/shared/interceptor.factory.js 
    4:4 error "angular" is not defined       no-undef 
    6:36 error factory was used before it was defined   no-use-before-define 
    8:4 error factory was used before it was defined   no-use-before-define 
    13:21 error request was used before it was defined   no-use-before-define 
    14:26 error requestError was used before it was defined  no-use-before-define 
    15:22 error response was used before it was defined   no-use-before-define 
    16:27 error responseError was used before it was defined  no-use-before-define 
    31:34 error Missing semicolon        semi 
    35:26 error response is already declared in the upper scope no-shadow 
    41:34 error Missing semicolon        semi 
    45:1 error Newline required at end of file but not found eol-last 

/home/james/code/proverbial/client/app/scripts/shared/lang.service.js 
    4:4 error "angular" is not defined      no-undef 
    6:30 error Service was used before it was defined   no-use-before-define 
    8:4 error Service was used before it was defined   no-use-before-define 
    13:8 error "angular" is not defined      no-undef 
    13:60 error key is defined but never used     no-unused-vars 
    20:21 error getLang was used before it was defined   no-use-before-define 
    21:21 error setLang was used before it was defined   no-use-before-define 
    28:9 error Unnecessary semicolon       no-extra-semi 
    28:9 error Found unexpected statement after a return  no-unreachable 
    34:16 error "angular" is not defined      no-undef 
    34:68 error key is defined but never used     no-unused-vars 
    40:9 error Unnecessary semicolon       no-extra-semi 
    40:9 error Found unexpected statement after a return  no-unreachable 
    42:1 error Newline required at end of file but not found eol-last 

/home/james/code/proverbial/client/app/scripts/shared/maxLength.filter.js 
    4:4 error "angular" is not defined      no-undef 
    6:29 error There should be no space before ','   comma-spacing 
    6:31 error Filter was used before it was defined   no-use-before-define 
    10:12 error Expected { after 'if' condition    curly 
    13:12 error Expected { after 'if' condition    curly 
    13:31 error "value" is not defined       no-undef 
    14:12 error Expected { after 'if' condition    curly 
    20:42 error Infix operators must be spaced     space-infix-ops 
    20:79 error Infix operators must be spaced     space-infix-ops 
    27:9 error Missing semicolon        semi 
    29:1 error Newline required at end of file but not found eol-last 

/home/james/code/proverbial/client/app/scripts/shared/onKey.directive.js 
    4:4 error "angular" is not defined      no-undef 
    6:28 error Directive was used before it was defined  no-use-before-define 
    8:4 error Directive was used before it was defined  no-use-before-define 
    10:23 error $timeout is defined but never used    no-unused-vars 
    12:18 error link was used before it was defined   no-use-before-define 
    19:25 error Strings must use singlequote     quotes 
    26:20 error Unexpected alert        no-alert 
    26:28 error Missing semicolon        semi 
    31:1 error Newline required at end of file but not found eol-last 

/home/james/code/proverbial/client/app/scripts/shared/onScroll.directive.js 
    4:4 error "angular" is not defined      no-undef 
    6:39 error Directive was used before it was defined  no-use-before-define 
    8:4 error Directive was used before it was defined  no-use-before-define 
    12:18 error link was used before it was defined   no-use-before-define 
    16:8 error Trailing spaces not allowed     no-trailing-spaces 
    19:39 error Missing semicolon        semi 
    27:1 error Newline required at end of file but not found eol-last 

/home/james/code/proverbial/client/app/scripts/shared/proverbs.service.js 
    4:4 error "angular" is not defined      no-undef 
    6:36 error Service was used before it was defined   no-use-before-define 
    8:4 error Service was used before it was defined   no-use-before-define 
    10:42 error CONFIG is defined but never used    no-unused-vars 
    14:25 error getProverbs was used before it was defined  no-use-before-define 
    14:36 error Unexpected trailing comma      comma-dangle 
    19:30 error options is defined but never used    no-unused-vars 
    23:42 error Missing semicolon        semi 
    27:1 error Newline required at end of file but not found eol-last 

/home/james/code/proverbial/client/app/scripts/shared/randomBackgroundColor.directive.js 
    4:4 error "angular" is not defined      no-undef 
    6:44 error Directive was used before it was defined  no-use-before-define 
    8:4 error Directive was used before it was defined  no-use-before-define 
    10:23 error $timeout is defined but never used    no-unused-vars 
    12:18 error link was used before it was defined   no-use-before-define 
    27:24 error Strings must use singlequote     quotes 
    27:37 error Strings must use singlequote     quotes 
    27:47 error Strings must use singlequote     quotes 
    27:57 error Strings must use singlequote     quotes 
    33:1 error Newline required at end of file but not found eol-last 

/home/james/code/proverbial/client/app/scripts/components/navbar/navbar.directive.js 
    4:4 error "angular" is not defined       no-undef 
    6:29 error Directive was used before it was defined   no-use-before-define 
    8:4 error Directive was used before it was defined   no-use-before-define 
    8:50 error A space is required after ','      comma-spacing 
    12:24 error Missing space before value for key "templateUrl" key-spacing 
    13:18 error link was used before it was defined    no-use-before-define 
    17:8 error Trailing spaces not allowed      no-trailing-spaces 
    18:38 error attrs is defined but never used     no-unused-vars 
    20:12 error Trailing spaces not allowed      no-trailing-spaces 
    29:18 error Missing semicolon         semi 
    30:13 error Missing semicolon         semi 
    34:18 error Missing semicolon         semi 
    35:13 error Missing semicolon         semi 
    38:1 error Newline required at end of file but not found  eol-last 

/home/james/code/proverbial/client/app/scripts/components/proverbs/proverb.ctrl.js 
    4:4 error "angular" is not defined      no-undef 
    6:35 error proverbCtrl was used before it was defined  no-use-before-define 
    8:4 error proverbCtrl was used before it was defined  no-use-before-define 
    9:36 error $stateParams is defined but never used   no-unused-vars 
    15:8 error activate was used before it was defined  no-use-before-define 
    18:25 error The '__proto__' property is deprecated   no-proto 
    21:1 error Newline required at end of file but not found eol-last 

/home/james/code/proverbial/client/app/scripts/components/proverbs/proverbs.cut-up.ctrl.js 
    4:4 error "angular" is not defined       no-undef 
    6:40 error proverbCutUpCtrl was used before it was defined no-use-before-define 
    8:4 error proverbCutUpCtrl was used before it was defined no-use-before-define 
    9:41 error $stateParams is defined but never used   no-unused-vars 
    16:26 error getFirstHalf was used before it was defined  no-use-before-define 
    16:49 error getSecondHalf was used before it was defined  no-use-before-define 
    18:8 error activate was used before it was defined   no-use-before-define 
    20:17 error getCutUp is defined but never used    no-unused-vars 
    20:33 error settings is defined but never used    no-unused-vars 
    24:16 error before is defined but never used     no-unused-vars 
    25:16 error after is defined but never used     no-unused-vars 
    61:25 error The '__proto__' property is deprecated   no-proto 
    64:1 error Newline required at end of file but not found eol-last 

/home/james/code/proverbial/client/app/scripts/components/proverbs/proverbs.detail.ctrl.js 
    4:4 error "angular" is not defined       no-undef 
    6:41 error proverbDetailCtrl was used before it was defined no-use-before-define 
    8:4 error proverbDetailCtrl was used before it was defined no-use-before-define 
    13:58 error Missing semicolon         semi 
    16:8 error activate was used before it was defined   no-use-before-define 
    19:25 error The '__proto__' property is deprecated   no-proto 
    22:1 error Newline required at end of file but not found  eol-last 

/home/james/code/proverbial/client/app/scripts/components/proverbs/proverbs.list.ctrl.js 
    4:4 error "angular" is not defined      no-undef 
    6:39 error proverbListCtrl was used before it was defined no-use-before-define 
    8:4 error proverbListCtrl was used before it was defined no-use-before-define 
    9:40 error $stateParams is defined but never used   no-unused-vars 
    17:40 error Missing semicolon        semi 
    18:9 error Missing semicolon        semi 
    20:8 error activate was used before it was defined   no-use-before-define 
    23:25 error The '__proto__' property is deprecated   no-proto 
    26:1 error Newline required at end of file but not found eol-last 

✖ 146 problems (146 errors, 0 warnings) 

[21:56:31] 'lint' errored after 2.05 s 
[21:56:31] ESLintError in plugin 'gulp-eslint' 
Message: 
    Failed with 146 errors 
[21:56:31] Finished 'scripts' after 1.61 s 

對於進一步分析,從build任務刪除lint,而確實是跳過前面提到的錯誤,導致以下Unhandled 'error' event

events.js:160 
     throw er; // Unhandled 'error' event 
    ^
Error 
    at new JS_Parse_Error (eval at <anonymous> (/home/james/code/proverbial/client/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1534:18) 
    at js_error (eval at <anonymous> (/home/james/code/proverbial/client/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1542:11) 
    at croak (eval at <anonymous> (/home/james/code/proverbial/client/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2089:9) 
    at token_error (eval at <anonymous> (/home/james/code/proverbial/client/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2097:9) 
    at unexpected (eval at <anonymous> (/home/james/code/proverbial/client/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2103:9) 
    at expr_atom (eval at <anonymous> (/home/james/code/proverbial/client/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2630:9) 
    at maybe_unary (eval at <anonymous> (/home/james/code/proverbial/client/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2792:19) 
    at expr_ops (eval at <anonymous> (/home/james/code/proverbial/client/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2827:24) 
    at maybe_conditional (eval at <anonymous> (/home/james/code/proverbial/client/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2832:20) 
    at maybe_assign (eval at <anonymous> (/home/james/code/proverbial/client/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2856:20) 
    at expression (eval at <anonymous> (/home/james/code/proverbial/client/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2875:20) 
    at simple_statement (eval at <anonymous> (/home/james/code/proverbial/client/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2314:55) 
    at eval (eval at <anonymous> (/home/james/code/proverbial/client/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2178:20) 
    at eval (eval at <anonymous> (/home/james/code/proverbial/client/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2136:24) 
    at eval (eval at <anonymous> (/home/james/code/proverbial/client/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2904:23) 
    at Object.parse (eval at <anonymous> (/home/james/code/proverbial/client/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2915:7) 

編輯:gulpfile.js根據要求

回答

0

後一些挖我能夠解決問題。

我遇到麻煩的大部分linting規則都可以在eslint npm包中的eslint.json文件上編輯。

我關閉了一些更過分熱心的linting錯誤,並最終以此eslint.json配置結束。

我並沒有忽視以下幾點:

  1. 「角」沒有定義:我加入var angular = window.angular || {};我所有角分量的開始解決。
  2. 換行符需要在文件末尾但未找到:我通過調整Visual Studio代碼的設置來解決問題。設置files.trimTrailingWhitespace並自動格式化影響文件解決了問題。這裏的settings.json供參考。
  3. 尾隨空格不允許:同上。設置files.insertFinalNewlinetrue解決了這個問題。

我手動修復了其他錯誤,例如缺少的分號,或者決定通過將它們降級爲警告來進行忽略。如上所述,您可以通過編輯eslit.json文件中的錯誤代碼之後的編號來完成此操作。例如,"no-use-before-define": 0將完全忽略這種情況。將其設置爲1將僅記錄警告,並且2將中斷任務的執行。


處理掉毛錯誤後,gulp build仍然試圖通過解析html文件示數出來。

一些調查導致我this thread這解決了我的問題。 generator-webapp軟件包中有一個gulp-if錯誤,我曾用它來支持我的應用程序。從線程引用:

After updating gulp-if to 2.0.2, the issue no longer exists.

我現在可以運行gulp build沒有問題。

0

有幾種方法來解決這個問題:

  1. 您可以在gulpfile從您的構建任務去除棉絨任務
  2. 更改掉毛規則,忽略這些錯誤
  3. 修復錯誤
  4. 使用--continue標誌告訴咕嘟咕嘟繼續即使引發的錯誤運行:gulp build --continue
+0

我之前試過'--continue'標誌,它對我沒有任何幫助。輸出完全一樣。修復錯誤是我想要避免的。當我從gulp build中刪除'lint'任務時,出現另一個錯誤,我可以在上面添加到我的文章中。 – Tiago

+0

我想這是與gulpfile的問題,你可以張貼或提供一個鏈接呢? –

+0

剛剛添加一個鏈接到我的gulpfile pastebin。 – Tiago