Vencovsky
Vencovsky

Reputation: 31693

ESLint Rule to Warn on Typescript's erasableSyntaxOnly flag

Typescript is launching --erasableSyntaxOnly flag in v5.8 that will throw an error if you use things like enum or parameter properties in classes (see article for more details).

When I enable that flag, I get so many errors that I won't be able to fix it all at once.

So I wanted a ESLint rule that can warn me when using invalid syntax so I can do a incremental removal of this syntax before enabling the flag in tsconfig.

What is the ESLint rule for this? If it doesn't exist, is there a way to do it using no-restricted-syntax?

Upvotes: 0

Views: 186

Answers (1)

Josh
Josh

Reputation: 3543

Yes, there is a plugin for this now, eslint-plugin-erasable-syntax-only. To use it, install it as a dev dependency:

npm i eslint-plugin-erasable-syntax-only -D

Then add its recommended configuration in your ESLint config file:

import erasableSyntaxOnly from "eslint-plugin-erasable-syntax-only";
import tseslint from "typescript-eslint";

export default tseslint.config(
    eslint.configs.recommended,
    tseslint.configs.recommended,
    erasableSyntaxOnly.configs.recommended, // 👈
);

https://github.com/JoshuaKGoldberg/eslint-plugin-erasable-syntax-only

(disclaimer: I'm the author)

Upvotes: 1

Related Questions