You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[similar_names]: Configuration option to whitelist specific names #10926
Which is something I ran into on #10891. IMO, tcx and ocx are short enough that you can tell them apart. Despite this, simply setting a minimum length isn't desirable; What about lli and lll? Therefore, I think this lint should have a configuration option that is by default empty that allows specific names.
There is a hardcoded list of "names that are allowed to be similar". This list could be added to, but I can imagine many scenarios where using some similar domain-specific acronyms would make the most sense. I agree this should be configurable
Maybe an easy refinement rule is to skip this check if the first letters are visually different. That would cover the txc/ocx, msb/lsb, slen/dlen cases, and I think probably a good number of other cases that exist. A list would also be nice, but I think that clippy could probably be a bit smarter here.
A slightly more complex but more general algorithm that could make sense is something like:
fn raise_similar_lint(muta:&str,mutb:&str) -> bool{// comparing identifiers a and b// commonize similar looking characters, e.g. l->i, 1->i, 5->s// from here on out, we are comparing visual difference
a = replace_similar(a)
b = replace_similar(b)// If the first characters are visually different, call it goodif a[0] != b[0]{returnfalse;}let lev = levenshtein(a, b);// If the difference is large relative to the string's length, call it OK. // This means that `abb` and `abc` are ok, but `abbbb` and `abbbc` are not
lev *4 < a.len()}
req/res are another example of a common identifier pair when remote calls are involved. They don't differ in the first letter. Having some way to configure the list of exceptions would be helpful.
Activity
eloc3147 commentedon Jul 12, 2023
Just ran into this as well with
msbandlsb.There is a hardcoded list of "names that are allowed to be similar". This list could be added to, but I can imagine many scenarios where using some similar domain-specific acronyms would make the most sense. I agree this should be configurable
tgross35 commentedon Oct 2, 2023
Maybe an easy refinement rule is to skip this check if the first letters are visually different. That would cover the
txc/ocx,msb/lsb,slen/dlencases, and I think probably a good number of other cases that exist. A list would also be nice, but I think that clippy could probably be a bit smarter here.A slightly more complex but more general algorithm that could make sense is something like:
[similar_names] don't raise if the first character is different
tgross35 commentedon Feb 10, 2024
I did part of my above suggestion in #12258. Not raising this lint if the first letter is different removes almost all of the cases I run into.
Doing something with replacing and then
levenshteinis probably still more accurate yet, but this is a good start.Auto merge of #12258 - tgross35:similiar-names-update, r=Alexendoo
demurgos commentedon Jun 3, 2024
req/resare another example of a common identifier pair when remote calls are involved. They don't differ in the first letter. Having some way to configure the list of exceptions would be helpful.