Skip to content

Commit cddf6cf

Browse files
committed
Fix warnings.
1 parent c37577d commit cddf6cf

5 files changed

Lines changed: 19 additions & 25 deletions

File tree

AspNetCoreAnalyzers.Tests/DocumentationTests.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
#pragma warning disable CA1055 // Uri return values should not be strings
2-
#pragma warning disable CA1056 // Uri properties should not be strings
3-
#pragma warning disable CA1721 // Property names should not match get methods
1+
#pragma warning disable CA1056 // Uri properties should not be strings
42
namespace AspNetCoreAnalyzers.Tests
53
{
64
using System;
@@ -228,7 +226,7 @@ private static string CreateStub(DiagnosticDescriptor descriptor)
228226
| Topic | Value
229227
| :-- | :--
230228
| Id | {descriptor.Id}
231-
| Severity | {descriptor.DefaultSeverity.ToString()}
229+
| Severity | {descriptor.DefaultSeverity}
232230
| Enabled | {(descriptor.IsEnabledByDefault ? "True" : "False")}
233231
| Category | {descriptor.Category}
234232
| Code | [<TYPENAME>](<URL>)

AspNetCoreAnalyzers.Tests/Helpers/UrlTemplateTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace AspNetCoreAnalyzers.Tests.Helpers
1+
namespace AspNetCoreAnalyzers.Tests.Helpers
22
{
33
using System;
44
using System.Linq;
@@ -32,7 +32,7 @@ public async Task<IActionResult> GetOrder([FromRoute]int id)
3232
var literal = syntaxTree.FindLiteralExpression(text);
3333
Assert.AreEqual(true, UrlTemplate.TryParse(literal, out var template));
3434
CollectionAssert.AreEqual(expected, template.Path.Select(x => x.Span.ToString()));
35-
Assert.IsTrue(template.Path.All(x => x.Parameter == null));
35+
Assert.IsTrue(template.Path.All(x => x.Parameter is null));
3636
}
3737

3838
[TestCase("{id}", new[] { "{id}" })]

AspNetCoreAnalyzers/Analyzers/AttributeAnalyzer.cs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ internal class AttributeAnalyzer : DiagnosticAnalyzer
3333

3434
public override void Initialize(AnalysisContext context)
3535
{
36-
if (context == null)
37-
{
38-
throw new ArgumentNullException(nameof(context));
39-
}
40-
4136
context.EnableConcurrentExecution();
4237
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
4338
context.RegisterSyntaxNodeAction(c => Handle(c), SyntaxKind.Attribute);
@@ -494,7 +489,7 @@ private static bool HasWrongSyntax(PathSegment segment, out Replacement<Span> re
494489
replacement = default;
495490
return false;
496491

497-
bool HasWrongIntArgumentSyntax(RouteConstraint constraint, string methodName, out Span result)
492+
static bool HasWrongIntArgumentSyntax(RouteConstraint constraint, string methodName, out Span result)
498493
{
499494
var text = constraint.Span;
500495
if (text.Length > methodName.Length + 2 &&
@@ -519,7 +514,7 @@ bool HasWrongIntArgumentSyntax(RouteConstraint constraint, string methodName, ou
519514

520515
private static bool HasWrongRegexSyntax(PathSegment segment, out Replacement<Span> replacement)
521516
{
522-
if (segment.Parameter is TemplateParameter parameter)
517+
if (segment.Parameter is { } parameter)
523518
{
524519
foreach (var constraint in parameter.Constraints)
525520
{
@@ -648,7 +643,7 @@ private static bool HasInvalidName(PathSegment segment, out Replacement<Span> re
648643

649644
private static bool ShouldKebabCase(PathSegment segment, [NotNullWhen(true)] out string? kebabCase)
650645
{
651-
if (segment.Parameter == null &&
646+
if (segment is { Parameter: null } &&
652647
IsHumpOrSnakeCased(segment.Span))
653648
{
654649
kebabCase = KebabCase(segment.Span.ToString());
@@ -658,7 +653,7 @@ private static bool ShouldKebabCase(PathSegment segment, [NotNullWhen(true)] out
658653
kebabCase = null;
659654
return false;
660655

661-
bool IsHumpOrSnakeCased(Span span)
656+
static bool IsHumpOrSnakeCased(Span span)
662657
{
663658
for (var i = 0; i < span.Length; i++)
664659
{
@@ -707,7 +702,7 @@ private static string KebabCase(string text)
707702
/// </summary>
708703
private static bool HasSyntaxError(PathSegment segment, [NotNullWhen(true)] out Location? location)
709704
{
710-
if (segment.Parameter == null)
705+
if (segment.Parameter is null)
711706
{
712707
for (var i = 0; i < segment.Span.Length; i++)
713708
{
@@ -732,8 +727,8 @@ private static bool HasSyntaxError(PathSegment segment, [NotNullWhen(true)] out
732727

733728
private static bool IsMultipleOccurringParameter(PathSegment segment, UrlAttribute urlAttribute, SyntaxNodeAnalysisContext context, [NotNullWhen(true)] out Location? location)
734729
{
735-
if (segment.Parameter is TemplateParameter parameter &&
736-
urlAttribute.UrlTemplate is UrlTemplate template)
730+
if (segment.Parameter is { } parameter &&
731+
urlAttribute.UrlTemplate is { } template)
737732
{
738733
if (ContainsName(template.Path))
739734
{
@@ -743,8 +738,7 @@ private static bool IsMultipleOccurringParameter(PathSegment segment, UrlAttribu
743738

744739
if (urlAttribute.TryGetParentMember(out var parentMember))
745740
{
746-
if (parentMember is MethodDeclarationSyntax parentMethod &&
747-
parentMethod.Parent is ClassDeclarationSyntax classDeclaration &&
741+
if (parentMember is MethodDeclarationSyntax { Parent: ClassDeclarationSyntax classDeclaration } &&
748742
TryGetOtherTemplate(classDeclaration.AttributeLists, out var otherTemplate) &&
749743
ContainsName(otherTemplate.Path))
750744
{
@@ -822,7 +816,7 @@ private static bool ShouldUseExplicitRoute(PathSegment segment, SyntaxNodeAnalys
822816
private static bool ShouldRenameController(PathSegment segment, UrlAttribute urlAttribute, SyntaxNodeAnalysisContext context, out Replacement<Location> replacement)
823817
{
824818
if (urlAttribute.UrlTemplate is { } template &&
825-
template.Path.TryLast(x => x.Parameter == null, out var last) &&
819+
template.Path.TryLast(x => x.Parameter is null, out var last) &&
826820
last == segment &&
827821
segment.Span.Length > 0 &&
828822
segment.Span[0] != '[' &&
@@ -945,7 +939,7 @@ private static bool TryFindParameter(TemplateParameter templateParameter, Method
945939
result = null;
946940
return false;
947941

948-
bool IsFromRoute(ParameterSyntax p)
942+
static bool IsFromRoute(ParameterSyntax p)
949943
{
950944
foreach (var attributeList in p.AttributeLists)
951945
{

AspNetCoreAnalyzers/Helpers/UrlAttribute.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ argument.Expression is LiteralExpressionSyntax literal &&
7676

7777
internal bool TryGetParentMember(out MemberDeclarationSyntax memberDeclaration)
7878
{
79-
if (this.Attribute.Parent is AttributeListSyntax attributeList &&
80-
attributeList.Parent is MemberDeclarationSyntax temp)
79+
if (this.Attribute.Parent is AttributeListSyntax { Parent: MemberDeclarationSyntax temp })
8180
{
8281
memberDeclaration = temp;
8382
return true;

ValidCode/.editorconfig

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ dotnet_diagnostic.CS8618.severity = none
1515
# Default severity for analyzer diagnostics with category 'StyleCop.CSharp.DocumentationRules'
1616
dotnet_analyzer_diagnostic.category-StyleCop.CSharp.DocumentationRules.severity = none
1717
# SA0001: XML comment analysis is disabled due to project configuration
18-
dotnet_diagnostic.SA0001.severity = none
18+
dotnet_diagnostic.SA0001.severity = none
19+
20+
# IDE0079: Remove unnecessary suppression
21+
dotnet_diagnostic.IDE0079.severity = none

0 commit comments

Comments
 (0)