Skip to content

feat(eslint-plugin): [no-base-to-string] prevent stringifying arrays with elements that cannot be stringified #10114

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

Closed

Conversation

ronami
Copy link
Member

@ronami ronami commented Oct 9, 2024

PR Checklist

Overview

This PR addresses #3388 and adds checks calling .join() on an array that not all of its elements can be stringified correctly:

function test(type: {}[]) {
  return type.join();
}

I've also included failing in the case of trying to stringify an array (without .join()):

function test(type: {}[]) {
  return `${type}`;
}

function test(type: {}[]) {
  return type.toString();
}

Please note that I haven't put this behind an option, so this is technically a breaking change, although according to the docs:

A change to the plugins shall be considered breaking if it will require the user to change their config. More specifically:

  • Changes the default behavior of a rule in such a way that causes new reports in a large set of cases in an average codebase.

Please let me know if I should put this behind an option.

@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 Oct 9, 2024

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 51bd1b7
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/67082c83471f3e0008d5440e
😎 Deploy Preview https://deploy-preview-10114--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 5 from production)
Accessibility: 100 (no change from production)
Best Practices: 92 (no change from production)
SEO: 90 (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.

@ronami ronami changed the title No base to string array join feat(eslint-plugin): [no-base-to-string] prevent stringifying arrays with elements that cannot be stringified Oct 9, 2024
Copy link

codecov bot commented Oct 9, 2024

Codecov Report

Attention: Patch coverage is 96.77419% with 1 line in your changes missing coverage. Please review.

Project coverage is 86.11%. Comparing base (3f02687) to head (51bd1b7).
Report is 23 commits behind head on main.

Files with missing lines Patch % Lines
...kages/eslint-plugin/src/rules/no-base-to-string.ts 95.83% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10114      +/-   ##
==========================================
+ Coverage   86.07%   86.11%   +0.03%     
==========================================
  Files         428      429       +1     
  Lines       14939    14993      +54     
  Branches     4333     4346      +13     
==========================================
+ Hits        12859    12911      +52     
+ Misses       1735     1734       -1     
- Partials      345      348       +3     
Flag Coverage Δ
unittest 86.11% <96.77%> (+0.03%) ⬆️

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

Files with missing lines Coverage Δ
...t-plugin/src/rules/prefer-reduce-type-parameter.ts 100.00% <100.00%> (ø)
packages/eslint-plugin/src/util/isArrayType.ts 100.00% <100.00%> (ø)
...kages/eslint-plugin/src/rules/no-base-to-string.ts 95.29% <95.83%> (+0.13%) ⬆️

... and 10 files with indirect coverage changes

@ronami
Copy link
Member Author

ronami commented Oct 13, 2024

Closing as it takes me a bit longer than I thought to finish this. I'll re-open when the PR is ready for review.

@ronami ronami closed this Oct 13, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[no-base-to-string] add option to prevent usage of Array .join on non-toString things
1 participant