Skip to content

Commit 79d7a5f

Browse files
authored
CM-48120 - Add detection sorting by line number in addition to severity (#40)
1 parent 0eeeb71 commit 79d7a5f

23 files changed

+54
-28
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
## [Unreleased]
66

7+
## [1.10.0] - 2025-05-14
8+
9+
- Add detection sorting by line number in addition to severity
10+
711
## [1.9.0] - 2025-02-24
812

913
- Add tree view filtering by severity
@@ -85,6 +89,8 @@
8589

8690
The first public release of the extension.
8791

92+
[1.10.0]: https://github.com/cycodehq/visual-studio-extension/releases/tag/v1.10.0
93+
8894
[1.9.0]: https://github.com/cycodehq/visual-studio-extension/releases/tag/v1.9.0
8995

9096
[1.8.0]: https://github.com/cycodehq/visual-studio-extension/releases/tag/v1.8.0
@@ -119,4 +125,4 @@ The first public release of the extension.
119125

120126
[1.0.0]: https://github.com/cycodehq/visual-studio-extension/releases/tag/v1.0.0
121127

122-
[Unreleased]: https://github.com/cycodehq/visual-studio-extension/compare/v1.9.0...HEAD
128+
[Unreleased]: https://github.com/cycodehq/visual-studio-extension/compare/v1.10.0...HEAD

global.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "8.0.404",
4-
"rollForward": "latestFeature"
3+
"version": "8.0.408",
4+
"rollForward": "disable"
55
}
66
}

src/extension/Cycode.VisualStudio.Extension.14.0-16.0/source.extension.vsixmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
33
<Metadata>
4-
<Identity Id="Cycode.7e1a0714-9b3b-4e0e-9c0a-d23fb20ab86e" Version="1.9.0" Language="en-US" Publisher="cycodehq" />
4+
<Identity Id="Cycode.7e1a0714-9b3b-4e0e-9c0a-d23fb20ab86e" Version="1.10.0" Language="en-US" Publisher="cycodehq" />
55
<DisplayName>Cycode</DisplayName>
66
<Description xml:space="preserve">Cycode for Visual Studio IDE</Description>
77
<MoreInfo>https://github.com/cycodehq/visual-studio-extension</MoreInfo>

src/extension/Cycode.VisualStudio.Extension.17.0/source.extension.vsixmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
33
<Metadata>
4-
<Identity Id="Cycode.f2c5020e-67a2-46f8-a888-609412fd59db" Version="1.9.0" Language="en-US" Publisher="cycodehq" />
4+
<Identity Id="Cycode.f2c5020e-67a2-46f8-a888-609412fd59db" Version="1.10.0" Language="en-US" Publisher="cycodehq" />
55
<DisplayName>Cycode</DisplayName>
66
<Description xml:space="preserve">Cycode for Visual Studio IDE</Description>
77
<MoreInfo>https://github.com/cycodehq/visual-studio-extension</MoreInfo>

src/extension/Cycode.VisualStudio.Extension.Shared/Cli/DTO/ScanResult/DetectionDetailsBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
public abstract class DetectionDetailsBase {
44
public abstract string GetFilePath();
5+
// This method returns a 1-indexed line number
6+
public abstract int GetLineNumber();
57
}

src/extension/Cycode.VisualStudio.Extension.Shared/Cli/DTO/ScanResult/Iac/IacDetection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ public override string GetFormattedTitle() {
3131
}
3232

3333
public override string GetFormattedNodeTitle() {
34-
return $"line {DetectionDetails.LineInFile + 1}: {GetFormattedMessage()}";
34+
return $"line {DetectionDetails.GetLineNumber()}: {GetFormattedMessage()}";
3535
}
3636
}

src/extension/Cycode.VisualStudio.Extension.Shared/Cli/DTO/ScanResult/Iac/IacDetectionDetails.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,8 @@ public class IacDetectionDetails : DetectionDetailsBase {
3535
public override string GetFilePath() {
3636
return FileName;
3737
}
38+
39+
public override int GetLineNumber() {
40+
return LineInFile;
41+
}
3842
}

src/extension/Cycode.VisualStudio.Extension.Shared/Cli/DTO/ScanResult/Sast/SastDetection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ public override string GetFormattedTitle() {
3131
}
3232

3333
public override string GetFormattedNodeTitle() {
34-
return $"line {DetectionDetails.LineInFile}: {GetFormattedMessage()}";
34+
return $"line {DetectionDetails.GetLineNumber()}: {GetFormattedMessage()}";
3535
}
3636
}

src/extension/Cycode.VisualStudio.Extension.Shared/Cli/DTO/ScanResult/Sast/SastDetectionDetails.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,8 @@ public class SastDetectionDetails : DetectionDetailsBase {
4646
public override string GetFilePath() {
4747
return FilePath;
4848
}
49+
50+
public override int GetLineNumber() {
51+
return LineInFile;
52+
}
4953
}

src/extension/Cycode.VisualStudio.Extension.Shared/Cli/DTO/ScanResult/Sca/ScaDetection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ public override string GetFormattedTitle() {
3232
}
3333

3434
public override string GetFormattedNodeTitle() {
35-
return $"line {DetectionDetails.LineInFile}: {GetFormattedTitle()}";
35+
return $"line {DetectionDetails.GetLineNumber()}: {GetFormattedTitle()}";
3636
}
3737
}

src/extension/Cycode.VisualStudio.Extension.Shared/Cli/DTO/ScanResult/Sca/ScaDetectionDetails.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,8 @@ public class ScaDetectionDetails : DetectionDetailsBase {
3737
public override string GetFilePath() {
3838
return FileName;
3939
}
40+
41+
public override int GetLineNumber() {
42+
return LineInFile;
43+
}
4044
}

src/extension/Cycode.VisualStudio.Extension.Shared/Cli/DTO/ScanResult/Secret/SecretDetection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ public override string GetFormattedTitle() {
3131
}
3232

3333
public override string GetFormattedNodeTitle() {
34-
return $"line {DetectionDetails.Line + 1}: a hardcoded {Type} is used";
34+
return $"line {DetectionDetails.GetLineNumber()}: a hardcoded {Type} is used";
3535
}
3636
}

src/extension/Cycode.VisualStudio.Extension.Shared/Cli/DTO/ScanResult/Secret/SecretDetectionDetails.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,8 @@ public class SecretDetectionDetails : DetectionDetailsBase {
4040
public override string GetFilePath() {
4141
return $"{FilePath}{FileName}";
4242
}
43+
44+
public override int GetLineNumber() {
45+
return Line + 1; // 1-indexed
46+
}
4347
}

src/extension/Cycode.VisualStudio.Extension.Shared/Components/TreeView/CycodeTreeViewControl.xaml.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ private void OnSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs
4444
case SecretDetectionNode secretDetectionNode: {
4545
SecretDetection detection = secretDetectionNode.Detection;
4646
filePath = detection.DetectionDetails.GetFilePath();
47-
line = detection.DetectionDetails.Line + 1;
47+
line = detection.DetectionDetails.GetLineNumber();
4848
_toolWindowMessengerService.Send(
4949
new MessageEventArgs(MessengerCommand.LoadSecretViolationCardControl, detection)
5050
);
@@ -53,7 +53,7 @@ private void OnSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs
5353
case ScaDetectionNode scaDetectionNode: {
5454
ScaDetection detection = scaDetectionNode.Detection;
5555
filePath = detection.DetectionDetails.GetFilePath();
56-
line = detection.DetectionDetails.LineInFile;
56+
line = detection.DetectionDetails.GetLineNumber();
5757
_toolWindowMessengerService.Send(
5858
new MessageEventArgs(MessengerCommand.LoadScaViolationCardControl, detection)
5959
);
@@ -62,7 +62,7 @@ private void OnSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs
6262
case IacDetectionNode iacDetectionNode: {
6363
IacDetection detection = iacDetectionNode.Detection;
6464
filePath = detection.DetectionDetails.GetFilePath();
65-
line = detection.DetectionDetails.LineInFile + 1;
65+
line = detection.DetectionDetails.GetLineNumber();
6666
_toolWindowMessengerService.Send(
6767
new MessageEventArgs(MessengerCommand.LoadIacViolationCardControl, detection)
6868
);
@@ -71,7 +71,7 @@ private void OnSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs
7171
case SastDetectionNode sastDetectionNode: {
7272
SastDetection detection = sastDetectionNode.Detection;
7373
filePath = detection.DetectionDetails.GetFilePath();
74-
line = detection.DetectionDetails.LineInFile;
74+
line = detection.DetectionDetails.GetLineNumber();
7575
_toolWindowMessengerService.Send(
7676
new MessageEventArgs(MessengerCommand.LoadSastViolationCardControl, detection)
7777
);
@@ -144,14 +144,11 @@ Func<DetectionBase, BaseNode> createNodeCallback
144144
List<DetectionBase> severityFilteredDetections = detections
145145
.Where(detection => !enabledSeverityFilters.Contains(detection.Severity.ToLower()))
146146
.ToList();
147-
List<DetectionBase> sortedDetections = severityFilteredDetections
148-
.OrderByDescending(detection => GetSeverityWeight(detection.Severity))
149-
.ToList();
150147
IEnumerable<IGrouping<string, DetectionBase>> detectionsByFile =
151-
sortedDetections.GroupBy(detection => detection.GetDetectionDetails().GetFilePath());
148+
severityFilteredDetections.GroupBy(detection => detection.GetDetectionDetails().GetFilePath());
152149

153150
ScanTypeNode scanTypeNode = RootNodesManager.GetScanTypeNode(scanType);
154-
scanTypeNode.Summary = GetRootNodeSummary(sortedDetections);
151+
scanTypeNode.Summary = GetRootNodeSummary(severityFilteredDetections);
155152

156153
foreach (IGrouping<string, DetectionBase> detectionsInFile in detectionsByFile) {
157154
string filePath = detectionsInFile.Key;
@@ -162,7 +159,12 @@ Func<DetectionBase, BaseNode> createNodeCallback
162159
Icon = ExtensionIcons.GetFileIconPath(filePath)
163160
};
164161

165-
foreach (DetectionBase detection in detectionsInFile) fileNode.Items.Add(createNodeCallback(detection));
162+
List<DetectionBase> sortedDetectionsInFile = detectionsInFile
163+
.OrderByDescending(detection => GetSeverityWeight(detection.Severity))
164+
.ThenBy(detection => detection.GetDetectionDetails().GetLineNumber())
165+
.ToList();
166+
167+
foreach (DetectionBase detection in sortedDetectionsInFile) fileNode.Items.Add(createNodeCallback(detection));
166168

167169
scanTypeNode.Items.Add(fileNode);
168170
}

src/extension/Cycode.VisualStudio.Extension.Shared/Services/ErrorList/TaskCreators/IacErrorTaskCreator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static List<ErrorTask> CreateErrorTasks(List<IacDetection> detections) {
1010

1111
errorTasks.AddRange(detections.Select(detection => new ErrorTask {
1212
Text = $"Cycode: {detection.GetFormattedTitle()}",
13-
Line = detection.DetectionDetails.LineInFile,
13+
Line = detection.DetectionDetails.GetLineNumber() - 1,
1414
Document = detection.DetectionDetails.GetFilePath(),
1515
Category = TaskCategory.User,
1616
ErrorCategory = ErrorCategoryUtilities.GetTaskErrorCategory(detection.Severity),

src/extension/Cycode.VisualStudio.Extension.Shared/Services/ErrorList/TaskCreators/SastErrorTaskCreator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static List<ErrorTask> CreateErrorTasks(List<SastDetection> detections) {
1010

1111
errorTasks.AddRange(detections.Select(detection => new ErrorTask {
1212
Text = $"Cycode: {detection.GetFormattedTitle()}",
13-
Line = detection.DetectionDetails.LineInFile - 1,
13+
Line = detection.DetectionDetails.GetLineNumber() - 1,
1414
Document = detection.DetectionDetails.GetFilePath(),
1515
Category = TaskCategory.User,
1616
ErrorCategory = ErrorCategoryUtilities.GetTaskErrorCategory(detection.Severity),

src/extension/Cycode.VisualStudio.Extension.Shared/Services/ErrorList/TaskCreators/ScaErrorTaskCreator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static List<ErrorTask> CreateErrorTasks(List<ScaDetection> detections) {
1010

1111
errorTasks.AddRange(detections.Select(detection => new ErrorTask {
1212
Text = $"Cycode: {detection.GetFormattedTitle()}",
13-
Line = detection.DetectionDetails.LineInFile - 1,
13+
Line = detection.DetectionDetails.GetLineNumber() - 1,
1414
Document = detection.DetectionDetails.GetFilePath(),
1515
Category = TaskCategory.User,
1616
ErrorCategory = ErrorCategoryUtilities.GetTaskErrorCategory(detection.Severity),

src/extension/Cycode.VisualStudio.Extension.Shared/Services/ErrorList/TaskCreators/SecretsErrorTaskCreator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static List<ErrorTask> CreateErrorTasks(List<SecretDetection> detections)
1010

1111
errorTasks.AddRange(detections.Select(detection => new ErrorTask {
1212
Text = $"Cycode: {detection.GetFormattedTitle()}",
13-
Line = detection.DetectionDetails.Line,
13+
Line = detection.DetectionDetails.GetLineNumber() - 1,
1414
Document = detection.DetectionDetails.GetFilePath(),
1515
Category = TaskCategory.User,
1616
ErrorCategory = ErrorCategoryUtilities.GetTaskErrorCategory(detection.Severity),

src/extension/Cycode.VisualStudio.Extension.Shared/Services/ErrorTagger/TagSpansCreators/IacTagSpansCreator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static List<ITagSpan<DetectionTag>> CreateTagSpans(ITextSnapshot snapshot
2323
.ToList();
2424

2525
tagSpans.AddRange(from detection in detections
26-
let line = detection.DetectionDetails.LineInFile
26+
let line = detection.DetectionDetails.GetLineNumber() - 1
2727
let startSnapshotPoint = snapshot.GetLineFromLineNumber(line).Start
2828
let endSnapshotPoint = snapshot.GetLineFromLineNumber(line).End
2929
let snapshotSpan = new SnapshotSpan(startSnapshotPoint, endSnapshotPoint)

src/extension/Cycode.VisualStudio.Extension.Shared/Services/ErrorTagger/TagSpansCreators/SastTagSpansCreator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static List<ITagSpan<DetectionTag>> CreateTagSpans(ITextSnapshot snapshot
2323
.ToList();
2424

2525
tagSpans.AddRange(from detection in detections
26-
let line = detection.DetectionDetails.LineInFile - 1
26+
let line = detection.DetectionDetails.GetLineNumber() - 1
2727
let startSnapshotPoint = snapshot.GetLineFromLineNumber(line).Start
2828
let endSnapshotPoint = snapshot.GetLineFromLineNumber(line).End
2929
let snapshotSpan = new SnapshotSpan(startSnapshotPoint, endSnapshotPoint)

src/extension/Cycode.VisualStudio.Extension.Shared/Services/ErrorTagger/TagSpansCreators/ScaTagSpansCreator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static List<ITagSpan<DetectionTag>> CreateTagSpans(ITextSnapshot snapshot
2323
.ToList();
2424

2525
tagSpans.AddRange(from detection in detections
26-
let line = detection.DetectionDetails.LineInFile - 1
26+
let line = detection.DetectionDetails.GetLineNumber() - 1
2727
let length = snapshot.GetLineFromLineNumber(line).Length
2828
let startSnapshotPoint = snapshot.GetLineFromLineNumber(line).Start.Add(0)
2929
let endSnapshotPoint = snapshot.GetLineFromLineNumber(line).Start.Add(length)

src/extension/Cycode.VisualStudio.Extension.Shared/Services/ErrorTagger/TagSpansCreators/SecretsTagSpansCreator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static List<ITagSpan<DetectionTag>> CreateTagSpans(ITextSnapshot snapshot
2323
.ToList();
2424

2525
tagSpans.AddRange(from detection in detections
26-
let line = detection.DetectionDetails.Line
26+
let line = detection.DetectionDetails.GetLineNumber() - 1
2727
let column = ErrorTaggerUtilities.CalculateColumn(snapshot, detection.DetectionDetails.StartPosition)
2828
let length = detection.DetectionDetails.Length
2929
let startSnapshotPoint = snapshot.GetLineFromLineNumber(line).Start.Add(column)

src/extension/Cycode.VisualStudio.Extension.Shared/source.extension.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ namespace Cycode.VisualStudio.Extension.Shared;
33
internal sealed class Vsix {
44
public const string Name = "Cycode";
55
public const string Description = "Cycode for Visual Studio IDE";
6-
public const string Version = "1.9.0";
6+
public const string Version = "1.10.0";
77
}

0 commit comments

Comments
 (0)