tools icon indicating copy to clipboard operation
tools copied to clipboard

`match_str_case_mismatch`

Open ematipico opened this issue 3 years ago • 5 comments

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 avatar Oct 07 '22 12:10 ematipico

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

github-actions[bot] avatar Oct 24 '22 12:10 github-actions[bot]

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

95th avatar Nov 06 '22 09:11 95th

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?)

MichaReiser avatar Nov 06 '22 12:11 MichaReiser

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 │

95th avatar Nov 18 '22 09:11 95th

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

MichaReiser avatar Nov 18 '22 09:11 MichaReiser