Skip to content

Commit 482dccd

Browse files
committed
Small refactorings:
- Replaced two calls to Count() calls (with O(n)) with faster calls to .Length and .Count (O(1)) - Few typos fixed - Removed code redundancies
1 parent aa0175a commit 482dccd

19 files changed

Lines changed: 27 additions & 44 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1502/SA1502UnitTests.Events.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public event EventHandler Bar
9292
}
9393

9494
/// <summary>
95-
/// Verifies that an event with its block defined on a mutiple lines will pass without diagnostic.
95+
/// Verifies that an event with its block defined on a multiple lines will pass without diagnostic.
9696
/// </summary>
9797
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
9898
[Fact]

StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1502/SA1502UnitTests.Indexers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public bool this[int index]
7474
}
7575

7676
/// <summary>
77-
/// Verifies that an indexer with its block defined on a mutiple lines will pass without diagnostic.
77+
/// Verifies that an indexer with its block defined on a multiple lines will pass without diagnostic.
7878
/// </summary>
7979
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
8080
[Fact]

StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1502/SA1502UnitTests.Namespaces.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public async Task TestNamespaceWithBlockOnSingleLineAsync()
6969
}
7070

7171
/// <summary>
72-
/// Verifies that a namespace with its block defined on a mutiple lines will pass without diagnostic.
72+
/// Verifies that a namespace with its block defined on a multiple lines will pass without diagnostic.
7373
/// </summary>
7474
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
7575
[Fact]

StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1119UnitTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ public void Bar()
11691169
public async Task TestElementAccessExpressionAroundConditionalMemberAccessExpressionAsync()
11701170
{
11711171
// In this case removing the parenthesis is an syntactical(because char is a value type) change to the code.
1172-
// If (myObject?.Foo)[0] would be a refrrence type removing parenthesis would be a semantic change
1172+
// If (myObject?.Foo)[0] would be a reference type removing parenthesis would be a semantic change
11731173
// because (myObject?.Foo)[0] crashes if myObject is null, but myObject?.Foo[0] evaluates to null.
11741174
string testCode = @"class Foo
11751175
{

StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1122UnitTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void Bar()
4949
[Fact]
5050
public async Task TestCodeFixMultipleNodesAsync()
5151
{
52-
// Tests if the code fix works if the SourceSpan of the diagnostic has more then one SynatxNode associated with it
52+
// Tests if the code fix works if the SourceSpan of the diagnostic has more then one SyntaxNode associated with it
5353
// In this case it is a InterpolatedStringInsert and the StringLiteralExpression
5454
string oldSource = @"public class Foo
5555
{

StyleCop.Analyzers/StyleCop.Analyzers.Test/Settings/SettingsUnitTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ private static async Task<SyntaxTreeAnalysisContext> CreateAnalysisContextAsync(
157157
var additionalFiles = ImmutableArray.Create<AdditionalText>(stylecopJSONFile);
158158
var analyzerOptions = new AnalyzerOptions(additionalFiles);
159159

160-
return new SyntaxTreeAnalysisContext(syntaxTree, analyzerOptions, rd => { }, isd => { return true; }, CancellationToken.None);
160+
return new SyntaxTreeAnalysisContext(syntaxTree, analyzerOptions, rd => { }, isd => true, CancellationToken.None);
161161
}
162162

163163
private class AdditionalTextHelper : AdditionalText

StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules/NumberSignSpacingTestBase.cs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ void Foo()
8080
}
8181
";
8282

83-
string test;
84-
85-
test = string.Format(testFormat, this.Sign + "3");
83+
string test = string.Format(testFormat, this.Sign + "3");
8684
await this.VerifyCSharpDiagnosticAsync(test, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
8785
await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None).ConfigureAwait(false);
8886

@@ -123,9 +121,7 @@ void Foo()
123121
}
124122
";
125123

126-
string test;
127-
128-
test = string.Format(testFormat, this.Sign + "3");
124+
string test = string.Format(testFormat, this.Sign + "3");
129125
await this.VerifyCSharpDiagnosticAsync(test, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
130126
await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None).ConfigureAwait(false);
131127

@@ -164,9 +160,7 @@ void Foo()
164160
}
165161
";
166162

167-
string test;
168-
169-
test = string.Format(testFormat, " " + this.Sign + "3");
163+
string test = string.Format(testFormat, " " + this.Sign + "3");
170164
await this.VerifyCSharpDiagnosticAsync(test, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
171165
await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None).ConfigureAwait(false);
172166

@@ -229,9 +223,7 @@ void Foo()
229223
}
230224
";
231225

232-
string test;
233-
234-
test = string.Format(testFormat, this.Sign + "3");
226+
string test = string.Format(testFormat, this.Sign + "3");
235227
await this.VerifyCSharpDiagnosticAsync(test, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
236228
await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None).ConfigureAwait(false);
237229

@@ -270,9 +262,7 @@ void Foo()
270262
}
271263
";
272264

273-
string test;
274-
275-
test = string.Format(testFormat, this.Sign + "3");
265+
string test = string.Format(testFormat, this.Sign + "3");
276266
await this.VerifyCSharpDiagnosticAsync(test, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
277267
await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None).ConfigureAwait(false);
278268

@@ -332,9 +322,7 @@ void Foo()
332322
}
333323
";
334324

335-
string test;
336-
337-
test = string.Format(testFormat, this.Sign + "3");
325+
string test = string.Format(testFormat, this.Sign + "3");
338326
await this.VerifyCSharpDiagnosticAsync(test, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
339327
await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None).ConfigureAwait(false);
340328

@@ -394,9 +382,7 @@ void Foo()
394382
}
395383
";
396384

397-
string test;
398-
399-
test = string.Format(testFormat, this.Sign + "0");
385+
string test = string.Format(testFormat, this.Sign + "0");
400386
await this.VerifyCSharpDiagnosticAsync(test, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
401387
await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None).ConfigureAwait(false);
402388

StyleCop.Analyzers/StyleCop.Analyzers.Test/Verifiers/DiagnosticVerifier.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ protected Task VerifyCSharpDiagnosticAsync(string[] sources, DiagnosticResult[]
129129
/// diagnostics for the sources.</param>
130130
private static void VerifyDiagnosticResults(IEnumerable<Diagnostic> actualResults, ImmutableArray<DiagnosticAnalyzer> analyzers, DiagnosticResult[] expectedResults)
131131
{
132-
int expectedCount = expectedResults.Count();
132+
int expectedCount = expectedResults.Length;
133133
int actualCount = actualResults.Count();
134134

135135
if (expectedCount != actualCount)
@@ -284,7 +284,7 @@ private static string FormatDiagnostics(ImmutableArray<DiagnosticAnalyzer> analy
284284
{
285285
var diagnosticsId = diagnostics[i].Id;
286286

287-
builder.AppendLine("// " + diagnostics[i].ToString());
287+
builder.AppendLine("// " + diagnostics[i]);
288288

289289
var applicableAnalyzer = analyzers.FirstOrDefault(a => a.SupportedDiagnostics.Any(dd => dd.Id == diagnosticsId));
290290
if (applicableAnalyzer != null)
@@ -300,7 +300,7 @@ private static string FormatDiagnostics(ImmutableArray<DiagnosticAnalyzer> analy
300300
{
301301
Assert.True(
302302
location.IsInSource,
303-
string.Format("Test base does not currently handle diagnostics in metadata locations. Diagnostic in metadata:\r\n", diagnostics[i]));
303+
string.Format("Test base does not currently handle diagnostics in metadata locations. Diagnostic in metadata:{0}\r\n", diagnostics[i]));
304304

305305
string resultMethodName = diagnostics[i].Location.SourceTree.FilePath.EndsWith(".cs") ? "GetCSharpResultAt" : "GetBasicResultAt";
306306
var linePosition = diagnostics[i].Location.GetLineSpan().StartLinePosition;

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1615SA1616CodeFixProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private static async Task<Document> GetTransformedDocumentAsync(Document documen
9494
isAsynchronousTestMethod = false;
9595
}
9696

97-
XmlNodeSyntax returnsElement = documentationComment.Content.GetFirstXmlElement(XmlCommentHelper.ReturnsXmlTag) as XmlNodeSyntax;
97+
XmlNodeSyntax returnsElement = documentationComment.Content.GetFirstXmlElement(XmlCommentHelper.ReturnsXmlTag);
9898
if (returnsElement != null && !isTask)
9999
{
100100
// This code fix doesn't know how to do anything more than document Task-returning methods.

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1650ElementDocumentationMustBeSpelledCorrectly.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace StyleCop.Analyzers.DocumentationRules
3737
/// Joinsnames to a CustomDictionary.xml file.</para>
3838
///
3939
/// <list type="bullet">
40-
/// <item>CustomDictionary.xml files can contain words that the spelling checker does not normally recognise.</item>
40+
/// <item>CustomDictionary.xml files can contain words that the spelling checker does not normally recognize.</item>
4141
/// <item>The CustomDictionary.xml file should be placed in the same folder as the StyleCop.dll and the Rules. That
4242
/// folder (and all subfolders) are checked for the dictionary files.</item>
4343
/// <item>StyleCop loads CustomDictionary.xml, CustomDictionary.en-GB.xml and then CustomDictionary.en.xml (where

0 commit comments

Comments
 (0)