Skip to content

Commit

Permalink
feat: issue view options settings [IDE-212] (#456)
Browse files Browse the repository at this point in the history
* feat: issue view options settings

* chore: CHANGELOG

* refactor: make sure all products filter visible issues

* refactor: linting
  • Loading branch information
teodora-sandu authored May 15, 2024
1 parent 1d2b3b7 commit bfae2d6
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Snyk Security Changelog
## [2.7,1]
- Add the Issue View Options panel to the Snyk Security Settings.

## [2.6.1]
- Improve the validation of the custom endpoint and change the default to https://api.snyk.io.

Expand Down
22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,28 @@
"description": "Find and fix your IaC misconfigurations.",
"default": true
},
"snyk.issueViewOptions": {
"type": "object",
"default": {
"openIssues": true,
"ignoredIssues": true
},
"properties": {
"openIssues": {
"type": "boolean",
"description": "Open Issues",
"default": true
},
"ignoredIssues": {
"type": "boolean",
"description": "Ignored Issues",
"default": true
}
},
"additionalProperties": false,
"markdownDescription": "Ignores settings is currently an experimental feature. Please reach out to [support.snyk.io](https://support.snyk.io) for more details.\n\nShow the following issues:",
"scope": "window"
},
"snyk.severity": {
"type": "object",
"default": {
Expand Down
22 changes: 22 additions & 0 deletions src/snyk/common/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
IAC_ENABLED_SETTING,
OSS_ENABLED_SETTING,
SCANNING_MODE,
ISSUE_VIEW_OPTIONS_SETTING,
SEVERITY_FILTER_SETTING,
TRUSTED_FOLDERS,
YES_BACKGROUND_OSS_NOTIFICATION_SETTING,
Expand All @@ -35,6 +36,11 @@ export type FeaturesConfiguration = {
iacEnabled: boolean | undefined;
};

export interface IssueViewOptions {
ignoredIssues: boolean;
openIssues: boolean;
}

export interface SeverityFilter {
critical: boolean;
high: boolean;
Expand Down Expand Up @@ -101,6 +107,8 @@ export interface IConfiguration {

isFedramp: boolean;

issueViewOptions: IssueViewOptions;

severityFilter: SeverityFilter;

scanningMode: string | undefined;
Expand Down Expand Up @@ -399,6 +407,20 @@ export class Configuration implements IConfiguration {
);
}

get issueViewOptions(): IssueViewOptions {
const config = this.workspace.getConfiguration<IssueViewOptions>(
CONFIGURATION_IDENTIFIER,
this.getConfigName(ISSUE_VIEW_OPTIONS_SETTING),
);

return (
config ?? {
openIssues: true,
ignoredIssues: true,
}
);
}

get severityFilter(): SeverityFilter {
const config = this.workspace.getConfiguration<SeverityFilter>(
CONFIGURATION_IDENTIFIER,
Expand Down
1 change: 1 addition & 0 deletions src/snyk/common/constants/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const ADVANCED_AUTOMATIC_DEPENDENCY_MANAGEMENT = `${CONFIGURATION_IDENTIF
export const ADVANCED_CLI_PATH = `${CONFIGURATION_IDENTIFIER}.advanced.cliPath`;
export const ADVANCED_CUSTOM_LS_PATH = `${CONFIGURATION_IDENTIFIER}.advanced.languageServerPath`;

export const ISSUE_VIEW_OPTIONS_SETTING = `${CONFIGURATION_IDENTIFIER}.issueViewOptions`;
export const SEVERITY_FILTER_SETTING = `${CONFIGURATION_IDENTIFIER}.severity`;
export const TRUSTED_FOLDERS = `${CONFIGURATION_IDENTIFIER}.trustedFolders`;
export const SCANNING_MODE = `${CONFIGURATION_IDENTIFIER}.scanningMode`;
27 changes: 25 additions & 2 deletions src/snyk/common/views/issueTreeProvider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import _, { flatten } from 'lodash';
import * as vscode from 'vscode'; // todo: invert dependency
import { IConfiguration } from '../../common/configuration/configuration';
import { IConfiguration, IssueViewOptions } from '../../common/configuration/configuration';
import { Issue, IssueSeverity } from '../../common/languageServer/types';
import { messages as commonMessages } from '../../common/messages/analysisMessages';
import { IContextService } from '../../common/services/contextService';
Expand Down Expand Up @@ -119,6 +119,28 @@ export abstract class ProductIssueTreeProvider<T> extends AnalysisTreeNodeProvid
return false; // optionally overridden by products
}

filterVisibleIssues(issues: Issue<T>[]): Issue<T>[] {
return issues.filter(issue => this.isVisibleIssue(issue, this.configuration.issueViewOptions));
}

protected isVisibleIssue(issue: Issue<T>, issueViewOptions: IssueViewOptions) {
const { ignoredIssues: includeIgnoredIssues, openIssues: includeOpenIssues } = issueViewOptions;

// Show all issues
if (includeIgnoredIssues && includeOpenIssues) {
return true;
}

// Show issues based on options
if (includeIgnoredIssues) {
return issue.isIgnored;
}
if (includeOpenIssues) {
return !issue.isIgnored;
}
return false;
}

getResultNodes(): TreeNode[] {
const nodes: TreeNode[] = [];

Expand Down Expand Up @@ -151,8 +173,9 @@ export abstract class ProductIssueTreeProvider<T> extends AnalysisTreeNodeProvid
const fileSeverityCounts = this.initSeverityCounts();

const filteredIssues = this.filterIssues(fileIssues);
const visibleIssues = this.filterVisibleIssues(filteredIssues);

const issueNodes = filteredIssues.map(issue => {
const issueNodes = visibleIssues.map(issue => {
fileSeverityCounts[issue.severity] += 1;
folderVulnCount++;

Expand Down
4 changes: 4 additions & 0 deletions src/snyk/common/watchers/configurationWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
CODE_SECURITY_ENABLED_SETTING,
IAC_ENABLED_SETTING,
ADVANCED_ORGANIZATION,
ISSUE_VIEW_OPTIONS_SETTING,
OSS_ENABLED_SETTING,
SEVERITY_FILTER_SETTING,
TRUSTED_FOLDERS,
Expand Down Expand Up @@ -42,6 +43,8 @@ class ConfigurationWatcher implements IWatcher {
return extension.viewManagerService.refreshAllCodeAnalysisViews();
} else if (key === IAC_ENABLED_SETTING) {
return extension.viewManagerService.refreshIacView();
} else if (key === ISSUE_VIEW_OPTIONS_SETTING) {
extension.viewManagerService.refreshAllViews();
} else if (key === SEVERITY_FILTER_SETTING) {
return extension.viewManagerService.refreshAllViews();
} else if (key === ADVANCED_CUSTOM_ENDPOINT) {
Expand Down Expand Up @@ -81,6 +84,7 @@ class ConfigurationWatcher implements IWatcher {
ADVANCED_CUSTOM_ENDPOINT,
ADVANCED_CUSTOM_LS_PATH,
TRUSTED_FOLDERS,
ISSUE_VIEW_OPTIONS_SETTING,
].find(config => event.affectsConfiguration(config));

if (change) {
Expand Down
28 changes: 15 additions & 13 deletions src/snyk/snykOss/providers/ossVulnerabilityTreeProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,21 @@ export default class OssIssueTreeProvider extends ProductIssueTreeProvider<OssIs

const filteredIssues = this.filterIssues(uniqueIssues);

const vulnerabilityNodes: TreeNode[] = filteredIssues.map((issue: Issue<OssIssueData>) => {
fileSeverityCounts[issue.severity] += 1;
folderVulnCount++;

return new TreeNode({
text: `${issue.additionalData.packageName}@${issue.additionalData.version} - ${issue.title}`,
icon: ProductIssueTreeProvider.getSeverityIcon(issue.severity),
internal: {
severity: ProductIssueTreeProvider.getSeverityComparatorIndex(issue.severity),
},
command: this.getOpenIssueCommand(issue, folderPath, '', filteredIssues),
});
});
const vulnerabilityNodes: TreeNode[] = this.filterVisibleIssues(filteredIssues).map(
(issue: Issue<OssIssueData>) => {
fileSeverityCounts[issue.severity] += 1;
folderVulnCount++;

return new TreeNode({
text: `${issue.additionalData.packageName}@${issue.additionalData.version} - ${issue.title}`,
icon: ProductIssueTreeProvider.getSeverityIcon(issue.severity),
internal: {
severity: ProductIssueTreeProvider.getSeverityComparatorIndex(issue.severity),
},
command: this.getOpenIssueCommand(issue, folderPath, '', filteredIssues),
});
},
);

if (vulnerabilityNodes.length === 0) {
continue;
Expand Down

0 comments on commit bfae2d6

Please sign in to comment.