Skip to content

Commit c330114

Browse files
authored
Fix/resharper warnings (#3790)
* Fix some resharper warnings * fix resharper warnings and introduced namespacing for internals in the low level client * fixes * addressed resharper warnings in Elasticsearch.Net * started to tackle NEST warnings * fix obsolete warning from forward port of #3770 (cherry picked from commit 7c4996f) * tackled NEST warnings further * split requests/descriptors * tackled more warnings * tackled more warnings
1 parent 7c364be commit c330114

File tree

1,821 files changed

+26109
-25164
lines changed

Some content is hidden

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

1,821 files changed

+26109
-25164
lines changed

.editorconfig

Lines changed: 79 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,111 @@
1+
root=true
2+
3+
[*.cs]
4+
trim_trailing_whitespace=true
5+
insert_final_newline=true
6+
7+
[*]
8+
indent_style = tab
9+
indent_size = 4
10+
11+
[*.cshtml]
12+
indent_style = tab
13+
indent_size = 4
14+
15+
[*.{fs,fsx,yml}]
16+
indent_style = space
17+
indent_size = 4
18+
19+
[*.{md,markdown,json,js,csproj,fsproj,targets,targets,props}]
20+
indent_style = space
21+
indent_size = 2
22+
123
# Dotnet code style settings:
224
[*.{cs,vb}]
325

26+
# ---
27+
# naming conventions https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-naming-conventions
28+
# currently not supported in Rider/Resharper so not using these for now
29+
# ---
30+
31+
# ---
32+
# langugage conventions https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#language-conventions
33+
434
# Sort using and Import directives with System.* appearing first
535
dotnet_sort_system_directives_first = true
636

7-
# Prefer this.X except for _fields
8-
# TODO can we force _ for private fields?
9-
# TODO elevate severity after code cleanup to warning minimum
10-
# TODO use language latest
11-
dotnet_style_qualification_for_field = false:suggestion
12-
dotnet_style_qualification_for_property = false:suggestion
13-
dotnet_style_qualification_for_method = false:suggestion
14-
dotnet_style_qualification_for_event = false:suggestion
37+
dotnet_style_qualification_for_field = false:error
38+
dotnet_style_qualification_for_property = false:error
39+
dotnet_style_qualification_for_method = false:error
40+
dotnet_style_qualification_for_event = false:error
1541

1642
# Use language keywords instead of framework type names for type references
17-
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
18-
dotnet_style_predefined_type_for_member_access = true:suggestion
43+
dotnet_style_predefined_type_for_locals_parameters_members = true:error
44+
dotnet_style_predefined_type_for_member_access = true:error
1945

2046
# Suggest more modern language features when available
21-
dotnet_style_object_initializer = true:suggestion
22-
dotnet_style_collection_initializer = true:suggestion
23-
dotnet_style_explicit_tuple_names = true:suggestion
24-
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
25-
dotnet_style_prefer_inferred_tuple_names = true:suggestion
26-
dotnet_style_coalesce_expression = true:suggestion
27-
dotnet_style_null_propagation = true:suggestion
47+
dotnet_style_object_initializer = true:error
48+
dotnet_style_collection_initializer = true:error
49+
dotnet_style_explicit_tuple_names = true:error
50+
dotnet_style_prefer_inferred_anonymous_type_member_names = true:error
51+
dotnet_style_prefer_inferred_tuple_names = true:error
52+
dotnet_style_coalesce_expression = true:error
53+
dotnet_style_null_propagation = true:error
2854

29-
dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion
30-
dotnet_style_readonly_field = true:suggestion
55+
dotnet_style_require_accessibility_modifiers = for_non_interface_members:error
56+
dotnet_style_readonly_field = true:error
3157

3258
# CSharp code style settings:
3359
[*.cs]
3460
# Prefer "var" everywhere
35-
csharp_style_var_for_built_in_types = true:suggestion
36-
csharp_style_var_when_type_is_apparent = true:suggestion
37-
csharp_style_var_elsewhere = true:suggestion
61+
csharp_style_var_for_built_in_types = true:error
62+
csharp_style_var_when_type_is_apparent = true:error
63+
csharp_style_var_elsewhere = true:error
3864

39-
csharp_style_expression_bodied_methods = true:suggestion
40-
csharp_style_expression_bodied_constructors = true:suggestion
41-
csharp_style_expression_bodied_operators = true:suggestion
42-
csharp_style_expression_bodied_properties = true:suggestion
43-
csharp_style_expression_bodied_indexers = true:suggestion
44-
csharp_style_expression_bodied_accessors = true:suggestion
65+
csharp_style_expression_bodied_methods = true:error
66+
csharp_style_expression_bodied_constructors = true:error
67+
csharp_style_expression_bodied_operators = true:error
68+
csharp_style_expression_bodied_properties = true:error
69+
csharp_style_expression_bodied_indexers = true:error
70+
csharp_style_expression_bodied_accessors = true:error
4571

4672
# Suggest more modern language features when available
47-
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
48-
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
49-
csharp_style_inlined_variable_declaration = true:suggestion
50-
csharp_style_deconstructed_variable_declaration = true:suggestion
51-
csharp_style_pattern_local_over_anonymous_function = true:suggestion
52-
csharp_style_throw_expression = true:suggestion
53-
csharp_style_conditional_delegate_call = true:suggestion
73+
csharp_style_pattern_matching_over_is_with_cast_check = true:error
74+
csharp_style_pattern_matching_over_as_with_null_check = true:error
75+
csharp_style_inlined_variable_declaration = true:error
76+
csharp_style_deconstructed_variable_declaration = true:error
77+
csharp_style_pattern_local_over_anonymous_function = true:error
78+
csharp_style_throw_expression = true:error
79+
csharp_style_conditional_delegate_call = true:error
5480

55-
csharp_prefer_braces = false:suggestion
56-
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion
81+
csharp_prefer_braces = false:warning
82+
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:error
5783

5884
# ---
5985
# formatting conventions https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#formatting-conventions
6086

6187
# Newline settings (Allman yo!)
62-
csharp_new_line_before_open_brace = all:suggestion
63-
csharp_new_line_before_else = true:suggestion
64-
csharp_new_line_before_catch = true:suggestion
65-
csharp_new_line_before_finally = true:suggestion
88+
csharp_new_line_before_open_brace = all:error
89+
csharp_new_line_before_else = true:error
90+
csharp_new_line_before_catch = true:error
91+
csharp_new_line_before_finally = true:error
6692
csharp_new_line_before_members_in_object_initializers = true
6793
# just a suggestion do to our JSON tests that use anonymous types to
6894
# represent json quite a bit (makes copy paste easier).
6995
csharp_new_line_before_members_in_anonymous_types = true:suggestion
70-
csharp_new_line_between_query_expression_clauses = true:suggestion
96+
csharp_new_line_between_query_expression_clauses = true:error
7197

7298
# Indent
73-
csharp_indent_case_contents = true:suggestion
74-
csharp_indent_switch_labels = true:suggestion
75-
csharp_space_after_cast = false:suggestion
76-
csharp_space_after_keywords_in_control_flow_statements = true:suggestion
77-
csharp_space_between_method_declaration_parameter_list_parentheses = false:suggestion
78-
csharp_space_between_method_call_parameter_list_parentheses = false:suggestion
99+
csharp_indent_case_contents = true:error
100+
csharp_indent_switch_labels = true:error
101+
csharp_space_after_cast = false:error
102+
csharp_space_after_keywords_in_control_flow_statements = true:error
103+
csharp_space_between_method_declaration_parameter_list_parentheses = false:error
104+
csharp_space_between_method_call_parameter_list_parentheses = false:error
79105

80106
#Wrap
81-
csharp_preserve_single_line_statements = false:suggestion
82-
csharp_preserve_single_line_blocks = true:suggestion
107+
csharp_preserve_single_line_statements = false:error
108+
csharp_preserve_single_line_blocks = true:error
83109

84110
# Resharper
85111
resharper_csharp_braces_for_lock=required_for_complex
@@ -92,11 +118,6 @@ resharper_csharp_braces_for_ifelse=required_for_complex
92118

93119
resharper_csharp_accessor_owner_body=expression_body
94120

95-
# Override source included files
96-
[SynchronizedCollection.cs]
97-
csharp_style_var_for_built_in_types = false:none
98-
csharp_style_var_when_type_is_apparent = false:none
99-
csharp_style_var_elsewhere = false:none
100-
dotnet_style_predefined_type_for_locals_parameters_members = false:none
101-
dotnet_style_predefined_type_for_member_access = false:none
102-
csharp_prefer_braces = false:none
121+
122+
resharper_redundant_case_label_highlighting=do_not_show
123+

src/CodeGeneration/ApiGenerator/Configuration/GeneratorLocations.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static class GeneratorLocations
1818

1919
public static readonly Assembly Assembly = typeof(Generator.ApiGenerator).Assembly;
2020

21-
private static string _root = null;
21+
private static string _root;
2222
public static string Root
2323
{
2424
get

src/CodeGeneration/ApiGenerator/Domain/Code/CsharpNames.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using System.Text.RegularExpressions;
54
using ApiGenerator.Configuration;
65
using ApiGenerator.Generator;
76
using CsQuery.ExtensionMethods.Internal;

src/CodeGeneration/ApiGenerator/Domain/Code/HighLevel/Methods/FluentSyntaxBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private List<UrlPart> CreateDescriptorArgs(IReadOnlyCollection<UrlPart> parts)
9090

9191
public string DescriptorArguments()
9292
{
93-
string codeArgs = null;
93+
string codeArgs;
9494
if (CodeConfiguration.DescriptorConstructors.TryGetValue(CsharpNames.DescriptorName, out codeArgs))
9595
codeArgs += ",";
9696

src/CodeGeneration/ApiGenerator/Domain/Code/HighLevel/Requests/Constructor.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ string generic
6464
ctors.AddRange(from path in paths.Where(path => path.HasResolvableArguments)
6565
let baseArgs = path.AutoResolveBaseArguments(generic)
6666
let constructorArgs = path.AutoResolveConstructorArguments
67-
let baseOrThis = inheritsFromPlainRequestBase ? "this" : "base"
67+
let baseOrThis = inheritsFromPlainRequestBase
68+
? "this"
69+
: "base"
6870
let generated = $"public {typeName}({constructorArgs}) : {baseOrThis}({baseArgs})"
6971
select new Constructor
7072
{
@@ -82,6 +84,7 @@ string generic
8284
{
8385
Parameterless = string.IsNullOrEmpty(docPathConstArgs),
8486
Generated = $"public {typeName}({docPathConstArgs}) : this({docPathBaseArgs})",
87+
8588
AdditionalCode = $"partial void DocumentFromPath({generic} document);",
8689
Description = docPath.GetXmlDocs(Indent, skipResolvable: true, documentConstructor: true),
8790
Body = "=> DocumentFromPath(documentWithId);"
@@ -90,15 +93,13 @@ string generic
9093
}
9194
var constructors = ctors.GroupBy(c => c.Generated.Split(new[] { ':' }, 2)[0]).Select(g => g.Last()).ToList();
9295
if (!constructors.Any(c=>c.Parameterless))
93-
{
9496
constructors.Add(new Constructor
9597
{
9698
Parameterless = true,
9799
Generated = $"protected {typeName}() : base()",
98100
Description =
99101
$"///<summary>Used for serialization purposes, making sure we have a parameterless constructor</summary>{Indent}[SerializationConstructor]",
100102
});
101-
}
102103
return constructors;
103104
}
104105
}

src/CodeGeneration/ApiGenerator/Domain/Code/HighLevel/Requests/DescriptorPartialImplementation.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ public IEnumerable<FluentRouteSetter> GetFluentRouteSetters()
3737
var routeValue = "v";
3838
var routeSetter = p.Required ? "Required" : "Optional";
3939

40-
if (paramName == "metric" || paramName == "watcherStatsMetric") routeValue = "(Metrics)v";
41-
else if (paramName == "indexMetric") routeValue = "(IndexMetrics)v";
42-
4340
var code =
4441
$"public {returnType} {p.InterfaceName}({p.ClrTypeName} {paramName}) => Assign({paramName}, (a,v)=>a.RouteValues.{routeSetter}(\"{p.Name}\", {routeValue}));";
4542
var xmlDoc = $"///<summary>{p.Description}</summary>";
@@ -53,7 +50,7 @@ public IEnumerable<FluentRouteSetter> GetFluentRouteSetters()
5350
}
5451
if (paramName == "index" && p.Type == "list")
5552
{
56-
code = $"public {returnType} AllIndices() => this.Index(Indices.All);";
53+
code = $"public {returnType} AllIndices() => Index(Indices.All);";
5754
xmlDoc = $"///<summary>A shortcut into calling Index(Indices.All)</summary>";
5855
setters.Add(new FluentRouteSetter { Code = code, XmlDoc = xmlDoc });
5956
}

src/CodeGeneration/ApiGenerator/Domain/Code/LowLevel/LowLevelClientMethod.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,18 @@ public string UrlInCode
2525
{
2626
get
2727
{
28+
string Evaluator(Match m)
29+
{
30+
var arg = m.Groups.Last().Value.ToCamelCase();
31+
return $"{{{arg}:{arg}}}";
32+
}
33+
2834
var url = Path.TrimStart('/');
2935
var pattern = string.Join("|", Url.Parts.Select(p => p.Name));
3036
var urlCode = $"\"{url}\"";
3137
if (Path.Contains("{"))
3238
{
33-
var patchedUrl = Regex.Replace(url, "{(" + pattern + ")}", "{$1:$1}");
39+
var patchedUrl = Regex.Replace(url, "{(" + pattern + ")}", Evaluator);
3440
urlCode = $"Url($\"{patchedUrl}\")";
3541
}
3642
return urlCode;

src/CodeGeneration/ApiGenerator/Domain/RestApiSpec.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
using System.Collections.ObjectModel;
44
using System.Linq;
55
using ApiGenerator.Domain.Specification;
6-
using CsQuery.ExtensionMethods.Internal;
7-
using Microsoft.CodeAnalysis.CSharp;
86

97
namespace ApiGenerator.Domain
108
{
@@ -38,11 +36,13 @@ string CreateName(string name, string methodName, string @namespace)
3836
if (
3937
name.ToLowerInvariant().Contains("metric")
4038
||(name.ToLowerInvariant() == "status")
41-
)
39+
)
40+
{
4241
if (methodName.StartsWith(@namespace))
4342
return methodName + name;
4443
else
4544
return @namespace + methodName + name;
45+
}
4646

4747
return name;
4848
}

src/CodeGeneration/ApiGenerator/Domain/Specification/UrlInformation.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Collections.Generic;
22
using System.Linq;
3-
using ApiGenerator.Domain.Code;
43
using Newtonsoft.Json;
54

65
namespace ApiGenerator.Domain.Specification
@@ -36,7 +35,7 @@ public IReadOnlyCollection<UrlPath> Paths
3635

3736
private static readonly string[] DocumentApiParts = { "index", "id" };
3837

39-
public bool IsDocumentApi => UrlInformation.IsADocumentRoute(Parts);
38+
public bool IsDocumentApi => IsADocumentRoute(Parts);
4039

4140
public static bool IsADocumentRoute(IReadOnlyCollection<UrlPart> parts) =>
4241
parts.Count() == DocumentApiParts.Length

src/CodeGeneration/ApiGenerator/Domain/Specification/UrlPart.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ public string Argument
1515
{
1616
case "int":
1717
case "string":
18-
return Type + " " + Name;
18+
return Type + " " + NameAsArgument;
1919
case "list":
20-
return "string " + Name;
20+
return "string " + NameAsArgument;
2121
case "enum":
22-
return Name.ToPascalCase() + " " + Name;
22+
return Name.ToPascalCase() + " " + NameAsArgument;
2323
case "number":
24-
return "string " + Name;
24+
return "string " + NameAsArgument;
2525
default:
26-
return Type + " " + Name;
26+
return Type + " " + NameAsArgument;
2727
}
2828
}
2929
}

0 commit comments

Comments
 (0)