How to disable ESLint rule for whole TypeScript project using ts-standard?
Asked Answered
O

1

6

In my TypeScript project I am using the node modules "typescript" and "ts-standard". As IDE I am using Visual Studio Code with the "StandardJS - JavaScript Standard Style" extension. In its settings "Engine" is set to "ts-standard".

To disable a certain ESLint rule for one line I could write /* eslint-disable-next-line padded-blocks */ right above that line.

To disable a certain ESLint rule for one file I could write /* eslint-disable padded-blocks */ at the top of the file.

How do I disable a certain ESLint rule for the whole project/package/workspace?

Odyssey answered 26/3, 2022 at 22:9 Comment(0)
H
1

Problem

Standard.js, and consequently ts-standard, does not allow configuration of rules out-of-the-box:

I disagree with rule X, can you change it?

No. [...]

Standard.js

🚫 Please change X rule

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.

🧙 Why

This utility was designed to be the standard equivalent for typescript. Underneath the hood, this utility uses the same standard-engine and combines that engine with the official eslint-config-standard-with-typescript ruleset.

ts-standard

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. But ts-standard saves you from having to manually install all the extra dependencies and may reduce configuration overhead.

ts-standard

So what you must do is:

  1. Uninstall ts-standard.
  2. Install eslint-config-standard-with-typescript, along with its peer dependencies:
  3. Configure ESLint, extending the configuration provided by eslint-config-standard-with-typescript, in an ESLint configuration file. An example, in an .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. An example, continuing from the previous:

module.exports = {
  extends: 'standard-with-typescript',
  parserOptions: {
    project: './tsconfig.json'
  },
  rules: {
    'padded-blocks': 'off'
  }
}
Helterskelter answered 27/7, 2022 at 19:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.