Commit 216a1d1
Implement LuceneDev6001, 6002, 6003 Analyzers & CodeFixes with Unit Tests (#14)
* Add analyzers, codefixes, sample and test files for 6001, 6002, 6003
* feat(analyzers): smart Span fixes, char optimizations,NRT updatesand add Documentation as per suggestion
* Address LuceneDev600x review feedback and fix tests
- LuceneDev6003 code fix: use getInnermostNodeForTie + descendant
fallback so FindNode resolves to the LiteralExpressionSyntax.
- LuceneDev6003 analyzer: detect char overload correctly for spans.
ReadOnlySpan<T>.IndexOf(T) / LastIndexOf(T) are MemoryExtensions
extensions, so the previous search on the containing type missed
them. StartsWith/EndsWith intentionally remain excluded (no char
overload exists for spans).
- LuceneDev6001 analyzer: pass the invalid StringComparison value
name to Diagnostic.Create so the {1} placeholder in the message
format is substituted (previously rendered as literal "{1}").
- LuceneDev6001 code fix: use continue instead of return inside the
diagnostic loop so multiple diagnostics in one file all get fixes
offered.
- Sample project: uncomment violating examples so the diagnostics
fire live in the IDE (matches the existing LuceneDevXxxxSample
convention). Add .editorconfig to downgrade error-severity rules
to warning in the sample project so it still compiles.
- LuceneDev6003 sample: rewrite to use the analyzer's target methods
(IndexOf/LastIndexOf/StartsWith/EndsWith) rather than string.Equals,
including a ReadOnlySpan<char> example.
- Clean up excessive blank lines in 6002 code fix and a stray
trailing space in a variable name.
- Update 6001 tests to include the comparison-value argument.
- Fix off-by-one spans in 6003 code fix tests and add a span test.
* Renumber LuceneDev6xxx rules to contiguous IDs
Replace the underscore-suffixed IDs (6001_1, 6001_2, 6002_1, 6002_2)
with contiguous numeric IDs matching the rest of the Lucene.NET
analyzer taxonomy:
6001_1 -> 6001 Missing StringComparison on String overload
6001_2 -> 6002 Invalid StringComparison on String overload
6002_1 -> 6003 Redundant Ordinal on span overload
6002_2 -> 6004 Invalid StringComparison on span overload
6003 -> 6005 Single-character string literal
Each analyzer class still bundles the two related diagnostics that
share symbol resolution; files are named with the ID range
(e.g., LuceneDev6001_6002_StringComparisonAnalyzer.cs) and the
LuceneDev6005 analyzer stands alone.
Update Descriptors, Resources.resx, AnalyzerReleases.Unshipped.md,
DiagnosticCategoryAndIdRanges.txt, samples, editorconfig overrides,
and tests to reference the new IDs. Tighten the 6005 summary doc
to note that spans only have char overloads for IndexOf/LastIndexOf.
---------
Co-authored-by: Paul Irwin <paulirwin@gmail.com>1 parent 998cc93 commit 216a1d1
23 files changed
Lines changed: 3652 additions & 23 deletions
File tree
- src
- Lucene.Net.CodeAnalysis.Dev.CodeFixes/LuceneDev6xxx
- Lucene.Net.CodeAnalysis.Dev.Sample
- LuceneDev6xxx
- Lucene.Net.CodeAnalysis.Dev
- LuceneDev6xxx
- Utility
- tests
- Lucene.Net.CodeAnalysis.Dev.CodeFixes.Tests/LuceneDev6xxx
- Lucene.Net.CodeAnalysis.Dev.Tests/LuceneDev6xxx
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | 26 | | |
28 | 27 | | |
29 | 28 | | |
30 | | - | |
31 | 29 | | |
32 | 30 | | |
33 | 31 | | |
| |||
Lines changed: 229 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
0 commit comments