Skip to content
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

Rule Change: Add suggestions to no-constant-binary-expression #18051

Closed
1 task
littlemoji opened this issue Jan 30, 2024 · 5 comments
Closed
1 task

Rule Change: Add suggestions to no-constant-binary-expression #18051

littlemoji opened this issue Jan 30, 2024 · 5 comments
Labels
enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules

Comments

@littlemoji
Copy link

What rule do you want to change?

no-constant-binary-expression

What change do you want to make?

Generate more warnings

How do you think the change should be implemented?

A new default behavior

Example code

function a():boolean{
  ...
}
if(!a){
// !a always return false, and didn't report an error 
  ...
}

What does the rule currently do for this code?

nothing, no error report

What will the rule do after it's changed?

Report an error

Participation

  • I am willing to submit a pull request to implement this change.

Additional comments

No response

@littlemoji littlemoji added enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules labels Jan 30, 2024
@Tanujkanti4441
Copy link
Contributor

Hey @littlemoji, thanks for the issue, i am a bit confuse, your title says 'to add suggestions' but from the code example you have given seems like the issue is about to enable the rule to check the types also, can you clear this.

@aladdin-add
Copy link
Member

it's confusing: "suggestions" is a term used in eslint: https://eslint.org/docs/latest/extend/custom-rules#providing-suggestions. 😄

If you're proposing to report an error in the code in the example, this is not possible in eslint because eslint doesn't have type information. But it's possible in ts-eslint. /cc @bradzacher

@bradzacher
Copy link
Contributor

You could use scope analysis to attempt to resolve an expression to a static value (I believe there's already a util function you guys use for this purpose!) which would let you provide extra help messages for some cases.

@bradzacher
Copy link
Contributor

If you want a rule which warns against constant/unnecessary conditions - we have that - https://typescript-eslint.io/rules/no-unnecessary-condition/

@mdjermanovic
Copy link
Member

function a():boolean{
  ...
}
if(!a){
// !a always return false, and didn't report an error 
  ...
}

This case is included in #13776 proposal, so I'm closing this issue as a duplicate.

@mdjermanovic mdjermanovic closed this as not planned Won't fix, can't repro, duplicate, stale Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules
Projects
Archived in project
Development

No branches or pull requests

5 participants