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 option allow any #1762

Conversation

itowlson
Copy link
Contributor

Fixes #1660.

Sometimes it can be useful to allow the any type in template expressions. Although a typescript-eslint user will usually prefer the stronger checking, there are times when the weaker checking is useful if the author is confident the value will stringise sanely, for example in codebases with significant legacy, or where there is a lot of handling of untyped values, or in scenarios such as the catch case outlined in #1660.

This PR provides an option not to warn if an any value is dumped in a template expression. The option is off by default because, as mentioned in the issue, the goal of the rule is "to make sure you're not doing something that might dump garbage into your template strings," and nothing is more able to dump garbage than any...!

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @itowlson!

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. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day.

@bradzacher bradzacher changed the title feat(eslint-plugin): allow 'any' in template expressions feat(eslint-plugin): [restrict-template-expressions] add option allow any Mar 18, 2020
@bradzacher bradzacher added the enhancement: plugin rule option New rule option for an existing eslint-plugin rule label Mar 18, 2020
@codecov
Copy link

codecov bot commented Mar 20, 2020

Codecov Report

Merging #1762 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #1762   +/-   ##
=======================================
  Coverage   94.48%   94.48%           
=======================================
  Files         162      162           
  Lines        7487     7490    +3     
  Branches     2146     2148    +2     
=======================================
+ Hits         7074     7077    +3     
  Misses        178      178           
  Partials      235      235           
Flag Coverage Δ
#unittest 94.48% <100.00%> (+<0.01%) ⬆️
Impacted Files Coverage Δ
...-plugin/src/rules/restrict-template-expressions.ts 100.00% <100.00%> (ø)

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.

lgtm thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement: plugin rule option New rule option for an existing eslint-plugin rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[restrict-template-expressions] Errors if type is any
2 participants