Skip to content

Commit 3ccabcd

Browse files
mpidashbuyaa-nsharwell
authored
Add CA1868: Unnecessary call to Set.Contains(item) (#6767)
* Add analyzer and fixer for CA1865 This analyzer detects when either `Set.Add` or `Set.Remove` is guarded by `Set.Contains`. A fix is only suggested when the conditional body has a single statement that is either one of the former two methods. * Add CA1865 to Microsoft.CodeAnalysis.NetAnalyzers.md * Add CA1865 to RulesMissingDocumentation.md * Update DoNotGuardSetAddOrRemoveByContainsDescription * Add ExportCodeFixProviderAttribute * Remove call to First with call to indexer * Change equivalenceKey of CodeAction * Check for interface implementation instead of signature match * Remove call to First with call to indexer * Add additional tests * Fix ifs with additional statements * Fix single line ifs in VB * Add fixer case for single line ifs in VB * CA1865: Add tests for other set types * CA1865: Check descendants instead of switch * CA1865: Do not fire when arguments are different * CA1865: Change fixer title * CA1865: Update resources * WIP: Try to handle IImmutableSet Add and Remove * Apply suggestions from code review * CA1865: Use original definitions to filter methods * Check parameter length before using them * Only check child operations instead of descendants This ensures that nested Add or Remove calls are not flagged. * Fix diagnostic message * Also flag when interface types are used * Use helper class for required symbols * Only compare first argument value This is sufficient as each method involved only has one argument. * Make symbol display format static * Update DoNotGuardSetAddOrRemoveByContainsTitle * Change condition to pattern matching * Add tests for ternary operators * Use raw strings and inline class and usings * Support Add or Remove in else block * Support ternary operator (diagnostic only) * Move from CA1865 to CA1868 --------- Co-authored-by: Buyaa Namnan <buyankhishig.namnan@microsoft.com> Co-authored-by: Sam Harwell <sam@tunnelvisionlabs.com>
1 parent 55df92b commit 3ccabcd

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Utilities/Compiler/DiagnosticCategoryAndIdRanges.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# This file contains the allowed analyzer rule "Category" and corresponding "Diagnostic ID range"
1+
# This file contains the allowed analyzer rule "Category" and corresponding "Diagnostic ID range"
22
# FORMAT:
33
# 'Category': Comma separate list of 'StartId-EndId' or 'Id' or 'Prefix'
44

@@ -12,7 +12,7 @@
1212
Design: CA2210, CA1000-CA1070
1313
Globalization: CA2101, CA1300-CA1311
1414
Mobility: CA1600-CA1601
15-
Performance: HA, CA1800-CA1867
15+
Performance: HA, CA1800-CA1868
1616
Security: CA2100-CA2153, CA2300-CA2330, CA3000-CA3147, CA5300-CA5405
1717
Usage: CA1801, CA1806, CA1816, CA2200-CA2209, CA2211-CA2261
1818
Naming: CA1700-CA1727

0 commit comments

Comments
 (0)