Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

match_str_case_mismatch #3368

Closed
Tracked by #3358 ...
ematipico opened this issue Oct 7, 2022 · 5 comments · Fixed by #3794
Closed
Tracked by #3358 ...

match_str_case_mismatch #3368

ematipico opened this issue Oct 7, 2022 · 5 comments · Fixed by #3794
Labels
A-Linter Area: linter I-Normal Implementation: normal understanding of the tool and awareness S-Planned Status: planned by the team, but not in the short term

Comments

@ematipico
Copy link
Contributor

ematipico commented Oct 7, 2022

https://rust-lang.github.io/rust-clippy/master/#match_str_case_mismatch

For this rule, we should try to implement simple cases such as:

const lorem = "foo";

if (lorem == "Foo") { // trigger the rule
}
@ematipico ematipico changed the title match_str_case_mismatch https://rust-lang.github.io/rust-clippy/master/#match_str_case_mismatch match_str_case_mismatch Oct 7, 2022
@ematipico ematipico added A-Linter Area: linter I-Normal Implementation: normal understanding of the tool and awareness labels Oct 7, 2022
@ematipico ematipico added this to the 10.0.0 milestone Oct 7, 2022
@github-actions
Copy link

This issue is stale because it has been open 14 days with no activity.

@ematipico ematipico added S-Planned Status: planned by the team, but not in the short term and removed S-Stale labels Nov 2, 2022
@ematipico ematipico modified the milestones: 10.0.0, 10.1.0 Nov 2, 2022
@95th
Copy link
Contributor

95th commented Nov 6, 2022

Hi @ematipico.
Is the goal here to find mismatching comparison of const/effectively const variables?
or is it to find toUpperCase/toLowerCase comparisons?

@MichaReiser
Copy link
Contributor

MichaReiser commented Nov 6, 2022

const lorem = "foo";

if (lorem == "Foo") { // trigger the rule
}

I doubt that a rule limited to this pattern will catch many bugs and isn't what the clippy equivalent is testing for.

or is it to find toUpperCase/toLowerCase comparisons?

This feels more valuable to me (testing in all places where conditions can appear: if/else, switch, maybe for, and while?)

@ematipico ematipico mentioned this issue Nov 15, 2022
29 tasks
@95th
Copy link
Contributor

95th commented Nov 18, 2022

Should it only raise for conditional statements mentioned above or in general as well?

For example, this also look right to me:

! This expression always returns false.

> 10 │ const a = s.toUpperCase() === "abc";
     │           ^^^^^^^^^^^^^^^^^^^^^^^^^
  11 │

i This call convert the string to upper case

> 10 │ const a = s.toUpperCase() === "abc";
     │           ^^^^^^^^^^^^^^^
  11 │

i ... but this value is not in upper case

> 10 │ const a = s.toUpperCase() === "abc";
     │                               ^^^^^
  11 │

@MichaReiser
Copy link
Contributor

It probably makes sense in all positions where a value is compared with a string.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Linter Area: linter I-Normal Implementation: normal understanding of the tool and awareness S-Planned Status: planned by the team, but not in the short term
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants