forked from square/dagger
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a set of custom lints along with fixes to help with migration to improved kotlin support in Dagger. This covers the following cases: * Using field: site target in injected properties * Using @JvmStatic in object modules * Annotating companion objects with @module This CL also includes the necessary infrastructure changes to build, package and deploy lint rules in the Dagger project. For Kotlin-only projects, a new artifact 'com.google.dagger:dagger-lint' will be published so that lint checks can be added via the lintChecks configuration in Gradle: ``` apply plugin: "com.android.lint" dependencies { lintChecks "com.google.dagger:dagger-lint:<version>" } ``` Meanwhile for users of Hilt and dagger-android, the lint checks will be applied from a new transitive dependency 'com.google.dagger:dagger-lint-aar'. Closes #1805 RELNOTES="Add custom lint checks to Dagger" ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=310269729
- Loading branch information
1 parent
277fbcf
commit 2597f5a
Showing
15 changed files
with
897 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<!-- | ||
Copyright (C) 2020 The Dagger Authors. | ||
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. | ||
--> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="dagger.hilt.android"> | ||
<uses-sdk android:minSdkVersion="14" /> | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<!-- | ||
Copyright (C) 2020 The Dagger Authors. | ||
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. | ||
--> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="dagger.hilt.android.testing"> | ||
<uses-sdk android:minSdkVersion="14" /> | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!-- | ||
Copyright (C) 2020 The Dagger Authors. | ||
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. | ||
--> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="dagger.lint"> | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Copyright (C) 2020 The Dagger Authors. | ||
# | ||
# 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. | ||
|
||
# Description: | ||
# Dagger Lint Rules | ||
|
||
load("//tools:maven.bzl", "POM_VERSION", "gen_maven_artifact") | ||
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library") | ||
|
||
package(default_visibility = ["//:src"]) | ||
|
||
kt_jvm_library( | ||
name = "lint-artifact-lib", | ||
srcs = glob(["*.kt"]), | ||
tags = ["maven_coordinates=com.google.dagger:dagger-lint:" + POM_VERSION], | ||
deps = [ | ||
"@google_bazel_common//third_party/java/auto:service", | ||
"@maven//:com_android_tools_external_com_intellij_intellij_core", | ||
"@maven//:com_android_tools_external_com_intellij_kotlin_compiler", | ||
"@maven//:com_android_tools_external_org_jetbrains_uast", | ||
"@maven//:com_android_tools_lint_lint", | ||
"@maven//:com_android_tools_lint_lint_api", | ||
], | ||
) | ||
|
||
# Current `kt_jvm_library` does not output source jars and gen_maven_artifact expects one. | ||
# See: https://github.com/bazelbuild/rules_kotlin/issues/324 | ||
genrule( | ||
name = "dagger-lint-sources", | ||
srcs = glob(["*.kt"]), | ||
outs = ["liblint-artifact-lib-src.jar"], | ||
cmd = """ | ||
TEMP="$$(mktemp -d)" | ||
for file in $(SRCS); do | ||
filename="$$TEMP/$${file#java/}" | ||
mkdir -p `dirname $$filename` && cp $$file $$filename | ||
done | ||
jar cf $@ -C $$TEMP . | ||
""", | ||
) | ||
|
||
gen_maven_artifact( | ||
name = "lint-artifact", | ||
artifact_id = "dagger-lint", | ||
artifact_name = "Dagger Lint Rules", | ||
artifact_target = ":lint-artifact-lib", | ||
pom_name = "lint-pom", | ||
) | ||
|
||
# An empty android artifact to distribute and share the Dagger lint rules for | ||
# the Android sub-projects. | ||
android_library( | ||
name = "lint-android-artifact-lib", | ||
tags = ["maven_coordinates=com.google.dagger:dagger-lint-aar:" + POM_VERSION], | ||
) | ||
|
||
gen_maven_artifact( | ||
name = "lint-android-artifact", | ||
artifact_id = "dagger-lint-aar", | ||
artifact_name = "Dagger Lint Rules AAR Distribution", | ||
artifact_target = ":lint-android-artifact-lib", | ||
lint_deps = [":lint-artifact-lib"], | ||
manifest = "AndroidManifest.xml", | ||
packaging = "aar", | ||
pom_name = "lint-android-pom", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (C) 2020 The Dagger Authors. | ||
* | ||
* 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 dagger.lint | ||
|
||
import com.android.tools.lint.client.api.IssueRegistry | ||
import com.android.tools.lint.detector.api.CURRENT_API | ||
import com.android.tools.lint.detector.api.Issue | ||
import com.google.auto.service.AutoService | ||
|
||
/** | ||
* Dagger Lint Issues Registry. | ||
* | ||
* A META-INF/services entry is added for this class that Lint will discover and call into for | ||
* detecting issues. | ||
*/ | ||
@AutoService(IssueRegistry::class) | ||
@Suppress("unused", "UnstableApiUsage") | ||
class DaggerIssueRegistry : IssueRegistry() { | ||
override val api: Int = CURRENT_API | ||
override val issues: List<Issue> = DaggerKotlinIssueDetector.issues | ||
} |
Oops, something went wrong.