Skip to content

Repo: Enforce that all rules have a "When Not To Use It" docs section? #7257

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

Closed
JoshuaKGoldberg opened this issue Jul 17, 2023 · 8 comments · Fixed by #7447
Closed

Repo: Enforce that all rules have a "When Not To Use It" docs section? #7257

JoshuaKGoldberg opened this issue Jul 17, 2023 · 8 comments · Fixed by #7447
Assignees
Labels
accepting prs Go ahead, send a pull request that resolves this issue repo maintenance things to do with maintenance of the repo, and not with code/docs

Comments

@JoshuaKGoldberg
Copy link
Member

Suggestion

Right now, about 70 rule docs files have a ## When Not To Use It heading. Is this practice something we want to standardize for all rules and enforce as a CI/lint/test check?

FWIW I'd be in favor. I think it's good to always portray a nuanced view of when you would or wouldn't want to use a rule.

@JoshuaKGoldberg JoshuaKGoldberg added triage Waiting for team members to take a look repo maintenance things to do with maintenance of the repo, and not with code/docs labels Jul 17, 2023
@bradzacher
Copy link
Member

We probably need to do a broader review of the docs to clean them up.
A lot of the "when not to use it" sections are bollocks like "if you don't use this syntax don't use the rule" - which is entirely unhelpful noise IMO.

I'm in favour of us adding it to the template as a section that would be good to include - but I don't think saying "always" is necessarily correct.

@JoshuaKGoldberg
Copy link
Member Author

but I don't think saying "always" is necessarily correct

Are there any rules where you don't think it'd be valuable?

I think from at least a philosophical perspective, it'd be beneficial for us to showcase that all rules are nuanced. A lot of new-to-ESLint devs treat rules as immutable truths, and it's good to encourage them to think more deeply on them.

Sent #7447 as a draft for reference of a rough attempt to fill out all remaining ones.

@bradzacher
Copy link
Member

commented with some quick examples

@JoshuaKGoldberg
Copy link
Member Author

Cool - I'm going to say this has passed triage, in that the When Not To Use It examples should be filled out more. I'll try to get to that draft PR to fix up for the comments. +1 to @Josh-Cena's #7447 (comment) that mentioning using disable comments there can be valuable.

@JoshuaKGoldberg JoshuaKGoldberg added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for team members to take a look labels Oct 17, 2023
@JoshuaKGoldberg JoshuaKGoldberg self-assigned this Oct 17, 2023
@bradzacher
Copy link
Member

One way to frame this - IMO if the rule is in our recommended set - there probably shouldn't be a "when not to use it" section. If we recommend the rule we believe it forms the base set of checks that every TS codebase should have no - we don't believe there is a reason you should turn it off!

@Josh-Cena
Copy link
Member

I've had non-zero problems with no-var-requires and JSON files (or Webpack in general, when you want to import hundreds of images without writing them on separate lines). Similarly, unbound-method is often subject to how the method is declared in the lib—for example, did you know that paths.map(Path.resolve) is flagged by this rule?

I appreciate these are edge cases that maybe not everyone encounters, but we can definitely find a way to generalize them.

@bradzacher
Copy link
Member

The webpack stuff - 100% outside our concern.
As far as we're concerned "you're writing ESM that runs in an ESM environment".

This is becoming more and more of a true assumption as projects move to be esm-only nodejs (eg require is physically unavailable). And modern bundlers are getting stricter as well - I think webpack is one of those stragglers that relies on require so heavily.

Essentially the rule is right - if you're writing modern TS you should use es6 module syntax only. If your environment happens to support require and you feel the need to drop on it - that's still a violation of the rule because you're probably doing something lazy.

The only time I've seen it "not lazy" and actually required is the package.json case to prevent it being copied to the build folder. But that's just an edge-case that either we keep as "use a disable" or we could add an exception to the rule.

@JoshuaKGoldberg
Copy link
Member Author

Coming back to this!

IMO if the rule is in our recommended set - there probably shouldn't be a "when not to use it" section

I would flip that logic: if the rule isn't in the recommended set, then IMO there should be a "when not to use it" section.

But if the rule's in recommended, that means a lot more eyes are going to be on it. And we've had issues with devs thinking the recommended ruleset is all must-have. https://typescript-eslint.io/rules/no-floating-promises is a good example of "this absolutely should be recommended, but dang do people need caveats on how to use it right".

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue repo maintenance things to do with maintenance of the repo, and not with code/docs
Projects
None yet
3 participants