node.js - JSHint 和下划线问题 '_'

标签 node.js jshint lodash

运行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
  }
}

关于node.js - JSHint 和下划线问题 '_',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27188210/

相关文章:

javascript - 如何使用angularJS过滤选中的复选框

javascript - 使用 lodash 获取 json 对象数组名称(元数据)

node.js - 如何 POST/GET 到路由的根目录?

javascript - 使用 Node js 在 for 循环中同步多个请求

angularjs - Angular 应用程序的最大圈复杂度

javascript - JSLint 100% 有效的 Google Universal Analytics 片段,修复 "Unexpected assignment expression"

javascript - 检查字符串类型而不进行转换

node.js - Node 中具有 gm、缓冲区和 promise 的非常随机的行为

node.js - 未捕获的语法错误 : Unexpected token {

testing - 如何使用 Webpack jsHint 两个不同的文件夹?