Skip to content

Commit

Permalink
collect custom lint rules from project
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammadkahelghi-grabtaxi committed Apr 5, 2024
1 parent bf96961 commit 15102c4
Show file tree
Hide file tree
Showing 31 changed files with 5,408 additions and 640 deletions.
39 changes: 35 additions & 4 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
name = "grab_bazel_common",
commit = "46e70d673d86c1aae4b317f05506601b19c2b4c9",
commit = "e68539fe1df4eff9c613bd78a6003c6dad9a0018",
remote = "https://github.com/grab/grab-bazel-common.git",
)

Expand Down Expand Up @@ -126,6 +126,8 @@ maven_install(
"androidx.annotation:annotation": "@maven//:androidx_annotation_annotation_jvm",
"androidx.annotation:annotation-experimental": "@maven//:androidx_annotation_annotation_experimental",
"androidx.lifecycle:lifecycle-common": "@maven//:androidx_lifecycle_lifecycle_common",
"com.google.code.findbugs:jsr305": "@maven//:com_google_code_findbugs_jsr305",
"com.google.guava:listenablefuture": "@maven//:com_google_guava_listenablefuture",
"javax.inject:javax.inject": "@maven//:javax_inject_javax_inject",
"org.jetbrains.kotlin:kotlin-stdlib": "@maven//:org_jetbrains_kotlin_kotlin_stdlib",
"org.jetbrains.kotlin:kotlin-stdlib-common": "@maven//:org_jetbrains_kotlin_kotlin_stdlib_common",
Expand Down Expand Up @@ -307,23 +309,52 @@ maven_install(
"androidx.vectordrawable:vectordrawable:1.1.0",
"androidx.versionedparcelable:versionedparcelable:1.1.1",
"androidx.viewpager:viewpager:1.0.0",
"com.android.tools.build:manifest-merger:31.5.0-alpha02",
"com.android.tools.external.com-intellij:intellij-core:31.5.0-alpha02",
"com.android.tools.external.com-intellij:kotlin-compiler:31.5.0-alpha02",
"com.android.tools.external.org-jetbrains:uast:31.5.0-alpha02",
"com.android.tools.layoutlib:layoutlib-api:31.5.0-alpha02",
"com.android.tools.lint:lint-api:31.5.0-alpha02",
"com.android.tools.lint:lint-checks:31.5.0-alpha02",
"com.android.tools.lint:lint-model:31.5.0-alpha02",
"com.android.tools:annotations:31.5.0-alpha02",
"com.android.tools:common:31.5.0-alpha02",
"com.android.tools:repository:31.5.0-alpha02",
"com.android.tools:sdk-common:31.5.0-alpha02",
"com.android.tools:sdklib:31.5.0-alpha02",
"com.google.ar.sceneform.ux:sceneform-ux:1.15.0",
"com.google.ar.sceneform:core:1.15.0",
"com.google.ar.sceneform:filament-android:1.15.0",
"com.google.ar.sceneform:rendering:1.15.0",
"com.google.ar.sceneform:sceneform-base:1.15.0",
"com.google.ar:core:1.15.0",
"com.google.auto.service:auto-service-annotations:1.1.1",
"com.google.auto.service:auto-service:1.1.1",
"com.google.auto:auto-common:1.2.1",
"com.google.code.findbugs:jsr305:3.0.2",
"com.google.dagger:dagger:2.47",
"com.google.errorprone:error_prone_annotations:2.18.0",
"com.google.guava:failureaccess:1.0.1",
"com.google.guava:guava:32.0.1-jre",
"com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava",
"com.google.j2objc:j2objc-annotations:2.8",
"com.jakewharton.timber:timber:5.0.1",
"commons-io:commons-io:2.13.0",
"javax.inject:javax.inject:1",
"net.sf.kxml:kxml2:2.3.0",
"org.checkerframework:checker-qual:3.33.0",
"org.jetbrains.kotlin:kotlin-reflect:1.9.20",
"org.jetbrains.kotlin:kotlin-stdlib-common:1.8.10",
"org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.10",
"org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.10",
"org.jetbrains.kotlin:kotlin-stdlib:1.8.10",
"org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.20",
"org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.20",
"org.jetbrains.kotlin:kotlin-stdlib:1.9.20",
"org.jetbrains.kotlinx:atomicfu:0.17.3",
"org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4",
"org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.6.4",
"org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4",
"org.jetbrains:annotations:13.0",
"org.ow2.asm:asm-tree:9.6",
"org.ow2.asm:asm:9.6",
],
excluded_artifacts = ["androidx.test.espresso:espresso-contrib"],
fail_if_repin_required = False,
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ grazel {
rules {
bazelCommon {
gitRepository {
commit = "46e70d673d86c1aae4b317f05506601b19c2b4c9"
commit = "e68539fe1df4eff9c613bd78a6003c6dad9a0018"
remote = "https://github.com/grab/grab-bazel-common.git"
}
toolchains {
Expand Down
2 changes: 1 addition & 1 deletion constants.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
ext {
groupId = "com.grab.grazel"
versionName = project.hasProperty("versionName") ? versionName : "0.4.1-alpha.26"
versionName = project.hasProperty("versionName") ? versionName : "0.4.1-alpha.27"

website = "https://grab.github.io/Grazel/"
}
2 changes: 1 addition & 1 deletion flavor-libs/sample-library-flavor1/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ kotlin_library(
"src/main/java/com/grab/grazel/android/flavor/ModuleName.kt",
]),
lint_options = {
"enabled": "true",
"enabled": True,
},
visibility = [
"//visibility:public",
Expand Down
2 changes: 1 addition & 1 deletion flavor-libs/sample-library-flavor2/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ kotlin_library(
"src/main/java/com/grab/grazel/android/flavor/ModuleName.kt",
]),
lint_options = {
"enabled": "true",
"enabled": True,
},
visibility = [
"//visibility:public",
Expand Down
5 changes: 4 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ org.gradle.caching=true
android.enableJetifier=true
android.useAndroidX=true
# Kotlin code style
kotlin.code.style=official
kotlin.code.style=official

#lint version
android.experimental.lint.version = 8.5.0-alpha02
11 changes: 10 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ kotlinx-coroutines-android = "1.3.9"
kotlinx-coroutines-core-jvm = "1.7.2"
leakcanary-android = "2.12"
lifecycle-viewmodel = "2.6.1"
lint-api = "31.5.0-alpha02"
mockito-kotlin = "1.6.0"
nexus = "1.1.0"
paging-runtime = "3.1.1"
picnic = "0.4.0"
sceneform-ux = "1.15.0"
timber = "5.0.1"
auto-service = "1.1.1"
truth = "1.1.3"
jetbrains-kotlin-jvm = "1.8.10"

[libraries]
android-gradle-plugin = { module = "com.android.tools.build:gradle", version.ref = "android-gradle-plugin" }
Expand Down Expand Up @@ -83,12 +87,17 @@ kotlin-serialization = { module = "org.jetbrains.kotlinx:kotlinx-serialization-j
kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "kotlinx-coroutines-android" }
kotlinx-coroutines-core-jvm = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm", version.ref = "kotlinx-coroutines-core-jvm" }
leakcanary-android = { module = "com.squareup.leakcanary:leakcanary-android", version.ref = "leakcanary-android" }
lint-api = { module = "com.android.tools.lint:lint-api", version.ref = "lint-api" }
lint-checks = { module = "com.android.tools.lint:lint-checks", version.ref = "lint-api" }
mockito-kotlin = { module = "com.nhaarman:mockito-kotlin", version.ref = "mockito-kotlin" }
nexus-gradle-publish-plugin = { module = "io.github.gradle-nexus:publish-plugin", version.ref = "nexus" }
picnic = { module = "com.jakewharton.picnic:picnic", version.ref = "picnic" }
sceneform-ux = { module = "com.google.ar.sceneform.ux:sceneform-ux", version.ref = "sceneform-ux" }
timber = { module = "com.jakewharton.timber:timber", version.ref = "timber" }
auto-service = { module = "com.google.auto.service:auto-service", version.ref = "auto-service" }

[plugins]
kotlin-dsl = { id = "org.gradle.kotlin.kotlin-dsl", version.ref = "kotlin-dsl" }
gradle-publish = { id = "com.gradle.plugin-publish", version.ref = "gradle-plugin-publish" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
jetbrainsKotlinJvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "jetbrains-kotlin-jvm" }
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ internal fun StatementsBuilder.androidBinary(
}

if (lintConfigs?.merged?.isNotEmpty() == true) {
"lint_options" `=` lintConfigs.merged.toObject(quoteKeys = true, quoteValues = true)
"lint_options" `=` lintConfigs.merged.toObject()
}
}
}
Expand Down Expand Up @@ -251,7 +251,7 @@ internal fun StatementsBuilder.androidLibrary(
}

if (lintConfigs?.merged?.isNotEmpty() == true) {
"lint_options" `=` lintConfigs.merged.toObject(quoteKeys = true, quoteValues = true)
"lint_options" `=` lintConfigs.merged.toObject()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ fun StatementsBuilder.ktLibrary(
}

if (lintConfigs?.merged?.isNotEmpty() == true) {
"lint_options" `=` lintConfigs.merged.toObject(quoteKeys = true, quoteValues = true)
"lint_options" `=` lintConfigs.merged.toObject()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,42 @@

package com.grab.grazel.bazel.starlark

import java.util.Locale

data class LintConfigs(
val enabled: Boolean = true,
val configPath: String? = null,
val baselinePath: String? = null
val baselinePath: String? = null,
val lintChecks: List<String>? = null
) {
val merged: Map<String, String> = mapOf(
"enabled" to enabled.toString(),
"config" to configPath,
"baseline" to baselinePath
).filterValues { it != null } as Map<String, String>
val merged: List<Field> = listOf(
Field(
name = "enabled",
value = enabled.toString().capitalize(Locale.ROOT),
quoteKeys = true,
quoteValues = false
),
Field(
name = "config",
value = configPath,
quoteKeys = true,
quoteValues = true
),
Field(
name = "baseline",
value = baselinePath,
quoteKeys = true,
quoteValues = true
),
Field(
name = "lint_checks",
value = if (lintChecks != null) {
"[${lintChecks.joinToString(",") { "\"//$it\"" }}]"
} else {
null
},
quoteKeys = true,
quoteValues = false
)
).filter { it.value != null }
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,33 @@ fun Map<*, *>.toObject(
}
}
}
}
}

/**
* Converts the given `List<Field>` to bazel dict.
*/
fun List<Field>.toObject(): ObjectStatement = obj {
forEach { field ->
val key = if (field.quoteKeys) {
field.name.quote
} else {
field.name
}
val value = if (field.quoteValues) {
field.value!!.quote
} else {
field.value!!
}
key `=` value
}
}

/**
* field model for starlark
*/
data class Field(
val name: String,
val value: String?,
val quoteKeys: Boolean,
val quoteValues: Boolean,
)
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ fun lintConfigs(
},
lintOptions.baselineFile?.let {
project.relativePath(it)
}
},
project.customLintRulesTargets()
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2024 Grabtaxi Holdings PTE LTD (GRAB)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.grab.grazel.migrate.android

import org.gradle.api.Project
import org.gradle.api.artifacts.ProjectDependency


fun Project.customLintRulesTargets(): List<String>? {
val root= this.rootProject
return configurations.filter { it.name.contains("lintChecks") }.flatMap { lintChecksConfig ->
lintChecksConfig.dependencies.filterIsInstance<ProjectDependency>().map { root.relativePath(it.dependencyProject.projectDir) }
}.let {
it.ifEmpty { null }
}
}
Loading

0 comments on commit 15102c4

Please sign in to comment.