如何设置ESLint规则来接受snake_case?

pro*_*php 8 node.js eslint

总是出错

  `16:3  error  Property name `type_array` must match one of the following formats: camelCase, UPPER_CASE, PascalCase    @typescript-eslint/naming-convention
  16:3  error  Identifier 'type_array' is not in camel case 
16:3  error  Property name `instument_view_id` must match one of the following formats: camelCase, UPPER_CASE, PascalCase`
Run Code Online (Sandbox Code Playgroud)

我尝试从页面 https://eslint.org/docs/2.0.0/rules/camelcase 添加到 .eslintrc.js 变体中的规则,但对我没有任何作用..:(

  `rules: {
    camelcase: ['error', {properties: 'always'}],
  },
```
  rules: {
    camelcase: ['error', {allow: ['aa_bb']}],,
  },`
Run Code Online (Sandbox Code Playgroud)

小智 6

如果你使用打字稿,你可以使用这个:

"rules": {
    "@typescript-eslint/naming-convention": [
        "error",
        {
            "selector": "variableLike", "format": ["snake_case", "camelCase"]
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

这可能不是最好的选择,但至少对我有用。


nam*_*old 5

ESLint 不支持snake_case. 如果你想使用snake_case,试试这个ESLint 插件。