Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gradleLint.ignore is ignored #399

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class UnusedDependencyRule extends GradleLintRule implements GradleModelAware {

@Override
void visitGradleDependency(MethodCallExpression call, String declaredConf, GradleDependency dep) {
if (ignored) {
return // short-circuit ignored dependencies
}
String conf = dependencyService.findAndReplaceNonResolvableConfiguration(project.configurations.getByName(declaredConf)).name

if(SourceSetUtils.hasSourceSets(project)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,65 @@ class UnusedDependencyRuleSpec extends BaseIntegrationTestKitSpec {
assert result.output.contains(it)
}
}

@Issue('#380')
def 'ignore dependencies in closures when rule is ignored'() {
setup:
buildFile.text = """
plugins {
id 'java'
id 'nebula.lint'
}

gradleLint.rules = ['all-dependency']

repositories { mavenCentral() }

dependencies {
implementation 'com.google.guava:guava:18.0'
gradleLint.ignore('unused-dependency') {
implementation 'org.apache.httpcomponents:httpclient:4.5.3'
}
}
"""

when:
writeJavaSourceFile(main)
def result = runTasks('compileJava')

then:
!result.output.contains('warning unused-dependency this dependency is unused and can be removed')
}

@Issue('#380')
def 'dont ignore dependencies not in closures when rule is ignored'() {
setup:
buildFile.text = """
plugins {
id 'java'
id 'nebula.lint'
}

gradleLint.rules = ['all-dependency']

repositories { mavenCentral() }

dependencies {
implementation 'com.google.guava:guava:18.0'
implementation 'org.apache.poi:poi:5.2.5'
gradleLint.ignore('unused-dependency') {
implementation 'org.apache.httpcomponents:httpclient:4.5.3'
}
}
"""

when:
writeJavaSourceFile(main)
def result = runTasks('compileJava')

then:
result.output.contains('warning unused-dependency this dependency is unused and can be removed')
}

def dependencies(File _buildFile, String... confs = ['compile', 'testCompile', 'implementation', 'testImplementation', 'api']) {
_buildFile.text.readLines()
Expand Down