ESLint 在“__place”中出现意外的悬挂“_”无下划线悬挂

ESLint Unexpected dangling '_' in '__place' no-underscore-dangle

我有下面的 JSON 响应,为了验证 __place,我使用了 responseData.search[0].edges[0].node.__place

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

我收到 ESLint 错误 "error Unexpected dangling '_' in '__typename' no-underscore-dangle"

我经历了 link、http://eslint.org/docs/rules/no-underscore-dangle 但我无法解决这个问题。

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

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

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

或添加

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

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

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

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

在行上方添加以下内容:

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

如果您想禁用整个规则(例如 "no-underscore-dangle"),只需输入配置:

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