Skip to content

feat(eslint-plugin): [consistent-type-assertions] add arrayLiteralTypeAssertions option #6749

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

Conversation

danvk
Copy link
Collaborator

@danvk danvk commented Mar 23, 2023

PR Checklist

Overview

This PR adds an arrayLiteralTypeAssertions option to the consistent-type-assertions rule as described in the linked issue. This uses the same auto-fixer as the objectLiteralTypeAssertions option.

I didn't include an equivalent of the "allow-as-parameter" option but I can do so if there's a need.

If I may step on my soapbox for a moment:

  1. The objectLiteralTypeAssertions option (and this new one) are an awkward fit for the consistent-type-assertions, which you would expect to just enforce consistency between x as T and <T>x. Both options would make more sense in a distinct rule that bans type assertions (rather than enforcing a consistent style).
  2. I'm not sure why you'd ever want to enable objectLiteralTypeAssertions but not arrayLiteralTypeAssertions, or vice versa. It also feels odd that we're singling out these two types but allowing constructs with other types such as const x = 'foo' as string;

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @danvk!

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.

@netlify
Copy link

netlify bot commented Mar 23, 2023

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit fd20281
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/641ccf88ba6eac0008050326
😎 Deploy Preview https://deploy-preview-6749--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.

@danvk danvk changed the title feat(consistent-type-assertions): Add arrayLiteralTypeAssertions option to consistent-type-assertions rule feat(eslint-plugin): Add arrayLiteralTypeAssertions option to consistent-type-assertions rule Mar 23, 2023
@danvk danvk changed the title feat(eslint-plugin): Add arrayLiteralTypeAssertions option to consistent-type-assertions rule feat(eslint-plugin): [consistent-type-assertions] add arrayLiteralTypeAssertions option Mar 23, 2023
@codecov
Copy link

codecov bot commented Mar 23, 2023

Codecov Report

Merging #6749 (fd20281) into main (c166cc9) will increase coverage by 0.01%.
The diff coverage is 95.23%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6749      +/-   ##
==========================================
+ Coverage   87.24%   87.25%   +0.01%     
==========================================
  Files         383      383              
  Lines       13080    13091      +11     
  Branches     3845     3849       +4     
==========================================
+ Hits        11411    11422      +11     
  Misses       1302     1302              
  Partials      367      367              
Flag Coverage Δ
unittest 87.25% <95.23%> (+0.01%) ⬆️

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

Impacted Files Coverage Δ
...int-plugin/src/rules/consistent-type-assertions.ts 93.84% <95.23%> (+1.25%) ⬆️

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.

Sorry this took so long to get to @danvk - the implementation looks very clean and the tests are thorough. Thanks for sending it in!

Just requesting changes on the missing "allow-as-parameter" equivalent.

type OptUnion =
| {
assertionStyle: 'as' | 'angle-bracket';
objectLiteralTypeAssertions?: 'allow' | 'allow-as-parameter' | 'never';
arrayLiteralTypeAssertions?: 'allow' | 'never';
Copy link
Member

Choose a reason for hiding this comment

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

I didn't include an equivalent of the "allow-as-parameter" option but I can do so if there's a need.

Yeah it feels weird to have one without the other... Could you please?

@JoshuaKGoldberg
Copy link
Member

If I may step on my soapbox for a moment

You most certainly may 😄 I agree with your points. It does seem odd to be so specific, especially since it means the exception doesn't cover 'foo' as string & co. Could I ask you to file a new issue with your proposed changes? It might end up being a breaking change, so we might have to wait until v7 to get it in.

@JoshuaKGoldberg JoshuaKGoldberg added the awaiting response Issues waiting for a reply from the OP or another party label Apr 8, 2023
@bradzacher bradzacher added the enhancement: plugin rule option New rule option for an existing eslint-plugin rule label Apr 10, 2023
@JoshuaKGoldberg JoshuaKGoldberg added the stale PRs or Issues that are at risk of being or have been closed due to inactivity for a prolonged period label Jul 16, 2023
@JoshuaKGoldberg
Copy link
Member

👋 Hey @danvk! Just checking in, is this still something you have time for? No worries if not - I just don't want to leave it hanging.

@JoshuaKGoldberg
Copy link
Member

Closing this PR as it's been stale for a few months without activity. Feel free to reopen @danvk if you have time - but no worries if not! If anybody wants to drive it forward, please do post your own PR - and if you use this as a start, consider adding Co-authored-by: @danvk at the end of your PR description. Thanks! 😊

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
awaiting response Issues waiting for a reply from the OP or another party enhancement: plugin rule option New rule option for an existing eslint-plugin rule stale PRs or Issues that are at risk of being or have been closed due to inactivity for a prolonged period
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants