-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Enhancement: [restrict-template-expressions] option to allow string[] #6203
Comments
I don't agree at all. The spirit of this rule is to enforce you are producing good, user-facing strings - IMO an unspaced, comma delimited string definitely is NOT a good, user-facing string. |
From the reasoning provided in the docs for this rule "This rule reports on values used in a template literal string that aren't primitives and don't define a more useful .toString() method.", I think that Array does provide a "useful" toString implementation. So yes, perhaps not what you want in "your opinion" - which is why I think it makes a good option, when someone else wants to configure the rule to follow their opinion. By the logic of your opinion, the type any will very often not produce good user facing strings, and yet that is an option for this rule. |
I strongly disagree. I think it is a fair statement to say that |
If you were using a public product and saw a lit of options displayed like "Foo,Bar,Baz", you would for sure look at that and go "someone incorrectly concatenated their string". It's simply not something that's correct when writing latin text - a comma is always proceeded by a space. This issue has not received additional feedback or reactions from the community in a few months, so I'm going to close it. |
I want to display a comma-separated list of valid values in my internal log messages. Right now, I have to do this to workaround this eslint rule being too strict:
why are you so quick to dismiss these use cases? Of course, if you are presenting to the public, I would not want to enable the option to support Understood your point about lack of feedback or reaction from the community, but it has only been open for 1 month and this was over the holiday period so community engagement may not be as high as normal. Would you be open to a PR adding this or do you disagree that this option should be even added? |
I'd +1 the use case of an opt-in option to allow |
I does seem to me that seeing such violations of the current rule in the typescript codebase indicates that there are enough differing opinions on what is a suitable string representation to make it at least an option to the rule. Thanks for reopening this. I would much prefer turning on this option instead of peppering the logging code with eslint ignore directives. |
The big delineation is between user-facing and developer-facing strings. Josh's example from the TS codebase is an example of a developer-facing string - it's not even shown to the users of TS (who themselves are developers) - it's only shown internally within TS's tests. The issue you've got is that there is no way to provide the lint rule with the required context that delineates between developer-facing and user-facing strings. This is context only a human can build. So you're left with two options:
The thing I've learned over the years is that false positives are much better than false negatives - always. False negatives allow bugs to enter your code. They reduce user trust in the linting and seed doubt about the accuracy of rules. So the question is - are there enough examples of codebases where they always want to allow arrays in template strings to justify building out an option? Well this issue has been open for 8 months and has had a total of 4 users chime in. This is very low - which suggests that it's not something that a lot of the community cares about. As such, I am going to close this issue. |
That's fair, I think it's probably the right decision. Could I just ask, why the same logic does not apply to the options allowAny, allowNullish and allowRegExp all of which produce strings that most users would likely see as an error? (Keeping these options because they are "already implemented" is probably reasonable, but do you not agree that the logic you are using now was not applied at the time those options were originally created?) |
I definitely hate The
There's also something to be said for this project's growth - ~4y ago we had ~150k weekly DLs - so we were really small and accepting a lot of questionable things because we didn't think TOO deeply, we didn't know any better and we were happy to be growing. |
Before You File a Proposal Please Confirm You Have Done The Following...
My proposal is suitable for this project
Link to the rule's documentation
https://typescript-eslint.io/rules/restrict-template-expressions/
Description
Using an Array as a template literal gets this error:
the toString method when called returns a comma delimited string, which is pretty much what you would want. I don't see much unexpected there that would need a warning, so the reasoning behind erroring on other types does not hold for Array (and probably other Array types too)
Fail
Pass
Additional Info
No response
The text was updated successfully, but these errors were encountered: