-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
docs(eslint-plugin): [no-extraneous-class] overhaul rule docs #5059
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
docs(eslint-plugin): [no-extraneous-class] overhaul rule docs #5059
Conversation
Thanks for the PR, @JoshuaKGoldberg! typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community. The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately. Thanks again! 🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day. |
✅ Deploy Preview for typescript-eslint ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
…Goldberg/typescript-eslint into no-extraneous-class-docs
Codecov Report
@@ Coverage Diff @@
## main #5059 +/- ##
==========================================
+ Coverage 91.32% 93.83% +2.50%
==========================================
Files 132 286 +154
Lines 1487 9839 +8352
Branches 224 2939 +2715
==========================================
+ Hits 1358 9232 +7874
- Misses 65 328 +263
- Partials 64 279 +215
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to add a clear example to the docs saying what you should do instead of a static class.
For example:
Instead of using a static utility class you should individually export the utilities from your module.
❌ Incorrect
export default class Utilities {
static util1() { return Utilities.util3(); }
static util2() { ... }
static util3() { ... }
}
✅ Correct
export function util1() { return util3(); }
export function util2() { ... }
export function util3() { ... }
:::note
One case you need to be careful of is exporting mutable variables.
A class property can be mutated externally, however exported variables are always constant. This means that importers can only ever read the first value they are assigned and importers cannot write to the variables.
This case is very rare and is generally considered a code smell, but if you do need it you can still accomplish it using getters and setter functions as seen below.
:::
❌ Incorrect
export default class Utilities {
static mutableField = 1;
static util1() {
Utilities.mutableField += 1;
}
}
✅ Correct
let mutableField = 1;
export function getMutableField() {
return mutableField;
}
export function setMutableField(value: number) {
mutableField = value;
}
export function util1() {
mutableField += 1;}
}
I'm still planning on getting to this, btw - likely on my Twitch stream tomorrow. |
a917483
Co-authored-by: Brad Zacher <brad.zacher@gmail.com>
PR Checklist
Overview
Expands the rule's docs to include a more complete explanation of the points against namespace-y classes.