Skip to content

Commit

Permalink
StyleCop cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkWanderer committed Feb 21, 2020
1 parent 8f0481f commit 587208b
Show file tree
Hide file tree
Showing 22 changed files with 55 additions and 228 deletions.
185 changes: 8 additions & 177 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -20,183 +20,14 @@ dotnet_diagnostic.SA1600.severity = none # SA1600: Elements should be documented
dotnet_diagnostic.SA1629.severity = none # SA1629: Documentation text should end with a period
dotnet_diagnostic.SA1602.severity = none # SA1602: Enumeration items should be documented

#### .NET Coding Conventions ####
# SA1201: Elements should appear in the correct order
dotnet_diagnostic.SA1201.severity = suggestion

# Organize usings
dotnet_separate_import_directive_groups = false
dotnet_sort_system_directives_first = true
# SA1202: Elements should be ordered by access
dotnet_diagnostic.SA1202.severity = suggestion

# this. and Me. preferences
dotnet_style_qualification_for_event = false:suggestion
dotnet_style_qualification_for_field = false:suggestion
dotnet_style_qualification_for_method = false:suggestion
dotnet_style_qualification_for_property = false:suggestion
# SA1502: Element should not be on a single line
dotnet_diagnostic.SA1502.severity = none

# Language keywords vs BCL types preferences
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion

# Parentheses preferences
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:suggestion
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:suggestion
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:suggestion

# Modifier preferences
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent

# Expression-level preferences
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_object_initializer = true:suggestion
dotnet_style_prefer_auto_properties = true:suggestion
dotnet_style_prefer_compound_assignment = true:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion
dotnet_style_prefer_conditional_expression_over_return = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion

# Field preferences
dotnet_style_readonly_field = true:suggestion

# Parameter preferences
dotnet_code_quality_unused_parameters = all:suggestion

#### C# Coding Conventions ####

# var preferences
csharp_style_var_elsewhere = true:suggestion
csharp_style_var_for_built_in_types = true:suggestion
csharp_style_var_when_type_is_apparent = true:suggestion

# Expression-bodied members
csharp_style_expression_bodied_accessors = when_on_single_line:suggestion
csharp_style_expression_bodied_constructors = false:suggestion
csharp_style_expression_bodied_indexers = when_on_single_line:suggestion
csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = true:silent
csharp_style_expression_bodied_methods = when_on_single_line:suggestion
csharp_style_expression_bodied_operators = when_on_single_line:suggestion
csharp_style_expression_bodied_properties = when_on_single_line:suggestion

# Pattern matching preferences
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_prefer_switch_expression = true:suggestion

# Null-checking preferences
csharp_style_conditional_delegate_call = true:suggestion

# Modifier preferences
csharp_prefer_static_local_function = true:suggestion
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async

# Code-block preferences
csharp_prefer_braces = when_multiline:suggestion
csharp_prefer_simple_using_statement = true:suggestion

# Expression-level preferences
csharp_prefer_simple_default_expression = true:suggestion
csharp_style_deconstructed_variable_declaration = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion
csharp_style_pattern_local_over_anonymous_function = true:suggestion
csharp_style_prefer_index_operator = true:suggestion
csharp_style_prefer_range_operator = true:suggestion
csharp_style_throw_expression = true:suggestion
csharp_style_unused_value_assignment_preference = discard_variable:suggestion
csharp_style_unused_value_expression_statement_preference = discard_variable:silent

# 'using' directive preferences
csharp_using_directive_placement = outside_namespace:silent

#### C# Formatting Rules ####

# New line preferences
csharp_new_line_before_catch = true
csharp_new_line_before_else = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_open_brace = all
csharp_new_line_between_query_expression_clauses = true

# Indentation preferences
csharp_indent_block_contents = true
csharp_indent_braces = false
csharp_indent_case_contents = true
csharp_indent_case_contents_when_block = true
csharp_indent_labels = no_change
csharp_indent_switch_labels = true

# Space preferences
csharp_space_after_cast = false
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_after_comma = true
csharp_space_after_dot = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_after_semicolon_in_for_statement = true
csharp_space_around_binary_operators = before_and_after
csharp_space_around_declaration_statements = false
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_before_comma = false
csharp_space_before_dot = false
csharp_space_before_open_square_brackets = false
csharp_space_before_semicolon_in_for_statement = false
csharp_space_between_empty_square_brackets = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_declaration_name_and_open_parenthesis = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_space_between_square_brackets = false

# Wrapping preferences
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = false

#### Naming styles ####

# Naming rules

dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i

dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case

dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case

# Symbol specifications

dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.required_modifiers =

dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types.required_modifiers =

dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers =

# Naming styles

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case

dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.capitalization = pascal_case
# SA1204: Static elements should appear before instance elements
dotnet_diagnostic.SA1204.severity = suggestion
1 change: 0 additions & 1 deletion ClickHouse.Client/ADO/ClickHouseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace ClickHouse.Client.ADO
{

internal class ClickHouseCommand : DbCommand
{
private readonly ClickHouseConnection dbConnection;
Expand Down
14 changes: 7 additions & 7 deletions ClickHouse.Client/ADO/ClickHouseConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ namespace ClickHouse.Client.ADO
{
public class ClickHouseConnection : DbConnection, ICloneable
{
private static readonly HttpClientHandler handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate };
private static readonly HttpClient httpClient = new HttpClient(handler);
private static readonly HttpClientHandler HttpClientHandler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate };
private static readonly HttpClient HttpClient = new HttpClient(HttpClientHandler);

private ConnectionState state = ConnectionState.Closed;
private string serverVersion;
Expand All @@ -40,7 +40,7 @@ public ClickHouseConnection(string connectionString)
}

/// <summary>
/// String defining connection settings for ClickHouse server
/// Gets or sets string defining connection settings for ClickHouse server
/// Example: Host=localhost;Port=8123;Username=default;Password=123;Compression=true
/// </summary>
public sealed override string ConnectionString
Expand All @@ -56,7 +56,7 @@ public sealed override string ConnectionString
Port = (ushort)serverUri?.Port,
Driver = Driver,
Compression = useCompression,
UseSession = session != null
UseSession = session != null,
};
return builder.ToString();
}
Expand Down Expand Up @@ -103,7 +103,7 @@ internal async Task<HttpResponseMessage> PostSqlQueryAsync(string sqlQuery, Canc
}

postMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("text/sql");
var response = await httpClient.SendAsync(postMessage, HttpCompletionOption.ResponseHeadersRead, token).ConfigureAwait(false);
var response = await HttpClient.SendAsync(postMessage, HttpCompletionOption.ResponseHeadersRead, token).ConfigureAwait(false);
return await HandleError(response, sqlQuery).ConfigureAwait(false);
}

Expand All @@ -117,7 +117,7 @@ internal async Task<HttpResponseMessage> PostBulkDataAsync(string sql, Stream da
if (isCompressed)
postMessage.Content.Headers.Add("Content-Encoding", "gzip");

var response = await httpClient.SendAsync(postMessage, HttpCompletionOption.ResponseHeadersRead, token).ConfigureAwait(false);
var response = await HttpClient.SendAsync(postMessage, HttpCompletionOption.ResponseHeadersRead, token).ConfigureAwait(false);
return await HandleError(response, sql).ConfigureAwait(false);
}

Expand All @@ -139,7 +139,7 @@ private string MakeUri(string sql = null)
Database = database,
UseHttpCompression = useCompression,
SqlQuery = sql,
SessionId = session
SessionId = session,
};

uriBuilder.Query = queryParameters.ToString();
Expand Down
6 changes: 3 additions & 3 deletions ClickHouse.Client/ADO/Readers/ClickHouseBinaryReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ namespace ClickHouse.Client.ADO.Readers
{
internal class ClickHouseBinaryReader : ClickHouseDataReader
{
private const int bufferSize = 512 * 1024;
private const int BufferSize = 512 * 1024;

private readonly ExtendedBinaryReader reader;
private readonly BinaryStreamReader streamReader;

public ClickHouseBinaryReader(HttpResponseMessage httpResponse)
: base(httpResponse)
{
var stream = new BufferedStream(httpResponse.Content.ReadAsStreamAsync().GetAwaiter().GetResult(), bufferSize);
var stream = new BufferedStream(httpResponse.Content.ReadAsStreamAsync().GetAwaiter().GetResult(), BufferSize);
reader = new ExtendedBinaryReader(stream); // will dispose of stream
streamReader = new BinaryStreamReader(reader);
ReadHeaders();
Expand Down Expand Up @@ -67,4 +67,4 @@ protected override void Dispose(bool disposing)
base.Dispose(disposing);
}
}
}
}
10 changes: 5 additions & 5 deletions ClickHouse.Client/ADO/Readers/ClickHouseJsonCompactReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ private void ReadHeaders()
private class JsonColumnRecord
{
[JsonProperty("name")]
public readonly string Name;
public string Name { get; }

[JsonProperty("type")]
public readonly string Type;
public string Type { get; }

[JsonConstructor]
public JsonColumnRecord(string name, string type)
Expand All @@ -80,13 +80,13 @@ public JsonColumnRecord(string name, string type)

private void AssertEquals<T>(T expected, T actual)
{
Debug.Assert(Equals(expected, actual));
Debug.Assert(Equals(expected, actual), "Comparison failed");
if (!Equals(expected, actual))
throw new InvalidOperationException($"Error: expected {expected}, got {actual}");
}

/// <summary>
/// Streams
/// Reads next row of JSON from input stream
/// </summary>
/// <returns>Whether read was successful</returns>
public override bool Read()
Expand Down Expand Up @@ -134,4 +134,4 @@ private object TryConvertTo(object data, ClickHouseType type)
return data;
}
}
}
}
2 changes: 1 addition & 1 deletion ClickHouse.Client/ClickHouseConnectionDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public enum ClickHouseConnectionDriver
{
Binary,
JSON,
TSV
TSV,
}
}
1 change: 0 additions & 1 deletion ClickHouse.Client/Formats/BinaryStreamReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ public object ReadValue(ClickHouseType databaseType, bool nullAsDbNull)
case ClickHouseTypeCode.LowCardinality:
var lcCardinality = (LowCardinalityType)databaseType;
return ReadValue(lcCardinality.UnderlyingType, nullAsDbNull);

}
throw new NotImplementedException($"Reading of {databaseType.TypeCode} is not implemented");
}
Expand Down
4 changes: 2 additions & 2 deletions ClickHouse.Client/Formats/BinaryStreamWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ private static Guid ExtractGuid(object data)
else if (data is string s)
guid = new Guid(s);
else
throw new NotSupportedException($"Cannot convert {data?.GetType()?.Name ?? "null"} to GUID");
throw new ArgumentException($"Cannot convert {data?.GetType()?.Name ?? "null"} to GUID");
return guid;
}

Expand All @@ -205,7 +205,7 @@ private static IPAddress ExtractIPAddress(object data)
else if (data is string s)
address = IPAddress.Parse(s);
else
throw new NotSupportedException($"Cannot convert {data?.GetType()?.Name ?? "null"} to IPv4");
throw new ArgumentException($"Cannot convert {data?.GetType()?.Name ?? "null"} to IPv4");
return address;
}
}
Expand Down
2 changes: 1 addition & 1 deletion ClickHouse.Client/Types/ArrayType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public override ParameterizedType Parse(string typeName, Func<string, ClickHouse

return new ArrayType
{
UnderlyingType = typeResolverFunc(typeName.Substring(Name.Length).TrimRoundBrackets())
UnderlyingType = typeResolverFunc(typeName.Substring(Name.Length).TrimRoundBrackets()),
};
}

Expand Down
2 changes: 1 addition & 1 deletion ClickHouse.Client/Types/DateTime64Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public override ParameterizedType Parse(string typeName, Func<string, ClickHouse
return new DateTime64Type
{
TimeZone = timeZone,
Scale = scale
Scale = scale,
};
}
}
Expand Down
3 changes: 1 addition & 2 deletions ClickHouse.Client/Types/DateTimeType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

namespace ClickHouse.Client.Types
{

internal class DateTimeType : ParameterizedType
{
public override ClickHouseTypeCode TypeCode => ClickHouseTypeCode.DateTime;
Expand Down Expand Up @@ -60,7 +59,7 @@ public override ParameterizedType Parse(string typeName, Func<string, ClickHouse

return new DateTimeType
{
TimeZone = timeZone
TimeZone = timeZone,
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion ClickHouse.Client/Types/Decimal128Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public override ParameterizedType Parse(string typeName, Func<string, ClickHouse

return new Decimal128Type
{
Scale = int.Parse(typeName.Substring(Name.Length).TrimRoundBrackets())
Scale = int.Parse(typeName.Substring(Name.Length).TrimRoundBrackets()),
};
}

Expand Down
Loading

0 comments on commit 587208b

Please sign in to comment.