New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[explicit-member-accessibility]: autofix #503
Comments
We've talked about this in the past. The entire point of the rule is so that you think about the accessibility of your members. Of course, there are people that use this rule purely as a consistency check. |
I use eslint and prettier to cleanup and format the --declaration *.d.ts output generated after compilation. It would be really helpful to allow the autofix for this rule at least on .d.ts files or with a flag. |
need a fixer too, or how can I just write one for myself |
happy to accept a PR. |
|
I don't need an autofixer that just adds How about a fixer that is enabled under a flag in rule options? That way you can turn it on for short time, prefix required nodes and turn off so that developers won't accidentally put Maybe something very explicit, like this? interface Config {
// ...
overrides?: {
accessors?: AccessibilityLevel;
constructors?: AccessibilityLevel;
// ...
};
UNSAFE_AUTOFIX: true | Array<keyof NonNullable<Config["overrides"]>>;
} |
Happy for someone to add suggestion fixers to this rule: Suggestion fixers are not automatic, but IDEs will show them as possible to fix. |
Looks exactly what I needed, thanks. Will provide a PR shortly. I'm I right these can be applied with |
No; suggestion fixers cannot be applied via the CLI at all. Only manually via an IDE. It's a bit confusing yeah, because they used the same terminology unfortunately. The |
Hey, it's a little disappointing that you don't want to accept a fixer that adds |
If your usecase is normalising a codebase, then you're not looking for a lint rule - you want a codemod, which is pretty trivial to do using a tool like Push comes to shove, it would also be relatively low effort to patch a fixer locally into the rule using a tool like Also worth noting that if someone adds suggestion fixers, then it would be easy enough to then write a script using ESLint's API that runs the rule, collects and then applies the fixes. Will gladly accept a PR to add suggestion fixers, but a full auto fixer will not be added. |
I'm going to reject this request for the following reasons: (1) it goes against the spirit of the rule. As with Automatically fixing all methods to be (2) fixers live for the lifetime of the rule, not just the the initial onboarding Adding a fixer to help onboard users seems like a great idea on the surface, but it is actually a really bad idea. If you add a fixer that's always on, then users will just use the fixer and not think about it, so that's bad as per (1). (2)(a) make a configurable fixer If you make a configurable fixer, then you're relying on users to turn the fixer off once they've onboarded their codebase. Having seen many codebases and onboarding processes, I know that this is not likely to happen - users will more than likely forget to turn the fixer off once onboarded, which leads back to (1). (3) the only safe fix is to fix to ESLint fixers have to be safe. That means that ideally there should be no build or runtime errors introduced into the codebase by running a fixer. This means it's impossible for a fixer for this rule to do anything but add the (3)(a) making a "smart" fixer requires type information. This of course brings up the idea that the rule could use type information to find usages of a member so it can default to the strictest possible accessibility. There are two problems with this:
I understand that there may be some convenience to having a fixer for those that are adding the rule to a codebase, but a fixer isn't just a codemod tool - it lives on, and runs forever with the rule. It's for these reasons like this that rules like no-unused-vars don't have fixers either - it might be good to cleanup a codebase, but it's not good during development. If you need to onboard your codebase onto this rule, consider using a codemod tool to update your codebase as you wish. |
Feature Request for autofixing for rule explicit-member-accessibility
Its currently possible with the TSLint plugin: member-access and makes live easier by defaulting everything to public (based on settings)
The text was updated successfully, but these errors were encountered: