From b75ae5e4ae2490601f4474a66f9229e30cc02341 Mon Sep 17 00:00:00 2001 From: Basil Crow Date: Sun, 19 Mar 2023 01:22:51 -0700 Subject: [PATCH] Upgrade CodeNarc from 1.2 to 1.6.1 (#1277) --- .github/dependabot.yml | 5 ++++ config/codenarc/rules.groovy | 25 +++++++++++++++++-- job-dsl-ast/pom.xml | 2 +- job-dsl-core/pom.xml | 6 ++--- .../jobdsl/dsl/doc/ApiDocGenerator.groovy | 1 - .../jobdsl/dsl/helpers/ScmContext.groovy | 3 ++- job-dsl-plugin/pom.xml | 4 +-- .../GlobalJobDslSecurityConfiguration.groovy | 1 - .../plugin/ExecuteDslScriptsSpec.groovy | 3 ++- .../plugin/JenkinsJobManagementSpec.groovy | 2 +- pom.xml | 2 +- 11 files changed, 40 insertions(+), 14 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index bcd55555d..9e63b0a52 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -7,6 +7,11 @@ updates: schedule: interval: "weekly" ignore: + # Jenkins core is stuck on Groovy 2.4 due to JENKINS-53372, and CodeNarc + # 1.x is the last version to support Groovy 2.4. Until Jenkins core moves + # forward, this plugin is stuck on CodeNarc 1.x. + - dependency-name: "org.codenarc:CodeNarc" + versions: [">=2.0.0"] # Jenkins core is stuck on Groovy 2.4 due to JENKINS-53372, and Spock 1.x # is the last version to support Groovy 2.4. Until Jenkins core moves # forward, this plugin is stuck on Spock 1.x. See: diff --git a/config/codenarc/rules.groovy b/config/codenarc/rules.groovy index 402b5f302..d9fae60d0 100644 --- a/config/codenarc/rules.groovy +++ b/config/codenarc/rules.groovy @@ -6,10 +6,20 @@ ruleset { ruleset('rulesets/concurrency.xml') ruleset('rulesets/convention.xml') { + // pending GROOVY-8814 + exclude 'CompileStatic' // we don't care exclude 'CouldBeSwitchStatement' // this rule does not necessarily lead to better code exclude 'IfStatementCouldBeTernary' + // this rule does not necessarily lead to better code + exclude 'ImplicitClosureParameter' + // we use UnnecessaryReturnKeyword instead + exclude 'ImplicitReturnStatement' + // satisfying this rule would introduce bugs + exclude 'NoDouble' + // satisfying this rule would introduce bugs + exclude 'NoFloat' // we don't care exclude 'StaticMethodsBeforeInstanceMethods' // we don't care @@ -36,6 +46,16 @@ ruleset { ruleset('rulesets/exceptions.xml') ruleset('rulesets/formatting.xml') { + // this rule does not necessarily lead to better code + ClassStartsWithBlankLine { + blankLineRequired = false + } + + // this rule does not necessarily lead to better code + ClassEndsWithBlankLine { + blankLineRequired = false + } + // empty blocks like {} are OK SpaceAfterOpeningBrace { ignoreEmptyBlock = true @@ -54,8 +74,6 @@ ruleset { exclude 'ClassJavadoc' // causes false positives exclude 'Indentation' - // existing violations - exclude 'LineLength' } @@ -111,9 +129,12 @@ ruleset { // constructors with annotations are probably necessary ignoreAnnotations = true } + UnnecessaryReturnKeyword // we don't care, does not necessarily lead to better code exclude 'UnnecessaryElseStatement' + // we don't care, does not necessarily lead to better code + exclude 'UnnecessaryGetter' // we don't care for now, does not necessarily lead to better code exclude 'UnnecessaryObjectReferences' // we do "unnecessary" overrides for the @NoDoc annotation diff --git a/job-dsl-ast/pom.xml b/job-dsl-ast/pom.xml index 69c1e6b15..5732507fc 100644 --- a/job-dsl-ast/pom.xml +++ b/job-dsl-ast/pom.xml @@ -37,7 +37,7 @@ - + diff --git a/job-dsl-core/pom.xml b/job-dsl-core/pom.xml index fb35927ec..4bebb21fd 100644 --- a/job-dsl-core/pom.xml +++ b/job-dsl-core/pom.xml @@ -160,21 +160,21 @@ - + - + - + diff --git a/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/doc/ApiDocGenerator.groovy b/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/doc/ApiDocGenerator.groovy index f9218d41c..3d719e65d 100644 --- a/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/doc/ApiDocGenerator.groovy +++ b/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/doc/ApiDocGenerator.groovy @@ -20,7 +20,6 @@ import java.lang.reflect.ParameterizedType import java.lang.reflect.Type class ApiDocGenerator { - final private File baseDir final private GroovyDocHelper docHelper = new GroovyDocHelper(new File("${baseDir}/src/main/groovy/")) final private String commandDocsPath = 'src/main/docs' diff --git a/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/ScmContext.groovy b/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/ScmContext.groovy index ab642c0c6..ef08496dc 100644 --- a/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/ScmContext.groovy +++ b/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/ScmContext.groovy @@ -296,7 +296,8 @@ class ScmContext extends AbstractExtensibleContext { checkNotNull(parentProject, 'parentProject must not be null') checkArgument( PublisherContext.VALID_CLONE_WORKSPACE_CRITERIA.contains(criteria), - "Clone Workspace Criteria needs to be one of these values: ${PublisherContext.VALID_CLONE_WORKSPACE_CRITERIA.join(',')}" + 'Clone Workspace Criteria needs to be one of these values: ' + + PublisherContext.VALID_CLONE_WORKSPACE_CRITERIA.join(',') ) scmNodes << new NodeBuilder().scm(class: 'hudson.plugins.cloneworkspace.CloneWorkspaceSCM') { diff --git a/job-dsl-plugin/pom.xml b/job-dsl-plugin/pom.xml index 85dee9662..8ec3cfa68 100644 --- a/job-dsl-plugin/pom.xml +++ b/job-dsl-plugin/pom.xml @@ -226,14 +226,14 @@ - + - + diff --git a/job-dsl-plugin/src/main/groovy/javaposse/jobdsl/plugin/GlobalJobDslSecurityConfiguration.groovy b/job-dsl-plugin/src/main/groovy/javaposse/jobdsl/plugin/GlobalJobDslSecurityConfiguration.groovy index eb4f76456..49b3162a1 100644 --- a/job-dsl-plugin/src/main/groovy/javaposse/jobdsl/plugin/GlobalJobDslSecurityConfiguration.groovy +++ b/job-dsl-plugin/src/main/groovy/javaposse/jobdsl/plugin/GlobalJobDslSecurityConfiguration.groovy @@ -8,7 +8,6 @@ import org.kohsuke.stapler.StaplerRequest @Extension class GlobalJobDslSecurityConfiguration extends GlobalConfiguration { - GlobalConfigurationCategory getCategory() { GlobalConfigurationCategory.get(GlobalConfigurationCategory.Security) } diff --git a/job-dsl-plugin/src/test/groovy/javaposse/jobdsl/plugin/ExecuteDslScriptsSpec.groovy b/job-dsl-plugin/src/test/groovy/javaposse/jobdsl/plugin/ExecuteDslScriptsSpec.groovy index 0c428f52c..11ff191ee 100644 --- a/job-dsl-plugin/src/test/groovy/javaposse/jobdsl/plugin/ExecuteDslScriptsSpec.groovy +++ b/job-dsl-plugin/src/test/groovy/javaposse/jobdsl/plugin/ExecuteDslScriptsSpec.groovy @@ -1316,6 +1316,7 @@ folder('folder-a/folder-b') { jenkinsRule.instance.rootPath.child('userContent').child('foo.txt').readToString().trim() == 'lorem ipsum' } + @SuppressWarnings('LineLength') def 'deprecation warning in DSL script with unstableOnDeprecation set to #{unstableOnDeprecation}'() { setup: FreeStyleProject job = jenkinsRule.createFreeStyleProject('seed') @@ -1329,7 +1330,7 @@ folder('folder-a/folder-b') { then: build.getLog(25).join('\n') =~ - /Warning: \(script, line 1\) support for Matrix Authorization Strategy Plugin versions older than 999999.0 is deprecated/ + /Warning: \(script, line 1\) support for Matrix Authorization Strategy Plugin versions older than 999999.0 is deprecated/ build.result == result where: diff --git a/job-dsl-plugin/src/test/groovy/javaposse/jobdsl/plugin/JenkinsJobManagementSpec.groovy b/job-dsl-plugin/src/test/groovy/javaposse/jobdsl/plugin/JenkinsJobManagementSpec.groovy index cefd3ceb1..cb1638522 100644 --- a/job-dsl-plugin/src/test/groovy/javaposse/jobdsl/plugin/JenkinsJobManagementSpec.groovy +++ b/job-dsl-plugin/src/test/groovy/javaposse/jobdsl/plugin/JenkinsJobManagementSpec.groovy @@ -125,7 +125,7 @@ class JenkinsJobManagementSpec extends Specification { then: buffer.toString() =~ - /Warning: \(.+, line \d+\) support for Script Security Plugin versions older than 999999.0 is deprecated/ + /Warning: \(.+, line \d+\) support for Script Security Plugin versions older than 999999.0 is deprecated/ } def 'logPluginDeprecationWarning does not log anything if plugin version is newer'() { diff --git a/pom.xml b/pom.xml index 0dbccff8d..2ad246932 100644 --- a/pom.xml +++ b/pom.xml @@ -85,7 +85,7 @@ org.codenarc CodeNarc - 1.2 + 1.6.1