Skip to content

Move setting android linter options #309

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

Open
wants to merge 8 commits into
base: master
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
2 changes: 1 addition & 1 deletion gradle/plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repositories {

dependencies {
// android gradle plugin, required by custom plugin
implementation("com.android.tools.build:gradle:4.0.1")
implementation("com.android.tools.build:gradle:7.1.3")

implementation("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.10.0")
implementation("de.aaschmid:gradle-cpd-plugin:3.1")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package static_analysis.linters

import com.android.build.gradle.AppExtension
import com.android.build.gradle.AppPlugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.findByType
import static_analysis.errors.AndroidLintError
import static_analysis.errors.StaticAnalysisError
import static_analysis.plugins.StaticAnalysisExtension
Expand Down Expand Up @@ -33,22 +31,10 @@ class AndroidLinter : Linter {
.flatten()

override fun setupForProject(project: Project, extension: StaticAnalysisExtension) {
project.beforeEvaluate {
subprojects
.mapNotNull { it.extensions.findByType<AppExtension>() }
.first()
.lintOptions.apply {
isAbortOnError = false
isCheckAllWarnings = true
isWarningsAsErrors = false
xmlReport = true
htmlReport = false
isCheckDependencies = true
disable("MissingConstraints", "VectorRaster")
xmlOutput = getLintReportFile()
lintConfig = file("${extension.buildScriptDir}/static_analysis_configs/lint.xml")
}
}
// Make sure to set lint options manually in modules gradle file
// Otherwise you will get java.io.FileNotFoundException

// See issue: https://github.com/TouchInstinct/BuildScripts/issues/310
}

override fun getTaskNames(project: Project, buildType: String?): List<String> {
Expand All @@ -62,11 +48,14 @@ class AndroidLinter : Linter {
.mapNotNull { subproject: Project ->
subproject
.tasks
.find { task -> task.name.contains(buildType, ignoreCase = true) && task.name.contains("lint") }
?.path
.filter { task ->
task.name.equals("lint${buildType}", ignoreCase = true)
|| task.name.equals("copy${buildType}AndroidLintReports", ignoreCase = true)
}
.map { it.path }
}
.flatten()
}

private fun Project.getLintReportFile() = file("${rootProject.buildDir}/reports/lint-report.xml")

}
13 changes: 13 additions & 0 deletions gradle/scripts/lintOptions.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
android {
lint {
abortOnError false
checkAllWarnings true
warningsAsErrors false
checkDependencies true
htmlReport false
textReport false
xmlReport true
xmlOutput file("${rootProject.buildDir}/reports/lint-report.xml")
lintConfig file("${rootProject.ext["buildScriptsDir"]}/static_analysis_configs/lint.xml")
}
}
3 changes: 3 additions & 0 deletions static_analysis_configs/lint.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
<!--All activities should have locked orientation-->
<issue id="LockedOrientationActivity" severity="ignore" />

<!-- TODO: Update Timber version. See this issue: https://github.com/JakeWharton/timber/issues/408 -->
<issue id="WrongTimberUsageDetector" severity="ignore" />

<issue id="AllowAllHostnameVerifier" severity="error" />
<issue id="InvalidUsesTagAttribute" severity="error" />
<issue id="MissingIntentFilterForMediaSearch" severity="error" />
Expand Down