Skip to content

Commit 9244616

Browse files
committed
Update preferred code style
1 parent d56d53d commit 9244616

8 files changed

Lines changed: 132 additions & 70 deletions

File tree

.editorconfig

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,72 @@ insert_final_newline = true
66
indent_style = space
77
indent_size = 4
88

9+
# Non-private static fields are PascalCase
10+
dotnet_naming_rule.non_private_static_fields_should_be_pascal_case.severity = silent
11+
dotnet_naming_rule.non_private_static_fields_should_be_pascal_case.symbols = non_private_static_fields
12+
dotnet_naming_rule.non_private_static_fields_should_be_pascal_case.style = non_private_static_field_style
13+
14+
dotnet_naming_symbols.non_private_static_fields.applicable_kinds = field
15+
dotnet_naming_symbols.non_private_static_fields.applicable_accessibilities = public, protected, internal, protected internal, private protected
16+
dotnet_naming_symbols.non_private_static_fields.required_modifiers = static
17+
18+
dotnet_naming_style.non_private_static_field_style.capitalization = pascal_case
19+
20+
# Constants are PascalCase
21+
dotnet_naming_rule.constants_should_be_pascal_case.severity = silent
22+
dotnet_naming_rule.constants_should_be_pascal_case.symbols = constants
23+
dotnet_naming_rule.constants_should_be_pascal_case.style = constant_style
24+
25+
dotnet_naming_symbols.constants.applicable_kinds = field, local
26+
dotnet_naming_symbols.constants.required_modifiers = const
27+
28+
dotnet_naming_style.constant_style.capitalization = pascal_case
29+
30+
# Fields are camelCase and start with _
31+
dotnet_naming_rule.instance_fields_should_be_camel_case.severity = silent
32+
dotnet_naming_rule.instance_fields_should_be_camel_case.symbols = instance_fields
33+
dotnet_naming_rule.instance_fields_should_be_camel_case.style = instance_field_style
34+
35+
dotnet_naming_symbols.instance_fields.applicable_kinds = field
36+
37+
dotnet_naming_style.instance_field_style.capitalization = camel_case
38+
dotnet_naming_style.instance_field_style.required_prefix = _
39+
40+
# Locals and parameters are camelCase
41+
dotnet_naming_rule.locals_should_be_camel_case.severity = silent
42+
dotnet_naming_rule.locals_should_be_camel_case.symbols = locals_and_parameters
43+
dotnet_naming_rule.locals_should_be_camel_case.style = camel_case_style
44+
45+
dotnet_naming_symbols.locals_and_parameters.applicable_kinds = parameter, local
46+
47+
dotnet_naming_style.camel_case_style.capitalization = camel_case
48+
49+
# Local functions are PascalCase
50+
dotnet_naming_rule.local_functions_should_be_pascal_case.severity = silent
51+
dotnet_naming_rule.local_functions_should_be_pascal_case.symbols = local_functions
52+
dotnet_naming_rule.local_functions_should_be_pascal_case.style = local_function_style
53+
54+
dotnet_naming_symbols.local_functions.applicable_kinds = local_function
55+
56+
dotnet_naming_style.local_function_style.capitalization = pascal_case
57+
58+
# By default, name items with PascalCase
59+
dotnet_naming_rule.members_should_be_pascal_case.severity = silent
60+
dotnet_naming_rule.members_should_be_pascal_case.symbols = all_members
61+
dotnet_naming_rule.members_should_be_pascal_case.style = pascal_case_style
62+
63+
dotnet_naming_symbols.all_members.applicable_kinds = *
64+
65+
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
66+
967
# Sort using and Import directives with System.* appearing first
1068
dotnet_sort_system_directives_first = true
1169

12-
# Always use "this." and "Me." when applicable; let StyleCop Analyzers provide the warning and fix
13-
dotnet_style_qualification_for_field = true:none
14-
dotnet_style_qualification_for_property = true:none
15-
dotnet_style_qualification_for_method = true:none
16-
dotnet_style_qualification_for_event = true:none
70+
# Only use "this." and "Me." when required; let StyleCop Analyzers provide the warning and fix
71+
dotnet_style_qualification_for_field = false:none
72+
dotnet_style_qualification_for_property = false:none
73+
dotnet_style_qualification_for_method = false:none
74+
dotnet_style_qualification_for_event = false:none
1775

1876
# Use language keywords where applicable; let StyleCop Analyzers provide the warning and fix
1977
dotnet_style_predefined_type_for_locals_parameters_members = true:none

DocumentationAnalyzers/DocumentationAnalyzers.CodeFixes/Helpers/CustomBatchFixAllProvider.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ public override async Task<CodeAction> GetFixAsync(FixAllContext fixAllContext)
3131
{
3232
if (fixAllContext.Document != null)
3333
{
34-
var documentsAndDiagnosticsToFixMap = await this.GetDocumentDiagnosticsToFixAsync(fixAllContext).ConfigureAwait(false);
35-
return await this.GetFixAsync(documentsAndDiagnosticsToFixMap, fixAllContext).ConfigureAwait(false);
34+
var documentsAndDiagnosticsToFixMap = await GetDocumentDiagnosticsToFixAsync(fixAllContext).ConfigureAwait(false);
35+
return await GetFixAsync(documentsAndDiagnosticsToFixMap, fixAllContext).ConfigureAwait(false);
3636
}
3737
else
3838
{
39-
var projectsAndDiagnosticsToFixMap = await this.GetProjectDiagnosticsToFixAsync(fixAllContext).ConfigureAwait(false);
40-
return await this.GetFixAsync(projectsAndDiagnosticsToFixMap, fixAllContext).ConfigureAwait(false);
39+
var projectsAndDiagnosticsToFixMap = await GetProjectDiagnosticsToFixAsync(fixAllContext).ConfigureAwait(false);
40+
return await GetFixAsync(projectsAndDiagnosticsToFixMap, fixAllContext).ConfigureAwait(false);
4141
}
4242
}
4343

@@ -61,14 +61,14 @@ public virtual async Task<CodeAction> GetFixAsync(
6161

6262
var document = documents[index];
6363
fixesBag[index] = new List<CodeAction>();
64-
fixOperations.Add(this.AddDocumentFixesAsync(document, documentsAndDiagnosticsToFixMap[document], fixesBag[index].Add, fixAllContext));
64+
fixOperations.Add(AddDocumentFixesAsync(document, documentsAndDiagnosticsToFixMap[document], fixesBag[index].Add, fixAllContext));
6565
}
6666

6767
await Task.WhenAll(fixOperations).ConfigureAwait(false);
6868

6969
if (fixesBag.Any(fixes => fixes.Count > 0))
7070
{
71-
return await this.TryGetMergedFixAsync(fixesBag.SelectMany(i => i), fixAllContext).ConfigureAwait(false);
71+
return await TryGetMergedFixAsync(fixesBag.SelectMany(i => i), fixAllContext).ConfigureAwait(false);
7272
}
7373
}
7474

@@ -149,14 +149,14 @@ public virtual async Task<CodeAction> GetFixAsync(
149149
index++;
150150
var diagnostics = projectsAndDiagnosticsToFixMap[project];
151151
fixesBag[index] = new List<CodeAction>();
152-
fixOperations.Add(this.AddProjectFixesAsync(project, diagnostics, fixesBag[index].Add, fixAllContext));
152+
fixOperations.Add(AddProjectFixesAsync(project, diagnostics, fixesBag[index].Add, fixAllContext));
153153
}
154154

155155
await Task.WhenAll(fixOperations).ConfigureAwait(false);
156156

157157
if (fixesBag.Any(fixes => fixes.Count > 0))
158158
{
159-
return await this.TryGetMergedFixAsync(fixesBag.SelectMany(i => i), fixAllContext).ConfigureAwait(false);
159+
return await TryGetMergedFixAsync(fixesBag.SelectMany(i => i), fixAllContext).ConfigureAwait(false);
160160
}
161161
}
162162

@@ -181,10 +181,10 @@ public virtual async Task<CodeAction> TryGetMergedFixAsync(IEnumerable<CodeActio
181181
}
182182

183183
var solution = fixAllContext.Solution;
184-
var newSolution = await this.TryMergeFixesAsync(solution, batchOfFixes, fixAllContext.CancellationToken).ConfigureAwait(false);
184+
var newSolution = await TryMergeFixesAsync(solution, batchOfFixes, fixAllContext.CancellationToken).ConfigureAwait(false);
185185
if (newSolution != null && newSolution != solution)
186186
{
187-
var title = this.GetFixAllTitle(fixAllContext);
187+
var title = GetFixAllTitle(fixAllContext);
188188
return CodeAction.Create(title, cancellationToken => Task.FromResult(newSolution));
189189
}
190190

DocumentationAnalyzers/DocumentationAnalyzers.Status.Generator/DocumentationDiagnostic.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public static DocumentationDiagnostic FromJson(string value)
121121
/// </returns>
122122
public override string ToString()
123123
{
124-
return this.Id + " " + this.Name;
124+
return Id + " " + Name;
125125
}
126126

127127
/// <summary>

DocumentationAnalyzers/DocumentationAnalyzers.Status.Generator/SolutionReader.cs

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace DocumentationAnalyzers.Status.Generator
66
using System;
77
using System.Collections.Generic;
88
using System.Collections.Immutable;
9-
using System.IO;
109
using System.Linq;
1110
using System.Reflection;
1211
using System.Text.RegularExpressions;
@@ -24,28 +23,28 @@ namespace DocumentationAnalyzers.Status.Generator
2423
/// </summary>
2524
public class SolutionReader
2625
{
27-
private static Regex diagnosticPathRegex = new Regex(@"(?<type>[A-Za-z]+)Rules\\(?<name>[A-Za-z0-9]+)\.cs$");
28-
private INamedTypeSymbol diagnosticAnalyzerTypeSymbol;
29-
private INamedTypeSymbol noCodeFixAttributeTypeSymbol;
30-
31-
private Solution solution;
32-
private Project analyzerProject;
33-
private Project codeFixProject;
34-
private MSBuildWorkspace workspace;
35-
private Assembly analyzerAssembly;
36-
private Assembly codeFixAssembly;
37-
private Compilation analyzerCompilation;
38-
private Compilation codeFixCompilation;
39-
private ITypeSymbol booleanType;
40-
private Type batchFixerType;
26+
private static Regex _diagnosticPathRegex = new Regex(@"(?<type>[A-Za-z]+)Rules\\(?<name>[A-Za-z0-9]+)\.cs$");
27+
private INamedTypeSymbol _diagnosticAnalyzerTypeSymbol;
28+
private INamedTypeSymbol _noCodeFixAttributeTypeSymbol;
29+
30+
private Solution _solution;
31+
private Project _analyzerProject;
32+
private Project _codeFixProject;
33+
private MSBuildWorkspace _workspace;
34+
private Assembly _analyzerAssembly;
35+
private Assembly _codeFixAssembly;
36+
private Compilation _analyzerCompilation;
37+
private Compilation _codeFixCompilation;
38+
private ITypeSymbol _booleanType;
39+
private Type _batchFixerType;
4140

4241
private SolutionReader()
4342
{
4443
AppDomain.CurrentDomain.AssemblyResolve += (s, e) =>
4544
{
46-
if (e.Name.Contains(this.AnalyzerProjectName))
45+
if (e.Name.Contains(AnalyzerProjectName))
4746
{
48-
return this.analyzerAssembly;
47+
return _analyzerAssembly;
4948
}
5049

5150
return null;
@@ -74,7 +73,7 @@ public static async Task<SolutionReader> CreateAsync(string pathToSln, string an
7473
reader.SlnPath = pathToSln;
7574
reader.AnalyzerProjectName = analyzerProjectName;
7675
reader.CodeFixProjectName = codeFixProjectName;
77-
reader.workspace = MSBuildWorkspace.Create();
76+
reader._workspace = MSBuildWorkspace.Create();
7877

7978
await reader.InitializeAsync().ConfigureAwait(false);
8079

@@ -89,11 +88,11 @@ public async Task<ImmutableList<DocumentationDiagnostic>> GetDiagnosticsAsync()
8988
{
9089
var diagnostics = ImmutableList.CreateBuilder<DocumentationDiagnostic>();
9190

92-
var syntaxTrees = this.analyzerCompilation.SyntaxTrees;
91+
var syntaxTrees = _analyzerCompilation.SyntaxTrees;
9392

9493
foreach (var syntaxTree in syntaxTrees)
9594
{
96-
var match = diagnosticPathRegex.Match(syntaxTree.FilePath);
95+
var match = _diagnosticPathRegex.Match(syntaxTree.FilePath);
9796
if (!match.Success)
9897
{
9998
continue;
@@ -104,7 +103,7 @@ public async Task<ImmutableList<DocumentationDiagnostic>> GetDiagnosticsAsync()
104103

105104
// Check if this syntax tree represents a diagnostic
106105
SyntaxNode syntaxRoot = await syntaxTree.GetRootAsync().ConfigureAwait(false);
107-
SemanticModel semanticModel = this.analyzerCompilation.GetSemanticModel(syntaxTree);
106+
SemanticModel semanticModel = _analyzerCompilation.GetSemanticModel(syntaxTree);
108107
SyntaxNode classSyntaxNode = syntaxRoot.DescendantNodes().FirstOrDefault(x => x.IsKind(SyntaxKind.ClassDeclaration));
109108

110109
if (classSyntaxNode == null)
@@ -114,7 +113,7 @@ public async Task<ImmutableList<DocumentationDiagnostic>> GetDiagnosticsAsync()
114113

115114
INamedTypeSymbol classSymbol = semanticModel.GetDeclaredSymbol(classSyntaxNode) as INamedTypeSymbol;
116115

117-
if (!this.InheritsFrom(classSymbol, this.diagnosticAnalyzerTypeSymbol))
116+
if (!InheritsFrom(classSymbol, _diagnosticAnalyzerTypeSymbol))
118117
{
119118
continue;
120119
}
@@ -126,12 +125,12 @@ public async Task<ImmutableList<DocumentationDiagnostic>> GetDiagnosticsAsync()
126125

127126
bool hasImplementation = HasImplementation(syntaxRoot);
128127

129-
IEnumerable<DiagnosticDescriptor> descriptorInfos = this.GetDescriptor(classSymbol);
128+
IEnumerable<DiagnosticDescriptor> descriptorInfos = GetDescriptor(classSymbol);
130129

131130
foreach (var descriptorInfo in descriptorInfos)
132131
{
133-
var (codeFixStatus, fixAllStatus) = this.GetCodeFixAndFixAllStatus(descriptorInfo.Id, classSymbol, out noCodeFixReason);
134-
string status = this.GetStatus(classSymbol, syntaxRoot, semanticModel, descriptorInfo);
132+
var (codeFixStatus, fixAllStatus) = GetCodeFixAndFixAllStatus(descriptorInfo.Id, classSymbol, out noCodeFixReason);
133+
string status = GetStatus(classSymbol, syntaxRoot, semanticModel, descriptorInfo);
135134
if (descriptorInfo.CustomTags.Contains(WellKnownDiagnosticTags.NotConfigurable))
136135
{
137136
continue;
@@ -176,33 +175,33 @@ private static bool HasImplementation(SyntaxNode syntaxRoot)
176175

177176
private async Task InitializeAsync()
178177
{
179-
this.solution = await this.workspace.OpenSolutionAsync(this.SlnPath).ConfigureAwait(false);
178+
_solution = await _workspace.OpenSolutionAsync(SlnPath).ConfigureAwait(false);
180179

181-
this.analyzerProject = this.solution.Projects.First(x => x.Name == this.AnalyzerProjectName || x.AssemblyName == this.AnalyzerProjectName);
182-
this.analyzerCompilation = await this.analyzerProject.GetCompilationAsync().ConfigureAwait(false);
183-
this.analyzerCompilation = this.analyzerCompilation.WithOptions(this.analyzerCompilation.Options.WithOutputKind(OutputKind.DynamicallyLinkedLibrary));
180+
_analyzerProject = _solution.Projects.First(x => x.Name == AnalyzerProjectName || x.AssemblyName == AnalyzerProjectName);
181+
_analyzerCompilation = await _analyzerProject.GetCompilationAsync().ConfigureAwait(false);
182+
_analyzerCompilation = _analyzerCompilation.WithOptions(_analyzerCompilation.Options.WithOutputKind(OutputKind.DynamicallyLinkedLibrary));
184183

185-
this.codeFixProject = this.solution.Projects.First(x => x.Name == this.CodeFixProjectName || x.AssemblyName == this.CodeFixProjectName);
186-
this.codeFixCompilation = await this.codeFixProject.GetCompilationAsync().ConfigureAwait(false);
187-
this.codeFixCompilation = this.codeFixCompilation.WithOptions(this.codeFixCompilation.Options.WithOutputKind(OutputKind.DynamicallyLinkedLibrary));
184+
_codeFixProject = _solution.Projects.First(x => x.Name == CodeFixProjectName || x.AssemblyName == CodeFixProjectName);
185+
_codeFixCompilation = await _codeFixProject.GetCompilationAsync().ConfigureAwait(false);
186+
_codeFixCompilation = _codeFixCompilation.WithOptions(_codeFixCompilation.Options.WithOutputKind(OutputKind.DynamicallyLinkedLibrary));
188187

189-
this.booleanType = this.analyzerCompilation.GetSpecialType(SpecialType.System_Boolean);
188+
_booleanType = _analyzerCompilation.GetSpecialType(SpecialType.System_Boolean);
190189

191-
this.LoadAssemblies();
190+
LoadAssemblies();
192191

193-
this.noCodeFixAttributeTypeSymbol = this.analyzerCompilation.GetTypeByMetadataName("DocumentationAnalyzers.NoCodeFixAttribute");
194-
this.diagnosticAnalyzerTypeSymbol = this.analyzerCompilation.GetTypeByMetadataName(typeof(DiagnosticAnalyzer).FullName);
192+
_noCodeFixAttributeTypeSymbol = _analyzerCompilation.GetTypeByMetadataName("DocumentationAnalyzers.NoCodeFixAttribute");
193+
_diagnosticAnalyzerTypeSymbol = _analyzerCompilation.GetTypeByMetadataName(typeof(DiagnosticAnalyzer).FullName);
195194

196-
this.batchFixerType = this.codeFixAssembly.GetType("DocumentationAnalyzers.Helpers.CustomBatchFixAllProvider");
195+
_batchFixerType = _codeFixAssembly.GetType("DocumentationAnalyzers.Helpers.CustomBatchFixAllProvider");
197196

198-
this.InitializeCodeFixTypes();
197+
InitializeCodeFixTypes();
199198
}
200199

201200
private void InitializeCodeFixTypes()
202201
{
203-
var codeFixTypes = this.codeFixAssembly.GetTypes().Where(x => x.FullName.EndsWith("CodeFixProvider"));
202+
var codeFixTypes = _codeFixAssembly.GetTypes().Where(x => x.FullName.EndsWith("CodeFixProvider"));
204203

205-
this.CodeFixProviders = ImmutableArray.Create(
204+
CodeFixProviders = ImmutableArray.Create(
206205
codeFixTypes
207206
.Select(t => Activator.CreateInstance(t, true))
208207
.OfType<CodeFixProvider>()
@@ -212,8 +211,8 @@ private void InitializeCodeFixTypes()
212211

213212
private void LoadAssemblies()
214213
{
215-
this.analyzerAssembly = this.GetAssembly(this.analyzerProject);
216-
this.codeFixAssembly = this.GetAssembly(this.codeFixProject);
214+
_analyzerAssembly = GetAssembly(_analyzerProject);
215+
_codeFixAssembly = GetAssembly(_codeFixProject);
217216
}
218217

219218
private Assembly GetAssembly(Project project)
@@ -261,7 +260,7 @@ private string GetStatus(INamedTypeSymbol classSymbol, SyntaxNode root, Semantic
261260

262261
// We use the fact that the only parameter that returns a boolean is the one we are interested in
263262
var enabledByDefaultParameter = from argument in initializer.ArgumentList.Arguments
264-
where Equals(model.GetTypeInfo(argument.Expression).Type, this.booleanType)
263+
where Equals(model.GetTypeInfo(argument.Expression).Type, _booleanType)
265264
select argument.Expression;
266265
var parameter = enabledByDefaultParameter.FirstOrDefault();
267266
string parameterString = parameter.ToString();
@@ -280,7 +279,7 @@ where Equals(model.GetTypeInfo(argument.Expression).Type, this.booleanType)
280279

281280
private IEnumerable<DiagnosticDescriptor> GetDescriptor(INamedTypeSymbol classSymbol)
282281
{
283-
var analyzer = (DiagnosticAnalyzer)Activator.CreateInstance(this.analyzerAssembly.GetType(classSymbol.ToString()));
282+
var analyzer = (DiagnosticAnalyzer)Activator.CreateInstance(_analyzerAssembly.GetType(classSymbol.ToString()));
284283

285284
// This currently only supports one diagnostic for each analyzer.
286285
return analyzer.SupportedDiagnostics;
@@ -295,7 +294,7 @@ private IEnumerable<DiagnosticDescriptor> GetDescriptor(INamedTypeSymbol classSy
295294

296295
var noCodeFixAttribute = classSymbol
297296
.GetAttributes()
298-
.SingleOrDefault(x => Equals(x.AttributeClass, this.noCodeFixAttributeTypeSymbol));
297+
.SingleOrDefault(x => Equals(x.AttributeClass, _noCodeFixAttributeTypeSymbol));
299298

300299
bool hasCodeFix = noCodeFixAttribute == null;
301300
if (!hasCodeFix)
@@ -310,9 +309,9 @@ private IEnumerable<DiagnosticDescriptor> GetDescriptor(INamedTypeSymbol classSy
310309
else
311310
{
312311
// Check if the code fix actually exists
313-
var codeFixes = this.CodeFixProviders
312+
var codeFixes = CodeFixProviders
314313
.Where(x => x.FixableDiagnosticIds.Contains(diagnosticId))
315-
.Select(x => this.IsBatchFixer(x))
314+
.Select(x => IsBatchFixer(x))
316315
.Where(x => x != null)
317316
.Select(x => (bool)x).ToArray();
318317

@@ -347,7 +346,7 @@ private IEnumerable<DiagnosticDescriptor> GetDescriptor(INamedTypeSymbol classSy
347346
}
348347
else
349348
{
350-
return fixAllProvider.GetType() == this.batchFixerType;
349+
return fixAllProvider.GetType() == _batchFixerType;
351350
}
352351
}
353352

0 commit comments

Comments
 (0)