简体   繁体   English

关闭接口的 eslint 规则?

[英]Turning off eslint rule for an interface?

I have TypeScript interfaces that I use in Axios and they're ugly since my API requires them in that way:我在 Axios 中使用了 TypeScript 接口,它们很丑,因为我的 API 以这种方式需要它们:

interface MyImage {
  URI: string,
  Width?: number,
  Height?: number,
}

Is there a way to disable eslint rule ( naming-convention ) for the whole interface (I have many of them inside one file)有没有办法为整个界面禁用 eslint 规则( naming-convention )(我在一个文件中有很多规则)

Override the rule at the top of your file by turning the format off for interfaces, try this:通过关闭接口的格式来覆盖文件顶部的规则,试试这个:

/* eslint @typescript-eslint/naming-convention: ["off", { "selector": "interface", "format": ["camelCase"] }] */

Original answer:原答案:

You'd have to find the rule name that's enforcing the style, I'm guessing it's the @typescript-eslint/camelcase .您必须找到执行样式的规则名称,我猜它是@typescript-eslint/camelcase

When you find the rule name, you can turn the rule off for the current file by writing当您找到规则名称时,您可以通过编写关闭当前文件的规则

/* eslint-disable @typescript-eslint/camelcase */

at the top of your file.在文件的顶部。

Since disabling eslint on each file doesn't seem to be the most convenient approach, you can make some changes in your .eslintrc and have it for all files across your project in a more maintainable way.由于在每个文件上禁用 eslint 似乎不是最方便的方法,您可以在.eslintrc中进行一些更改,并以更易于维护的方式将其用于项目中的所有文件。

This has been already answered here: Turn off eslint camelCase for typescript interface identifiers这已经在这里得到回答: Turn off eslint camelCase for typescript interface identifiers

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

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