Skip to content

Commit fa51c2c

Browse files
[APIPUB-76] - Adds Sonar Analyzer (#80)
* Add sonar analyzer Treat warnings as errors * Add editorconfig files * Fix many SonarLint warnings * Fixes * fixes some warnings. * Fixes format warnings * Trying to fix tests. * More warnings fixed. * More warnings fixed. * Removes unnecessary file --------- Co-authored-by: Stephen A. Fuqua <[email protected]>
1 parent ca37c63 commit fa51c2c

File tree

155 files changed

+1409
-1320
lines changed

Some content is hidden

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

155 files changed

+1409
-1320
lines changed

.editorconfig

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style=space
6+
indent_size=4
7+
tab_width=2
8+
insert_final_newline = true
9+
charset = utf-8
10+
trim_trailing_whitespace = true
11+
max_line_length = 110
12+
13+
[*.{yml,json}]
14+
indent_size=2
15+
16+
[*.md]
17+
trim_trailing_whitespace = false

src/.editorconfig

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# References
2+
# https://docs.microsoft.com/en-us/visualstudio/code-quality/use-roslyn-analyzers?view=vs-2022
3+
# https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/language-rules
4+
# https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/naming-rules
5+
# https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/
6+
# https://rules.sonarsource.com/csharp
7+
# https://editorconfig.org/
8+
9+
root = true
10+
11+
[**/*]
12+
# Sensible Defaults
13+
file_header_template = SPDX-License-Identifier: Apache-2.0\nLicensed to the Ed-Fi Alliance under one or more agreements.\nThe Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.\nSee the LICENSE and NOTICES files in the project root for more information.
14+
indent_style=space
15+
indent_size=4
16+
tab_width=2
17+
insert_final_newline = true
18+
charset = utf-8
19+
trim_trailing_whitespace = true
20+
max_line_length = 110
21+
22+
[**/*.md]
23+
trim_trailing_whitespace = false
24+
25+
[**/*.{cs,cshtml,csx}]
26+
indent_style = space
27+
indent_size = 4
28+
tab_width = 4
29+
end_of_line = lf
30+
csharp_new_line_before_members_in_object_initializers = false
31+
csharp_preferred_modifier_order = private, public, protected, internal, new, abstract, virtual, sealed, override, static, readonly, extern, unsafe, volatile, async:suggestion
32+
33+
dotnet_diagnostic.IDE0073.severity=error # File header template required
34+
35+
# Formatting rules
36+
dotnet_diagnostic.IDE0055.severity=warning
37+
csharp_new_line_before_open_brace = all # Allman style
38+
csharp_new_line_before_else = true
39+
csharp_new_line_before_catch = true
40+
csharp_new_line_before_finally = true
41+
csharp_new_line_before_members_in_object_initializers = true
42+
csharp_new_line_before_members_in_anonymous_types = true
43+
csharp_new_line_between_query_expression_clauses = true
44+
csharp_indent_case_contents = true
45+
csharp_indent_switch_labels = true
46+
csharp_indent_labels = no_change
47+
csharp_indent_block_contents = true
48+
csharp_indent_braces = false
49+
csharp_indent_case_contents_when_block = true
50+
csharp_space_after_cast = false
51+
csharp_space_after_keywords_in_control_flow_statements = true
52+
csharp_space_between_parentheses = none
53+
csharp_space_before_colon_in_inheritance_clause = true
54+
csharp_space_after_colon_in_inheritance_clause = true
55+
csharp_space_around_binary_operators = before_and_after
56+
csharp_space_between_method_declaration_parameter_list_parentheses = false
57+
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
58+
csharp_space_between_method_declaration_name_and_open_parenthesis = false
59+
csharp_space_between_method_call_parameter_list_parentheses = false
60+
csharp_space_between_method_call_empty_parameter_list_parentheses = false
61+
csharp_space_between_method_call_name_and_opening_parenthesis = false
62+
csharp_space_after_comma = true
63+
csharp_space_before_comma = false
64+
csharp_space_after_dot = false
65+
csharp_space_before_dot = false
66+
csharp_space_after_semicolon_in_for_statement = true
67+
csharp_space_before_semicolon_in_for_statement = false
68+
csharp_space_around_declaration_statements = false
69+
csharp_space_before_open_square_brackets = false
70+
csharp_space_between_empty_square_brackets = false
71+
csharp_space_between_square_brackets = false
72+
csharp_preserve_single_line_blocks = true
73+
csharp_preserve_single_line_statements = false
74+
75+
# Naming rules
76+
dotnet_naming_rule.local_constants_rule.severity = warning
77+
dotnet_naming_rule.local_constants_rule.style = upper_camel_case_style
78+
dotnet_naming_rule.local_constants_rule.symbols = local_constants_symbols
79+
dotnet_naming_rule.private_constants_rule.import_to_resharper = as_predefined
80+
dotnet_naming_rule.private_constants_rule.severity = warning
81+
dotnet_naming_rule.private_constants_rule.style = upper_camel_case_style
82+
dotnet_naming_rule.private_constants_rule.symbols = private_constants_symbols
83+
dotnet_naming_rule.private_static_readonly_rule.import_to_resharper = as_predefined
84+
dotnet_naming_rule.private_static_readonly_rule.severity = warning
85+
dotnet_naming_rule.private_static_readonly_rule.style = lower_camel_case_style
86+
dotnet_naming_rule.private_static_readonly_rule.symbols = private_static_readonly_symbols
87+
dotnet_naming_style.lower_camel_case_style.capitalization = camel_case
88+
dotnet_naming_style.lower_camel_case_style.required_prefix = _
89+
dotnet_naming_style.upper_camel_case_style.capitalization = pascal_case
90+
dotnet_naming_symbols.local_constants_symbols.applicable_accessibilities = *
91+
dotnet_naming_symbols.local_constants_symbols.applicable_kinds = local
92+
dotnet_naming_symbols.local_constants_symbols.required_modifiers = const
93+
dotnet_naming_symbols.private_constants_symbols.applicable_accessibilities = private
94+
dotnet_naming_symbols.private_constants_symbols.applicable_kinds = field
95+
dotnet_naming_symbols.private_constants_symbols.required_modifiers = const
96+
dotnet_naming_symbols.private_static_readonly_symbols.applicable_accessibilities = private
97+
dotnet_naming_symbols.private_static_readonly_symbols.applicable_kinds = field
98+
dotnet_naming_symbols.private_static_readonly_symbols.required_modifiers = static,readonly
99+
100+
# Misc style
101+
dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:none
102+
dotnet_style_parentheses_in_other_binary_operators = never_if_unnecessary:none
103+
dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:none
104+
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
105+
dotnet_style_predefined_type_for_member_access = true:suggestion
106+
dotnet_style_qualification_for_event = false:suggestion
107+
dotnet_style_qualification_for_field = false:suggestion
108+
dotnet_style_qualification_for_method = false:suggestion
109+
dotnet_style_qualification_for_property = false:suggestion
110+
dotnet_style_require_accessibility_modifiers = for_non_interface_members:warning
111+
dotnet_style_operator_placement_when_wrapping = beginning_of_line
112+
dotnet_sort_system_directives_first = true
113+
dotnet_separate_import_directive_groups = false
114+
115+
# We *like* var
116+
dotnet_diagnostic.IDE0008.severity=none # IDE0008: Use explicit type
117+
csharp_style_var_elsewhere = false:none
118+
csharp_style_var_for_built_in_types = false:suggestion
119+
120+
# Using statements
121+
csharp_using_directive_placement=outside_namespace:warning
122+
dotnet_diagnostic.IDE0065.severity=warning # placement of using statements
123+
dotnet_diagnostic.IDE0005.severity=suggestion # Remove unnecessary using directives
124+
125+
# Lower the priority
126+
dotnet_diagnostic.S4136.severity=suggestion # Method overloads should be grouped together
127+
dotnet_diagnostic.S1135.severity=suggestion # Complete TODO comments
128+
dotnet_diagnostic.S112.severity=suggestion # 'System.Exception' should not be thrown by user code.
129+
dotnet_diagnostic.S3247.severity=suggestion # Remove redundant cast - getting false positives
130+
131+
# Allow empty records for discriminated union types
132+
dotnet_diagnostic.S2094.severity=none # S2094: Classes should not be empty
133+
134+
[**/tests/**/*.cs]
135+
# Allow our strange test class naming convention
136+
dotnet_naming_symbols.amt_tests.applicable_kinds = class,method
137+
dotnet_naming_symbols.amt_tests.word_separator = "_"
138+
dotnet_naming_symbols.amt_tests.capitalization = first_word_upper
139+
dotnet_diagnostic.IDE1006.severity=none
140+
dotnet_diagnostic.S101.severity=none
141+
142+
# SonarLint doesn't understand implied assertions from FakeItEasy
143+
dotnet_diagnostic.S2699.severity=none # S2699: Tests should include assertions

src/EdFi.Tools.ApiPublisher.Cli/Program.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using EdFi.Tools.ApiPublisher.Core.Registration;
1414
using Microsoft.Extensions.Configuration;
1515
using Microsoft.Extensions.DependencyInjection;
16+
using Polly.RateLimit;
1617
using Serilog;
1718
using System;
1819
using System.Collections.Generic;
@@ -22,8 +23,8 @@
2223
using System.Threading.Tasks;
2324

2425
namespace EdFi.Tools.ApiPublisher.Cli
25-
{
26-
internal class Program
26+
{
27+
internal class Program
2728
{
2829
private static readonly ILogger _logger = Log.ForContext(typeof(Program));
2930

@@ -174,6 +175,11 @@ private static async Task<int> Main(string[] args)
174175
_logger.Information($"Processing complete.");
175176
return 0;
176177
}
178+
//catch (RateLimitRejectedException ex)
179+
//{
180+
// _logger.Fatal(ex, ex.Message);
181+
// return -1;
182+
//}
177183
catch (Exception ex)
178184
{
179185
_logger.Error($"Processing failed: {string.Join(" ", GetExceptionMessages(ex))}");

src/EdFi.Tools.ApiPublisher.ConfigurationStore.Aws/AwsSystemManagerChangeVersionProcessedWriter.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616

1717
namespace EdFi.Tools.ApiPublisher.ConfigurationStore.Aws
1818
{
19-
public class AwsSystemManagerChangeVersionProcessedWriter : IChangeVersionProcessedWriter
19+
public class AwsSystemManagerChangeVersionProcessedWriter : IChangeVersionProcessedWriter
2020
{
2121
private readonly ILogger _logger = Log.ForContext(typeof(AwsSystemManagerChangeVersionProcessedWriter));
22-
22+
2323
public async Task SetProcessedChangeVersionAsync(
2424
string sourceConnectionName,
2525
string targetConnectionName,
@@ -34,7 +34,7 @@ public async Task SetProcessedChangeVersionAsync(
3434

3535
// Assign the new "LastChangeVersionProcessed" value
3636
currentParameter[targetConnectionName] = changeVersion;
37-
37+
3838
// Serialize the parameter's values
3939
string newParameterJson = currentParameter.ToString(Formatting.None);
4040

@@ -51,7 +51,7 @@ public async Task SetProcessedChangeVersionAsync(
5151
var response = await amazonSimpleSystemsManagement.PutParameterAsync(putRequest)
5252
.ConfigureAwait(false);
5353

54-
if ((int) response.HttpStatusCode >= 400)
54+
if ((int)response.HttpStatusCode >= 400)
5555
{
5656
throw new Exception(
5757
$"Failed to write updated change version of {changeVersion} for source connection '{sourceConnectionName}' to target connection '{targetConnectionName}' (AWS response status: {response.HttpStatusCode}).");
@@ -63,7 +63,7 @@ private async Task<JObject> GetParameterValueAsync(
6363
string sourceConnectionName)
6464
{
6565
string parameterName = $"{ConfigurationStoreHelper.Key(sourceConnectionName)}/lastChangeVersionsProcessed";
66-
66+
6767
var getRequest = new GetParameterRequest
6868
{
6969
Name = parameterName,

src/EdFi.Tools.ApiPublisher.ConfigurationStore.Aws/AwsSystemManagerNamedApiConnectionDetailsReader.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace EdFi.Tools.ApiPublisher.ConfigurationStore.Aws
1111
{
12-
public class AwsSystemManagerNamedApiConnectionDetailsReader : INamedApiConnectionDetailsReader
12+
public class AwsSystemManagerNamedApiConnectionDetailsReader : INamedApiConnectionDetailsReader
1313
{
1414
public ApiConnectionDetails GetNamedApiConnectionDetails(
1515
string apiConnectionName,
@@ -21,13 +21,13 @@ public ApiConnectionDetails GetNamedApiConnectionDetails(
2121
var config = new ConfigurationBuilder()
2222
.AddSystemsManager(ConfigurationStoreHelper.Key(apiConnectionName), awsOptions)
2323
.Build();
24-
24+
2525
// Read the connection details from the configuration values
2626
var connectionDetails = config.Get<ApiConnectionDetails>();
2727

2828
// Assign the connection name
2929
connectionDetails.Name = apiConnectionName;
30-
30+
3131
return connectionDetails;
3232
}
3333
}

src/EdFi.Tools.ApiPublisher.ConfigurationStore.Aws/Plugin.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace EdFi.Tools.ApiPublisher.ConfigurationStore.Aws;
1414
public class Plugin : IPlugin
1515
{
1616
private const string ConfigurationProviderName = "awsParameterStore";
17-
17+
1818
public void ApplyConfiguration(string[] args, IConfigurationBuilder configBuilder)
1919
{
2020
// Nothing to do

src/EdFi.Tools.ApiPublisher.ConfigurationStore.Plaintext/Modules/PluginModule.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace EdFi.Tools.ApiPublisher.ConfigurationStore.Plaintext.Modules
1111
{
12-
public class PluginModule : Module
12+
public class PluginModule : Module
1313
{
1414
protected override void Load(ContainerBuilder builder)
1515
{

src/EdFi.Tools.ApiPublisher.ConfigurationStore.Plaintext/PlainTextJsonFileNamedApiConnectionDetailsReader.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace EdFi.Tools.ApiPublisher.ConfigurationStore.Plaintext
1010
{
11-
public class PlainTextJsonFileNamedApiConnectionDetailsReader : INamedApiConnectionDetailsReader
11+
public class PlainTextJsonFileNamedApiConnectionDetailsReader : INamedApiConnectionDetailsReader
1212
{
1313
public ApiConnectionDetails GetNamedApiConnectionDetails(
1414
string apiConnectionName,
@@ -18,9 +18,9 @@ public ApiConnectionDetails GetNamedApiConnectionDetails(
1818
var config = new ConfigurationBuilder()
1919
.AddJsonFile("plainTextNamedConnections.json")
2020
.Build();
21-
21+
2222
var connections = config.Get<PlainTextNamedConnectionConfiguration>();
23-
23+
2424
return connections.Connections?
2525
.Where(details => details.Name != null)
2626
.FirstOrDefault(details => details.Name!.Equals(apiConnectionName, StringComparison.OrdinalIgnoreCase))

src/EdFi.Tools.ApiPublisher.ConfigurationStore.Plaintext/PlainTextNamedConnectionConfiguration.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace EdFi.Tools.ApiPublisher.ConfigurationStore.Plaintext
99
{
10-
internal class PlainTextNamedConnectionConfiguration
10+
internal class PlainTextNamedConnectionConfiguration
1111
{
1212
public ApiConnectionDetails[] Connections { get; set; }
1313
}

src/EdFi.Tools.ApiPublisher.ConfigurationStore.Plaintext/PlaintextChangeVersionProcessedWriter.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
namespace EdFi.Tools.ApiPublisher.ConfigurationStore.Plaintext
1111
{
12-
public class PlaintextChangeVersionProcessedWriter : IChangeVersionProcessedWriter
12+
public class PlaintextChangeVersionProcessedWriter : IChangeVersionProcessedWriter
1313
{
1414
private readonly ILogger _logger = Log.Logger.ForContext(typeof(PlaintextChangeVersionProcessedWriter));
15-
15+
1616
public Task SetProcessedChangeVersionAsync(
1717
string sourceConnectionName,
1818
string targetConnectionName,

src/EdFi.Tools.ApiPublisher.ConfigurationStore.PostgreSql/ConfigurationBuilderExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// ReSharper disable once CheckNamespace
99
namespace Microsoft.Extensions.Configuration
1010
{
11-
public static class ConfigurationBuilderExtensions
11+
public static class ConfigurationBuilderExtensions
1212
{
1313
public static IConfigurationBuilder AddConfigurationStoreForPostgreSql(
1414
this IConfigurationBuilder builder,

src/EdFi.Tools.ApiPublisher.ConfigurationStore.PostgreSql/Modules/PluginModule.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99

1010
namespace EdFi.Tools.ApiPublisher.ConfigurationStore.PostgreSql.Modules
1111
{
12-
public class PluginModule : Module
12+
public class PluginModule : Module
1313
{
1414
protected override void Load(ContainerBuilder builder)
1515
{
1616
builder.RegisterType<PostgreSqlConfigurationChangeVersionProcessedWriter>()
1717
.As<IChangeVersionProcessedWriter>()
1818
.SingleInstance();
19-
19+
2020
builder.RegisterType<PostgreSqlConfigurationNamedApiConnectionDetailsReader>()
2121
.As<INamedApiConnectionDetailsReader>()
2222
.SingleInstance();

src/EdFi.Tools.ApiPublisher.ConfigurationStore.PostgreSql/Plugin.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace EdFi.Tools.ApiPublisher.ConfigurationStore.PostgreSql;
1414
public class Plugin : IPlugin
1515
{
1616
private const string ConfigurationProviderName = "postgreSql";
17-
17+
1818
public void ApplyConfiguration(string[] args, IConfigurationBuilder configBuilder)
1919
{
2020
// Nothing to do

src/EdFi.Tools.ApiPublisher.ConfigurationStore.PostgreSql/PostgreSqlConfigurationChangeVersionProcessedWriter.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
namespace EdFi.Tools.ApiPublisher.ConfigurationStore.PostgreSql
1616
{
17-
public class PostgreSqlConfigurationChangeVersionProcessedWriter : IChangeVersionProcessedWriter
17+
public class PostgreSqlConfigurationChangeVersionProcessedWriter : IChangeVersionProcessedWriter
1818
{
1919
public async Task SetProcessedChangeVersionAsync(
2020
string sourceConnectionName,
@@ -25,7 +25,7 @@ public async Task SetProcessedChangeVersionAsync(
2525
var postgresConfiguration = configurationStoreSection.Get<PostgresConfigurationStore>().PostgreSql;
2626

2727
// Make sure Postgres configuration has encryption key provided
28-
if (string.IsNullOrWhiteSpace(postgresConfiguration?.EncryptionPassword))
28+
if (string.IsNullOrWhiteSpace(postgresConfiguration?.EncryptionPassword))
2929
{
3030
throw new Exception("The PostgreSQL Configuration Store encryption key for storing API keys and secrets was not provided.");
3131
}
@@ -37,7 +37,7 @@ public async Task SetProcessedChangeVersionAsync(
3737
postgresConfiguration.ConnectionString,
3838
postgresConfiguration.EncryptionPassword,
3939
ConfigurationStoreHelper.Key(sourceConnectionName));
40-
40+
4141
var currentParameter = new JObject();
4242

4343
if (configurationValues.TryGetValue("lastChangeVersionsProcessed", out string changeVersionsJson))

0 commit comments

Comments
 (0)