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

Refactoring #867

Merged
merged 2 commits into from
Aug 24, 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
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
private readonly IPayloadService _payloadService;
private readonly IWorkflowService _workflowService;

private readonly Regex _squigglyBracketsRegex = new Regex(@"\{{(.*?)\}}");
private readonly Regex _squigglyBracketsRegex = new(@"\{{(.*?)\}}", RegexOptions.None, matchTimeout: TimeSpan.FromSeconds(2));

private WorkflowInstance? _workflowInstance = null;
private string? _workflowInstanceId = null;
Expand Down Expand Up @@ -282,7 +282,7 @@
var subValues = subValue.Split('.');
var id = subValues[1].Trim('\'');

var task = WorkflowInstance?.Tasks.FirstOrDefault(t => t.TaskId == id);

Check warning on line 285 in src/WorkflowManager/ConditionsResolver/Parser/ConditionalParameterParser.cs

View workflow job for this annotation

GitHub Actions / sonarscanner

"Find" method should be used instead of the "FirstOrDefault" extension method. (https://rules.sonarsource.com/csharp/RSPEC-6602)

if (task is null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@

public int GroupedLogical { get; set; } = 1;

public Regex FindAnds { get; } = new Regex(@"([\s]and[\s]|[\s]AND[\s]|[\s]And[\s])");
public Regex FindAnds { get; } = new(@"([\s]and[\s]|[\s]AND[\s]|[\s]And[\s])", RegexOptions.None, matchTimeout: TimeSpan.FromSeconds(2));

public Regex FindOrs { get; } = new Regex(@"([\s]or[\s]|[\s]OR[\s]|[\s]Or[\s])");
public Regex FindOrs { get; } = new(@"([\s]or[\s]|[\s]OR[\s]|[\s]Or[\s])", RegexOptions.None, matchTimeout: TimeSpan.FromSeconds(2));

public Regex FindBrackets { get; } = new Regex(@"((?<!\[)\()");
public Regex FindBrackets { get; } = new(@"((?<!\[)\()", RegexOptions.None, matchTimeout: TimeSpan.FromSeconds(2));

public Regex FindCloseBrackets { get; } = new Regex(@"((?<!\[)\))");
public Regex FindCloseBrackets { get; } = new(@"((?<!\[)\))", RegexOptions.None, matchTimeout: TimeSpan.FromSeconds(2));

private string[] ParseOrs(string input) => FindOrs.SplitOnce(input);

Expand Down Expand Up @@ -96,7 +96,7 @@

if (foundOpenBrackets.Count >= 1)
{
var firstOpenBracketIndex = foundOpenBrackets.First().Index;

Check warning on line 99 in src/WorkflowManager/ConditionsResolver/Resovler/ConditionalGroup.cs

View workflow job for this annotation

GitHub Actions / sonarscanner

Indexing at 0 should be used instead of the "Enumerable" extension method "First" (https://rules.sonarsource.com/csharp/RSPEC-6608)
if (firstOpenBracketIndex == 0)
{
GroupedLogical = groupedLogicalParent + 1;
Expand Down Expand Up @@ -141,15 +141,15 @@
}
var startingBracketHasBeenTrimmed = indexOfClosingBracket < foundBrackets.Index;
// if first index of any ANDs or ORs are before the first bracket then left hand evaluation should be processed
if (!startingBracketHasBeenTrimmed && (foundAnds.Any() && foundAnds.First().Index < foundBrackets.Index) || (foundOrs.Any() && foundOrs.First().Index < foundBrackets.Index))

Check warning on line 144 in src/WorkflowManager/ConditionsResolver/Resovler/ConditionalGroup.cs

View workflow job for this annotation

GitHub Actions / sonarscanner

Indexing at 0 should be used instead of the "Enumerable" extension method "First" (https://rules.sonarsource.com/csharp/RSPEC-6608)

Check warning on line 144 in src/WorkflowManager/ConditionsResolver/Resovler/ConditionalGroup.cs

View workflow job for this annotation

GitHub Actions / sonarscanner

Indexing at 0 should be used instead of the "Enumerable" extension method "First" (https://rules.sonarsource.com/csharp/RSPEC-6608)
{
if (!foundOrs.Any() || foundAnds.Any() && foundAnds.First().Index < foundOrs.First().Index)

Check warning on line 146 in src/WorkflowManager/ConditionsResolver/Resovler/ConditionalGroup.cs

View workflow job for this annotation

GitHub Actions / sonarscanner

Indexing at 0 should be used instead of the "Enumerable" extension method "First" (https://rules.sonarsource.com/csharp/RSPEC-6608)

Check warning on line 146 in src/WorkflowManager/ConditionsResolver/Resovler/ConditionalGroup.cs

View workflow job for this annotation

GitHub Actions / sonarscanner

Indexing at 0 should be used instead of the "Enumerable" extension method "First" (https://rules.sonarsource.com/csharp/RSPEC-6608)
{
var splitByAnds = ParseAnds(input);
var rightAnd = splitByAnds[1].TrimStartExt("AND");
Set(splitByAnds[0], rightAnd, Keyword.And);
}
else if (!foundAnds.Any() && foundOrs.Any() || foundOrs.First().Index < foundAnds.First().Index)

Check warning on line 152 in src/WorkflowManager/ConditionsResolver/Resovler/ConditionalGroup.cs

View workflow job for this annotation

GitHub Actions / sonarscanner

Indexing at 0 should be used instead of the "Enumerable" extension method "First" (https://rules.sonarsource.com/csharp/RSPEC-6608)

Check warning on line 152 in src/WorkflowManager/ConditionsResolver/Resovler/ConditionalGroup.cs

View workflow job for this annotation

GitHub Actions / sonarscanner

Indexing at 0 should be used instead of the "Enumerable" extension method "First" (https://rules.sonarsource.com/csharp/RSPEC-6608)
{
var splitByOrs = ParseOrs(input);
var rightOrs = splitByOrs[1].TrimStartExt("OR");
Expand Down Expand Up @@ -321,8 +321,8 @@

if (foundOpenBrackets.Count == 1)
{
var foundBracketsAreAtStartAndEnd = foundOpenBrackets.First().Index == 0

Check warning on line 324 in src/WorkflowManager/ConditionsResolver/Resovler/ConditionalGroup.cs

View workflow job for this annotation

GitHub Actions / sonarscanner

Indexing at 0 should be used instead of the "Enumerable" extension method "First" (https://rules.sonarsource.com/csharp/RSPEC-6608)
&& foundClosingBrackets.First().Index == input.Length - 1;

Check warning on line 325 in src/WorkflowManager/ConditionsResolver/Resovler/ConditionalGroup.cs

View workflow job for this annotation

GitHub Actions / sonarscanner

Indexing at 0 should be used instead of the "Enumerable" extension method "First" (https://rules.sonarsource.com/csharp/RSPEC-6608)
if (foundBracketsAreAtStartAndEnd)
{
input = input.Trim('(');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ private async Task ValidateWorkflowSpec(Workflow workflow)
}

var taskIds = workflow.Tasks.Select(t => t.Id);
var pattern = new Regex(@"^[a-zA-Z0-9-_]+$");
var pattern = new Regex(@"^[a-zA-Z0-9-_]+$", RegexOptions.None, matchTimeout: TimeSpan.FromSeconds(2));
foreach (var taskId in taskIds)
{
if (pattern.IsMatch(taskId) is false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class RegexExtensionsTests
[InlineData(new string[] { "test ", "( test( test" }, "test ( test( test")]
public void Regex_WhenSplitOnce_ShouldOnlyHaveArrayOfTwo(string[] expected, string stringToSplit)
{
var regexFindBrackets = new Regex(@"((?<!\[)\()");
var regexFindBrackets = new Regex(@"((?<!\[)\()", RegexOptions.None, matchTimeout: TimeSpan.FromSeconds(2));
var result = regexFindBrackets.SplitOnce(stringToSplit);
Assert.Equal(expected, result);
Assert.Equal(2, result.Length);
Expand All @@ -40,7 +40,7 @@ public void Regex_WhenSplitOnce_ShouldOnlyHaveArrayOfTwo(string[] expected, stri
public void Regex_WhenSplitOnceProvidedNullInput_ShouldThrowException()
{
var expectedErrorMessage = "Value cannot be null. (Parameter 'input')";
var regexFindBrackets = new Regex(@"((?<!\[)\()");
var regexFindBrackets = new Regex(@"((?<!\[)\()", RegexOptions.None, matchTimeout: TimeSpan.FromSeconds(2));
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
var exception = Assert.Throws<ArgumentNullException>(() => regexFindBrackets.SplitOnce(null));
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
Expand Down
Loading