-
Notifications
You must be signed in to change notification settings - Fork 16
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
CodeQL fixups #2134
CodeQL fixups #2134
Conversation
Finally fix that "Joink" typo after all the others
Fix up Equality override warning
Remove unused string constant
Fix up TestUpTo method
Use pattern matching instead of casts and null checks
Rdmp.UI.Tests/DesignPatternTests/ClassFileEvaluation/DocumentationCrossExaminationTest.cs
Fixed
Show fixed
Hide fixed
Fix CodeQL warning
Use LINQ per CodeQL
Fix redundant verbatim prefixes
foreach (var match in rWords.Matches(line).Where(match => glossaryHeaders.Contains(match.Value))) | ||
{ | ||
//It's already got a link on it e.g. [DBMS] or it's "UNION - sometext" | ||
if (match.Index - 1 > 0 | ||
&& | ||
(line[match.Index - 1] == '[' || line[match.Index - 1] == '"')) | ||
continue; | ||
|
||
|
||
var path1 = new Uri(mdFile); | ||
var path2 = new Uri(glossaryPath); | ||
var diff = path1.MakeRelativeUri(path2); | ||
var relPath = diff.OriginalString; | ||
|
||
if (!relPath.StartsWith('.')) | ||
relPath = $"./{relPath}"; | ||
|
||
var suggestedLine = $"[{match.Value}]: {relPath}#{match.Value}"; | ||
var markdownLink = $"[{match.Value}]({relPath}#{match.Value})"; | ||
|
||
//if it has spaces on either side | ||
if (line[Math.Max(0, match.Index - 1)] == ' ' && line[ | ||
Math.Min(line.Length - 1, | ||
match.Index + match.Length)] == ' ' | ||
//don't mess with lines that contain an image | ||
&& !line.Contains("![")) | ||
allLines[lineNumber - 1] = line.Replace($" {match.Value} ", $" [{match.Value}] "); | ||
|
||
//also if we have a name like `Catalogue` it should probably be [Catalogue] instead so it works as a link | ||
allLines[lineNumber - 1] = line.Replace($"`{match.Value}`", $"[{match.Value}]"); | ||
|
||
//if it is a novel occurrence | ||
if (!allLines.Contains(suggestedLine) && !suggestedLinks.ContainsValue(suggestedLine) && !allLines.Contains(markdownLink) && !suggestedLinks.ContainsValue(markdownLink)) | ||
{ | ||
suggestedLinks.Add(match.Value, suggestedLine); | ||
problems.Add( | ||
$"Glossary term should be link in {mdFile} line number {lineNumber}. Term is {match.Value}. Suggested link line is:\"{suggestedLine}\""); | ||
} | ||
} |
Check notice
Code scanning / CodeQL
Missed opportunity to use Where Note test
implicitly filters its target sequence
|
||
|
||
var startDate = ConvertAxisOverridetoDate(startDateOverride.Trim('\''), incriment); | ||
var endDate = ConvertAxisOverridetoDate(endDateOverride.Trim('\''), incriment); | ||
var startDate = ConvertAxisOverridetoDate(startDateOverride.Trim('\''), increment); |
Check warning
Code scanning / CodeQL
Dereferenced variable may be null Warning
startDateOverride
this
Variable
startDateOverride
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 18 days ago
To fix the problem, we need to ensure that startDateOverride
is not null
before it is dereferenced on line 305. The best way to fix this is to add a null check for startDateOverride
before it is used. If startDateOverride
is null
, we can either set a default value or handle the situation appropriately, such as by returning early from the method.
-
Copy modified lines R304-R305
@@ -303,2 +303,4 @@ | ||
|
||
if (startDateOverride == null || endDateOverride == null) | ||
throw new ArgumentNullException("startDateOverride or endDateOverride cannot be null during refresh."); | ||
|
var startDate = ConvertAxisOverridetoDate(startDateOverride.Trim('\''), incriment); | ||
var endDate = ConvertAxisOverridetoDate(endDateOverride.Trim('\''), incriment); | ||
var startDate = ConvertAxisOverridetoDate(startDateOverride.Trim('\''), increment); | ||
var endDate = ConvertAxisOverridetoDate(endDateOverride.Trim('\''), increment); |
Check warning
Code scanning / CodeQL
Dereferenced variable may be null Warning
endDateOverride
this
Variable
endDateOverride
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 18 days ago
To fix the problem, we need to ensure that endDateOverride
is not null before it is dereferenced. The best way to fix this without changing existing functionality is to add a null check for endDateOverride
before it is used on line 306. If endDateOverride
is null, we should handle it appropriately, possibly by skipping the relevant code block or providing a default value.
-
Copy modified line R306
@@ -305,3 +305,3 @@ | ||
var startDate = ConvertAxisOverridetoDate(startDateOverride.Trim('\''), increment); | ||
var endDate = ConvertAxisOverridetoDate(endDateOverride.Trim('\''), increment); | ||
var endDate = endDateOverride != null ? ConvertAxisOverridetoDate(endDateOverride.Trim('\''), increment) : DateTime.MaxValue; | ||
var rowsToDelete = _dt.Rows.Cast<DataRow>().Where(r => |
Update docs for PluginSecondaryConstraint replacement with SecondaryConstraint
Proposed Change
Fix some CodeQL warnings and one error flagged after #2133
Type of change
What types of changes does your code introduce? Tick all that apply.
Checklist
By opening this PR, I confirm that I have: