繁体   English   中英

关闭接口的 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中进行一些更改,并以更易于维护的方式将其用于项目中的所有文件。

这已经在这里得到回答: Turn off eslint camelCase for typescript interface identifiers

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM