【问题标题】:gulp-eslint: How to configure the "no-use-before-define" rulegulp-eslint:如何配置“no-use-before-define”规则
【发布时间】:2017-09-11 08:25:57
【问题描述】:

我正在尝试关闭函数的 "no-use-before-define" 规则,但让变量和类保持活动状态。

在这里找到的文档http://eslint.org/docs/rules/no-use-before-define 说这是正确的配置语法:

"no-use-before-define": ["error", { "functions": false, "classes": true, "variables ": true }]

当我运行它时,虽然我得到了这个错误:

[21:00:46] Error: CLI:
    Configuration for rule "no-use-before-define" is invalid:
    Severity should be one of the following: 0 = off, 1 = warning, 2 = error (you passed "error").
    Value "[object Object]" must be an enum value.

    at Object.validateRuleOptions (E:\01-Dans stuff\Projects\00 - YeoSword\YeoSword-git\node_modules\gulp-eslint\node_modules\eslint\lib\config\config-validator.js:102:15)
    at CLIEngine.<anonymous> (E:\01-Dans stuff\Projects\00 - YeoSword\YeoSword-git\node_modules\gulp-eslint\node_modules\eslint\lib\cli-engine.js:421:19)
    at Array.forEach (native)
    at new CLIEngine (E:\01-Dans stuff\Projects\00 - YeoSword\YeoSword-git\node_modules\gulp-eslint\node_modules\eslint\lib\cli-engine.js:420:43)
    at Object.gulpEslint (E:\01-Dans stuff\Projects\00 - YeoSword\YeoSword-git\node_modules\gulp-eslint\index.js:17:15)
    at E:/01-Dans stuff/Projects/00 - YeoSword/YeoSword-git/gulp/tasks/eslint.js:24:16
    at taskWrapper (E:\01-Dans stuff\Projects\00 - YeoSword\YeoSword-git\node_modules\undertaker\lib\set-task.js:13:15)
    at bound (domain.js:287:14)
    at runBound (domain.js:300:12)
    at asyncRunner (E:\01-Dans stuff\Projects\00 - YeoSword\YeoSword-git\node_modules\async-done\index.js:36:18)

我知道 gulp-eslint 的语法和官方的 eslint 配置语法有点不一样。

我无法弄清楚 { "functions": false, "classes": true, "variables ": true } 位的 gulp-eslint 语法是什么。似乎在任何地方都没有任何文档。

【问题讨论】:

    标签: eslint gulp-eslint


    【解决方案1】:

    这个答案没有解释如何进行自定义配置,但它确实解释了如何获得我最初追求的功能。

    "no-use-before-define": [1, "nofunc"]
    

    "nofunc"基本上只是{ "functions": false, "classes": true, "variables ": true }的快捷命令

    我觉得这实际上是 gulp-eslint 中的一个错误,并且没有实际的方法可以使用该插件进行自定义设置。

    【讨论】:

      【解决方案2】:

      您的规则中有一个额外的空格,就在“变量”一词之后:

      "no-use-before-define": ["error", { "functions": false, "classes": true, "variables": true }]

      这是非法的,会产生错误。

      【讨论】:

        猜你喜欢
        • 2021-12-30
        • 2021-06-25
        • 1970-01-01
        • 2020-03-23
        • 1970-01-01
        • 2021-05-04
        • 2020-08-01
        • 2019-11-10
        • 2018-02-26
        相关资源
        最近更新 更多