8000 chore: enable `unicorn/prefer-ternary` by abrahamguo · Pull Request #9886 · typescript-eslint/typescript-eslint · GitHub
[go: up one dir, main page]

Skip to content

chore: enable unicorn/prefer-ternary #9886

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
wants to merge 4 commits into from

Conversation

abrahamguo
Copy link
Contributor

PR Checklist

Overview

Enable unicorn/prefer-ternary (docs).
I believe many of these cases are much simpler than they were previously. Several lets could be changed to consts — always a good thing.
I recommend viewing the diff with whitespace hidden 😉

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @abrahamguo!

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.

Copy link
netlify bot commented Aug 27, 2024

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit d9decd7
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/66d7bd62df293c0008fc626e
😎 Deploy Preview https://deploy-preview-9886--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 99 (no change from production)
Accessibility: 100 (no change from production)
Best Practices: 92 (no change from production)
SEO: 90 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

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

Copy link
nx-cloud bot commented Aug 27, 2024

@Josh-Cena
Copy link
Member

I thought from the issue that pretty much everyone were negative/ambivalent on this rule? I personally wouldn't want it enforced though I may enjoy its style.

Copy link
codecov bot commented Aug 27, 2024

Codecov Report

Attention: Patch coverage is 86.20690% with 4 lines in your changes missing coverage. Please review.

Project coverage is 88.11%. Comparing base (6f24fe6) to head (d9decd7).
Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
packages/typescript-estree/src/convert.ts 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9886      +/-   ##
==========================================
- Coverage   88.12%   88.11%   -0.02%     
==========================================
  Files         406      406              
  Lines       13951    13920      -31     
  Branches     4076     4073       -3     
==========================================
- Hits        12294    12265      -29     
+ Misses       1344     1342       -2     
  Partials      313      313              
Flag Coverage Δ
unittest 88.11% <86.20%> (-0.02%) ⬇️

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

Files with missing lines Coverage Δ
.../eslint-plugin/src/rules/class-methods-use-this.ts 86.66% <100.00%> (-0.29%) ⬇️
...eslint-plugin/src/rules/consistent-type-exports.ts 95.00% <100.00%> (-0.41%) ⬇️
...eslint-plugin/src/rules/consistent-type-imports.ts 94.67% <100.00%> (-0.07%) ⬇️
...es/eslint-plugin/src/rules/prefer-function-type.ts 96.96% <100.00%> (-0.14%) ⬇️
...lint-plugin/src/rules/prefer-nullish-coalescing.ts 100.00% <100.00%> (ø)
.../rules/prefer-optional-chain-utils/analyzeChain.ts 100.00% <100.00%> (ø)
...ackages/eslint-plugin/src/rules/prefer-readonly.ts 97.82% <100.00%> (-0.04%) ⬇️
...plugin/src/rules/prefer-string-starts-ends-with.ts 97.42% <100.00%> (-0.03%) ⬇️
packages/eslint-plugin/src/rules/return-await.ts 97.34% <100.00%> (-0.05%) ⬇️
packages/utils/src/eslint-utils/applyDefault.ts 100.00% <100.00%> (ø)
... and 2 more

@abrahamguo
Copy link
Contributor Author

Sure thing! I wanted to open a PR since I felt it might help to see the actual changes recommended and gather a bit more feedback as to whether it would be beneficial to enforce. I'm also open to removing the lint rule and keeping the changes, a la #9640

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm kind of surprised this doesn't check this code:

const typeArgumentsText = (() => {
if (node.typeArguments == null) {
return '';
}
return sourceCode.getText(node.typeArguments);
})();

which could just be converted to

        const typeArgumentsText =
          node.typeArguments == null
            ? ''
            : sourceCode.getText(node.typeArguments);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

My 2c - all these changes are less clear code. I don't think compacting the code down improves anything and I think instead you lose out. So I'm a -1 for this rule.

@@ -193,46 +193,20 @@ export default createRule<Options, MessageIds>({
const allExportNames = report.typeBasedSpecifiers.map(
specifier => specifier.local.name,
);

if (allExportNames.length === 1) {
const exportNames = allExportNames[0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line was lost in the transition.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was actually not needed, because formatWordList is able to handle a 1-length array

@bradzacher
Copy link
Member

@typescript-eslint/triage-team - do we have the consensus to reject this rule? Based on thumbs up I think we do but just confirming before I close.

@Josh-Cena
Copy link
Member

+1 to reject

@bradzacher bradzacher closed this Sep 4, 2024
@abrahamguo abrahamguo deleted the prefer-ternary branch September 5, 2024 12:03
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0