Skip to content

Commit 67e3473

Browse files
authored
Merge pull request #255 from snyk/feat/fix-lint
feat: fix lint
2 parents 3b0f7df + b46b8ce commit 67e3473

29 files changed

+723
-240
lines changed

plugin/.eclipse-pmd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<analysis enabled="true" />
4+
<rulesets>
5+
<ruleset name="Custom Rules" ref="src/main/resources/pmd-ruleset.xml" refcontext="project" />
6+
</rulesets>
7+
</eclipse-pmd>

plugin/.pmd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<pmd>
3+
<useProjectRuleSet>true</useProjectRuleSet>
4+
<ruleSetFile>src/main/resources/pmd-ruleset.xml</ruleSetFile>
5+
<includeDerivedFiles>false</includeDerivedFiles>
6+
<violationsAsErrors>true</violationsAsErrors>
7+
<fullBuildEnabled>true</fullBuildEnabled>
8+
</pmd>

plugin/.ruleset

Lines changed: 429 additions & 0 deletions
Large diffs are not rendered by default.

plugin/src/main/java/io/snyk/eclipse/plugin/SnykStartup.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
public class SnykStartup implements IStartup {
3737
private static LsRuntimeEnvironment runtimeEnvironment;
38-
private static SnykToolView snykToolView = null;
38+
private static SnykToolView snykToolView;
3939
private static boolean downloading = true;
4040
private static ILog logger;
4141

@@ -116,7 +116,7 @@ private boolean downloadLS() {
116116
basicFileAttributes = Files.readAttributes(lsFile.toPath(), BasicFileAttributes.class);
117117
Instant lastModified = basicFileAttributes.lastModifiedTime().toInstant();
118118
boolean needsUpdate = lastModified.isBefore(Instant.now().minus(4, ChronoUnit.DAYS))
119-
|| !Preferences.getInstance().getLspVersion().equals(LsBinaries.REQUIRED_LS_PROTOCOL_VERSION);
119+
|| !LsBinaries.REQUIRED_LS_PROTOCOL_VERSION.equals(Preferences.getInstance().getLspVersion());
120120
logger.info(
121121
String.format("LS: Needs update? %s. Required LSP version=%s, actual version=%s", needsUpdate,
122122
LsBinaries.REQUIRED_LS_PROTOCOL_VERSION, Preferences.getInstance().getLspVersion()));

plugin/src/main/java/io/snyk/eclipse/plugin/domain/ProductConstants.java

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,48 @@
22

33
import java.util.Map;
44

5-
public interface ProductConstants {
6-
String SCAN_STATE_IN_PROGRESS = "inProgress";
7-
String SCAN_STATE_SUCCESS = "success";
8-
String SCAN_STATE_ERROR = "error";
9-
10-
String SCAN_PARAMS_OSS = "oss";
11-
String SCAN_PARAMS_CODE = "code";
12-
String SCAN_PARAMS_IAC = "iac";
13-
14-
String DIAGNOSTIC_SOURCE_SNYK_OSS = "Snyk Open Source";
15-
String DIAGNOSTIC_SOURCE_SNYK_CODE = "Snyk Code";
16-
String DIAGNOSTIC_SOURCE_SNYK_IAC = "Snyk IaC";
17-
18-
String DISPLAYED_OSS = "Snyk Open Source";
19-
String DISPLAYED_CODE_SECURITY = "Code Security";
20-
String DISPLAYED_CODE_QUALITY = "Code Quality";
21-
String DISPLAYED_IAC = "Configuration";
22-
23-
String SEVERITY_CRITICAL = "critical";
24-
String SEVERITY_HIGH = "high";
25-
String SEVERITY_MEDIUM = "medium";
26-
String SEVERITY_LOW = "low";
27-
28-
String FILTERABLE_ISSUE_OPEN_SOURCE = "Open Source";
29-
String FILTERABLE_ISSUE_CODE_SECURITY = "Code Security";
30-
String FILTERABLE_ISSUE_CODE_QUALITY = "Code Quality";
31-
String FILTERABLE_ISSUE_INFRASTRUCTURE_AS_CODE = "Infrastructure As Code";
32-
33-
Map<String, String> FILTERABLE_ISSUE_TYPE_TO_DISPLAY = Map.of(FILTERABLE_ISSUE_CODE_QUALITY, DISPLAYED_CODE_QUALITY,
34-
FILTERABLE_ISSUE_CODE_SECURITY, DISPLAYED_CODE_SECURITY, FILTERABLE_ISSUE_INFRASTRUCTURE_AS_CODE,
35-
DISPLAYED_IAC, FILTERABLE_ISSUE_OPEN_SOURCE, DISPLAYED_OSS);
36-
37-
Map<String, String> LSP_SOURCE_TO_SCAN_PARAMS = Map.of(DIAGNOSTIC_SOURCE_SNYK_CODE, SCAN_PARAMS_CODE,
38-
DIAGNOSTIC_SOURCE_SNYK_IAC, SCAN_PARAMS_IAC, DIAGNOSTIC_SOURCE_SNYK_OSS, SCAN_PARAMS_OSS);
39-
40-
// code cannot be mapped easily
41-
Map<String, String> SCAN_PARAMS_TO_DISPLAYED = Map.of(SCAN_PARAMS_OSS, DISPLAYED_OSS, SCAN_PARAMS_IAC,
42-
DISPLAYED_IAC);
5+
public final class ProductConstants {
6+
7+
public static final String SCAN_STATE_IN_PROGRESS = "inProgress";
8+
public static final String SCAN_STATE_SUCCESS = "success";
9+
public static final String SCAN_STATE_ERROR = "error";
10+
11+
public static final String SCAN_PARAMS_OSS = "oss";
12+
public static final String SCAN_PARAMS_CODE = "code";
13+
public static final String SCAN_PARAMS_IAC = "iac";
14+
15+
public static final String DIAGNOSTIC_SOURCE_SNYK_OSS = "Snyk Open Source";
16+
public static final String DIAGNOSTIC_SOURCE_SNYK_CODE = "Snyk Code";
17+
public static final String DIAGNOSTIC_SOURCE_SNYK_IAC = "Snyk IaC";
18+
19+
public static final String DISPLAYED_OSS = "Snyk Open Source";
20+
public static final String DISPLAYED_CODE_SECURITY = "Code Security";
21+
public static final String DISPLAYED_CODE_QUALITY = "Code Quality";
22+
public static final String DISPLAYED_IAC = "Configuration";
23+
24+
public static final String SEVERITY_CRITICAL = "critical";
25+
public static final String SEVERITY_HIGH = "high";
26+
public static final String SEVERITY_MEDIUM = "medium";
27+
public static final String SEVERITY_LOW = "low";
28+
29+
public static final String FILTERABLE_ISSUE_OPEN_SOURCE = "Open Source";
30+
public static final String FILTERABLE_ISSUE_CODE_SECURITY = "Code Security";
31+
public static final String FILTERABLE_ISSUE_CODE_QUALITY = "Code Quality";
32+
public static final String FILTERABLE_ISSUE_INFRASTRUCTURE_AS_CODE = "Infrastructure As Code";
33+
34+
public static final Map<String, String> FILTERABLE_ISSUE_TYPE_TO_DISPLAY = Map.of(
35+
FILTERABLE_ISSUE_CODE_QUALITY, DISPLAYED_CODE_QUALITY,
36+
FILTERABLE_ISSUE_CODE_SECURITY, DISPLAYED_CODE_SECURITY,
37+
FILTERABLE_ISSUE_INFRASTRUCTURE_AS_CODE, DISPLAYED_IAC,
38+
FILTERABLE_ISSUE_OPEN_SOURCE, DISPLAYED_OSS);
39+
40+
public static final Map<String, String> LSP_SOURCE_TO_SCAN_PARAMS = Map.of(
41+
DIAGNOSTIC_SOURCE_SNYK_CODE, SCAN_PARAMS_CODE,
42+
DIAGNOSTIC_SOURCE_SNYK_IAC, SCAN_PARAMS_IAC,
43+
DIAGNOSTIC_SOURCE_SNYK_OSS, SCAN_PARAMS_OSS);
44+
45+
// code cannot be mapped easily
46+
public static final Map<String, String> SCAN_PARAMS_TO_DISPLAYED = Map.of(
47+
SCAN_PARAMS_OSS, DISPLAYED_OSS,
48+
SCAN_PARAMS_IAC, DISPLAYED_IAC);
4349
}

plugin/src/main/java/io/snyk/eclipse/plugin/html/CodeHtmlProvider.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ private String getThemeScript() {
6565

6666
@Override
6767
public String replaceCssVariables(String html) {
68-
html = super.replaceCssVariables(html);
68+
String htmlStyled = super.replaceCssVariables(html);
6969

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

74-
return html;
74+
return htmlStyled;
7575
}
7676
}

plugin/src/main/java/io/snyk/eclipse/plugin/html/HtmlProviderFactory.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
import io.snyk.eclipse.plugin.domain.ProductConstants;
44

55
public class HtmlProviderFactory {
6-
7-
public static BaseHtmlProvider GetHtmlProvider(String product)
8-
{
9-
switch (product) {
10-
case ProductConstants.DISPLAYED_CODE_SECURITY:
11-
case ProductConstants.DISPLAYED_CODE_QUALITY:
12-
return CodeHtmlProvider.getInstance();
13-
case ProductConstants.DISPLAYED_OSS:
14-
return OssHtmlProvider.getInstance();
15-
case ProductConstants.DISPLAYED_IAC:
16-
return IacHtmlProvider.getInstance();
17-
}
18-
return null;
19-
}
6+
7+
public static BaseHtmlProvider GetHtmlProvider(String product) {
8+
switch (product) {
9+
case ProductConstants.DISPLAYED_CODE_SECURITY:
10+
case ProductConstants.DISPLAYED_CODE_QUALITY:
11+
return CodeHtmlProvider.getInstance();
12+
case ProductConstants.DISPLAYED_OSS:
13+
return OssHtmlProvider.getInstance();
14+
case ProductConstants.DISPLAYED_IAC:
15+
return IacHtmlProvider.getInstance();
16+
default:
17+
return null;
18+
}
19+
}
2020
}

plugin/src/main/java/io/snyk/eclipse/plugin/preferences/LabelFieldEditor.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ public LabelFieldEditor(String value, Composite parent) {
2020

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

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

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

4143
// Returns the number of controls in the field editor.
44+
@Override
4245
public int getNumberOfControls() {
4346
return 1;
4447
}
4548

4649
// Labels do not persist any preferences, so these methods are empty.
50+
@Override
4751
protected void doLoad() {
4852
}
4953

54+
@Override
5055
protected void doLoadDefault() {
5156
}
52-
57+
58+
@Override
5359
protected void doStore() {
5460
}
5561
}

plugin/src/main/java/io/snyk/eclipse/plugin/properties/FolderConfigs.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ public FolderConfigsParam updateFolderConfigs() {
7676

7777
for (var project : openProjects) {
7878
Path path = ResourceUtils.getFullPath(project);
79-
IScopeContext projectScope = new ProjectScope(project);
79+
//Linter does not like when new objects are created in loops, but here we do want to create new ProjectScopes in the loop.
80+
IScopeContext projectScope = new ProjectScope(project); //NOPMD,
8081
var projectSettings = projectScope.getNode(Activator.PLUGIN_ID);
8182
String additionalParams = projectSettings.get(ProjectPropertyPage.SNYK_ADDITIONAL_PARAMETERS, "");
8283
var additionalParamsList = Arrays.asList(additionalParams.split(" "));

plugin/src/main/java/io/snyk/eclipse/plugin/views/ScanWorkspaceFolderHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
public class ScanWorkspaceFolderHandler extends AbstractHandler {
2020

2121
@SuppressWarnings("restriction")
22+
@Override
2223
public Object execute(ExecutionEvent event) throws ExecutionException {
2324
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
2425

0 commit comments

Comments
 (0)