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

feat: fix lint #255

Merged
merged 8 commits into from
Feb 7, 2025
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
7 changes: 7 additions & 0 deletions plugin/.eclipse-pmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<eclipse-pmd xmlns="http://acanda.ch/eclipse-pmd/0.8" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://acanda.ch/eclipse-pmd/0.8 http://acanda.ch/eclipse-pmd/eclipse-pmd-0.8.xsd">
<analysis enabled="true" />
<rulesets>
<ruleset name="Custom Rules" ref="src/main/resources/pmd-ruleset.xml" refcontext="project" />
</rulesets>
</eclipse-pmd>
8 changes: 8 additions & 0 deletions plugin/.pmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<pmd>
<useProjectRuleSet>true</useProjectRuleSet>
<ruleSetFile>src/main/resources/pmd-ruleset.xml</ruleSetFile>
<includeDerivedFiles>false</includeDerivedFiles>
<violationsAsErrors>true</violationsAsErrors>
<fullBuildEnabled>true</fullBuildEnabled>
</pmd>
429 changes: 429 additions & 0 deletions plugin/.ruleset

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

public class SnykStartup implements IStartup {
private static LsRuntimeEnvironment runtimeEnvironment;
private static SnykToolView snykToolView = null;
private static SnykToolView snykToolView;
private static boolean downloading = true;
private static ILog logger;

Expand Down Expand Up @@ -116,7 +116,7 @@ private boolean downloadLS() {
basicFileAttributes = Files.readAttributes(lsFile.toPath(), BasicFileAttributes.class);
Instant lastModified = basicFileAttributes.lastModifiedTime().toInstant();
boolean needsUpdate = lastModified.isBefore(Instant.now().minus(4, ChronoUnit.DAYS))
|| !Preferences.getInstance().getLspVersion().equals(LsBinaries.REQUIRED_LS_PROTOCOL_VERSION);
|| !LsBinaries.REQUIRED_LS_PROTOCOL_VERSION.equals(Preferences.getInstance().getLspVersion());
logger.info(
String.format("LS: Needs update? %s. Required LSP version=%s, actual version=%s", needsUpdate,
LsBinaries.REQUIRED_LS_PROTOCOL_VERSION, Preferences.getInstance().getLspVersion()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,48 @@

import java.util.Map;

public interface ProductConstants {
String SCAN_STATE_IN_PROGRESS = "inProgress";
String SCAN_STATE_SUCCESS = "success";
String SCAN_STATE_ERROR = "error";

String SCAN_PARAMS_OSS = "oss";
String SCAN_PARAMS_CODE = "code";
String SCAN_PARAMS_IAC = "iac";

String DIAGNOSTIC_SOURCE_SNYK_OSS = "Snyk Open Source";
String DIAGNOSTIC_SOURCE_SNYK_CODE = "Snyk Code";
String DIAGNOSTIC_SOURCE_SNYK_IAC = "Snyk IaC";

String DISPLAYED_OSS = "Snyk Open Source";
String DISPLAYED_CODE_SECURITY = "Code Security";
String DISPLAYED_CODE_QUALITY = "Code Quality";
String DISPLAYED_IAC = "Configuration";

String SEVERITY_CRITICAL = "critical";
String SEVERITY_HIGH = "high";
String SEVERITY_MEDIUM = "medium";
String SEVERITY_LOW = "low";

String FILTERABLE_ISSUE_OPEN_SOURCE = "Open Source";
String FILTERABLE_ISSUE_CODE_SECURITY = "Code Security";
String FILTERABLE_ISSUE_CODE_QUALITY = "Code Quality";
String FILTERABLE_ISSUE_INFRASTRUCTURE_AS_CODE = "Infrastructure As Code";

Map<String, String> FILTERABLE_ISSUE_TYPE_TO_DISPLAY = Map.of(FILTERABLE_ISSUE_CODE_QUALITY, DISPLAYED_CODE_QUALITY,
FILTERABLE_ISSUE_CODE_SECURITY, DISPLAYED_CODE_SECURITY, FILTERABLE_ISSUE_INFRASTRUCTURE_AS_CODE,
DISPLAYED_IAC, FILTERABLE_ISSUE_OPEN_SOURCE, DISPLAYED_OSS);

Map<String, String> LSP_SOURCE_TO_SCAN_PARAMS = Map.of(DIAGNOSTIC_SOURCE_SNYK_CODE, SCAN_PARAMS_CODE,
DIAGNOSTIC_SOURCE_SNYK_IAC, SCAN_PARAMS_IAC, DIAGNOSTIC_SOURCE_SNYK_OSS, SCAN_PARAMS_OSS);

// code cannot be mapped easily
Map<String, String> SCAN_PARAMS_TO_DISPLAYED = Map.of(SCAN_PARAMS_OSS, DISPLAYED_OSS, SCAN_PARAMS_IAC,
DISPLAYED_IAC);
public final class ProductConstants {

public static final String SCAN_STATE_IN_PROGRESS = "inProgress";
public static final String SCAN_STATE_SUCCESS = "success";
public static final String SCAN_STATE_ERROR = "error";

public static final String SCAN_PARAMS_OSS = "oss";
public static final String SCAN_PARAMS_CODE = "code";
public static final String SCAN_PARAMS_IAC = "iac";

public static final String DIAGNOSTIC_SOURCE_SNYK_OSS = "Snyk Open Source";
public static final String DIAGNOSTIC_SOURCE_SNYK_CODE = "Snyk Code";
public static final String DIAGNOSTIC_SOURCE_SNYK_IAC = "Snyk IaC";

public static final String DISPLAYED_OSS = "Snyk Open Source";
public static final String DISPLAYED_CODE_SECURITY = "Code Security";
public static final String DISPLAYED_CODE_QUALITY = "Code Quality";
public static final String DISPLAYED_IAC = "Configuration";

public static final String SEVERITY_CRITICAL = "critical";
public static final String SEVERITY_HIGH = "high";
public static final String SEVERITY_MEDIUM = "medium";
public static final String SEVERITY_LOW = "low";

public static final String FILTERABLE_ISSUE_OPEN_SOURCE = "Open Source";
public static final String FILTERABLE_ISSUE_CODE_SECURITY = "Code Security";
public static final String FILTERABLE_ISSUE_CODE_QUALITY = "Code Quality";
public static final String FILTERABLE_ISSUE_INFRASTRUCTURE_AS_CODE = "Infrastructure As Code";

public static final Map<String, String> FILTERABLE_ISSUE_TYPE_TO_DISPLAY = Map.of(
FILTERABLE_ISSUE_CODE_QUALITY, DISPLAYED_CODE_QUALITY,
FILTERABLE_ISSUE_CODE_SECURITY, DISPLAYED_CODE_SECURITY,
FILTERABLE_ISSUE_INFRASTRUCTURE_AS_CODE, DISPLAYED_IAC,
FILTERABLE_ISSUE_OPEN_SOURCE, DISPLAYED_OSS);

public static final Map<String, String> LSP_SOURCE_TO_SCAN_PARAMS = Map.of(
DIAGNOSTIC_SOURCE_SNYK_CODE, SCAN_PARAMS_CODE,
DIAGNOSTIC_SOURCE_SNYK_IAC, SCAN_PARAMS_IAC,
DIAGNOSTIC_SOURCE_SNYK_OSS, SCAN_PARAMS_OSS);

// code cannot be mapped easily
public static final Map<String, String> SCAN_PARAMS_TO_DISPLAYED = Map.of(
SCAN_PARAMS_OSS, DISPLAYED_OSS,
SCAN_PARAMS_IAC, DISPLAYED_IAC);
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ private String getThemeScript() {

@Override
public String replaceCssVariables(String html) {
html = super.replaceCssVariables(html);
String htmlStyled = super.replaceCssVariables(html);

// Replace CSS variables with actual color values
html = html.replace("var(--example-line-removed-color)", super.getColorAsHex("DELETION_COLOR", "#ff0000"));
html = html.replace("var(--example-line-added-color)", super.getColorAsHex("ADDITION_COLOR", "#00ff00"));
htmlStyled = htmlStyled.replace("var(--example-line-removed-color)", super.getColorAsHex("DELETION_COLOR", "#ff0000"));
htmlStyled = htmlStyled.replace("var(--example-line-added-color)", super.getColorAsHex("ADDITION_COLOR", "#00ff00"));

return html;
return htmlStyled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
import io.snyk.eclipse.plugin.domain.ProductConstants;

public class HtmlProviderFactory {
public static BaseHtmlProvider GetHtmlProvider(String product)
{
switch (product) {
case ProductConstants.DISPLAYED_CODE_SECURITY:
case ProductConstants.DISPLAYED_CODE_QUALITY:
return CodeHtmlProvider.getInstance();
case ProductConstants.DISPLAYED_OSS:
return OssHtmlProvider.getInstance();
case ProductConstants.DISPLAYED_IAC:
return IacHtmlProvider.getInstance();
}
return null;
}

public static BaseHtmlProvider GetHtmlProvider(String product) {
switch (product) {
case ProductConstants.DISPLAYED_CODE_SECURITY:
case ProductConstants.DISPLAYED_CODE_QUALITY:
return CodeHtmlProvider.getInstance();
case ProductConstants.DISPLAYED_OSS:
return OssHtmlProvider.getInstance();
case ProductConstants.DISPLAYED_IAC:
return IacHtmlProvider.getInstance();
default:
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ public LabelFieldEditor(String value, Composite parent) {

// Adjusts the field editor to be displayed correctly
// for the given number of columns.
@Override
protected void adjustForNumColumns(int numColumns) {
((GridData) label.getLayoutData()).horizontalSpan = numColumns;
}

// Fills the field editor's controls into the given parent.
@Override
protected void doFillIntoGrid(Composite parent, int numColumns) {
label = getLabelControl(parent);

Expand All @@ -39,17 +41,21 @@ protected void doFillIntoGrid(Composite parent, int numColumns) {
}

// Returns the number of controls in the field editor.
@Override
public int getNumberOfControls() {
return 1;
}

// Labels do not persist any preferences, so these methods are empty.
@Override
protected void doLoad() {
}

@Override
protected void doLoadDefault() {
}


@Override
protected void doStore() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public FolderConfigsParam updateFolderConfigs() {

for (var project : openProjects) {
Path path = ResourceUtils.getFullPath(project);
IScopeContext projectScope = new ProjectScope(project);
//Linter does not like when new objects are created in loops, but here we do want to create new ProjectScopes in the loop.
IScopeContext projectScope = new ProjectScope(project); //NOPMD,
var projectSettings = projectScope.getNode(Activator.PLUGIN_ID);
String additionalParams = projectSettings.get(ProjectPropertyPage.SNYK_ADDITIONAL_PARAMETERS, "");
var additionalParamsList = Arrays.asList(additionalParams.split(" "));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
public class ScanWorkspaceFolderHandler extends AbstractHandler {

@SuppressWarnings("restriction")
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@

public class ScanWorkspaceMenuHandler extends AbstractHandler {

public Object execute(ExecutionEvent event) throws ExecutionException {
CompletableFuture.runAsync(() -> {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
CompletableFuture.runAsync(() -> {
SnykExtendedLanguageClient.getInstance().triggerScan(null);
});
return null;
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Issue getIssue() {
return issue;
}

public void setIssue(Issue issue) {
public final void setIssue(Issue issue) {
this.issue = issue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import io.snyk.eclipse.plugin.preferences.Preferences;
import io.snyk.eclipse.plugin.views.snyktoolview.TreeFilterManager;

@SuppressWarnings("rawtypes")
@SuppressWarnings({"rawtypes"})
public abstract class BaseFilter {
protected Preferences preferences = Preferences.getInstance();
protected TreeFilterManager filterManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
import io.snyk.eclipse.plugin.views.snyktoolview.TreeFilterManager;

public class BaseHandler extends AbstractHandler implements IElementUpdater, IHandlerCommands {
protected ImageDescriptor iconEnabled = null;
protected ImageDescriptor iconDisabled = null;
protected String preferenceKey = null;
protected ImageDescriptor iconEnabled;
protected ImageDescriptor iconDisabled;
protected String preferenceKey;

public BaseHandler() {
iconEnabled = SnykIcons.ENABLED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,29 @@ public void addPages() {
setNeedsProgressMonitor(true);
}

@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
this.workbench = workbench;
this.selection = selection;
}

@Override
public boolean canFinish() {
if (this.getContainer().getCurrentPage() == authenticatePage) {
if (this.getContainer().getCurrentPage().equals(authenticatePage)) {
return true;
}
return false;
}

@Override
public boolean performCancel() {
model.resetPreferences();
return true;
}

@Override
public boolean performFinish() {
new Job("Applying configuration from wizard...") {
new Job("Applying configuration from wizard...") {
@Override
protected IStatus run(IProgressMonitor monitor) {
monitor.beginTask("starting", 60);
Expand All @@ -84,7 +88,7 @@ protected IStatus run(IProgressMonitor monitor) {
monitor.worked(20);
monitor.subTask("trusting workspace folders...");
var projects = ResourceUtils.getAccessibleTopLevelProjects();
if (projects != null && projects.size()>0) {
if (projects != null && !projects.isEmpty()) {
lc.trustWorkspaceFolders();
}
monitor.worked(20);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,28 @@
import org.eclipse.ui.IWorkbenchPart;

public class SnykWizardAction implements IObjectActionDelegate {
IWorkbenchPart part;
ISelection selection;

public void setActivePart(IAction action, IWorkbenchPart part) {
this.part = part;
}

public void run(IAction action) {
// Instantiates and initialises the wizard
SnykWizard wizard = new SnykWizard();
if ((selection instanceof IStructuredSelection) || (selection == null))
wizard.init(part.getSite().getWorkbenchWindow().getWorkbench(),
(IStructuredSelection)selection);

// Instantiates the wizard container with the wizard and opens it
WizardDialog dialog = new WizardDialog(part.getSite().getShell(), wizard);
dialog.open();
}

public void selectionChanged(IAction action, ISelection selection) {
this.selection = selection;
}
IWorkbenchPart part;
ISelection selection;

@Override
public void setActivePart(IAction action, IWorkbenchPart part) {
this.part = part;
}

@Override
public void run(IAction action) {
// Instantiates and initialises the wizard
SnykWizard wizard = new SnykWizard();
if ((selection instanceof IStructuredSelection) || (selection == null))
wizard.init(part.getSite().getWorkbenchWindow().getWorkbench(), (IStructuredSelection) selection);

// Instantiates the wizard container with the wizard and opens it
WizardDialog dialog = new WizardDialog(part.getSite().getShell(), wizard);
dialog.open();
}

@Override
public void selectionChanged(IAction action, ISelection selection) {
this.selection = selection;
}
}
Loading