Skip to content

Commit

Permalink
Fixed path checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Bot-Dev-RPA committed Sep 20, 2024
1 parent 12e76fe commit 660732d
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 144 deletions.
9 changes: 5 additions & 4 deletions CodeAnalyzer/Config/CodeQuality.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"OpenCloseMethodPair": {
"Name": "Open-Close Method Pair",
"Name": "Open-Close Connector",
"Description": "Activities with an 'Open' method must have a corresponding 'Close' method.",
"Enabled": true,
"Severity": "Warn",
"OpenMethodPrefixes": [
"Open",
"Load"
"Load",
"SetAccount"
],
"CloseMethodPrefixes": [
"Close"
Expand All @@ -16,7 +17,7 @@
"Name": "Hardcoded Delay",
"Description": "Activities should not use hardcoded delays (WaitForTime)",
"Enabled": true,
"Severity": "Fail",
"Severity": "Warn",
"ProhibitedTypes": [
"WaitForTime"
]
Expand All @@ -25,7 +26,7 @@
"Name": "Modified Delay Properties",
"Description": "BeforeDelay and AfterDelay should be avoided, and EnableTimeout should be false",
"Enabled": true,
"Severity": "Fail",
"Severity": "Warn",
"AllowedBeforeDelay": 0,
"AllowedAfterDelay": 0,
"AllowedEnableTimeout": false
Expand Down
2 changes: 1 addition & 1 deletion CodeAnalyzer/Config/Diagnostics.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"Enabled": true,
"Severity": "Fail",
"AllowedLogLevels": [
"WARN",
"WARNING",
"ERROR",
"EXCEPTION"
]
Expand Down
28 changes: 17 additions & 11 deletions CodeAnalyzer/Config/Framework.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
"Enabled": true,
"Severity": "Fail",
"RequiredActivities": [
"Initialize Workflow",
"Get Workitem",
"Process Workitem",
"Exit Workflow"
"Initialize",
"Queue Setup",
"Queue Processing",
"Exit"
]
},
"ActivityNamingConvention": {
Expand All @@ -32,22 +32,21 @@
"Enabled": true,
"Severity": "Warn",
"MinLength": 3,
"NamingRegex": "^[a-zA-Z_][a-zA-Z0-9_]*$"
"NamingRegex": "^[a-zA-Z0-9\\s-_]*$"
},
"ActivityVariableNamingConvention": {
"Name": "Activity Variable Naming Convention",
"Description": "Activity variables should follow the specified naming convention",
"Enabled": true,
"Severity": "Warn",
"MinLength": 3,
"NamingRegex": "^[a-zA-Z_][a-zA-Z0-9_]*$"
"NamingRegex": "^[a-zA-Z0-9\\s-_]*$"
},
"GlobalVariablePlacement": {
"Name": "Global Variable Placement",
"Description": "Global Variables should be placed under 'Global Object/Variables' or its subfolders",
"Description": "Global Variables should be placed under 'Variables' or its subfolders",
"Enabled": true,
"Severity": "Warn",
"ExpectedPath": "Global Objects/Variables"
"Severity": "Warn"
},
"ExecutableComponentCount": {
"Name": "Executable Component Count",
Expand All @@ -60,8 +59,7 @@
"Name": "Connector Grouping",
"Description": "Connectors should be grouped under specific folders based on their types",
"Enabled": true,
"Severity": "Warn",
"ExpectedPath": "Global Objects/{ConnectorType}"
"Severity": "Warn"
},
"QueueUtilization": {
"Name": "Queue Utilization",
Expand All @@ -72,12 +70,20 @@
"PickWorkitem": {
"Name": "Pick Workitem",
"Description": "Pick Workitem executable item must be used in framework Get Workitem activity",
"ActivityNames": [
"Queue Processing"
],
"Enabled": true,
"Severity": "Fail"
},
"UpdateWorkitem": {
"Name": "Update Workitem",
"Description": "Update Workitem executable item must be used in framework Process Workitem activity",
"ActivityNames": [
"Process Work Item",
"Process Business Exception",
"Process System Exception"
],
"Enabled": true,
"Severity": "Fail"
}
Expand Down
49 changes: 18 additions & 31 deletions CodeAnalyzer/Models/Bot/Activity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,59 +13,46 @@ public record Activity
public OnErrorAction OnErrorActionAfterRetry { get; set; }
public string RootPath { get; set; } = string.Empty;

public CommentConnection? GetCommentConnectionWithSourcePort(Guid? portId)
public CommentConnection? GetCommentConnectionWithSourceComponent(Guid? sourceComponentId, Guid? sourcePortId)
{
return Items.OfType<CommentConnection>()
.FirstOrDefault(connection => connection.SourcePortId == portId);
.FirstOrDefault(connection => connection.SourceComponentId == sourceComponentId &&
connection.SourcePortId == sourcePortId);
}

public ControlConnection? GetControlConnectionWithSourcePort(Guid? portId)
public ControlConnection? GetControlConnectionWithSourceComponent(Guid? sourceComponentId, Guid? sourcePortId)
{
return Items.OfType<ControlConnection>()
.FirstOrDefault(connection => connection.SourcePortId == portId);
.FirstOrDefault(connection => connection.SourceComponentId == sourceComponentId &&
connection.SourcePortId == sourcePortId);
}

public DataConnection? GetDataConnectionWithSourcePort(Guid? portId)
public DataConnection? GetDataConnectionWithSourceComponent(Guid? sourceComponentId, Guid? sourcePortId)
{
return Items.OfType<DataConnection>()
.FirstOrDefault(connection => connection.SourcePortId == portId);
.FirstOrDefault(connection => connection.SourceComponentId == sourceComponentId &&
connection.SourcePortId == sourcePortId);
}

public List<DataConnection> GetDataConnectionsWithSourcePort(Guid? portId)
{
return Items.OfType<DataConnection>()
.Where(connection => connection.SourcePortId == portId)
.ToList();
}

public ControlConnection? GetControlConnectionWithSinkPort(Guid? portId)
public List<ControlConnection> GetControlConnectionsWithSinkComponent(Guid? sinkComponentId, Guid? sinkPortId)
{
return Items.OfType<ControlConnection>()
.FirstOrDefault(connection => connection.SinkPortId == portId);
}

public List<ControlConnection> GetControlConnectionsWithSinkPort(Guid? portId)
{
return Items.OfType<ControlConnection>()
.Where(connection => connection.SinkPortId == portId)
.Where(connection => connection.SinkComponentId == sinkComponentId &&
connection.SinkPortId == sinkPortId)
.ToList();
}

public DataConnection? GetDataControlConnectionWithSinkPort(Guid? portId)
{
return Items.OfType<DataConnection>()
.FirstOrDefault(connection => connection.SinkPortId == portId);
}

public ExecutableItem? GetExecutableItemWithControlInPort(Guid? portId)
public ExecutableItem? GetExecutableItemWithControlInPort(Guid? itemId, Guid? itemControlInPortId)
{
return Items.OfType<ExecutableItem>()
.FirstOrDefault(item => item.ControlIn?.Id == portId);
.FirstOrDefault(item => item.Id == itemId &&
item.ControlIn?.Id == itemControlInPortId);
}

public ExecutableItem? GetExecutableItemWithControlOutPort(Guid? portId)
public ExecutableItem? GetExecutableItemWithControlOutPort(Guid? itemId, Guid? itemControlOutPortId)
{
return Items.OfType<ExecutableItem>()
.FirstOrDefault(item => item.ControlOut?.Id == portId);
.FirstOrDefault(item => item.Id == itemId &&
item.ControlOut?.Id == itemControlOutPortId);
}
}
22 changes: 13 additions & 9 deletions CodeAnalyzer/Services/RuleChecker/CodeQualityRuleChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public CodeQualityRuleChecker()
throw new InvalidOperationException("CodeQuality config not initialized");
_rules = new Dictionary<string, Func<Process, Rule, List<RuleCheckResult>>>
{
{ "OpenCloseMethodPair", CheckOpenCloseMethods },
{ "OpenCloseMethodPair", CheckOpenCloseConnectorMethods },
{ "HardcodedDelay", CheckHardcodedDelays },
{ "ModifiedDelayProperties", CheckModifiedDelayProperties },
{ "Comments", CheckNonEmptyComments },
Expand Down Expand Up @@ -50,11 +50,11 @@ public List<RuleCheckResult> CheckRules(Process process)
return results;
}

private List<RuleCheckResult> CheckOpenCloseMethods(Process process, Rule rule)
private List<RuleCheckResult> CheckOpenCloseConnectorMethods(Process process, Rule rule)
{
var severity = _config.GetParameter("OpenCloseMethodPair", "Severity", "Warn");
var openMethodPrefixes =
_config.GetStringArrayParameter("OpenCloseMethodPair", "OpenMethodPrefixes", ["Open", "Load"]);
_config.GetStringArrayParameter("OpenCloseMethodPair", "OpenMethodPrefixes", ["Open", "Load", "SetAccount"]);
var closeMethodPrefixes =
_config.GetStringArrayParameter("OpenCloseMethodPair", "CloseMethodPrefixes", ["Close"]);

Expand All @@ -63,12 +63,14 @@ private List<RuleCheckResult> CheckOpenCloseMethods(Process process, Rule rule)
foreach (var activity in process.Activities)
{
var openMethods = activity.Items.OfType<ExecutableItem>()
.Where(item => item.MethodName != null && openMethodPrefixes.Any(prefix =>
item.MethodName.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)))
.Where(item => item.Type.Equals("AutxMethod") && item.MethodName != null && openMethodPrefixes.Any(
prefix =>
item.MethodName.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)))
.ToList();
var closeMethods = activity.Items.OfType<ExecutableItem>()
.Where(item => item.MethodName != null && closeMethodPrefixes.Any(prefix =>
item.MethodName.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)))
.Where(item => item.Type.Equals("AutxMethod") && item.MethodName != null && closeMethodPrefixes.Any(
prefix =>
item.MethodName.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)))
.ToList();

// Check for Open methods without corresponding Close methods
Expand Down Expand Up @@ -280,7 +282,8 @@ private List<RuleCheckResult> CheckWindowsConnectorScreenRules(Process process,
Source = $"{screen.RootPath}/{screen.Name}",
Status = ParseSeverity(severity),
Comments =
$"Windows Screen '{screen.Name}' uses strict 'Equals' comparison: {GetRuleType(stringRule.Type)} {stringRule.Comparer.Type} '{stringRule.Comparer.ComparisonValue}'."
$"Windows Screen '{screen.Name}' uses strict 'Equals' comparison:" +
$" {GetRuleType(stringRule.Type)} {stringRule.Comparer.Type} '{stringRule.Comparer.ComparisonValue}'."
});
if (ContainsDigit(stringRule.Comparer.ComparisonValue))
screenViolations.Add(new RuleCheckResult
Expand All @@ -289,7 +292,8 @@ private List<RuleCheckResult> CheckWindowsConnectorScreenRules(Process process,
Source = $"{screen.RootPath}/{screen.Name}",
Status = ParseSeverity(severity),
Comments =
$"Windows Screen '{screen.Name}' match rule contains number: {GetRuleType(stringRule.Type)} {stringRule.Comparer.Type} '{stringRule.Comparer.ComparisonValue}'."
$"Windows Screen '{screen.Name}' match rule contains number:" +
$" {GetRuleType(stringRule.Type)} {stringRule.Comparer.Type} '{stringRule.Comparer.ComparisonValue}'."
});
}

Expand Down
Loading

0 comments on commit 660732d

Please sign in to comment.