Enhancement: no-base-to-string -- close the String constructor loophole #6956
Labels
duplicate
This issue or pull request already exists
package: eslint-plugin
Issues related to @typescript-eslint/eslint-plugin
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://eslint.org/docs/latest/rules/no-restricted-syntax
Description
I've noticed folks getting around the no-base-to-string rule by using the
String
constructor.Fail
Pass
Additional Info
Banning the
String
constructor could probably be achieved throughno-restricted-syntax
, but I can't think of a reason anyone would use it in the first place except to get around this rule. Andno-restricted-syntax
doesn't mesh well with shared configs.The built-in
no-implicit-coercion
rule actually encourages the use ofString
. It's a blunt instrument that makes sense in JavaScript, where static analysis in most cases can't guarantee that.toString()
won't throw a runtime error.The
Number
constructor is similarly (ab)used. I have an idea of what to do about that, but one thing at a time.The text was updated successfully, but these errors were encountered: