Skip to content

Enhancement: [restrict-plus-operands] Bring in options from restrict-template-expressions #6110

Closed
@JoshuaKGoldberg

Description

@JoshuaKGoldberg

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Link to the rule's documentation

https://typescript-eslint.io/rules/restrict-plus-operands

Description

restrict-plus-operands and restrict-template-expressions don't tackle the exact same JavaScript behaviors (+ operands and template expressions don't concatenate/toString()/toValue() quite the same). But they both generally tackle the specific common case of code trying to join a string with a non-string:

'' + 0;
'' + {};
// _roughly_ equivalent to:
`${0}`;
`${{}}`;

As a user, I've been inconvenienced by restrict-plus-operands complaining on concatenating two primitive values: e.g. number and string. Sometimes I want to be able to join primitives together in my logs!

Proposal: can we add the following options that already exist in restrict-template-expressions?

Fail

'' + {}

Pass

'' + 0

Additional Info

I think we've seen a bigger demand for them in restrict-template-expressions because of https://eslint.org/docs/latest/rules/prefer-template. Linted projects don't concatenate strings with + as much as they used to.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement: plugin rule optionNew rule option for an existing eslint-plugin rulepackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugintriageWaiting for team members to take a look

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions