UNPKG

npm-groovy-lint

Version:

Lint, format and auto-fix your Groovy / Jenkinsfile / Gradle files

43 lines (38 loc) 1.17 kB
// Unnecessary package reference import { getVariable, getVariableRange } from "../utils.js"; const rule = { variables: [ { name: "CLASS_WITH_PACKAGE", regex: /The (.*) (.*) was explicitly imported, so specifying the package name is not necessary/, }, ], range: { type: "function", func: (errLine, errItem, evaluatedVars) => { return getVariableRange(errLine, evaluatedVars, "CLASS_WITH_PACKAGE", errItem); }, }, fix: { label: "Use short name", type: "function", func: (line, evaluatedVars) => { const packageName = getVariable(evaluatedVars, "CLASS_WITH_PACKAGE", { mandatory: true, htmlToString: true, line: line }); const packageShortName = packageName.split(".").pop(); return line.replace(packageName, packageShortName); }, }, tests: [ { sourceBefore: ` import groovy.json.JsonOutput def body = groovy.json.JsonOutput.toJson(value) `, sourceAfter: ` import groovy.json.JsonOutput def body = JsonOutput.toJson(value) `, }, ], }; export { rule };