Skip to content

Commit abc4c40

Browse files
committed
fix: lint improvements
1 parent 2e6e18e commit abc4c40

File tree

8 files changed

+53
-51
lines changed

8 files changed

+53
-51
lines changed

plugin/.pmd

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
<pmd>
33
<useProjectRuleSet>true</useProjectRuleSet>
4-
<ruleSetFile>/Users/skippy/repos/snyk-eclipse-plugin/plugin/src/main/resources/pmd-ruleset.xml</ruleSetFile>
4+
<ruleSetFile>src/main/resources/pmd-ruleset.xml</ruleSetFile>
55
<includeDerivedFiles>false</includeDerivedFiles>
66
<violationsAsErrors>true</violationsAsErrors>
77
<fullBuildEnabled>true</fullBuildEnabled>

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); //NOPMD
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/snyktoolview/IssueTreeNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class IssueTreeNode extends BaseTreeNode {
1111

1212
public IssueTreeNode(Issue issue) {
1313
super(issue);
14-
this.issue = issue;
14+
this.setIssue(issue);
1515
}
1616

1717
@Override
@@ -44,7 +44,7 @@ public Issue getIssue() {
4444
return issue;
4545
}
4646

47-
public void setIssue(Issue issue) {
47+
public final void setIssue(Issue issue) {
4848
this.issue = issue;
4949
}
5050

plugin/src/main/java/io/snyk/eclipse/plugin/views/snyktoolview/filters/BaseFilter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
import io.snyk.eclipse.plugin.preferences.Preferences;
66
import io.snyk.eclipse.plugin.views.snyktoolview.TreeFilterManager;
77

8-
@SuppressWarnings({ "rawtypes"})
9-
public class BaseFilter {
8+
@SuppressWarnings({"rawtypes"})
9+
public abstract class BaseFilter {
1010
protected Preferences preferences = Preferences.getInstance();
1111
protected TreeFilterManager filterManager;
1212
protected String filterName;
1313
protected Predicate predicate;
1414

15-
protected BaseFilter(String filterName, Predicate predicate, TreeFilterManager tfm) {
15+
public BaseFilter(String filterName, Predicate predicate, TreeFilterManager tfm) {
1616
this.filterName = filterName;
1717
this.predicate = predicate;
1818
this.filterManager = tfm;

plugin/src/main/java/io/snyk/languageserver/LsConfigurationUpdater.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public String getAutomaticAuthentication() {
209209
}
210210

211211
public String[] getTrustedFolders() {
212-
return Arrays.copyOf(trustedFolders, trustedFolders.length);
212+
return trustedFolders.clone();
213213
}
214214

215215
public String getEnableTrustedFoldersFeature() {

plugin/src/main/java/io/snyk/languageserver/protocolextension/messageObjects/PublishDiagnostics316Param.java

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,41 +20,44 @@ public void setUri(String uri) {
2020
}
2121

2222
public Diagnostic316[] getDiagnostics() {
23-
if (diagnostics == null) {
24-
return new Diagnostic316[0]; // Return an empty array if diagnostics is null
25-
}
26-
return Arrays.copyOf(diagnostics, diagnostics.length);
23+
if (diagnostics == null) {
24+
return null;
25+
}
26+
return diagnostics.clone();
2727
}
2828

29-
3029
public void setDiagnostics(Diagnostic316... diagnostics) {
30+
if (diagnostics == null) {
31+
this.diagnostics = null;
32+
}
3133
this.diagnostics = diagnostics.clone();
3234
}
3335

3436
@Override
3537
public int hashCode() {
36-
final int prime = 31;
37-
int result = 1;
38-
result = prime * result + (diagnostics == null ? 0 : Arrays.hashCode(diagnostics));
39-
result = prime * result + Objects.hash(uri);
40-
return result;
38+
final int prime = 31;
39+
int result = 1;
40+
result = prime * result + (diagnostics == null ? 0 : Arrays.hashCode(diagnostics));
41+
result = prime * result + Objects.hash(uri);
42+
return result;
4143
}
4244

4345
@Override
4446
public boolean equals(Object obj) {
45-
if (this == obj)
46-
return true;
47-
if (obj == null)
48-
return false;
49-
if (getClass() != obj.getClass())
50-
return false;
51-
PublishDiagnostics316Param other = (PublishDiagnostics316Param) obj;
52-
return (diagnostics == null ? other.diagnostics == null : Arrays.equals(diagnostics, other.diagnostics))
53-
&& Objects.equals(uri, other.uri);
47+
if (this == obj)
48+
return true;
49+
if (obj == null)
50+
return false;
51+
if (getClass() != obj.getClass())
52+
return false;
53+
PublishDiagnostics316Param other = (PublishDiagnostics316Param) obj;
54+
return (diagnostics == null ? other.diagnostics == null : Arrays.equals(diagnostics, other.diagnostics))
55+
&& Objects.equals(uri, other.uri);
5456
}
5557

5658
@Override
5759
public String toString() {
58-
return "PublishDiagnostic316Param [uri=" + uri + ", diagnostics=" + (diagnostics == null ? "null" : Arrays.toString(diagnostics)) + "]";
60+
return "PublishDiagnostic316Param [uri=" + uri + ", diagnostics="
61+
+ (diagnostics == null ? "null" : Arrays.toString(diagnostics)) + "]";
5962
}
6063
}

plugin/src/main/java/io/snyk/languageserver/protocolextension/messageObjects/SnykTrustedFoldersParams.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package io.snyk.languageserver.protocolextension.messageObjects;
22

3-
import java.util.Arrays;
4-
53
public class SnykTrustedFoldersParams {
64
private String[] trustedFolders;
75

86
public String[] getTrustedFolders() {
9-
return Arrays.copyOf(trustedFolders, trustedFolders.length);
7+
return trustedFolders.clone();
108
}
119

1210
public void setTrustedFolders(String... trustedFolders) {

plugin/src/main/java/io/snyk/languageserver/protocolextension/messageObjects/scanResults/Issue.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,20 @@
44

55
public record Issue(String id, String title, String severity, String filePath, Range range, boolean isIgnored,
66
boolean isNew, String filterableIssueType, IgnoreDetails ignoreDetails, AdditionalData additionalData) {
7-
87
public String getDisplayTitle() {
98
if (title == null || title.isEmpty()) {
109
return additionalData != null ? additionalData.message() : null;
1110
}
12-
13-
StringBuilder displayTitle = new StringBuilder(title);
14-
11+
String displayTitle = title;
1512
if (isIgnored()) {
16-
displayTitle.insert(0, " [ Ignored ] ");
13+
displayTitle = " [ Ignored ] " + displayTitle;
1714
}
1815

1916
if (hasFix()) {
20-
displayTitle.insert(0, " ⚡");
17+
displayTitle = " ⚡" + displayTitle;
2118
}
22-
23-
return displayTitle.toString();
19+
20+
return displayTitle;
2421
}
2522

2623
public String getDisplayTitleWithLineNumber() {
@@ -53,17 +50,20 @@ public Boolean hasFix() {
5350
}
5451
return additionalData.hasAIFix() || additionalData.isUpgradable();
5552
}
56-
53+
5754
public Boolean isVisible(Boolean includeIgnoredIssues, Boolean includeOpenedIssues) {
58-
if (includeIgnoredIssues && includeOpenedIssues) {
59-
return true;
60-
}
61-
if (includeIgnoredIssues) {
62-
return this.isIgnored();
63-
}
64-
if (includeOpenedIssues) {
65-
return !this.isIgnored();
66-
}
67-
return false;
68-
}
55+
if (includeIgnoredIssues && includeOpenedIssues)
56+
{
57+
return true;
58+
}
59+
if (includeIgnoredIssues)
60+
{
61+
return this.isIgnored();
62+
}
63+
if (includeOpenedIssues)
64+
{
65+
return !this.isIgnored();
66+
}
67+
return false;
68+
}
6969
}

0 commit comments

Comments
 (0)