Skip to content

feat: add allow option for restrict-template-expressions #8556

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

Conversation

abrahamguo
Copy link
Contributor

@abrahamguo abrahamguo commented Feb 27, 2024

PR Checklist

Overview

Building on the work from #8389, which @JoshuaKGoldberg has been reviewing, this PR ports the ignoredTypeNames option from no-base-to-string into restrict-template-expressions. I'm open to further discussion about this, as this update definitely blurs the line between the two rules.

@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 27, 2024

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit d8509be
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/66d62c16df293c0008bcc03d
😎 Deploy Preview https://deploy-preview-8556--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.

@JoshuaKGoldberg JoshuaKGoldberg requested review from bradzacher and removed request for bradzacher March 18, 2024 12:56
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.

Thanks for sending this in - but would you be open to filing an issue? I think we'd want to discuss this a bit before landing it.

Also, just a couple preliminary review thoughts if it does land:

  • Unit tests?
  • I think we'd want to share the default value of ignoredTypeNames in a constant so it doesn't risk getting out of sync

@JoshuaKGoldberg JoshuaKGoldberg added the awaiting response Issues waiting for a reply from the OP or another party label Mar 18, 2024
@JoshuaKGoldberg
Copy link
Member

Marking as a draft pending #8722's resolution.

@bradzacher bradzacher removed the awaiting response Issues waiting for a reply from the OP or another party label Aug 25, 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.

This is fantastic, great work @abrahamguo! Really clean implementation and I like the sharing of docs. Thanks!

I'll also want to wait on another review from @typescript-eslint/triage-team. The more we use the shared TypeOrValueSpecifier format the more review eyes we'll want on it.

IMO we should land this before #9875 and then I can adjust the docs there to fit this PR.

Captain Holt in Brooklyn 99 Happily clapping his hands together and shouting 'Hot damn!' with fiery steel caption font

@JoshuaKGoldberg JoshuaKGoldberg requested a review from a team August 25, 2024 16:40
@JoshuaKGoldberg JoshuaKGoldberg added the 1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge label Aug 25, 2024
Copy link
Member

@kirkwaiblinger kirkwaiblinger left a comment

Choose a reason for hiding this comment

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

Since #9875 ended up landing first, some merge conflicts will need to be addressed. Ping for another review pass after that is completed?

@kirkwaiblinger kirkwaiblinger added the awaiting response Issues waiting for a reply from the OP or another party label Aug 30, 2024
…estrict-template-expressions-ignoredtypenames
@github-actions github-actions bot removed 1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge awaiting response Issues waiting for a reply from the OP or another party labels Sep 2, 2024
@abrahamguo
Copy link
Contributor Author

Conflicts resolved and ready for re-review!

I am not clear why the one test is failing. It works locally for me.

@JoshuaKGoldberg
Copy link
Member

It's from the CI job that runs tests with the project service enabled:

TYPESCRIPT_ESLINT_PROJECT_SERVICE: true

Copying the failure here:

  ● restrict-template-expressions › valid › const msg = `arg = ${new URLSearchParams()}`;

    assert.strictEqual(received, expected)

    Expected value to strictly be equal to:
      0
    Received:
      1
    
    Message:
      Should have no errors but had 1: [
      {
        ruleId: '@rule-tester/restrict-template-expressions',
        severity: 2,
        message: 'Invalid type "URLSearchParams" of template literal expression.',
        line: 1,
        column: 22,
        nodeType: 'NewExpression',
        messageId: 'invalidType',
        endLine: 1,
        endColumn: 43
      }
    ]

You can directly test that file in packages/eslint-plugin with TYPESCRIPT_ESLINT_PROJECT_SERVICE=true yarn jest restrict-template-.

…estrict-template-expressions-ignoredtypenames
@abrahamguo
Copy link
Contributor Author

Hmm, looks like setting TYPESCRIPT_ESLINT_PROJECT_SERVICE=true causes it to bypass the tsconfig-withdom.json set in restrict-template-expressions.test.ts.

@abrahamguo
Copy link
Contributor Author

I've worked around this by ensuring that (similar to the new examples in the docs page) the unit tests only refer to the Error type, which is available with or without the DOM types.
URL and URLSearchParams are not shown in the docs code examples, nor in the unit tests, since they require DOM types in order to work properly.

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.

@JoshuaKGoldberg JoshuaKGoldberg added the 1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge label Sep 13, 2024
@@ -85,7 +85,7 @@ const msg2 = `arg = ${arg || 'not truthy'}`;

### `allowAny`

Whether to `any` typed values in template expressions.
Copy link
Member

Choose a reason for hiding this comment

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

lol

Copy link
Member

@kirkwaiblinger kirkwaiblinger left a comment

Choose a reason for hiding this comment

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

Peachy keen!

@JoshuaKGoldberg JoshuaKGoldberg merged commit af92611 into typescript-eslint:main Sep 16, 2024
61 checks passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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