javascript - 钩子(Hook) (`sails-eslint` ) 加载失败

标签 javascript node.js sails.js eslint

将其重新打开为最新的 sails-eslint 版本,引发相同的错误

"npm": "5.0.2"
"sails": "~0.12.13",
"sails-disk": "~0.10.9",
"sails-eslint": "^1.0.9",
"sails-hook-eslint": "^1.0.3",
"sails-mysql": "^0.11.5"

sails-hook-eslint is not helpful to resolve the error mentioned below:

通过安装 sails-eslint 将 lint 配置到项目

eslint.js 添加到 config 文件夹中:

module.exports.eslint = {
  active: true,
  usePolling: false,
  formatter: 'stylish',
  dirs: [
    "api",
    "config"
  ],
  ignored: [
    "api/policies"
  ]
};

但是当尝试运行应用程序时,它会抛出如下错误:

    info: ESlint watching...
error: A hook (`sails-eslint`) failed to load!
Code did not pass lint rules
c:\Projects\test\api\controllers\UsersController.js
  10:4   error  'Users' is not defined        no-undef
  10:22  error  Expected error to be handled  handle-callback-err
  15:4   error  'Users' is not defined        no-undef
  15:50  error  Expected error to be handled  handle-callback-err

c:\Projects\test\api\policies\sessionAuth.js
  10:25  error  Missing space before function parentheses  space-before-function-parentheses
  12:50  error  Trailing spaces not allowed                no-trailing-spaces

c:\Projects\test\api\responses\badRequest.js
  29:2   error  Expected { after 'else'                                                       curly
  30:64  error  A space is required after ','                                                 comma-spacing
  53:38  error  Expected literal to be on the right side of ==                                yoda
  57:4   error  Closing curly brace does not appear on the same line as the subsequent block  brace-style
  65:2   error  Expected { after 'else'                                                       curly
  71:96  error  Unexpected space before function parentheses                                  space-before-function-parentheses

c:\Projects\test\api\responses\created.js
  14:33  error  Unexpected space before function parentheses                                  space-before-function-parentheses
  38:38  error  Expected literal to be on the right side of ==                                yoda
  42:4   error  Closing curly brace does not appear on the same line as the subsequent block  brace-style
  50:2   error  Expected { after 'else'                                                       curly
  56:92  error  Unexpected space before function parentheses                                  space-before-function-parentheses

c:\Projects\test\api\responses\forbidden.js
  15:35   error  Unexpected space before function parentheses                                  space-before-function-parentheses
  26:2    error  Expected { after 'else'                                                       curly
  27:62   error  A space is required after ','                                                 comma-spacing
  50:38   error  Expected literal to be on the right side of ==                                yoda
  54:4    error  Closing curly brace does not appear on the same line as the subsequent block  brace-style
  62:2    error  Expected { after 'else'                                                       curly
  76:118  error  A space is required after ','                                                 comma-spacing
  79:11   error  Closing curly brace does not appear on the same line as the subsequent block  brace-style

c:\Projects\test\api\responses\notFound.js
  20:34   error  Unexpected space before function parentheses                                  space-before-function-parentheses
  31:2    error  Expected { after 'else'                                                       curly
  32:62   error  A space is required after ','                                                 comma-spacing
  55:38   error  Expected literal to be on the right side of ==                                yoda
  59:4    error  Closing curly brace does not appear on the same line as the subsequent block  brace-style
  67:2    error  Expected { after 'else'                                                       curly
  81:117  error  A space is required after ','                                                 comma-spacing
  84:11   error  Closing curly brace does not appear on the same line as the subsequent block  brace-style

c:\Projects\test\api\responses\ok.js
  14:32  error  Unexpected space before function parentheses                                  space-before-function-parentheses
  38:38  error  Expected literal to be on the right side of ==                                yoda
  42:4   error  Closing curly brace does not appear on the same line as the subsequent block  brace-style
  50:2   error  Expected { after 'else'                                                       curly
  56:87  error  Unexpected space before function parentheses                                  space-before-function-parentheses

c:\Projects\test\api\responses\serverError.js
  15:37   error  Unexpected space before function parentheses                                  space-before-function-parentheses
  26:2    error  Expected { after 'else'                                                       curly
  27:63   error  A space is required after ','                                                 comma-spacing
  50:38   error  Expected literal to be on the right side of ==                                yoda
  54:4    error  Closing curly brace does not appear on the same line as the subsequent block  brace-style
  62:2    error  Expected { after 'else'                                                       curly
  76:120  error  A space is required after ','                                                 comma-spacing
  79:11   error  Closing curly brace does not appear on the same line as the subsequent block  brace-style

✖ 46 problems (46 errors, 0 warnings)

Code did not pass lint rules
c:\Projects\test\config\bootstrap.js
  12:35  error  Missing space before function parentheses  space-before-function-parentheses

c:\Projects\test\config\connections.js
  47:18  error  Expected exception block, space or tab after // in comment  spaced-line-comment
  48:23  error  Expected exception block, space or tab after // in comment  spaced-line-comment
  52:3   error  Unexpected trailing comma                                   comma-dangle

c:\Projects\test\config\eslint.js
   6:4  error  Strings must use singlequote  quotes
   7:4  error  Strings must use singlequote  quotes
  10:4  error  Strings must use singlequote  quotes

c:\Projects\test\config\http.js
  80:3  error  Unexpected trailing comma  comma-dangle

c:\Projects\test\config\session.js
  24:44  error  Unexpected trailing comma  comma-dangle

c:\Projects\test\config\sockets.js
  54:0  error  Multiple blank lines not allowed  no-multiple-empty-lines
  71:0  error  Multiple blank lines not allowed  no-multiple-empty-lines

c:\Projects\test\config\views.js
  95:1  error  Newline required at end of file but not found  eol-last

✖ 12 problems (12 errors, 0 warnings)

error: TypeError: Expected `input` to be a `string`, got `number`
    at module.exports (c:\Projects\test\node_modules\repeating\index.js:6:9)
    at c:\Projects\test\node_modules\sails-eslint\pretty-formatter.js:95:17
    at Array.map (native)
    at module.exports (c:\Projects\test\node_modules\sails-eslint\pretty-formatter.js:84:21)
    at runLint (c:\Projects\test\node_modules\sails-eslint\index.js:28:7)
    at c:\Projects\test\node_modules\sails-eslint\index.js:52:7
    at Array.forEach (native)
    at processingQueue (c:\Projects\test\node_modules\sails-eslint\index.js:46:8)
    at Hook.initialize (c:\Projects\test\node_modules\sails-eslint\index.js:140:9)
    at Hook.wrapper [as initialize] (c:\Projects\test\node_modules\@sailshq\lodash\lib\index.js:3250:19)
    at c:\Projects\test\node_modules\sails\lib\hooks\index.js:88:16
    at c:\Projects\test\node_modules\sails\node_modules\async\lib\async.js:52:16
    at c:\Projects\test\node_modules\sails\node_modules\async\lib\async.js:548:17
    at c:\Projects\test\node_modules\sails\node_modules\async\lib\async.js:542:17
    at _arrayEach (c:\Projects\test\node_modules\sails\node_modules\async\lib\async.js:85:13)
    at Immediate.taskComplete (c:\Projects\test\node_modules\sails\node_modules\async\lib\async.js:541:13)
    at runCallback (timers.js:672:20)
    at tryOnImmediate (timers.js:645:5)
    at processImmediate [as _immediateCallback] (timers.js:617:5)

代码有什么问题吗?

另外,是否有可能使用 babel-eslint?

最佳答案

您可以使用 sails-hook-eslint 插件。 sails-eslint 也不适合我。

https://github.com/Globegitter/sails-hook-eslint

npm install sails-hook-eslint

之后将 .eslintrc 文件添加到 sails 根目录。

现在,如果您启动 sails lift,则会执行 linting 任务。 另外,如果你想要一个更新的 eslint。我为此做了一个公关。 https://github.com/Globegitter/sails-hook-eslint/pull/8

关于javascript - 钩子(Hook) (`sails-eslint` ) 加载失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42944128/

相关文章:

javascript - 在 WebGL 与 WebGL 中模拟基于调色板的图形 Canvas 二维

javascript - jQuery 验证不工作 - jqueryvalidation.org

node.js - 从用户设置动态设置 LESS 变量

javascript - 访问服务器端 javascript 变量以使用客户端 javascript 进行操作

javascript - 如果 Grunt 任务的子任务之一失败,如何使其失败?

javascript - 有没有办法跳过在 sails.js 应用程序中加载某些配置文件?

javascript - 如何检查事件是否被阻止

Javascript - 可以模拟经典的 OOP 继承吗?

angularjs - 尽管 ui-route 和提供程序似乎工作正常,但我无法在 angularjs 中加载 View ...这是一段代码

sockets - Node 代理与主机 :port but doesn't take a unix socket-path 一起工作