当前位置 : 主页 > 网页制作 > Nodejs >

node.js – JSHint和下划线’_’的问题

来源:互联网 收集:自由互联 发布时间:2021-06-16
运行jshint时出现以下错误; line 4 col 5 Redefinition of '_'. 代码是抱怨的; var _ = require('lodash'); 项目中的jshint { "node": true, "esnext": true, "bitwise": true, "eqeqeq": true, "immed": true, "latedef": "nofunc", "new
运行jshint时出现以下错误;

line 4   col 5  Redefinition of '_'.

代码是抱怨的;

var _ = require('lodash');

项目中的jshint

{
    "node": true,
    "esnext": true,
    "bitwise": true,
    "eqeqeq": true,
    "immed": true,
    "latedef": "nofunc",
    "newcap": true,
    "noarg": true,
    "regexp": true,
    "undef": true,
    "smarttabs": true,
    "asi": true,
    "debug": true,
    "globals": {
        "angular": false,
        "_": false
    }
}
将.jshintrc更新为以下似乎已解决问题.

{
    "node": true,
    "browser": true,
    "esnext": true,
    "bitwise": false,
    "camelcase": false,
    "eqeqeq": true,
    "immed": true,
    "indent": 4,
    "latedef": true,
    "newcap": true,
    "noarg": true,
    "quotmark": "single",
    "regexp": true,
    "undef": true,
    "unused": false,    
    "strict": true,
    "trailing": true,
    "smarttabs": true,
    "globals": {
        "jQuery": true,
        "angular": true,
        "console": true,
        "AppConfig": true,
        "$": true,
        "_": true,
        "moment": true,
        "module": true,
        "inject": true,
        "browser": true,
        "element": true,

        "describe": true,
        "before": true,
        "beforeEach": true,
        "after": true,
        "afterEach": true,
        "expect": true,
        "it": true,
        "by": true,
        "chai": true
    }
}

还创建了一个.jshintrc-spec

{
  "extends": ".jshintrc",
  "globals": {
    "describe": true,
    "it": true,
    "before": true,
    "beforeEach": true,
    "after": true,
    "afterEach": true,
    "chai": true,
    "inject" : true
  }
}
网友评论