Skip to content

Commit

Permalink
Updates from CA and SonarCloud
Browse files Browse the repository at this point in the history
  • Loading branch information
k3ldar committed Dec 22, 2023
1 parent ff0fca5 commit 00f4974
Show file tree
Hide file tree
Showing 27 changed files with 116 additions and 96 deletions.
2 changes: 1 addition & 1 deletion src/GCAAnalyser/Analyzers/AnalyzeM605PlaySounds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses)
if (!gCodeAnalyses.AnalysesOptions.HasFlag(AnalysesOptions.PlaySound))
codeAnalyses.AddOptions(AnalysesOptions.PlaySound);

List<int> lineNumbers = new();
List<int> lineNumbers = [];

foreach (IGCodeCommand command in m605Commands)
{
Expand Down
2 changes: 1 addition & 1 deletion src/GCAAnalyser/Analyzers/AnalyzeM62XComPorts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses)

if (gCodeAnalyses is GCodeAnalyses codeAnalyses)
{
Dictionary<string, bool> comPortUsage = new();
Dictionary<string, bool> comPortUsage = [];

foreach (IGCodeCommand command in comPortCommands)
{
Expand Down
2 changes: 1 addition & 1 deletion src/GCAAnalyser/Analyzers/AnalyzeM630RunProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses)
if (!gCodeAnalyses.AnalysesOptions.HasFlag(AnalysesOptions.RunProgram))
codeAnalyses.AddOptions(AnalysesOptions.RunProgram);

List<int> lineNumbers = new();
List<int> lineNumbers = [];

foreach (IGCodeCommand command in m630Commands)
{
Expand Down
2 changes: 1 addition & 1 deletion src/GCAAnalyser/Analyzers/AnalyzeM630_1RunParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses)

if (mCommands.Count > 0 && gCodeAnalyses is GCodeAnalyses codeAnalyses)
{
List<int> lineNumbers = new();
List<int> lineNumbers = [];

foreach (IGCodeCommand command in mCommands)
{
Expand Down
2 changes: 1 addition & 1 deletion src/GCAAnalyser/Analyzers/AnalyzeM631_1RunParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses)

if (mCommands.Count > 0 && gCodeAnalyses is GCodeAnalyses codeAnalyses)
{
List<int> lineNumbers = new();
List<int> lineNumbers = [];

foreach (IGCodeCommand command in mCommands)
{
Expand Down
6 changes: 3 additions & 3 deletions src/GCAAnalyser/Analyzers/AnalyzeVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses)
{
if (gCodeAnalyses is GCodeAnalyses codeAnalyses)
{
Dictionary<ushort, IGCodeCommand> subprogramVariableDeclarations = new();
Dictionary<ushort, int> declaredVariables = new();
Dictionary<ushort, IGCodeCommand> subprogramVariableDeclarations = [];
Dictionary<ushort, int> declaredVariables = [];
List<IGCodeCommand> subprograms = gCodeAnalyses.Commands.Where(c => c.Command.Equals('O')).ToList();
List<ushort> subprogramVariables = new();
List<ushort> subprogramVariables = [];

foreach (IGCodeCommand subProgram in subprograms)
{
Expand Down
2 changes: 1 addition & 1 deletion src/GCAAnalyser/Analyzers/BaseAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ protected static List<IGCodeCommand> CommandsOnSameLine(IGCodeCommand command)
{
ArgumentNullException.ThrowIfNull(command);

List<IGCodeCommand> Result = new();
List<IGCodeCommand> Result = [];

LookPrevious(command, Result);
LookNext(command, Result);
Expand Down
16 changes: 8 additions & 8 deletions src/GCAAnalyser/GCodeAnalyses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ namespace GSendAnalyzer
internal class GCodeAnalyses : IGCodeAnalyses
{
private readonly object _lockObject = new();
private readonly List<IGCodeCommand> _commands = new();
private readonly List<IGCodeCommand> _commands = [];
private List<IGCodeCommand> _allCommands;
private readonly Dictionary<char, List<IGCodeCommand>> _allSpecificCommands = new();
private readonly Dictionary<char, List<IGCodeCommand>> _allSpecificCommands = [];
private readonly IPluginClassesService _pluginClassesService;
private readonly Dictionary<ushort, IGCodeVariable> _variables = new();
private readonly List<string> _errors = new();
private readonly List<string> _warnings = new();
private readonly Dictionary<ushort, IGCodeVariable> _variables = [];
private readonly List<string> _errors = [];
private readonly List<string> _warnings = [];

public GCodeAnalyses(IPluginClassesService pluginClassesService)
{
Expand Down Expand Up @@ -92,7 +92,7 @@ public IReadOnlyList<IGCodeCommand> AllCommands
{
if (_allCommands == null)
{
List<IGCodeCommand> Result = new();
List<IGCodeCommand> Result = [];

int lineNumber = 0;
RecursivelyRetrieveAllCommands(Result, _commands, ref lineNumber, 0);
Expand Down Expand Up @@ -197,7 +197,7 @@ private void RecursivelyRetrieveAllCommands(List<IGCodeCommand> Result, IReadOnl

public List<IGCodeLine> Lines(out int lineCount)
{
List<IGCodeLine> Result = new();
List<IGCodeLine> Result = [];

lineCount = 0;
GCodeLine currentLine = null;
Expand All @@ -219,7 +219,7 @@ public List<IGCodeLine> Lines(out int lineCount)

public List<IGCodeLine> AllLines(out int lineCount)
{
List<IGCodeLine> Result = new();
List<IGCodeLine> Result = [];

lineCount = 0;
GCodeLine currentLine = null;
Expand Down
2 changes: 1 addition & 1 deletion src/GCAAnalyser/GCodeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public GCodeCommand(int index, char currentCommand, decimal commandValue, string
CommandValue = commandValue;
CommandValueString = commandValueString;
Comment = comment ?? String.Empty;
VariableBlocks = variables ?? new();
VariableBlocks = variables ?? [];
_currentCodeValues = currentValues ?? throw new ArgumentNullException(nameof(currentValues));
Attributes = currentValues.Attributes;
LineNumber = lineNumber;
Expand Down
2 changes: 1 addition & 1 deletion src/GCAAnalyser/GCodeLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public GCodeLine(IGCodeAnalyses gCodeAnalyses, IGCodeCommand command)

public LineStatus Status { get; set; }

public List<IGCodeCommand> Commands { get; } = new();
public List<IGCodeCommand> Commands { get; } = [];

public int LineNumber { get; }

Expand Down
2 changes: 1 addition & 1 deletion src/GCAAnalyser/Internal/GCodeParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ private GCodeCommand UpdateGCodeValue(GCodeAnalyses analysis, GCodeCommand lastC
int lineNumber, int recursionDepth, ref GCodeCommand result, char currentCommand, StringBuilder comment)
{
string lineValue = lineValues.ToString().Trim();
List<IGCodeVariableBlock> variables = new();
List<IGCodeVariableBlock> variables = [];
bool commandValueConvert = Decimal.TryParse(lineValue, out decimal commandValue);

if (!commandValueConvert)
Expand Down
32 changes: 18 additions & 14 deletions src/GCATests/GCService/JobProfileApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

using static GSendShared.Constants;

#pragma warning disable CA1861

namespace GSendTests.GCService
{
[TestClass]
Expand All @@ -24,7 +26,7 @@ public class JobProfileApiTests
[ExcludeFromCodeCoverage]
public void JobProfilesGet_RetrievesAllJobProfiles_Success()
{
MockGSendDataProvider gSendDataProvider = new(new string[] { "ProverXL", "3018" });
MockGSendDataProvider gSendDataProvider = new(["ProverXL", "3018"]);
gSendDataProvider.JobProfiles.Add(new JobProfileModel(1) { Name = "Profile 1", Description = "test 1" });
gSendDataProvider.JobProfiles.Add(new JobProfileModel(325) { Name = "Profile 2", Description = "test 2" });
gSendDataProvider.JobProfiles.Add(new JobProfileModel(9865433) { Name = "Profile 3", Description = "test 3" });
Expand Down Expand Up @@ -63,7 +65,7 @@ public void JobProfilesGet_RetrievesAllJobProfiles_Success()
[TestMethod]
public void JobProfileAdd_NullParameter_Returns_JsonErrorResponse()
{
IGSendDataProvider gSendDataProvider = new MockGSendDataProvider(new string[] { "ProverXL", "3018" });
IGSendDataProvider gSendDataProvider = new MockGSendDataProvider(["ProverXL", "3018"]);
JobProfileApi sut = new(gSendDataProvider, new MockNotification());
ActionResult Result = sut.JobProfileAdd(null) as ActionResult;
Assert.IsNotNull(Result);
Expand All @@ -81,7 +83,7 @@ public void JobProfileAdd_NullParameter_Returns_JsonErrorResponse()
[TestMethod]
public void JobProfileAdd_NullName_Returns_JsonErrorResponse()
{
IGSendDataProvider gSendDataProvider = new MockGSendDataProvider(new string[] { "ProverXL", "3018" });
IGSendDataProvider gSendDataProvider = new MockGSendDataProvider(["ProverXL", "3018"]);
JobProfileApi sut = new(gSendDataProvider, new MockNotification());
ActionResult Result = sut.JobProfileAdd(new JobProfileModel(1) { Description = "a desc" }) as ActionResult;
Assert.IsNotNull(Result);
Expand All @@ -99,7 +101,7 @@ public void JobProfileAdd_NullName_Returns_JsonErrorResponse()
[TestMethod]
public void JobProfileAdd_NullDescription_Returns_JsonErrorResponse()
{
IGSendDataProvider gSendDataProvider = new MockGSendDataProvider(new string[] { "ProverXL", "3018" });
IGSendDataProvider gSendDataProvider = new MockGSendDataProvider(["ProverXL", "3018"]);
JobProfileApi sut = new(gSendDataProvider, new MockNotification());
ActionResult Result = sut.JobProfileAdd(new JobProfileModel(1) { Name = "a test" }) as ActionResult;
Assert.IsNotNull(Result);
Expand All @@ -118,7 +120,7 @@ public void JobProfileAdd_NullDescription_Returns_JsonErrorResponse()
public void JobProfileAdd_ValidModel_Returns_JsonResponse()
{
MockNotification notification = new();
IGSendDataProvider gSendDataProvider = new MockGSendDataProvider(new string[] { "ProverXL", "3018" });
IGSendDataProvider gSendDataProvider = new MockGSendDataProvider(["ProverXL", "3018"]);
JobProfileApi sut = new(gSendDataProvider, notification);
ActionResult Result = sut.JobProfileAdd(new JobProfileModel(1) { Name = "a test", Description = "a test" }) as ActionResult;
Assert.IsNotNull(Result);
Expand All @@ -140,7 +142,7 @@ public void JobProfileAdd_ValidModel_Returns_JsonResponse()
public void JobProfileAdd_InvalidModel_DuplicateName_Returns_JsonResponse()
{
MockNotification notification = new();
IGSendDataProvider gSendDataProvider = new MockGSendDataProvider(new string[] { "ProverXL", "3018" });
IGSendDataProvider gSendDataProvider = new MockGSendDataProvider(["ProverXL", "3018"]);
JobProfileApi sut = new(gSendDataProvider, notification);
ActionResult Result = sut.JobProfileAdd(new JobProfileModel(0) { Name = "a test", Description = "a test" }) as ActionResult;
Assert.IsNotNull(Result);
Expand Down Expand Up @@ -174,7 +176,7 @@ public void JobProfileAdd_InvalidModel_DuplicateName_Returns_JsonResponse()
public void JobProfileDelete_InvalidItemNotFound_ReturnsJsonErrorResponse()
{
MockNotification notification = new();
IGSendDataProvider gSendDataProvider = new MockGSendDataProvider(new string[] { "ProverXL", "3018" });
IGSendDataProvider gSendDataProvider = new MockGSendDataProvider(["ProverXL", "3018"]);
JobProfileApi sut = new(gSendDataProvider, notification);
ActionResult Result = sut.JobProfileDelete(111) as ActionResult;
Assert.IsNotNull(Result);
Expand All @@ -195,7 +197,7 @@ public void JobProfileDelete_InvalidItemNotFound_ReturnsJsonErrorResponse()
public void JobProfileDelete_ValidModel_LastRemainingJobProfile_Returns_JsonErrorResponse()
{
MockNotification notification = new();
IGSendDataProvider gSendDataProvider = new MockGSendDataProvider(new string[] { "ProverXL", "3018" });
IGSendDataProvider gSendDataProvider = new MockGSendDataProvider(["ProverXL", "3018"]);
JobProfileApi sut = new(gSendDataProvider, notification);
ActionResult Result = sut.JobProfileAdd(new JobProfileModel(1) { Name = "a test", Description = "a test" }) as ActionResult;
Assert.IsNotNull(Result);
Expand Down Expand Up @@ -226,7 +228,7 @@ public void JobProfileDelete_ValidModel_LastRemainingJobProfile_Returns_JsonErro
public void JobProfileDelete_ValidModel_ItemCanBeDeleted_Returns_JsonSuccessResponse()
{
MockNotification notification = new();
MockGSendDataProvider gSendDataProvider = new(new string[] { "ProverXL", "3018" });
MockGSendDataProvider gSendDataProvider = new(["ProverXL", "3018"]);
JobProfileApi sut = new(gSendDataProvider, notification);
ActionResult Result = sut.JobProfileAdd(new JobProfileModel(-1) { Name = "a test", Description = "a test" }) as ActionResult;
Assert.IsNotNull(Result);
Expand Down Expand Up @@ -257,7 +259,7 @@ public void JobProfileDelete_ValidModel_ItemCanBeDeleted_Returns_JsonSuccessResp
public void JobProfileUpdate_InvalidModel_Null_Returns_JsonErrorResponse()
{
MockNotification notification = new();
MockGSendDataProvider gSendDataProvider = new(new string[] { "ProverXL", "3018" });
MockGSendDataProvider gSendDataProvider = new(["ProverXL", "3018"]);
JobProfileApi sut = new(gSendDataProvider, notification);
ActionResult Result = sut.JobProfileAdd(new JobProfileModel(-1) { Name = "a test", Description = "a test" }) as ActionResult;
Assert.IsNotNull(Result);
Expand All @@ -284,7 +286,7 @@ public void JobProfileUpdate_InvalidModel_Null_Returns_JsonErrorResponse()
public void JobProfileUpdate_InvalidModel_NameNull_Returns_JsonErrorResponse()
{
MockNotification notification = new();
MockGSendDataProvider gSendDataProvider = new(new string[] { "ProverXL", "3018" });
MockGSendDataProvider gSendDataProvider = new(["ProverXL", "3018"]);
JobProfileApi sut = new(gSendDataProvider, notification);

IActionResult result = sut.JobProfileUpdate(new JobProfileModel(0));
Expand All @@ -309,7 +311,7 @@ public void JobProfileUpdate_InvalidModel_NameNull_Returns_JsonErrorResponse()
public void JobProfileUpdate_InvalidModel_DescriptionNull_Returns_JsonErrorResponse()
{
MockNotification notification = new();
MockGSendDataProvider gSendDataProvider = new(new string[] { "ProverXL", "3018" });
MockGSendDataProvider gSendDataProvider = new(["ProverXL", "3018"]);
JobProfileApi sut = new(gSendDataProvider, notification);

IActionResult result = sut.JobProfileUpdate(new JobProfileModel(0) { Name = "name" });
Expand All @@ -334,7 +336,7 @@ public void JobProfileUpdate_InvalidModel_DescriptionNull_Returns_JsonErrorRespo
public void JobProfileUpdate_InvalidModel_NotFound_Returns_JsonErrorResponse()
{
MockNotification notification = new();
MockGSendDataProvider gSendDataProvider = new(new string[] { "ProverXL", "3018" });
MockGSendDataProvider gSendDataProvider = new(["ProverXL", "3018"]);
JobProfileApi sut = new(gSendDataProvider, notification);

IActionResult result = sut.JobProfileUpdate(new JobProfileModel(245) { Name = "name", Description = "desc" });
Expand All @@ -358,7 +360,7 @@ public void JobProfileUpdate_InvalidModel_NotFound_Returns_JsonErrorResponse()
[TestMethod]
public void JobProfileUpdate_ValidModel_ItemCanBeUpdated_Returns_JsonSuccessResponse()
{
MockGSendDataProvider gSendDataProvider = new(new string[] { "ProverXL", "3018" });
MockGSendDataProvider gSendDataProvider = new(["ProverXL", "3018"]);
gSendDataProvider.JobProfiles.Add(new JobProfileModel(1) { Name = "Profile 1", Description = "test 1" });
gSendDataProvider.JobProfiles.Add(new JobProfileModel(325) { Name = "Profile 2", Description = "test 2" });
gSendDataProvider.JobProfiles.Add(new JobProfileModel(9865433) { Name = "Profile 3", Description = "test 3" });
Expand Down Expand Up @@ -412,3 +414,5 @@ public void JobProfileUpdate_ValidModel_ItemCanBeUpdated_Returns_JsonSuccessResp
}
}
}

#pragma warning restore CA1861
Loading

0 comments on commit 00f4974

Please sign in to comment.