Skip to content

Commit cb1720d

Browse files
authored
fix(eslint-plugin): [no-base-to-string] make error message more nuanced (typescript-eslint#9281)
* refactor(eslint-plugin): [no-base-to-string] make error message more nuanced * Fix test
1 parent ae3cec5 commit cb1720d

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

packages/eslint-plugin/docs/rules/no-base-to-string.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import TabItem from '@theme/TabItem';
1010
> See **https://typescript-eslint.io/rules/no-base-to-string** for documentation.
1111
1212
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.
13-
The default Object `.toString()` returns `"[object Object]"`, which is often not what was intended.
13+
The default Object `.toString()` uses the format `"[object Object]"`, which is often not what was intended.
1414
This rule reports on stringified values that aren't primitives and don't define a more useful `.toString()` method.
1515

1616
> Note that `Function` provides its own `.toString()` that returns the function's code.

packages/eslint-plugin/docs/rules/restrict-template-expressions.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import TabItem from '@theme/TabItem';
1010
> See **https://typescript-eslint.io/rules/restrict-template-expressions** for documentation.
1111
1212
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 `${}`.
13-
The default `toString()` method of objects returns `"[object Object]"`, which is often not what was intended.
13+
The default `toString()` method of objects uses the format `"[object Object]"`, which is often not what was intended.
1414
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.
1515

1616
:::note

packages/eslint-plugin/src/rules/no-base-to-string.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default createRule<Options, MessageIds>({
2828
},
2929
messages: {
3030
baseToString:
31-
"'{{name}}' {{certainty}} evaluate to '[object Object]' when stringified.",
31+
"'{{name}}' {{certainty}} use Object's default stringification format ('[object Object]') when stringified.",
3232
},
3333
schema: [
3434
{

packages/eslint-plugin/tests/docs-eslint-output-snapshots/no-base-to-string.shot

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)