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): [restrict-template-expressions] add allowArray option #8389

Merged

Conversation

abrahamguo
Copy link
Contributor

@abrahamguo abrahamguo commented Feb 6, 2024

PR Checklist

Overview

I've added a new allowArray option that applies the existing checks from restrict-template-expressions recursively (i.e. no undefineds, etc.).

I haven't added unit tests yet but I'd like to begin receiving feedback on this change.

@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 Feb 6, 2024

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 9a3c36a
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/65eef16041aa3f0008d14d3d
😎 Deploy Preview https://deploy-preview-8389--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: 94 (🟢 up 4 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.

@abrahamguo abrahamguo changed the title WAdd allowArray option for restrict-template-expressions feat: Add allowArray option for restrict-template-expressions Feb 6, 2024
@abrahamguo abrahamguo changed the title feat: Add allowArray option for restrict-template-expressions feat: add allowArray option for restrict-template-expressions Feb 12, 2024
Copy link

codecov bot commented Feb 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.20%. Comparing base (c0e3267) to head (9a3c36a).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8389      +/-   ##
==========================================
- Coverage   87.21%   87.20%   -0.01%     
==========================================
  Files         251      251              
  Lines       12315    12308       -7     
  Branches     3883     3875       -8     
==========================================
- Hits        10740    10733       -7     
  Misses       1305     1305              
  Partials      270      270              
Flag Coverage Δ
unittest 87.20% <100.00%> (-0.01%) ⬇️

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

Files Coverage Δ
...-plugin/src/rules/restrict-template-expressions.ts 100.00% <100.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.

This is a clever way of automating the repeated parts 🙂. Nicely done.

...but like many clever code things, there was a difficulty cost of reading it at first. I played around with it locally and found it easier to read through with a few small structural changes. What do you think?

Aaron Ashmore in character in some sci fi show saying "Nifty!", impressed

@JoshuaKGoldberg JoshuaKGoldberg added the awaiting response Issues waiting for a reply from the OP or another party label Feb 23, 2024
@github-actions github-actions bot removed the awaiting response Issues waiting for a reply from the OP or another party label Feb 26, 2024
JoshuaKGoldberg
JoshuaKGoldberg previously approved these changes Mar 5, 2024
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.

Super, looks good to me! Thanks for all the code tinkering. 😄

Leaving open with 1 approval as I know at least @bradzacher has had well-informed thoughts on this family of rules in the past.

@JoshuaKGoldberg JoshuaKGoldberg added the 1 approval PR that a maintainer has LGTM'd - any maintainer can merge this when ready label Mar 5, 2024
@bradzacher bradzacher changed the title feat: add allowArray option for restrict-template-expressions feat(eslint-plugin): [restrict-template-expressions] add allowArray option Mar 16, 2024
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.

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
recursivelyCheckType(type.getNumberIndexType()!),
],
// eslint-disable-next-line @typescript-eslint/internal/prefer-ast-types-enum
Copy link
Member

Choose a reason for hiding this comment

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

@JoshuaKGoldberg - Originally this rule's purpose was to prevent code like node.type === 'string'.
Given we now have the no-unsafe-enum-comparison rule - do you think this internal rule still has value? WDYT about deleting it? (we already have nuec turned on via the recommended config)

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I'd be in favor of that. It wouldn't be the first example of an internal lint rule ending up as a subset of a general good one.

@bradzacher bradzacher merged commit e4b1672 into typescript-eslint:main Mar 16, 2024
59 of 61 checks passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1 approval PR that a maintainer has LGTM'd - any maintainer can merge this when ready
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhancement: [restrict-template-expressions] More permissive type check
3 participants