关闭TypeScrip界面标识符的eslint CamelCase [英] Turn off eslint camelCase for typescript interface identifiers
本文介绍了关闭TypeScrip界面标识符的eslint CamelCase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将现有的JS存储库迁移到TypeScrip。问题是项目的API响应是snake_case
中具有标识符的对象,这与默认的eslintcamelCase
规则冲突。
迁移之前,我们使用.eslintrc.js
中的此规则处理snake_case
对象标识符:
'camelcase': ['error', {properties: 'never'}],
并且在我们的代码中可能有这样的对象:
const { variable_name } = await axios(url)
但在移至TypeScrip之后,这些标识符也将显示在界面中。
所以基本上我希望能够:
interface Model<T extends string> {
type: T;
id: number;
variable_name: string;
language_code: string;
}
但TypeScrip现在引发:
Identifier 'variable_name' is not in camel case.
我的.eslintrc.js
文件中应该有什么规则来证明这一点?请注意,我的标识符并不限于上面列出的这两个,为了简单起见,我删除了其他几十个标识符。
推荐答案
请记住,(ESLint是为其开发的)不知道类型(例如。接口)。
所以我认为这就是在linting文件时发生的情况:
- ESLint的
camelCase
规则适用于对象及其属性。 - ESLint的解析器不理解您有一个接口,并认为这些是另一个块中的变量。因此,检查会导致错误的结果。
我认为您需要做的是:
- 禁用
camelCase
规则(至少对于您的打字稿文件)。 - 改用naming-convention规则,并根据需要进行配置。
这应该是可行的:
"@typescript-eslint/naming-convention": [
"error",
{
"selector": "default",
"format": ["camelCase"]
},
{
"selector": "typeProperty",
"format": null
}
]
这篇关于关闭TypeScrip界面标识符的eslint CamelCase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文