关闭接口的 eslint 规则?
Turning off eslint rule for an interface?
我有在 Axios 中使用的 TypeScript 接口,它们很丑陋,因为我的 API 需要它们:
interface MyImage {
URI: string,
Width?: number,
Height?: number,
}
有没有办法为整个界面禁用 eslint 规则 (naming-convention
)(我在一个文件中有很多规则)
通过关闭接口格式来覆盖文件顶部的规则,试试这个:
/* eslint @typescript-eslint/naming-convention: ["off", { "selector": "interface", "format": ["camelCase"] }] */
原回答:
您必须找到强制执行样式的规则名称,我猜是 @typescript-eslint/camelcase
。
找到规则名称后,您可以通过写入
为当前文件关闭规则
/* eslint-disable @typescript-eslint/camelcase */
在文件的顶部。
由于在每个文件上禁用 eslint 似乎不是最方便的方法,您可以在 .eslintrc
中进行一些更改,并以更易于维护的方式将其用于项目中的所有文件。
这里已经回答了:
我有在 Axios 中使用的 TypeScript 接口,它们很丑陋,因为我的 API 需要它们:
interface MyImage {
URI: string,
Width?: number,
Height?: number,
}
有没有办法为整个界面禁用 eslint 规则 (naming-convention
)(我在一个文件中有很多规则)
通过关闭接口格式来覆盖文件顶部的规则,试试这个:
/* eslint @typescript-eslint/naming-convention: ["off", { "selector": "interface", "format": ["camelCase"] }] */
原回答:
您必须找到强制执行样式的规则名称,我猜是 @typescript-eslint/camelcase
。
找到规则名称后,您可以通过写入
为当前文件关闭规则/* eslint-disable @typescript-eslint/camelcase */
在文件的顶部。
由于在每个文件上禁用 eslint 似乎不是最方便的方法,您可以在 .eslintrc
中进行一些更改,并以更易于维护的方式将其用于项目中的所有文件。
这里已经回答了: