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

ttvkxqim  于 2023-05-22  发布在  Node.js
关注(0)|答案(3)|浏览(107)

总是错误

`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`

我尝试规则从页面https://eslint.org/docs/2.0.0/rules/camelcase添加到.eslintrc.js变量,但没有什么对我有用。:(

`rules: {
    camelcase: ['error', {properties: 'always'}],
  },

rules: {
camelcase: ['error', {allow: ['aa_bb']}],,
},`

jogvjijk

jogvjijk1#

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

6ovsh4lw

6ovsh4lw2#

如果你使用的是typescript,你可以这样做:

"rules": {
    "@typescript-eslint/naming-convention": [
        "error",
        {
            "selector": "variableLike", "format": ["snake_case", "camelCase"]
        }
    ]
}

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

yyhrrdl8

yyhrrdl83#

有时候你真的无法解决这个问题。例如,我在执行以下操作时出现了此错误

this.httpClient.post<void>(url, body,{headers: new HttpHeaders({ 'Content-Type': 'application/json' })});

但是,将http-header-property-name Content-Type更改为camelcase(因为它将不再工作)确实没有意义,因此不幸的是,为此目的的唯一选择是插入行

// eslint-disable-next-line @typescript-eslint/naming-convention

在导致linting-message的行之前。

相关问题