dotnet / roslyn-analyzers

MIT License
1.59k stars 465 forks source link

Support operators in BannedApiAnalyzers #6622

Open Drake53 opened 1 year ago

Drake53 commented 1 year ago

If I'm not mistaken, the analyzer currently doesn't support operators. I tried with the following in BannedSymbols.txt:

M:System.String.op_Equality(System.String,System.String)

But I'm not seeing RS0030 when I try the following:

var test = "a" == "b";

I'd like to ban this in my projects in favour of string.Equals(string, string, System.StringComparison), since in my opinion you should always explicitly define what type of StringComparison to use.

mavasani commented 1 year ago

@Drake53 This is correct. This analyzer supports banning user defined operator methods, but not built-in operators. For the above case, the correct declaration syntax for string equality check is M:System.String.op_Equality(System.String), but even that is not supported by this analyzer.

You are always welcome to submit a PR to implement this support.

AndriSig commented 4 months ago

@mavasani Do you know if not supporting that was because of a significant technical hurdle, or if it just didn't seem worth doing?