强迫吞咽?

时间:2017-04-03 21:04:57

标签: javascript gulp

我试图使用gulp build创建角度项目的分发版本,但是,当我运行命令时,它失败了146个错误,其中许多似乎是严格的样式执行

有没有办法强制gulp忽略这些linting错误并强制创建dist版本?

我正在使用gulp-cli 1.2.2

该应用程序是使用自耕农搭建的。这是我的package.jsongulpfile.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

要进行进一步分析,从lint任务中删除build,同时确实跳过前面提到的错误,会产生以下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

2 个答案:

答案 0 :(得分:0)

有几种方法可以解决这个问题:

  1. 您可以从gulpfile
  2. 中的构建任务中删除lint任务
  3. 更改您的linting规则以忽略这些错误
  4. 修复错误
  5. 使用--continue标志告诉Gulp即使出现错误也会继续运行:gulp build --continue

答案 1 :(得分:0)

经过一番挖掘,我能够解决问题。

我遇到问题的大多数linting规则都可以在eslint npm包中的eslint.json文件中进行编辑。

我关闭了一些过于热心的linting错误,最终使用了这个eslint.json配置。

我没有忽略以下内容:

  1. “angular”未定义:我通过将var angular = window.angular || {};添加到所有角度组件的开头来解决。
  2. 文件末尾需要换行符但未找到:我通过调整Visual Studio Code上的设置解决了问题。设置files.trimTrailingWhitespace并自动格式化影响文件解决了问题。这里有settings.json供参考。
  3. 不允许使用尾随空格:与上述相同。将files.insertFinalNewline设置为true可以解决问题。
  4. 我手动修复的其余错误,例如缺少的冒号,或者通过将它们降级为警告而决定忽略。您可以通过编辑eslit.json文件中错误代码之后的数字来执行此操作,如上所述。例如,"no-use-before-define": 0将完全忽略此发生。将其设置为1将仅记录警告,2将中断任务的执行。

    在处理了linting错误后,gulp build仍然因尝试解析html个文件而出错。

    一些调查让我this thread为我解决了这个问题。 gulp-if包中存在generator-webapp的错误,我曾用它来构建我的应用程序。引用帖子:

      

    将gulp-if更新为2.0.2后,问题不再存在。

    我现在可以毫无问题地运行gulp build