Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.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 ourterms of service andprivacy 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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
nx-cloudbot commentedMay 23, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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 onhttps://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitorsper day. |
netlifybot commentedMay 23, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
✅ Deploy Preview fortypescript-eslint ready!
To edit notification comments on pull requests, go to yourNetlify site settings. |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
codecovbot commentedMay 23, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.
|
bradzacher left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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
exportdefaultclassUtilities{staticutil1(){returnUtilities.util3();}staticutil2(){ ...}staticutil3(){ ...}}
✅ Correct
exportfunctionutil1(){returnutil3();}exportfunctionutil2(){ ...}exportfunctionutil3(){ ...}
:::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
exportdefaultclassUtilities{staticmutableField=1;staticutil1(){Utilities.mutableField+=1;}}
✅ Correct
letmutableField=1;exportfunctiongetMutableField(){returnmutableField;}exportfunctionsetMutableField(value:number){mutableField=value;}exportfunctionutil1(){mutableField+=1;}}
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
I'm still planning on getting to this, btw - likely on my Twitch stream tomorrow. |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
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.