Skip to content

Commit cf9df0a

Browse files
Cleanup
1 parent 8c5d971 commit cf9df0a

16 files changed

Lines changed: 59 additions & 105 deletions

Directory.Packages.props

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
</PropertyGroup>
66
<ItemGroup>
77
<PackageVersion Include="coverlet.collector" Version="8.0.0" />
8-
<PackageVersion Include="IntelliTect.Analyzers" Version="0.1.8" />
9-
<PackageVersion Include="Microsoft.Build.Locator" Version="1.7.8" />
10-
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" />
11-
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="5.0.0" />
12-
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="5.0.0" />
13-
<PackageVersion Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="10.0.103" />
14-
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="5.0.0" />
8+
<PackageVersion Include="IntelliTect.Analyzers" Version="0.2.0" />
9+
<PackageVersion Include="Microsoft.Build.Locator" Version="1.11.2" />
10+
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="5.3.0" />
11+
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="5.3.0" />
12+
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="5.3.0" />
13+
<PackageVersion Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="10.0.200" />
14+
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="5.3.0" />
1515
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.3.0" />
1616
<PackageVersion Include="MSTest.TestAdapter" Version="4.1.0" />
1717
<PackageVersion Include="MSTest.TestFramework" Version="4.1.0" />
18-
<PackageVersion Include="System.CommandLine.DragonFruit" Version="0.4.0-alpha.23407.1" />
18+
<PackageVersion Include="System.CommandLine.DragonFruit" Version="0.4.0-alpha.25320.106" />
1919
<!-- Reference-only packages for test framework namespace resolution in analyzer tests -->
2020
<PackageVersion Include="xunit.v3.core" Version="3.2.2" />
2121
<PackageVersion Include="NUnit" Version="4.5.1" />

IntelliTect.Analyzer/IntelliTect.Analyzer.CodeFixes/AttributesOnSeparateLines.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,10 @@ private static async Task<Document> PutOnSeparateLine(Document document, SyntaxN
7373
attributeLists = attributeLists.Add(
7474
SyntaxFactory.AttributeList(
7575
SyntaxFactory.SeparatedList(
76-
new[] {
77-
SyntaxFactory.Attribute(
76+
[SyntaxFactory.Attribute(
7877
attribute.Name,
79-
attribute.ArgumentList)
80-
})));
78+
attribute.ArgumentList)])))
79+
;
8180
}
8281

8382
// the formatter-annotation will wrap every attribute on a separate line

IntelliTect.Analyzer/IntelliTect.Analyzer.CodeFixes/FavorDirectoryEnumerationCalls.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ private static bool NeedsToArrayWrapper(
143143
LocalFunctionStatementSyntax lf => lf.ReturnType,
144144
_ => null
145145
})
146-
.FirstOrDefault(t => t != null);
147-
if (returnType != null
146+
.FirstOrDefault(t => t is not null);
147+
if (returnType is not null
148148
&& semanticModel.GetTypeInfo(returnType, ct).Type is IArrayTypeSymbol)
149149
{
150150
return true;
@@ -161,7 +161,7 @@ private static bool NeedsToArrayWrapper(
161161
PropertyDeclarationSyntax p => p.Type,
162162
_ => null
163163
};
164-
if (returnType != null && semanticModel.GetTypeInfo(returnType, ct).Type is IArrayTypeSymbol)
164+
if (returnType is not null && semanticModel.GetTypeInfo(returnType, ct).Type is IArrayTypeSymbol)
165165
{
166166
return true;
167167
}
@@ -176,7 +176,7 @@ private static bool NeedsToArrayWrapper(
176176
IParameterSymbol? targetParam;
177177

178178
// Named argument: SomeMethod(param: Directory.GetFiles(...))
179-
if (argument.NameColon != null)
179+
if (argument.NameColon is not null)
180180
{
181181
string paramName = argument.NameColon.Name.Identifier.Text;
182182
targetParam = outerMethod.Parameters.FirstOrDefault(p => p.Name == paramName);

IntelliTect.Analyzer/IntelliTect.Analyzer.CodeFixes/NamingFieldPascalUnderscore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private static async Task<Solution> MakePascalWithUnderscore(Document document,
5252
{
5353
string nameOfField = declaration.ValueText;
5454
string nameWithoutUnderscore = nameOfField.TrimStart('_');
55-
string newName = "_" + char.ToUpper(nameWithoutUnderscore.First()) + nameWithoutUnderscore.Substring(1);
55+
string newName = $"_{char.ToUpper(nameWithoutUnderscore[0])}{nameWithoutUnderscore.Substring(1)}";
5656

5757
SemanticModel? semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
5858
if (semanticModel is null || declaration.Parent is null)

IntelliTect.Analyzer/IntelliTect.Analyzer.CodeFixes/NamingIdentifierPascal.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
5151
private static async Task<Solution> MakePascal(Document document, SyntaxToken declaration, CancellationToken cancellationToken)
5252
{
5353
string nameOfField = declaration.ValueText;
54-
string newName = char.ToUpper(nameOfField.First()) + nameOfField.Substring(1);
54+
string newName = $"{char.ToUpper(nameOfField[0])}{nameOfField.Substring(1)}";
5555

5656
SemanticModel? semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
5757
if (semanticModel is null || declaration.Parent is null)

IntelliTect.Analyzer/IntelliTect.Analyzer.Test/AttributesOnSeparateLinesTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ partial class Program
9494
}";
9595
//Testing both here because the order the files are loaded changes
9696
//the order that location information from the Program symbol is returned.
97-
VerifyCSharpDiagnostic(new[] { test2, test });
98-
VerifyCSharpDiagnostic(new[] { test, test2 });
97+
VerifyCSharpDiagnostic([test2, test]);
98+
VerifyCSharpDiagnostic([test, test2]);
9999
}
100100

101101
[TestMethod]

IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Helpers/DiagnosticResult.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,12 @@ public DiagnosticResultLocation(string path, int line, int column)
3535
/// </summary>
3636
public struct DiagnosticResult
3737
{
38-
private DiagnosticResultLocation[] _Locations;
39-
4038
#pragma warning disable CA1819 // Properties should not return arrays
4139

4240
public DiagnosticResultLocation[] Locations
4341
{
44-
get
45-
{
46-
_Locations ??= [];
47-
return _Locations;
48-
}
49-
50-
set
51-
{
52-
_Locations = value;
53-
}
42+
get { field ??= []; return field; }
43+
set;
5444
}
5545

5646
#pragma warning restore CA1819 // Properties should not return arrays

IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Helpers/DiagnosticVerifier.Helper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ protected static Diagnostic[] GetSortedDiagnosticsFromDocuments(DiagnosticAnalyz
6767
{
6868
ArgumentNullException.ThrowIfNull(documents);
6969

70-
var projects = new HashSet<Project>();
70+
HashSet<Project> projects = [];
7171
foreach (Document document in documents)
7272
{
7373
projects.Add(document.Project);
7474
}
7575

76-
var diagnostics = new List<Diagnostic>();
76+
List<Diagnostic> diagnostics = [];
7777
foreach (Project project in projects)
7878
{
7979
CompilationWithAnalyzers compilationWithAnalyzers = (project.GetCompilationAsync().Result
@@ -194,7 +194,7 @@ private static Project CreateProject(string[] sources, string language = Languag
194194
int count = 0;
195195
foreach (string source in sources)
196196
{
197-
string newFileName = fileNamePrefix + count + "." + fileExt;
197+
string newFileName = $"{fileNamePrefix}{count}.{fileExt}";
198198
var documentId = DocumentId.CreateNewId(projectId, debugName: newFileName);
199199
solution = solution.AddDocument(documentId, newFileName, SourceText.From(source));
200200
count++;

IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Verifiers/CodeFixVerifier.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private static async Task VerifyFix(string language, DiagnosticAnalyzer? analyze
8484

8585
for (int i = 0; i < attempts; ++i)
8686
{
87-
var actions = new List<CodeAction>();
87+
List<CodeAction> actions = [];
8888
var context = new CodeFixContext(document, analyzerDiagnostics[0], (a, d) => actions.Add(a), CancellationToken.None);
8989
codeFixProvider.RegisterCodeFixesAsync(context).Wait();
9090

@@ -93,7 +93,7 @@ private static async Task VerifyFix(string language, DiagnosticAnalyzer? analyze
9393
break;
9494
}
9595

96-
if (codeFixIndex != null)
96+
if (codeFixIndex is not null)
9797
{
9898
document = await ApplyFix(document, actions.ElementAt((int)codeFixIndex));
9999
break;

IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Verifiers/DiagnosticVerifier.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private static void VerifyDiagnosticResults(IEnumerable<Diagnostic> actualResult
117117
{
118118
Assert.AreEqual(actual.Location,
119119
Location.None,
120-
string.Format($"Expected:{Environment.NewLine}A project diagnostic with No location{Environment.NewLine}Actual:{Environment.NewLine}{FormatDiagnostics(analyzer, actual)}"));
120+
$"Expected:{Environment.NewLine}A project diagnostic with No location{Environment.NewLine}Actual:{Environment.NewLine}{FormatDiagnostics(analyzer, actual)}");
121121
}
122122
else
123123
{
@@ -158,7 +158,7 @@ private static void VerifyDiagnosticLocation(DiagnosticAnalyzer analyzer, Diagno
158158
{
159159
FileLinePositionSpan actualSpan = actual.GetLineSpan();
160160

161-
Assert.IsTrue(actualSpan.Path == expected.Path || (actualSpan.Path != null
161+
Assert.IsTrue(actualSpan.Path == expected.Path || (actualSpan.Path is not null
162162
&& actualSpan.Path.Contains("Test0.", StringComparison.Ordinal)
163163
&& expected.Path.Contains("Test.", StringComparison.Ordinal)),
164164
$"Expected diagnostic to be in file \"{expected.Path}\" was actually in file \"{actualSpan.Path}\"{Environment.NewLine}{Environment.NewLine}Diagnostic:{Environment.NewLine} {FormatDiagnostics(analyzer, diagnostic)}{Environment.NewLine}");
@@ -195,19 +195,19 @@ private static string FormatDiagnostics(DiagnosticAnalyzer analyzer, params Diag
195195
var builder = new StringBuilder();
196196
for (int i = 0; i < diagnostics.Length; ++i)
197197
{
198-
builder.AppendLine("// " + diagnostics[i].ToString());
198+
builder.AppendLine($"// {diagnostics[i]}");
199199

200200
Type analyzerType = analyzer.GetType();
201201
System.Collections.Immutable.ImmutableArray<DiagnosticDescriptor> rules = analyzer.SupportedDiagnostics;
202202

203203
foreach (DiagnosticDescriptor rule in rules)
204204
{
205-
if (rule != null && rule.Id == diagnostics[i].Id)
205+
if (rule is not null && rule.Id == diagnostics[i].Id)
206206
{
207207
Location location = diagnostics[i].Location;
208208
if (location == Location.None)
209209
{
210-
builder.AppendFormat("GetGlobalResult({0}.{1})", analyzerType.Name, rule.Id);
210+
builder.Append($"GetGlobalResult({analyzerType.Name}.{rule.Id})");
211211
}
212212
else
213213
{
@@ -217,12 +217,7 @@ private static string FormatDiagnostics(DiagnosticAnalyzer analyzer, params Diag
217217
string resultMethodName = diagnostics[i].Location.SourceTree!.FilePath.EndsWith(".cs", StringComparison.Ordinal) ? "GetCSharpResultAt" : "GetBasicResultAt";
218218
Microsoft.CodeAnalysis.Text.LinePosition linePosition = diagnostics[i].Location.GetLineSpan().StartLinePosition;
219219

220-
builder.AppendFormat("{0}({1}, {2}, {3}.{4})",
221-
resultMethodName,
222-
linePosition.Line + 1,
223-
linePosition.Character + 1,
224-
analyzerType.Name,
225-
rule.Id);
220+
builder.Append($"{resultMethodName}({linePosition.Line + 1}, {linePosition.Character + 1}, {analyzerType.Name}.{rule.Id})");
226221
}
227222

228223
if (i != diagnostics.Length - 1)

0 commit comments

Comments
 (0)