Skip to content

Commit

Permalink
Upgrade CodeNarc from 1.2 to 1.6.1 (#1277)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil committed Mar 19, 2023
1 parent 5ea2b5d commit b75ae5e
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
25 changes: 23 additions & 2 deletions config/codenarc/rules.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -54,8 +74,6 @@ ruleset {
exclude 'ClassJavadoc'
// causes false positives
exclude 'Indentation'
// existing violations
exclude 'LineLength'

}

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion job-dsl-ast/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<target>
<taskdef classname="org.codenarc.ant.CodeNarcTask" name="codenarc" />
<echo level="info" message="Checking src/main/groovy code with CodeNarc" />
<codenarc maxPriority1Violations="0" maxPriority2Violations="0" maxPriority3Violations="0" ruleSetFiles="file:${maven.multiModuleProjectDirectory}/config/codenarc/rules.groovy">
<codenarc failOnError="true" maxPriority1Violations="0" maxPriority2Violations="0" maxPriority3Violations="0" ruleSetFiles="file:${maven.multiModuleProjectDirectory}/config/codenarc/rules.groovy">
<fileset dir="src/main/groovy">
<include name="**/*.groovy" />
</fileset>
Expand Down
6 changes: 3 additions & 3 deletions job-dsl-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,21 +160,21 @@
<target>
<taskdef classname="org.codenarc.ant.CodeNarcTask" name="codenarc" />
<echo level="info" message="Checking src/main/groovy code with CodeNarc" />
<codenarc maxPriority1Violations="0" maxPriority2Violations="0" maxPriority3Violations="0" ruleSetFiles="file:${maven.multiModuleProjectDirectory}/config/codenarc/rules.groovy">
<codenarc failOnError="true" maxPriority1Violations="0" maxPriority2Violations="0" maxPriority3Violations="0" ruleSetFiles="file:${maven.multiModuleProjectDirectory}/config/codenarc/rules.groovy">
<fileset dir="src/main/groovy">
<include name="**/*.groovy" />
</fileset>
<report type="console" />
</codenarc>
<echo level="info" message="Checking src/test/groovy code with CodeNarc" />
<codenarc maxPriority1Violations="0" maxPriority2Violations="0" maxPriority3Violations="0" ruleSetFiles="file:${maven.multiModuleProjectDirectory}/config/codenarc/rules-test.groovy">
<codenarc failOnError="true" maxPriority1Violations="0" maxPriority2Violations="0" maxPriority3Violations="0" ruleSetFiles="file:${maven.multiModuleProjectDirectory}/config/codenarc/rules-test.groovy">
<fileset dir="src/test/groovy">
<include name="**/*.groovy" />
</fileset>
<report type="console" />
</codenarc>
<echo level="info" message="Checking src/main/docs/examples code with CodeNarc" />
<codenarc maxPriority1Violations="0" maxPriority2Violations="0" maxPriority3Violations="0" ruleSetFiles="file:${maven.multiModuleProjectDirectory}/config/codenarc/rules-examples.groovy">
<codenarc failOnError="true" maxPriority1Violations="0" maxPriority2Violations="0" maxPriority3Violations="0" ruleSetFiles="file:${maven.multiModuleProjectDirectory}/config/codenarc/rules-examples.groovy">
<fileset dir="src/main/docs/examples">
<include name="**/*.groovy" />
</fileset>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
4 changes: 2 additions & 2 deletions job-dsl-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,14 @@
<target>
<taskdef classname="org.codenarc.ant.CodeNarcTask" name="codenarc" />
<echo level="info" message="Checking src/main/groovy code with CodeNarc" />
<codenarc maxPriority1Violations="0" maxPriority2Violations="0" maxPriority3Violations="0" ruleSetFiles="file:${maven.multiModuleProjectDirectory}/config/codenarc/rules.groovy">
<codenarc failOnError="true" maxPriority1Violations="0" maxPriority2Violations="0" maxPriority3Violations="0" ruleSetFiles="file:${maven.multiModuleProjectDirectory}/config/codenarc/rules.groovy">
<fileset dir="src/main/groovy">
<include name="**/*.groovy" />
</fileset>
<report type="console" />
</codenarc>
<echo level="info" message="Checking src/test/groovy code with CodeNarc" />
<codenarc maxPriority1Violations="0" maxPriority2Violations="0" maxPriority3Violations="0" ruleSetFiles="file:${maven.multiModuleProjectDirectory}/config/codenarc/rules-test.groovy">
<codenarc failOnError="true" maxPriority1Violations="0" maxPriority2Violations="0" maxPriority3Violations="0" ruleSetFiles="file:${maven.multiModuleProjectDirectory}/config/codenarc/rules-test.groovy">
<fileset dir="src/test/groovy">
<include name="**/*.groovy" />
</fileset>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import org.kohsuke.stapler.StaplerRequest

@Extension
class GlobalJobDslSecurityConfiguration extends GlobalConfiguration {

GlobalConfigurationCategory getCategory() {
GlobalConfigurationCategory.get(GlobalConfigurationCategory.Security)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'() {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<dependency>
<groupId>org.codenarc</groupId>
<artifactId>CodeNarc</artifactId>
<version>1.2</version>
<version>1.6.1</version>
</dependency>
</dependencies>
</plugin>
Expand Down

0 comments on commit b75ae5e

Please sign in to comment.