Skip to content

Commit 8e1559f

Browse files
committed
Add stub analyzers for new readability rules
1 parent be984ba commit 8e1559f

14 files changed

Lines changed: 702 additions & 0 deletions

StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/ReadabilityResources.Designer.cs

Lines changed: 135 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/ReadabilityResources.resx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,4 +408,49 @@
408408
<data name="SA1128Title" xml:space="preserve">
409409
<value>Put constructor initializers on their own line</value>
410410
</data>
411+
<data name="SA1129Description" xml:space="preserve">
412+
<value>When creating a new instance of a value type T, the syntax 'default(T)' is functionally equivalent to the syntax 'new T()'. To avoid confusion regarding the behavior of the resulting instance, the first form is preferred.</value>
413+
</data>
414+
<data name="SA1129MessageFormat" xml:space="preserve">
415+
<value />
416+
</data>
417+
<data name="SA1129Title" xml:space="preserve">
418+
<value>Do not use default value type constructor</value>
419+
</data>
420+
<data name="SA1130Description" xml:space="preserve">
421+
<value>Lambda expressions are more succinct and easier to read than anonymous methods, so they should are preferred whenever the two are functionally equivalent.</value>
422+
</data>
423+
<data name="SA1130MessageFormat" xml:space="preserve">
424+
<value />
425+
</data>
426+
<data name="SA1130Title" xml:space="preserve">
427+
<value>Use lambda syntax</value>
428+
</data>
429+
<data name="SA1131Description" xml:space="preserve">
430+
<value>When a comparison is made between a variable and a literal, the variable should be placed on the left-hand-side to maximize readability.</value>
431+
</data>
432+
<data name="SA1131MessageFormat" xml:space="preserve">
433+
<value />
434+
</data>
435+
<data name="SA1131Title" xml:space="preserve">
436+
<value>Use readable conditions</value>
437+
</data>
438+
<data name="SA1132Description" xml:space="preserve">
439+
<value>Each field should be declared on its own line, in order to clearly see each field of a type and allow for proper documentation of the behavior of each field.</value>
440+
</data>
441+
<data name="SA1132MessageFormat" xml:space="preserve">
442+
<value />
443+
</data>
444+
<data name="SA1132Title" xml:space="preserve">
445+
<value>Do not combine fields</value>
446+
</data>
447+
<data name="SA1133Description" xml:space="preserve">
448+
<value>Each attribute usage should be placed in its own set of square brackets for maximum readability.</value>
449+
</data>
450+
<data name="SA1133MessageFormat" xml:space="preserve">
451+
<value />
452+
</data>
453+
<data name="SA1133Title" xml:space="preserve">
454+
<value>Do not combine attributes</value>
455+
</data>
411456
</root>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
4+
namespace StyleCop.Analyzers.ReadabilityRules
5+
{
6+
using System.Collections.Immutable;
7+
using Microsoft.CodeAnalysis;
8+
using Microsoft.CodeAnalysis.Diagnostics;
9+
10+
/// <summary>
11+
/// A value type was constructed using the syntax <c>new T()</c>.
12+
/// </summary>
13+
[DiagnosticAnalyzer(LanguageNames.CSharp)]
14+
internal class SA1129DoNotUseDefaultValueTypeConstructor : DiagnosticAnalyzer
15+
{
16+
/// <summary>
17+
/// The ID for diagnostics produced by the <see cref="SA1129DoNotUseDefaultValueTypeConstructor"/> analyzer.
18+
/// </summary>
19+
public const string DiagnosticId = "SA1129";
20+
private static readonly LocalizableString Title = new LocalizableResourceString(nameof(ReadabilityResources.SA1129Title), ReadabilityResources.ResourceManager, typeof(ReadabilityResources));
21+
private static readonly LocalizableString MessageFormat = new LocalizableResourceString(nameof(ReadabilityResources.SA1129MessageFormat), ReadabilityResources.ResourceManager, typeof(ReadabilityResources));
22+
private static readonly LocalizableString Description = new LocalizableResourceString(nameof(ReadabilityResources.SA1129Description), ReadabilityResources.ResourceManager, typeof(ReadabilityResources));
23+
private static readonly string HelpLink = "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1129.md";
24+
25+
private static readonly DiagnosticDescriptor Descriptor =
26+
new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, AnalyzerCategory.ReadabilityRules, DiagnosticSeverity.Warning, AnalyzerConstants.DisabledNoTests, Description, HelpLink);
27+
28+
/// <inheritdoc/>
29+
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; }
30+
= ImmutableArray.Create(Descriptor);
31+
32+
/// <inheritdoc/>
33+
public override void Initialize(AnalysisContext context)
34+
{
35+
// TODO: Implement analysis
36+
}
37+
}
38+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
4+
namespace StyleCop.Analyzers.ReadabilityRules
5+
{
6+
using System.Collections.Immutable;
7+
using Microsoft.CodeAnalysis;
8+
using Microsoft.CodeAnalysis.Diagnostics;
9+
10+
/// <summary>
11+
/// An anonymous method was declared using the form <c>delegate (parameters) { }</c>, when a lambda expression would
12+
/// provide equivalent behavior with the syntax <c>(parameters) => { }</c>.
13+
/// </summary>
14+
[DiagnosticAnalyzer(LanguageNames.CSharp)]
15+
internal class SA1130UseLambdaSyntax : DiagnosticAnalyzer
16+
{
17+
/// <summary>
18+
/// The ID for diagnostics produced by the <see cref="SA1130UseLambdaSyntax"/> analyzer.
19+
/// </summary>
20+
public const string DiagnosticId = "SA1130";
21+
private static readonly LocalizableString Title = new LocalizableResourceString(nameof(ReadabilityResources.SA1130Title), ReadabilityResources.ResourceManager, typeof(ReadabilityResources));
22+
private static readonly LocalizableString MessageFormat = new LocalizableResourceString(nameof(ReadabilityResources.SA1130MessageFormat), ReadabilityResources.ResourceManager, typeof(ReadabilityResources));
23+
private static readonly LocalizableString Description = new LocalizableResourceString(nameof(ReadabilityResources.SA1130Description), ReadabilityResources.ResourceManager, typeof(ReadabilityResources));
24+
private static readonly string HelpLink = "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1130.md";
25+
26+
private static readonly DiagnosticDescriptor Descriptor =
27+
new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, AnalyzerCategory.ReadabilityRules, DiagnosticSeverity.Warning, AnalyzerConstants.DisabledNoTests, Description, HelpLink);
28+
29+
/// <inheritdoc/>
30+
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; }
31+
= ImmutableArray.Create(Descriptor);
32+
33+
/// <inheritdoc/>
34+
public override void Initialize(AnalysisContext context)
35+
{
36+
// TODO: Implement analysis
37+
}
38+
}
39+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
4+
namespace StyleCop.Analyzers.ReadabilityRules
5+
{
6+
using System.Collections.Immutable;
7+
using Microsoft.CodeAnalysis;
8+
using Microsoft.CodeAnalysis.Diagnostics;
9+
10+
/// <summary>
11+
/// A comparison was made between a variable and a literal or constant value, and the variable appeared on the
12+
/// right-hand-side of the expression.
13+
/// </summary>
14+
[DiagnosticAnalyzer(LanguageNames.CSharp)]
15+
internal class SA1131UseReadableConditions : DiagnosticAnalyzer
16+
{
17+
/// <summary>
18+
/// The ID for diagnostics produced by the <see cref="SA1131UseReadableConditions"/> analyzer.
19+
/// </summary>
20+
public const string DiagnosticId = "SA1131";
21+
private static readonly LocalizableString Title = new LocalizableResourceString(nameof(ReadabilityResources.SA1131Title), ReadabilityResources.ResourceManager, typeof(ReadabilityResources));
22+
private static readonly LocalizableString MessageFormat = new LocalizableResourceString(nameof(ReadabilityResources.SA1131MessageFormat), ReadabilityResources.ResourceManager, typeof(ReadabilityResources));
23+
private static readonly LocalizableString Description = new LocalizableResourceString(nameof(ReadabilityResources.SA1131Description), ReadabilityResources.ResourceManager, typeof(ReadabilityResources));
24+
private static readonly string HelpLink = "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1131.md";
25+
26+
private static readonly DiagnosticDescriptor Descriptor =
27+
new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, AnalyzerCategory.ReadabilityRules, DiagnosticSeverity.Warning, AnalyzerConstants.DisabledNoTests, Description, HelpLink);
28+
29+
/// <inheritdoc/>
30+
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; }
31+
= ImmutableArray.Create(Descriptor);
32+
33+
/// <inheritdoc/>
34+
public override void Initialize(AnalysisContext context)
35+
{
36+
// TODO: Implement analysis
37+
}
38+
}
39+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
4+
namespace StyleCop.Analyzers.ReadabilityRules
5+
{
6+
using System.Collections.Immutable;
7+
using Microsoft.CodeAnalysis;
8+
using Microsoft.CodeAnalysis.Diagnostics;
9+
10+
/// <summary>
11+
/// Two or more fields were declared in the same field declaration syntax.
12+
/// </summary>
13+
[DiagnosticAnalyzer(LanguageNames.CSharp)]
14+
internal class SA1132DoNotCombineFields : DiagnosticAnalyzer
15+
{
16+
/// <summary>
17+
/// The ID for diagnostics produced by the <see cref="SA1132DoNotCombineFields"/> analyzer.
18+
/// </summary>
19+
public const string DiagnosticId = "SA1132";
20+
private static readonly LocalizableString Title = new LocalizableResourceString(nameof(ReadabilityResources.SA1132Title), ReadabilityResources.ResourceManager, typeof(ReadabilityResources));
21+
private static readonly LocalizableString MessageFormat = new LocalizableResourceString(nameof(ReadabilityResources.SA1132MessageFormat), ReadabilityResources.ResourceManager, typeof(ReadabilityResources));
22+
private static readonly LocalizableString Description = new LocalizableResourceString(nameof(ReadabilityResources.SA1132Description), ReadabilityResources.ResourceManager, typeof(ReadabilityResources));
23+
private static readonly string HelpLink = "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1132.md";
24+
25+
private static readonly DiagnosticDescriptor Descriptor =
26+
new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, AnalyzerCategory.ReadabilityRules, DiagnosticSeverity.Warning, AnalyzerConstants.DisabledNoTests, Description, HelpLink);
27+
28+
/// <inheritdoc/>
29+
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; }
30+
= ImmutableArray.Create(Descriptor);
31+
32+
/// <inheritdoc/>
33+
public override void Initialize(AnalysisContext context)
34+
{
35+
// TODO: Implement analysis
36+
}
37+
}
38+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
4+
namespace StyleCop.Analyzers.ReadabilityRules
5+
{
6+
using System.Collections.Immutable;
7+
using Microsoft.CodeAnalysis;
8+
using Microsoft.CodeAnalysis.Diagnostics;
9+
10+
/// <summary>
11+
/// Two or more attribute uses appeared within the same set of square brackets.
12+
/// </summary>
13+
[DiagnosticAnalyzer(LanguageNames.CSharp)]
14+
internal class SA1133DoNotCombineAttributes : DiagnosticAnalyzer
15+
{
16+
/// <summary>
17+
/// The ID for diagnostics produced by the <see cref="SA1133DoNotCombineAttributes"/> analyzer.
18+
/// </summary>
19+
public const string DiagnosticId = "SA1133";
20+
private static readonly LocalizableString Title = new LocalizableResourceString(nameof(ReadabilityResources.SA1133Title), ReadabilityResources.ResourceManager, typeof(ReadabilityResources));
21+
private static readonly LocalizableString MessageFormat = new LocalizableResourceString(nameof(ReadabilityResources.SA1133MessageFormat), ReadabilityResources.ResourceManager, typeof(ReadabilityResources));
22+
private static readonly LocalizableString Description = new LocalizableResourceString(nameof(ReadabilityResources.SA1133Description), ReadabilityResources.ResourceManager, typeof(ReadabilityResources));
23+
private static readonly string HelpLink = "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1133.md";
24+
25+
private static readonly DiagnosticDescriptor Descriptor =
26+
new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, AnalyzerCategory.ReadabilityRules, DiagnosticSeverity.Warning, AnalyzerConstants.DisabledNoTests, Description, HelpLink);
27+
28+
/// <inheritdoc/>
29+
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; }
30+
= ImmutableArray.Create(Descriptor);
31+
32+
/// <inheritdoc/>
33+
public override void Initialize(AnalysisContext context)
34+
{
35+
// TODO: Implement analysis
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)