简体   繁体   English

如何使用 ts-standard 禁用整个 TypeScript 项目的 ESLint 规则?

[英]How to disable ESLint rule for whole TypeScript project using ts-standard?

In my TypeScript project I am using the node modules "typescript" and "ts-standard".在我的 TypeScript 项目中,我使用节点模块“typescript”和“ts-standard”。 As IDE I am using Visual Studio Code with the "StandardJS - JavaScript Standard Style" extension.作为 IDE,我正在使用带有“StandardJS - JavaScript 标准样式”扩展名的 Visual Studio Code。 In its settings "Engine" is set to "ts-standard".在其设置中,“引擎”设置为“ts-standard”。

To disable a certain ESLint rule for one line I could write /* eslint-disable-next-line padded-blocks */ right above that line.要为一行禁用某个 ESLint 规则,我可以在该行的正上方编写/* eslint-disable-next-line padded-blocks */

To disable a certain ESLint rule for one file I could write /* eslint-disable padded-blocks */ at the top of the file.要为一个文件禁用某个 ESLint 规则,我可以在文件顶部写/* eslint-disable padded-blocks */

How do I disable a certain ESLint rule for the whole project/package/workspace?如何为整个项目/包/工作区禁用某个 ESLint 规则?

Problem问题

Standard.js , and consequently ts-standard , does not allow configuration of rules out-of-the-box: Standard.js以及因此ts-standard不允许开箱即用的规则配置:

I disagree with rule X, can you change it?我不同意规则 X,你能改变它吗?

No. [...]不。 [...]

Standard.js 标准.js

🚫 Please change X rule 🚫 请更改 X 规则

This project has no control over the rules implemented, as such this project cannot change any of the rules that have been configured.该项目无法控制实施的规则,因此该项目无法更改已配置的任何规则。 If you want to discuss the rules, please visit the rules configuration repo eslint-config-standard-with-typescript .如果你想讨论规则,请访问规则配置eslint-config-standard-with-typescript

🧙 Why 🧙 为什么

This utility was designed to be the standard equivalent for typescript.此实用程序设计为与 typescript 等效的standard Underneath the hood, this utility uses the same standard-engine and combines that engine with the official eslint-config-standard-with-typescript ruleset.在底层,该实用程序使用相同的standard-engine并将该引擎与官方eslint-config-standard-with-typescript规则集相结合。

ts-standard ts-标准

Solution解决方案

The documentation above, however, does detail how you could get the ability to configure the rules:但是,上面的文档确实详细说明了如何获得配置规则的能力:

You can also choose to just use eslint with the eslint-config-standard-with-typescript shareable config instead and achieve the same results as this project.您也可以选择仅将eslinteslint-config-standard-with-typescript可共享配置一起使用,并获得与本项目相同的结果。 But ts-standard saves you from having to manually install all the extra dependencies and may reduce configuration overhead.但是ts-standard使您不必手动安装所有额外的依赖项,并且可以减少配置开销。

ts-standard ts-标准

So what you must do is:所以你必须做的是:

  1. Uninstall ts-standard .卸载ts-standard
  2. Install eslint-config-standard-with-typescript , along with its peer dependencies:安装eslint-config-standard-with-typescript及其对等依赖项:
  3. Configure ESLint, extending the configuration provided by eslint-config-standard-with-typescript , in an ESLint configuration file .ESLint 配置文件中配置 ESLint,扩展eslint-config-standard-with-typescript typescript 提供的配置。 An example, in an .eslintrc.js :一个示例,在.eslintrc.js中:
module.exports = {
  extends: 'standard-with-typescript',
  parserOptions: {
    project: './tsconfig.json'
  }
}

At this point, you can now specify your own rules in the ESLint configuration file, with the rules key .此时,您现在可以在 ESLint 配置文件中指定自己的规则,使用rules An example, continuing from the previous:一个例子,从上一个继续:

module.exports = {
  extends: 'standard-with-typescript',
  parserOptions: {
    project: './tsconfig.json'
  },
  rules: {
    'padded-blocks': 'off'
  }
}

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

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