Skip to content

fix(eslint-plugin): [no-base-to-string] check array generic type #10437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

ronami
Copy link
Member

@ronami ronami commented Dec 1, 2024

PR Checklist

Overview

This PR addresses #10430 and adjusts the rule so it reports on the following ways of stringifying arrays (to my understanding, all are effectively the same as calling array.join('')):

// '[object Object],[object Object]'
String([{}, {}]);

// '[object Object],[object Object]'
`${[{}, {}]}`;

// '[object Object],[object Object]'
[{}, {}].toString();

Note that only the first (string coercion) is mentioned on the original issue, but it made sense to support the other ones too.

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @ronami!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint.

Copy link

netlify bot commented Dec 1, 2024

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 5ebba43
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/6772e202ca061e0008481ed0
😎 Deploy Preview https://deploy-preview-10437--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 99 (🟢 up 8 from production)
Accessibility: 100 (no change from production)
Best Practices: 92 (no change from production)
SEO: 98 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

nx-cloud bot commented Dec 1, 2024

View your CI Pipeline Execution ↗ for commit 5ebba43.

Command Status Duration Result
nx run-many --target=build --exclude website --... ✅ Succeeded 2s View ↗
nx run-many --target=clean ✅ Succeeded 10s View ↗

☁️ Nx Cloud last updated this comment at 2024-12-30 18:48:49 UTC

@ronami ronami force-pushed the no-base-to-string-check-array-type branch from 694ada9 to 1052e4c Compare December 1, 2024 21:09
Copy link

codecov bot commented Dec 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.90%. Comparing base (24a1510) to head (5ebba43).
Report is 56 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10437      +/-   ##
==========================================
+ Coverage   86.77%   86.90%   +0.13%     
==========================================
  Files         444      446       +2     
  Lines       15335    15506     +171     
  Branches     4468     4518      +50     
==========================================
+ Hits        13307    13476     +169     
- Misses       1673     1675       +2     
  Partials      355      355              
Flag Coverage Δ
unittest 86.90% <100.00%> (+0.13%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...kages/eslint-plugin/src/rules/no-base-to-string.ts 97.05% <100.00%> (+0.18%) ⬆️

... and 29 files with indirect coverage changes

@ronami ronami marked this pull request as ready for review December 1, 2024 22:19
@ronami ronami marked this pull request as draft December 1, 2024 22:54
@ronami ronami marked this pull request as ready for review December 2, 2024 16:37
Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What Kirk said ✨

@JoshuaKGoldberg JoshuaKGoldberg added the awaiting response Issues waiting for a reply from the OP or another party label Dec 14, 2024
@github-actions github-actions bot removed the awaiting response Issues waiting for a reply from the OP or another party label Dec 15, 2024
Copy link
Member

@kirkwaiblinger kirkwaiblinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(leaving a review in order for the label automations to work right)

@kirkwaiblinger kirkwaiblinger added the awaiting response Issues waiting for a reply from the OP or another party label Dec 17, 2024
… faulty tests to not check against the {} type
@github-actions github-actions bot removed the awaiting response Issues waiting for a reply from the OP or another party label Dec 18, 2024
Copy link
Member

@kirkwaiblinger kirkwaiblinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question, otherwise looks great to me!

@kirkwaiblinger kirkwaiblinger added the awaiting response Issues waiting for a reply from the OP or another party label Dec 28, 2024
@github-actions github-actions bot removed the awaiting response Issues waiting for a reply from the OP or another party label Dec 30, 2024
Copy link
Member

@kirkwaiblinger kirkwaiblinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kirkwaiblinger kirkwaiblinger added the 1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge label Dec 30, 2024
Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So many tests! 🙌

@JoshuaKGoldberg JoshuaKGoldberg merged commit c27399b into typescript-eslint:main Dec 30, 2024
62 of 65 checks passed
@ronami ronami deleted the no-base-to-string-check-array-type branch December 30, 2024 19:03
OlivierZal pushed a commit to OlivierZal/typescript-eslint that referenced this pull request Dec 30, 2024
…escript-eslint#10437)

* initial implementation

* add missing test

* undo unrelated change

* also cover [].toString()

* refactor

* respect the ignoredTypeNames option

* update existing tests to use a helper for checking arrays, and change faulty tests to not check against the {} type

* don't use a test helper for creating tests dynamically

* remove unnecessary check
renovate bot added a commit to mmkal/eslint-plugin-mmkal that referenced this pull request Jan 6, 2025
##### [v8.19.1](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8191-2025-01-06)

##### 🩹 Fixes

-   **eslint-plugin:** \[no-unnecessary-type-assertion] handle literal types ([#10523](typescript-eslint/typescript-eslint#10523))
-   **eslint-plugin:** \[no-deprecated] doesn't report on shorthand property in an object expression ([#10550](typescript-eslint/typescript-eslint#10550))
-   **eslint-plugin:** \[strict-boolean-expressions] remove remaining (unsafe) autofixes ([#10548](typescript-eslint/typescript-eslint#10548))
-   **eslint-plugin:** \[no-shadow] report correctly on parameters of functions declared with the `declare` keyword ([#10543](typescript-eslint/typescript-eslint#10543))
-   **eslint-plugin:** \[no-base-to-string] check array generic type ([#10437](typescript-eslint/typescript-eslint#10437))

##### ❤️ Thank You

-   Kirk Waiblinger
-   mdm317
-   Ronen Amiel
-   Yukihiro Hasegawa [@y-hsgw](https://github.com/y-hsgw)

You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Jan 6, 2025
| datasource | package                          | from   | to     |
| ---------- | -------------------------------- | ------ | ------ |
| npm        | @typescript-eslint/eslint-plugin | 8.19.0 | 8.19.1 |
| npm        | @typescript-eslint/parser        | 8.19.0 | 8.19.1 |


## [v8.19.1](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8191-2025-01-06)

##### 🩹 Fixes

-   **eslint-plugin:** \[no-unnecessary-type-assertion] handle literal types ([#10523](typescript-eslint/typescript-eslint#10523))
-   **eslint-plugin:** \[no-deprecated] doesn't report on shorthand property in an object expression ([#10550](typescript-eslint/typescript-eslint#10550))
-   **eslint-plugin:** \[strict-boolean-expressions] remove remaining (unsafe) autofixes ([#10548](typescript-eslint/typescript-eslint#10548))
-   **eslint-plugin:** \[no-shadow] report correctly on parameters of functions declared with the `declare` keyword ([#10543](typescript-eslint/typescript-eslint#10543))
-   **eslint-plugin:** \[no-base-to-string] check array generic type ([#10437](typescript-eslint/typescript-eslint#10437))

##### ❤️ Thank You

-   Kirk Waiblinger
-   mdm317
-   Ronen Amiel
-   Yukihiro Hasegawa [@y-hsgw](https://github.com/y-hsgw)

You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 7, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: [no-base-to-string] check array generic type
3 participants