Skip to content

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

Merged

Conversation

JoshuaKGoldberg
Copy link
Member

PR Checklist

Overview

Expands the rule's docs to include a more complete explanation of the points against namespace-y classes.

@nx-cloud
Copy link

nx-cloud bot commented May 23, 2022

☁️ Nx Cloud Report

CI is running/has finished running commands for commit a1a5b17. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 46 targets

Sent with 💌 from NxCloud.

@typescript-eslint
Copy link
Contributor

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.

@netlify
Copy link

netlify bot commented May 23, 2022

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit a1a5b17
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/6298cb1561de3100080f7652
😎 Deploy Preview https://deploy-preview-5059--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@bradzacher bradzacher added the documentation Documentation ("docs") that needs adding/updating label May 23, 2022
@bradzacher bradzacher changed the title docs: overhauled no-extraneous-class rule docs docs(eslint-plugin): [no-extraneous-class] overhaul rule docs May 23, 2022
@JoshuaKGoldberg JoshuaKGoldberg marked this pull request as ready for review May 23, 2022 19:36
@codecov
Copy link

codecov bot commented May 23, 2022

Codecov Report

Merging #5059 (a1a5b17) into main (ce3083e) will increase coverage by 2.50%.
The diff coverage is n/a.

@@            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     
Flag Coverage Δ
unittest 93.83% <ø> (+2.50%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...kages/eslint-plugin/src/rules/func-call-spacing.ts 96.87% <0.00%> (ø)
...es/eslint-plugin/src/rules/prefer-function-type.ts 97.18% <0.00%> (ø)
...n/src/rules/no-non-null-asserted-optional-chain.ts 46.66% <0.00%> (ø)
...t-plugin/src/rules/no-meaningless-void-operator.ts 100.00% <0.00%> (ø)
...plugin/src/rules/explicit-module-boundary-types.ts 91.04% <0.00%> (ø)
...c/rules/no-non-null-asserted-nullish-coalescing.ts 91.66% <0.00%> (ø)
...t-plugin/src/rules/adjacent-overload-signatures.ts 95.34% <0.00%> (ø)
...eslint-plugin/src/rules/consistent-type-imports.ts 94.26% <0.00%> (ø)
.../eslint-plugin/src/rules/no-useless-constructor.ts 95.23% <0.00%> (ø)
...t-plugin/src/rules/prefer-reduce-type-parameter.ts 100.00% <0.00%> (ø)
... and 144 more

Esqarrouth
Esqarrouth previously approved these changes May 23, 2022
bradzacher
bradzacher previously approved these changes May 25, 2022
Copy link
Member

@bradzacher bradzacher left a 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;}
}

@JoshuaKGoldberg
Copy link
Member Author

I'm still planning on getting to this, btw - likely on my Twitch stream tomorrow.

@JoshuaKGoldberg JoshuaKGoldberg dismissed stale reviews from bradzacher and Esqarrouth via a917483 May 31, 2022 19:10
bradzacher
bradzacher previously approved these changes Jun 1, 2022
@bradzacher
Copy link
Member

200

@bradzacher bradzacher merged commit 8698e80 into typescript-eslint:main Jun 4, 2022
@JoshuaKGoldberg JoshuaKGoldberg deleted the no-extraneous-class-docs branch June 4, 2022 19:52
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Documentation ("docs") that needs adding/updating
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Docs: [no-extraneous-class] Explain why the rule is useful
4 participants