Skip to content

fix(eslint-plugin): [restrict-plus-operands] report adding bigints to strings when allowNumberAndString is false #10737

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

0x31
Copy link
Contributor

@0x31 0x31 commented Jan 29, 2025

PR Checklist

Overview

If allowNumberAndString is set to false, restrict-plus-operands now reports when a bigint and a string are added, instead of just reporting for number and string. This is inline with the docs for allowNumberAndString:

Whether to allow bigint/number typed values and string typed values to be added together.

Example

eslintrc:

{
  "rules": {
    "@typescript-eslint/restrict-plus-operands": [
      "error",
      {
          "allowNumberAndString": false
      }
    ]
  }
}

Code snippet:

let fnBigint = (a: bigint, b: string) => a + b;

Warning

Operands of '+' operations must be a number or string, allowing a string + any of: any, boolean, null, RegExp, undefined. Got bigint + string.

…s string

When `allowNumberAndString: false` is set, adding bigints and strings should not be allowed
@typescript-eslint
Copy link
Contributor

Thanks for the PR, @0x31!

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 Jan 29, 2025

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 40eb372
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/679c19d49800d300082d006e
😎 Deploy Preview https://deploy-preview-10737--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 1 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 Jan 29, 2025

View your CI Pipeline Execution ↗ for commit 40eb372.

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

☁️ Nx Cloud last updated this comment at 2025-02-03 16:56:19 UTC

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.

👍 LGTM, nice and straightforward. Thanks!

@JoshuaKGoldberg JoshuaKGoldberg added the 1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge label Feb 3, 2025
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.

Congrats on your first PR to typescript-eslint!

@JoshuaKGoldberg JoshuaKGoldberg merged commit d30a497 into typescript-eslint:main Feb 5, 2025
64 checks passed
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Feb 11, 2025
| datasource | package                          | from   | to     |
| ---------- | -------------------------------- | ------ | ------ |
| npm        | @typescript-eslint/eslint-plugin | 8.23.0 | 8.24.0 |
| npm        | @typescript-eslint/parser        | 8.23.0 | 8.24.0 |


## [v8.24.0](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8240-2025-02-10)

##### 🚀 Features

-   **eslint-plugin:** \[no-unnecessary-condition] make `allowConstantLoopConditions` more granular ([#10639](typescript-eslint/typescript-eslint#10639))

##### 🩹 Fixes

-   **eslint-plugin:** \[no-misused-spread] correct and elaborate string spread report message ([#10751](typescript-eslint/typescript-eslint#10751))
-   **eslint-plugin:** \[restrict-plus-operands] report adding bigints to strings when `allowNumberAndString` is `false` ([#10737](typescript-eslint/typescript-eslint#10737))

##### ❤️ Thank You

-   Josh Goldberg ✨
-   noah
-   Ronen Amiel

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 Feb 11, 2025
| datasource | package                          | from   | to     |
| ---------- | -------------------------------- | ------ | ------ |
| npm        | @typescript-eslint/eslint-plugin | 8.23.0 | 8.24.0 |
| npm        | @typescript-eslint/parser        | 8.23.0 | 8.24.0 |


## [v8.24.0](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8240-2025-02-10)

##### 🚀 Features

-   **eslint-plugin:** \[no-unnecessary-condition] make `allowConstantLoopConditions` more granular ([#10639](typescript-eslint/typescript-eslint#10639))

##### 🩹 Fixes

-   **eslint-plugin:** \[no-misused-spread] correct and elaborate string spread report message ([#10751](typescript-eslint/typescript-eslint#10751))
-   **eslint-plugin:** \[restrict-plus-operands] report adding bigints to strings when `allowNumberAndString` is `false` ([#10737](typescript-eslint/typescript-eslint#10737))

##### ❤️ Thank You

-   Josh Goldberg ✨
-   noah
-   Ronen Amiel

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 Feb 13, 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: [restrict-plus-operands] allowNumberAndString: false doesn't report when adding a bigint to a string
3 participants