Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/sonar issues #31

Merged
merged 5 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ G Code Analyser, Editor and Sender


## Devops
main: ![Build Status main Branch](https://ci.appveyor.com/api/projects/status/eordnrimxkovdwe2/branch/main?svg=true)

Latest Branch: ![Build Status Latest Build](https://ci.appveyor.com/api/projects/status/eordnrimxkovdwe2?svg=true)

main: [![CodeQL](https://github.com/k3ldar/GSendPro/actions/workflows/codeql-analysis.yml/badge.svg?branch=main)](https://github.com/k3ldar/GSendPro/actions/workflows/codeql-analysis.yml)

[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=k3ldar_GSendPro&metric=vulnerabilities)](https://sonarcloud.io/summary/overall?id=k3ldar_GSendPro) [![Bugs](https://sonarcloud.io/api/project_badges/measure?project=k3ldar_GSendPro&metric=bugs)](https://sonarcloud.io/summary/overalloverall?id=k3ldar_GSendPro) [![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=k3ldar_GSendPro&metric=code_smells)](https://sonarcloud.io/summary/overall?id=k3ldar_GSendPro)

[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=k3ldar_GSendPro&metric=reliability_rating)](https://sonarcloud.io/summary/overall?id=k3ldar_GSendPro) [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=k3ldar_GSendPro&metric=sqale_rating)](https://sonarcloud.io/summary/overall?id=k3ldar_GSendPro) [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=k3ldar_GSendPro&metric=security_rating)](https://sonarcloud.io/summary/overall?id=k3ldar_GSendPro) [![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=k3ldar_GSendPro&metric=sqale_index)](https://sonarcloud.io/summary/overall?id=k3ldar_GSendPro)
Expand Down
2 changes: 1 addition & 1 deletion src/GCAAnalyser/Analyzers/AnalyzeCoordinateSystemsUsed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses)
});
}

if (gCodeAnalyses.CoordinateSystems.EndsWith(","))
if (gCodeAnalyses.CoordinateSystems.EndsWith(','))
gCodeAnalyses.CoordinateSystems = gCodeAnalyses.CoordinateSystems[..^1];
}

Expand Down
2 changes: 1 addition & 1 deletion src/GCAAnalyser/Analyzers/AnalyzeInvalidGCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal class AnalyzeInvalidGCode : IGCodeAnalyzer

public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses)
{
bool longLine = gCodeAnalyses.AllCommands.Where(c => c.Attributes.HasFlag(CommandAttributes.InvalidLineTooLong)).Any();
bool longLine = gCodeAnalyses.AllCommands.Any(c => c.Attributes.HasFlag(CommandAttributes.InvalidLineTooLong));

if (longLine)
{
Expand Down
9 changes: 3 additions & 6 deletions src/GCAAnalyser/Analyzers/AnalyzeToolChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@ public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses)

tools.ForEach(t => gCodeAnalyses.Tools += $"{t.CommandValueString},");
}
else if (gCodeAnalyses.AnalysesOptions.HasFlag(AnalysesOptions.ContainsAutomaticToolChanges))
else if (gCodeAnalyses.AnalysesOptions.HasFlag(AnalysesOptions.ContainsAutomaticToolChanges) && (gCodeAnalyses is GCodeAnalyses codeAnalyses))
{
if (gCodeAnalyses is GCodeAnalyses codeAnalyses)
{
codeAnalyses.AddError(GSend.Language.Resources.AnalyzeError1);
}
codeAnalyses.AddError(GSend.Language.Resources.AnalyzeError1);
}

if (gCodeAnalyses.Tools.EndsWith(","))
if (gCodeAnalyses.Tools.EndsWith(','))
gCodeAnalyses.Tools = gCodeAnalyses.Tools[..^1];
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/GCAAnalyser/Analyzers/BaseAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ namespace GSendAnalyzer.Analyzers
{
public class BaseAnalyzer
{
protected bool HasCommandsOnSameLine(IGCodeCommand command, char ignoreCommands)
protected static bool HasCommandsOnSameLine(IGCodeCommand command, char ignoreCommands)
{
var commandsOnLine = CommandsOnSameLine(command);

return commandsOnLine.Any(c => c.Command != ignoreCommands);
return commandsOnLine.Exists(c => c.Command != ignoreCommands);
}

protected List<IGCodeCommand> CommandsOnSameLine(IGCodeCommand command)
protected static List<IGCodeCommand> CommandsOnSameLine(IGCodeCommand command)
{
if (command == null)
throw new ArgumentNullException(nameof(command));
Expand All @@ -25,7 +25,7 @@ protected List<IGCodeCommand> CommandsOnSameLine(IGCodeCommand command)
return Result;
}

private void LookPrevious(IGCodeCommand command, List<IGCodeCommand> commands)
private static void LookPrevious(IGCodeCommand command, List<IGCodeCommand> commands)
{
IGCodeCommand previous = command.PreviousCommand;

Expand All @@ -43,7 +43,7 @@ private void LookPrevious(IGCodeCommand command, List<IGCodeCommand> commands)
}
}

private void LookNext(IGCodeCommand command, List<IGCodeCommand> commands)
private static void LookNext(IGCodeCommand command, List<IGCodeCommand> commands)
{
IGCodeCommand next = command.NextCommand;

Expand All @@ -61,7 +61,7 @@ private void LookNext(IGCodeCommand command, List<IGCodeCommand> commands)
}
}

protected bool ValidatePreviousNextCommand(IGCodeCommand command, char toFindCommand)
protected static bool ValidatePreviousNextCommand(IGCodeCommand command, char toFindCommand)
{
if (command == null)
return false;
Expand All @@ -75,7 +75,7 @@ protected bool ValidatePreviousNextCommand(IGCodeCommand command, char toFindCom
return false;
}

protected bool ValidateNextCommand(IGCodeCommand command, decimal finalNextTo)
protected static bool ValidateNextCommand(IGCodeCommand command, decimal finalNextTo)
{
if (command == null)
return false;
Expand All @@ -88,7 +88,7 @@ protected bool ValidateNextCommand(IGCodeCommand command, decimal finalNextTo)
return false;
}

protected bool ValidateNextCommand(IGCodeCommand command, decimal finalNextTo, decimal[] nextTo, char[] ignoreNextCommands, int depth)
protected static bool ValidateNextCommand(IGCodeCommand command, decimal finalNextTo, decimal[] nextTo, char[] ignoreNextCommands, int depth)
{
if (command == null || command.NextCommand == null || depth == 10)
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/GCAAnalyser/GCodeAnalyses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public List<IGCodeLine> Lines(out int lineCount)
Result.Add(currentLine);
}

currentLine.Commands.Add(command);
currentLine?.Commands.Add(command);
}

return Result;
Expand All @@ -233,7 +233,7 @@ public List<IGCodeLine> AllLines(out int lineCount)
Result.Add(currentLine);
}

currentLine.Commands.Add(command);
currentLine?.Commands.Add(command);
}

return Result;
Expand Down
46 changes: 10 additions & 36 deletions src/GCSDesktop/Forms/FrmMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@

using static GSendShared.Constants;

//using static System.Windows.Forms.VisualStyles.VisualStyleElement.TrayNotify;

namespace GSendDesktop.Forms
{
public partial class FrmMachine : BaseForm, IUiUpdate, IShortcutImplementation
Expand Down Expand Up @@ -200,8 +198,6 @@ private void ClientWebSocket_ProcessMessage(string message)
if (String.IsNullOrWhiteSpace(message))
return;

//Trace.WriteLine($"Client: {message}");

ClientBaseMessage clientMessage = null;
try
{
Expand All @@ -212,9 +208,6 @@ private void ClientWebSocket_ProcessMessage(string message)
return;
}

//Trace.WriteLine(String.Format("Machine {0} Socket Message: {1}", _machine.Name, clientMessage.success));
//Trace.WriteLine(message);

if (clientMessage == null)
return;

Expand All @@ -223,8 +216,6 @@ private void ClientWebSocket_ProcessMessage(string message)
ProcessFailedMessage(clientMessage);
}

string serverCpu = String.Format(GSend.Language.Resources.ServerCpuStateConnected, clientMessage.ServerCpuStatus.ToString("N2"));

switch (clientMessage.request)
{
case "Stop":
Expand Down Expand Up @@ -307,7 +298,7 @@ private void ClientWebSocket_ProcessMessage(string message)

case "ResponseReceived":
case "MessageReceived":
if (clientMessage.message.ToString().StartsWith("<") || _isJogging)
if (clientMessage.message.ToString().StartsWith('<') || _isJogging)
{
_lastMessageWasHiddenCommand = true;
}
Expand Down Expand Up @@ -360,7 +351,7 @@ private void ClientWebSocket_ProcessMessage(string message)
break;

case Constants.MessageLineStatusUpdated:
LineStatusUpdateModel lineStatusUpdateModel = (LineStatusUpdateModel)JsonSerializer.Deserialize<LineStatusUpdateModel>(clientMessage.message.ToString(), Constants.DefaultJsonSerializerOptions);
LineStatusUpdateModel lineStatusUpdateModel = JsonSerializer.Deserialize<LineStatusUpdateModel>(clientMessage.message.ToString(), Constants.DefaultJsonSerializerOptions);

if (lineStatusUpdateModel != null && _gcodeLines != null)
{
Expand All @@ -384,7 +375,7 @@ private void ClientWebSocket_ProcessMessage(string message)
break;

case Constants.MessageInformationUpdate:
InformationMessageModel informationMessageModel = (InformationMessageModel)JsonSerializer.Deserialize<InformationMessageModel>(clientMessage.message.ToString(), Constants.DefaultJsonSerializerOptions);
InformationMessageModel informationMessageModel = JsonSerializer.Deserialize<InformationMessageModel>(clientMessage.message.ToString(), Constants.DefaultJsonSerializerOptions);

if (informationMessageModel != null)
{
Expand All @@ -397,7 +388,7 @@ private void ClientWebSocket_ProcessMessage(string message)
break;

case Constants.MessageConfigurationUpdated:
ConfigurationUpdatedMessage updateMessage = (ConfigurationUpdatedMessage)JsonSerializer.Deserialize<ConfigurationUpdatedMessage>(clientMessage.message.ToString(), Constants.DefaultJsonSerializerOptions);
ConfigurationUpdatedMessage updateMessage = JsonSerializer.Deserialize<ConfigurationUpdatedMessage>(clientMessage.message.ToString(), Constants.DefaultJsonSerializerOptions);

if (_machine.Name != updateMessage.Name)
{
Expand Down Expand Up @@ -465,7 +456,6 @@ protected override void UpdateEnabledState()
mnuMachineLoadGCode.Enabled = _machineStatusModel?.IsRunning == false;
mnuMachineClearGCode.Enabled = _machineStatusModel?.IsRunning == false && _gCodeAnalyses != null;

//tabPageServiceSchedule.Enabled = _machineConnected && _machineStatusModel?.IsRunning == false;
tabPageSpindle.Enabled = _machineConnected && _machineStatusModel?.IsRunning == false;
}

Expand Down Expand Up @@ -509,14 +499,6 @@ private void UpdateMachineStatus(MachineStateModel status)
}
}

//if (!_updatingRapidOverride && selectionOverrideRapids.Value != (int)status.RapidSpeed)
//{
// selectionOverrideRapids.ValueChanged -= SelectionOverrideRapids_ValueChanged;
// selectionOverrideRapids.Value = (int)status.RapidSpeed;
// selectionOverrideRapids.LabelValue = HelperMethods.TranslateRapidOverride(status.RapidSpeed);
// selectionOverrideRapids.ValueChanged += SelectionOverrideRapids_ValueChanged;
//}

if (status.IsConnected)
{
machine2dView1.XPosition = (float)status.WorkX;
Expand Down Expand Up @@ -582,7 +564,7 @@ private void UpdateMachineStatus(MachineStateModel status)
_isRunning = status.IsRunning || status.MachineState == MachineState.Run;
_isJogging = status.MachineState == MachineState.Jog;
_isAlarm = status.IsLocked;
toolStripProgressBarJob.Visible = status == null ? false : status.IsConnected && status.IsRunning;
toolStripProgressBarJob.Visible = status != null && status.IsConnected && status.IsRunning;

toolStripProgressBarJob.Value = status.LineNumber;

Expand Down Expand Up @@ -926,7 +908,6 @@ private void SelectionOverrideRapids_ValueChanged(object sender, EventArgs e)
{
if (selectionOverrideRapids.Checked)
{
//_updatingRapidOverride = true;
_machineUpdateThread.Overrides.Rapids = (RapidsOverride)selectionOverrideRapids.Value;
}
else
Expand Down Expand Up @@ -1024,8 +1005,6 @@ private void OverrideAxis_Checked(object sender, EventArgs e)

protected override void WndProc(ref Message m)
{
//_shortcutHandler.WndProc(ref m);

base.WndProc(ref m);
}

Expand Down Expand Up @@ -1152,7 +1131,7 @@ private void ValidateLaserSpindleMode(MachineStateModel status)
switch (_machine.MachineType)
{
case MachineType.CNC:
if (status.UpdatedGrblConfiguration.Any(s => s.DollarValue.Equals(32) && s.OldValue.Equals("0") && s.NewValue.Equals("1")))
if (status.UpdatedGrblConfiguration.Exists(s => s.DollarValue.Equals(32) && s.OldValue.Equals("0") && s.NewValue.Equals("1")))
{
warningsAndErrors.AddWarningPanel(InformationType.Information, GSend.Language.Resources.AutomaticallySelectedSpindleMode);
_machine.Settings.LaserModeEnabled = false;
Expand All @@ -1164,7 +1143,7 @@ private void ValidateLaserSpindleMode(MachineStateModel status)
break;

case MachineType.Laser:
if (status.UpdatedGrblConfiguration.Any(s => s.DollarValue.Equals(32) && s.OldValue.Equals("1") && s.NewValue.Equals("2")))
if (status.UpdatedGrblConfiguration.Exists(s => s.DollarValue.Equals(32) && s.OldValue.Equals("1") && s.NewValue.Equals("2")))
{
warningsAndErrors.AddWarningPanel(InformationType.Information, GSend.Language.Resources.AutomaticallySelectedLaserMode);
_machine.Settings.LaserModeEnabled = true;
Expand Down Expand Up @@ -1341,7 +1320,7 @@ private void btnGrblCommandSend_Click(object sender, EventArgs e)

string command = txtUserGrblCommand.Text.Replace(":", "\t").Trim();

if (txtUserGrblCommand.Text.StartsWith("$") || txtUserGrblCommand.Text == "?")
if (txtUserGrblCommand.Text.StartsWith('$') || txtUserGrblCommand.Text == "?")
SendMessage(String.Format(Constants.MessageMachineWriteLineR, _machine.Id, command));
else
SendMessage(String.Format(Constants.MessageMachineWriteLine, _machine.Id, command));
Expand Down Expand Up @@ -1565,7 +1544,6 @@ private void ConfigureMachine()
selectionOverrideZDown.EnabledChanged += OverrideAxis_Checked;
selectionOverrideSpindle.EnabledChanged += OverrideAxis_Checked;

//trackBarPercent.ValueChanged -= trackBarPercent_ValueChanged;
selectionOverrideRapids.ValueChanged -= SelectionOverrideRapids_ValueChanged;
selectionOverrideXY.ValueChanged -= SelectionOverride_ValueChanged;
selectionOverrideZDown.ValueChanged -= SelectionOverride_ValueChanged;
Expand All @@ -1586,7 +1564,6 @@ private void ConfigureMachine()
cbSoftStart.Checked = _machine.SoftStart;
trackBarDelaySpindle.Value = Shared.Utilities.CheckMinMax(_machine.SoftStartSeconds, trackBarDelaySpindle.Minimum, trackBarDelaySpindle.Maximum);

//trackBarPercent.ValueChanged += trackBarPercent_ValueChanged;
selectionOverrideRapids.ValueChanged += SelectionOverrideRapids_ValueChanged;
selectionOverrideXY.ValueChanged += SelectionOverride_ValueChanged;
selectionOverrideZDown.ValueChanged += SelectionOverride_ValueChanged;
Expand All @@ -1596,7 +1573,6 @@ private void ConfigureMachine()
// spindle
trackBarSpindleSpeed.Maximum = (int)_machine.Settings.MaxSpindleSpeed;
trackBarSpindleSpeed.Minimum = (int)_machine.Settings.MinSpindleSpeed;
//trackBarSpindleSpeed.TickFrequency =
trackBarSpindleSpeed.Value = trackBarSpindleSpeed.Maximum;
cbSpindleCounterClockwise.Checked = _machine.Options.HasFlag(MachineOptions.SpindleCounterClockWise);
cmbSpindleType.SelectedItem = _machine.SpindleType;
Expand Down Expand Up @@ -1696,7 +1672,6 @@ private void HookUpEvents()
mnuViewJog.Click += SelectTabControlMainTab;
mnuViewSpindle.Tag = tabPageSpindle;
mnuViewSpindle.Click += SelectTabControlMainTab;
//mnuViewServiceSchedule.Tag = tabPageServiceSchedule;
mnuViewServiceSchedule.Click += SelectTabControlMainTab;
mnuViewMachineSettings.Tag = tabPageMachineSettings;
mnuViewMachineSettings.Click += SelectTabControlMainTab;
Expand Down Expand Up @@ -1734,7 +1709,6 @@ protected override void LoadResources()
//tab pages
tabPageMain.Text = GSend.Language.Resources.General;
tabPageOverrides.Text = GSend.Language.Resources.Overrides;
//tabPageServiceSchedule.Text = GSend.Language.Resources.ServiceSchedule;
tabPageMachineSettings.Text = GSend.Language.Resources.GrblSettings;
tabPageSpindle.Text = GSend.Language.Resources.Spindle;
tabPageSettings.Text = GSend.Language.Resources.Settings;
Expand Down Expand Up @@ -2440,7 +2414,7 @@ private void UpdateShortcutKeyValues(List<IShortcut> Result)
}
}

if (shortcut != null && shortcut.KeysUpdated != null)
if (shortcut.KeysUpdated != null)
shortcut.KeysUpdated(shortcut.DefaultKeys);
}
}
Expand All @@ -2449,7 +2423,7 @@ private void RecursivelyRetrieveAllShortcutClasses(Control control, List<IShortc
{
if (depth > 25)
{

return;
}

if (control is IShortcutImplementation shortcutImpl)
Expand Down
3 changes: 0 additions & 3 deletions src/GCSDesktop/Forms/StartJobWizard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ public StartJobWizard(MachineStateModel machineStatusModel, IGCodeAnalyses gCode
_gCodeAnalyses = gCodeAnalyses ?? throw new ArgumentNullException(nameof(gCodeAnalyses));
_gSendApiWrapper = machineApiWrapper ?? throw new ArgumentNullException(nameof(machineApiWrapper));

if (machineApiWrapper == null)
throw new ArgumentNullException(nameof(machineApiWrapper));

string jobName = DesktopSettings.ReadValue<string>(nameof(StartJobWizard), Constants.StartWizardSelectedJob, String.Empty);

if (!String.IsNullOrEmpty(gCodeAnalyses.JobName))
Expand Down
Loading
Loading