Disallow plain toString calls as part of no-implicit-coercion
See original GitHub issueWhat rule do you want to change?
no-implicit-coercion
Does this change cause the rule to produce more or fewer warnings?
More
How will the change be implemented? (New option, new default behavior, etc.)?
The rule will report usage of .toString()
.
A new option toString
will be added. In a major release this option will be removed and behaviour will be merged with the existing string
option.
The following edge cases will not be reported:
foo?.toString()
foo.toString('ascii')
foo.toString
This may change behaviour of the code. For example null.toString()
will be converted to String(null)
, which will no longer throw.
Please provide some example code that this change will affect:
foo.toString()
What does the rule currently do for this code?
It will report the foo.toString()
call expression.
What will the rule do after it’s changed?
The code will be replaced with the following:
String(foo)
Are you willing to submit a pull request to implement this change?
Yes
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
@remcohaszing this sounds like a situation where creating a custom rule is the best approach.
Closing, as there is no change to be made here.