Skip to content

Commit

Permalink
Merge pull request #338 from nebula-plugins/fixme-rule-can-be-noncrit…
Browse files Browse the repository at this point in the history
…ical

Fixme violations can be noncritical when a property is passed in
  • Loading branch information
OdysseusLives authored Jun 16, 2021
2 parents 28e0a85 + 5ce451e commit a6c0195
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/groovy/com/netflix/nebula/lint/rule/FixmeRule.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ class FixmeRule implements Rule {

@Override
int getPriority() {
// A system property is used since not all lint rules are GradleModelAware in order to pass in a project
// We would prefer to use https://docs.gradle.org/6.1/javadoc/org/gradle/api/provider/ProviderFactory.html#systemProperty-java.lang.String-
// but this was introduced in Gradle 6.1
def nonCriticalPriority = System.getProperty('nebula.lint.fixmeAsNonCritical')
if (nonCriticalPriority != null && nonCriticalPriority == "true") {
return 2 // violations of fixmes are noncritical only when the property is used
}
return 1 // violations of fixmes are always critical rule failures
}

Expand Down
40 changes: 40 additions & 0 deletions src/test/groovy/com/netflix/nebula/lint/rule/FixmeRuleSpec.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.netflix.nebula.lint.rule

import nebula.test.IntegrationTestKitSpec
import spock.lang.Subject

@Subject(FixmeRule)
class FixmeRuleSpec extends IntegrationTestKitSpec {
def tasks = ['assemble', 'fixGradleLint']

def setup() {
def oldDate = '2010-12-1'
buildFile.text = """
plugins {
id 'nebula.lint'
id 'java-library'
}
gradleLint.rules = ['minimum-dependency-version']
repositories { mavenCentral() }
dependencies {
gradleLint.fixme('$oldDate') {
implementation 'com.google.guava:guava:18.+'
}
}
""".stripIndent()
}

def 'expired fixmes are critical violations'() {
expect:
def result = runTasksAndFail(*tasks)
result.output.contains('needs fixing')
result.output.contains('critical lint violation')
}

def 'expired fixmes are noncritical violations when a property is used'() {
expect:
def result = runTasks(*tasks, '-Dnebula.lint.fixmeAsNonCritical=true')
result.output.contains('needs fixing')
!result.output.contains('critical lint violation')
}
}

0 comments on commit a6c0195

Please sign in to comment.