ESLint在'__place'中没有下划线悬挂的意外悬空'_'

时间:2017-05-23 06:08:26

标签: javascript eslint

我有以下JSON响应,为了验证__place,我使用了responseData.search [0] .edges [0] .node。 __ place

{
  "data": {
    "search": [
      {
        "__place": "SearchResultItemConnection",
        "edges": [
          {
            "cursor": "New",
            "node": {
              "__place": "Delhi",
              "name": "AIIMS"
            }
          }
        ]
      }
    ]
  }
}

我收到ESLint错误,指出“错误'__typename'无下划线悬空中意外悬空'_'

我查看了链接http://eslint.org/docs/rules/no-underscore-dangle,但我无法解决此问题。

有谁知道如何解决这个问题,而不是改变规则?

4 个答案:

答案 0 :(得分:16)

您可以在产生错误的代码行之前添加以下注释:

/* eslint no-underscore-dangle: ["error", { "allow": ["__place"] }]*/
responseData.search[0].edges[0].node.__place

或添加

/* eslint no-underscore-dangle: 0 */

为该脚本文件禁用此特定规则。

答案 1 :(得分:3)

您可以简单地通过在配置文件中提供例外来排除那些例外。

"no-underscore-dangle":  ["error", { "allow": ["_place"] }]

答案 2 :(得分:1)

如果您想禁用整个规则(例如“ no-underscore-dangle”),只需输入config:

{    
   rules: {        
      "no-underscore-dangle": 'off'
   },
};

答案 3 :(得分:0)

在行上方添加以下内容:

// eslint-disable-next-line no-underscore-dangle