Skip to content
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

feat(eslint-plugin): [consistent-type-assertions] add arrayLiteralTypeAssertions options #10565

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

yeonjuan
Copy link
Contributor

@yeonjuan yeonjuan commented Dec 29, 2024

PR Checklist

Overview

This pr addresses #6374 and adds arrayLiteralTypeAssertions option to the consistent-type-assertions rule.
It starts from #6749, which was previously closed, and adds allow-as-parameter to the arrayLiteralTypeAssertions option. (#6749 (comment))

Co-authored-by: @danvk

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @yeonjuan!

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 Dec 29, 2024

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit b64df60
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/677380a8ca061e00080b8cc6
😎 Deploy Preview https://deploy-preview-10565--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: 93 (🟢 up 2 from production)
Accessibility: 100 (no change from production)
Best Practices: 92 (no change from production)
SEO: 98 (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 Dec 29, 2024

View your CI Pipeline Execution ↗ for commit b64df60.

Command Status Duration Result
nx test eslint-plugin --coverage=false ✅ Succeeded 7m 17s View ↗
nx test eslint-plugin ✅ Succeeded 5m 56s View ↗
nx test type-utils --coverage=false ✅ Succeeded <1s View ↗
nx test visitor-keys --coverage=false ✅ Succeeded <1s View ↗
nx test rule-tester --coverage=false ✅ Succeeded <1s View ↗
nx test typescript-estree --coverage=false ✅ Succeeded <1s View ↗
nx run types:build ✅ Succeeded <1s View ↗
nx test utils --coverage=false ✅ Succeeded <1s View ↗
Additional runs (24) ✅ Succeeded ... View ↗

☁️ Nx Cloud last updated this comment at 2024-12-31 05:42:15 UTC

Copy link

codecov bot commented Dec 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.92%. Comparing base (3ae4148) to head (b64df60).
Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10565      +/-   ##
==========================================
+ Coverage   86.86%   86.92%   +0.05%     
==========================================
  Files         445      446       +1     
  Lines       15455    15521      +66     
  Branches     4507     4524      +17     
==========================================
+ Hits        13425    13491      +66     
  Misses       1675     1675              
  Partials      355      355              
Flag Coverage Δ
unittest 86.92% <100.00%> (+0.05%) ⬆️

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

Files with missing lines Coverage Δ
...int-plugin/src/rules/consistent-type-assertions.ts 95.89% <100.00%> (+1.06%) ⬆️

... and 10 files with indirect coverage changes

@yeonjuan yeonjuan marked this pull request as ready for review December 29, 2024 10:00
Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

Lovely! The logic all makes sense and I like how the array and object checks are now mirrored. Great.

Requesting changes on some docs and testing please. 🚀

print?.(<Foo>[5]);
print?.call(<Foo>[5]);
print\`\${<Foo>[5]}\`;
`;
Copy link
Member

Choose a reason for hiding this comment

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

😬 I know this is existing code with its own pattern, but - we're trying to move away from auto-generated tests. They're much harder to statically analyze and tend to batch together a lot of redundant tests with multiple edge cases per test. Could you please keep to manually written tests for the new code?

Since all this change does functionally is add a new typed of checked assertion (arrays), I think adding a test per each of these lines should be fine.

Copy link
Contributor Author

@yeonjuan yeonjuan Dec 31, 2024

Choose a reason for hiding this comment

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

Sounds good,

I think adding a test per each of these lines should be fine.

Does this mean writing a test like the one below?

    {
      code: `
const x = [] as string[];
const x = ['a'] as string[];
const x = [] as Array<string>;
const x = ['a'] as Array<string>;
const x = [Math.random() ? 'a' : 'b'] as 'a'[];
      `, options: [
        {
          assertionStyle: "as"
        }
      ]
    }

@JoshuaKGoldberg JoshuaKGoldberg added the awaiting response Issues waiting for a reply from the OP or another party label Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting response Issues waiting for a reply from the OP or another party
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhancement: [consistent-type-assertions] Prefer type annotation over assertion for arrays
2 participants