question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Disallow plain toString calls as part of no-implicit-coercion

See original GitHub issue

What 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:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
nzakascommented, Nov 10, 2020

@remcohaszing this sounds like a situation where creating a custom rule is the best approach.

0reactions
nzakascommented, Nov 17, 2020

Closing, as there is no change to be made here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-implicit-coercion - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
4. Coercion - You Don't Know JS: Types & Grammar [Book]
Before we can explore explicit versus implicit coercion, we need to learn the basic rules that govern how values become either a string...
Read more >
is it possible to disable implicit ToString() call? - Stack Overflow
@bas - the problem is not that I want to use ToString() or I want to use default behavior. The problem is that...
Read more >
JavaScript The Tricky Parts: Part-1 - Samayun Miah Chowdhury
Defination : Type coercion is the process of converting value from one type to another (such as string to number, object to boolean,...
Read more >
Lua 5.1 Reference Manual
Names (also called identifiers) in Lua can be any string of letters, digits, ... This type corresponds to a block of raw memory...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found