allegro / typescript-strict-plugin

Typescript plugin that allows turning on strict mode in specific files or directories.
MIT License
332 stars 29 forks source link

Add optional support for disabling typescript-eslint rules that depend on strict mode #81

Open Diesmon opened 1 month ago

Diesmon commented 1 month ago

Maybe this request is out-of-scope for this project, but I think it would be a valuable addition.

Certain typescript-eslint rules are depending on having a typescript codebase that is using strict or at least strictNullChecks. For example this no-unnecessary-condition will work best if strictNullChecks are enabled.

Problem

If I run this plugin and start gradually migrating files by removing the strict ignore comment, and fixing all TS-errors, I would also like to remove unnecessary optional chaining calls or other condition that are not needed and only show up now after enabling strict mode.

Proposal

Enhance the script so that it can also add ignore comment for certain typescript-eslint rules to every file where it adds the //@ts-strict-ignore comment. An optional behavior that the user can select.

Examples

Comment block added when choosing to also ignore no-unnecessary-condition rule:

//@ts-strict-ignore
/* eslint-disable @typescript-eslint/no-unnecessary-condition */

Comment block added when choosing to only ignore ts-strict errors (like it is now):

//@ts-strict-ignore

Pros

Cons

Conclusion

Improving your codebase with typescript-eslint rules is considered good practice, but adding the rules to an already "problematic" ts-codebase is a pain, as you need to disable certain rules for many files (in my case 3000+ files). Bundling this action together with the plugin makes sense in my opinion, as typescript-eslint + ts-strict mode serve the same purpose, to make the code less error prone and also easier to read. There seem to also be other typescript-eslint rules that depend on strict mode that would make sense to also disable for files where strict mode is also disabled, if teh users wishes so. So maybe this feature should include more rules than only the one I gave as an example.