Skip to content

Commit 5ce226d

Browse files
Add Meziantou.Analyzers (#160)
1 parent 352953b commit 5ce226d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+127
-97
lines changed

.editorconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,3 +306,13 @@ dotnet_diagnostic.CA2000.severity = error # CA2000: Dispose object
306306
dotnet_diagnostic.CA1515.severity = none # CA1515: Consider making public types internal
307307
dotnet_diagnostic.CA1708.severity = none # CA1708: Identifiers should differ by more than case
308308
dotnet_diagnostic.CA1716.severity = none # CA1716: Identifiers should not match keywords
309+
310+
MA0053.public_class_should_be_sealed = true
311+
MA0053.exceptions_should_be_sealed = true
312+
313+
dotnet_diagnostic.MA0004.severity = none
314+
dotnet_diagnostic.MA0023.severity = none
315+
dotnet_diagnostic.MA0048.severity = none
316+
dotnet_diagnostic.MA0051.severity = none
317+
dotnet_diagnostic.MA0053.severity = warning
318+
dotnet_diagnostic.MA0071.severity = none

Directory.Packages.props

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,8 @@
3434
<PackageVersion Include="Verify.TUnit" Version="28.9.0" />
3535
<PackageVersion Include="xunit.v3.assert" Version="1.0.1" />
3636
</ItemGroup>
37+
38+
<ItemGroup>
39+
<GlobalPackageReference Include="Meziantou.Analyzer" Version="2.0.186" />
40+
</ItemGroup>
3741
</Project>

src/Common/ITypeSymbolExtensions.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,15 @@ public static IEnumerable<ITypeSymbol> GetBaseTypesAndThis(this ITypeSymbol? typ
5353
}
5454
}
5555

56-
public static IEnumerable<ISymbol> GetAllMembers(this ITypeSymbol type)
57-
{
58-
if (type is { TypeKind: TypeKind.Interface })
59-
{
60-
return type.AllInterfaces
56+
public static IEnumerable<ISymbol> GetAllMembers(this ITypeSymbol type) =>
57+
type is { TypeKind: TypeKind.Interface }
58+
? type
59+
.AllInterfaces
6160
.SelectMany(i => i.GetMembers())
62-
.Concat(type.GetMembers());
63-
}
64-
else
65-
{
66-
return type
61+
.Concat(type.GetMembers())
62+
: type
6763
.GetBaseTypesAndThis()
6864
.SelectMany(t => t.GetMembers());
69-
}
70-
}
7165

7266
public static bool IsValidateAttribute([NotNullWhen(returnValue: true)] this INamedTypeSymbol? typeSymbol) =>
7367
typeSymbol is

src/Immediate.Validations.Analyzers/UnusedConstructorParameterSuppressor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ public override void ReportSuppressions(SuppressionAnalysisContext context)
3636

3737
if (symbol.BaseType.IsValidatorAttribute())
3838
{
39-
var suppression = SupportedSuppressions.First(s => s.SuppressedDiagnosticId == diagnostic.Id);
39+
var suppression = SupportedSuppressions
40+
.First(s => string.Equals(s.SuppressedDiagnosticId, diagnostic.Id, StringComparison.Ordinal));
4041

4142
context.ReportSuppression(
4243
Suppression.Create(

src/Immediate.Validations.Analyzers/ValidateClassAnalyzer.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,9 @@ ITypeSymbol typeArgumentType
352352
attributeProperties ??= attribute.AttributeClass!.GetMembers()
353353
.OfType<IPropertySymbol>()
354354
.ToList();
355-
var property = attributeProperties.First(a => a.Name == name);
355+
356+
var property = attributeProperties
357+
.First(a => string.Equals(a.Name, name, StringComparison.Ordinal));
356358

357359
ValidateArgument(
358360
context,
@@ -370,7 +372,7 @@ ITypeSymbol typeArgumentType
370372
{
371373
for (var j = 0; j < attributeParameters.Length; j++)
372374
{
373-
if (attributeParameters[j].Name == name)
375+
if (string.Equals(attributeParameters[j].Name, name, StringComparison.Ordinal))
374376
{
375377
ValidateArgument(
376378
context,
@@ -422,12 +424,13 @@ List<ISymbol> members
422424
if (!parameter.IsTargetTypeSymbol())
423425
return;
424426

425-
var validateParameter = validateParameterSymbols.First(p => p.Name == parameter.Name);
427+
var validateParameter = validateParameterSymbols
428+
.First(p => string.Equals(p.Name, parameter.Name, StringComparison.Ordinal));
426429

427430
if (syntax.Expression.IsNameOfExpression(out var propertyName))
428431
{
429432
var member = members
430-
.FirstOrDefault(p => p.Name == propertyName);
433+
.Find(p => string.Equals(p.Name, propertyName, StringComparison.Ordinal));
431434

432435
if (member is null)
433436
{

src/Immediate.Validations.Analyzers/ValidatorClassAnalyzer.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,7 @@ IMethodSymbol methodSymbol
283283
.GetMembers()
284284
.OfType<IPropertySymbol>()
285285
.Where(p =>
286-
p.Name != "Message"
287-
&& !p.IsStatic
286+
p is { Name: not "Message", IsStatic: false }
288287
)
289288
.Cast<ISymbol>()
290289
.ToList();

src/Immediate.Validations.CodeFixes/AddAdditionalValidationsCodeRefactoringProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace Immediate.Validations.CodeFixes;
1010

1111
[ExportCodeRefactoringProvider(LanguageNames.CSharp, Name = "Add AdditionalValidations Method")]
12-
public class AddAdditionalValidationsCodeRefactoringProvider : CodeRefactoringProvider
12+
public sealed class AddAdditionalValidationsCodeRefactoringProvider : CodeRefactoringProvider
1313
{
1414
public override async Task ComputeRefactoringsAsync(CodeRefactoringContext context)
1515
{

src/Immediate.Validations.CodeFixes/AddValidateMethodCodefixProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace Immediate.Validations.CodeFixes;
1212

1313
[ExportCodeFixProvider(LanguageNames.CSharp)]
14-
public class AddValidateMethodCodefixProvider : CodeFixProvider
14+
public sealed class AddValidateMethodCodefixProvider : CodeFixProvider
1515
{
1616
public sealed override ImmutableArray<string> FixableDiagnosticIds { get; } =
1717
ImmutableArray.Create([DiagnosticIds.IV0001ValidateMethodMustExist]);

src/Immediate.Validations.CodeFixes/CorrectValidatePropertyReturnTypeCodefixProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace Immediate.Validations.CodeFixes;
1111

1212
[ExportCodeFixProvider(LanguageNames.CSharp)]
13-
public class CorrectValidatePropertyReturnTypeCodefixProvider : CodeFixProvider
13+
public sealed class CorrectValidatePropertyReturnTypeCodefixProvider : CodeFixProvider
1414
{
1515
public sealed override ImmutableArray<string> FixableDiagnosticIds { get; } =
1616
ImmutableArray.Create([DiagnosticIds.IV0004ValidateMethodMustReturnValueTuple]);

src/Immediate.Validations.CodeFixes/MakeValidatePropertyMethodStaticCodefixProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace Immediate.Validations.CodeFixes;
1010

1111
[ExportCodeFixProvider(LanguageNames.CSharp)]
12-
public class MakeValidatePropertyMethodStaticCodefixProvider : CodeFixProvider
12+
public sealed class MakeValidatePropertyMethodStaticCodefixProvider : CodeFixProvider
1313
{
1414
public sealed override ImmutableArray<string> FixableDiagnosticIds { get; } =
1515
ImmutableArray.Create([DiagnosticIds.IV0002ValidateMethodMustBeStatic]);

0 commit comments

Comments
 (0)