Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Pmd released
[7.0.0](https://github.com/pmd/pmd/releases/tag/pmd_releases%2F7.0.0),
which includes some expansions on their CLI and better support for Java
(migration guide
[here](https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_userdocs_migrating_to_pmd7.html)).

Updates the download, commands, and snapshot. Commands are first-match,
so 7.0.0 works cleanly on all platforms.
  • Loading branch information
TylerJang27 authored Mar 25, 2024
1 parent c6a3a87 commit bd33b4d
Show file tree
Hide file tree
Showing 5 changed files with 239 additions and 84 deletions.
45 changes: 31 additions & 14 deletions linters/pmd/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,66 @@ version: 0.1
lint:
downloads:
- name: pmd
args:
semver: ${version}=>(pmd_releases\/)*(?P<semver>.*)
downloads:
- url: https://github.com/pmd/pmd/releases/download/pmd_releases%2F${semver}/pmd-dist-${semver}-bin.zip
version: ">=7.0.0"
strip_components: 1
- url: https://github.com/pmd/pmd/releases/download/pmd_releases%2F${semver}/pmd-bin-${semver}.zip
strip_components: 1
args:
semver: ${version}=>(pmd_releases\/)*(?P<semver>.*)
definitions:
- name: pmd
download: pmd
commands:
- name: lint-apex
version: ">=7.0.0"
output: sarif
# Override this in your repo if you have custom rulesets
run: pmd check -R rulesets/apex/quickstart.xml -f sarif -d ${target}
success_codes: [0, 4]
read_output_from: stdout
files: [apex]
- name: lint-apex
platforms: [windows]
output: sarif
# Override this in your repo if you have a custom rulesets
# Override this in your repo if you have custom rulesets
run: pmd.bat -R rulesets/apex/quickstart.xml -f sarif -d ${target}
success_codes: [0, 4]
read_output_from: stdout
files:
- apex
files: [apex]
- name: lint-apex
# 6.55.0 uses run.sh in place of pmd for non-Windows
output: sarif
# Override this in your repo if you have a custom rulesets
# Override this in your repo if you have custom rulesets
run: run.sh pmd -R rulesets/apex/quickstart.xml -f sarif -d ${target}
success_codes: [0, 4]
read_output_from: stdout
files:
- apex
files: [apex]
- name: lint-java
version: ">=7.0.0"
output: sarif
# Override this in your repo if you have custom rulesets
run: pmd check -R rulesets/java/quickstart.xml -f sarif -d ${target}
success_codes: [0, 4]
read_output_from: stdout
files: [java]
- name: lint-java
platforms: [windows]
output: sarif
# Override this in your repo if you have a custom rulesets
# Override this in your repo if you have custom rulesets
run: pmd.bat -R rulesets/java/quickstart.xml -f sarif -d ${target}
success_codes: [0, 4]
read_output_from: stdout
files:
- java
files: [java]
- name: lint-java
# 6.55.0 uses run.sh in place of pmd
output: sarif
# Override this in your repo if you have a custom rulesets
# Override this in your repo if you have custom rulesets
run: run.sh pmd -R rulesets/java/quickstart.xml -f sarif -d ${target}
success_codes: [0, 4]
read_output_from: stdout
files:
- java
files: [java]
runtime: java
suggest_if: never
known_good_version: 6.55.0
Expand Down
14 changes: 12 additions & 2 deletions linters/pmd/pmd.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { linterCheckTest } from "tests";
import semver from "semver";
import { customLinterCheckTest } from "tests";
import { TEST_DATA } from "tests/utils";

linterCheckTest({
const versionGreaterThanOrEqual = (a: string, b: string) => {
const normalizedA = a.replace("pmd_releases/", "");
const normalizedB = b.replace("pmd_releases/", "");
return semver.gte(normalizedA, normalizedB);
};

customLinterCheckTest({
linterName: "pmd",
args: TEST_DATA,
versionGreaterThanOrEqual,
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Testing linter pmd test apex 1`] = `
exports[`Testing linter pmd test CUSTOM 1`] = `
{
"issues": [
{
Expand Down Expand Up @@ -57,6 +57,42 @@ exports[`Testing linter pmd test apex 1`] = `
],
"targetType": "apex",
},
{
"code": "NoPackage",
"column": "1",
"file": "test_data/hello.in.java",
"issueClass": "ISSUE_CLASS_EXISTING",
"level": "LEVEL_HIGH",
"line": "3",
"linter": "pmd",
"message": "All classes, interfaces, enums and annotations must belong to a named package",
"ranges": [
{
"filePath": "test_data/hello.in.java",
"length": "116",
"offset": "23",
},
],
"targetType": "java",
},
{
"code": "UseUtilityClass",
"column": "18",
"file": "test_data/hello.in.java",
"issueClass": "ISSUE_CLASS_EXISTING",
"level": "LEVEL_HIGH",
"line": "3",
"linter": "pmd",
"message": "All methods are static. Consider using a utility class instead. Alternatively, you could add a private constructor or make the class abstract to silence this warning.",
"ranges": [
{
"filePath": "test_data/hello.in.java",
"length": "99",
"offset": "40",
},
],
"targetType": "java",
},
],
"lintActions": [
{
Expand All @@ -78,6 +114,25 @@ exports[`Testing linter pmd test apex 1`] = `
"upstream": true,
"verb": "TRUNK_VERB_CHECK",
},
{
"command": "lint-java",
"fileGroupName": "java",
"linter": "pmd",
"paths": [
"test_data/hello.in.java",
],
"verb": "TRUNK_VERB_CHECK",
},
{
"command": "lint-java",
"fileGroupName": "java",
"linter": "pmd",
"paths": [
"test_data/hello.in.java",
],
"upstream": true,
"verb": "TRUNK_VERB_CHECK",
},
],
"taskFailures": [],
"unformattedFiles": [],
Expand Down
67 changes: 0 additions & 67 deletions linters/pmd/test_data/pmd_v6.55.0_hello.check.shot

This file was deleted.

140 changes: 140 additions & 0 deletions linters/pmd/test_data/pmd_v7.0.0_CUSTOM.check.shot
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Testing linter pmd test CUSTOM 1`] = `
{
"issues": [
{
"code": "ApexDoc",
"column": "8",
"file": "test_data/apex.in.cls",
"issueClass": "ISSUE_CLASS_EXISTING",
"level": "LEVEL_HIGH",
"line": "1",
"linter": "pmd",
"message": "Missing ApexDoc comment",
"ranges": [
{
"filePath": "test_data/apex.in.cls",
"length": "69",
"offset": "7",
},
],
"targetType": "apex",
},
{
"code": "AvoidGlobalModifier",
"column": "8",
"file": "test_data/apex.in.cls",
"issueClass": "ISSUE_CLASS_EXISTING",
"level": "LEVEL_HIGH",
"line": "1",
"linter": "pmd",
"message": "Avoid using global modifier",
"ranges": [
{
"filePath": "test_data/apex.in.cls",
"length": "69",
"offset": "7",
},
],
"targetType": "apex",
},
{
"code": "ApexDoc",
"column": "8",
"file": "test_data/apex.in.cls",
"issueClass": "ISSUE_CLASS_EXISTING",
"level": "LEVEL_HIGH",
"line": "2",
"linter": "pmd",
"message": "Missing ApexDoc comment",
"ranges": [
{
"filePath": "test_data/apex.in.cls",
"length": "41",
"offset": "33",
},
],
"targetType": "apex",
},
{
"code": "NoPackage",
"column": "1",
"file": "test_data/hello.in.java",
"issueClass": "ISSUE_CLASS_EXISTING",
"level": "LEVEL_HIGH",
"line": "3",
"linter": "pmd",
"message": "All classes, interfaces, enums and annotations must belong to a named package",
"ranges": [
{
"filePath": "test_data/hello.in.java",
"length": "5",
"offset": "23",
},
],
"targetType": "java",
},
{
"code": "UseUtilityClass",
"column": "1",
"file": "test_data/hello.in.java",
"issueClass": "ISSUE_CLASS_EXISTING",
"level": "LEVEL_HIGH",
"line": "3",
"linter": "pmd",
"message": "This utility class has a non-private constructor",
"ranges": [
{
"filePath": "test_data/hello.in.java",
"length": "5",
"offset": "23",
},
],
"targetType": "java",
},
],
"lintActions": [
{
"command": "lint-apex",
"fileGroupName": "apex",
"linter": "pmd",
"paths": [
"test_data/apex.in.cls",
],
"verb": "TRUNK_VERB_CHECK",
},
{
"command": "lint-apex",
"fileGroupName": "apex",
"linter": "pmd",
"paths": [
"test_data/apex.in.cls",
],
"upstream": true,
"verb": "TRUNK_VERB_CHECK",
},
{
"command": "lint-java",
"fileGroupName": "java",
"linter": "pmd",
"paths": [
"test_data/hello.in.java",
],
"verb": "TRUNK_VERB_CHECK",
},
{
"command": "lint-java",
"fileGroupName": "java",
"linter": "pmd",
"paths": [
"test_data/hello.in.java",
],
"upstream": true,
"verb": "TRUNK_VERB_CHECK",
},
],
"taskFailures": [],
"unformattedFiles": [],
}
`;

0 comments on commit bd33b4d

Please sign in to comment.