Skip to content

Commit

Permalink
fix(eslint-plugin): [no-base-to-string] make error message more nuanc…
Browse files Browse the repository at this point in the history
…ed (#9281)

* refactor(eslint-plugin): [no-base-to-string] make error message more nuanced

* Fix test
  • Loading branch information
Josh-Cena committed Jun 5, 2024
1 parent ae3cec5 commit cb1720d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/eslint-plugin/docs/rules/no-base-to-string.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import TabItem from '@theme/TabItem';
> See **https://typescript-eslint.io/rules/no-base-to-string** for documentation.
JavaScript will call `toString()` on an object when it is converted to a string, such as when `+` adding to a string or in `${}` template literals.
The default Object `.toString()` returns `"[object Object]"`, which is often not what was intended.
The default Object `.toString()` uses the format `"[object Object]"`, which is often not what was intended.
This rule reports on stringified values that aren't primitives and don't define a more useful `.toString()` method.

> Note that `Function` provides its own `.toString()` that returns the function's code.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import TabItem from '@theme/TabItem';
> See **https://typescript-eslint.io/rules/restrict-template-expressions** for documentation.
JavaScript automatically [converts an object to a string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#string_coercion) in a string context, such as when concatenating it with a string using `+` or embedding it in a template literal using `${}`.
The default `toString()` method of objects returns `"[object Object]"`, which is often not what was intended.
The default `toString()` method of objects uses the format `"[object Object]"`, which is often not what was intended.
This rule reports on values used in a template literal string that aren't strings, optionally allowing other data types that provide useful stringification results.

:::note
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/no-base-to-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default createRule<Options, MessageIds>({
},
messages: {
baseToString:
"'{{name}}' {{certainty}} evaluate to '[object Object]' when stringified.",
"'{{name}}' {{certainty}} use Object's default stringification format ('[object Object]') when stringified.",
},
schema: [
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cb1720d

Please sign in to comment.