diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 550abe50..efa2d160 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,5 +1,13 @@ # How to become a contributor and submit your own code +## Documentation + +Note the all the documentation under docs/ is only a mirror; +the original documentation is maintained in the Android +source code repository: + +https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/docs/ + ## Contributor License Agreements We'd love to accept your sample apps and patches! Before we can take them, we diff --git a/app/build.gradle b/app/build.gradle deleted file mode 100644 index 7f031ff9..00000000 --- a/app/build.gradle +++ /dev/null @@ -1,37 +0,0 @@ -plugins { - id 'com.android.application' - id 'kotlin-android' -} - -android { - compileSdkVersion 33 - - defaultConfig { - applicationId "com.android.example.lint_usage" - minSdkVersion 21 - targetSdkVersion 33 - versionCode 1 - versionName "1.0" - } - - compileOptions { - sourceCompatibility JavaVersion.VERSION_17 - targetCompatibility JavaVersion.VERSION_17 - } - kotlinOptions { - jvmTarget = '17' - } - namespace 'com.android.example' - lint { - checkDependencies true - // Produce report for CI: - // https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/sarif-support-for-code-scanning - sarifOutput file('../lint-results.sarif') - textReport true - } -} - -dependencies { - implementation project(':library') -} - diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 00000000..b397c317 --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,33 @@ +plugins { + alias(libs.plugins.android.application) + alias(libs.plugins.kotlin.android) +} + +android { + namespace = "com.android.example" + compileSdk = 34 + + defaultConfig { + applicationId = "com.android.example.lint_usage" + minSdk = 21 + targetSdk = 34 + versionCode = 1 + versionName = "1.0" + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } + lint { + checkDependencies = true + // Produce report for CI: + // https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/sarif-support-for-code-scanning + sarifOutput = file("../lint-results.sarif") + textReport = true + } +} + +dependencies { + implementation(project(":library")) +} \ No newline at end of file diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 8d9778fd..00000000 --- a/build.gradle +++ /dev/null @@ -1,31 +0,0 @@ -buildscript { - ext { - kotlinVersion = '1.8.20' - // Current release: Flamingo / AGP 8.0 - gradlePluginVersion = '8.0.2' - lintVersion = '31.0.2' - // Current preview release: Hedgehog - //gradlePluginVersion = '8.2.0-alpha07' - //lintVersion = '31.2.0-alpha07' - } - - repositories { - google() - mavenCentral() - } - dependencies { - classpath "com.android.tools.build:gradle:$gradlePluginVersion" - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" - } -} - -allprojects { - repositories { - google() - mavenCentral() - } -} - -task clean(type: Delete) { - delete rootProject.buildDir -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 00000000..7511b799 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,8 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +plugins { + alias(libs.plugins.kotlin.jvm) apply false + alias(libs.plugins.kotlin.android) apply false + alias(libs.plugins.android.application) apply false + alias(libs.plugins.android.library) apply false + alias(libs.plugins.android.lint) apply false +} diff --git a/checks/app b/checks/app new file mode 100644 index 00000000..123a6651 --- /dev/null +++ b/checks/app @@ -0,0 +1,51 @@ +plugins { + alias(libs.plugins.androidApplication) + alias(libs.plugins.kotlinAndroid) +} + +android { + namespace = "com.android.example.lint_usage" + compileSdk = 34 + + defaultConfig { + applicationId = "com.android.example.lint_usage" + minSdk = 21 + targetSdk = 34 + versionCode = 1 + versionName = "1.0" + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = "1.8" + } + buildFeatures { + compose = true + } + composeOptions { + kotlinCompilerExtensionVersion = "1.5.1" + } +} + +dependencies { + + implementation(libs.core.ktx) + implementation(libs.lifecycle.runtime.ktx) + implementation(libs.activity.compose) + implementation(platform(libs.compose.bom)) + implementation(libs.ui) + implementation(libs.ui.graphics) + implementation(libs.ui.tooling.preview) + implementation(libs.material3) + implementation(project(":library")) + testImplementation(libs.junit) + androidTestImplementation(libs.androidx.test.ext.junit) + androidTestImplementation(libs.espresso.core) + androidTestImplementation(platform(libs.compose.bom)) + androidTestImplementation(libs.ui.test.junit4) + debugImplementation(libs.ui.tooling) + debugImplementation(libs.ui.test.manifest) +} \ No newline at end of file diff --git a/checks/build.gradle b/checks/build.gradle deleted file mode 100644 index b2976f1b..00000000 --- a/checks/build.gradle +++ /dev/null @@ -1,26 +0,0 @@ -apply plugin: 'java-library' -apply plugin: 'kotlin' -apply plugin: 'com.android.lint' - -lintOptions { - htmlReport true - htmlOutput file("lint-report.html") - textReport true - absolutePaths false - ignoreTestSources true -} - -dependencies { - // For a description of the below dependencies, see the main project README - compileOnly "com.android.tools.lint:lint-api:$lintVersion" - // You typically don't need this one: - compileOnly "com.android.tools.lint:lint-checks:$lintVersion" - compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion" - - testImplementation "junit:junit:4.13.2" - testImplementation "com.android.tools.lint:lint:$lintVersion" - testImplementation "com.android.tools.lint:lint-tests:$lintVersion" -} - -sourceCompatibility = "17" -targetCompatibility = "17" diff --git a/checks/build.gradle.kts b/checks/build.gradle.kts new file mode 100644 index 00000000..2f515374 --- /dev/null +++ b/checks/build.gradle.kts @@ -0,0 +1,24 @@ +plugins { + id("java-library") + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.android.lint) +} + +java { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 +} + +lint { + htmlReport = true + htmlOutput = file("lint-report.html") + textReport = true + absolutePaths = false + ignoreTestSources = true +} + +dependencies { + // For a description of the below dependencies, see the main project README + compileOnly(libs.bundles.lint.api) + testImplementation(libs.bundles.lint.tests) +} diff --git a/checks/src/main/java/com/example/lint/checks/AvoidDateDetector.kt b/checks/src/main/java/com/example/lint/checks/AvoidDateDetector.kt new file mode 100644 index 00000000..cdda8bd4 --- /dev/null +++ b/checks/src/main/java/com/example/lint/checks/AvoidDateDetector.kt @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * 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.example.lint.checks + +import com.android.tools.lint.detector.api.Category +import com.android.tools.lint.detector.api.Detector +import com.android.tools.lint.detector.api.Implementation +import com.android.tools.lint.detector.api.Issue +import com.android.tools.lint.detector.api.JavaContext +import com.android.tools.lint.detector.api.Scope +import com.android.tools.lint.detector.api.Severity +import com.android.tools.lint.detector.api.SourceCodeScanner +import com.intellij.psi.PsiMethod +import org.jetbrains.uast.UCallExpression + +class AvoidDateDetector : Detector(), SourceCodeScanner { + companion object Issues { + private val IMPLEMENTATION = + Implementation(AvoidDateDetector::class.java, Scope.JAVA_FILE_SCOPE) + + @JvmField + val ISSUE = + Issue.create( + id = "OldDate", + briefDescription = "Avoid Date and Calendar", + explanation = + """ + The `java.util.Date` and `java.util.Calendar` classes should not be used; instead \ + use the `java.time` package, such as `LocalDate` and `LocalTime`. + """, + category = Category.CORRECTNESS, + priority = 6, + severity = Severity.ERROR, + androidSpecific = true, + implementation = IMPLEMENTATION, + ) + } + + // java.util.Date() + override fun getApplicableConstructorTypes(): List = listOf("java.util.Date") + + override fun visitConstructor( + context: JavaContext, + node: UCallExpression, + constructor: PsiMethod, + ) { + context.report( + ISSUE, + node, + context.getLocation(node), + "Don't use `Date`; use `java.time.*` instead", + fix() + .alternatives( + fix().replace().all().with("java.time.LocalTime.now()").shortenNames().build(), + fix().replace().all().with("java.time.LocalDate.now()").shortenNames().build(), + fix().replace().all().with("java.time.LocalDateTime.now()").shortenNames().build(), + ), + ) + } + + // java.util.Calendar.getInstance() + override fun getApplicableMethodNames(): List = listOf("getInstance") + + override fun visitMethodCall(context: JavaContext, node: UCallExpression, method: PsiMethod) { + val evaluator = context.evaluator + if (!evaluator.isMemberInClass(method, "java.util.Calendar")) { + return + } + context.report( + ISSUE, + node, + context.getLocation(node), + "Don't use `Calendar.getInstance`; use `java.time.*` instead", + ) + } +} diff --git a/checks/src/main/java/com/example/lint/checks/NotNullAssertionDetector.kt b/checks/src/main/java/com/example/lint/checks/NotNullAssertionDetector.kt new file mode 100644 index 00000000..8d0fe2de --- /dev/null +++ b/checks/src/main/java/com/example/lint/checks/NotNullAssertionDetector.kt @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * 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.example.lint.checks + +import com.android.tools.lint.client.api.UElementHandler +import com.android.tools.lint.detector.api.Category +import com.android.tools.lint.detector.api.Detector +import com.android.tools.lint.detector.api.Implementation +import com.android.tools.lint.detector.api.Incident +import com.android.tools.lint.detector.api.Issue +import com.android.tools.lint.detector.api.JavaContext +import com.android.tools.lint.detector.api.Scope +import com.android.tools.lint.detector.api.Severity +import com.android.tools.lint.detector.api.SourceCodeScanner +import org.jetbrains.kotlin.analysis.api.analyze +import org.jetbrains.kotlin.codegen.optimization.common.analyze +import org.jetbrains.kotlin.psi.KtExpression +import org.jetbrains.uast.UElement +import org.jetbrains.uast.UPostfixExpression + +class NotNullAssertionDetector : Detector(), SourceCodeScanner { + companion object Issues { + private val IMPLEMENTATION = + Implementation(NotNullAssertionDetector::class.java, Scope.JAVA_FILE_SCOPE) + + @JvmField + val ISSUE = + Issue.create( + id = "NotNullAssertion", + briefDescription = "Avoid `!!`", + explanation = + """ + Do not use the `!!` operator. It can lead to null pointer exceptions. \ + Please use the `?` operator instead, or assign to a local variable with \ + `?:` initialization if necessary. + """, + category = Category.CORRECTNESS, + priority = 6, + severity = Severity.WARNING, + implementation = IMPLEMENTATION, + ) + } + + override fun getApplicableUastTypes(): List>? { + return listOf(UPostfixExpression::class.java) + } + + override fun createUastHandler(context: JavaContext): UElementHandler { + return object : UElementHandler() { + override fun visitPostfixExpression(node: UPostfixExpression) { + if (node.operator.text == "!!") { + var message = "Do not use `!!`" + + // Kotlin Analysis API example + val sourcePsi = node.operand.sourcePsi + if (sourcePsi is KtExpression) { + analyze(sourcePsi) { + val type = sourcePsi.getKtType() + if (type != null && !type.canBeNull) { + message += " -- it's not even needed here" + } + } + } + + val incident = Incident(ISSUE, node, context.getLocation(node), message) + context.report(incident) + } + } + } + } +} diff --git a/checks/src/main/java/com/example/lint/checks/SampleCodeDetector.kt b/checks/src/main/java/com/example/lint/checks/SampleCodeDetector.kt index 1a27e22c..1f1efdca 100644 --- a/checks/src/main/java/com/example/lint/checks/SampleCodeDetector.kt +++ b/checks/src/main/java/com/example/lint/checks/SampleCodeDetector.kt @@ -29,64 +29,61 @@ import org.jetbrains.uast.ULiteralExpression import org.jetbrains.uast.evaluateString /** - * Sample detector showing how to analyze Kotlin/Java code. This example - * flags all string literals in the code that contain the word "lint". + * Sample detector showing how to analyze Kotlin/Java code. This example flags all string literals + * in the code that contain the word "lint". */ -@Suppress("UnstableApiUsage") class SampleCodeDetector : Detector(), UastScanner { - override fun getApplicableUastTypes(): List> { - return listOf(ULiteralExpression::class.java) - } + override fun getApplicableUastTypes(): List> { + return listOf(ULiteralExpression::class.java) + } - override fun createUastHandler(context: JavaContext): UElementHandler { - // Note: Visiting UAST nodes is a pretty general purpose mechanism; - // Lint has specialized support to do common things like "visit every class - // that extends a given super class or implements a given interface", and - // "visit every call site that calls a method by a given name" etc. - // Take a careful look at UastScanner and the various existing lint check - // implementations before doing things the "hard way". - // Also be aware of context.getJavaEvaluator() which provides a lot of - // utility functionality. - return object : UElementHandler() { - override fun visitLiteralExpression(node: ULiteralExpression) { - val string = node.evaluateString() ?: return - if (string.contains("lint") && string.matches(Regex(".*\\blint\\b.*"))) { - context.report( - ISSUE, node, context.getLocation(node), - "This code mentions `lint`: **Congratulations**" - ) - } - } + override fun createUastHandler(context: JavaContext): UElementHandler { + // Note: Visiting UAST nodes is a pretty general purpose mechanism; + // Lint has specialized support to do common things like "visit every class + // that extends a given super class or implements a given interface", and + // "visit every call site that calls a method by a given name" etc. + // Take a careful look at UastScanner and the various existing lint check + // implementations before doing things the "hard way". + // Also be aware of context.getJavaEvaluator() which provides a lot of + // utility functionality. + return object : UElementHandler() { + override fun visitLiteralExpression(node: ULiteralExpression) { + val string = node.evaluateString() ?: return + if (string.contains("lint") && string.matches(Regex(".*\\blint\\b.*"))) { + context.report( + ISSUE, + node, + context.getLocation(node), + "This code mentions `lint`: **Congratulations**", + ) } + } } + } - companion object { - /** - * Issue describing the problem and pointing to the detector - * implementation. - */ - @JvmField - val ISSUE: Issue = Issue.create( - // ID: used in @SuppressLint warnings etc - id = "SampleId", - // Title -- shown in the IDE's preference dialog, as category headers in the - // Analysis results window, etc - briefDescription = "Lint Mentions", - // Full explanation of the issue; you can use some markdown markup such as - // `monospace`, *italic*, and **bold**. - explanation = """ - This check highlights string literals in code which mentions the word `lint`. \ - Blah blah blah. + companion object { + /** Issue describing the problem and pointing to the detector implementation. */ + @JvmField + val ISSUE: Issue = + Issue.create( + // ID: used in @SuppressLint warnings etc + id = "SampleId", + // Title -- shown in the IDE's preference dialog, as category headers in the + // Analysis results window, etc + briefDescription = "Lint Mentions", + // Full explanation of the issue; you can use some markdown markup such as + // `monospace`, *italic*, and **bold**. + explanation = + """ + This check highlights string literals in code which mentions the word `lint`. \ + Blah blah blah. - Another paragraph here. - """, // no need to .trimIndent(), lint does that automatically - category = Category.CORRECTNESS, - priority = 6, - severity = Severity.WARNING, - implementation = Implementation( - SampleCodeDetector::class.java, - Scope.JAVA_FILE_SCOPE - ) - ) - } + Another paragraph here. + """, // no need to .trimIndent(), lint does that automatically + category = Category.CORRECTNESS, + priority = 6, + severity = Severity.WARNING, + implementation = Implementation(SampleCodeDetector::class.java, Scope.JAVA_FILE_SCOPE), + ) + } } diff --git a/checks/src/main/java/com/example/lint/checks/SampleIssueRegistry.kt b/checks/src/main/java/com/example/lint/checks/SampleIssueRegistry.kt index aafaafa9..042eac3c 100644 --- a/checks/src/main/java/com/example/lint/checks/SampleIssueRegistry.kt +++ b/checks/src/main/java/com/example/lint/checks/SampleIssueRegistry.kt @@ -22,21 +22,22 @@ import com.android.tools.lint.detector.api.CURRENT_API /* * The list of issues that will be checked when running lint. */ -@Suppress("UnstableApiUsage") class SampleIssueRegistry : IssueRegistry() { - override val issues = listOf(SampleCodeDetector.ISSUE) + override val issues = + listOf(SampleCodeDetector.ISSUE, AvoidDateDetector.ISSUE, NotNullAssertionDetector.ISSUE) - override val api: Int - get() = CURRENT_API + override val api: Int + get() = CURRENT_API - override val minApi: Int - get() = 8 // works with Studio 4.1 or later; see com.android.tools.lint.detector.api.Api / ApiKt + override val minApi: Int + get() = 8 // works with Studio 4.1 or later; see com.android.tools.lint.detector.api.Api / ApiKt - // Requires lint API 30.0+; if you're still building for something - // older, just remove this property. - override val vendor: Vendor = Vendor( - vendorName = "Android Open Source Project", - feedbackUrl = "https://github.com/googlesamples/android-custom-lint-rules/issues", - contact = "https://github.com/googlesamples/android-custom-lint-rules" + // Requires lint API 30.0+; if you're still building for something + // older, just remove this property. + override val vendor: Vendor = + Vendor( + vendorName = "Android Open Source Project", + feedbackUrl = "https://github.com/googlesamples/android-custom-lint-rules/issues", + contact = "https://github.com/googlesamples/android-custom-lint-rules", ) } diff --git a/checks/src/test/java/com/example/lint/checks/AvoidDateDetectorTest.kt b/checks/src/test/java/com/example/lint/checks/AvoidDateDetectorTest.kt new file mode 100644 index 00000000..8f8fe5fb --- /dev/null +++ b/checks/src/test/java/com/example/lint/checks/AvoidDateDetectorTest.kt @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * 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.example.lint.checks + +import com.android.tools.lint.checks.infrastructure.LintDetectorTest +import com.android.tools.lint.detector.api.Detector +import com.android.tools.lint.detector.api.Issue + +class AvoidDateDetectorTest : LintDetectorTest() { + override fun getDetector(): Detector = AvoidDateDetector() + + override fun getIssues(): List = listOf(AvoidDateDetector.ISSUE) + + fun testDocumentationExample() { + lint() + .files( + kotlin( + """ + package test.pkg + import java.util.Date + fun test() { + val date = Date() + } + """ + ) + .indented(), + kotlin( + """ + package test.pkg + import java.util.Calendar + + fun test2() { + val calendar = Calendar.getInstance() + } + """ + ) + .indented(), + ) + .allowMissingSdk() + .run() + .expect( + """ + src/test/pkg/test.kt:4: Error: Don't use Date; use java.time.* instead [OldDate] + val date = Date() + ~~~~~~ + src/test/pkg/test2.kt:5: Error: Don't use Calendar.getInstance; use java.time.* instead [OldDate] + val calendar = Calendar.getInstance() + ~~~~~~~~~~~~~~~~~~~~~~ + 2 errors, 0 warnings + """ + ) + .expectFixDiffs( + """ + Fix for src/test/pkg/test.kt line 4: Replace with java.time.LocalTime.now(): + @@ -2 +2 + + import java.time.LocalTime + @@ -4 +5 + - val date = Date() + + val date = LocalTime.now() + Fix for src/test/pkg/test.kt line 4: Replace with java.time.LocalDate.now(): + @@ -2 +2 + + import java.time.LocalDate + @@ -4 +5 + - val date = Date() + + val date = LocalDate.now() + Fix for src/test/pkg/test.kt line 4: Replace with java.time.LocalDateTime.now(): + @@ -2 +2 + + import java.time.LocalDateTime + @@ -4 +5 + - val date = Date() + + val date = LocalDateTime.now() + """ + ) + } +} diff --git a/checks/src/test/java/com/example/lint/checks/NotNullAssertionDetectorTest.kt b/checks/src/test/java/com/example/lint/checks/NotNullAssertionDetectorTest.kt new file mode 100644 index 00000000..3b951866 --- /dev/null +++ b/checks/src/test/java/com/example/lint/checks/NotNullAssertionDetectorTest.kt @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * 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.example.lint.checks + +import com.android.tools.lint.checks.infrastructure.LintDetectorTest +import com.android.tools.lint.detector.api.Detector +import com.android.tools.lint.detector.api.Issue + +class NotNullAssertionDetectorTest : LintDetectorTest() { + override fun getDetector(): Detector { + return NotNullAssertionDetector() + } + + override fun getIssues(): List { + return listOf(NotNullAssertionDetector.ISSUE) + } + + fun testDocumentationExample() { + lint() + .files( + kotlin( + """ + package test.pkg + + fun test(s: String?, t: String) { + s?.plus(s) + s!!.plus(s) + t!!.plus(t) + } + """ + ) + .indented() + ) + .run() + .expect( + """ + src/test/pkg/test.kt:5: Warning: Do not use !! [NotNullAssertion] + s!!.plus(s) + ~~~ + src/test/pkg/test.kt:6: Warning: Do not use !! -- it's not even needed here [NotNullAssertion] + t!!.plus(t) + ~~~ + 0 errors, 2 warnings + """ + ) + } +} diff --git a/checks/src/test/java/com/example/lint/checks/SampleCodeDetectorTest.kt b/checks/src/test/java/com/example/lint/checks/SampleCodeDetectorTest.kt index fe476397..3f9afa37 100644 --- a/checks/src/test/java/com/example/lint/checks/SampleCodeDetectorTest.kt +++ b/checks/src/test/java/com/example/lint/checks/SampleCodeDetectorTest.kt @@ -19,31 +19,32 @@ import com.android.tools.lint.checks.infrastructure.TestFiles.java import com.android.tools.lint.checks.infrastructure.TestLintTask.lint import org.junit.Test -@Suppress("UnstableApiUsage") class SampleCodeDetectorTest { - @Test - fun testBasic() { - lint().files( - java( - """ - package test.pkg; - public class TestClass1 { - // In a comment, mentioning "lint" has no effect - private static String s1 = "Ignore non-word usages: linting"; - private static String s2 = "Let's say it: lint"; - } - """ - ).indented() - ) - .issues(SampleCodeDetector.ISSUE) - .run() - .expect( - """ - src/test/pkg/TestClass1.java:5: Warning: This code mentions lint: Congratulations [SampleId] - private static String s2 = "Let's say it: lint"; - ~~~~~~~~~~~~~~~~~~~~ - 0 errors, 1 warnings - """ - ) - } + @Test + fun testBasic() { + lint() + .files( + java( + """ + package test.pkg; + public class TestClass1 { + // In a comment, mentioning "lint" has no effect + private static String s1 = "Ignore non-word usages: linting"; + private static String s2 = "Let's say it: lint"; + } + """ + ) + .indented() + ) + .issues(SampleCodeDetector.ISSUE) + .run() + .expect( + """ + src/test/pkg/TestClass1.java:5: Warning: This code mentions lint: Congratulations [SampleId] + private static String s2 = "Let's say it: lint"; + ~~~~~~~~~~~~~~~~~~~~ + 0 errors, 1 warnings + """ + ) + } } diff --git a/docs/README.md.html b/docs/README.md.html index dd5a4108..4fa4bb40 100644 --- a/docs/README.md.html +++ b/docs/README.md.html @@ -36,6 +36,7 @@ - [A Sample Lint Check](api-guide/example.md.html) - [Analyzing data flow](api-guide/dataflow-analyzer.md.html) - [Publishing a Lint check](api-guide/publishing.md.html) + - [AST Analysis](api-guide/ast-analysis.md.html) - [Unit Testing](api-guide/unit-testing.md.html) - [Test Modes](api-guide/test-modes.md.html) - [Annotations](api-guide/annotations.md.html) @@ -51,15 +52,15 @@ - [Generating Issue Documentation](internal/document-checks.md.html) - [Testing dev builds](internal/verify.md.html) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +--------------------------------------------------------------------- Documentation History: * June 2022: Added documentation for [crafting error messages](messages.md.html) * May 2022: Noticed that the document rendering was broken, such that many chapters were missing from - the api-guide: "Adding Quickfixes", "Partial Analysis", - "Data Flow Analyzer", "Annotations", and "Options". + the api-guide: “Adding Quickfixes”, “Partial Analysis”, + “Data Flow Analyzer”, “Annotations”, and “Options”. These are now included. * November 2021: Added documentation for [option handling](api-guide/options.md.html) diff --git a/docs/api-guide.html b/docs/api-guide.html index 08663230..56a7eb25 100644 --- a/docs/api-guide.html +++ b/docs/api-guide.html @@ -1,6 +1,6 @@ - diff --git a/docs/api-guide/basics.md.html b/docs/api-guide/basics.md.html index 1cbbb3ac..e61e03c4 100644 --- a/docs/api-guide/basics.md.html +++ b/docs/api-guide/basics.md.html @@ -17,7 +17,7 @@ prefix to make it really clear that this is a static analysis tool intended for analysis of Android code, provided by the Android Open Source Project -- and to disambiguate it from the many other tools with -"lint“ in their names. +“lint” in their names. However, since then, Android Lint has broadened its support and is no longer intended only for Android code. In fact, within Google, it is @@ -35,7 +35,7 @@ not under our control (such as UAST and PSI). Therefore, custom lint checks may need to be updated periodically to keep working. -However, ”some APIs are more stable than others“. In particular, the +However, “some APIs are more stable than others”. In particular, the detector API (described below) is much less likely to change than the client API (which is not intended for lint check authors but for tools integrating lint to run within, such as IDEs and build systems). @@ -121,11 +121,11 @@ problems, and each one is called an `Issue`, which has associated metadata like a unique id, a category, an explanation, and so on. -Each instance that it finds is called an ”incident“. +Each instance that it finds is called an “incident”. The actual responsibility of searching for and reporting incidents is handled by detectors -- subclasses of `Detector`. Your lint check will -extend `Detector`, and when it has found a problem, it will ”report“ +extend `Detector`, and when it has found a problem, it will “report” the incident to lint. A `Detector` can analyze more than one `Issue`. For example, the @@ -134,7 +134,7 @@ multiple unrelated issues -- invalid formatting strings, formatting strings which should probably use the plurals API instead, mismatched types, and so on. The detector could simply have a single issue called -"StringFormatProblems” and report everything as a StringFormatProblem, +“StringFormatProblems” and report everything as a StringFormatProblem, but that's not a good idea. Each of these individual types of String format problems should have their own explanation, their own category, their own severity, and most importantly should be individually @@ -154,7 +154,7 @@ The name `Scope.JAVA_FILE` may make it sound like there should also be a `Scope.KOTLIN_FILE`. However, `JAVA_FILE` here really refers to both Java and Kotlin files since the analysis and APIs are identical - for both (using “UAST”, a universal abstract syntax tree). However, + for both (using “UAST”, a unified abstract syntax tree). However, at this point we don't want to rename it since it would break a lot of existing checks. We might introduce an alias and deprecate this one in the future. @@ -169,13 +169,13 @@ Many detector methods will pass in a `Context`, or a more specific subclass of `Context` such as `JavaContext` or `XmlContext`. This -allows lint to provide access to the detectors information they may -need, without passing in a lot of parameters (and allowing lint to add -additional data over time without breaking signatures). +allows lint to give the detectors information they may need, without +passing in a lot of parameters. It also allows lint to add additional data +over time without breaking signatures. The `Context` classes also provide many convenience APIs. For example, for `XmlContext` there are methods for creating locations for XML tags, -XML attributes, just the name part of an XML attribute and just the +XML attributes, just the name part of an XML attribute, and just the value part of an XML attribute. For a `JavaContext` there are also methods for creating locations, such as for a method call, including whether to include the receiver and/or the argument list. @@ -204,7 +204,7 @@ Lint's API has two halves: - The **Client API**: “Integrate (and run) lint from within a tool”. - For example, both the IDE and the build system uses this API to embed + For example, both the IDE and the build system use this API to embed and invoke lint to analyze the code in the project or editor. - The **Detector API**: “Implement a new lint check”. This is the API @@ -213,12 +213,12 @@ The class in the Client API which represents lint running in a tool is called `LintClient`. This class is responsible for, among other things: -* Reporting incidents found by detectors. For example, in the IDE, it +* **Reporting incidents found by detectors**. For example, in the IDE, it will place error markers into the source editor, and in a build system, it may write warnings to the console or generate a report or even fail the build. -* Handling I/O. Detectors should never read files from disk directly. +* **Handling I/O**. Detectors should never read files from disk directly. This allows lint checks to work smoothly in for example the IDE. When lint runs on the fly, and a lint check asks for the source file contents (or other supporting files), the `LintClient` in the IDE @@ -226,14 +226,13 @@ editors and if the requested file is being edited, it will return the current (often unsaved!) contents. -* Handling network traffic. Lint checks should never open - URLConnections themselves. By going through the lint API to request - data for a URL, not only can the LintClient for example use any - configured IDE proxy settings which is done in the IntelliJ - integration of lint, but even the lint check's own unit tests can - easily be tested because the special unit test implementation of a - `LintClient` provides a simple way to provide exact responses for - specific URLs: +* **Handling network traffic**. Lint checks should never open + URLConnections themselves. Instead, they should go through the lint API + to request data for URLs. Among other things, this allows the + `LintClient` to use configured IDE proxy settings (as is done in the + IntelliJ integration of lint). This is also good for testing, because + the special unit test implementation of a `LintClient` has a simple way + to provide exact responses for specific URLs: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lint() @@ -256,8 +255,8 @@ And much, much, more. **However, most of the implementation of `LintClient` is intended for integration of lint itself, and as a check -author you don't need to worry about it.** It's the detector API that -matters, and is also less likely to change than the client API. +author you don't need to worry about it.** The detector API will matter +more, and it's also less likely to change than the client API. !!! Tip The division between the two halves is not perfect; some classes @@ -273,8 +272,8 @@ for internal lint usage have been made `public` such that lint's code in one package can access it from the other. There's normally a comment explaining that this is for internal use only, but be aware - that just because something is `public` or not `final` it's a good - idea to call or override it. + that even when something is `public` or not `final`, it might not be a + good idea to call or override it. ## Creating an Issue @@ -283,7 +282,7 @@ [publishing](publishing.md.html) chapters. `Issue` is a final class, so unlike `Detector`, you don't subclass -it, you instantiate it via `Issue.create`. +it; you instantiate it via `Issue.create`. By convention, issues are registered inside the companion object of the corresponding detector, but that is not required. @@ -369,7 +368,7 @@ across a number of languages and technologies. Next, we have the **`briefDescription`**. You can think of this as a -"category report header“; this is a static description for all +“category report header”; this is a static description for all incidents of this type, so it cannot include any specifics. This string is used for example as a header in HTML reports for all incidents of this type, and in the IDE, if you open the Inspections UI, the various @@ -377,7 +376,7 @@ The **`explanation`** is a multi line, ideally multi-paragraph explanation of what the problem is. In some cases, the problem is self -evident, as in the case of ”Unused declaration“, but in many cases, the +evident, as in the case of “Unused declaration”, but in many cases, the issue is more subtle and might require additional explanation, particularly for what the developer should **do** to address the problem. The explanation is included both in HTML reports and in the @@ -392,7 +391,7 @@ \'s at the end of the lines. Note also that we have a Markdown-like simple syntax, described in the -"TextFormat” section below. You can use asterisks for italics or double +“TextFormat” section below. You can use asterisks for italics or double asterisks for bold, you can use apostrophes for code font, and so on. In terminal output this doesn't make a difference, but the IDE, explanations, incident error messages, etc, are all formatted using @@ -409,11 +408,11 @@ warning or an error. These are treated differently in the IDE (where errors are red underlines and warnings are yellow highlights), and in the build system (where errors can optionally break the build and -warnings do not). There are some other severities too; ”fatal“ is like +warnings do not). There are some other severities too; “fatal” is like error except these checks are designated important enough (and have very few false positives) such that we run them during release builds, even if the user hasn't explicitly run a lint target. There's also -"informational” severity, which is only used in one or two places, and +“informational” severity, which is only used in one or two places, and finally the “ignore” severity. This is never the severity you register for an issue, but it's part of the severities a developer can configure for a particular issue, thereby turning off that particular check. @@ -432,6 +431,7 @@ This is a \`code symbol\` | This is a `code symbol` This is `*italics*` | This is *italics* This is `**bold**` | This is **bold** +This is `~~strikethrough~~` | This is ~~strikethrough~~ http://, https:// | [](http://), [](https://) `\*not italics*` | `\*not italics*` \`\`\`language\n text\n\`\`\`| (preformatted text block) @@ -492,7 +492,7 @@ When a lint issue requires multiple scopes, that means lint will **only** run this detector if **all** the scopes are available in the running tool. When lint runs a full batch run (such as a Gradle lint -target or a full “Inspect Code“ in the IDE), all scopes are available. +target or a full “Inspect Code” in the IDE), all scopes are available. However, when lint runs on the fly in the editor, it only has access to the current file; it won't re-analyze *all* files in the project for @@ -509,7 +509,7 @@ correctly in all cases, but it can still identify *some* problems given individual source files. In this case, the `Implementation` constructor (which takes a vararg of scope sets) can be handed additional sets of -scopes, called ”analysis scopes“. If the current lint client's scope +scopes, called “analysis scopes”. If the current lint client's scope matches or is a subset of any of the analysis scopes, then the check will run after all. @@ -630,16 +630,16 @@ * When implementing **`SourceCodeScanner`**, in Kotlin and Java files you can be called back - - When a method of a given name is invoked (`getApplicableMethodNames` + - when a method of a given name is invoked (`getApplicableMethodNames` and `visitMethodCall`) - - When a class of the given type is instantiated + - when a class of the given type is instantiated (`getApplicableConstructorTypes` and `visitConstructor`) - - When a new class is declared which extends (possibly indirectly) + - when a new class is declared which extends (possibly indirectly) a given class or interface (`applicableSuperClasses` and `visitClass`) - - When annotated elements are referenced or combined + - when annotated elements are referenced or combined (`applicableAnnotations` and `visitAnnotationUsage`) - - When any AST nodes of given types appear (`getApplicableUastTypes` + - when any AST nodes of given types appear (`getApplicableUastTypes` and `createUastHandler`) * When implementing a **`ClassScanner`**, in `.class` and `.jar` files @@ -649,7 +649,7 @@ - when a given bytecode instruction occurs (`getApplicableAsmNodeTypes` and `checkInstruction`) - like with XmlScanner's `visitDocument`, you can perform your own - ASM bytecode iteration via `checkClass`. + ASM bytecode iteration via `checkClass` * There are various other scanners too, for example `GradleScanner` which lets you visit `build.gradle` and `build.gradle.kts` DSL @@ -676,12 +676,12 @@ the detector in fields and accumulate information for analysis at the end. -There are some callbacks both before each individual file is analyzed -(`beforeCheckFile` and `afterCheckFile`), as well as before and after -analysis of all the modules (`beforeCheckRootProject` and +There are some callbacks both before and after each individual file is +analyzed (`beforeCheckFile` and `afterCheckFile`), as well as before and +after analysis of all the modules (`beforeCheckRootProject` and `afterCheckRootProject`). -This is for example how the ”unused resources“ check works: we store +This is for example how the “unused resources” check works: we store all the resource declarations and resource references we find in the project as we process each file, and then in the `afterCheckRootProject` method we analyze the resource graph and @@ -714,10 +714,11 @@ example layouts are processed before value files like translations) 3. Kotlin and Java files 4. Bytecode (local `.class` files and library `.jar` files) -5. Gradle files -6. Other files -7. ProGuard files -8. Property Files +5. TOML files +6. Gradle files +7. Other files +8. ProGuard files +9. Property Files Similarly, lint will always process libraries before the modules that depend on them. @@ -726,7 +727,7 @@ If you need to access something from later in the iteration order, and it's not practical to store all the current data and instead handle it when the later data is encountered, note that lint has - support for ”multi-pass analysis“: it can run multiple times over + support for “multi-pass analysis”: it can run multiple times over the data. The way you invoke this is via `context.driver.requestRepeat(this, …)`. This is actually how the unused resource analysis works. Note however that this repeat is @@ -762,8 +763,7 @@ like the `ResourceRepository` and the `ResourceEvaluator`. * Finally, there are a number of utility methods; for example there is - an `editDistance` method used to find likely typos used by a number - of checks. + an `editDistance` method used to find likely typos. ## Scanner Example @@ -786,7 +786,7 @@ val incident = Incident(context, ISSUE) .message( "Use `` instead of ``") .at(element) - context.report(incident)) + context.report(incident) } } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -805,7 +805,7 @@ } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -The second, older form, may seem simpler, but the new API allows a lot +The second (older) form may seem simpler, but the new API allows a lot more metadata to be attached to the report, such as an override severity. You don't have to convert to the builder syntax to do this; you could also have written the second form as @@ -820,20 +820,20 @@ ### UAST To analyze Kotlin and Java code, lint offers an abstract syntax tree, -or ”AST“, for the code. +or “AST”, for the code. -This AST is called ”UAST“, for ”Universal Abstract Syntax Tree“, which +This AST is called “UAST”, for “Universal Abstract Syntax Tree”, which represents multiple languages in the same way, hiding the language specific details like whether there is a semicolon at the end of the statements or whether the way an annotation class is declared is as `@interface` or `annotation class`, and so on. This makes it possible to write a single analyzer which works -(”universally“) across all languages supported by UAST. And this is +across all languages supported by UAST. And this is very useful; most lint checks are doing something API or data-flow specific, not something language specific. If however you do need to implement something very language specific, see the next section, -"PSI”. +“PSI”. In UAST, each element is called a **`UElement`**, and there are a number of subclasses -- `UFile` for the compilation unit, `UClass` for @@ -880,7 +880,7 @@ (unless of course the Kotlin property specifies a private setter). If you’ve written code in Kotlin and have tried to access that Kotlin code from a Java file you will see the same thing -- the - “Java view” of Kotlin. The next section, “PSI“, will discuss how to + “Java view” of Kotlin. The next section, “PSI”, will discuss how to do more language specific analysis. ### UAST Example @@ -893,7 +893,7 @@ Line 1 says we want to have line 3 called whenever lint comes across a method to `setRepeating`. -On lines 8-4 we make sure we're talking about the correct method on the +On lines 8-14 we make sure we're talking about the correct method on the correct class with the correct signature. This uses the `JavaEvaluator` to check that the called method is a member of the named class. This is necessary because the callback would also be invoked if lint came @@ -955,7 +955,7 @@ To write your detector's analysis, you need to know what the AST for your code of interest looks like. Instead of trying to figure it out by examining the elements under a debugger, a simple way to find out is to -”pretty print“ it, using the `UElement` extension method +“pretty print” it, using the `UElement` extension method **`asRecursiveLogString`**. For example, given the following unit test: @@ -984,14 +984,14 @@ ``` (This also illustrates the earlier point about UAST representing the -Java view of the code; here the read-only public Kotlin property ”s“ is +Java view of the code; here the read-only public Kotlin property “s” is represented by both a private field `s` and a public getter method, `getS()`.) ### Resolving When you have a method call, or a field reference, you may want to take -a look at the called method or field. This is called ”resolving“, and +a look at the called method or field. This is called “resolving”, and UAST supports it directly; on a `UCallExpression` for example, call `.resolve()`, which returns a `PsiMethod`, which is like a `UMethod`, but may not represent a method we have source for (which for example @@ -1001,10 +1001,10 @@ !!! Warning Resolving only works if lint has a correct classpath such that the - referenced method, field or class are actually present. If it is + referenced method, field, or class is actually present. If it is not, resolve will return null, and various lint callbacks will not be invoked. This is a common source of questions for lint checks - ”not working“; it frequently comes up in lint unit tests where a + “not working”; it frequently comes up in lint unit tests where a test file will reference some API that isn't actually included in the class path. The recommended approach for this is to declare local stubs. See the [unit testing](unit-testing.md.html) chapter @@ -1054,7 +1054,7 @@ callback for the binary operator scenario shown above as well, passing you a call which has the right value arguments, method name, and so on. -The way this works is that lint can create a ”wrapper“ class which +The way this works is that lint can create a “wrapper” class which presents the underlying `UBinaryExpression` (or `UArrayAccessExpression` and so on) as a `UCallExpression`. In the case of a binary operator, the value parameter list will be the left and @@ -1066,7 +1066,7 @@ wrappers yourself, via `UBinaryExpression.asCall()`, `UUnaryExpression.asCall()`, and `UArrayAccessExpression.asCall()`. -There is also a visitor you can use to visit call calls -- +There is also a visitor you can use to visit all calls -- `UastCallVisitor`, which will visit all calls, including those from array accesses and unary operators and binary operators. @@ -1078,7 +1078,7 @@ ### PSI -PSI is short for ”Program Structure Interface“, and is IntelliJ's AST +PSI is short for “Program Structure Interface”, and is IntelliJ's AST abstraction used for all language modeling in the IDE. Note that there is a **different** PSI representation for each @@ -1087,7 +1087,7 @@ writing a lot of logic twice; once for Java, and once for Kotlin. (And the Kotlin PSI is a bit trickier to work with.) -That's what UAST is for: there's a ”bridge“ from the Java PSI to UAST +That's what UAST is for: there's a “bridge” from the Java PSI to UAST and there's a bridge from the Kotlin PSI to UAST, and your lint check just analyzes UAST. @@ -1112,7 +1112,7 @@ instead of `uastParent`), so be sure to configure it for your project. -When you are dealing with ”signatures“ -- looking at classes and +When you are dealing with “signatures” -- looking at classes and class inheritance, methods, parameters and so on -- using PSI is fine -- and unavoidable since UAST does not represent bytecode (though in the future it potentially could, via a decompiler) diff --git a/docs/api-guide/changes.md.html b/docs/api-guide/changes.md.html index 1f0816c0..dc87c11e 100644 --- a/docs/api-guide/changes.md.html +++ b/docs/api-guide/changes.md.html @@ -5,6 +5,142 @@ information about user visible changes to lint, see the User Guide. +**8.9** + +* Lint's testing infrastructure support for testing quickfixes + (`expectFixDiffs()`) now also validates that the modified + source file is valid Kotlin, Java or XML. You can control + this using the `lint().verifyFixedFileSyntax()` option. + +**8.8** + +* For the string-replacement quickfix, you can now specify + regex flags (such as Pattern.DOT_ALL) to change the pattern + matching behavior. + +**8.7** + +* The unit testing support now checks to make sure that you + don't have duplicate class names across Java and Kotlin + (which can lead to subtle and confusing errors.) +* The `build.gradle.kts` unit testing support (`TestFiles.kts()`) + now performs the same mocking of the builder model that the + corresponding Groovy Gradle support (`Testfiles.gradle()`) + performs. Among other things, this means that the other + source files (`java()`, `kotlin()`, etc) must be located in + source sets, e.g. `src/main/res/` and `/src/main/java/` + rather than just `res/` and `src/`. This happens automatically + if you don't manually specify a target path in the test file + declaration. + +**8.6** + +* UAST repeats @JvmOverloaded methods in the AST. Lint now looks for + and skips these duplications, and a new test mode also looks for + potential problems in third party checks. +* Added a new chapter to the api-guide on AST analysis, and in + particular, using the Kotlin Analysis API. +* The `UElementHandler` now supports recently added UAST element + types: `UPatternExpression` and `UBinaryExpressionWithPattern`. +* There's a new test mode checking for issues related to + `@JvmOverloads`. See the [test modes](test-modes.md.html) chapter + for more. + +**8.4** + +* You can now use `~~` in text messages (error messages, issue + explanations, etc) to create strikethrough text. For example, “`Don't + do this: ~~super.onCreate()~~`” will render as “Don't do this: + ~~super.onCreate()~~”. + +**8.3** + +* If you'd like to change your error message reported by your + detector, you can now override your `Detector`'s `sameMessage` + method: match the details in the previous error message with the + new format. This is used by the baseline mechanism such that your + message change doesn't suddenly invalidate all existing baseline + files for your issue. + +* The replace-string quickfix descriptor now lets you replace a string + repeatedly. Example: + ``` + fix().replace().text("Foo").with("Bar").repeatedly().build() + ``` + + You can also match an element optionally. Example: + ``` + fix().composite( + fix().replace().text("").with("").build(), + fix().replace().text("").with("").optional().build() + ) + ``` + +* The quickfix machinery was improved significantly. It now does a + better job inserting imports (in alphabetical order instead of always + prepending to the import list), inserting new XML attributes in the + right canonical Android order, cleaning up whitespace after edits, + etc. This may result in some diffs in any quickfix-related unit tests + (e.g. `lint().run().expectFixDiffs(...)`) + +* The `getFileNameWithParent` utility method now always uses / as + a file separator instead of the platform-specific one (e.g. \ on + Windows). This ensures that baselines don't vary their error + messages (where this utility method is typically used) based on + which OS they were generated on. + +**8.2** + +* For unit tests, you can now specify the language level to be used + for Kotlin and Java. For example, if your unit test is using Java + records, add `.javaLanguageLevel("17")` to your `lint()` test + configuration. + +**8.1** + +* The [data flow analyzer](dataflow-analyzer.md.html) has been + improved; in addition to fixing a few bugs, there are a couple of + new convenience sub classes which makes common tasks easier to + accomplish; see the documentation for `TargetMethodDataFlowAnalyzer` + for example. + +* The new `mavenLibrary` (and `binaryStub`) test files make it simple + to create binary stub files in your tests, without having to perform + compilation and check in base64 and gzip encoded test files. When + your detector resolves references, the PSI elements you get back + differ whether you're calling into source or into binary (jar/.class + file) elements, so testing both (which the new test files automate + using test modes) is helpful. More information about this is + available in [](unit-testing.md.html). + +* Lint now supports analyzing TOML files. There is a new + Scope.TOML_FILE detectors can register an interest in, a new + TomlScanner interface to implement for visitTomlDocument callbacks, + etc. From a GradleScanner, you can directly resolve version catalog + libraries via lookup methods on the GradleContext. + +* Lint's “diff” output for unit test verification has been improved; + it's now smarter about combining nearby chunks. (This should not + break existing tests; the test infrastructure will try the older + format as a fallback if the diffs aren't matching for the new + format.) + +* Lint contains JVM 17 bytecode. You will now need to use JDK 17+ + when compiling custom Lint checks. You should also configure + the Kotlin compiler to target JVM 17, otherwise you may see errors + when calling inline functions declared in Lint, UAST, or PSI. + +* Lint's testing infrastructure now looks not just for test/ + but also androidTest/ and testFixtures/ to set the corresponding + source set type on each test context. + +**8.0** + +* A new testmode which makes sure lint checks are all suppressible. + It analyzes the reported error locations from the expected test + output, and inserts suppress annotations in XML, Kotlin and Java + files and makes sure that the corresponding warnings disappear. + **7.4** * Annotation detectors can now specify just an annotation name instead @@ -122,7 +258,7 @@ It also offers better control for handling scopes -- providing all relevant annotations in the hierarchy at the same time such that a lint check for example can easily determine whether an outer - annotation like `@Immutable` is canceled by a closer @Mutable` + annotation like `@Immutable` is canceled by a closer `@Mutable` annotation. There are some new annotation usage type enum constants which let @@ -242,7 +378,7 @@ Previously only `visitMethodCall()` was triggered. * Quickfixes can now create and delete new files; see - `LintFix#newFile` and `LintFix#deleteFile`.. + `LintFix#newFile` and `LintFix#deleteFile`. * For quickfixes, the `independent` property had inverted logic; this has now been reversed to follow the meaning of the name. diff --git a/docs/api-guide/dataflow-analyzer.md.html b/docs/api-guide/dataflow-analyzer.md.html index a94bc2a5..1af02645 100644 --- a/docs/api-guide/dataflow-analyzer.md.html +++ b/docs/api-guide/dataflow-analyzer.md.html @@ -44,6 +44,13 @@ `DataFlowAnalyzer` class, and override one or more of its callbacks, and then tell it to analyze a method scope. +!!! Tip + In recent versions of lint, there is a new special subclass of the + `DataFlowAnalyzer`, `TargetMethodDataFlowAnalyzer`, which makes it + easier to write flow analyzers where you are looking for a specific + “cleanup” or close function invoked on an instance. See the separate + section on `TargetMethodDataFlowAnalyzer` below for more information. + For the above transaction scenario, it might look like this: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers @@ -76,7 +83,7 @@ } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Aas you can see, the `DataFlowAnalyzer` is a visitor, so when we find a +As you can see, the `DataFlowAnalyzer` is a visitor, so when we find a call we're interested in, we construct a `DataFlowAnalyzer` and initialize it with the instance we want to track, and then we visit the surrounding method with this visitor. @@ -247,8 +254,8 @@ call. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers -fun test) { - val transaction = getFragmentManager().beginTransaction() +fun test() { + val transaction = getFragmentManager().beginTransaction() process(transaction) } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -303,6 +310,12 @@ case you want to perform additional analysis to track field values; see the next section. +!!! Tip + There is a special subclass of the `DataFlowAnalyzer`, called + `EscapeCheckingDataFlowAnalyzer`, which you can extend instead. This + handles recording all the scenarios where the instance escapes from + the method, and at the end you can just check its `escaped` property. + ## Non Local Analysis In the above examples, if we found that the value escaped via a return @@ -347,4 +360,40 @@ [Source](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/SliceDetector.kt) [Test](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/SliceDetectorTest.kt) +## TargetMethodDataFlowAnalyzer + +The `TargetMethodDataFlowAnalyzer` is a special subclass of the +`DataFlowAnalyzer` which makes it simple to see if you eventually wind up +calling a target method on a particular instance. For example, calling +`close` on a file that was opened, or calling `start` on an animation you +created. + +In addition, there is an extension function on `UMethod` which visits +this analyzer, and then checks for various conditions, e.g. whether the +instance “escaped” (for example by being stored in a field or passed to +another method), in which case you probably don't want to conclude (and +report) that the close method is never called. It also handles failures +to resolve, where it remembers whether there was a resolve failure, and +if so it looks to see if it finds a likely match (with the same name as +the target function), and if so also makes sure you don't report a false +positive. + +A simple way to do this is as follows: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +val targets = mapOf("show" to listOf("android.widget.Toast", + "com.google.android.material.snackbar.Snackbar") +val analyzer = TargetMethodDataFlowAnalyzer.create(node, targets) +if (method.isMissingTarget(analyzer)) { + context.report(...) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can subclass `TargetMethodDataFlowAnalyzer` directly and override the +`getTargetMethod` methods and any other UAST visitor methods if you want +to customize the behavior further. + +One advantage of using the `TargetMethodDataFlowAnalyzer` is that it also +correctly handles method references. + diff --git a/docs/api-guide/example.md.html b/docs/api-guide/example.md.html index 0442bac9..51c93d7c 100644 --- a/docs/api-guide/example.md.html +++ b/docs/api-guide/example.md.html @@ -301,7 +301,7 @@ relevant node types (literal expressions, on line 18) and visiting them on line 23. Lint has a large number of convenience APIs for doing higher level things, such as “call this callback when somebody extends -this class”, or “when somebody calls a method named ”foo“, and so on. +this class”, or “when somebody calls a method named `foo`”, and so on. Explore the `SourceCodeScanner` and other `Detector` interfaces to see what's possible. We'll hopefully also add more dedicated documentation for this. diff --git a/docs/api-guide/faq.md.html b/docs/api-guide/faq.md.html index 83e3ca13..d0a9ac87 100644 --- a/docs/api-guide/faq.md.html +++ b/docs/api-guide/faq.md.html @@ -110,14 +110,14 @@ ### How do I get the `UMethod` for a `PsiMethod` ? -Call `psiMethod.toUElementOfType()`. Note that this may return +Call `psiMethod.toUElementOfType<UMethod>()`. Note that this may return null if UAST cannot find valid Java or Kotlin source code for the method. For `PsiField` and `PsiClass` instances use the equivalent `toUElementOfType` type arguments. -### How do get a `JavaEvaluator` ? +### How do get a `JavaEvaluator`? The `Context` passed into most of the `Detector` callback methods relevant to Kotlin and Java analysis is of type `JavaContext`, and it @@ -173,7 +173,7 @@ abstract fun getTypeClass(psiType: PsiType?): PsiClass? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -### How do I look up hierarhcy annotations for an element? +### How do I look up hierarchy annotations for an element? You can directly look up annotations via the modified list of PsiElement or the annotations for a `UAnnotated` element, @@ -254,7 +254,7 @@ open fun computeArgumentMapping( call: UCallExpression, method: PsiMethod - ): Map { /* ... */ + ): Map<UExpression, PsiParameter> { /* ... */ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This returns a map from UAST expressions (each argument to a UAST call @@ -290,7 +290,7 @@ ### Why are overloaded operators not handled? Kotlin supports overloaded operators, but these are not handled as -calls in the AST - instead, an implicit `get` or `set` method from an +calls in the AST -- instead, an implicit `get` or `set` method from an array access will show up as a `UArrayAccessExpression`. Lint has specific support to help handling these scenarios; see the “Implicit Calls” section in the [basics chapter](basics.md.html). @@ -324,4 +324,12 @@ browse sources online: [](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/) +### How do I analyze details about Kotlin? + +The new Kotlin Analysis API offers access to detailed information about +Kotlin (types, resolution, as well as information the compiler has +figured out such as smart casts, nullability, deprecation info, and so +on). There are more details about this, as well as a number of recipes, +in the [AST Analysis chapter](ast-analysis.md.html). + diff --git a/docs/api-guide/images/java-psi.png b/docs/api-guide/images/java-psi.png new file mode 100644 index 00000000..35df46c5 Binary files /dev/null and b/docs/api-guide/images/java-psi.png differ diff --git a/docs/api-guide/images/kotlin-psi.png b/docs/api-guide/images/kotlin-psi.png new file mode 100644 index 00000000..40ebb087 Binary files /dev/null and b/docs/api-guide/images/kotlin-psi.png differ diff --git a/docs/api-guide/images/uast-if.png b/docs/api-guide/images/uast-if.png new file mode 100644 index 00000000..b63d03a0 Binary files /dev/null and b/docs/api-guide/images/uast-if.png differ diff --git a/docs/api-guide/images/uast-java.png b/docs/api-guide/images/uast-java.png new file mode 100644 index 00000000..23314e08 Binary files /dev/null and b/docs/api-guide/images/uast-java.png differ diff --git a/docs/api-guide/images/uast-kotlin-val.png b/docs/api-guide/images/uast-kotlin-val.png new file mode 100644 index 00000000..c34bd9c9 Binary files /dev/null and b/docs/api-guide/images/uast-kotlin-val.png differ diff --git a/docs/api-guide/images/uast-kotlin.png b/docs/api-guide/images/uast-kotlin.png new file mode 100644 index 00000000..57b66ade Binary files /dev/null and b/docs/api-guide/images/uast-kotlin.png differ diff --git a/docs/api-guide/images/uast-sourcepsi-type.png b/docs/api-guide/images/uast-sourcepsi-type.png new file mode 100644 index 00000000..c30290ba Binary files /dev/null and b/docs/api-guide/images/uast-sourcepsi-type.png differ diff --git a/docs/api-guide/images/uast-sourcepsi.png b/docs/api-guide/images/uast-sourcepsi.png new file mode 100644 index 00000000..02bd5532 Binary files /dev/null and b/docs/api-guide/images/uast-sourcepsi.png differ diff --git a/docs/api-guide/messages.md.html b/docs/api-guide/messages.md.html index 2267cc21..496677aa 100644 --- a/docs/api-guide/messages.md.html +++ b/docs/api-guide/messages.md.html @@ -29,6 +29,7 @@ This is a \`code symbol\` | This is a `code symbol` This is `*italics*` | This is *italics* This is `**bold**` | This is **bold** +This is `~~strikethrough~~` | This is ~~strikethrough~~ http://, https:// | [](http://), [](https://) `\*not italics*` | `\*not italics*` \`\`\`language\n text\n\`\`\`| (preformatted text block) @@ -40,7 +41,7 @@ ## Punctuation -One line error messages should not be punctuated - e.g. the error message +One line error messages should not be punctuated -- e.g. the error message should be “Unused import foo”, not “Unused import foo.” However, if there are multiple sentences in the error message, all sentences @@ -68,7 +69,7 @@ When referring to Android behaviors introduced in new API levels, use the phrase “In Android 12 and higher”, instead of variations like “Android S” or -"API 31“. +“API 31”. ## Keep Messages Stable @@ -86,15 +87,27 @@ * Adding a suffix * Adding a suffix which also changes the final punctuation; e.g. changing - ”Hello.“ to ”Hello, world!“ is compatible. + “Hello.” to “Hello, world!” is compatible. * Adding a prefix +## Plurals + +Avoid trying to make sentences gramatically correct and flexible by +using constructs like “(s)” to quantity strings. In other words, +instead of for example saying + + *“register your receiver(s) in the manifest”* + +just use the plural form, + + *“register your receivers in the manifest”* + ## Examples Here are some examples from lint's built-in checks. Note that these are not chosen as great examples of clear error messages; most of these were written by engineers without review from a tech writer. But for better or worse they -reflect the ”tone“ of the built-in lint checks today. (These were derived from +reflect the “tone” of the built-in lint checks today. (These were derived from lint's unit test suite, which explains silly symbols like `test.pkg` in the error messages.) @@ -127,8 +140,8 @@ * [BlockedPrivateApi] Reflective access to NETWORK_TYPES is forbidden when targeting API 28 and above * [BottomAppBar] This \`BottomAppBar\` must be wrapped in a \`CoordinatorLayout\` (\`android.support.design.widget.CoordinatorLayout\`) * [BrokenIterator] \`Vector#listIterator\` was broken in API 24 and 25; it can return \`hasNext()=false\` before the last element. Consider switching to \`ArrayList\` with synchronization if you need it. -* [ButtonCase] @android:string/yes actually returns ”OK“, not ”Yes“; use @android:string/ok instead or create a local string resource for Yes -* [ButtonOrder] OK button should be on the right (was ”OK | Cancel“, should be ”Cancel | OK“) +* [ButtonCase] @android:string/yes actually returns “OK”, not “Yes”; use @android:string/ok instead or create a local string resource for Yes +* [ButtonOrder] OK button should be on the right (was “OK | Cancel”, should be “Cancel | OK”) * [ButtonStyle] Buttons in button bars should be borderless; use \`style="?android:attr/buttonBarButtonStyle"\` (and \`?android:attr/buttonBarStyle\` on the parent) * [ByteOrderMark] Found byte-order-mark in the middle of a file * [CanvasSize] Calling \`Canvas.getWidth()\` is usually wrong; you should be calling \`getWidth()\` instead diff --git a/docs/api-guide/partial-analysis.md.html b/docs/api-guide/partial-analysis.md.html index 68553443..a004774b 100644 --- a/docs/api-guide/partial-analysis.md.html +++ b/docs/api-guide/partial-analysis.md.html @@ -308,8 +308,8 @@ represents it. To report an incident you simply call `context.report(incident)`. There are several ways to create these incidents. The easiest is to simply edit your existing call above by -adding `Incident(` (or from Java, `new Incident(`) inside the -`context.report` block like this: +putting it inside `Incident(...)` (in Java, `new Incident(...)`) inside +the `context.report` block like this: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin context.report(Incident( @@ -390,7 +390,7 @@ from the `Constraints` class. Recording an incident with a constraint is easy; first construct the -`Incident` as before, and then report them via +`Incident` as before, and then report it via `context.report(incident, constraint)`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java @@ -403,7 +403,7 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Finally, note that you can combine constraints; there are both “and” -and “or” operators defined for the `Constraint` class. so the following +and “or” operators defined for the `Constraint` class, so the following is valid: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin @@ -497,7 +497,7 @@ [UnusedResourceDetector](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/UnusedResourceDetector.java), which locates unused resources. This “requires” global analysis, since we want to include all resources in the entire project. We also cannot just store lists of “resources declared” and -"resources referenced“ since we really want to treat this as a graph. +“resources referenced” since we really want to treat this as a graph. For example if `@layout/main` is including `@drawable/icon`, then a naive approach would see the icon as referenced (by main) and therefore mark it as not unused. But what we want is that if the icon is **only** diff --git a/docs/api-guide/publishing.md.html b/docs/api-guide/publishing.md.html index b2973c52..cfa3f4aa 100644 --- a/docs/api-guide/publishing.md.html +++ b/docs/api-guide/publishing.md.html @@ -52,7 +52,7 @@ ### lintPublish Configuration The Android Gradle library plugin provides some special configurations, -`lintConfig` and `lintPublish`. +`lintChecks` and `lintPublish`. The `lintPublish` configuration lets you reference another project, and it will take that project's output jar and package it as a `lint.jar` @@ -94,7 +94,7 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ apply plugin: 'com.android.application' dependencies { - lintConfig project(':checks') + lintChecks project(':checks') // other dependencies } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -126,7 +126,7 @@ * and is no longer registered, any existing mentions of the issue * id in baselines, lint.xml files etc are gracefully handled. */ -open val deletedIssues: List = emptyList() +open val deletedIssues: List<String> = emptyList() ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The reason you'll want to do this is listed right there in the doc: If @@ -136,7 +136,7 @@ is done to catch issue id typos. And if the user has a baseline file listing incidents from your check, then if your issue id is not registered as deleted, lint will think this is an issue that has been -"fixed“ since it's no longer reported, and lint will issue an +“fixed” since it's no longer reported, and lint will issue an informational message that the baseline contains issues no longer reported (which is done such that users can update their baseline files, to ensure that the fixed issues aren't reintroduced again.) diff --git a/docs/api-guide/quickfixes.md.html b/docs/api-guide/quickfixes.md.html index 909b2696..68d77af2 100644 --- a/docs/api-guide/quickfixes.md.html +++ b/docs/api-guide/quickfixes.md.html @@ -5,7 +5,7 @@ ## Introduction When your detector reports an incident, it can also provide one or more -"quick fixes“, which are actions the users can invoke in the IDE (or, +“quick fixes”, which are actions the users can invoke in the IDE (or, for safe fixes, in batch mode) to address the reported incident. For example, if the lint check reports an unused resource, a quick fix @@ -47,12 +47,12 @@ ## Creating a LintFix -Lint fixes use a ”fluent API“; you first construct a `LintFix`, and on +Lint fixes use a “fluent API”; you first construct a `LintFix`, and on that method you call various available type methods, which will then further direct you to the allowed options. For example, to create a lint fix to set an XML attribute of a given -name to ”true“, use something like this: +name to “true”, use something like this: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin LintFix fix = fix().set(null, "singleLine", "true").build() @@ -68,10 +68,10 @@ * `name`: Sets the description of the lint fix. This should be brief; it's in the quickfix popup shown to the user. -* `sharedName`: This sets the ”shared“ or ”family“ name: all fixes in +* `sharedName`: This sets the “shared” or “family” name: all fixes in the file will with the same name can be applied in a single - invocation by the user. For example, if you register 500 ”Remove - unused import“ quickfixes in a file, you don't want to force the user + invocation by the user. For example, if you register 500 “Remove + unused import” quickfixes in a file, you don't want to force the user to have to invoke each and every one. By setting the shared name, the user will be offered to **Fix All *$family name* problems in the current file**, which they can then perform to have all 500 @@ -93,7 +93,7 @@ beginning? At the end? Therefore, lint has the `autoFix` property you can set on a quickfix. - This indicates that this fix is ”safe“ and can be performed in batch + This indicates that this fix is “safe” and can be performed in batch mode. When the `lintFix` target runs, it will only apply fixes marked safe in this way. @@ -103,7 +103,7 @@ * `fix().replace`: String replacements. This is the most general mechanism, and allows you to perform arbitrary edits to the source - code. In addition to the obvious ”replace old string with new“, the + code. In addition to the obvious “replace old string with new”, the old string can use a different location range than the incident range, you can match with regular expressions (and perform replacements on a specific group within the regular expression), and @@ -161,11 +161,11 @@ !!! Tip If you use the `todo()` quickfix, it's a good idea to special case - your lint check to deliberately not accept ”TODO“ as a valid value. + your lint check to deliberately not accept “TODO” as a valid value. For example, for lint's accessibility check which makes sure you set a content description, it will complain both when you haven't set the content description attribute, **and** if the text is set to - ”TODO“. That way, if the user applies the quickfix, which creates + “TODO”. That way, if the user applies the quickfix, which creates the attribute in the right place and moves the focus to the right place, the editor is still showing a warning that the content description should be set. @@ -173,10 +173,10 @@ * `fix().unset`: Remove XML attribute. This is a special case of add attribute. -* `fix().url`: Show URL. In some cases, you can't ”fix“ or do anything +* `fix().url`: Show URL. In some cases, you can't “fix” or do anything local to address the problem, but you really want to direct the user's attention to additional documentation. In that case, you can - attach a ”show this URL“ quick fix to the incident which will open + attach a “show this URL” quick fix to the incident which will open the browser with the given URL when invoked. For example, in a complicated deprecation where you want users to migrate from one approach to a completely different one that you cannot automate, you @@ -207,10 +207,10 @@ Both scenarios have their uses, so lint makes this explicit: -- `fix().composite`: create a ”composite“ fix, which composes the fix +- `fix().composite`: create a “composite” fix, which composes the fix out of multiple individual fixes, or -- `fix().alternatives`: create an ”alternatives“ fix, which holds a +- `fix().alternatives`: create an “alternatives” fix, which holds a number of individual fixes, which lint will present as separate options to the user. @@ -229,8 +229,8 @@ And here's an example of how to create an alternatives fix, which are offered to the user as separate options; this is from our earlier example of the accessibility check which requires you to set a content -description, which can be set either on the ”text“ attribute or the -"contentDescription” attribute: +description, which can be set either on the “text” attribute or the +“contentDescription” attribute: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin val fix = fix().alternatives( @@ -297,6 +297,17 @@ ) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## Verifying Quickfixes + +Lint's test support will also attempt to verify that your quickfixes +still produces a valid Kotlin, Java or XML source file. It does this +by parsing these files after testing the quickfixes using +`expectFixDiffs()`. It will only complain if the fixed source file didn't +already have parsing errors *before* applying the fix. + +You can control this behavior using the `.verifyFixedFileSyntax()` method +on the `lint()` task. + ## Emitting quick fix XML to apply on CI Note that the `lint` has an option (`--describe-suggestions`) to emit diff --git a/docs/api-guide/terminology.md.html b/docs/api-guide/terminology.md.html index b9cf4347..477f4675 100644 --- a/docs/api-guide/terminology.md.html +++ b/docs/api-guide/terminology.md.html @@ -9,7 +9,7 @@ Configuration : A configuration provides extra information or parameters to lint on a - per project, or even per directory basis. For example, the `lint.xml` + per-project, or even per-directory, basis. For example, the `lint.xml` files can change the severity for issues, or list incidents to ignore (matched for example by a regular expression), or even provide values for options read by a specific detector. @@ -17,7 +17,7 @@ Context : An object passed into detectors in many APIs, providing data about (for example) which file is being analyzed (and in which project), - and for specific types of analysis additional information; for + and (for specific types of analysis) additional information; for example, an XmlContext points to the DOM document, a JavaContext includes the AST, and so on. @@ -97,7 +97,7 @@ Java and Kotlin files, there is a scope for .class files, and so on. Typically lint cares about which **set** of scopes apply, - so most of the APIs take an `EnumSet< Scope>`, but we'll often + so most of the APIs take an `EnumSet<Scope>`, but we'll often refer to this as just “the scope” instead of the “scope set”. Severity diff --git a/docs/api-guide/test-modes.md.html b/docs/api-guide/test-modes.md.html index bca73fee..18749ed4 100644 --- a/docs/api-guide/test-modes.md.html +++ b/docs/api-guide/test-modes.md.html @@ -9,7 +9,7 @@ There are a number of built-in test modes: -* Test modes which makes small tweaks to the source files which +* Test modes which make small tweaks to the source files which should be compatible, such as * Inserting unnecessary parentheses * Replacing imported symbols with fully qualified names @@ -18,10 +18,6 @@ * Reordering Kotlin named arguments * Replacing simple functions with Kotlin expression bodies * etc -* A test mode which changes that detectors are correctly handling - Kotlin literal expressions by running them both with and without - the upcoming UiInjectionHost mode which will change the - representation of strings in an upcoming Kotlin version * A partial analysis test mode which runs the tests in “partial analysis” mode; two phases, analysis and reporting, with minSdkVersion set to 1 during analysis and set to the true test @@ -36,7 +32,7 @@ `skipTestModes` DSL method, as described below. You can also add in your own test modes. For example, lint adds its own -internal test mode for making sure the built-in annotation checks works +internal test mode for making sure the built-in annotation checks work with Android platform annotations in the following test mode: [](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AndroidPlatformAnnotationsTestMode.kt) @@ -322,7 +318,7 @@ last argument is a literal expression such as a number or a String. You *can't* just use `if (call.valueArguments.lastOrNull() is ULiteralExpression)`, because that first argument could be a -`UParenthesizedExpression`, as in `call(1, true, ("hello")), so you'd +`UParenthesizedExpression`, as in `call(1, true, ("hello"))`, so you'd need to look inside the parentheses. UAST comes with two functions to help you handle this correctly: @@ -360,7 +356,7 @@ (("foo".chars()).allMatch { (it.dec() > 0) }).toString() ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -By default the parenthesis mode limits itself to "likely" unnecessary +By default the parenthesis mode limits itself to “likely” unnecessary parentheses; in particular, it won't put extra parenthesis around simple literals, like (1) or (false). You can explicitly construct `ParenthesizedTestMode(includeUnlikely=true)` if you want additional @@ -458,7 +454,7 @@ ### Whitespace Mode -This test mode inserts a number of "unnecessary" whitespace characters +This test mode inserts a number of “unnecessary” whitespace characters in valid places in the source code. This helps catch bugs where lint checks are improperly making @@ -517,4 +513,81 @@ string resources, and will convert regular text into `CDATA` and makes sure the results continue to be the same. +### Suppressible Mode + +Users should be able to ignore lint warnings by inserting suppress annotations +(in Kotlin and Java), and via `tools:ignore` attributes in XML files. + +This normally works for simple checks, but if you are combining results from +different parts of the code, or for example caching locations and reporting +them later, this is sometimes broken. + +This test mode looks at the reported warnings from your unit tests, and then +for each one, it looks up the corresponding error location's source file, and +inserts a suppress directive at the nearest applicable location. It then +re-runs the analysis, and makes sure that the warning no longer appears. + +### @JvmOverloads Test Mode + +When UAST comes across a method like this: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin +@JvmOverloads +fun test(parameter: Int = 0) { + implementation() +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +it will “inline” these two methods in the AST, such that we see the whole +method body twice: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin +fun test() { + implementation() +} + +fun test(parameter: Int) { + implementation() +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +If there were additional default parameters, there would be additional +repetitions. + +This is similar to what the compiler does, since Java doesn't have +default arguments, but the compiler will actually just generate some +trampoline code to jump to the implementation with all the parameters; +it will NOT repeat the method implementation: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin +fun test(parameter: Int) { + implementation() +} + +// $FF: synthetic method +fun `test$default`(var0: Int, var1: Int, var2: Any?) { + var var0 = var0 + if ((var1 and 1) != 0) { + var0 = 0 + } + + test(var0) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Again, UAST will instead just repeat the method body. And this means +lint detectors may trigger repeatedly on the same code. In most cases +this will result in duplicated warnings. But it can also lead to other +problems; for example, a lint check which makes sure you don't have any +code duplication would incorrectly believe code fragments are repeated. + +Lint already looks for this situation and avoids visiting duplicated +methods in its shared implementations (which is dispatching to most +`Detector` callbacks). However, if you manually visit a class yourself, +you can run into this problem. + +This test mode simulates this situation by finding all methods where +it can safely add at least one default parameter, and marks it +@JvmOverloaded. It then makes sure the results are the same as before. + diff --git a/docs/api-guide/unit-testing.md.html b/docs/api-guide/unit-testing.md.html index 4e849770..a31d56c8 100644 --- a/docs/api-guide/unit-testing.md.html +++ b/docs/api-guide/unit-testing.md.html @@ -174,7 +174,7 @@ ## Trimming indents? Notice how in the above Kotlin unit tests we used raw strings, **and** -we indented the sources to be flush with the opening “”“ string +we indented the sources to be flush with the opening `"""` string delimiter. You might be tempted to call `.trimIndent()` on the raw string. @@ -257,10 +257,10 @@ `RecyclerView`. But how does lint know what `RecyclerView` is? If it doesn't, type resolve won't work, and as a result the detector won't. -You could make your test ”depend“ on the `RecyclerView`. This is +You could make your test “depend” on the `RecyclerView`. This is possible, using the `LibraryReferenceTestFile`, but is not recommended. -Instead, the recommended approach is to just use ”stubs“; create +Instead, the recommended approach is to just use “stubs”; create skeleton classes which represent only the **signatures** of the library, and in particular, only the subset that your lint check cares about. @@ -338,10 +338,65 @@ ## Binary and Compiled Source Files -If you need to use binaries in your unit tests, there is -a special test file type for that: base64gzip. Here's an -example from a lint check which tries to recognize usage -of Cordova in the bytecode: +If you need to use binaries in your unit tests, there are two options: + + 1. base64gzip + 2. API stubs + +If you want to analyze bytecode of method bodies, you'll need to use +the first option. + +The first type requires you to actually compile your test file into a +set of .class files, and check those in as a gzip-compressed, base64 +encoded string. Lint has utilities for this; see the next section. + +The second option is using API stubs. For simple stub files (where you +only need to provide APIs you'll call as binaries, but not code), lint +can produce the corresponding bytecode on the fly, so you don't need +to pre-create binary contents of the class. This is particularly +helpful when you just want to create stubs for a library your lint +check is targeting and you want to make sure the detector is seeing +the same types of elements as it will when analyzing real code outside +of tests (since there is a difference between resolving into APIs from +source and form binaries; when you're analyzing calls into source, you +can access for example method bodies, and this isn't available via +UAST from byte code.) + +These test files also let you specify an artifact name instead of a +jar path, and lint will use this to place the jar in a special place +such that it recognizes it (via `JavaEvaluator.findOwnerLibrary`) as +belonging to this library. + +Here's an example of how you can create one of these binary stub +files: + +``` +fun testIdentityEqualsOkay() { + lint().files( + kotlin( + "/*test contents here *using* some recycler view APIs*/" + ).indented(), + mavenLibrary( + "androidx.recyclerview:recyclerview:1.0.0", + java( + """ + package androidx.recyclerview.widget; + public class DiffUtil { + public abstract static class ItemCallback { + public abstract boolean areItemsTheSame(T oldItem, T newItem); + public abstract boolean areContentsTheSame(T oldItem, T newItem); + } + } + """ + ).indented() + ) + ).run().expect( +``` + +## Base64-encoded gzipped byte code + +Here's an example from a lint check which tries to recognize usage of +Cordova in the bytecode: ``` fun testVulnerableCordovaVersionInClasses() { @@ -357,11 +412,11 @@ "BwAAAAIAAQAIAAkAAQAKAAAAHQABAAEAAAAFKrcAAbEAAAABAAsAAAAGAAEA" + "AAAEAAgADAAJAAEACgAAAB4AAQAAAAAABhICswADsQAAAAEACwAAAAYAAQAA" + "AAUAAQANAAAAAgAO" - )` + ) ).run().expect( ``` -Here, ”base64gzip“ means that the file is gzipped and then base64 +Here, “base64gzip” means that the file is gzipped and then base64 encoded. If you want to compute the base64gzip string for a given file, a simple @@ -395,7 +450,7 @@ and emit the full test file registration. This isn't just a convenience; lint's test infrastructure also uses -this to test some additional scenarios (for example, in a multi- module +this to test some additional scenarios (for example, in a multi-module project it will only provide the binaries, not the sources, for upstream modules.) @@ -407,8 +462,30 @@ > from my unit test, my detector is never called! Why? This is almost always because the test sources are referring to some -library or dependency which isn't on the class path. See the ”Library -Dependencies and Stubs“ section above, as well as the [frequently asked +library or dependency which isn't on the class path. See the “Library +Dependencies and Stubs” section above, as well as the [frequently asked questions](faq.md.html). +## Language Level + +Lint will analyze Java and Kotlin test files using its own default +language levels. If you need a higher (or lower) language level in order +to test a particular scenario, you can use the `kotlinLanguageLevel` +and `javaLanguageLevel` setter methods on the lint test configuration. +Here's an example of a unit test setup for Java records: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin + lint() + .files( + java(""" + record Person(String name, int age) { + } + """) + .indented() + ) + .javaLanguageLevel("17") + .run() + .expect(...) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + diff --git a/docs/book.html b/docs/book.html index f9353138..bebe97fa 100644 --- a/docs/book.html +++ b/docs/book.html @@ -1,6 +1,6 @@ - \ No newline at end of file diff --git a/docs/checks/AccessibilityScrollActions.md.html b/docs/checks/AccessibilityScrollActions.md.html new file mode 100644 index 00000000..7be95129 --- /dev/null +++ b/docs/checks/AccessibilityScrollActions.md.html @@ -0,0 +1,143 @@ + +(#) Incomplete Scroll Action support + +!!! WARNING: Incomplete Scroll Action support + This is a warning. + +Id +: `AccessibilityScrollActions` +Summary +: Incomplete Scroll Action support +Severity +: Warning +Category +: Accessibility +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.6.0 (August 2024) +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AccessibilityViewScrollActionsDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AccessibilityViewScrollActionsDetectorTest.kt) + +Views that behave like `ScrollView` and support +`ACTION_SCROLL_{FORWARD,BACKWARD}` should also support +`ACTION_SCROLL_{LEFT,RIGHT}` and/or `ACTION_SCROLL_{UP,DOWN}`. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/com/my/app/MyView.kt:11:Warning: Views that behave like ScrollView +and support ACTION_SCROLL_{FORWARD,BACKWARD} should also support +ACTION_SCROLL_{LEFT,RIGHT} and/or ACTION_SCROLL_{UP,DOWN} +[AccessibilityScrollActions] + override fun onInitializeAccessibilityNodeInfo(info: AccessibilityNodeInfo) { + ^ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/com/my/app/MyView.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package com.my.app + +import android.content.Context +import android.view.View +import android.view.accessibility.AccessibilityEvent +import android.view.accessibility.AccessibilityNodeInfo +import android.widget.ScrollView + +class MyView(context: Context) : View(context) { + + override fun onInitializeAccessibilityNodeInfo(info: AccessibilityNodeInfo) { + super.onInitializeAccessibilityNodeInfo(info) + info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_FORWARD) + info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_BACKWARD) + } + + override fun getAccessibilityClassName(): CharSequence { + return ScrollView::class.java.name + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AccessibilityViewScrollActionsDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("AccessibilityScrollActions") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("AccessibilityScrollActions") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection AccessibilityScrollActions + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="AccessibilityScrollActions" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'AccessibilityScrollActions' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore AccessibilityScrollActions ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/AccessibilityWindowStateChangedEvent.md.html b/docs/checks/AccessibilityWindowStateChangedEvent.md.html new file mode 100644 index 00000000..6d49e46b --- /dev/null +++ b/docs/checks/AccessibilityWindowStateChangedEvent.md.html @@ -0,0 +1,183 @@ + +(#) Use of accessibility window state change events + +!!! WARNING: Use of accessibility window state change events + This is a warning. + +Id +: `AccessibilityWindowStateChangedEvent` +Summary +: Use of accessibility window state change events +Severity +: Warning +Category +: Accessibility +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.6.0 (August 2024) +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AccessibilityWindowStateChangedDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AccessibilityWindowStateChangedDetectorTest.kt) + +Sending or populating `TYPE_WINDOW_STATE_CHANGED` events in your code is +strongly discouraged. Instead, prefer to use or extend system-provided +widgets that are as far down Android's class hierarchy as possible. +System-provided widgets that are far down the hierarchy already have +most of the accessibility capabilities your app needs. If you must +extend `View` or `Canvas` directly, then still prefer to: set UI +metadata by calling `Activity.setTitle`, +`ViewCompat.setAccessibilityPaneTitle`, or +`ViewCompat.setAccessibilityLiveRegion`; implement +`View.onInitializeAccessibilityNodeInfo`; and (for very specialized +custom controls) implement `View.getAccessibilityNodeProvider` to +provide a virtual view hierarchy. These approaches allow accessibility +services to inspect the view hierarchy, rather than relying on +incomplete information provided by events. Events like +`TYPE_WINDOW_STATE_CHANGED` will be sent automatically when updating +this metadata, and so trying to manually send this event will result in +duplicate events, or the event may be ignored entirely. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/com/my/app/MyView.kt:12:Warning: Manually populating or sending +TYPE_WINDOW_STATE_CHANGED events should be avoided. They may be ignored +on certain versions of Android. Prefer setting UI metadata using +View.onInitializeAccessibilityNodeInfo, Activity.setTitle, +ViewCompat.setAccessibilityPaneTitle, etc. to inform users of crucial +changes to the UI. [AccessibilityWindowStateChangedEvent] + sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) + -------------------------------------------------------------------- +src/com/my/app/MyView.kt:16:Warning: Manually populating or sending +TYPE_WINDOW_STATE_CHANGED events should be avoided. They may be ignored +on certain versions of Android. Prefer setting UI metadata using +View.onInitializeAccessibilityNodeInfo, Activity.setTitle, +ViewCompat.setAccessibilityPaneTitle, etc. to inform users of crucial +changes to the UI. [AccessibilityWindowStateChangedEvent] + if (event.eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { + ------------------------- +src/com/my/app/MyView.kt:23:Warning: Manually populating or sending +TYPE_WINDOW_STATE_CHANGED events should be avoided. They may be ignored +on certain versions of Android. Prefer setting UI metadata using +View.onInitializeAccessibilityNodeInfo, Activity.setTitle, +ViewCompat.setAccessibilityPaneTitle, etc. to inform users of crucial +changes to the UI. [AccessibilityWindowStateChangedEvent] + if (event.eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { + ------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/com/my/app/MyView.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package com.my.app + +import android.content.Context +import android.view.View +import android.view.accessibility.AccessibilityEvent +import android.view.accessibility.AccessibilityNodeInfo +import android.widget.ScrollView + +class MyView(context: Context) : View(context) { + + fun foo() { + sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) + } + + override fun dispatchPopulateAccessibilityEvent(event: AccessibilityEvent): Boolean { + if (event.eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { + event.contentChangeTypes = AccessibilityEvent.CONTENT_CHANGE_TYPE_TEXT + } + return super.dispatchPopulateAccessibilityEvent(event) + } + + override fun onPopulateAccessibilityEvent(event: AccessibilityEvent) { + if (event.eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { + event.contentChangeTypes = AccessibilityEvent.CONTENT_CHANGE_TYPE_TEXT + } + super.onPopulateAccessibilityEvent(event) + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AccessibilityWindowStateChangedDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("AccessibilityWindowStateChangedEvent") + fun method() { + sendAccessibilityEvent(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("AccessibilityWindowStateChangedEvent") + void method() { + sendAccessibilityEvent(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection AccessibilityWindowStateChangedEvent + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="AccessibilityWindowStateChangedEvent" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'AccessibilityWindowStateChangedEvent' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore AccessibilityWindowStateChangedEvent ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/AccidentalOctal.md.html b/docs/checks/AccidentalOctal.md.html index 2addc3af..994c972a 100644 --- a/docs/checks/AccidentalOctal.md.html +++ b/docs/checks/AccidentalOctal.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Gradle build files Editing @@ -40,11 +42,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text build.gradle:13:Error: The leading 0 turns this number into octal which is probably not what was intended (interpreted as 8) [AccidentalOctal] - versionCode 010 --- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/ActivityIconColor.md.html b/docs/checks/ActivityIconColor.md.html new file mode 100644 index 00000000..3d720775 --- /dev/null +++ b/docs/checks/ActivityIconColor.md.html @@ -0,0 +1,148 @@ + +(#) Ongoing activity icon is not white + +!!! WARNING: Ongoing activity icon is not white + This is a warning. + +Id +: `ActivityIconColor` +Summary +: Ongoing activity icon is not white +Severity +: Warning +Category +: Usability: Icons +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.3.0 (February 2024) +Affects +: Kotlin and Java files, binary resource files and resource files +Editing +: This check can *not* run live in the IDE editor +See +: https://developer.android.com/training/wearables/ongoing-activity#best-practices +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ActivityIconColorDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ActivityIconColorDetectorTest.kt) + +The resources passed to `setAnimatedIcon` and `setStaticIcon` should be +white with a transparent background, preferably a VectorDrawable or +AnimatedVectorDrawable. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test/pkg/ForegroundOnlyWalkingWorkoutService.kt:9:Warning: The +animated icon for an ongoing activity should be white with a transparent +background [ActivityIconColor] + .setAnimatedIcon(R.drawable.animated_walk) + ------------------------ +src/test/pkg/ForegroundOnlyWalkingWorkoutService.kt:10:Warning: The +static icon for an ongoing activity should be white with a transparent +background [ActivityIconColor] + .setStaticIcon(R.drawable.ic_walk) + ------------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test/pkg/ForegroundOnlyWalkingWorkoutService.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg; + +import androidx.wear.ongoing.OngoingActivity + +class ForegroundOnlyWalkingWorkoutService { + private fun generateNotification(mainText: String) { + val ongoingActivity = + OngoingActivity.Builder() + .setAnimatedIcon(R.drawable.animated_walk) + .setStaticIcon(R.drawable.ic_walk) + .build() + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ActivityIconColorDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ActivityIconColor") + fun method() { + setAnimatedIcon(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ActivityIconColor") + void method() { + setAnimatedIcon(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ActivityIconColor + problematicStatement() + ``` + +* Adding the suppression attribute `tools:ignore="ActivityIconColor"` + on the problematic XML element (or one of its enclosing elements). + You may also need to add the following namespace declaration on the + root element in the XML file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ActivityIconColor" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ActivityIconColor' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ActivityIconColor ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/AdapterViewChildren.md.html b/docs/checks/AdapterViewChildren.md.html index 0a97398d..5d3e4727 100644 --- a/docs/checks/AdapterViewChildren.md.html +++ b/docs/checks/AdapterViewChildren.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -40,11 +42,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/has_children.xml:1:Warning: A list/grid should have no children declared in XML [AdapterViewChildren] - <ListView -------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/AddJavascriptInterface.md.html b/docs/checks/AddJavascriptInterface.md.html index 9a6646e6..88102616 100644 --- a/docs/checks/AddJavascriptInterface.md.html +++ b/docs/checks/AddJavascriptInterface.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files Editing @@ -26,6 +28,8 @@ : https://developer.android.com/reference/android/webkit/WebView.html#addJavascriptInterface(java.lang.Object,%20java.lang.String) See : https://support.google.com/faqs/answer/9095419?hl=en +See +: https://goo.gle/AddJavascriptInterface Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AddJavascriptInterfaceDetector.kt) Tests @@ -47,20 +51,14 @@ WebView.addJavascriptInterface should not be called with minSdkVersion < 17 for security reasons: JavaScript can use reflection to manipulate application [AddJavascriptInterface] - webView.addJavascriptInterface(object, string); ---------------------- - - src/test/pkg/AddJavascriptInterfaceTest.java:23:Warning: WebView.addJavascriptInterface should not be called with minSdkVersion < 17 for security reasons: JavaScript can use reflection to manipulate application [AddJavascriptInterface] - webView.addJavascriptInterface(object, string); ---------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/AlertDialogUsage.md.html b/docs/checks/AlertDialogUsage.md.html new file mode 100644 index 00000000..e47e94a6 --- /dev/null +++ b/docs/checks/AlertDialogUsage.md.html @@ -0,0 +1,172 @@ + +(#) Use the support library AlertDialog instead of android.app.AlertDialog + +!!! WARNING: Use the support library AlertDialog instead of android.app.AlertDialog + This is a warning. + +Id +: `AlertDialogUsage` +Summary +: Use the support library AlertDialog instead of android.app.AlertDialog +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html) +Since +: 0.9.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/main/kotlin/com/vanniktech/lintrules/android/AlertDialogUsageDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/AlertDialogUsageDetectorTest.kt) + +Support library AlertDialog is much more powerful and plays better +together with the new theming / styling than the AlertDialog built into +the framework. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/Test.java:4:Warning: Should not be using android.app.AlertDialog +[AlertDialogUsage] + public Test(AlertDialog dialog) { } + ------------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/Test.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +import android.app.AlertDialog; + +class Test { + public Test(AlertDialog dialog) { } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/AlertDialogUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `AlertDialogUsageDetector.constructorParameterInJava`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-android:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-android:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.android) + +# libs.versions.toml +[versions] +lint-rules-android = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-android = { + module = "com.vanniktech:lint-rules-android", + version.ref = "lint-rules-android" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("AlertDialogUsage") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("AlertDialogUsage") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection AlertDialogUsage + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="AlertDialogUsage" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'AlertDialogUsage' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore AlertDialogUsage ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/Aligned16KB.md.html b/docs/checks/Aligned16KB.md.html new file mode 100644 index 00000000..cfc35294 --- /dev/null +++ b/docs/checks/Aligned16KB.md.html @@ -0,0 +1,135 @@ + +(#) Native library dependency not 16 KB aligned + +!!! WARNING: Native library dependency not 16 KB aligned + This is a warning. + +Id +: `Aligned16KB` +Summary +: Native library dependency not 16 KB aligned +Severity +: Warning +Category +: Correctness +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.10.0 (May 2025) +Affects +: Gradle build files and TOML files +Editing +: This check runs on the fly in the IDE editor +See +: https://developer.android.com/guide/practices/page-sizes +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/PageAlignmentDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/PageAlignmentDetectorTest.kt) + +Android has traditionally used 4 KB memory page sizes. However, to +support future devices that only work with 16 KB aligned libraries apps +containing native libraries need to be built with 16 KB alignment. + +Apps with 4 KB aligned native libraries may not work correctly on +devices requiring 16 KB alignment. To ensure compatibility and +future-proof your app, it is strongly recommended that your native +libraries are aligned to 16 KB boundaries. + +If your app uses any NDK libraries, directly or indirectly through an +SDK, you should rebuild your app to meet this recommendation. Make sure +all native libraries within your application, including those from +dependencies, are built with 16 KB page alignment. + +This lint check looks at all native libraries that your app depends on. +If any are found to be aligned to 4 KB instead of 16 KB, you will need +to address this. + +When a library is flagged, first try to update to a newer version that +supports 16 KB alignment. If an updated version is not available, +contact the library vendor to ask about their plans for 16 KB support +and request a compatible version. Updating your libraries proactively +will help ensure your app works properly on a wider range of devices. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +build.gradle:2:Warning: The native library +arm64-v8a/libtensorflowlite_jni.so (from +org.tensorflow:tensorflow-lite:2.16.1) is not 16 KB aligned +[Aligned16KB] + implementation("org.tensorflow:tensorflow-lite:2.16.1") + --------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant test files: + +`build.gradle`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~groovy linenumbers +dependencies { + implementation("org.tensorflow:tensorflow-lite:2.16.1") +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +[build/intermediates/exploded-aar/org.tensorflow/tensorflow-lite/2.16.1/jni/arm64-v8a/libtensorflowlite_jni.so](examples/arm64-v8a/libtensorflowlite_jni.so) + +[build/intermediates/exploded-aar/org.tensorflow/tensorflow-lite/2.16.1/jni/x86_64/libtensorflowlite_jni.so](examples/x86_64/libtensorflowlite_jni.so) + +[build/intermediates/exploded-aar/org.tensorflow/tensorflow-lite/2.16.1/jni/armeabi-v7a/libtensorflowlite_jni.so](examples/armeabi-v7a/libtensorflowlite_jni.so) + +[build/intermediates/exploded-aar/org.tensorflow/tensorflow-lite/2.16.1/jni/x86/libtensorflowlite_jni.so](examples/x86/libtensorflowlite_jni.so) + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/PageAlignmentDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection Aligned16KB + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="Aligned16KB" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'Aligned16KB' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore Aligned16KB ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/AllCaps.md.html b/docs/checks/AllCaps.md.html index ce7f4815..e5b4b5b0 100644 --- a/docs/checks/AllCaps.md.html +++ b/docs/checks/AllCaps.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 2.3.0 (March 2017) Affects : Resource files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AllCapsDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AllCapsDetectorTest.kt) -Copyright Year -: 2016 The textAllCaps text transform will end up calling `toString` on the `CharSequence`, which has the net effect of removing any markup such as @@ -41,14 +41,11 @@ res/layout/constraint.xml:12:Warning: Using textAllCaps with a string (has_markup) that contains markup; the markup will be dropped by the caps conversion [AllCaps] - android:textAllCaps="true" -------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `res/layout/constraint.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -80,6 +77,14 @@ </merge> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/values/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<resources> + <string name="plain">Home Sample</string> + <string name="has_markup">This is <b>bold</b></string> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AllCapsDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/AllowAllHostnameVerifier.md.html b/docs/checks/AllowAllHostnameVerifier.md.html index e868a420..e1673ca6 100644 --- a/docs/checks/AllowAllHostnameVerifier.md.html +++ b/docs/checks/AllowAllHostnameVerifier.md.html @@ -18,16 +18,18 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 1.5.0 (November 2015) Affects : Kotlin and Java files Editing : This check runs on the fly in the IDE editor +See +: https://goo.gle/AllowAllHostnameVerifier Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AllowAllHostnameVerifierDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AllowAllHostnameVerifierDetectorTest.java) -Copyright Year -: 2015 This check looks for use of HostnameVerifier implementations whose `verify` method always returns true (thus trusting any hostname) which @@ -43,21 +45,15 @@ returns true, which could cause insecure network traffic due to trusting TLS/SSL server certificates for wrong hostnames [AllowAllHostnameVerifier] - connection.setHostnameVerifier(new AllowAllHostnameVerifier()); ------------------------------ - - src/test/pkg/InsecureHostnameVerifier.java:23:Warning: Using the ALLOW_ALL_HOSTNAME_VERIFIER HostnameVerifier is unsafe because it always returns true, which could cause insecure network traffic due to trusting TLS/SSL server certificates for wrong hostnames [AllowAllHostnameVerifier] - connection.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); -------------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/AlwaysShowAction.md.html b/docs/checks/AlwaysShowAction.md.html index ac6fbf4b..c5a368ad 100644 --- a/docs/checks/AlwaysShowAction.md.html +++ b/docs/checks/AlwaysShowAction.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files and resource files Editing @@ -54,11 +56,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/menu-land/actions.xml:6:Warning: Prefer "ifRoom" instead of "always" [AlwaysShowAction] - android:showAsAction="always|collapseActionView" ------------------------------------------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/AndroidGradlePluginVersion.md.html b/docs/checks/AndroidGradlePluginVersion.md.html index 64d1ab47..d1e2c93b 100644 --- a/docs/checks/AndroidGradlePluginVersion.md.html +++ b/docs/checks/AndroidGradlePluginVersion.md.html @@ -18,8 +18,10 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects -: Gradle build files +: Gradle build files, TOML files and property files Editing : This check runs on the fly in the IDE editor Implementation @@ -43,34 +45,53 @@ Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -build.gradle:7:Warning: A newer version of -com.android.tools.build:gradle than 3.4.0-alpha3 is available: -3.6.0-alpha01 [AndroidGradlePluginVersion] - - classpath 'com.android.tools.build:gradle:3.4.0-alpha3' - ------------------------------------------------------- - - +../gradle/libs.versions.toml:8:Warning: A newer version of +com.android.application than 8.0.0 is available: 8.0.2 +[AndroidGradlePluginVersion] +gradlePlugins-agp = "8.0.0" + ------- +../gradle/libs.versions.toml:9:Warning: A newer version of +com.android.application than 8.1.0-alpha01 is available: 8.1.0-rc01 +[AndroidGradlePluginVersion] +gradlePlugins-agp-alpha = "8.1.0-alpha01" + --------------- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: -`build.gradle`: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~groovy linenumbers -buildscript { - repositories { - google() - jcenter() - } - dependencies { - classpath 'com.android.tools.build:gradle:3.4.0-alpha3' - } -} -dependencies { - compile 'org.apache.httpcomponents:httpcomponents-core:4.2' - compile 'com.android.support:recyclerview-v7:25.0.0' - compile 'com.google.firebase:firebase-messaging:10.2.1' -} +`../gradle/libs.versions.toml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~toml linenumbers +[versions] +guavaVersion = "11.0.2" +appCompatVersion="13.0.0" +wearableVersion=" 1.2.0 " +# Test comment suppression: +#noinspection GradleDependency +multi-dex="1.0.0" +gradlePlugins-agp = "8.0.0" +gradlePlugins-agp-alpha = "8.1.0-alpha01" +gradlePlugins-agp-dev = "8.2.0-dev" +gradlePlugins-crashlytics = "2.9.2" +gradlePlugins-dependency-analysis = "1.0.0" + +[libraries] +com-google-guava = { module = "com.google.guava:guava", version.ref = "guavaVersion"} +appcompat = { module = "com.android.support:appcompat-v7", version.ref = "appCompatVersion" } +wearable-support = { group = " com.google.android.support ", name =" wearable ", version.ref = " wearableVersion " } +multidex-lib = { module = "com.android.support:multidex", version.ref = "multi-dex" } + +[bundles] +misc = [ + "com-google-guava", + "appcompat", +] + +[plugins] +android-application = { id = "com.android.application", version.ref = "gradlePlugins-agp" } +android-application2 = { id = "com.android.application", version.ref = "gradlePlugins-agp-alpha" } +android-application3 = { id = "com.android.application", version.ref = "gradlePlugins-agp-dev" } +crashlytics = { id = "com.google.firebase.crashlytics", version.ref = "gradlePlugins-crashlytics" } +dependency-analysis = { id = "com.autonomousapps.dependency-analysis", version.ref = "gradlePlugins-dependency-analysis" } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can also visit the @@ -78,7 +99,7 @@ for the unit tests for this check to see additional scenarios. The above example was automatically extracted from the first unit test -found for this lint check, `GradleDetector.testVersionsFromGradleCache`. +found for this lint check, `GradleDetector.testTomlVersionCatalogFile`. To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=192708. diff --git a/docs/checks/AnimatorKeep.md.html b/docs/checks/AnimatorKeep.md.html index db6a8b5c..9eb86c4b 100644 --- a/docs/checks/AnimatorKeep.md.html +++ b/docs/checks/AnimatorKeep.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 2.3.0 (March 2017) Affects : Kotlin and Java files and resource files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ObjectAnimatorDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ObjectAnimatorDetectorTest.kt) -Copyright Year -: 2016 When you use property animators, properties can be accessed via reflection. Those methods should be annotated with @Keep to ensure that @@ -45,117 +45,38 @@ Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -src/main/java/test/pkg/AnimatorTest.java:55:Warning: This method is -accessed from an ObjectAnimator so it should be annotated with @Keep to -ensure that it is not discarded or renamed in release builds -[AnimatorKeep] - +src/main/java/AnimationExample.java:14:Warning: This method is accessed +from an ObjectAnimator so it should be annotated with @Keep to ensure +that it is not discarded or renamed in release builds [AnimatorKeep] public void setProp1(int x) { --------------- - - -src/main/java/test/pkg/AnimatorTest.java:58:Warning: This method is -accessed from an ObjectAnimator so it should be annotated with @Keep to -ensure that it is not discarded or renamed in release builds -[AnimatorKeep] - - private void setProp2(float x) { - ----------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: -`src/main/java/test/pkg/AnimatorTest.java`: +`src/main/java/AnimationExample.java`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers -package test.pkg; - - import android.animation.ObjectAnimator; -import android.animation.PropertyValuesHolder; -import androidx.annotation.Keep; -import android.view.View; -import android.widget.Button; -import android.animation.FloatEvaluator; -@SuppressWarnings("unused") -public class AnimatorTest { - - public void testObjectAnimator(Button button) { + +public class AnimationExample { + public void startAnimations() { Object myObject = new MyObject(); ObjectAnimator animator1 = ObjectAnimator.ofInt(myObject, "prop1", 0, 1, 2, 5); - animator1.setDuration(10); animator1.start(); - - // Incorrect type (float parameter) warning - ObjectAnimator.ofInt(myObject, "prop2", 0, 1, 2, 5).start(); - - // Missing method warning - ObjectAnimator.ofInt(myObject, "unknown", 0, 1, 2, 5).start(); - - // Static method warning - ObjectAnimator.ofInt(myObject, "prop3", 0, 1, 2, 5).start(); - - // OK: Already marked @Keep - ObjectAnimator.ofInt(myObject, "prop4", 0, 1, 2, 5).start(); - - // OK: multi int - ObjectAnimator.ofMultiInt(myObject, "prop4", new int[0][]).start(); - - // OK: multi int - ObjectAnimator.ofMultiFloat(myObject, "prop5", new float[0][]).start(); - - // View stuff - ObjectAnimator.ofFloat(button, "alpha", 1, 5); // TODO: Warn about better method?, e.g. button.animate().alpha(...) - ObjectAnimator.ofArgb(button, "alpha2", 1, 5); // Missing - } - - public void testPropertyHolder() { - Object myObject = new MyObject(); - - PropertyValuesHolder p1 = PropertyValuesHolder.ofInt("prop1", 50); - PropertyValuesHolder p2 = PropertyValuesHolder.ofFloat("prop2", 100f); - ObjectAnimator.ofPropertyValuesHolder(myObject, p1, p2).start(); - ObjectAnimator.ofPropertyValuesHolder(myObject, - PropertyValuesHolder.ofInt("prop1", 50), - PropertyValuesHolder.ofFloat("prop2", 100f)).start(); + ObjectAnimator animator2 = ObjectAnimator.ofInt(myObject, "prop2", 0, 1, 2, 5); + animator2.start(); } private static class MyObject { public void setProp1(int x) { + // Implementation here } private void setProp2(float x) { + // Implementation here } - - public static void setProp3(int x) { - } - - @Keep - public void setProp4(int[] x) { - } - - @Keep - public void setProp5(float[] x) { - } - - @Keep - public void setProp4(int x) { - } - - @Keep - public void setProp5(float x) { - } - } - - public void testEvaluators() { - Object myObject = new MyObject(); - PropertyValuesHolder p1 = PropertyValuesHolder.ofObject("prop5", new FloatEvaluator()); - ObjectAnimator.ofPropertyValuesHolder(myObject, p1); - ObjectAnimator.ofObject(myObject, "prop5", new FloatEvaluator(), 1f, 2f); } - } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -163,11 +84,6 @@ [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ObjectAnimatorDetectorTest.kt) for the unit tests for this check to see additional scenarios. -The above example was automatically extracted from the first unit test -found for this lint check, `ObjectAnimatorDetector.testBasic`. -To report a problem with this extracted sample, visit -https://issuetracker.google.com/issues/new?component=192708. - (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/AnnotateVersionCheck.md.html b/docs/checks/AnnotateVersionCheck.md.html index e5e2386e..2718ab45 100644 --- a/docs/checks/AnnotateVersionCheck.md.html +++ b/docs/checks/AnnotateVersionCheck.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.0.0 (July 2021) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/SdkIntDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/SdkIntDetectorTest.kt) -Copyright Year -: 2021 Methods which perform `SDK_INT` version checks (or field constants which reflect the result of a version check) in libraries should be annotated @@ -45,26 +45,17 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/test.kt:8:Warning: This method should be annotated with @ChecksSdkIntAtLeast(api=VERSION_CODES.N) [AnnotateVersionCheck] - fun isNougat(): Boolean { -------- - - src/test/pkg/test.kt:12:Warning: This method should be annotated with @ChecksSdkIntAtLeast(parameter=0) [AnnotateVersionCheck] - fun isAtLeast(api: Int): Boolean { --------- - - src/test/pkg/test.kt:16:Warning: This method should be annotated with @ChecksSdkIntAtLeast(api=Build.VERSION_CODES.O, lambda=1) [AnnotateVersionCheck] - inline fun <T> T.applyForOreoOrAbove(block: T.() -> Unit): T { ------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/AnnotationProcessorOnCompilePath.md.html b/docs/checks/AnnotationProcessorOnCompilePath.md.html index e3b8c806..86b7f2e9 100644 --- a/docs/checks/AnnotationProcessorOnCompilePath.md.html +++ b/docs/checks/AnnotationProcessorOnCompilePath.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.6.0 (February 2020) Affects : Gradle build files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GradleDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) -Copyright Year -: 2014 This dependency is identified as an annotation processor. Consider adding it to the processor path using `annotationProcessor` instead of @@ -42,51 +42,33 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text build.gradle:2:Warning: Add annotation processor to processor path using annotationProcessor instead of api [AnnotationProcessorOnCompilePath] - api 'com.jakewharton:butterknife-compiler:10.1.0' --- - - build.gradle:3:Warning: Add annotation processor to processor path using annotationProcessor instead of implementation [AnnotationProcessorOnCompilePath] - implementation 'com.github.bumptech.glide:compiler:4.9.0' -------------- - - build.gradle:4:Warning: Add annotation processor to processor path using annotationProcessor instead of compile [AnnotationProcessorOnCompilePath] - compile "androidx.lifecycle:lifecycle-compiler:2.2.0-alpha01" ------- - - build.gradle:5:Warning: Add annotation processor to processor path using testAnnotationProcessor instead of testImplementation [AnnotationProcessorOnCompilePath] - testImplementation "com.google.auto.value:auto-value:1.6.2" ------------------ - - build.gradle:6:Warning: Add annotation processor to processor path using androidTestAnnotationProcessor instead of androidTestCompile [AnnotationProcessorOnCompilePath] - androidTestCompile "org.projectlombok:lombok:1.18.8" ------------------ - - build.gradle:8:Warning: Add annotation processor to processor path using debugAnnotationProcessor instead of debugCompile [AnnotationProcessorOnCompilePath] - debugCompile "android.arch.persistence.room:compiler:1.1.1" ------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/AppBundleLocaleChanges.md.html b/docs/checks/AppBundleLocaleChanges.md.html index 15f2da28..57f3728a 100644 --- a/docs/checks/AppBundleLocaleChanges.md.html +++ b/docs/checks/AppBundleLocaleChanges.md.html @@ -18,18 +18,18 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.1.0 (January 2022) Affects : Gradle build files and Kotlin and Java files Editing -: This check can *not* run live in the IDE editor +: This check runs on the fly in the IDE editor See : https://developer.android.com/guide/app-bundle/configure-base#handling_language_changes Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AppBundleLocaleChangesDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AppBundleLocaleChangesDetectorTest.kt) -Copyright Year -: 2021 When changing locales at runtime (e.g. to provide an in-app language switcher), the Android App Bundle must be configured to not split by @@ -44,11 +44,8 @@ corresponding Play Core library calls for downloading languages and splitting by language is not disabled in the bundle configuration [AppBundleLocaleChanges] - configuration.locale = locale ------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/AppCompatCustomView.md.html b/docs/checks/AppCompatCustomView.md.html index 771052ea..6949ebd0 100644 --- a/docs/checks/AppCompatCustomView.md.html +++ b/docs/checks/AppCompatCustomView.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 2.3.0 (March 2017) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AppCompatCustomViewDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AppCompatCustomViewDetectorTest.kt) -Copyright Year -: 2016 In order to support features such as tinting, the appcompat library will automatically load special appcompat replacements for the builtin @@ -47,116 +47,74 @@ src/test/pkg/TestAppCompatSuperClasses.java:23:Error: This custom view should extend android.support.v7.widget.AppCompatButton instead [AppCompatCustomView] - public class MyButton1 extends Button { // ERROR ------ - - src/test/pkg/TestAppCompatSuperClasses.java:28:Error: This custom view should extend android.support.v7.widget.AppCompatButton instead [AppCompatCustomView] - public class MyButton2 extends Button implements Runnable { // ERROR ------ - - src/test/pkg/TestAppCompatSuperClasses.java:47:Error: This custom view should extend android.support.v7.widget.AppCompatEditText instead [AppCompatCustomView] - public class MyEditText extends EditText { // ERROR -------- - - src/test/pkg/TestAppCompatSuperClasses.java:51:Error: This custom view should extend android.support.v7.widget.AppCompatTextView instead [AppCompatCustomView] - public class MyTextView extends TextView { // ERROR -------- - - src/test/pkg/TestAppCompatSuperClasses.java:55:Error: This custom view should extend android.support.v7.widget.AppCompatCheckBox instead [AppCompatCustomView] - public class MyCheckBox extends CheckBox { // ERROR -------- - - src/test/pkg/TestAppCompatSuperClasses.java:59:Error: This custom view should extend android.support.v7.widget.AppCompatCheckedTextView instead [AppCompatCustomView] - public class MyCheckedTextView extends CheckedTextView { // ERROR --------------- - - src/test/pkg/TestAppCompatSuperClasses.java:63:Error: This custom view should extend android.support.v7.widget.AppCompatImageButton instead [AppCompatCustomView] - public class MyImageButton extends ImageButton { // ERROR ----------- - - src/test/pkg/TestAppCompatSuperClasses.java:67:Error: This custom view should extend android.support.v7.widget.AppCompatImageView instead [AppCompatCustomView] - public class MyImageView extends ImageView { // ERROR --------- - - src/test/pkg/TestAppCompatSuperClasses.java:71:Error: This custom view should extend android.support.v7.widget.AppCompatMultiAutoCompleteTextView instead [AppCompatCustomView] - public class MyMultiAutoCompleteTextView extends MultiAutoCompleteTextView { // ERROR ------------------------- - - src/test/pkg/TestAppCompatSuperClasses.java:75:Error: This custom view should extend android.support.v7.widget.AppCompatAutoCompleteTextView instead [AppCompatCustomView] - public class MyAutoCompleteTextView extends AutoCompleteTextView { // ERROR -------------------- - - src/test/pkg/TestAppCompatSuperClasses.java:79:Error: This custom view should extend android.support.v7.widget.AppCompatRadioButton instead [AppCompatCustomView] - public class MyRadioButton extends RadioButton { // ERROR ----------- - - src/test/pkg/TestAppCompatSuperClasses.java:83:Error: This custom view should extend android.support.v7.widget.AppCompatRatingBar instead [AppCompatCustomView] - public class MyRatingBar extends RatingBar { // ERROR --------- - - src/test/pkg/TestAppCompatSuperClasses.java:87:Error: This custom view should extend android.support.v7.widget.AppCompatSeekBar instead [AppCompatCustomView] - public class MySeekBar extends SeekBar { // ERROR ------- - - src/test/pkg/TestAppCompatSuperClasses.java:91:Error: This custom view should extend android.support.v7.widget.AppCompatSpinner instead [AppCompatCustomView] - public class MySpinner extends Spinner { // ERROR ------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/AppCompatMethod.md.html b/docs/checks/AppCompatMethod.md.html index 1bf8f746..931cfc47 100644 --- a/docs/checks/AppCompatMethod.md.html +++ b/docs/checks/AppCompatMethod.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files Editing @@ -47,51 +49,33 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/AppCompatTest.java:5:Warning: Should use getSupportActionBar instead of getActionBar name [AppCompatMethod] - getActionBar(); // ERROR -------------- - - src/test/pkg/AppCompatTest.java:8:Warning: Should use startSupportActionMode instead of startActionMode name [AppCompatMethod] - startActionMode(null); // ERROR --------------------- - - src/test/pkg/AppCompatTest.java:11:Warning: Should use supportRequestWindowFeature instead of requestWindowFeature name [AppCompatMethod] - requestWindowFeature(0); // ERROR ----------------------- - - src/test/pkg/AppCompatTest.java:14:Warning: Should use setSupportProgressBarVisibility instead of setProgressBarVisibility name [AppCompatMethod] - setProgressBarVisibility(true); // ERROR ------------------------------ - - src/test/pkg/AppCompatTest.java:15:Warning: Should use setSupportProgressBarIndeterminate instead of setProgressBarIndeterminate name [AppCompatMethod] - setProgressBarIndeterminate(true); // ERROR --------------------------------- - - src/test/pkg/AppCompatTest.java:16:Warning: Should use setSupportProgressBarIndeterminateVisibility instead of setProgressBarIndeterminateVisibility name [AppCompatMethod] - setProgressBarIndeterminateVisibility(true); // ERROR ------------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/AppCompatResource.md.html b/docs/checks/AppCompatResource.md.html index b8b8d918..72f40689 100644 --- a/docs/checks/AppCompatResource.md.html +++ b/docs/checks/AppCompatResource.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -46,11 +48,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/menu/showAction1.xml:6:Error: Should use android:showAsAction when not using the appcompat library [AppCompatResource] - app:showAsAction="never" /> ------------------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/AppIndexingService.md.html b/docs/checks/AppIndexingService.md.html index c3b0e85f..794f06cb 100644 --- a/docs/checks/AppIndexingService.md.html +++ b/docs/checks/AppIndexingService.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.1.0 (March 2018) Affects : Manifest files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ManifestDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ManifestDetectorTest.kt) -Copyright Year -: 2011 Apps targeting Android 8.0 or higher can no longer rely on background services while listening for updates to the on-device index. Use a @@ -43,14 +43,11 @@ src/main/AndroidManifest.xml:10:Warning: UPDATE_INDEX is configured as a service in your app, which is no longer supported for the API level you're targeting. Use a BroadcastReceiver instead. [AppIndexingService] - <action android:name="com.google.firebase.appindexing.UPDATE_INDEX" /> ----------------------------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `src/main/AndroidManifest.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -71,6 +68,15 @@ </manifest> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`build.gradle`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~groovy linenumbers +apply plugin: 'com.android.application' + +dependencies { + compile 'com.google.firebase:firebase-appindexing:11.0.4' +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ManifestDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/AppLinkSplitToWebAndCustom.md.html b/docs/checks/AppLinkSplitToWebAndCustom.md.html new file mode 100644 index 00000000..87b5dbcd --- /dev/null +++ b/docs/checks/AppLinkSplitToWebAndCustom.md.html @@ -0,0 +1,160 @@ + +(#) Android App links should only use http(s) schemes + +!!! ERROR: Android App links should only use http(s) schemes + This is an error. + +Id +: `AppLinkSplitToWebAndCustom` +Summary +: Android App links should only use http(s) schemes +Severity +: Error +Category +: Correctness +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.8.0 (January 2025) +Affects +: Manifest files +Editing +: This check runs on the fly in the IDE editor +See +: https://developer.android.com/training/app-links/verify-android-applinks#add-intent-filters +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AppLinksValidDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AppLinksValidDetectorTest.kt) + +In order for Android App Links to open in your app, Android must perform +domain verification. However, Android only sends domain verification +requests for ``s that only contain http(s) schemes. + +To ensure correct behavior, please split your http(s) schemes and other +schemes into two different ``s. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +AndroidManifest.xml:7:Error: Split your http(s) and custom schemes into +separate intent filters [AppLinkSplitToWebAndCustom] + <intent-filter android:autoVerify="true" android:order="-1" android:priority="-1"> + ------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`AndroidManifest.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.example.helloworld" > + <uses-sdk android:minSdkVersion="31" android:targetSdkVersion="34" /> + + <application> + <activity android:name=".SplitWebAndCustomActivity" android:exported="true"> + <intent-filter android:autoVerify="true" android:order="-1" android:priority="-1"> + <action android:name="android.intent.action.VIEW" /> + <category android:name="android.intent.category.DEFAULT" /> + <category android:name="android.intent.category.BROWSABLE" /> + <uri-relative-filter-group> + <data android:path="/path" /> + <data android:query="queryparam=value" /> + </uri-relative-filter-group> + <data android:scheme="http" /> + <data android:scheme="custom" /> + <data android:host="example.com" /> + <data android:path="@string/path" /> + <data android:path="/<&''" /> + <data android:path='/single"quote' /> + <data android:path="" /> + <!-- Test having tags underneath the host elements as well --> + <action android:name="android.intent.action.SEND"/> + <uri-relative-filter-group> + <data android:path="/path" /> + <data android:query="queryparam=value" /> + </uri-relative-filter-group> + </intent-filter> + </activity> + </application> +</manifest> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/values/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<resources> + <string name="path">/path</string> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AppLinksValidDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `AppLinksValidDetector.test_splitToWebAndCustomSchemes`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=192708. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute + `tools:ignore="AppLinkSplitToWebAndCustom"` on the problematic XML + element (or one of its enclosing elements). You may also need to add + the following namespace declaration on the root element in the XML + file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <manifest xmlns:tools="http://schemas.android.com/tools"> + ... + <activity tools:ignore="AppLinkSplitToWebAndCustom" .../> + ... + </manifest> + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="AppLinkSplitToWebAndCustom" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'AppLinkSplitToWebAndCustom' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore AppLinkSplitToWebAndCustom ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/AppLinkUriRelativeFilterGroupError.md.html b/docs/checks/AppLinkUriRelativeFilterGroupError.md.html new file mode 100644 index 00000000..8f988d95 --- /dev/null +++ b/docs/checks/AppLinkUriRelativeFilterGroupError.md.html @@ -0,0 +1,180 @@ + +(#) URI relative filter group invalid + +!!! ERROR: URI relative filter group invalid + This is an error. + +Id +: `AppLinkUriRelativeFilterGroupError` +Summary +: URI relative filter group invalid +Severity +: Error +Category +: Correctness +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.9.0 (March 2025) +Affects +: Manifest files +Editing +: This check runs on the fly in the IDE editor +See +: https://developer.android.com/guide/topics/manifest/uri-relative-filter-group-element?utm_source=lint +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AppLinksValidDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AppLinksValidDetectorTest.kt) + +Ensure that your URI relative filter group is correctly configured. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +AndroidManifest.xml:29:Error: MIME types prevent Android App Links from +matching [AppLinkUriRelativeFilterGroupError] + <data android:mimeType="application/json" /> + -------------------------------------------- +AndroidManifest.xml:40:Error: MIME types prevent Android App Links from +matching [AppLinkUriRelativeFilterGroupError] + <data android:host="example.com" android:mimeType="application/json" android:pathPrefix="/gizmos" /> + ---------------------------------------------------------------------------------------------------- +AndroidManifest.xml:51:Error: MIME types prevent Android App Links from +matching [AppLinkUriRelativeFilterGroupError] + <data android:host='example.com' android:mimeType="application/json" android:pathPrefix='/gizmos' /> + ---------------------------------------------------------------------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`AndroidManifest.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.example.helloworld" > + + <application> + <activity android:name=".FullscreenActivity"> + + <intent-filter android:autoVerify="true"> <!-- Fine --> + <action android:name="android.intent.action.VIEW" /> + <category android:name="android.intent.category.DEFAULT" /> + <category android:name="android.intent.category.BROWSABLE" /> + + <data android:scheme="http" /> + <data android:scheme="https" /> + + <data android:host="example.com" /> + <data android:pathPrefix="/gizmos" /> + </intent-filter> + + <intent-filter android:autoVerify="true"> <!-- Has MIME type in its own data tag--> + <action android:name="android.intent.action.VIEW" /> + <category android:name="android.intent.category.DEFAULT" /> + <category android:name="android.intent.category.BROWSABLE" /> + + <data android:scheme="http" /> + <data android:scheme="https" /> + + <data android:host="example.com" /> + <data android:pathPrefix="/gizmos" /> + <data android:mimeType="application/json" /> + </intent-filter> + + <intent-filter android:autoVerify="true"> <!-- Has MIME type in the same data tag as other content --> + <action android:name="android.intent.action.VIEW" /> + <category android:name="android.intent.category.DEFAULT" /> + <category android:name="android.intent.category.BROWSABLE" /> + + <data android:scheme="http" /> + <data android:scheme="https" /> + + <data android:host="example.com" android:mimeType="application/json" android:pathPrefix="/gizmos" /> + </intent-filter> + + <intent-filter android:autoVerify="true"> <!-- Has MIME type in the same data tag as other content; mix single/double quotes --> + <action android:name="android.intent.action.VIEW" /> + <category android:name="android.intent.category.DEFAULT" /> + <category android:name="android.intent.category.BROWSABLE" /> + + <data android:scheme="http" /> + <data android:scheme="https" /> + + <data android:host='example.com' android:mimeType="application/json" android:pathPrefix='/gizmos' /> + </intent-filter> + </activity> + </application> +</manifest> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AppLinksValidDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `AppLinksValidDetector.testAutoVerify_extraAttribute_mimeType`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=192708. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute + `tools:ignore="AppLinkUriRelativeFilterGroupError"` on the + problematic XML element (or one of its enclosing elements). You may + also need to add the following namespace declaration on the root + element in the XML file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <manifest xmlns:tools="http://schemas.android.com/tools"> + ... + <activity tools:ignore="AppLinkUriRelativeFilterGroupError" .../> + ... + </manifest> + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="AppLinkUriRelativeFilterGroupError" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'AppLinkUriRelativeFilterGroupError' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore AppLinkUriRelativeFilterGroupError ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/AppLinkUrlError.md.html b/docs/checks/AppLinkUrlError.md.html index 2e5e8ee4..605bd8e8 100644 --- a/docs/checks/AppLinkUrlError.md.html +++ b/docs/checks/AppLinkUrlError.md.html @@ -1,38 +1,40 @@ -(#) URL not supported by app for Firebase App Indexing +(#) URI invalid -!!! ERROR: URL not supported by app for Firebase App Indexing +!!! ERROR: URI invalid This is an error. Id : `AppLinkUrlError` Summary -: URL not supported by app for Firebase App Indexing +: URI invalid Severity : Error Category -: Usability +: Correctness Platform : Android Vendor : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.0.0 (October 2017) Affects : Manifest files Editing : This check runs on the fly in the IDE editor See +: https://developer.android.com/training/app-links +See : https://g.co/AppIndexing/AndroidStudio Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AppLinksValidDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AppLinksValidDetectorTest.kt) -Copyright Year -: 2017 -Ensure the URL is supported by your app, to get installs and traffic to -your app from Google Search. +Ensure your intent filter has the documented elements for deep links, +web links, or Android App Links. !!! Tip This lint check has an associated quickfix available in the IDE. @@ -41,13 +43,10 @@ Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -AndroidManifest.xml:12:Error: Expected testUrl attribute +AndroidManifest.xml:15:Error: Expected testUrl attribute [AppLinkUrlError] - <tools:validation /> -------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -59,8 +58,11 @@ package="test.pkg" > <application> - <activity> + <activity android:name=".MainActivity"> <intent-filter android:autoVerify="true"> + <action android:name="android.intent.action.VIEW" /> + <category android:name="android.intent.category.DEFAULT" /> + <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="http" android:host="example.com" android:pathPrefix="/gizmos" /> diff --git a/docs/checks/AppLinkWarning.md.html b/docs/checks/AppLinkWarning.md.html new file mode 100644 index 00000000..289de85a --- /dev/null +++ b/docs/checks/AppLinkWarning.md.html @@ -0,0 +1,225 @@ + +(#) App Link warning + +!!! WARNING: App Link warning + This is a warning. + +Id +: `AppLinkWarning` +Summary +: App Link warning +Severity +: Warning +Category +: Correctness +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.8.0 (January 2025) +Affects +: Manifest files +Editing +: This check runs on the fly in the IDE editor +See +: https://developer.android.com/training/app-links +See +: https://g.co/AppIndexing/AndroidStudio +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AppLinksValidDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AppLinksValidDetectorTest.kt) + +From Android 12, intent filters that use the HTTP and HTTPS schemes will +no longer bring the user to your app when the user clicks +a link, unless the intent filter is an Android App Link. +Such intent filters must include certain elements, and at least + one Android App Link for each domain must have +`android:autoVerify="true"` to verify ownership of the +domain. We recommend adding `android:autoVerify="true"` to any intent + filter that is intended to be an App Link, in case the other +App Links are modified. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +AndroidManifest.xml:6:Warning: This intent filter has the format of an +Android App Link but is missing the autoVerify attribute; add +android:autoVerify="true" to ensure your domain will be validated and +enable App Link-related Lint warnings. If you do not want clicked URLs +to bring the user to your app, remove the +android.intent.category.BROWSABLE category, or set +android:autoVerify="false" to make it clear this is not intended to be +an Android App Link. [AppLinkWarning] + <intent-filter> <!-- We expect a warning here --> + ------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`AndroidManifest.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.example.helloworld" > + + <application> + <activity android:name=".FullscreenActivity"> + <intent-filter> <!-- We expect a warning here --> + <action android:name="android.intent.action.VIEW" /> + <category android:name="android.intent.category.DEFAULT" /> + <category android:name="android.intent.category.BROWSABLE" /> + + <data android:scheme="http" /> + <data android:scheme="https" /> + + <data android:host="example.com" /> + <data android:pathPrefix="/gizmos" /> + </intent-filter> + + <intent-filter> <!-- Missing VIEW --> + <category android:name="android.intent.category.DEFAULT" /> + <category android:name="android.intent.category.BROWSABLE" /> + + <data android:scheme="http" /> + <data android:scheme="https" /> + + <data android:host="example.com" /> + <data android:pathPrefix="/gizmos" /> + </intent-filter> + + <intent-filter> <!-- Missing DEFAULT --> + <action android:name="android.intent.action.VIEW" /> + <category android:name="android.intent.category.BROWSABLE" /> + + <data android:scheme="http" /> + <data android:scheme="https" /> + + <data android:host="example.com" /> + <data android:pathPrefix="/gizmos" /> + </intent-filter> + + <intent-filter> <!-- Missing BROWSABLE --> + <action android:name="android.intent.action.VIEW" /> + <category android:name="android.intent.category.DEFAULT" /> + + <data android:scheme="http" /> + <data android:scheme="https" /> + + <data android:host="example.com" /> + <data android:pathPrefix="/gizmos" /> + </intent-filter> + + <intent-filter> <!-- Has custom scheme, missing http --> + <action android:name="android.intent.action.VIEW" /> + <category android:name="android.intent.category.DEFAULT" /> + <category android:name="android.intent.category.BROWSABLE" /> + + <data android:scheme="other" /> + + <data android:host="example.com" /> + <data android:pathPrefix="/gizmos" /> + </intent-filter> + + <intent-filter> <!-- Has no scheme --> + <action android:name="android.intent.action.VIEW" /> + <category android:name="android.intent.category.DEFAULT" /> + <category android:name="android.intent.category.BROWSABLE" /> + + <data android:host="example.com" /> + <data android:pathPrefix="/gizmos" /> + </intent-filter> + + <intent-filter> <!-- Missing host --> + <action android:name="android.intent.action.VIEW" /> + <category android:name="android.intent.category.DEFAULT" /> + <category android:name="android.intent.category.BROWSABLE" /> + + <data android:scheme="http" /> + <data android:scheme="https" /> + </intent-filter> + + <intent-filter android:autoVerify="false"> <!-- We would usually expect a warning here, but it has autoVerify="false" --> + <action android:name="android.intent.action.VIEW" /> + <category android:name="android.intent.category.DEFAULT" /> + <category android:name="android.intent.category.BROWSABLE" /> + + <data android:scheme="http" /> + <data android:scheme="https" /> + + <data android:host="example.com" /> + <data android:pathPrefix="/gizmos" /> + </intent-filter> + </activity> + </application> +</manifest> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AppLinksValidDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `AppLinksValidDetector.testAddAutoVerifySuggestion`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=192708. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute `tools:ignore="AppLinkWarning"` on + the problematic XML element (or one of its enclosing elements). You + may also need to add the following namespace declaration on the root + element in the XML file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <manifest xmlns:tools="http://schemas.android.com/tools"> + ... + <activity tools:ignore="AppLinkWarning" .../> + ... + </manifest> + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="AppLinkWarning" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'AppLinkWarning' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore AppLinkWarning ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/AppLinksAutoVerify.md.html b/docs/checks/AppLinksAutoVerify.md.html index 6a273276..7b585412 100644 --- a/docs/checks/AppLinksAutoVerify.md.html +++ b/docs/checks/AppLinksAutoVerify.md.html @@ -6,10 +6,6 @@ Id : `AppLinksAutoVerify` -Previously -: AppLinksAutoVerifyError -Previously -: AppLinksAutoVerifyWarning Summary : App Links Auto Verification Failure Note @@ -24,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.0.0 (July 2021) Affects : Manifest files Editing @@ -31,11 +29,9 @@ See : https://g.co/appindexing/applinks Implementation -: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AppLinksAutoVerifyDetector.java) +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AppLinksAutoVerifyDetector.kt) Tests -: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AppLinksAutoVerifyDetectorTest.java) -Copyright Year -: 2015 +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AppLinksAutoVerifyDetectorTest.kt) Ensures that app links are correctly set and associated with website. @@ -46,11 +42,8 @@ AndroidManifest.xml:12:Error: This host does not support app links to your app. Checks the Digital Asset Links JSON file: http://example.com/.well-known/assetlinks.json [AppLinksAutoVerify] - android:host="example.com" -------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -80,7 +73,7 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can also visit the -[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AppLinksAutoVerifyDetectorTest.java) +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AppLinksAutoVerifyDetectorTest.kt) for the unit tests for this check to see additional scenarios. The above example was automatically extracted from the first unit test diff --git a/docs/checks/ApplySharedPref.md.html b/docs/checks/ApplySharedPref.md.html index f467037b..b58f8529 100644 --- a/docs/checks/ApplySharedPref.md.html +++ b/docs/checks/ApplySharedPref.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 2.3.0 (March 2017) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/CleanupDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/CleanupDetectorTest.kt) -Copyright Year -: 2012 Consider using `apply()` instead of `commit` on shared preferences. Whereas `commit` blocks and writes its data to persistent storage @@ -43,11 +43,8 @@ src/test/pkg/SharedPrefsTest.java:16:Warning: Consider using apply() instead; commit writes its data to persistent storage immediately, whereas apply will handle it in the background [ApplySharedPref] - editor.commit(); -------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -138,7 +135,7 @@ for the unit tests for this check to see additional scenarios. The above example was automatically extracted from the first unit test -found for this lint check, `CleanupDetector.test`. +found for this lint check, `CleanupDetector.testSharedPrefs`. To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=192708. diff --git a/docs/checks/ArcAnimationSpecTypeIssue.md.html b/docs/checks/ArcAnimationSpecTypeIssue.md.html new file mode 100644 index 00000000..a5179501 --- /dev/null +++ b/docs/checks/ArcAnimationSpecTypeIssue.md.html @@ -0,0 +1,198 @@ + +(#) ArcAnimationSpec is designed for 2D values. Particularly, for positional values such as Offset. + +!!! Tip: ArcAnimationSpec is designed for 2D values. Particularly, for positional values such as Offset. + Advice from this check is just a hint; it's a "weak" warning. + +Id +: `ArcAnimationSpecTypeIssue` +Summary +: ArcAnimationSpec is designed for 2D values. Particularly, for positional values such as Offset. +Severity +: Hint +Category +: Correctness +Platform +: Any +Vendor +: Jetpack Compose +Identifier +: androidx.compose.animation.core +Feedback +: https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.animation:animation-core-android](androidx_compose_animation_animation-core-android.md.html) +Since +: 1.7.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/animation/animation-core-lint/src/main/java/androidx/compose/animation/core/lint/ArcAnimationSpecTypeDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/animation/animation-core-lint/src/test/java/androidx/compose/animation/core/lint/ArcAnimationSpecTypeDetectorTest.kt) +Copyright Year +: 2023 + +ArcAnimationSpec is designed for 2D values. Particularly, for positional +values such as Offset. +Trying to use it for values of different dimensions (Float, Size, Color, +etc.) will result in unpredictable animation behavior. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/test.kt:14:Information: Arc animation is intended for 2D values +such as Offset, IntOffset or DpOffset. +Otherwise, the animation might not be what you expect. +[ArcAnimationSpecTypeIssue] + ArcAnimationSpec<Float>(ArcAbove) + ---------------- +src/foo/test.kt:15:Information: Arc animation is intended for 2D values +such as Offset, IntOffset or DpOffset. +Otherwise, the animation might not be what you expect. +[ArcAnimationSpecTypeIssue] + ArcAnimationSpec<String>(ArcAbove) + ---------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package foo + +import androidx.compose.animation.core.ArcAnimationSpec +import androidx.compose.animation.core.ArcAbove +import androidx.compose.ui.geometry.Offset +import androidx.compose.ui.unit.DpOffset +import androidx.compose.ui.unit.IntOffset + +fun test() { + ArcAnimationSpec(ArcAbove) + ArcAnimationSpec(ArcAbove) + ArcAnimationSpec(ArcAbove) + ArcAnimationSpec(ArcAbove) + ArcAnimationSpec(ArcAbove) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/animation/animation-core-lint/src/test/java/androidx/compose/animation/core/lint/ArcAnimationSpecTypeDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `ArcAnimationSpecTypeDetector.testPreferredTypeIssue`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=612128. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.animation:animation-core-android:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.animation:animation-core-android:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.animation.core.android) + +# libs.versions.toml +[versions] +animation-core-android = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +animation-core-android = { + module = "androidx.compose.animation:animation-core-android", + version.ref = "animation-core-android" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.animation:animation-core-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.animation:animation-core-android](androidx_compose_animation_animation-core-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ArcAnimationSpecTypeIssue") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ArcAnimationSpecTypeIssue") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ArcAnimationSpecTypeIssue + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ArcAnimationSpecTypeIssue" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ArcAnimationSpecTypeIssue' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ArcAnimationSpecTypeIssue ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ArgInFormattedQuantityStringRes.md.html b/docs/checks/ArgInFormattedQuantityStringRes.md.html new file mode 100644 index 00000000..ccb50c3d --- /dev/null +++ b/docs/checks/ArgInFormattedQuantityStringRes.md.html @@ -0,0 +1,186 @@ + +(#) Count value in formatted string resource + +!!! WARNING: Count value in formatted string resource + This is a warning. + +Id +: `ArgInFormattedQuantityStringRes` +Summary +: Count value in formatted string resource +Severity +: Warning +Category +: Internationalization +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/ArgInFormattedQuantityStringResDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/ArgInFormattedQuantityStringResDetectorTest.kt) +Copyright Year +: 2021 + +Some languages require modifiers to counted values in written text. +Consider consulting #plz-localization if you are unsure if this +formatted string requires a special modifier. If one is required, +consider using `LocalizationUtils.getFormattedCount()`. If not, suppress +this warning. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/com/slack/lint/Foo.java:7:Warning: This may require a localized +count modifier. If so, use LocalizationUtils.getFormattedCount(). +Consult #plz-localization if you are unsure. +[ArgInFormattedQuantityStringRes] + String s = res.getQuantityString(0, 3, 3, "asdf"); + ------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/com/slack/lint/Foo.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package com.slack.lint; + +import android.content.res.Resources; + +public class Foo { + public void bar(Resources res) { + String s = res.getQuantityString(0, 3, 3, "asdf"); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/ArgInFormattedQuantityStringResDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `ArgInFormattedQuantityStringResDetector.getQuantityStringWithNoLocalizedFormatTest`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ArgInFormattedQuantityStringRes") + fun method() { + getQuantityString(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ArgInFormattedQuantityStringRes") + void method() { + getQuantityString(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ArgInFormattedQuantityStringRes + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ArgInFormattedQuantityStringRes" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ArgInFormattedQuantityStringRes' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ArgInFormattedQuantityStringRes ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/AssertionSideEffect.md.html b/docs/checks/AssertionSideEffect.md.html index 2f84b680..8aabf500 100644 --- a/docs/checks/AssertionSideEffect.md.html +++ b/docs/checks/AssertionSideEffect.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.2.0 (May 2022) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AssertDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AssertDetectorTest.kt) -Copyright Year -: 2014 Assertion conditions can have side effects. This is risky because the behavior depends on whether assertions are on or off. This is usually @@ -42,130 +42,42 @@ Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -src/test.kt:4:Warning: Assertion condition has a side effect: i++ +src/test.kt:5:Warning: Assertion condition has a side effect: setOf(42) [AssertionSideEffect] - - assert(i++ < 5) // WARN 1 - --- - - -src/test.kt:5:Warning: Assertion condition has a side effect: x++ -[AssertionSideEffect] - - assert(method1() > 5) // WARN 2 - --------- - - -src/test.kt:6:Warning: Assertion condition has a side effect: x++ -[AssertionSideEffect] - - assert(method2() > 5) // WARN 3 - --------- - - -src/test.kt:7:Warning: Assertion condition has a side effect: x = 0 -[AssertionSideEffect] - - assert(method3()) // WARN 4 - --------- - - -src/test.kt:9:Warning: Assertion condition has a side effect: delete() -[AssertionSideEffect] - - assert(file.delete()) // WARN 5 - ------------- - - -src/test.kt:10:Warning: Assertion condition has a side effect: mkdirs() -[AssertionSideEffect] - - assert(file.mkdirs()) // WARN 6 - ------------- - - -src/test.kt:11:Warning: Assertion condition has a side effect: -add("test") [AssertionSideEffect] - - assert(list.add("test")) // WARN 7 - ---------------- - - -src/test.kt:12:Warning: Assertion condition has a side effect: -setExecutable(true) [AssertionSideEffect] - - assert(file.setExecutable(true)) // WARN 8 - ------------------------ - - -src/test.kt:14:Warning: Assertion condition has a side effect: x++ -[AssertionSideEffect] - - assert(method5()) // WARN 9 - --------- - - -src/test.kt:15:Warning: Assertion condition has a side effect: x++ -[AssertionSideEffect] - - assert(method6()) // WARN 10 - --------- - - -src/test.kt:16:Warning: Assertion condition has a side effect: x++ -[AssertionSideEffect] - - assert(method7()) // WARN 11 - --------- - - + assert(42 != f.setOf(42)) // WARN 1 + ----------- +src/test.kt:6:Warning: Assertion condition has a side effect: f.of = +2024 [AssertionSideEffect] + assert(2024 != (f.of = 2024)) // WARN 2 + ----------- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `src/test.kt`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers -var x: Int = 0 -fun test(file: java.io.File, list: java.util.List) { - var i = 0 - assert(i++ < 5) // WARN 1 - assert(method1() > 5) // WARN 2 - assert(method2() > 5) // WARN 3 - assert(method3()) // WARN 4 - assert(method4()) // OK 1 - assert(file.delete()) // WARN 5 - assert(file.mkdirs()) // WARN 6 - assert(list.add("test")) // WARN 7 - assert(file.setExecutable(true)) // WARN 8 - assert(list.contains("test")) // OK 2 - assert(method5()) // WARN 9 - assert(method6()) // WARN 10 - assert(method7()) // WARN 11 -} +import test.pkg.Foo -fun method1(): Int = x++ // side effect -fun method2(): Int = method1() // indirect side effect -fun method3(): Boolean { - x = 0 // side effect - return true +fun test() { + val f = Foo() + assert(42 != f.setOf(42)) // WARN 1 + assert(2024 != (f.of = 2024)) // WARN 2 } -fun method4(): Boolean { - val x: Int - x = 0 // not a side effect - x++ // not a side effect - return true -} -fun method5(v: Int): Boolean { - if (v > 5) { } else { x++ } - return true -} -fun method6(v: Int): Boolean { - for (i in 0 until v) x++ - return true -} -fun method7(v: Int): Boolean { - try { println(v) } finally { x++ } - return true +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/Foo.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; +public class Foo { + private int OF = 0; + public int getOf() { + return OF; + } + public int setOf(int v) { + int prev = OF; + OF = v; + return prev; + } } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -174,7 +86,7 @@ for the unit tests for this check to see additional scenarios. The above example was automatically extracted from the first unit test -found for this lint check, `AssertDetector.testSideEffects`. +found for this lint check, `AssertDetector.testSetOf_JavaSyntheticPropertySetter`. To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=192708. diff --git a/docs/checks/AssertjImport.md.html b/docs/checks/AssertjImport.md.html new file mode 100644 index 00000000..92b6e091 --- /dev/null +++ b/docs/checks/AssertjImport.md.html @@ -0,0 +1,146 @@ + +(#) Flags Java 6 incompatible imports + +!!! WARNING: Flags Java 6 incompatible imports + This is a warning. + +Id +: `AssertjImport` +Summary +: Flags Java 6 incompatible imports +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html) +Since +: 0.8.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/main/kotlin/com/vanniktech/lintrules/android/AssertjDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/AssertjDetectorTest.kt) + +Importing org.assertj.core.api.Assertions is not ideal. Since it can +require Java 8. It's simple as instead +org.assertj.core.api.Java6Assertions can be imported and provides +guarantee to run on Java 6 as well. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-android:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-android:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.android) + +# libs.versions.toml +[versions] +lint-rules-android = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-android = { + module = "com.vanniktech:lint-rules-android", + version.ref = "lint-rules-android" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("AssertjImport") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("AssertjImport") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection AssertjImport + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="AssertjImport" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'AssertjImport' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore AssertjImport ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/AuthLeak.md.html b/docs/checks/AuthLeak.md.html index 0c3b526a..183dfd55 100644 --- a/docs/checks/AuthLeak.md.html +++ b/docs/checks/AuthLeak.md.html @@ -18,16 +18,18 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 2.2.0 (September 2016) Affects : Kotlin and Java files Editing : This check runs on the fly in the IDE editor +See +: https://goo.gle/AuthLeak Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/StringAuthLeakDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/StringAuthLeakDetectorTest.kt) -Copyright Year -: 2016 Strings in java apps can be discovered by decompiling apps, this lint check looks for code which looks like it may contain an url with a @@ -38,17 +40,11 @@ Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/AuthDemo.java:2:Warning: Possible credential leak [AuthLeak] - private static final String AUTH_IP = "scheme://user:pwd@127.0.0.1:8000"; // WARN 1 --------------------------- - - src/AuthDemo.java:4:Warning: Possible credential leak [AuthLeak] - private static final String LEAK = "http://someuser:%restofmypass@example.com"; // WARN 2 ----------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/AutoDispose.md.html b/docs/checks/AutoDispose.md.html new file mode 100644 index 00000000..43c50b7a --- /dev/null +++ b/docs/checks/AutoDispose.md.html @@ -0,0 +1,190 @@ + +(#) Missing Disposable handling: Apply AutoDispose or cache the Disposable instance manually and enable lenient mode + +!!! ERROR: Missing Disposable handling: Apply AutoDispose or cache the Disposable instance manually and enable lenient mode + This is an error. + +Id +: `AutoDispose` +Summary +: Missing Disposable handling: Apply AutoDispose or cache the Disposable instance manually and enable lenient mode +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: Uber +Identifier +: AutoDispose +Feedback +: https://github.com/uber/AutoDispose/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.uber.autodispose2:autodispose-lint](com_uber_autodispose2_autodispose-lint.md.html) +Since +: 2.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/uber/AutoDispose/tree/main/static-analysis/autodispose-lint/src/main/kotlin/autodispose2/lint/AutoDisposeDetector.kt) +Tests +: [Source Code](https://github.com/uber/AutoDispose/tree/main/static-analysis/autodispose-lint/src/test/kotlin/autodispose2/lint/AutoDisposeDetectorTest.kt) +Copyright Year +: 2019 + +You're subscribing to an observable but not handling its subscription. +This can result in memory leaks. You can avoid memory leaks by appending +`.as(autoDisposable(this))` before you subscribe or cache the Disposable +instance manually and enable lenient mode. More: +https://github.com/uber/AutoDispose/wiki/Lint-Check. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/MyActivity.kt:10:Error: [AutoDispose] + Observable.just(1).subscribe() + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src/foo/MyActivity.kt:12: Error: [AutoDispose] + Observable.just(2).subscribe() + ------------------------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/MyActivity.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package foo +import androidx.appcompat.app.AppCompatActivity +import io.reactivex.rxjava3.core.Observable +import io.reactivex.rxjava3.disposables.CompositeDisposable + +class MyActivity: AppCompatActivity { + private val disposables = CompositeDisposable() + fun doSomething(flag: Boolean) { + if (flag) { + Observable.just(1).subscribe() + } else { + Observable.just(2).subscribe() + } + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/uber/AutoDispose/tree/main/static-analysis/autodispose-lint/src/test/kotlin/autodispose2/lint/AutoDisposeDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `AutoDisposeDetector.checkLenientLintInIfExpression`. +To report a problem with this extracted sample, visit +https://github.com/uber/AutoDispose/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.uber.autodispose2:autodispose-lint:2.2.1") + +// build.gradle +lintChecks 'com.uber.autodispose2:autodispose-lint:2.2.1' + +// build.gradle.kts with version catalogs: +lintChecks(libs.autodispose.lint) + +# libs.versions.toml +[versions] +autodispose-lint = "2.2.1" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +autodispose-lint = { + module = "com.uber.autodispose2:autodispose-lint", + version.ref = "autodispose-lint" +} +``` + +2.2.1 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.uber.autodispose2:autodispose-lint](com_uber_autodispose2_autodispose-lint.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("AutoDispose") + fun method() { + subscribe(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("AutoDispose") + void method() { + subscribe(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection AutoDispose + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="AutoDispose" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'AutoDispose' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore AutoDispose ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/AutoboxingStateCreation.md.html b/docs/checks/AutoboxingStateCreation.md.html new file mode 100644 index 00000000..2095efc3 --- /dev/null +++ b/docs/checks/AutoboxingStateCreation.md.html @@ -0,0 +1,193 @@ + +(#) `State` will autobox values assigned to this state. Use a specialized state type instead. + +!!! Tip: `State` will autobox values assigned to this state. Use a specialized state type instead. + Advice from this check is just a hint; it's a "weak" warning. + +Id +: `AutoboxingStateCreation` +Summary +: `State` will autobox values assigned to this state. Use a specialized state type instead. +Severity +: Hint +Category +: Performance +Platform +: Any +Vendor +: Jetpack Compose +Identifier +: androidx.compose.runtime +Feedback +: https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.runtime:runtime-android](androidx_compose_runtime_runtime-android.md.html) +Since +: 1.5.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/runtime/runtime-lint/src/main/java/androidx/compose/runtime/lint/AutoboxingStateCreationDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/runtime/runtime-lint/src/test/java/androidx/compose/runtime/lint/AutoboxingStateCreationDetectorTest.kt) +Copyright Year +: 2023 + +Calling `mutableStateOf()` when `T` is either backed by a primitive +type on the JVM or is a value class results in a state implementation +that requires all state values to be boxed. This usually causes an +additional allocation for each state write, and adds some additional +work to auto-unbox values when reading the value of the state. Instead, +prefer to use a specialized primitive state implementation for `Int`, +`Long`, `Float`, and `Double` when the state does not need to track null +values and does not override the default `SnapshotMutationPolicy`. See +`mutableIntStateOf()`, `mutableLongStateOf()`, `mutableFloatStateOf()`, +and `mutableDoubleStateOf()` for more information. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/androidx/compose/runtime/lint/test/test.kt:8:Information: Prefer +mutableStateOf instead of mutableStateOf [AutoboxingStateCreation] + val state = mutableStateOf<>() + -------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/androidx/compose/runtime/lint/test/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package androidx.compose.runtime.lint.test + +import androidx.compose.runtime.* +import + +fun valueAssignment() { + val state = mutableStateOf<>() + state.value = +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/runtime/runtime-lint/src/test/java/androidx/compose/runtime/lint/AutoboxingStateCreationDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `AutoboxingStateCreationDetector.testTrivialMutableStateOf_thatCouldBeMutablePrimitiveStateOf`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=612128. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.runtime:runtime-android:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.runtime:runtime-android:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.runtime.android) + +# libs.versions.toml +[versions] +runtime-android = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +runtime-android = { + module = "androidx.compose.runtime:runtime-android", + version.ref = "runtime-android" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.runtime:runtime-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.runtime:runtime-android](androidx_compose_runtime_runtime-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("AutoboxingStateCreation") + fun method() { + mutableStateOf(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("AutoboxingStateCreation") + void method() { + mutableStateOf(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection AutoboxingStateCreation + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="AutoboxingStateCreation" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'AutoboxingStateCreation' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore AutoboxingStateCreation ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/AutoboxingStateValueProperty.md.html b/docs/checks/AutoboxingStateValueProperty.md.html new file mode 100644 index 00000000..530d2ce0 --- /dev/null +++ b/docs/checks/AutoboxingStateValueProperty.md.html @@ -0,0 +1,188 @@ + +(#) State access causes value to be autoboxed + +!!! WARNING: State access causes value to be autoboxed + This is a warning. + +Id +: `AutoboxingStateValueProperty` +Summary +: State access causes value to be autoboxed +Severity +: Warning +Category +: Performance +Platform +: Any +Vendor +: Jetpack Compose +Identifier +: androidx.compose.runtime +Feedback +: https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.runtime:runtime-android](androidx_compose_runtime_runtime-android.md.html) +Since +: 1.5.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/runtime/runtime-lint/src/main/java/androidx/compose/runtime/lint/AutoboxingStateValuePropertyDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/runtime/runtime-lint/src/test/java/androidx/compose/runtime/lint/AutoboxingStateValuePropertyDetectorTest.kt) +Copyright Year +: 2023 + +Avoid using the generic `value` property when using a specialized State +type. Reading or writing to the state's generic `value` property will +result in an unnecessary autoboxing operation. Prefer the specialized +value property (e.g. `intValue` for `MutableIntState`), or use property +delegation to avoid unnecessary allocations. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/androidx/compose/runtime/lint/test/test.kt:7:Warning: Reading value +will cause an autoboxing operation. Use intValue to avoid unnecessary +allocations. [AutoboxingStateValueProperty] + val value = state.value + ----- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/androidx/compose/runtime/lint/test/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package androidx.compose.runtime.lint.test + +import androidx.compose.runtime.mutableIntStateOf + +fun valueAssignment() { + val state = mutableIntStateOf(4) + val value = state.value +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/runtime/runtime-lint/src/test/java/androidx/compose/runtime/lint/AutoboxingStateValuePropertyDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `AutoboxingStateValuePropertyDetector.testReadAutoboxingPropertyAsVariableAssignment`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=612128. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.runtime:runtime-android:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.runtime:runtime-android:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.runtime.android) + +# libs.versions.toml +[versions] +runtime-android = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +runtime-android = { + module = "androidx.compose.runtime:runtime-android", + version.ref = "runtime-android" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.runtime:runtime-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.runtime:runtime-android](androidx_compose_runtime_runtime-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("AutoboxingStateValueProperty") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("AutoboxingStateValueProperty") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection AutoboxingStateValueProperty + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="AutoboxingStateValueProperty" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'AutoboxingStateValueProperty' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore AutoboxingStateValueProperty ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/Autofill.md.html b/docs/checks/Autofill.md.html index a30c7168..84586a89 100644 --- a/docs/checks/Autofill.md.html +++ b/docs/checks/Autofill.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.2.0 (September 2018) Affects : Resource files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AutofillDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AutofillDetectorTest.java) -Copyright Year -: 2018 Specify an `autofillHints` attribute when targeting SDK version 26 or higher or explicitly specify that the view is not important for @@ -57,11 +57,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/autofill.xml:6:Warning: Missing autofillHints attribute [Autofill] - <EditText -------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/AvoidUsingNotNullOperator.md.html b/docs/checks/AvoidUsingNotNullOperator.md.html new file mode 100644 index 00000000..ab6d0af1 --- /dev/null +++ b/docs/checks/AvoidUsingNotNullOperator.md.html @@ -0,0 +1,180 @@ + +(#) Avoid using the !! operator in Kotlin + +!!! WARNING: Avoid using the !! operator in Kotlin + This is a warning. + +Id +: `AvoidUsingNotNullOperator` +Summary +: Avoid using the !! operator in Kotlin +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.8.1 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/NotNullOperatorDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/NotNullOperatorDetectorTest.kt) +Copyright Year +: 2024 + +The `!!` operator is a not-null assertion in Kotlin that will lead to a +`NullPointerException` if the value is null. It's better to use safe +null-handling mechanisms like `?.`, `?:`, `?.let`, etc. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/Test.kt:6:Warning: Avoid using the !! operator +[AvoidUsingNotNullOperator] + t/* this is legal */!!.length + -- +src/foo/Test.kt:7:Warning: Avoid using the !! operator +[AvoidUsingNotNullOperator] + return t!!.length == 1 + -- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/Test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package foo + +class Test { + fun doNothing(t: String?): Boolean { + t/* this is legal */!!.length + return t!!.length == 1 + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/NotNullOperatorDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("AvoidUsingNotNullOperator") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("AvoidUsingNotNullOperator") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection AvoidUsingNotNullOperator + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="AvoidUsingNotNullOperator" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'AvoidUsingNotNullOperator' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore AvoidUsingNotNullOperator ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/BackButton.md.html b/docs/checks/BackButton.md.html index ee27b1d1..0d2af11d 100644 --- a/docs/checks/BackButton.md.html +++ b/docs/checks/BackButton.md.html @@ -20,12 +20,14 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing : This check runs on the fly in the IDE editor See -: https://material.io/design/ +: https://d.android.com/r/studio-ui/designer/material/design Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ButtonDetector.java) Tests @@ -50,14 +52,11 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/buttonbar.xml:183:Warning: Back buttons are not standard on Android; see design guide's navigation section [BackButton] - <Button ------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `res/layout/buttonbar.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -251,6 +250,25 @@ </LinearLayout> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/values/buttonbar-values.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<resources> + + <string name="button"> Button </string> + <string name="ok"> OK </string> + <string name="cancel"> Cancel </string> + <string name="resume"> OK </string> + <string name="giveup"> Cancel </string> + <string name="resume2"> Ok </string> + <string name="giveup2">"CANCEL"</string> + <string name="send"> Send </string> + <string name="abort">Abort</string> + <string name="goback">'Back'</string> + +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ButtonDetectorTest.java) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/BadConfigurationProvider.md.html b/docs/checks/BadConfigurationProvider.md.html index 78269796..0cce2370 100644 --- a/docs/checks/BadConfigurationProvider.md.html +++ b/docs/checks/BadConfigurationProvider.md.html @@ -22,12 +22,22 @@ : androidx.work Feedback : https://issuetracker.google.com/issues/new?component=409906 +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.7+ +Artifact +: [androidx.work:work-runtime](androidx_work_work-runtime.md.html) +Since +: 2.3.0 Affects : Kotlin and Java files Editing : This check runs on the fly in the IDE editor Implementation : [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/work/work-lint/src/main/java/androidx/work/lint/BadConfigurationProviderIssueDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/work/work-lint/src/test/java/androidx/work/lint/BadConfigurationProviderTest.kt) Copyright Year : 2019 @@ -35,6 +45,84 @@ `androidx.work.Configuration.Provider` for on-demand initialization. +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +com/example/App.kt:Error: Expected Application subtype to implement +Configuration.Provider [BadConfigurationProvider] +1 errors, 0 warnings +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`com/example/App.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package com.example + +import android.app.Application + +class App: Application() { + override fun onCreate() { + + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`com/example/CustomProvider.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package com.example + +import androidx.work.Configuration + +class Provider: Configuration.Provider { + override fun getWorkManagerConfiguration(): Configuration = TODO() +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/work/work-lint/src/test/java/androidx/work/lint/BadConfigurationProviderTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `BadConfigurationProviderIssueDetector.testWithInvalidConfigurationProvider`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=409906. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.work:work-runtime:2.10.1") + +// build.gradle +implementation 'androidx.work:work-runtime:2.10.1' + +// build.gradle.kts with version catalogs: +implementation(libs.work.runtime) + +# libs.versions.toml +[versions] +work-runtime = "2.10.1" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +work-runtime = { + module = "androidx.work:work-runtime", + version.ref = "work-runtime" +} +``` + +2.10.1 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.work:work-runtime](androidx_work_work-runtime.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/BadHostnameVerifier.md.html b/docs/checks/BadHostnameVerifier.md.html index bb5aec48..66263d7d 100644 --- a/docs/checks/BadHostnameVerifier.md.html +++ b/docs/checks/BadHostnameVerifier.md.html @@ -18,16 +18,18 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 2.0.0 (April 2016) Affects : Kotlin and Java files Editing : This check runs on the fly in the IDE editor +See +: https://goo.gle/BadHostnameVerifier Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/BadHostnameVerifierDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/BadHostnameVerifierDetectorTest.java) -Copyright Year -: 2015 This check looks for implementations of `HostnameVerifier` whose `verify` method always returns true (thus trusting any hostname) which @@ -41,11 +43,8 @@ src/test/pkg/InsecureHostnameVerifier.java:9:Warning: verify always returns true, which could cause insecure network traffic due to trusting TLS/SSL server certificates for wrong hostnames [BadHostnameVerifier] - public boolean verify(String hostname, SSLSession session) { ------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/BadPeriodicWorkRequestEnqueue.md.html b/docs/checks/BadPeriodicWorkRequestEnqueue.md.html index 798b1873..6d8740b0 100644 --- a/docs/checks/BadPeriodicWorkRequestEnqueue.md.html +++ b/docs/checks/BadPeriodicWorkRequestEnqueue.md.html @@ -20,6 +20,14 @@ : androidx.work Feedback : https://issuetracker.google.com/issues/new?component=409906 +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.7+ +Artifact +: [androidx.work:work-runtime](androidx_work_work-runtime.md.html) +Since +: 2.3.0 Affects : Kotlin and Java files Editing @@ -37,6 +45,40 @@ `enqueueUniquePeriodicWork` with an `ExistingPeriodicWorkPolicy.KEEP` instead. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.work:work-runtime:2.10.1") + +// build.gradle +implementation 'androidx.work:work-runtime:2.10.1' + +// build.gradle.kts with version catalogs: +implementation(libs.work.runtime) + +# libs.versions.toml +[versions] +work-runtime = "2.10.1" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +work-runtime = { + module = "androidx.work:work-runtime", + version.ref = "work-runtime" +} +``` + +2.10.1 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.work:work-runtime](androidx_work_work-runtime.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/BatteryLife.md.html b/docs/checks/BatteryLife.md.html index 9fa2cc00..9b898249 100644 --- a/docs/checks/BatteryLife.md.html +++ b/docs/checks/BatteryLife.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 2.2.0 (September 2016) Affects : Kotlin and Java files and manifest files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/BatteryDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/BatteryDetectorTest.java) -Copyright Year -: 2016 This issue flags code that either * negatively affects battery life, or @@ -49,42 +49,37 @@ android.net.conn.CONNECTIVITY_CHANGE is deprecated for apps targeting N and higher. In general, apps should not rely on this broadcast and instead use WorkManager. [BatteryLife] - <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> ------------------------------------ - - AndroidManifest.xml:10:Warning: Use of REQUEST_IGNORE_BATTERY_OPTIMIZATIONS violates the Play Store Content Policy regarding acceptable use cases, as described in https://developer.android.com/training/monitoring-device-state/doze-standby.html - [BatteryLife] - +[BatteryLife] <action android:name="android.settings.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" /> ----------------------------------------------------- - - AndroidManifest.xml:11:Warning: Use of com.android.camera.NEW_PICTURE is deprecated for all apps starting with the N release independent of the target SDK. Apps should not rely on these broadcasts and instead use WorkManager [BatteryLife] - <action android:name="com.android.camera.NEW_PICTURE" /> ------------------------------ - - AndroidManifest.xml:12:Warning: Use of android.hardware.action.NEW_PICTURE is deprecated for all apps starting with the N release independent of the target SDK. Apps should not rely on these broadcasts and instead use WorkManager [BatteryLife] - <action android:name="android.hardware.action.NEW_PICTURE" /> ----------------------------------- - - +src/test/pkg/BatteryTest.java:15:Warning: Use of +REQUEST_IGNORE_BATTERY_OPTIMIZATIONS violates the Play Store Content +Policy regarding acceptable use cases, as described in +https://developer.android.com/training/monitoring-device-state/doze-standby.html +[BatteryLife] + Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); + ------------------------------------------- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `AndroidManifest.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -106,15 +101,33 @@ </manifest> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/test/pkg/BatteryTest.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; + +import android.annotation.TargetApi; +import android.app.Activity; +import android.content.ActivityNotFoundException; +import android.content.Intent; +import android.net.Uri; +import android.os.Build; +import android.provider.Settings; + +@SuppressWarnings("unused") +public class BatteryTest extends Activity { + @TargetApi(Build.VERSION_CODES.M) + public void testNoNo() throws ActivityNotFoundException { + Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); + intent.setData(Uri.parse("package:my.pkg")); + startActivity(intent); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/BatteryDetectorTest.java) for the unit tests for this check to see additional scenarios. -The above example was automatically extracted from the first unit test -found for this lint check, `BatteryDetector.testConnectivityChange`. -To report a problem with this extracted sample, visit -https://issuetracker.google.com/issues/new?component=192708. - (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/BidiSpoofing.md.html b/docs/checks/BidiSpoofing.md.html index dfba0957..40335a3b 100644 --- a/docs/checks/BidiSpoofing.md.html +++ b/docs/checks/BidiSpoofing.md.html @@ -18,18 +18,20 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.1.0 (January 2022) Affects : Kotlin and Java files Editing : This check runs on the fly in the IDE editor See : https://krebsonsecurity.com/2021/11/trojan-source-bug-threatens-the-security-of-all-code/ +See +: https://goo.gle/BidiSpoofing Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/BidirectionalTextDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/BidirectionalTextDetectorTest.kt) -Copyright Year -: 2021 Unicode bidirectional text characters can alter the order in which the compiler processes tokens. However, this can also be used to hide @@ -43,25 +45,16 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/StretchedString.java:5:Error: String contains misleading Unicode bidirectional text [BidiSpoofing] - if (accessLevel != "user‮ ⁦// Check if admin⁩ ⁦") { ----------------------------- - - src/CommentingOut.java:5:Error: Comment contains misleading Unicode bidirectional text [BidiSpoofing] - /*‮ } ⁦if (isAdmin)⁩ ⁦ begin admins only */ ------------------------------------------- - - src/CommentingOut.java:7:Error: Comment contains misleading Unicode bidirectional text [BidiSpoofing] - /* end admins only ‮ { ⁦*/ -------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here are the relevant source files: diff --git a/docs/checks/BinaryOperationInTimber.md.html b/docs/checks/BinaryOperationInTimber.md.html new file mode 100644 index 00000000..134ea1d8 --- /dev/null +++ b/docs/checks/BinaryOperationInTimber.md.html @@ -0,0 +1,191 @@ + +(#) Use String#format() + +!!! WARNING: Use String#format() + This is a warning. + +Id +: `BinaryOperationInTimber` +Summary +: Use String#format() +Severity +: Warning +Category +: Correctness: Messages +Platform +: Any +Vendor +: JakeWharton/timber +Identifier +: com.jakewharton.timber:timber:{version} +Feedback +: https://github.com/JakeWharton/timber/issues +Min +: Lint 4.0 +Compiled +: Lint 7.0 +Artifact +: [com.jakewharton.timber:timber](com_jakewharton_timber_timber.md.html) +Since +: 4.6.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/JakeWharton/timber/tree/trunk/timber-lint/src/main/java/timber/lint/WrongTimberUsageDetector.kt) +Tests +: [Source Code](https://github.com/JakeWharton/timber/tree/trunk/timber-lint/src/test/java/timber/lint/WrongTimberUsageDetectorTest.kt) + +Since Timber handles String#format() automatically, use this instead of +String concatenation. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/Example.java:6:Warning: Replace String concatenation with +Timber's string formatting [BinaryOperationInTimber] + Timber.d(foo + "bar"); + ----------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`src/foo/Example.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package foo; +import timber.log.Timber; +public class Example { + public void log() { + String foo = "foo"; + Timber.d(foo + "bar"); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/foo/Example.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package foo +import timber.log.Timber +class Example { + fun log() { + val foo = "foo" + Timber.d("${foo}bar") + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/JakeWharton/timber/tree/trunk/timber-lint/src/test/java/timber/lint/WrongTimberUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `WrongTimberUsageDetector.stringConcatenationLeftLiteral`. +To report a problem with this extracted sample, visit +https://github.com/JakeWharton/timber/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +implementation("com.jakewharton.timber:timber:5.0.1") + +// build.gradle +implementation 'com.jakewharton.timber:timber:5.0.1' + +// build.gradle.kts with version catalogs: +implementation(libs.timber) + +# libs.versions.toml +[versions] +timber = "5.0.1" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +timber = { + module = "com.jakewharton.timber:timber", + version.ref = "timber" +} +``` + +5.0.1 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.jakewharton.timber:timber](com_jakewharton_timber_timber.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("BinaryOperationInTimber") + fun method() { + tag(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("BinaryOperationInTimber") + void method() { + tag(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection BinaryOperationInTimber + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="BinaryOperationInTimber" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'BinaryOperationInTimber' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore BinaryOperationInTimber ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/BinderGetCallingInMainThread.md.html b/docs/checks/BinderGetCallingInMainThread.md.html new file mode 100644 index 00000000..85ed1516 --- /dev/null +++ b/docs/checks/BinderGetCallingInMainThread.md.html @@ -0,0 +1,140 @@ + +(#) Incorrect usage of getCallingUid() or getCallingPid() + +!!! ERROR: Incorrect usage of getCallingUid() or getCallingPid() + This is an error. + +Id +: `BinderGetCallingInMainThread` +Summary +: Incorrect usage of getCallingUid() or getCallingPid() +Severity +: Error +Category +: Security +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.0.0 (April 2023) +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/BinderGetCallingInMainThreadDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/BinderGetCallingInMainThreadDetectorTest.kt) + +`Binder.getCallingUid()` and `Binder.getCallingPid()` will return +information about the current process if called inside a thread that is +not handling a binder transaction. This can cause security issues. If +you still want to use your own uid/pid, use `Process.myUid()` or +`Process.myPid()`. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test/pkg/MyService.kt:10:Error: Binder.getCallingUid() should not be +used inside onBind() [BinderGetCallingInMainThread] + Binder.getCallingUid() + ---------------------- +src/test/pkg/MyService.kt:11:Error: Binder.getCallingPid() should not be +used inside onBind() [BinderGetCallingInMainThread] + Binder.getCallingPid() + ---------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test/pkg/MyService.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg + +import android.app.Service +import android.content.Intent +import android.os.Binder +import android.os.IBinder + +class MyService : Service() { + override fun onBind(intent: Intent): IBinder { + Binder.getCallingUid() + Binder.getCallingPid() + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/BinderGetCallingInMainThreadDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("BinderGetCallingInMainThread") + fun method() { + getCallingUid(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("BinderGetCallingInMainThread") + void method() { + getCallingUid(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection BinderGetCallingInMainThread + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="BinderGetCallingInMainThread" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'BinderGetCallingInMainThread' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore BinderGetCallingInMainThread ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/BindingReceiverParameter.md.html b/docs/checks/BindingReceiverParameter.md.html new file mode 100644 index 00000000..3afe4d93 --- /dev/null +++ b/docs/checks/BindingReceiverParameter.md.html @@ -0,0 +1,239 @@ + +(#) @Binds/@Provides functions cannot be extensions + +!!! ERROR: @Binds/@Provides functions cannot be extensions + This is an error. + +Id +: `BindingReceiverParameter` +Summary +: @Binds/@Provides functions cannot be extensions +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.5.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/DaggerIssuesDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/DaggerIssuesDetectorTest.kt) +Copyright Year +: 2021 + +@Binds/@Provides functions cannot be extension functions. Move the +receiver type to a parameter via IDE inspection (option+enter and +convert to parameter). + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/MyQualifier.kt:12:Error: @Binds/@Provides functions cannot be +extensions [BindingReceiverParameter] + @Binds fun Int.bind(): Number + --- +src/foo/MyQualifier.kt:13:Error: @Binds/@Provides functions cannot be +extensions [BindingReceiverParameter] + @Binds fun Long.bind(): Number + ---- +src/foo/MyQualifier.kt:14:Error: @Binds/@Provides functions cannot be +extensions [BindingReceiverParameter] + @Binds fun Double.bind(): Number + ------ +src/foo/MyQualifier.kt:15:Error: @Binds/@Provides functions cannot be +extensions [BindingReceiverParameter] + @Binds fun Float.bind(): Number + ----- +src/foo/MyQualifier.kt:16:Error: @Binds/@Provides functions cannot be +extensions [BindingReceiverParameter] + @Binds fun Short.bind(): Number + ----- +src/foo/MyQualifier.kt:17:Error: @Binds/@Provides functions cannot be +extensions [BindingReceiverParameter] + @Binds fun Byte.bind(): Number + ---- +src/foo/MyQualifier.kt:18:Error: @Binds/@Provides functions cannot be +extensions [BindingReceiverParameter] + @Binds fun Char.bind(): Comparable<Char> + ---- +src/foo/MyQualifier.kt:19:Error: @Binds/@Provides functions cannot be +extensions [BindingReceiverParameter] + @Binds fun String.bind(): Comparable<String> + ------ +src/foo/MyQualifier.kt:20:Error: @Binds/@Provides functions cannot be +extensions [BindingReceiverParameter] + @Binds fun @receiver:MyQualifier Boolean.bind(): Comparable<Boolean> + ------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/MyQualifier.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package foo +import javax.inject.Qualifier +import dagger.Binds +import dagger.Provides +import dagger.Module + +@Qualifier +annotation class MyQualifier + +@Module +interface MyModule { + @Binds fun Int.bind(): Number + @Binds fun Long.bind(): Number + @Binds fun Double.bind(): Number + @Binds fun Float.bind(): Number + @Binds fun Short.bind(): Number + @Binds fun Byte.bind(): Number + @Binds fun Char.bind(): Comparable + @Binds fun String.bind(): Comparable + @Binds fun @receiver:MyQualifier Boolean.bind(): Comparable +} + +@Module +interface MyModule2 { + @Provides fun Int.bind(): Number = this@bind + @Provides fun Long.bind(): Number = this@bind + @Provides fun Double.bind(): Number = this@bind + @Provides fun Float.bind(): Number = this@bind + @Provides fun Short.bind(): Number = this@bind + @Provides fun Byte.bind(): Number = this@bind + @Provides fun Char.bind(): Comparable = this@bind + @Provides fun String.bind(): Comparable = this@bind + @Provides fun @receiver:MyQualifier Boolean.bind(): Comparable = this@bind +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/DaggerIssuesDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `DaggerIssuesDetector.bindings cannot be extension functions`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("BindingReceiverParameter") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("BindingReceiverParameter") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection BindingReceiverParameter + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="BindingReceiverParameter" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'BindingReceiverParameter' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore BindingReceiverParameter ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/BindingReturnType.md.html b/docs/checks/BindingReturnType.md.html new file mode 100644 index 00000000..46b6b524 --- /dev/null +++ b/docs/checks/BindingReturnType.md.html @@ -0,0 +1,196 @@ + +(#) @Binds/@Provides must have a return type + +!!! ERROR: @Binds/@Provides must have a return type + This is an error. + +Id +: `BindingReturnType` +Summary +: @Binds/@Provides must have a return type +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.5.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/DaggerIssuesDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/DaggerIssuesDetectorTest.kt) +Copyright Year +: 2021 + +@Binds/@Provides functions must have a return type. Cannot be void or +Unit. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/MyQualifier.kt:14:Error: @Binds/@Provides must have a return +type [BindingReturnType] + @Provides fun invalidBind3() { + ^ +src/foo/MyQualifier.kt:17:Error: @Binds/@Provides must have a return +type [BindingReturnType] + @Provides fun invalidBind4(): Unit { + ^ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/MyQualifier.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package foo +import javax.inject.Qualifier +import dagger.Binds +import dagger.Provides +import dagger.Module + +@Qualifier +annotation class MyQualifier + +@Module +abstract class MyModule { + @Binds fun invalidBind1(@MyQualifier real: Unit) + @Binds fun invalidBind2(@MyQualifier real: Unit): Unit + @Provides fun invalidBind3() { + + } + @Provides fun invalidBind4(): Unit { + return Unit + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/DaggerIssuesDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `DaggerIssuesDetector.invalid return types`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("BindingReturnType") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("BindingReturnType") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection BindingReturnType + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="BindingReturnType" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'BindingReturnType' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore BindingReturnType ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/BindsMustBeAbstract.md.html b/docs/checks/BindsMustBeAbstract.md.html new file mode 100644 index 00000000..7570d5df --- /dev/null +++ b/docs/checks/BindsMustBeAbstract.md.html @@ -0,0 +1,195 @@ + +(#) @Binds functions must be abstract + +!!! ERROR: @Binds functions must be abstract + This is an error. + +Id +: `BindsMustBeAbstract` +Summary +: @Binds functions must be abstract +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.5.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/DaggerIssuesDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/DaggerIssuesDetectorTest.kt) +Copyright Year +: 2021 + +@Binds functions must be abstract and cannot have function bodies. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/MyQualifier.kt:12:Error: @Binds functions must be abstract +[BindsMustBeAbstract] + @Binds fun invalidBind1(@MyQualifier real: Unit) + ------------------------------------------------ +src/foo/MyQualifier.kt:13:Error: @Binds functions must be abstract +[BindsMustBeAbstract] + @Binds fun invalidBind2(@MyQualifier real: Unit): Unit + ------------------------------------------------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/MyQualifier.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package foo +import javax.inject.Qualifier +import dagger.Binds +import dagger.Provides +import dagger.Module + +@Qualifier +annotation class MyQualifier + +@Module +abstract class MyModule { + @Binds fun invalidBind1(@MyQualifier real: Unit) + @Binds fun invalidBind2(@MyQualifier real: Unit): Unit + @Provides fun invalidBind3() { + + } + @Provides fun invalidBind4(): Unit { + return Unit + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/DaggerIssuesDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `DaggerIssuesDetector.invalid return types`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("BindsMustBeAbstract") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("BindsMustBeAbstract") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection BindsMustBeAbstract + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="BindsMustBeAbstract" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'BindsMustBeAbstract' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore BindsMustBeAbstract ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/BindsTypeMismatch.md.html b/docs/checks/BindsTypeMismatch.md.html new file mode 100644 index 00000000..99f27e88 --- /dev/null +++ b/docs/checks/BindsTypeMismatch.md.html @@ -0,0 +1,204 @@ + +(#) @Binds parameter/return must be type-assignable + +!!! ERROR: @Binds parameter/return must be type-assignable + This is an error. + +Id +: `BindsTypeMismatch` +Summary +: @Binds parameter/return must be type-assignable +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.5.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/DaggerIssuesDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/DaggerIssuesDetectorTest.kt) +Copyright Year +: 2021 + +@Binds function parameters must be type-assignable to their return +types. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/TestModule.kt:18:Error: @Binds parameter/return must be +type-assignable [BindsTypeMismatch] + @Binds fun invalidBind(real: Long): String + ------------------------------------------ +src/foo/TestModule.kt:19:Error: @Binds parameter/return must be +type-assignable [BindsTypeMismatch] + @Binds fun invalidBind(real: Long): Comparable<Boolean> + ------------------------------------------------------- +src/foo/TestModule.kt:23:Error: @Binds parameter/return must be +type-assignable [BindsTypeMismatch] + @Binds fun invalidComplexBinding(real: DetailTypeAItemMapper): ItemMapper<ItemDetail> + ------------------------------------------------------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/TestModule.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package foo +import javax.inject.Qualifier +import dagger.Binds +import dagger.Module + +sealed interface ItemDetail { + object DetailTypeA : ItemDetail +} + +interface ItemMapper + +class DetailTypeAItemMapper : ItemMapper + +@Module +interface MyModule { + @Binds fun validBind(real: Int): Number + @Binds fun validBind(real: Boolean): Comparable + @Binds fun invalidBind(real: Long): String + @Binds fun invalidBind(real: Long): Comparable + + @Binds fun validComplexBinding(real: DetailTypeAItemMapper): ItemMapper + @Binds fun validComplexBinding2(real: DetailTypeAItemMapper): ItemMapper<*> + @Binds fun invalidComplexBinding(real: DetailTypeAItemMapper): ItemMapper +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/DaggerIssuesDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `DaggerIssuesDetector.binds type mismatches`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("BindsTypeMismatch") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("BindsTypeMismatch") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection BindsTypeMismatch + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="BindsTypeMismatch" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'BindsTypeMismatch' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore BindsTypeMismatch ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/BindsWrongParameterCount.md.html b/docs/checks/BindsWrongParameterCount.md.html new file mode 100644 index 00000000..37973a76 --- /dev/null +++ b/docs/checks/BindsWrongParameterCount.md.html @@ -0,0 +1,185 @@ + +(#) @Binds must have one parameter + +!!! ERROR: @Binds must have one parameter + This is an error. + +Id +: `BindsWrongParameterCount` +Summary +: @Binds must have one parameter +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.5.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/DaggerIssuesDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/DaggerIssuesDetectorTest.kt) +Copyright Year +: 2021 + +@Binds functions require a single parameter as an input to bind. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/MyModule.kt:8:Error: @Binds must have one parameter +[BindsWrongParameterCount] + @Binds fun invalidBind(real: Int, second: Int): Number + ------------------------ +src/foo/MyModule.kt:9:Error: @Binds must have one parameter +[BindsWrongParameterCount] + @Binds fun invalidBind(): Number + -------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/MyModule.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package foo +import dagger.Binds +import dagger.Module + +@Module +interface MyModule { + @Binds fun validBind(real: Int): Number + @Binds fun invalidBind(real: Int, second: Int): Number + @Binds fun invalidBind(): Number +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/DaggerIssuesDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `DaggerIssuesDetector.binds param counts`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("BindsWrongParameterCount") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("BindsWrongParameterCount") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection BindsWrongParameterCount + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="BindsWrongParameterCount" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'BindsWrongParameterCount' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore BindsWrongParameterCount ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/BlockedPrivateApi.md.html b/docs/checks/BlockedPrivateApi.md.html index c3f1b5d4..83203fc1 100644 --- a/docs/checks/BlockedPrivateApi.md.html +++ b/docs/checks/BlockedPrivateApi.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.5.0 (August 2019) Affects : Kotlin and Java files Editing @@ -30,8 +32,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/PrivateApiDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/PrivateApiDetectorTest.kt) -Copyright Year -: 2017 Usage of restricted non-SDK interface is forbidden for this targetSDK. Accessing non-SDK methods or fields through reflection has a high @@ -45,11 +45,8 @@ src/test/pkg/TestReflection.java:12:Error: Reflective access to NETWORK_TYPES is forbidden when targeting API 28 and above [BlockedPrivateApi] - Field deniedField = TelephonyManager.class.getDeclaredField("NETWORK_TYPES"); // ERROR 1 -------------------------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/BomWithoutPlatform.md.html b/docs/checks/BomWithoutPlatform.md.html new file mode 100644 index 00000000..08ec003a --- /dev/null +++ b/docs/checks/BomWithoutPlatform.md.html @@ -0,0 +1,141 @@ + +(#) Using a BOM without platform call + +!!! WARNING: Using a BOM without platform call + This is a warning. + +Id +: `BomWithoutPlatform` +Summary +: Using a BOM without platform call +Severity +: Warning +Category +: Correctness +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.1.0 (July 2023) +Affects +: Gradle build files and TOML files +Editing +: This check runs on the fly in the IDE editor +See +: https://developer.android.com/r/tools/gradle-bom-docs +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GradleDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) + +When including a BOM, the dependency's coordinates must be wrapped in a +call to `platform()` for Gradle to interpret it correctly. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +build.gradle:6:Warning: BOM should be added with a call to platform() +[BomWithoutPlatform] + implementation(libs.compose.bom) + ---------------- +build.gradle:7:Warning: BOM should be added with a call to platform() +[BomWithoutPlatform] + testImplementation(libs.compose.bom) + ---------------- +build.gradle:8:Warning: BOM should be added with a call to platform() +[BomWithoutPlatform] + testImplementation "androidx.compose:compose-bom:2023.01.00" + ----------------------------------------- +build.gradle:9:Warning: BOM should be added with a call to platform() +[BomWithoutPlatform] + api("androidx.compose:compose-bom:2023.01.00") + ----------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`src/libs.versions.toml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~toml linenumbers +[versions] +composeBom = "2023.01.00" +[libraries] +compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" } +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`build.gradle`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~groovy linenumbers +plugins { + id 'com.android.application' + id 'kotlin-android' +} +dependencies { + implementation(libs.compose.bom) + testImplementation(libs.compose.bom) + testImplementation "androidx.compose:compose-bom:2023.01.00" + api("androidx.compose:compose-bom:2023.01.00") + // Make sure we don't complain about existing platforms + implementation platform("androidx.compose:compose-bom:2023.01.00") +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `GradleDetector.testBomWithoutPlatform`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=192708. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection BomWithoutPlatform + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="BomWithoutPlatform" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'BomWithoutPlatform' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore BomWithoutPlatform ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/BottomAppBar.md.html b/docs/checks/BottomAppBar.md.html index ee7e4ca7..a12e329a 100644 --- a/docs/checks/BottomAppBar.md.html +++ b/docs/checks/BottomAppBar.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.2.0 (September 2018) Affects : Resource files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/BottomAppBarDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/BottomAppBarDetectorTest.kt) -Copyright Year -: 2018 The `BottomAppBar` widget must be placed within a `CoordinatorLayout`. @@ -38,14 +38,40 @@ res/layout/wrong1.xml:9:Error: This BottomAppBar must be wrapped in a CoordinatorLayout (android.support.design.widget.CoordinatorLayout) [BottomAppBar] - <android.support.design.bottomappbar.BottomAppBar ------------------------------------------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Here are the relevant source files: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/layout/ok.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<androidx.coordinatorlayout.widget.CoordinatorLayout + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="#eeeeee"> -Here is the source file referenced above: + <com.google.android.material.bottomappbar.BottomAppBar + android:id="@+id/bottom_app_bar" + style="@style/Widget.MaterialComponents.BottomAppBar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="bottom" + app:navigationIcon="@drawable/ic_menu_black_24dp"/> + + <com.google.android.material.floatingactionbutton.FloatingActionButton + android:id="@+id/fab" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:tint="@android:color/white" + app:layout_anchor="@id/bottom_app_bar" + app:srcCompat="@drawable/ic_add_black_24dp" + tools:ignore="RtlHardcoded"/> +</androidx.coordinatorlayout.widget.CoordinatorLayout> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `res/layout/wrong1.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -68,6 +94,19 @@ </LinearLayout> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/layout/wrong2.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers + <com.google.android.material.bottomappbar.BottomAppBar + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + android:id="@+id/bottom_app_bar" + style="@style/Widget.MaterialComponents.BottomAppBar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="bottom" +app:navigationIcon="@drawable/ic_menu_black_24dp"/> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/BottomAppBarDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/BrokenIterator.md.html b/docs/checks/BrokenIterator.md.html index 95cad947..2f49c1ac 100644 --- a/docs/checks/BrokenIterator.md.html +++ b/docs/checks/BrokenIterator.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.6.0 (February 2020) Affects : Kotlin and Java files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/IteratorDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/IteratorDetectorTest.kt) -Copyright Year -: 2019 **For LinkedHashMap:** @@ -61,50 +61,35 @@ LinkedHashMap#spliterator was broken in API 24 and 25. Workaround: Use java.util.Spliterators.spliterator(c2a, c2a.spliterator().characteristics()) [BrokenIterator] - Spliterator<String> keys2a = c2a.spliterator(); // Warn ----------------- - - src/test/pkg/LinkedHashmapTest.java:35:Warning: LinkedHashMap#spliterator was broken in API 24 and 25. Workaround: Use java.util.Spliterators.spliterator(c2b, c2b.spliterator().characteristics()) [BrokenIterator] - Spliterator<String> keys2b = c2b.spliterator(); // Warn ----------------- - - src/test/pkg/LinkedHashmapTest.java:36:Warning: LinkedHashMap#spliterator was broken in API 24 and 25. Workaround: Use java.util.Spliterators.spliterator(c2c, c2c.spliterator().characteristics()) [BrokenIterator] - Spliterator<Entry<String, String>> keys2c = c2c.spliterator(); // Warn ----------------- - - src/test/pkg/LinkedHashmapTest.java:39:Warning: LinkedHashMap#stream was broken in API 24 and 25. Workaround: Use java.util.stream.StreamSupport.stream(spliterator, false) [BrokenIterator] - Stream<String> stream1 = c2a.stream(); // Warn ------------ - - src/test/pkg/LinkedHashmapTest.java:40:Warning: LinkedHashMap#spliterator was broken in API 24 and 25. Workaround: Use java.util.Spliterators.spliterator(c2a, c2a.spliterator().characteristics()) [BrokenIterator] - StreamSupport.stream(c2a.spliterator(), false); // Warn ----------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `src/test/pkg/LinkedHashmapTest.java`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers @@ -155,6 +140,46 @@ } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/test/pkg/kt/LinkedHashmapTest.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg.kt + +import android.os.Build +import androidx.annotation.RequiresApi +import java.util.* +import java.util.stream.StreamSupport + +class LinkedHashmapTest { + @RequiresApi(api = Build.VERSION_CODES.N) + fun test() { + val map1 = HashMap() + val c1a = map1.keys + val c1b = map1.values + val c1c = map1.entries + val keys1a = c1a.spliterator() + val keys1b = c1b.spliterator() + val keys1c = c1c.spliterator() // OK (not a LinkedHashMap) + val keys1 = Spliterators.spliterator(c1a, c1a.spliterator().characteristics())// OK + + val map2 = LinkedHashMap() + val c2a = map2.keys + val c2b = map2.values + val c2c = map2.entries + + val keys2a = c2a.spliterator() // Warn + val keys2b = c2b.spliterator() // Warn + val keys2c = c2c.spliterator() // Warn + val keys2 = Spliterators.spliterator(c2a, c2a.spliterator().characteristics())// OK + + val stream1 = c2a.stream() // Warn + StreamSupport.stream(c2a.spliterator(), false) // Warn + + Spliterators.spliterator(c2a, c2a.spliterator().characteristics()) // OK + StreamSupport.stream(keys2, false) // OK + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/IteratorDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/BuildListAdds.md.html b/docs/checks/BuildListAdds.md.html new file mode 100644 index 00000000..d6c87220 --- /dev/null +++ b/docs/checks/BuildListAdds.md.html @@ -0,0 +1,129 @@ + +(#) Missing `add` call in `buildList` + +!!! WARNING: Missing `add` call in `buildList` + This is a warning. + +Id +: `BuildListAdds` +Summary +: Missing `add` call in `buildList` +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.4.0 (April 2024) +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/BuildListDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/BuildListDetectorTest.kt) + +The `buildList { }` standard library function is a convenient way to +build lists, but you need to actually call `add` on the items. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/Cubic.kt:4:Warning: No add calls within buildList lambda; this is +usually a mistake [BuildListAdds] + return buildList { // ERROR + --------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/Cubic.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +class Cubic(id: Int) +val _morphMatch = listOf(1) +fun asCubics_broken(progress: Float): List { + return buildList { // ERROR + for (i in _morphMatch.indices) { + Cubic(i) // ERROR: Should have been wrapped in an add call. + } + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/BuildListDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("BuildListAdds") + fun method() { + buildList(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("BuildListAdds") + void method() { + buildList(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection BuildListAdds + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="BuildListAdds" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'BuildListAdds' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore BuildListAdds ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ButtonCase.md.html b/docs/checks/ButtonCase.md.html index 69714347..6c03916a 100644 --- a/docs/checks/ButtonCase.md.html +++ b/docs/checks/ButtonCase.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -40,22 +42,208 @@ res/values/buttonbar-values.xml:9:Warning: The standard Android way to capitalize Ok is "OK" (tip: use @android:string/ok instead) [ButtonCase] - <string name="resume2"> Ok </string> -- - - res/values/buttonbar-values.xml:10:Warning: The standard Android way to capitalize CANCEL is "Cancel" (tip: use @android:string/cancel instead) [ButtonCase] - <string name="giveup2">"CANCEL"</string> -------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Here are the relevant source files: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/layout/buttonbar.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" > + + <!-- Hardcoded strings, wrong order --> + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" > + + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="OK" /> + + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Cancel" /> + </LinearLayout> + + <!-- Hardcoded strings, right order --> + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" > + + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Cancel" /> + + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="OK" /> + </LinearLayout> + + <!-- @android:string resources, wrong order --> + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" > + + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@android:string/ok" /> + + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@android:string/cancel" /> + </LinearLayout> + + <!-- @android:string resources, right order --> + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" > + + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@android:string/cancel" /> + + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@android:string/ok" /> + </LinearLayout> + + <!-- @string/ok/cancel resources, right order --> + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" > + + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/cancel" /> -Here is the source file referenced above: + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/ok" /> + </LinearLayout> + + <!-- @string/ok/cancel resources, wrong order --> + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" > + + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/ok" /> + + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/cancel" /> + </LinearLayout> + + <!-- Random name resources, right order --> + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" > + + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/giveup" /> + + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/resume" /> + </LinearLayout> + + <!-- Random name resources, wrong order --> + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" > + + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/resume" /> + + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/giveup" /> + </LinearLayout> + + <!-- Random name resources with varying case, wrong order --> + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" > + + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/resume2" /> + + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/giveup2" /> + </LinearLayout> + + <!-- Resources with only one of OK and Cancel, wrong order --> + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" > + + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/ok" /> + + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/abort" /> + </LinearLayout> + + <!-- Resources with only one of OK and Cancel, wrong order --> + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" > + + <Button + android:layout_width="wrap_content" android:background="?android:attr/selectableItemBackground" + android:layout_height="wrap_content" + android:text="@string/send" /> + + <Button + android:layout_width="wrap_content" android:background="?android:attr/selectableItemBackground" + android:layout_height="wrap_content" + android:text="@string/cancel" /> + </LinearLayout> + + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/goback" /> + +</LinearLayout> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `res/values/buttonbar-values.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers diff --git a/docs/checks/ButtonOrder.md.html b/docs/checks/ButtonOrder.md.html index cdff1ab0..30b185f7 100644 --- a/docs/checks/ButtonOrder.md.html +++ b/docs/checks/ButtonOrder.md.html @@ -18,12 +18,14 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing : This check runs on the fly in the IDE editor See -: https://material.io/components/dialogs/ +: https://d.android.com/r/studio-ui/designer/material/dialogs Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ButtonDetector.java) Tests @@ -50,56 +52,35 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/buttonbar.xml:12:Warning: OK button should be on the right (was "OK | Cancel", should be "Cancel | OK") [ButtonOrder] - <Button ------ - - res/layout/buttonbar.xml:44:Warning: OK button should be on the right (was "OK | Cancel", should be "Cancel | OK") [ButtonOrder] - <Button ------ - - res/layout/buttonbar.xml:92:Warning: OK button should be on the right (was "OK | Cancel", should be "Cancel | OK") [ButtonOrder] - <Button ------ - - res/layout/buttonbar.xml:124:Warning: OK button should be on the right (was "OK | Cancel", should be "Cancel | OK") [ButtonOrder] - <Button ------ - - res/layout/buttonbar.xml:140:Warning: OK button should be on the right (was "Ok | CANCEL", should be "CANCEL | Ok") [ButtonOrder] - <Button ------ - - res/layout/buttonbar.xml:156:Warning: OK button should be on the right (was "OK | Abort", should be "Abort | OK") [ButtonOrder] - <Button ------ - - res/layout/buttonbar.xml:177:Warning: Cancel button should be on the left (was "Send | Cancel", should be "Cancel | Send") [ButtonOrder] - <Button ------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `res/layout/buttonbar.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -293,6 +274,25 @@ </LinearLayout> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/values/buttonbar-values.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<resources> + + <string name="button"> Button </string> + <string name="ok"> OK </string> + <string name="cancel"> Cancel </string> + <string name="resume"> OK </string> + <string name="giveup"> Cancel </string> + <string name="resume2"> Ok </string> + <string name="giveup2">"CANCEL"</string> + <string name="send"> Send </string> + <string name="abort">Abort</string> + <string name="goback">'Back'</string> + +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ButtonDetectorTest.java) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/ButtonStyle.md.html b/docs/checks/ButtonStyle.md.html index beb7c6dc..30819617 100644 --- a/docs/checks/ButtonStyle.md.html +++ b/docs/checks/ButtonStyle.md.html @@ -18,12 +18,14 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing : This check runs on the fly in the IDE editor See -: https://material.io/components/dialogs/ +: https://d.android.com/r/studio-ui/designer/material/dialogs Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ButtonDetector.java) Tests @@ -46,166 +48,106 @@ res/layout/buttonbar.xml:12:Warning: Buttons in button bars should be borderless; use style="?android:attr/buttonBarButtonStyle" (and ?android:attr/buttonBarStyle on the parent) [ButtonStyle] - <Button ------ - - res/layout/buttonbar.xml:17:Warning: Buttons in button bars should be borderless; use style="?android:attr/buttonBarButtonStyle" (and ?android:attr/buttonBarStyle on the parent) [ButtonStyle] - <Button ------ - - res/layout/buttonbar.xml:28:Warning: Buttons in button bars should be borderless; use style="?android:attr/buttonBarButtonStyle" (and ?android:attr/buttonBarStyle on the parent) [ButtonStyle] - <Button ------ - - res/layout/buttonbar.xml:33:Warning: Buttons in button bars should be borderless; use style="?android:attr/buttonBarButtonStyle" (and ?android:attr/buttonBarStyle on the parent) [ButtonStyle] - <Button ------ - - res/layout/buttonbar.xml:44:Warning: Buttons in button bars should be borderless; use style="?android:attr/buttonBarButtonStyle" (and ?android:attr/buttonBarStyle on the parent) [ButtonStyle] - <Button ------ - - res/layout/buttonbar.xml:49:Warning: Buttons in button bars should be borderless; use style="?android:attr/buttonBarButtonStyle" (and ?android:attr/buttonBarStyle on the parent) [ButtonStyle] - <Button ------ - - res/layout/buttonbar.xml:60:Warning: Buttons in button bars should be borderless; use style="?android:attr/buttonBarButtonStyle" (and ?android:attr/buttonBarStyle on the parent) [ButtonStyle] - <Button ------ - - res/layout/buttonbar.xml:65:Warning: Buttons in button bars should be borderless; use style="?android:attr/buttonBarButtonStyle" (and ?android:attr/buttonBarStyle on the parent) [ButtonStyle] - <Button ------ - - res/layout/buttonbar.xml:76:Warning: Buttons in button bars should be borderless; use style="?android:attr/buttonBarButtonStyle" (and ?android:attr/buttonBarStyle on the parent) [ButtonStyle] - <Button ------ - - res/layout/buttonbar.xml:81:Warning: Buttons in button bars should be borderless; use style="?android:attr/buttonBarButtonStyle" (and ?android:attr/buttonBarStyle on the parent) [ButtonStyle] - <Button ------ - - res/layout/buttonbar.xml:92:Warning: Buttons in button bars should be borderless; use style="?android:attr/buttonBarButtonStyle" (and ?android:attr/buttonBarStyle on the parent) [ButtonStyle] - <Button ------ - - res/layout/buttonbar.xml:97:Warning: Buttons in button bars should be borderless; use style="?android:attr/buttonBarButtonStyle" (and ?android:attr/buttonBarStyle on the parent) [ButtonStyle] - <Button ------ - - res/layout/buttonbar.xml:108:Warning: Buttons in button bars should be borderless; use style="?android:attr/buttonBarButtonStyle" (and ?android:attr/buttonBarStyle on the parent) [ButtonStyle] - <Button ------ - - res/layout/buttonbar.xml:113:Warning: Buttons in button bars should be borderless; use style="?android:attr/buttonBarButtonStyle" (and ?android:attr/buttonBarStyle on the parent) [ButtonStyle] - <Button ------ - - res/layout/buttonbar.xml:124:Warning: Buttons in button bars should be borderless; use style="?android:attr/buttonBarButtonStyle" (and ?android:attr/buttonBarStyle on the parent) [ButtonStyle] - <Button ------ - - res/layout/buttonbar.xml:129:Warning: Buttons in button bars should be borderless; use style="?android:attr/buttonBarButtonStyle" (and ?android:attr/buttonBarStyle on the parent) [ButtonStyle] - <Button ------ - - res/layout/buttonbar.xml:140:Warning: Buttons in button bars should be borderless; use style="?android:attr/buttonBarButtonStyle" (and ?android:attr/buttonBarStyle on the parent) [ButtonStyle] - <Button ------ - - res/layout/buttonbar.xml:145:Warning: Buttons in button bars should be borderless; use style="?android:attr/buttonBarButtonStyle" (and ?android:attr/buttonBarStyle on the parent) [ButtonStyle] - <Button ------ - - res/layout/buttonbar.xml:156:Warning: Buttons in button bars should be borderless; use style="?android:attr/buttonBarButtonStyle" (and ?android:attr/buttonBarStyle on the parent) [ButtonStyle] - <Button ------ - - res/layout/buttonbar.xml:161:Warning: Buttons in button bars should be borderless; use style="?android:attr/buttonBarButtonStyle" (and ?android:attr/buttonBarStyle on the parent) [ButtonStyle] - <Button ------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `res/layout/buttonbar.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -399,6 +341,120 @@ </LinearLayout> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/layout/buttonbar2.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="wrap_content" + android:layout_height="wrap_content" > + + <ProgressBar + android:id="@+id/loading_progress" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentLeft="true" + android:layout_alignParentTop="true" + android:layout_marginBottom="60dip" + android:layout_marginLeft="40dip" + android:layout_marginTop="40dip" + android:max="10000" /> + + <TextView + android:id="@+id/text" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentTop="true" + android:layout_alignWithParentIfMissing="true" + android:layout_marginBottom="60dip" + android:layout_marginLeft="40dip" + android:layout_marginTop="40dip" + android:layout_toRightOf="@id/loading_progress" + android:ellipsize="end" + android:maxLines="3" + android:paddingRight="120dip" + android:text="@string/creating_instant_mix" + android:textAppearance="?android:attr/textAppearanceMedium" /> + + <Button + android:id="@+id/cancel" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentLeft="true" + android:layout_alignRight="@id/text" + android:layout_below="@id/text" + android:background="@null" + android:text="@string/cancel" /> + + <ImageView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_above="@id/cancel" + android:layout_alignLeft="@id/cancel" + android:layout_alignRight="@id/cancel" + android:scaleType="fitXY" + android:src="@drawable/menu_list_divider" /> + +</RelativeLayout> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/layout/buttonbar3.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical" > + + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_horizontal" + android:text="@string/weekpicker_title" + android:textAppearance="?android:attr/textAppearanceMedium" /> + + <RelativeLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:background="#ffffff" + android:padding="6dip" > + + <Button + android:id="@+id/set" + android:layout_width="120dip" + android:layout_height="wrap_content" + android:layout_alignParentLeft="true" + android:text="@string/weekpicker_set" /> + + <Button + android:id="@+id/cancel" + android:layout_width="120dip" + android:layout_height="wrap_content" + android:layout_alignParentRight="true" + android:text="@string/cancel" /> + </RelativeLayout> + +</LinearLayout> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/values/buttonbar-values.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<resources> + + <string name="button"> Button </string> + <string name="ok"> OK </string> + <string name="cancel"> Cancel </string> + <string name="resume"> OK </string> + <string name="giveup"> Cancel </string> + <string name="resume2"> Ok </string> + <string name="giveup2">"CANCEL"</string> + <string name="send"> Send </string> + <string name="abort">Abort</string> + <string name="goback">'Back'</string> + +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ButtonDetectorTest.java) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/ByteOrderMark.md.html b/docs/checks/ByteOrderMark.md.html index 56e02ba3..c795ba6f 100644 --- a/docs/checks/ByteOrderMark.md.html +++ b/docs/checks/ByteOrderMark.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Gradle build files, Kotlin and Java files, manifest files, property files, resource files and shrinking configuration files Editing @@ -48,14 +50,11 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text AndroidManifest.xml:1:Error: Found byte-order-mark in the middle of a file [ByteOrderMark] - <manifest package='foo.bar'> - - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `AndroidManifest.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -63,6 +62,49 @@ </manifest> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/values-zh-rCN/bom.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<resources xmlns:tools="http://schemas.android.com/tools"> + <string name="hanping_chinese_lite_app_name">(Translated name)</string> + <string tools:ignore='ByteOrderMark' name="something">testtest2</string> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/raw/bom_allowed.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<resources xmlns:tools="http://schemas.android.com/tools"> + <string name="hanping_chinese_lite_app_name">(Translated name)</string> + <string tools:ignore='ByteOrderMark' name="something">testtest2</string> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/MyTest.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; +import android.annotation.SuppressLint; +public class MyTest { + public void test1() { + String s = "\uFEFF"; // OK + String t = ""; // ERROR + } + @SuppressLint("ByteOrderMark") + public void test2() { + String s = ""; //OK/suppressed + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`proguard.cfg`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~proguard linenumbers +-optimizationpasses 5 +-dontusemixedcaseclassnames +-dontskipnonpubliclibraryclasses +-dontpreverify +-verbose +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ByteOrderMarkDetectorTest.java) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/CanvasSize.md.html b/docs/checks/CanvasSize.md.html index 25700631..6a6ce5c8 100644 --- a/docs/checks/CanvasSize.md.html +++ b/docs/checks/CanvasSize.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.2.0 (September 2018) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/CanvasSizeDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/CanvasSizeDetectorTest.kt) -Copyright Year -: 2018 In a custom view's draw implementation, you should normally call `getWidth` and `getHeight` on the custom view itself, not on the @@ -56,37 +56,25 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/MyCustomView1.java:27:Warning: Calling Canvas.getWidth() is usually wrong; you should be calling getWidth() instead [CanvasSize] - int width4 = canvas.getWidth(); // WARN ----------------- - - src/test/pkg/MyCustomView1.java:28:Warning: Calling Canvas.getHeight() is usually wrong; you should be calling getHeight() instead [CanvasSize] - int height4 = canvas.getHeight(); // WARN ------------------ - - src/test/pkg/MyCustomView1.java:34:Warning: Calling Canvas.getWidth() is usually wrong; you should be calling getWidth() instead [CanvasSize] - int width4 = canvas.getWidth(); // WARN ----------------- - - src/test/pkg/MyCustomView1.java:35:Warning: Calling Canvas.getHeight() is usually wrong; you should be calling getHeight() instead [CanvasSize] - int height4 = canvas.getHeight(); // WARN ------------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `src/test/pkg/MyCustomView1.java`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers @@ -134,6 +122,66 @@ } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/test/pkg/MyCustomView2.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg + +import android.annotation.SuppressLint +import android.content.Context +import android.graphics.Canvas +import android.os.Build +import android.util.AttributeSet +import android.view.View + +@SuppressLint("ViewConstructor") +class MyCustomView2(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : View(context, attrs, defStyleAttr, defStyleRes) { + + override fun onDraw(canvas: Canvas) { + val view = this + val width3 = view.width // OK + val height3 = view.height // OK + val width4 = canvas.width // WARN + val height4 = canvas.height // WARN + val width5 = canvas.getWidth() // WARN + val height5 = canvas.getHeight() // WARN + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/MyDrawable.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; + +import android.graphics.Canvas; +import android.graphics.drawable.Drawable; + +@SuppressWarnings({"unused", "ClassNameDiffersFromFileName","MethodMayBeStatic", "NullableProblems"}) +public abstract class MyDrawable extends Drawable { + @Override + public void draw(Canvas canvas) { + int width1 = getBounds().width(); // OK + int width2 = canvas.getWidth(); // WARN + int height2 = canvas.getHeight(); // WARN + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/MyDrawableKotlin.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg + +import android.graphics.Canvas +import android.graphics.drawable.Drawable + +abstract class MyDrawableKotlin : Drawable() { + override fun draw(canvas: Canvas) { + val width1 = bounds.width() // OK + val width2 = canvas.width // WARN + val height2 = canvas.height // WARN + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/CanvasSizeDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/CastingViewContextToActivity.md.html b/docs/checks/CastingViewContextToActivity.md.html new file mode 100644 index 00000000..3d4c6bee --- /dev/null +++ b/docs/checks/CastingViewContextToActivity.md.html @@ -0,0 +1,149 @@ + +(#) Unsafe cast of `Context` to `Activity` + +!!! ERROR: Unsafe cast of `Context` to `Activity` + This is an error. + +Id +: `CastingViewContextToActivity` +Summary +: Unsafe cast of `Context` to `Activity` +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/ViewContextDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/ViewContextDetectorTest.kt) +Copyright Year +: 2021 + +`View.getContext()` is not guaranteed to return an `Activity` and can +often return a `ContextWrapper` instead resulting in a +`ClassCastException`. Instead, use +`UiUtils.getActivityFromView()`. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("CastingViewContextToActivity") + fun method() { + getContext(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("CastingViewContextToActivity") + void method() { + getContext(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection CastingViewContextToActivity + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="CastingViewContextToActivity" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'CastingViewContextToActivity' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore CastingViewContextToActivity ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/CheckResult.md.html b/docs/checks/CheckResult.md.html index 32a8007c..70d6cab3 100644 --- a/docs/checks/CheckResult.md.html +++ b/docs/checks/CheckResult.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.1.0 (March 2018) Affects : Kotlin and Java files and test sources Editing @@ -26,11 +28,9 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/CheckResultDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/CheckResultDetectorTest.kt) -Copyright Year -: 2017 Some methods have no side effects, and calling them without doing -something without the result is suspicious. +something with the result is suspicious. !!! Tip This lint check has an associated quickfix available in the IDE. @@ -41,11 +41,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/test.kt:10:Warning: The result of double is not used [CheckResult] - score.double() -------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/ChildInNonViewGroup.md.html b/docs/checks/ChildInNonViewGroup.md.html new file mode 100644 index 00000000..0000e8fe --- /dev/null +++ b/docs/checks/ChildInNonViewGroup.md.html @@ -0,0 +1,115 @@ + +(#) Only view groups can have children + +!!! ERROR: Only view groups can have children + This is an error. + +Id +: `ChildInNonViewGroup` +Summary +: Only view groups can have children +Severity +: Error +Category +: Correctness +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.7.0 (October 2024) +Affects +: Resource files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ChildInNonViewGroupDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ChildInNonViewGroupDetectorTest.kt) + +Only classes inheriting from `ViewGroup` can have children. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +res/layout/wrong.xml:9:Error: A ImageView should have no children +declared in XML [ChildInNonViewGroup] + <TextView /> + -------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`res/layout/wrong.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <ImageView + android:layout_width="wrap_content" + android:layout_height="wrap_content"> + <TextView /> + </ImageView> + +</LinearLayout> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ChildInNonViewGroupDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `ChildInNonViewGroupDetector.test wrong nesting of TextView within ImageView`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=192708. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute + `tools:ignore="ChildInNonViewGroup"` on the problematic XML element + (or one of its enclosing elements). You may also need to add the + following namespace declaration on the root element in the XML file + if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ChildInNonViewGroup" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ChildInNonViewGroup' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ChildInNonViewGroup ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ChromeOsAbiSupport.md.html b/docs/checks/ChromeOsAbiSupport.md.html new file mode 100644 index 00000000..6b9e14c0 --- /dev/null +++ b/docs/checks/ChromeOsAbiSupport.md.html @@ -0,0 +1,126 @@ + +(#) Missing ABI Support for ChromeOS + +!!! WARNING: Missing ABI Support for ChromeOS + This is a warning. + +Id +: `ChromeOsAbiSupport` +Summary +: Missing ABI Support for ChromeOS +Severity +: Warning +Category +: Correctness: Chrome OS +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.0.0 (April 2023) +Affects +: Gradle build files +Editing +: This check runs on the fly in the IDE editor +See +: https://developer.android.com/ndk/guides/abis +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GradleDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) + +To properly support ChromeOS, your Android application should have an +x86 and/or x86_64 binary as part of the build configuration. To fix the +issue, ensure your files are properly optimized for ARM; the binary +translator will then ensure compatibility with x86. Alternatively, add +an `abiSplit` for x86 within your `build.gradle` file and create the +required x86 dependencies. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +build.gradle:10:Warning: Missing x86_64 ABI support for ChromeOS +[ChromeOsAbiSupport] + abiFilters 'arm64-v8a' + ----------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`build.gradle`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~groovy linenumbers +apply plugin: 'com.android.application' + +android { + compileSdkVersion 21 + buildToolsVersion "21.1.2" + defaultConfig { + minSdkVersion 15 + targetSdkVersion 17 + ndk { + abiFilters 'arm64-v8a' + } + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `GradleDetector.testChromeOSAbiFiltersMissingX8664`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=192708. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ChromeOsAbiSupport + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ChromeOsAbiSupport" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ChromeOsAbiSupport' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ChromeOsAbiSupport ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ChromeOsOnConfigurationChanged.md.html b/docs/checks/ChromeOsOnConfigurationChanged.md.html new file mode 100644 index 00000000..6fd2225b --- /dev/null +++ b/docs/checks/ChromeOsOnConfigurationChanged.md.html @@ -0,0 +1,154 @@ + +(#) Poor performance with APIs inside `onConfigurationChanged()` + +!!! WARNING: Poor performance with APIs inside `onConfigurationChanged()` + This is a warning. + +Id +: `ChromeOsOnConfigurationChanged` +Summary +: Poor performance with APIs inside `onConfigurationChanged()` +Severity +: Warning +Category +: Correctness: Chrome OS +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.0.0 (April 2023) +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ChromeOsSourceDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ChromeOsSourceDetectorTest.kt) + +When users resize the Android emulator in Android 13 and Chrome OS, an +`onConfigurationChanged()` API call occurs. If your +`onConfigurationChanged()` method contains any code that can cause a +redraw, your app might take a performance hit on large screens. To fix +the issue, ensure your `onConfigurationChanged()` method does not +contain any calls to UI redraw logic for specific elements. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test/pkg/MainActivity.java:19:Warning: Calling finish() within +onConfigurationChanged() can lead to redraws +[ChromeOsOnConfigurationChanged] + finish(); // ERROR 1 + -------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test/pkg/MainActivity.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; +import android.app.Activity; +import android.content.pm.PackageManager; +import android.os.Bundle; + + +public class MainActivity extends Activity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA); + } + + @Override + protected void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + finish(); // ERROR 1 + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ChromeOsSourceDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `ChromeOsSourceDetector.testFinishFoundInsideOnConfigurationChanged`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=192708. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ChromeOsOnConfigurationChanged") + fun method() { + setRequestedOrientation(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ChromeOsOnConfigurationChanged") + void method() { + setRequestedOrientation(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ChromeOsOnConfigurationChanged + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ChromeOsOnConfigurationChanged" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ChromeOsOnConfigurationChanged' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ChromeOsOnConfigurationChanged ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ClickableViewAccessibility.md.html b/docs/checks/ClickableViewAccessibility.md.html index 64722988..00d5f51f 100644 --- a/docs/checks/ClickableViewAccessibility.md.html +++ b/docs/checks/ClickableViewAccessibility.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files Editing @@ -43,11 +45,8 @@ src/test/pkg/ClickableViewAccessibilityTest.java:15:Warning: Custom view ViewOverridesOnTouchEventButNotPerformClick overrides onTouchEvent but not performClick [ClickableViewAccessibility] - public boolean onTouchEvent(MotionEvent event) { ------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/CoarseFineLocation.md.html b/docs/checks/CoarseFineLocation.md.html index a939e3db..fe66739d 100644 --- a/docs/checks/CoarseFineLocation.md.html +++ b/docs/checks/CoarseFineLocation.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.0.0 (July 2021) Affects : Manifest files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/FineLocationDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/FineLocationDetectorTest.kt) -Copyright Year -: 2021 If your app requires access to FINE location, on Android 12 and higher you must now request both FINE and COARSE. Users will have the option to @@ -41,11 +41,8 @@ AndroidManifest.xml:3:Error: If you need access to FINE location, you must request both ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION [CoarseFineLocation] - <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> ------------------------------------------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/ColorCasing.md.html b/docs/checks/ColorCasing.md.html new file mode 100644 index 00000000..1be861d7 --- /dev/null +++ b/docs/checks/ColorCasing.md.html @@ -0,0 +1,149 @@ + +(#) Raw colors should be defined with uppercase letters + +!!! WARNING: Raw colors should be defined with uppercase letters + This is a warning. + +Id +: `ColorCasing` +Summary +: Raw colors should be defined with uppercase letters +Severity +: Warning +Category +: Correctness +Platform +: Android +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html) +Since +: 0.8.0 +Affects +: Resource files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/main/kotlin/com/vanniktech/lintrules/android/ColorCasingDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/ColorCasingDetectorTest.kt) + +Colors should have uppercase letters. #FF0099 is valid while #ff0099 +isn't since the ff should be written in uppercase. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +res/layout/layout.xml:2:Warning: Should be using uppercase letters +[ColorCasing] + tools:textColor="#fff"/> + ---- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`res/layout/layout.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<TextView xmlns:tools="http://schemas.android.com/tools" + tools:textColor="#fff"/> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/ColorCasingDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `ColorCasingDetector.lowercaseColor`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-android:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-android:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.android) + +# libs.versions.toml +[versions] +lint-rules-android = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-android = { + module = "com.vanniktech:lint-rules-android", + version.ref = "lint-rules-android" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute `tools:ignore="ColorCasing"` on the + problematic XML element (or one of its enclosing elements). You may + also need to add the following namespace declaration on the root + element in the XML file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ColorCasing" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ColorCasing' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ColorCasing ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/CommitPrefEdits.md.html b/docs/checks/CommitPrefEdits.md.html index 0d5a6e5f..205f76c5 100644 --- a/docs/checks/CommitPrefEdits.md.html +++ b/docs/checks/CommitPrefEdits.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 2.2.0 (September 2016) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/CleanupDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/CleanupDetectorTest.kt) -Copyright Year -: 2012 After calling `edit()` on a `SharedPreference`, you must call `commit()` or `apply()` on the editor to save the results. @@ -41,18 +41,12 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/SharedPrefsTest.java:54:Warning: SharedPreferences.edit() without a corresponding commit() or apply() call [CommitPrefEdits] - SharedPreferences.Editor editor = preferences.edit(); ------------------ - - src/test/pkg/SharedPrefsTest.java:62:Warning: SharedPreferences.edit() without a corresponding commit() or apply() call [CommitPrefEdits] - SharedPreferences.Editor editor = preferences.edit(); ------------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -143,7 +137,7 @@ for the unit tests for this check to see additional scenarios. The above example was automatically extracted from the first unit test -found for this lint check, `CleanupDetector.test`. +found for this lint check, `CleanupDetector.testSharedPrefs`. To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=192708. diff --git a/docs/checks/CommitTransaction.md.html b/docs/checks/CommitTransaction.md.html index 74d666e6..5f0912c2 100644 --- a/docs/checks/CommitTransaction.md.html +++ b/docs/checks/CommitTransaction.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files Editing @@ -38,46 +40,28 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/CommitTest.java:25:Warning: This transaction should be completed with a commit() call [CommitTransaction] - getFragmentManager().beginTransaction(); // ERROR 1 ---------------- - - src/test/pkg/CommitTest.java:30:Warning: This transaction should be completed with a commit() call [CommitTransaction] - FragmentTransaction transaction2 = getFragmentManager().beginTransaction(); // ERROR 2 ---------------- - - src/test/pkg/CommitTest.java:39:Warning: This transaction should be completed with a commit() call [CommitTransaction] - getFragmentManager().beginTransaction(); // ERROR 3 ---------------- - - src/test/pkg/CommitTest.java:65:Warning: This transaction should be completed with a commit() call [CommitTransaction] - getSupportFragmentManager().beginTransaction(); // ERROR 4 ---------------- - - src/test/pkg/CommitTest.java:123:Warning: This transaction should be completed with a commit() call [CommitTransaction] - transaction = getFragmentManager().beginTransaction(); // ERROR 5 ---------------- - - src/test/pkg/CommitTest.java:132:Warning: This transaction should be completed with a commit() call [CommitTransaction] - transaction = getFragmentManager().beginTransaction(); // ERROR 6 ---------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/ComposableDestinationInComposeScope.md.html b/docs/checks/ComposableDestinationInComposeScope.md.html index 2d936cbc..66433fc6 100644 --- a/docs/checks/ComposableDestinationInComposeScope.md.html +++ b/docs/checks/ComposableDestinationInComposeScope.md.html @@ -18,6 +18,14 @@ : Jetpack Navigation Compose Identifier : androidx.navigation.compose +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.7+ +Artifact +: [androidx.navigation:navigation-compose](androidx_navigation_navigation-compose.md.html) +Since +: 2.4.0 Affects : Kotlin and Java files and test sources Editing @@ -30,9 +38,8 @@ : 2021 Composable destinations should only be constructed directly within a -NavGraphBuilder scope. Composable destinations cannot not be nested, and -you should use the `navigation` function to create a nested graph -instead. +NavGraphBuilder scope. Composable destinations cannot be nested, and you +should use the `navigation` function to create a nested graph instead. (##) Example @@ -40,11 +47,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/com/example/test.kt:13:Error: Using composable inside of a compose scope [ComposableDestinationInComposeScope] - composable("wrong") { } ---------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -77,6 +81,40 @@ To report a problem with this extracted sample, contact Jetpack Navigation Compose. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.navigation:navigation-compose:2.9.0-rc01") + +// build.gradle +implementation 'androidx.navigation:navigation-compose:2.9.0-rc01' + +// build.gradle.kts with version catalogs: +implementation(libs.navigation.compose) + +# libs.versions.toml +[versions] +navigation-compose = "2.9.0-rc01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +navigation-compose = { + module = "androidx.navigation:navigation-compose", + version.ref = "navigation-compose" +} +``` + +2.9.0-rc01 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.navigation:navigation-compose](androidx_navigation_navigation-compose.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/ComposableLambdaParameterNaming.md.html b/docs/checks/ComposableLambdaParameterNaming.md.html index 33db6c1e..7c9466f2 100644 --- a/docs/checks/ComposableLambdaParameterNaming.md.html +++ b/docs/checks/ComposableLambdaParameterNaming.md.html @@ -22,6 +22,14 @@ : androidx.compose.runtime Feedback : https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.runtime:runtime-android](androidx_compose_runtime_runtime-android.md.html) +Since +: 1.5.0 Affects : Kotlin and Java files and test sources Editing @@ -36,17 +44,17 @@ Composable functions with only one composable lambda parameter should use the name `content` for the parameter. +!!! Tip + This lint check has an associated quickfix available in the IDE. + (##) Example Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/androidx/compose/ui/foo/test.kt:7:Warning: Composable lambda parameter should be named content [ComposableLambdaParameterNaming] - fun Button(foo: Int, text: @Composable () -> Unit) { ---- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -72,6 +80,44 @@ To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=612128. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.runtime:runtime-android:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.runtime:runtime-android:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.runtime.android) + +# libs.versions.toml +[versions] +runtime-android = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +runtime-android = { + module = "androidx.compose.runtime:runtime-android", + version.ref = "runtime-android" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.runtime:runtime-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.runtime:runtime-android](androidx_compose_runtime_runtime-android.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/ComposableLambdaParameterPosition.md.html b/docs/checks/ComposableLambdaParameterPosition.md.html index bf7038f8..67dda703 100644 --- a/docs/checks/ComposableLambdaParameterPosition.md.html +++ b/docs/checks/ComposableLambdaParameterPosition.md.html @@ -22,6 +22,14 @@ : androidx.compose.runtime Feedback : https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.runtime:runtime-android](androidx_compose_runtime_runtime-android.md.html) +Since +: 1.5.0 Affects : Kotlin and Java files and test sources Editing @@ -44,11 +52,8 @@ src/androidx/compose/ui/foo/test.kt:7:Warning: Composable lambda parameter should be the last parameter so it can be used as a trailing lambda [ComposableLambdaParameterPosition] - fun Button(content: @Composable () -> Unit, foo: Int) { ------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -74,6 +79,44 @@ To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=612128. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.runtime:runtime-android:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.runtime:runtime-android:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.runtime.android) + +# libs.versions.toml +[versions] +runtime-android = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +runtime-android = { + module = "androidx.compose.runtime:runtime-android", + version.ref = "runtime-android" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.runtime:runtime-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.runtime:runtime-android](androidx_compose_runtime_runtime-android.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/ComposableNaming.md.html b/docs/checks/ComposableNaming.md.html index 2987b84d..be81428a 100644 --- a/docs/checks/ComposableNaming.md.html +++ b/docs/checks/ComposableNaming.md.html @@ -20,6 +20,14 @@ : androidx.compose.runtime Feedback : https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.runtime:runtime-android](androidx_compose_runtime_runtime-android.md.html) +Since +: 1.5.0 Affects : Kotlin and Java files and test sources Editing @@ -46,11 +54,8 @@ src/androidx/compose/runtime/foo/test.kt:7:Warning: Composable functions that return Unit should start with an uppercase letter [ComposableNaming] - fun button() {} ------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -74,6 +79,44 @@ To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=612128. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.runtime:runtime-android:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.runtime:runtime-android:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.runtime.android) + +# libs.versions.toml +[versions] +runtime-android = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +runtime-android = { + module = "androidx.compose.runtime:runtime-android", + version.ref = "runtime-android" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.runtime:runtime-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.runtime:runtime-android](androidx_compose_runtime_runtime-android.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/ComposableNavGraphInComposeScope.md.html b/docs/checks/ComposableNavGraphInComposeScope.md.html index f32d8232..4e405014 100644 --- a/docs/checks/ComposableNavGraphInComposeScope.md.html +++ b/docs/checks/ComposableNavGraphInComposeScope.md.html @@ -18,6 +18,14 @@ : Jetpack Navigation Compose Identifier : androidx.navigation.compose +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.7+ +Artifact +: [androidx.navigation:navigation-compose](androidx_navigation_navigation-compose.md.html) +Since +: 2.4.0 Affects : Kotlin and Java files and test sources Editing @@ -38,11 +46,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/com/example/test.kt:14:Error: Using navigation inside of a compose scope [ComposableNavGraphInComposeScope] - navigation("wrong") { } ---------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -76,6 +81,40 @@ To report a problem with this extracted sample, contact Jetpack Navigation Compose. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.navigation:navigation-compose:2.9.0-rc01") + +// build.gradle +implementation 'androidx.navigation:navigation-compose:2.9.0-rc01' + +// build.gradle.kts with version catalogs: +implementation(libs.navigation.compose) + +# libs.versions.toml +[versions] +navigation-compose = "2.9.0-rc01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +navigation-compose = { + module = "androidx.navigation:navigation-compose", + version.ref = "navigation-compose" +} +``` + +2.9.0-rc01 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.navigation:navigation-compose](androidx_navigation_navigation-compose.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/ComposeCompositionLocalGetter.md.html b/docs/checks/ComposeCompositionLocalGetter.md.html new file mode 100644 index 00000000..826b7afc --- /dev/null +++ b/docs/checks/ComposeCompositionLocalGetter.md.html @@ -0,0 +1,200 @@ + +(#) CompositionLocals should not use getters + +!!! ERROR: CompositionLocals should not use getters + This is an error. + +Id +: `ComposeCompositionLocalGetter` +Summary +: CompositionLocals should not use getters +Severity +: Error +Category +: Productivity +Platform +: Any +Vendor +: slack +Identifier +: com.slack.lint.compose:compose-lints +Feedback +: https://github.com/slackhq/compose-lints/issues +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html) +Since +: 1.3.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/main/java/slack/lint/compose/CompositionLocalUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/CompositionLocalUsageDetectorTest.kt) +Copyright Year +: 2023 + +`CompositionLocal`s should be singletons and not use getters. Otherwise +a new instance will be returned every call. + +(##) Options + +You can configure this lint checks using the following options: + +(###) allowed-composition-locals + +A comma-separated list of CompositionLocals that should be allowed. +This property should define a comma-separated list of `CompositionLocal`s that should be allowed. + + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="ComposeCompositionLocalGetter"> + <option name="allowed-composition-locals" value="some string" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test.kt:2:Error: `CompositionLocal`s should be singletons and not +use getters. Otherwise a new instance will be returned every call. +[ComposeCompositionLocalGetter] + val LocalBanana get() = compositionLocalOf { "Prune" } + --- +src/test.kt:3:Error: `CompositionLocal`s should be singletons and not +use getters. Otherwise a new instance will be returned every call. +[ComposeCompositionLocalGetter] + val LocalPotato get() { + --- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +val LocalBanana get() = compositionLocalOf { "Prune" } +val LocalPotato get() { + return compositionLocalOf { "Prune" } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/CompositionLocalUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `CompositionLocalUsageDetector.getter is an error`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/compose-lints/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint.compose:compose-lint-checks:1.4.2") + +// build.gradle +lintChecks 'com.slack.lint.compose:compose-lint-checks:1.4.2' + +// build.gradle.kts with version catalogs: +lintChecks(libs.compose.lint.checks) + +# libs.versions.toml +[versions] +compose-lint-checks = "1.4.2" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +compose-lint-checks = { + module = "com.slack.lint.compose:compose-lint-checks", + version.ref = "compose-lint-checks" +} +``` + +1.4.2 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ComposeCompositionLocalGetter") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ComposeCompositionLocalGetter") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ComposeCompositionLocalGetter + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ComposeCompositionLocalGetter" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ComposeCompositionLocalGetter' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ComposeCompositionLocalGetter ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ComposeCompositionLocalUsage.md.html b/docs/checks/ComposeCompositionLocalUsage.md.html new file mode 100644 index 00000000..931c81a0 --- /dev/null +++ b/docs/checks/ComposeCompositionLocalUsage.md.html @@ -0,0 +1,216 @@ + +(#) CompositionLocals are discouraged + +!!! WARNING: CompositionLocals are discouraged + This is a warning. + +Id +: `ComposeCompositionLocalUsage` +Summary +: CompositionLocals are discouraged +Severity +: Warning +Category +: Productivity +Platform +: Any +Vendor +: slack +Identifier +: com.slack.lint.compose:compose-lints +Feedback +: https://github.com/slackhq/compose-lints/issues +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html) +Since +: 1.0.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/main/java/slack/lint/compose/CompositionLocalUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/CompositionLocalUsageDetectorTest.kt) +Copyright Year +: 2023 + +`CompositionLocal`s are implicit dependencies and creating new ones +should be avoided. See +https://slackhq.github.io/compose-lints/rules/#compositionlocals for +more information. + +(##) Options + +You can configure this lint checks using the following options: + +(###) allowed-composition-locals + +A comma-separated list of CompositionLocals that should be allowed. +This property should define a comma-separated list of `CompositionLocal`s that should be allowed. + + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="ComposeCompositionLocalUsage"> + <option name="allowed-composition-locals" value="some string" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test.kt:2:Warning: `CompositionLocal`s are implicit dependencies and +creating new ones should be avoided. See +https://slackhq.github.io/compose-lints/rules/#compositionlocals for +more information. [ComposeCompositionLocalUsage] + private val LocalApple = staticCompositionLocalOf<String> { "Apple" } + --------------------------------------------------------------------- +src/test.kt:3:Warning: `CompositionLocal`s are implicit dependencies and +creating new ones should be avoided. See +https://slackhq.github.io/compose-lints/rules/#compositionlocals for +more information. [ComposeCompositionLocalUsage] + internal val LocalPlum: String = staticCompositionLocalOf { "Plum" } + -------------------------------------------------------------------- +src/test.kt:4:Warning: `CompositionLocal`s are implicit dependencies and +creating new ones should be avoided. See +https://slackhq.github.io/compose-lints/rules/#compositionlocals for +more information. [ComposeCompositionLocalUsage] + val LocalPrune = compositionLocalOf { "Prune" } + ----------------------------------------------- +src/test.kt:5:Warning: `CompositionLocal`s are implicit dependencies and +creating new ones should be avoided. See +https://slackhq.github.io/compose-lints/rules/#compositionlocals for +more information. [ComposeCompositionLocalUsage] + private val LocalKiwi: String = compositionLocalOf { "Kiwi" } + ------------------------------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +private val LocalApple = staticCompositionLocalOf { "Apple" } +internal val LocalPlum: String = staticCompositionLocalOf { "Plum" } +val LocalPrune = compositionLocalOf { "Prune" } +private val LocalKiwi: String = compositionLocalOf { "Kiwi" } +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/CompositionLocalUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `CompositionLocalUsageDetector.warning when a CompositionLocal is defined`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/compose-lints/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint.compose:compose-lint-checks:1.4.2") + +// build.gradle +lintChecks 'com.slack.lint.compose:compose-lint-checks:1.4.2' + +// build.gradle.kts with version catalogs: +lintChecks(libs.compose.lint.checks) + +# libs.versions.toml +[versions] +compose-lint-checks = "1.4.2" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +compose-lint-checks = { + module = "com.slack.lint.compose:compose-lint-checks", + version.ref = "compose-lint-checks" +} +``` + +1.4.2 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ComposeCompositionLocalUsage") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ComposeCompositionLocalUsage") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ComposeCompositionLocalUsage + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ComposeCompositionLocalUsage" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ComposeCompositionLocalUsage' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ComposeCompositionLocalUsage ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ComposeContentEmitterReturningValues.md.html b/docs/checks/ComposeContentEmitterReturningValues.md.html new file mode 100644 index 00000000..ba05633f --- /dev/null +++ b/docs/checks/ComposeContentEmitterReturningValues.md.html @@ -0,0 +1,221 @@ + +(#) Composable functions should emit XOR return + +!!! ERROR: Composable functions should emit XOR return + This is an error. + +Id +: `ComposeContentEmitterReturningValues` +Summary +: Composable functions should emit XOR return +Severity +: Error +Category +: Productivity +Platform +: Any +Vendor +: slack +Identifier +: com.slack.lint.compose:compose-lints +Feedback +: https://github.com/slackhq/compose-lints/issues +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html) +Since +: 1.0.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/main/java/slack/lint/compose/ContentEmitterReturningValuesDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/ContentEmitterReturningValuesDetectorTest.kt) +Copyright Year +: 2023 + +Composable functions should either emit content into the composition or +return a value, but not both. If a composable should offer additional +control surfaces to its caller, those control surfaces or callbacks +should be provided as parameters to the composable function by the +caller. See +https://slackhq.github.io/compose-lints/rules/#do-not-emit-content-and-return-a-result +for more information. + +(##) Options + +You can configure this lint checks using the following options: + +(###) content-emitters + +A comma-separated list of known content-emitting composables. +This property should define a comma-separated list of known content-emitting composables. + + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="ComposeContentEmitterReturningValues"> + <option name="content-emitters" value="some string" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test.kt:3:Error: Composable functions should either emit content +into the composition or return a value, but not both.If a composable +should offer additional control surfaces to its caller, those control +surfaces or callbacks should be provided as parameters to the composable +function by the caller.See +https://slackhq.github.io/compose-lints/rules/#do-not-emit-content-and-return-a-result +for more information. [ComposeContentEmitterReturningValues] +@Composable +^ +src/test.kt:8:Error: Composable functions should either emit content +into the composition or return a value, but not both.If a composable +should offer additional control surfaces to its caller, those control +surfaces or callbacks should be provided as parameters to the composable +function by the caller.See +https://slackhq.github.io/compose-lints/rules/#do-not-emit-content-and-return-a-result +for more information. [ComposeContentEmitterReturningValues] +@Composable +^ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +import androidx.compose.runtime.Composable + +@Composable +fun Something() { + Text("Hi") + Text("Hola") +} +@Composable +fun Something() { + Spacer16() + Text("Hola") +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/ContentEmitterReturningValuesDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `ContentEmitterReturningValuesDetector.errors when a Composable function has more than one UI emitter at the top level`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/compose-lints/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint.compose:compose-lint-checks:1.4.2") + +// build.gradle +lintChecks 'com.slack.lint.compose:compose-lint-checks:1.4.2' + +// build.gradle.kts with version catalogs: +lintChecks(libs.compose.lint.checks) + +# libs.versions.toml +[versions] +compose-lint-checks = "1.4.2" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +compose-lint-checks = { + module = "com.slack.lint.compose:compose-lint-checks", + version.ref = "compose-lint-checks" +} +``` + +1.4.2 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ComposeContentEmitterReturningValues") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ComposeContentEmitterReturningValues") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ComposeContentEmitterReturningValues + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ComposeContentEmitterReturningValues" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ComposeContentEmitterReturningValues' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ComposeContentEmitterReturningValues ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ComposeM2Api.md.html b/docs/checks/ComposeM2Api.md.html new file mode 100644 index 00000000..217ad926 --- /dev/null +++ b/docs/checks/ComposeM2Api.md.html @@ -0,0 +1,257 @@ + +(#) Using a Compose M2 API is not recommended + +!!! ERROR: Using a Compose M2 API is not recommended + This is an error. + +Id +: `ComposeM2Api` +Summary +: Using a Compose M2 API is not recommended +Note +: **This issue is disabled by default**; use `--enable ComposeM2Api` +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: com.slack.lint.compose:compose-lints +Feedback +: https://github.com/slackhq/compose-lints/issues +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html) +Since +: 1.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/main/java/slack/lint/compose/M2ApiDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/M2ApiDetectorTest.kt) +Copyright Year +: 2022 + +Compose Material 2 (M2) is succeeded by Material 3 (M3). Please use M3 +APIs.See https://slackhq.github.io/compose-lints/rules/#use-material-3 +for more information. + +(##) Options + +You can configure this lint checks using the following options: + +(###) allowed-m2-apis + +A comma-separated list of APIs in androidx.compose.material that should be allowed.. +This property should define a comma-separated list of APIs in androidx.compose.material that should be allowed. + + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="ComposeM2Api"> + <option name="allowed-m2-apis" value="some string" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(###) enable-mangling-workaround + +Try to work around name mangling.. +See https://github.com/slackhq/compose-lints/issues/167 + +Default is false. + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="ComposeM2Api"> + <option name="enable-mangling-workaround" value="false" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test.kt:9:Error: Compose Material 2 (M2) is succeeded by Material 3 +(M3). Please use M3 APIs.See +https://slackhq.github.io/compose-lints/rules/#use-material-3 for more +information. [ComposeM2Api] + Text("Hello, world!") + --------------------- +src/test.kt:23:Error: Compose Material 2 (M2) is succeeded by Material 3 +(M3). Please use M3 APIs.See +https://slackhq.github.io/compose-lints/rules/#use-material-3 for more +information. [ComposeM2Api] + Text("Hello, world!") + --------------------- +src/test.kt:24:Error: Compose Material 2 (M2) is succeeded by Material 3 +(M3). Please use M3 APIs.See +https://slackhq.github.io/compose-lints/rules/#use-material-3 for more +information. [ComposeM2Api] + val elevation = BottomNavigationDefaults.Elevation + ---------------------------------- +src/test.kt:25:Error: Compose Material 2 (M2) is succeeded by Material 3 +(M3). Please use M3 APIs.See +https://slackhq.github.io/compose-lints/rules/#use-material-3 for more +information. [ComposeM2Api] + val drawerValue = BottomDrawerValue.Closed + ------------------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +import androidx.compose.material.BottomDrawerValue +import androidx.compose.material.BottomNavigationDefaults +import androidx.compose.material.Text +import androidx.compose.material.ripple.rememberRipple +import androidx.compose.runtime.Composable + +@Composable +fun Example() { + Text("Hello, world!") +} + +@Composable +fun AllowedExample() { + Surface { + + } +} + +@Composable +fun Composite() { + Surface { + val ripple = rememberRipple() + Text("Hello, world!") + val elevation = BottomNavigationDefaults.Elevation + val drawerValue = BottomDrawerValue.Closed + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/M2ApiDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `M2ApiDetector.smokeTest`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/compose-lints/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint.compose:compose-lint-checks:1.4.2") + +// build.gradle +lintChecks 'com.slack.lint.compose:compose-lint-checks:1.4.2' + +// build.gradle.kts with version catalogs: +lintChecks(libs.compose.lint.checks) + +# libs.versions.toml +[versions] +compose-lint-checks = "1.4.2" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +compose-lint-checks = { + module = "com.slack.lint.compose:compose-lint-checks", + version.ref = "compose-lint-checks" +} +``` + +1.4.2 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ComposeM2Api") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ComposeM2Api") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ComposeM2Api + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ComposeM2Api" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ComposeM2Api' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ComposeM2Api ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ComposeModifierComposed.md.html b/docs/checks/ComposeModifierComposed.md.html new file mode 100644 index 00000000..b5ab8e41 --- /dev/null +++ b/docs/checks/ComposeModifierComposed.md.html @@ -0,0 +1,211 @@ + +(#) Don't use Modifier.composed {} + +!!! ERROR: Don't use Modifier.composed {} + This is an error. + +Id +: `ComposeModifierComposed` +Summary +: Don't use Modifier.composed {} +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: com.slack.lint.compose:compose-lints +Feedback +: https://github.com/slackhq/compose-lints/issues +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html) +Since +: 1.3.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/main/java/slack/lint/compose/ModifierComposedDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/ModifierComposedDetectorTest.kt) +Copyright Year +: 2023 + +Modifier.composed { ... } is no longer recommended due to performance +issues. + +You should use the Modifier.Node API instead, as it was designed from +the ground up to be far more performant than composed modifiers. + +See +https://slackhq.github.io/compose-lints/rules/#migrate-to-modifiernode +for more information. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test/test.kt:6:Error: Modifier.composed { ... } is no longer +recommended due to performance issues. +You should use the Modifier.Node API instead, as it was designed from +the ground up to be far more performant than composed modifiers. +See +https://slackhq.github.io/compose-lints/rules/#migrate-to-modifiernode +for more information. [ComposeModifierComposed] +fun Modifier.something1() = Modifier.composed { } + --------------------- +src/test/test.kt:7:Error: Modifier.composed { ... } is no longer +recommended due to performance issues. +You should use the Modifier.Node API instead, as it was designed from +the ground up to be far more performant than composed modifiers. +See +https://slackhq.github.io/compose-lints/rules/#migrate-to-modifiernode +for more information. [ComposeModifierComposed] +fun Modifier.something2() = composed { } + ------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`test/androidx/compose/ui/ComposedModifier.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package androidx.compose.ui + +fun Modifier.composed( + inspectorInfo: InspectorInfo.() -> Unit = NoInspectorInfo, + factory: Modifier.() -> Modifier +): Modifier { + TODO() +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers + package test + +import androidx.compose.ui.composed +import androidx.compose.ui.Modifier + +fun Modifier.something1() = Modifier.composed { } +fun Modifier.something2() = composed { } +fun Modifier.something3() = somethingElse() +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/ModifierComposedDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `ModifierComposedDetector.errors when a composable Modifier extension is detected`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/compose-lints/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint.compose:compose-lint-checks:1.4.2") + +// build.gradle +lintChecks 'com.slack.lint.compose:compose-lint-checks:1.4.2' + +// build.gradle.kts with version catalogs: +lintChecks(libs.compose.lint.checks) + +# libs.versions.toml +[versions] +compose-lint-checks = "1.4.2" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +compose-lint-checks = { + module = "com.slack.lint.compose:compose-lint-checks", + version.ref = "compose-lint-checks" +} +``` + +1.4.2 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ComposeModifierComposed") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ComposeModifierComposed") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ComposeModifierComposed + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ComposeModifierComposed" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ComposeModifierComposed' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ComposeModifierComposed ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ComposeModifierMissing.md.html b/docs/checks/ComposeModifierMissing.md.html new file mode 100644 index 00000000..85b47e92 --- /dev/null +++ b/docs/checks/ComposeModifierMissing.md.html @@ -0,0 +1,249 @@ + +(#) Missing modifier parameter + +!!! ERROR: Missing modifier parameter + This is an error. + +Id +: `ComposeModifierMissing` +Summary +: Missing modifier parameter +Severity +: Error +Category +: Productivity +Platform +: Any +Vendor +: slack +Identifier +: com.slack.lint.compose:compose-lints +Feedback +: https://github.com/slackhq/compose-lints/issues +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html) +Since +: 1.0.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/main/java/slack/lint/compose/ModifierMissingDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/ModifierMissingDetectorTest.kt) +Copyright Year +: 2023 + +This @Composable function emits content but doesn't have a modifier +parameter.See +https://slackhq.github.io/compose-lints/rules/#when-should-i-expose-modifier-parameters +for more information. + +(##) Options + +You can configure this lint checks using the following options: + +(###) content-emitters + +A comma-separated list of known content-emitting composables. +This property should define a comma-separated list of known content-emitting composables. + + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="ComposeModifierMissing"> + <option name="content-emitters" value="some string" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(###) visibility-threshold + +Visibility threshold to check for Modifiers. +You can control the visibility of which composables to check for Modifiers. Possible values are: `only_public` (default), `public_and_internal` and `all` + +Default is "only_public". + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="ComposeModifierMissing"> + <option name="visibility-threshold" value=""only_public"" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test.kt:5:Error: This @Composable function emits content but doesn't +have a modifier parameter.See +https://slackhq.github.io/compose-lints/rules/#when-should-i-expose-modifier-parameters +for more information. [ComposeModifierMissing] +fun Something1() { + ---------- +src/test.kt:10:Error: This @Composable function emits content but +doesn't have a modifier parameter.See +https://slackhq.github.io/compose-lints/rules/#when-should-i-expose-modifier-parameters +for more information. [ComposeModifierMissing] +fun Something2() { + ---------- +src/test.kt:15:Error: This @Composable function emits content but +doesn't have a modifier parameter.See +https://slackhq.github.io/compose-lints/rules/#when-should-i-expose-modifier-parameters +for more information. [ComposeModifierMissing] +fun Something3(): Unit { + ---------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +import androidx.compose.ui.Modifier +import androidx.compose.runtime.Composable + +@Composable +fun Something1() { + Row { + } +} +@Composable +fun Something2() { + Column(modifier = Modifier.fillMaxSize()) { + } +} +@Composable +fun Something3(): Unit { + SomethingElse { + Box(modifier = Modifier.fillMaxSize()) { + } + } +} +@Composable +fun Something4(modifier: Modifier = Modifier) { + Row { + Text("Hi!") + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/ModifierMissingDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `ModifierMissingDetector.errors when a Composable has a layout inside and it doesn't have a modifier`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/compose-lints/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint.compose:compose-lint-checks:1.4.2") + +// build.gradle +lintChecks 'com.slack.lint.compose:compose-lint-checks:1.4.2' + +// build.gradle.kts with version catalogs: +lintChecks(libs.compose.lint.checks) + +# libs.versions.toml +[versions] +compose-lint-checks = "1.4.2" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +compose-lint-checks = { + module = "com.slack.lint.compose:compose-lint-checks", + version.ref = "compose-lint-checks" +} +``` + +1.4.2 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ComposeModifierMissing") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ComposeModifierMissing") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ComposeModifierMissing + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ComposeModifierMissing" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ComposeModifierMissing' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ComposeModifierMissing ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ComposeModifierReused.md.html b/docs/checks/ComposeModifierReused.md.html new file mode 100644 index 00000000..0ddce124 --- /dev/null +++ b/docs/checks/ComposeModifierReused.md.html @@ -0,0 +1,333 @@ + +(#) Modifiers should only be used once + +!!! ERROR: Modifiers should only be used once + This is an error. + +Id +: `ComposeModifierReused` +Summary +: Modifiers should only be used once +Severity +: Error +Category +: Productivity +Platform +: Any +Vendor +: slack +Identifier +: com.slack.lint.compose:compose-lints +Feedback +: https://github.com/slackhq/compose-lints/issues +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html) +Since +: 1.0.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/main/java/slack/lint/compose/ModifierReusedDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/ModifierReusedDetectorTest.kt) +Copyright Year +: 2023 + +Modifiers should only be used once and by the root level layout of a +Composable. This is true even if appended to or with other modifiers +e.g. `modifier.fillMaxWidth()`.Use Modifier (with a capital 'M') to +construct a new Modifier that you can pass to other composables.See +https://slackhq.github.io/compose-lints/rules/#dont-re-use-modifiers for +more information. + +(##) Options + +You can configure this lint checks using the following options: + +(###) content-emitters + +A comma-separated list of known content-emitting composables. +This property should define a comma-separated list of known content-emitting composables. + + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="ComposeModifierReused"> + <option name="content-emitters" value="some string" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test.kt:6:Error: Modifiers should only be used once and by the root +level layout of a Composable. This is true even if appended to or with +other modifiers e.g. modifier.fillMaxWidth().Use Modifier (with a +capital 'M') to construct a new Modifier that you can pass to other +composables.See +https://slackhq.github.io/compose-lints/rules/#dont-re-use-modifiers for +more information. [ComposeModifierReused] + Row(modifier) { + ^ +src/test.kt:7:Error: Modifiers should only be used once and by the root +level layout of a Composable. This is true even if appended to or with +other modifiers e.g. modifier.fillMaxWidth().Use Modifier (with a +capital 'M') to construct a new Modifier that you can pass to other +composables.See +https://slackhq.github.io/compose-lints/rules/#dont-re-use-modifiers for +more information. [ComposeModifierReused] + SomethingElse(modifier) + ----------------------- +src/test.kt:12:Error: Modifiers should only be used once and by the root +level layout of a Composable. This is true even if appended to or with +other modifiers e.g. modifier.fillMaxWidth().Use Modifier (with a +capital 'M') to construct a new Modifier that you can pass to other +composables.See +https://slackhq.github.io/compose-lints/rules/#dont-re-use-modifiers for +more information. [ComposeModifierReused] + Column(modifier = modifier) { + ^ +src/test.kt:14:Error: Modifiers should only be used once and by the root +level layout of a Composable. This is true even if appended to or with +other modifiers e.g. modifier.fillMaxWidth().Use Modifier (with a +capital 'M') to construct a new Modifier that you can pass to other +composables.See +https://slackhq.github.io/compose-lints/rules/#dont-re-use-modifiers for +more information. [ComposeModifierReused] + SomethingDifferent(modifier = modifier) + --------------------------------------- +src/test.kt:19:Error: Modifiers should only be used once and by the root +level layout of a Composable. This is true even if appended to or with +other modifiers e.g. modifier.fillMaxWidth().Use Modifier (with a +capital 'M') to construct a new Modifier that you can pass to other +composables.See +https://slackhq.github.io/compose-lints/rules/#dont-re-use-modifiers for +more information. [ComposeModifierReused] + Column(modifier = modifier) { + ^ +src/test.kt:22:Error: Modifiers should only be used once and by the root +level layout of a Composable. This is true even if appended to or with +other modifiers e.g. modifier.fillMaxWidth().Use Modifier (with a +capital 'M') to construct a new Modifier that you can pass to other +composables.See +https://slackhq.github.io/compose-lints/rules/#dont-re-use-modifiers for +more information. [ComposeModifierReused] + SomethingElse(modifier = modifier) + ---------------------------------- +src/test.kt:23:Error: Modifiers should only be used once and by the root +level layout of a Composable. This is true even if appended to or with +other modifiers e.g. modifier.fillMaxWidth().Use Modifier (with a +capital 'M') to construct a new Modifier that you can pass to other +composables.See +https://slackhq.github.io/compose-lints/rules/#dont-re-use-modifiers for +more information. [ComposeModifierReused] + SomethingElse(modifier = modifier.padding12()) + ---------------------------------------------- +src/test.kt:28:Error: Modifiers should only be used once and by the root +level layout of a Composable. This is true even if appended to or with +other modifiers e.g. modifier.fillMaxWidth().Use Modifier (with a +capital 'M') to construct a new Modifier that you can pass to other +composables.See +https://slackhq.github.io/compose-lints/rules/#dont-re-use-modifiers for +more information. [ComposeModifierReused] + SomethingElse(myMod) + -------------------- +src/test.kt:29:Error: Modifiers should only be used once and by the root +level layout of a Composable. This is true even if appended to or with +other modifiers e.g. modifier.fillMaxWidth().Use Modifier (with a +capital 'M') to construct a new Modifier that you can pass to other +composables.See +https://slackhq.github.io/compose-lints/rules/#dont-re-use-modifiers for +more information. [ComposeModifierReused] + SomethingElse(myMod) + -------------------- +src/test.kt:34:Error: Modifiers should only be used once and by the root +level layout of a Composable. This is true even if appended to or with +other modifiers e.g. modifier.fillMaxWidth().Use Modifier (with a +capital 'M') to construct a new Modifier that you can pass to other +composables.See +https://slackhq.github.io/compose-lints/rules/#dont-re-use-modifiers for +more information. [ComposeModifierReused] + Box( + ^ +src/test.kt:40:Error: Modifiers should only be used once and by the root +level layout of a Composable. This is true even if appended to or with +other modifiers e.g. modifier.fillMaxWidth().Use Modifier (with a +capital 'M') to construct a new Modifier that you can pass to other +composables.See +https://slackhq.github.io/compose-lints/rules/#dont-re-use-modifiers for +more information. [ComposeModifierReused] + Box( + ^ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier + +@Composable +fun Something(modifier: Modifier) { + Row(modifier) { + SomethingElse(modifier) + } +} +@Composable +fun Something(modifier: Modifier): Int { + Column(modifier = modifier) { + SomethingElse(modifier = Modifier) + SomethingDifferent(modifier = modifier) + } +} +@Composable +fun BoxScope.Something(modifier: Modifier) { + Column(modifier = modifier) { + SomethingDifferent() + } + SomethingElse(modifier = modifier) + SomethingElse(modifier = modifier.padding12()) +} +@Composable +fun Something(myMod: Modifier) { + Column { + SomethingElse(myMod) + SomethingElse(myMod) + } +} +@Composable +fun FoundThisOneInTheWild(modifier: Modifier = Modifier) { + Box( + modifier = modifier + .size(AvatarSize.Default.size) + .clip(CircleShape) + .then(colorModifier) + ) { + Box( + modifier = modifier.padding(spacesBorderWidth) + ) + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/ModifierReusedDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `ModifierReusedDetector.errors when the modifier parameter of a Composable is used more than once by siblings or parent-children`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/compose-lints/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint.compose:compose-lint-checks:1.4.2") + +// build.gradle +lintChecks 'com.slack.lint.compose:compose-lint-checks:1.4.2' + +// build.gradle.kts with version catalogs: +lintChecks(libs.compose.lint.checks) + +# libs.versions.toml +[versions] +compose-lint-checks = "1.4.2" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +compose-lint-checks = { + module = "com.slack.lint.compose:compose-lint-checks", + version.ref = "compose-lint-checks" +} +``` + +1.4.2 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ComposeModifierReused") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ComposeModifierReused") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ComposeModifierReused + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ComposeModifierReused" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ComposeModifierReused' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ComposeModifierReused ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ComposeModifierWithoutDefault.md.html b/docs/checks/ComposeModifierWithoutDefault.md.html new file mode 100644 index 00000000..dfadcba6 --- /dev/null +++ b/docs/checks/ComposeModifierWithoutDefault.md.html @@ -0,0 +1,190 @@ + +(#) Missing Modifier default value + +!!! ERROR: Missing Modifier default value + This is an error. + +Id +: `ComposeModifierWithoutDefault` +Summary +: Missing Modifier default value +Severity +: Error +Category +: Productivity +Platform +: Any +Vendor +: slack +Identifier +: com.slack.lint.compose:compose-lints +Feedback +: https://github.com/slackhq/compose-lints/issues +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html) +Since +: 1.0.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/main/java/slack/lint/compose/ModifierWithoutDefaultDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/ModifierWithoutDefaultDetectorTest.kt) +Copyright Year +: 2023 + +This @Composable function has a modifier parameter but it doesn't have a +default value.See +https://slackhq.github.io/compose-lints/rules/#modifiers-should-have-default-parameters +for more information. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test.kt:5:Error: This @Composable function has a modifier parameter +but it doesn't have a default value.See +https://slackhq.github.io/compose-lints/rules/#modifiers-should-have-default-parameters +for more information. [ComposeModifierWithoutDefault] +fun Something(modifier: Modifier) { } + ------------------ +src/test.kt:7:Error: This @Composable function has a modifier parameter +but it doesn't have a default value.See +https://slackhq.github.io/compose-lints/rules/#modifiers-should-have-default-parameters +for more information. [ComposeModifierWithoutDefault] +fun Something(modifier: Modifier = Modifier, modifier2: Modifier) { } + ------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier + +@Composable +fun Something(modifier: Modifier) { } +@Composable +fun Something(modifier: Modifier = Modifier, modifier2: Modifier) { } +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/ModifierWithoutDefaultDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `ModifierWithoutDefaultDetector.errors when a Composable has modifiers but without default values`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/compose-lints/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint.compose:compose-lint-checks:1.4.2") + +// build.gradle +lintChecks 'com.slack.lint.compose:compose-lint-checks:1.4.2' + +// build.gradle.kts with version catalogs: +lintChecks(libs.compose.lint.checks) + +# libs.versions.toml +[versions] +compose-lint-checks = "1.4.2" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +compose-lint-checks = { + module = "com.slack.lint.compose:compose-lint-checks", + version.ref = "compose-lint-checks" +} +``` + +1.4.2 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ComposeModifierWithoutDefault") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ComposeModifierWithoutDefault") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ComposeModifierWithoutDefault + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ComposeModifierWithoutDefault" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ComposeModifierWithoutDefault' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ComposeModifierWithoutDefault ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ComposeMultipleContentEmitters.md.html b/docs/checks/ComposeMultipleContentEmitters.md.html new file mode 100644 index 00000000..bdeb1562 --- /dev/null +++ b/docs/checks/ComposeMultipleContentEmitters.md.html @@ -0,0 +1,216 @@ + +(#) Composables should only be emit from one source + +!!! ERROR: Composables should only be emit from one source + This is an error. + +Id +: `ComposeMultipleContentEmitters` +Summary +: Composables should only be emit from one source +Severity +: Error +Category +: Productivity +Platform +: Any +Vendor +: slack +Identifier +: com.slack.lint.compose:compose-lints +Feedback +: https://github.com/slackhq/compose-lints/issues +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html) +Since +: 1.0.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/main/java/slack/lint/compose/MultipleContentEmittersDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/MultipleContentEmittersDetectorTest.kt) +Copyright Year +: 2023 + +Composable functions should only be emitting content into the +composition from one source at their top level. + +See +https://slackhq.github.io/compose-lints/rules/#do-not-emit-multiple-pieces-of-content +for more information. + +(##) Options + +You can configure this lint checks using the following options: + +(###) content-emitters + +A comma-separated list of known content-emitting composables. +This property should define a comma-separated list of known content-emitting composables. + + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="ComposeMultipleContentEmitters"> + <option name="content-emitters" value="some string" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test.kt:3:Error: Composable functions should only be emitting +content into the composition from one source at their top level. +See +https://slackhq.github.io/compose-lints/rules/#do-not-emit-multiple-pieces-of-content +for more information. [ComposeMultipleContentEmitters] +@Composable +^ +src/test.kt:8:Error: Composable functions should only be emitting +content into the composition from one source at their top level. +See +https://slackhq.github.io/compose-lints/rules/#do-not-emit-multiple-pieces-of-content +for more information. [ComposeMultipleContentEmitters] +@Composable +^ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +import androidx.compose.runtime.Composable + +@Composable +fun Something() { + Text("Hi") + Text("Hola") +} +@Composable +fun Something() { + Spacer16() + Text("Hola") +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/MultipleContentEmittersDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MultipleContentEmittersDetector.errors when a Composable function has more than one UI emitter at the top level`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/compose-lints/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint.compose:compose-lint-checks:1.4.2") + +// build.gradle +lintChecks 'com.slack.lint.compose:compose-lint-checks:1.4.2' + +// build.gradle.kts with version catalogs: +lintChecks(libs.compose.lint.checks) + +# libs.versions.toml +[versions] +compose-lint-checks = "1.4.2" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +compose-lint-checks = { + module = "com.slack.lint.compose:compose-lint-checks", + version.ref = "compose-lint-checks" +} +``` + +1.4.2 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ComposeMultipleContentEmitters") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ComposeMultipleContentEmitters") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ComposeMultipleContentEmitters + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ComposeMultipleContentEmitters" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ComposeMultipleContentEmitters' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ComposeMultipleContentEmitters ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ComposeMutableParameters.md.html b/docs/checks/ComposeMutableParameters.md.html new file mode 100644 index 00000000..5eddecb9 --- /dev/null +++ b/docs/checks/ComposeMutableParameters.md.html @@ -0,0 +1,217 @@ + +(#) Mutable objects in Compose will break state + +!!! ERROR: Mutable objects in Compose will break state + This is an error. + +Id +: `ComposeMutableParameters` +Summary +: Mutable objects in Compose will break state +Severity +: Error +Category +: Productivity +Platform +: Any +Vendor +: slack +Identifier +: com.slack.lint.compose:compose-lints +Feedback +: https://github.com/slackhq/compose-lints/issues +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html) +Since +: 1.0.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/main/java/slack/lint/compose/MutableParametersDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/MutableParametersDetectorTest.kt) +Copyright Year +: 2023 + +Using mutable objects as state in Compose will cause your users to see +incorrect or stale data in your app.Mutable objects that are not +observable, such as `ArrayList` or a mutable data class, cannot be +observed by Compose to trigger recomposition when they change.See +https://slackhq.github.io/compose-lints/rules/#do-not-use-inherently-mutable-types-as-parameters +for more information. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test.kt:5:Error: Using mutable objects as state in Compose will +cause your users to see incorrect or stale data in your app.Mutable +objects that are not observable, such as ArrayList or a mutable data +class, cannot be observed by Compose to trigger recomposition when they +change.See +https://slackhq.github.io/compose-lints/rules/#do-not-use-inherently-mutable-types-as-parameters +for more information. [ComposeMutableParameters] +fun Something(a: MutableState<String>) {} + -------------------- +src/test.kt:7:Error: Using mutable objects as state in Compose will +cause your users to see incorrect or stale data in your app.Mutable +objects that are not observable, such as ArrayList or a mutable data +class, cannot be observed by Compose to trigger recomposition when they +change.See +https://slackhq.github.io/compose-lints/rules/#do-not-use-inherently-mutable-types-as-parameters +for more information. [ComposeMutableParameters] +fun Something(a: ArrayList<String>) {} + ----------------- +src/test.kt:9:Error: Using mutable objects as state in Compose will +cause your users to see incorrect or stale data in your app.Mutable +objects that are not observable, such as ArrayList or a mutable data +class, cannot be observed by Compose to trigger recomposition when they +change.See +https://slackhq.github.io/compose-lints/rules/#do-not-use-inherently-mutable-types-as-parameters +for more information. [ComposeMutableParameters] +fun Something(a: HashSet<String>) {} + --------------- +src/test.kt:11:Error: Using mutable objects as state in Compose will +cause your users to see incorrect or stale data in your app.Mutable +objects that are not observable, such as ArrayList or a mutable data +class, cannot be observed by Compose to trigger recomposition when they +change.See +https://slackhq.github.io/compose-lints/rules/#do-not-use-inherently-mutable-types-as-parameters +for more information. [ComposeMutableParameters] +fun Something(a: MutableMap<String, String>) {} + -------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +import androidx.compose.runtime.MutableState +import androidx.compose.runtime.Composable + +@Composable +fun Something(a: MutableState) {} +@Composable +fun Something(a: ArrayList) {} +@Composable +fun Something(a: HashSet) {} +@Composable +fun Something(a: MutableMap) {} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/MutableParametersDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MutableParametersDetector.errors when a Composable has a mutable parameter`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/compose-lints/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint.compose:compose-lint-checks:1.4.2") + +// build.gradle +lintChecks 'com.slack.lint.compose:compose-lint-checks:1.4.2' + +// build.gradle.kts with version catalogs: +lintChecks(libs.compose.lint.checks) + +# libs.versions.toml +[versions] +compose-lint-checks = "1.4.2" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +compose-lint-checks = { + module = "com.slack.lint.compose:compose-lint-checks", + version.ref = "compose-lint-checks" +} +``` + +1.4.2 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ComposeMutableParameters") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ComposeMutableParameters") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ComposeMutableParameters + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ComposeMutableParameters" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ComposeMutableParameters' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ComposeMutableParameters ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ComposeNamingLowercase.md.html b/docs/checks/ComposeNamingLowercase.md.html new file mode 100644 index 00000000..d22bb2c3 --- /dev/null +++ b/docs/checks/ComposeNamingLowercase.md.html @@ -0,0 +1,198 @@ + +(#) Value-returning Composables should be lowercase + +!!! ERROR: Value-returning Composables should be lowercase + This is an error. + +Id +: `ComposeNamingLowercase` +Summary +: Value-returning Composables should be lowercase +Severity +: Error +Category +: Productivity +Platform +: Any +Vendor +: slack +Identifier +: com.slack.lint.compose:compose-lints +Feedback +: https://github.com/slackhq/compose-lints/issues +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html) +Since +: 1.0.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/main/java/slack/lint/compose/ComposableFunctionNamingDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/ComposableFunctionNamingDetectorTest.kt) +Copyright Year +: 2023 + +Composable functions that return a value should start with a lowercase +letter.While useful and accepted outside of @Composable functions, this +factory function convention has drawbacks that set inappropriate +expectations for callers when used with @Composable functions.See +https://slackhq.github.io/compose-lints/rules/#naming-composable-functions-properly +for more information. + +(##) Options + +You can configure this lint checks using the following options: + +(###) allowed-composable-function-names + +A comma-separated list of regexes of allowed composable function names. +This property should define comma-separated list of regexes of allowed composable function names. + + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="ComposeNamingLowercase"> + <option name="allowed-composable-function-names" value="some string" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test.kt:4:Error: Composable functions that return a value should +start with a lowercase letter.While useful and accepted outside of +@Composable functions, this factory function convention has drawbacks +that set inappropriate expectations for callers when used with +@Composable functions.See +https://slackhq.github.io/compose-lints/rules/#naming-composable-functions-properly +for more information. [ComposeNamingLowercase] +fun MyComposable(): Something { } + ------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +import androidx.compose.runtime.Composable + +@Composable +fun MyComposable(): Something { } +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/ComposableFunctionNamingDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint.compose:compose-lint-checks:1.4.2") + +// build.gradle +lintChecks 'com.slack.lint.compose:compose-lint-checks:1.4.2' + +// build.gradle.kts with version catalogs: +lintChecks(libs.compose.lint.checks) + +# libs.versions.toml +[versions] +compose-lint-checks = "1.4.2" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +compose-lint-checks = { + module = "com.slack.lint.compose:compose-lint-checks", + version.ref = "compose-lint-checks" +} +``` + +1.4.2 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ComposeNamingLowercase") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ComposeNamingLowercase") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ComposeNamingLowercase + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ComposeNamingLowercase" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ComposeNamingLowercase' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ComposeNamingLowercase ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ComposeNamingUppercase.md.html b/docs/checks/ComposeNamingUppercase.md.html new file mode 100644 index 00000000..a480bcd7 --- /dev/null +++ b/docs/checks/ComposeNamingUppercase.md.html @@ -0,0 +1,208 @@ + +(#) Unit Composables should be uppercase + +!!! ERROR: Unit Composables should be uppercase + This is an error. + +Id +: `ComposeNamingUppercase` +Summary +: Unit Composables should be uppercase +Severity +: Error +Category +: Productivity +Platform +: Any +Vendor +: slack +Identifier +: com.slack.lint.compose:compose-lints +Feedback +: https://github.com/slackhq/compose-lints/issues +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html) +Since +: 1.0.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/main/java/slack/lint/compose/ComposableFunctionNamingDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/ComposableFunctionNamingDetectorTest.kt) +Copyright Year +: 2023 + +Composable functions that return Unit should start with an uppercase +letter.They are considered declarative entities that can be either +present or absent in a composition and therefore follow the naming rules +for classes.See +https://slackhq.github.io/compose-lints/rules/#naming-composable-functions-properly +for more information. + +(##) Options + +You can configure this lint checks using the following options: + +(###) allowed-composable-function-names + +A comma-separated list of regexes of allowed composable function names. +This property should define comma-separated list of regexes of allowed composable function names. + + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="ComposeNamingUppercase"> + <option name="allowed-composable-function-names" value="some string" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test.kt:4:Error: Composable functions that return Unit should start +with an uppercase letter.They are considered declarative entities that +can be either present or absent in a composition and therefore follow +the naming rules for classes.See +https://slackhq.github.io/compose-lints/rules/#naming-composable-functions-properly +for more information. [ComposeNamingUppercase] +fun myComposable() { } + ------------ +src/test.kt:7:Error: Composable functions that return Unit should start +with an uppercase letter.They are considered declarative entities that +can be either present or absent in a composition and therefore follow +the naming rules for classes.See +https://slackhq.github.io/compose-lints/rules/#naming-composable-functions-properly +for more information. [ComposeNamingUppercase] +fun myComposable(): Unit { } + ------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +import androidx.compose.runtime.Composable + +@Composable +fun myComposable() { } + +@Composable +fun myComposable(): Unit { } +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/ComposableFunctionNamingDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint.compose:compose-lint-checks:1.4.2") + +// build.gradle +lintChecks 'com.slack.lint.compose:compose-lint-checks:1.4.2' + +// build.gradle.kts with version catalogs: +lintChecks(libs.compose.lint.checks) + +# libs.versions.toml +[versions] +compose-lint-checks = "1.4.2" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +compose-lint-checks = { + module = "com.slack.lint.compose:compose-lint-checks", + version.ref = "compose-lint-checks" +} +``` + +1.4.2 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ComposeNamingUppercase") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ComposeNamingUppercase") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ComposeNamingUppercase + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ComposeNamingUppercase" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ComposeNamingUppercase' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ComposeNamingUppercase ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ComposeParameterOrder.md.html b/docs/checks/ComposeParameterOrder.md.html new file mode 100644 index 00000000..13f0543d --- /dev/null +++ b/docs/checks/ComposeParameterOrder.md.html @@ -0,0 +1,246 @@ + +(#) Composable function parameters should be ordered + +!!! ERROR: Composable function parameters should be ordered + This is an error. + +Id +: `ComposeParameterOrder` +Summary +: Composable function parameters should be ordered +Severity +: Error +Category +: Productivity +Platform +: Any +Vendor +: slack +Identifier +: com.slack.lint.compose:compose-lints +Feedback +: https://github.com/slackhq/compose-lints/issues +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html) +Since +: 1.0.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/main/java/slack/lint/compose/ParameterOrderDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/ParameterOrderDetectorTest.kt) +Copyright Year +: 2023 + +This is replaced when reported. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test.kt:5:Error: Parameters in a composable function should be +ordered following this pattern: params without defaults, modifiers, +params with defaults and optionally, a trailing function that might not +have a default param. +Current params are: [modifier: Modifier = Modifier, other: String, +other2: String] but should be [other: String, other2: String, modifier: +Modifier = Modifier]. +See +https://slackhq.github.io/compose-lints/rules/#ordering-composable-parameters-properly +for more information. [ComposeParameterOrder] +fun MyComposable(modifier: Modifier = Modifier, other: String, other2: String) { } + -------------------------------------------------------------- +src/test.kt:8:Error: Parameters in a composable function should be +ordered following this pattern: params without defaults, modifiers, +params with defaults and optionally, a trailing function that might not +have a default param. +Current params are: [text: String = "deffo", modifier: Modifier = +Modifier] but should be [modifier: Modifier = Modifier, text: String = +"deffo"]. +See +https://slackhq.github.io/compose-lints/rules/#ordering-composable-parameters-properly +for more information. [ComposeParameterOrder] +fun MyComposable(text: String = "deffo", modifier: Modifier = Modifier) { } + ------------------------------------------------------- +src/test.kt:11:Error: Parameters in a composable function should be +ordered following this pattern: params without defaults, modifiers, +params with defaults and optionally, a trailing function that might not +have a default param. +Current params are: [modifier: Modifier = Modifier, text: String = +"123", modifier2: Modifier = Modifier] but should be [modifier: Modifier += Modifier, modifier2: Modifier = Modifier, text: String = "123"]. +See +https://slackhq.github.io/compose-lints/rules/#ordering-composable-parameters-properly +for more information. [ComposeParameterOrder] +fun MyComposable(modifier: Modifier = Modifier, text: String = "123", modifier2: Modifier = Modifier) { } + ------------------------------------------------------------------------------------- +src/test.kt:14:Error: Parameters in a composable function should be +ordered following this pattern: params without defaults, modifiers, +params with defaults and optionally, a trailing function that might not +have a default param. +Current params are: [text: String = "123", modifier: Modifier = +Modifier, lambda: () -> Unit] but should be [modifier: Modifier = +Modifier, text: String = "123", lambda: () -> Unit]. +See +https://slackhq.github.io/compose-lints/rules/#ordering-composable-parameters-properly +for more information. [ComposeParameterOrder] +fun MyComposable(text: String = "123", modifier: Modifier = Modifier, lambda: () -> Unit) { } + ------------------------------------------------------------------------- +src/test.kt:17:Error: Parameters in a composable function should be +ordered following this pattern: params without defaults, modifiers, +params with defaults and optionally, a trailing function that might not +have a default param. +Current params are: [text1: String, m2: Modifier = Modifier, modifier: +Modifier = Modifier, trailing: () -> Unit] but should be [text1: String, +modifier: Modifier = Modifier, m2: Modifier = Modifier, trailing: () -> +Unit]. +See +https://slackhq.github.io/compose-lints/rules/#ordering-composable-parameters-properly +for more information. [ComposeParameterOrder] +fun MyComposable(text1: String, m2: Modifier = Modifier, modifier: Modifier = Modifier, trailing: () -> Unit) { } + --------------------------------------------------------------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier + +@Composable +fun MyComposable(modifier: Modifier = Modifier, other: String, other2: String) { } + +@Composable +fun MyComposable(text: String = "deffo", modifier: Modifier = Modifier) { } + +@Composable +fun MyComposable(modifier: Modifier = Modifier, text: String = "123", modifier2: Modifier = Modifier) { } + +@Composable +fun MyComposable(text: String = "123", modifier: Modifier = Modifier, lambda: () -> Unit) { } + +@Composable +fun MyComposable(text1: String, m2: Modifier = Modifier, modifier: Modifier = Modifier, trailing: () -> Unit) { } +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/ParameterOrderDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `ParameterOrderDetector.errors found when ordering is wrong`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/compose-lints/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint.compose:compose-lint-checks:1.4.2") + +// build.gradle +lintChecks 'com.slack.lint.compose:compose-lint-checks:1.4.2' + +// build.gradle.kts with version catalogs: +lintChecks(libs.compose.lint.checks) + +# libs.versions.toml +[versions] +compose-lint-checks = "1.4.2" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +compose-lint-checks = { + module = "com.slack.lint.compose:compose-lint-checks", + version.ref = "compose-lint-checks" +} +``` + +1.4.2 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ComposeParameterOrder") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ComposeParameterOrder") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ComposeParameterOrder + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ComposeParameterOrder" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ComposeParameterOrder' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ComposeParameterOrder ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ComposePreviewNaming.md.html b/docs/checks/ComposePreviewNaming.md.html new file mode 100644 index 00000000..ca95961b --- /dev/null +++ b/docs/checks/ComposePreviewNaming.md.html @@ -0,0 +1,194 @@ + +(#) Preview annotations require certain suffixes + +!!! ERROR: Preview annotations require certain suffixes + This is an error. + +Id +: `ComposePreviewNaming` +Summary +: Preview annotations require certain suffixes +Severity +: Error +Category +: Productivity +Platform +: Any +Vendor +: slack +Identifier +: com.slack.lint.compose:compose-lints +Feedback +: https://github.com/slackhq/compose-lints/issues +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html) +Since +: 1.0.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/main/java/slack/lint/compose/PreviewNamingDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/PreviewNamingDetectorTest.kt) +Copyright Year +: 2023 + +This is replaced when reporting. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/Banana.kt:3:Error: Preview annotations with 1 preview annotations +should end with the Preview suffix. +See +https://slackhq.github.io/compose-lints/rules/#naming-multipreview-annotations-properly +for more information. [ComposePreviewNaming] +@Preview +^ +src/Banana.kt:5:Error: Preview annotations with 1 preview annotations +should end with the Preview suffix. +See +https://slackhq.github.io/compose-lints/rules/#naming-multipreview-annotations-properly +for more information. [ComposePreviewNaming] +@Preview +^ +src/Banana.kt:7:Error: Preview annotations with 1 preview annotations +should end with the Preview suffix. +See +https://slackhq.github.io/compose-lints/rules/#naming-multipreview-annotations-properly +for more information. [ComposePreviewNaming] +@BananaPreviews +^ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/Banana.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +import androidx.compose.ui.tooling.preview.Preview + +@Preview +annotation class Banana +@Preview +annotation class BananaPreviews +@BananaPreviews +annotation class WithBananaPreviews +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/PreviewNamingDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `PreviewNamingDetector.errors when a multipreview annotation is not correctly named for 1 preview`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/compose-lints/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint.compose:compose-lint-checks:1.4.2") + +// build.gradle +lintChecks 'com.slack.lint.compose:compose-lint-checks:1.4.2' + +// build.gradle.kts with version catalogs: +lintChecks(libs.compose.lint.checks) + +# libs.versions.toml +[versions] +compose-lint-checks = "1.4.2" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +compose-lint-checks = { + module = "com.slack.lint.compose:compose-lint-checks", + version.ref = "compose-lint-checks" +} +``` + +1.4.2 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ComposePreviewNaming") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ComposePreviewNaming") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ComposePreviewNaming + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ComposePreviewNaming" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ComposePreviewNaming' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ComposePreviewNaming ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ComposePreviewPublic.md.html b/docs/checks/ComposePreviewPublic.md.html new file mode 100644 index 00000000..652e1c9c --- /dev/null +++ b/docs/checks/ComposePreviewPublic.md.html @@ -0,0 +1,199 @@ + +(#) Preview composables should be private + +!!! ERROR: Preview composables should be private + This is an error. + +Id +: `ComposePreviewPublic` +Summary +: Preview composables should be private +Severity +: Error +Category +: Productivity +Platform +: Any +Vendor +: slack +Identifier +: com.slack.lint.compose:compose-lints +Feedback +: https://github.com/slackhq/compose-lints/issues +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html) +Since +: 1.0.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/main/java/slack/lint/compose/PreviewPublicDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/PreviewPublicDetectorTest.kt) +Copyright Year +: 2023 + +Composables annotated with `@Preview` that are used only for previewing +the UI should not be public.See +https://slackhq.github.io/compose-lints/rules/#preview-composables-should-not-be-public +for more information. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test.kt:4:Error: Composables annotated with @Preview that are used +only for previewing the UI should not be public.See +https://slackhq.github.io/compose-lints/rules/#preview-composables-should-not-be-public +for more information. [ComposePreviewPublic] +@Preview +^ +src/test.kt:7:Error: Composables annotated with @Preview that are used +only for previewing the UI should not be public.See +https://slackhq.github.io/compose-lints/rules/#preview-composables-should-not-be-public +for more information. [ComposePreviewPublic] +@CombinedPreviews +^ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`src/CombinedPreviews.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.tooling.preview.PreviewParameterProvider + +@Preview +annotation class CombinedPreviews + +class User +class UserProvider : PreviewParameterProvider +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +import androidx.compose.runtime.Composable +import androidx.compose.ui.tooling.preview.Preview + +@Preview +@Composable +fun MyComposable() { } +@CombinedPreviews +@Composable +fun MyComposable() { } +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/PreviewPublicDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint.compose:compose-lint-checks:1.4.2") + +// build.gradle +lintChecks 'com.slack.lint.compose:compose-lint-checks:1.4.2' + +// build.gradle.kts with version catalogs: +lintChecks(libs.compose.lint.checks) + +# libs.versions.toml +[versions] +compose-lint-checks = "1.4.2" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +compose-lint-checks = { + module = "com.slack.lint.compose:compose-lint-checks", + version.ref = "compose-lint-checks" +} +``` + +1.4.2 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ComposePreviewPublic") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ComposePreviewPublic") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ComposePreviewPublic + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ComposePreviewPublic" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ComposePreviewPublic' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ComposePreviewPublic ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ComposeRememberMissing.md.html b/docs/checks/ComposeRememberMissing.md.html new file mode 100644 index 00000000..2cf0d849 --- /dev/null +++ b/docs/checks/ComposeRememberMissing.md.html @@ -0,0 +1,194 @@ + +(#) State values should be remembered + +!!! ERROR: State values should be remembered + This is an error. + +Id +: `ComposeRememberMissing` +Summary +: State values should be remembered +Severity +: Error +Category +: Productivity +Platform +: Any +Vendor +: slack +Identifier +: com.slack.lint.compose:compose-lints +Feedback +: https://github.com/slackhq/compose-lints/issues +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html) +Since +: 1.0.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/main/java/slack/lint/compose/RememberMissingDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/RememberMissingDetectorTest.kt) +Copyright Year +: 2023 + +This is replaced when reported. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test.kt:7:Error: Using mutableStateOf in a @Composable function +without it being inside of a remember function. +If you don't remember the state instance, a new state instance will be +created when the function is recomposed. +See +https://slackhq.github.io/compose-lints/rules/#state-should-be-remembered-in-composables +for more information. [ComposeRememberMissing] + val something = mutableStateOf("X") + ------------------- +src/test.kt:10:Error: Using mutableStateOf in a @Composable function +without it being inside of a remember function. +If you don't remember the state instance, a new state instance will be +created when the function is recomposed. +See +https://slackhq.github.io/compose-lints/rules/#state-should-be-remembered-in-composables +for more information. [ComposeRememberMissing] +fun MyComposable(something: State<String> = mutableStateOf("X")) { + ------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +import androidx.compose.runtime.Composable +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.State + +@Composable +fun MyComposable() { + val something = mutableStateOf("X") +} +@Composable +fun MyComposable(something: State = mutableStateOf("X")) { +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/RememberMissingDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `RememberMissingDetector.errors when a non-remembered mutableStateOf is used in a Composable`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/compose-lints/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint.compose:compose-lint-checks:1.4.2") + +// build.gradle +lintChecks 'com.slack.lint.compose:compose-lint-checks:1.4.2' + +// build.gradle.kts with version catalogs: +lintChecks(libs.compose.lint.checks) + +# libs.versions.toml +[versions] +compose-lint-checks = "1.4.2" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +compose-lint-checks = { + module = "com.slack.lint.compose:compose-lint-checks", + version.ref = "compose-lint-checks" +} +``` + +1.4.2 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ComposeRememberMissing") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ComposeRememberMissing") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ComposeRememberMissing + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ComposeRememberMissing" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ComposeRememberMissing' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ComposeRememberMissing ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ComposeUnstableCollections.md.html b/docs/checks/ComposeUnstableCollections.md.html new file mode 100644 index 00000000..53cd766b --- /dev/null +++ b/docs/checks/ComposeUnstableCollections.md.html @@ -0,0 +1,219 @@ + +(#) Immutable collections should ideally be used in Composables + +!!! WARNING: Immutable collections should ideally be used in Composables + This is a warning. + +Id +: `ComposeUnstableCollections` +Summary +: Immutable collections should ideally be used in Composables +Severity +: Warning +Category +: Productivity +Platform +: Any +Vendor +: slack +Identifier +: com.slack.lint.compose:compose-lints +Feedback +: https://github.com/slackhq/compose-lints/issues +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html) +Since +: 1.0.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/main/java/slack/lint/compose/UnstableCollectionsDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/UnstableCollectionsDetectorTest.kt) +Copyright Year +: 2023 + +This is replaced when reported. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test.kt:4:Warning: The Compose Compiler cannot infer the stability +of a parameter if a Collection is used in it, even if the item +type is stable. +You should use Kotlinx Immutable Collections instead: a: +ImmutableCollection or create an @Immutable wrapper for this +class: @Immutable data class ACollection(val items: Collection) +See +https://slackhq.github.io/compose-lints/rules/#avoid-using-unstable-collections +for more information. [ComposeUnstableCollections] +fun Something(a: Collection<String>) {} + ------------------ +src/test.kt:6:Warning: The Compose Compiler cannot infer the stability +of a parameter if a List is used in it, even if the item type is +stable. +You should use Kotlinx Immutable Collections instead: a: +ImmutableList or create an @Immutable wrapper for this class: +@Immutable data class AList(val items: List) +See +https://slackhq.github.io/compose-lints/rules/#avoid-using-unstable-collections +for more information. [ComposeUnstableCollections] +fun Something(a: List<String>) {} + ------------ +src/test.kt:8:Warning: The Compose Compiler cannot infer the stability +of a parameter if a Set is used in it, even if the item type is +stable. +You should use Kotlinx Immutable Collections instead: a: +ImmutableSet or create an @Immutable wrapper for this class: +@Immutable data class ASet(val items: Set) +See +https://slackhq.github.io/compose-lints/rules/#avoid-using-unstable-collections +for more information. [ComposeUnstableCollections] +fun Something(a: Set<String>) {} + ----------- +src/test.kt:10:Warning: The Compose Compiler cannot infer the stability +of a parameter if a Map is used in it, even if the item +type is stable. +You should use Kotlinx Immutable Collections instead: a: +ImmutableMap or create an @Immutable wrapper for this +class: @Immutable data class AMap(val items: Map) +See +https://slackhq.github.io/compose-lints/rules/#avoid-using-unstable-collections +for more information. [ComposeUnstableCollections] +fun Something(a: Map<String, Int>) {} + ---------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +import androidx.compose.runtime.Composable + +@Composable +fun Something(a: Collection) {} +@Composable +fun Something(a: List) {} +@Composable +fun Something(a: Set) {} +@Composable +fun Something(a: Map) {} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/UnstableCollectionsDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `UnstableCollectionsDetector.warnings when a Composable has a Collection List Set Map parameter`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/compose-lints/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint.compose:compose-lint-checks:1.4.2") + +// build.gradle +lintChecks 'com.slack.lint.compose:compose-lint-checks:1.4.2' + +// build.gradle.kts with version catalogs: +lintChecks(libs.compose.lint.checks) + +# libs.versions.toml +[versions] +compose-lint-checks = "1.4.2" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +compose-lint-checks = { + module = "com.slack.lint.compose:compose-lint-checks", + version.ref = "compose-lint-checks" +} +``` + +1.4.2 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ComposeUnstableCollections") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ComposeUnstableCollections") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ComposeUnstableCollections + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ComposeUnstableCollections" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ComposeUnstableCollections' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ComposeUnstableCollections ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ComposeUnstableReceiver.md.html b/docs/checks/ComposeUnstableReceiver.md.html new file mode 100644 index 00000000..ec2ea845 --- /dev/null +++ b/docs/checks/ComposeUnstableReceiver.md.html @@ -0,0 +1,235 @@ + +(#) Unstable receivers will always be recomposed + +!!! WARNING: Unstable receivers will always be recomposed + This is a warning. + +Id +: `ComposeUnstableReceiver` +Summary +: Unstable receivers will always be recomposed +Severity +: Warning +Category +: Productivity +Platform +: Any +Vendor +: slack +Identifier +: com.slack.lint.compose:compose-lints +Feedback +: https://github.com/slackhq/compose-lints/issues +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html) +Since +: 1.3.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/main/java/slack/lint/compose/UnstableReceiverDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/UnstableReceiverDetectorTest.kt) +Copyright Year +: 2023 + +Instance composable functions on non-stable classes will always be +recomposed. If possible, make the receiver type stable or refactor this +function if that isn't possible. See +https://slackhq.github.io/compose-lints/rules/#unstable-receivers for +more information. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/ExampleInterface.kt:4:Warning: Instance composable functions on +non-stable classes will always be recomposed. If possible, make the +receiver type stable or refactor this function if that isn't possible. +See https://slackhq.github.io/compose-lints/rules/#unstable-receivers +for more information. [ComposeUnstableReceiver] + @Composable fun Content() + ------- +src/ExampleInterface.kt:8:Warning: Instance composable functions on +non-stable classes will always be recomposed. If possible, make the +receiver type stable or refactor this function if that isn't possible. +See https://slackhq.github.io/compose-lints/rules/#unstable-receivers +for more information. [ComposeUnstableReceiver] + @Composable fun Content() {} + ------- +src/ExampleInterface.kt:12:Warning: Instance composable functions on +non-stable classes will always be recomposed. If possible, make the +receiver type stable or refactor this function if that isn't possible. +See https://slackhq.github.io/compose-lints/rules/#unstable-receivers +for more information. [ComposeUnstableReceiver] +fun Example.OtherContent() {} + ------- +src/ExampleInterface.kt:15:Warning: Instance composable functions on +non-stable classes will always be recomposed. If possible, make the +receiver type stable or refactor this function if that isn't possible. +See https://slackhq.github.io/compose-lints/rules/#unstable-receivers +for more information. [ComposeUnstableReceiver] +val Example.OtherContentProperty get() {} + ------- +src/ExampleInterface.kt:19:Warning: Instance composable functions on +non-stable classes will always be recomposed. If possible, make the +receiver type stable or refactor this function if that isn't possible. +See https://slackhq.github.io/compose-lints/rules/#unstable-receivers +for more information. [ComposeUnstableReceiver] + @Composable fun present(): T + ------- +src/ExampleInterface.kt:23:Warning: Instance composable functions on +non-stable classes will always be recomposed. If possible, make the +receiver type stable or refactor this function if that isn't possible. +See https://slackhq.github.io/compose-lints/rules/#unstable-receivers +for more information. [ComposeUnstableReceiver] + @Composable override fun present(): String { return "hi" } + ------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/ExampleInterface.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +import androidx.compose.runtime.Composable + +interface ExampleInterface { + @Composable fun Content() +} + +class Example { + @Composable fun Content() {} +} + +@Composable +fun Example.OtherContent() {} + +@get:Composable +val Example.OtherContentProperty get() {} + +// Supertypes +interface Presenter { + @Composable fun present(): T +} + +class HomePresenter : Presenter { + @Composable override fun present(): String { return "hi" } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/UnstableReceiverDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `UnstableReceiverDetector.unstable receiver types report errors`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/compose-lints/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint.compose:compose-lint-checks:1.4.2") + +// build.gradle +lintChecks 'com.slack.lint.compose:compose-lint-checks:1.4.2' + +// build.gradle.kts with version catalogs: +lintChecks(libs.compose.lint.checks) + +# libs.versions.toml +[versions] +compose-lint-checks = "1.4.2" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +compose-lint-checks = { + module = "com.slack.lint.compose:compose-lint-checks", + version.ref = "compose-lint-checks" +} +``` + +1.4.2 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ComposeUnstableReceiver") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ComposeUnstableReceiver") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ComposeUnstableReceiver + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ComposeUnstableReceiver" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ComposeUnstableReceiver' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ComposeUnstableReceiver ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ComposeViewModelForwarding.md.html b/docs/checks/ComposeViewModelForwarding.md.html new file mode 100644 index 00000000..0d416b33 --- /dev/null +++ b/docs/checks/ComposeViewModelForwarding.md.html @@ -0,0 +1,183 @@ + +(#) Don't forward ViewModels through composables + +!!! ERROR: Don't forward ViewModels through composables + This is an error. + +Id +: `ComposeViewModelForwarding` +Summary +: Don't forward ViewModels through composables +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: com.slack.lint.compose:compose-lints +Feedback +: https://github.com/slackhq/compose-lints/issues +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html) +Since +: 1.0.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/main/java/slack/lint/compose/ViewModelForwardingDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/ViewModelForwardingDetectorTest.kt) +Copyright Year +: 2023 + +Forwarding a `ViewModel` through multiple `@Composable` functions should +be avoided. Consider using state hoisting.See +https://slackhq.github.io/compose-lints/rules/#hoist-all-the-things for +more information. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/MyViewModel.kt:7:Error: Forwarding a ViewModel through multiple +@Composable functions should be avoided. Consider using state +hoisting.See +https://slackhq.github.io/compose-lints/rules/#hoist-all-the-things for +more information. [ComposeViewModelForwarding] + AnotherComposable(viewModel) + ---------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/MyViewModel.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +import androidx.compose.runtime.Composable + +class MyViewModel + +@Composable +fun MyComposable(viewModel: MyViewModel) { + AnotherComposable(viewModel) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/ViewModelForwardingDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `ViewModelForwardingDetector.errors when a ViewModel is forwarded to another Composable`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/compose-lints/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint.compose:compose-lint-checks:1.4.2") + +// build.gradle +lintChecks 'com.slack.lint.compose:compose-lint-checks:1.4.2' + +// build.gradle.kts with version catalogs: +lintChecks(libs.compose.lint.checks) + +# libs.versions.toml +[versions] +compose-lint-checks = "1.4.2" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +compose-lint-checks = { + module = "com.slack.lint.compose:compose-lint-checks", + version.ref = "compose-lint-checks" +} +``` + +1.4.2 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ComposeViewModelForwarding") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ComposeViewModelForwarding") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ComposeViewModelForwarding + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ComposeViewModelForwarding" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ComposeViewModelForwarding' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ComposeViewModelForwarding ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ComposeViewModelInjection.md.html b/docs/checks/ComposeViewModelInjection.md.html new file mode 100644 index 00000000..86b2a058 --- /dev/null +++ b/docs/checks/ComposeViewModelInjection.md.html @@ -0,0 +1,226 @@ + +(#) Implicit dependencies of composables should be made explicit + +!!! ERROR: Implicit dependencies of composables should be made explicit + This is an error. + +Id +: `ComposeViewModelInjection` +Summary +: Implicit dependencies of composables should be made explicit +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: com.slack.lint.compose:compose-lints +Feedback +: https://github.com/slackhq/compose-lints/issues +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html) +Since +: 1.0.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/main/java/slack/lint/compose/ViewModelInjectionDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/ViewModelInjectionDetectorTest.kt) +Copyright Year +: 2023 + +Replaced when reporting. + +(##) Options + +You can configure this lint checks using the following options: + +(###) viewmodel-factories + +A comma-separated list of viewModel factories.. +This property should define comma-separated list of allowed viewModel factory function names. + + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="ComposeViewModelInjection"> + <option name="viewmodel-factories" value="some string" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test.kt:6:Error: Implicit dependencies of composables should be made +explicit. +Usages of to acquire a ViewModel should be done in composable default +parameters, so that it is more testable and flexible. +See https://slackhq.github.io/compose-lints/rules/#viewmodels for more +information. [ComposeViewModelInjection] + val viewModel = <MyVM>() + ------------------------ +src/test.kt:11:Error: Implicit dependencies of composables should be +made explicit. +Usages of to acquire a ViewModel should be done in composable default +parameters, so that it is more testable and flexible. +See https://slackhq.github.io/compose-lints/rules/#viewmodels for more +information. [ComposeViewModelInjection] + val viewModel: MyVM = () + ------------------------ +src/test.kt:16:Error: Implicit dependencies of composables should be +made explicit. +Usages of to acquire a ViewModel should be done in composable default +parameters, so that it is more testable and flexible. +See https://slackhq.github.io/compose-lints/rules/#viewmodels for more +information. [ComposeViewModelInjection] + val viewModel: MyVM = () + ------------------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier + + @Composable +fun MyComposable(modifier: Modifier) { + val viewModel = () +} + +@Composable +fun MyComposableNoParams() { + val viewModel: MyVM = () +} + +@Composable +fun MyComposableTrailingLambda(block: () -> Unit) { + val viewModel: MyVM = () +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/ViewModelInjectionDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `ViewModelInjectionDetector.errors when a weaverViewModel is used at the beginning of a Composable`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/compose-lints/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint.compose:compose-lint-checks:1.4.2") + +// build.gradle +lintChecks 'com.slack.lint.compose:compose-lint-checks:1.4.2' + +// build.gradle.kts with version catalogs: +lintChecks(libs.compose.lint.checks) + +# libs.versions.toml +[versions] +compose-lint-checks = "1.4.2" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +compose-lint-checks = { + module = "com.slack.lint.compose:compose-lint-checks", + version.ref = "compose-lint-checks" +} +``` + +1.4.2 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ComposeViewModelInjection") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ComposeViewModelInjection") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ComposeViewModelInjection + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ComposeViewModelInjection" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ComposeViewModelInjection' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ComposeViewModelInjection ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/CompositionLocalNaming.md.html b/docs/checks/CompositionLocalNaming.md.html index fd180e48..d2b3eb17 100644 --- a/docs/checks/CompositionLocalNaming.md.html +++ b/docs/checks/CompositionLocalNaming.md.html @@ -20,6 +20,14 @@ : androidx.compose.runtime Feedback : https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.runtime:runtime-android](androidx_compose_runtime_runtime-android.md.html) +Since +: 1.5.0 Affects : Kotlin and Java files and test sources Editing @@ -43,25 +51,16 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/androidx/compose/runtime/foo/Test.kt:6:Warning: CompositionLocal properties should be prefixed with Local [CompositionLocalNaming] - val FooCompositionLocal = compositionLocalOf { 5 } ------------------- - - src/androidx/compose/runtime/foo/Test.kt:9:Warning: CompositionLocal properties should be prefixed with Local [CompositionLocalNaming] - val BarCompositionLocal: CompositionLocal<String?> = staticCompositionLocalOf { ------------------- - - src/androidx/compose/runtime/foo/Test.kt:16:Warning: CompositionLocal properties should be prefixed with Local [CompositionLocalNaming] - val BazCompositionLocal: ProvidableCompositionLocal<Int> = ------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -97,6 +96,44 @@ To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=612128. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.runtime:runtime-android:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.runtime:runtime-android:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.runtime.android) + +# libs.versions.toml +[versions] +runtime-android = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +runtime-android = { + module = "androidx.compose.runtime:runtime-android", + version.ref = "runtime-android" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.runtime:runtime-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.runtime:runtime-android](androidx_compose_runtime_runtime-android.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/ConfigurationScreenWidthHeight.md.html b/docs/checks/ConfigurationScreenWidthHeight.md.html new file mode 100644 index 00000000..d7a81a0c --- /dev/null +++ b/docs/checks/ConfigurationScreenWidthHeight.md.html @@ -0,0 +1,243 @@ + +(#) Using Configuration.screenWidthDp/screenHeightDp instead of LocalWindowInfo.current.containerSize + +!!! WARNING: Using Configuration.screenWidthDp/screenHeightDp instead of LocalWindowInfo.current.containerSize + This is a warning. + +Id +: `ConfigurationScreenWidthHeight` +Summary +: Using Configuration.screenWidthDp/screenHeightDp instead of LocalWindowInfo.current.containerSize +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: Jetpack Compose +Identifier +: androidx.compose.ui +Feedback +: https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.ui:ui-android](androidx_compose_ui_ui-android.md.html) +Since +: 1.8.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/ui/ui-lint/src/main/java/androidx/compose/ui/lint/ConfigurationScreenWidthHeightDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/ui/ui-lint/src/test/java/androidx/compose/ui/lint/ConfigurationScreenWidthHeightDetectorTest.kt) +Copyright Year +: 2025 + +Configuration.screenWidthDp and Configuration.screenHeightDp have +different insets behaviour depending on target SDK version, and are +rounded to the nearest Dp. This means that using these values in +composition to size a layout can result in issues, as these values do +not accurately represent the actual available window size. Instead it is +recommended to use WindowInfo.containerSize which accurately represents +the window size. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test/test.kt:11:Warning: Using Configuration.screenWidthDp instead +of LocalWindowInfo.current.containerSize +[ConfigurationScreenWidthHeight] + LocalConfiguration.current.screenWidthDp + ---------------------------------------- +src/test/test.kt:12:Warning: Using Configuration.screenHeightDp instead +of LocalWindowInfo.current.containerSize +[ConfigurationScreenWidthHeight] + LocalConfiguration.current.screenHeightDp + ----------------------------------------- +src/test/test.kt:15:Warning: Using Configuration.screenWidthDp instead +of LocalWindowInfo.current.containerSize +[ConfigurationScreenWidthHeight] + val width = configuration.screenWidthDp.dp + --------------------------- +src/test/test.kt:16:Warning: Using Configuration.screenHeightDp instead +of LocalWindowInfo.current.containerSize +[ConfigurationScreenWidthHeight] + val height = configuration.screenHeightDp.dp + ---------------------------- +src/test/test.kt:21:Warning: Using Configuration.screenWidthDp instead +of LocalWindowInfo.current.containerSize +[ConfigurationScreenWidthHeight] + configuration.screenWidthDp + --------------------------- +src/test/test.kt:22:Warning: Using Configuration.screenHeightDp instead +of LocalWindowInfo.current.containerSize +[ConfigurationScreenWidthHeight] + configuration.screenHeightDp + ---------------------------- +src/test/test.kt:28:Warning: Using Configuration.screenWidthDp instead +of LocalWindowInfo.current.containerSize +[ConfigurationScreenWidthHeight] + val width = configuration.screenWidthDp.dp + --------------------------- +src/test/test.kt:29:Warning: Using Configuration.screenHeightDp instead +of LocalWindowInfo.current.containerSize +[ConfigurationScreenWidthHeight] + val height = configuration.screenHeightDp.dp + ---------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test + +import android.content.res.Configuration +import androidx.compose.runtime.Composable +import androidx.compose.ui.platform.LocalConfiguration +import androidx.compose.ui.unit.dp + +@Composable +fun Test() { + LocalConfiguration.current.screenWidthDp + LocalConfiguration.current.screenHeightDp + + val configuration = LocalConfiguration.current + val width = configuration.screenWidthDp.dp + val height = configuration.screenHeightDp.dp + + val someLambda = { + // Capture configuration value from composition, and use outside of + // composition + configuration.screenWidthDp + configuration.screenHeightDp + } +} + +@Composable +fun Test2(configuration: Configuration) { + val width = configuration.screenWidthDp.dp + val height = configuration.screenHeightDp.dp +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/ui/ui-lint/src/test/java/androidx/compose/ui/lint/ConfigurationScreenWidthHeightDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `ConfigurationScreenWidthHeightDetector.error`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=612128. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.ui:ui-android:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.ui:ui-android:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.ui.android) + +# libs.versions.toml +[versions] +ui-android = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +ui-android = { + module = "androidx.compose.ui:ui-android", + version.ref = "ui-android" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.ui:ui-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.ui:ui-android](androidx_compose_ui_ui-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ConfigurationScreenWidthHeight") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ConfigurationScreenWidthHeight") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ConfigurationScreenWidthHeight + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ConfigurationScreenWidthHeight" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ConfigurationScreenWidthHeight' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ConfigurationScreenWidthHeight ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ConflictingOnColor.md.html b/docs/checks/ConflictingOnColor.md.html index 9ba619ac..ebd284c1 100644 --- a/docs/checks/ConflictingOnColor.md.html +++ b/docs/checks/ConflictingOnColor.md.html @@ -20,6 +20,14 @@ : androidx.compose.material Feedback : https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.material:material-android](androidx_compose_material_material-android.md.html) +Since +: 1.5.0 Affects : Kotlin and Java files and test sources Editing @@ -46,88 +54,52 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/androidx/compose/material/foo/test.kt:15:Error: Conflicting 'on' color for a given background [ConflictingOnColor] - Color.White, ----------- - - src/androidx/compose/material/foo/test.kt:16:Error: Conflicting 'on' color for a given background [ConflictingOnColor] - Color.White, ----------- - - src/androidx/compose/material/foo/test.kt:17:Error: Conflicting 'on' color for a given background [ConflictingOnColor] - Color.White, ----------- - - src/androidx/compose/material/foo/test.kt:18:Error: Conflicting 'on' color for a given background [ConflictingOnColor] - Color.White, ----------- - - src/androidx/compose/material/foo/test.kt:19:Error: Conflicting 'on' color for a given background [ConflictingOnColor] - Color.Red, --------- - - src/androidx/compose/material/foo/test.kt:31:Error: Conflicting 'on' color for a given background [ConflictingOnColor] - Color.White, ----------- - - src/androidx/compose/material/foo/test.kt:32:Error: Conflicting 'on' color for a given background [ConflictingOnColor] - Color.Blue, ---------- - - src/androidx/compose/material/foo/test.kt:34:Error: Conflicting 'on' color for a given background [ConflictingOnColor] - onSurface = Color.White, ----------- - - src/androidx/compose/material/foo/test.kt:51:Error: Conflicting 'on' color for a given background [ConflictingOnColor] - Color.White, ----------- - - src/androidx/compose/material/foo/test.kt:52:Error: Conflicting 'on' color for a given background [ConflictingOnColor] - yellow400, --------- - - src/androidx/compose/material/foo/test.kt:53:Error: Conflicting 'on' color for a given background [ConflictingOnColor] - Color.Blue, ---------- - - src/androidx/compose/material/foo/test.kt:55:Error: Conflicting 'on' color for a given background [ConflictingOnColor] - yellow500, --------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -201,6 +173,44 @@ To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=612128. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.material:material-android:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.material:material-android:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.material.android) + +# libs.versions.toml +[versions] +material-android = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +material-android = { + module = "androidx.compose.material:material-android", + version.ref = "material-android" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.material:material-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.material:material-android](androidx_compose_material_material-android.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/ConstantContentStateKeyInItemsCall.md.html b/docs/checks/ConstantContentStateKeyInItemsCall.md.html new file mode 100644 index 00000000..146ebb73 --- /dev/null +++ b/docs/checks/ConstantContentStateKeyInItemsCall.md.html @@ -0,0 +1,320 @@ + +(#) Composables within an LazyList `items` call should have unique content state keys + +!!! ERROR: Composables within an LazyList `items` call should have unique content state keys + This is an error. + +Id +: `ConstantContentStateKeyInItemsCall` +Summary +: Composables within an LazyList `items` call should have unique content state keys +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: Jetpack Compose +Identifier +: androidx.compose.animation +Feedback +: https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.animation:animation-android](androidx_compose_animation_animation-android.md.html) +Since +: 1.8.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/animation/animation-lint/src/main/java/androidx/compose/animation/lint/SharedTransitionScopeDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/animation/animation-lint/src/test/java/androidx/compose/animation/lint/SharedTransitionScopeDetectorTest.kt) +Copyright Year +: 2024 + +When using shared elements (`Modifier.sharedElement` or +`Modifier.sharedBounds`) in a LazyList, each Composable within an +`items` block should have its own unique key. Otherwise, only one item +of the visible layout will be rendered, regardless if there's an ongoing +shared element transition. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/test.kt:20:Error: Each Composable within a LazyList items call +should have unique content state keys. Make sure to either associate a +unique key related to the item's data, or simply append the item's index +to the key. [ConstantContentStateKeyInItemsCall] + state = rememberSharedContentState("Foo"), + --------------------------------- +src/foo/test.kt:27:Error: Each Composable within a LazyList items call +should have unique content state keys. Make sure to either associate a +unique key related to the item's data, or simply append the item's index +to the key. [ConstantContentStateKeyInItemsCall] + sharedContentState = rememberSharedContentState("Foo" + "Bar"), + ----------------------------------------- +src/foo/test.kt:34:Error: Each Composable within a LazyList items call +should have unique content state keys. Make sure to either associate a +unique key related to the item's data, or simply append the item's index +to the key. [ConstantContentStateKeyInItemsCall] + state = rememberSharedContentState(0), + ----------------------------- +src/foo/test.kt:43:Error: Each Composable within a LazyList items call +should have unique content state keys. Make sure to either associate a +unique key related to the item's data, or simply append the item's index +to the key. [ConstantContentStateKeyInItemsCall] + state = rememberSharedContentState("Foo"), + --------------------------------- +src/foo/test.kt:50:Error: Each Composable within a LazyList items call +should have unique content state keys. Make sure to either associate a +unique key related to the item's data, or simply append the item's index +to the key. [ConstantContentStateKeyInItemsCall] + sharedContentState = rememberSharedContentState("Foo" + "Bar"), + ----------------------------------------- +src/foo/test.kt:57:Error: Each Composable within a LazyList items call +should have unique content state keys. Make sure to either associate a +unique key related to the item's data, or simply append the item's index +to the key. [ConstantContentStateKeyInItemsCall] + state = rememberSharedContentState(0), + ----------------------------- +src/foo/test.kt:66:Error: Each Composable within a LazyList items call +should have unique content state keys. Make sure to either associate a +unique key related to the item's data, or simply append the item's index +to the key. [ConstantContentStateKeyInItemsCall] + state = rememberSharedContentState("Foo"), + --------------------------------- +src/foo/test.kt:73:Error: Each Composable within a LazyList items call +should have unique content state keys. Make sure to either associate a +unique key related to the item's data, or simply append the item's index +to the key. [ConstantContentStateKeyInItemsCall] + sharedContentState = rememberSharedContentState("Foo" + "Bar"), + ----------------------------------------- +src/foo/test.kt:80:Error: Each Composable within a LazyList items call +should have unique content state keys. Make sure to either associate a +unique key related to the item's data, or simply append the item's index +to the key. [ConstantContentStateKeyInItemsCall] + state = rememberSharedContentState(0), + ----------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package foo + +import androidx.compose.animation.* +import androidx.compose.foundation.lazy.* +import androidx.compose.runtime.* +import androidx.compose.ui.* + +@Composable +fun Test() { + SharedTransitionLayout { + AnimatedContent( + true, + ) { targetState -> + if (targetState) { + items(10) { + MyLayoutComposable( + modifier = Modifier + .sharedElement( + state = rememberSharedContentState("Foo"), + animatedVisibilityScope = this@AnimatedContent + ) + ) + MyLayoutComposable( + modifier = Modifier + .sharedBounds( + sharedContentState = rememberSharedContentState("Foo" + "Bar"), + animatedVisibilityScope = this@AnimatedContent + ) + ) + MyLayoutComposable( + modifier = Modifier + .sharedElement( + state = rememberSharedContentState(0), + animatedVisibilityScope = this@AnimatedContent + ) + ) + } + items(List(10) { it }) { + MyLayoutComposable( + modifier = Modifier + .sharedElement( + state = rememberSharedContentState("Foo"), + animatedVisibilityScope = this@AnimatedContent + ) + ) + MyLayoutComposable( + modifier = Modifier + .sharedBounds( + sharedContentState = rememberSharedContentState("Foo" + "Bar"), + animatedVisibilityScope = this@AnimatedContent + ) + ) + MyLayoutComposable( + modifier = Modifier + .sharedElement( + state = rememberSharedContentState(0), + animatedVisibilityScope = this@AnimatedContent + ) + ) + } + itemsIndexed(List(10) { it }) { _, _ -> + MyLayoutComposable( + modifier = Modifier + .sharedElement( + state = rememberSharedContentState("Foo"), + animatedVisibilityScope = this@AnimatedContent + ) + ) + MyLayoutComposable( + modifier = Modifier + .sharedBounds( + sharedContentState = rememberSharedContentState("Foo" + "Bar"), + animatedVisibilityScope = this@AnimatedContent + ) + ) + MyLayoutComposable( + modifier = Modifier + .sharedElement( + state = rememberSharedContentState(0), + animatedVisibilityScope = this@AnimatedContent + ) + ) + } + } else { + // Do Nothing + } + } + } +} + +@Composable +fun MyLayoutComposable(modifier: Modifier = Modifier) { + // Do Nothing +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/animation/animation-lint/src/test/java/androidx/compose/animation/lint/SharedTransitionScopeDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `SharedTransitionScopeDetector.constantLiteralInItemsCall_shouldWarn`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=612128. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.animation:animation-android:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.animation:animation-android:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.animation.android) + +# libs.versions.toml +[versions] +animation-android = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +animation-android = { + module = "androidx.compose.animation:animation-android", + version.ref = "animation-android" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.animation:animation-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.animation:animation-android](androidx_compose_animation_animation-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ConstantContentStateKeyInItemsCall") + fun method() { + SharedTransitionScope(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ConstantContentStateKeyInItemsCall") + void method() { + SharedTransitionScope(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ConstantContentStateKeyInItemsCall + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ConstantContentStateKeyInItemsCall" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ConstantContentStateKeyInItemsCall' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ConstantContentStateKeyInItemsCall ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ConstantLocale.md.html b/docs/checks/ConstantLocale.md.html index 514c7b6c..4a791888 100644 --- a/docs/checks/ConstantLocale.md.html +++ b/docs/checks/ConstantLocale.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.2.0 (September 2018) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/LocaleDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/LocaleDetectorTest.kt) -Copyright Year -: 2012 Assigning `Locale.getDefault()` to a constant is suspicious, because the locale can change while the app is running. @@ -40,14 +40,11 @@ Locale.getDefault() to a final static field is suspicious; this code will not work correctly if the user changes locale while the app is running [ConstantLocale] - static final Locale errorLocale = Locale.getDefault(); ------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `src/test/pkg/TestLocaleJava.java`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers @@ -67,6 +64,57 @@ } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/test/pkg/TestLocaleKotlin.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg + +import java.util.Locale + +@Suppress("HasPlatformType","JoinDeclarationAndAssignment") +class TestLocaleKotlin { + companion object { + var okLocale1 = Locale.getDefault() + val errorLocale = Locale.getDefault() + } + var okLocale2 = Locale.getDefault() + val okLocale3 = Locale.getDefault() + fun test() { + val okLocale4 = Locale.getDefault() + } + val okLocale5: Locale + init { + okLocale5 = Locale.getDefault() + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/MainActivity.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg + +import android.app.Activity +import android.util.Log +import java.text.SimpleDateFormat +import java.util.* + +class MainActivity : Activity() { + companion object { + val PROBLEMATIC_DESCRIPTION_DATE_FORMAT = SimpleDateFormat("MMM dd", Locale.getDefault()) + //same for the single parameter CTOR : SimpleDateFormat("MMM dd") + } + + @Suppress("PropertyName") + val SAFE_DESCRIPTION_DATE_FORMAT = SimpleDateFormat("MMM dd", Locale.getDefault()) + + override fun onResume() { + super.onResume() + val today = Calendar.getInstance().time + Log.d("AppLog", "problematic:" + PROBLEMATIC_DESCRIPTION_DATE_FORMAT.format(today)) + Log.d("AppLog", "safe:" + SAFE_DESCRIPTION_DATE_FORMAT.format(today)) + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/LocaleDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/ConstraintLayoutToolsEditorAttribute.md.html b/docs/checks/ConstraintLayoutToolsEditorAttribute.md.html new file mode 100644 index 00000000..f53d0059 --- /dev/null +++ b/docs/checks/ConstraintLayoutToolsEditorAttribute.md.html @@ -0,0 +1,152 @@ + +(#) Flags tools:layout_editor xml properties + +!!! WARNING: Flags tools:layout_editor xml properties + This is a warning. + +Id +: `ConstraintLayoutToolsEditorAttribute` +Summary +: Flags tools:layout_editor xml properties +Severity +: Warning +Category +: Correctness +Platform +: Android +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html) +Since +: 0.6.0 +Affects +: Resource files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/main/kotlin/com/vanniktech/lintrules/android/ConstraintLayoutToolsEditorAttributeDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/ConstraintLayoutToolsEditorAttributeDetectorTest.kt) + +The tools:layout_editor xml properties are only used for previewing and +won't be used in your APK hence they're unnecessary and just add +overhead. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +res/layout/layout.xml:3:Warning: Don't use tools:layout_editor_absoluteX +[ConstraintLayoutToolsEditorAttribute] + tools:layout_editor_absoluteX="4dp"/> + ----------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`res/layout/layout.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<TextView + xmlns:tools="http://schemas.android.com/tools" + tools:layout_editor_absoluteX="4dp"/> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/ConstraintLayoutToolsEditorAttributeDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `ConstraintLayoutToolsEditorAttributeDetector.toolsLayoutEditor`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-android:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-android:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.android) + +# libs.versions.toml +[versions] +lint-rules-android = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-android = { + module = "com.vanniktech:lint-rules-android", + version.ref = "lint-rules-android" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute + `tools:ignore="ConstraintLayoutToolsEditorAttribute"` on the + problematic XML element (or one of its enclosing elements). You may + also need to add the following namespace declaration on the root + element in the XML file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ConstraintLayoutToolsEditorAttribute" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ConstraintLayoutToolsEditorAttribute' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ConstraintLayoutToolsEditorAttribute ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ContentDescription.md.html b/docs/checks/ContentDescription.md.html index 23e2c999..015c158b 100644 --- a/docs/checks/ContentDescription.md.html +++ b/docs/checks/ContentDescription.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -38,8 +40,10 @@ Note that elements in application screens that are purely decorative and do not provide any content or enable a user action should not have -accessibility content descriptions. In this case, just suppress the lint -warning with a tools:ignore="ContentDescription" attribute. +accessibility content descriptions. In this case, set their descriptions +to `@null`. If your app's minSdkVersion is 16 or higher, you can instead +set these graphical elements' `android:importantForAccessibility` +attributes to `no`. Note that for text fields, you should not set both the `hint` and the `contentDescription` attributes since the hint will never be shown. Just @@ -54,47 +58,29 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/accessibility.xml:4:Warning: Missing `contentDescription` attribute on image [ContentDescription] - <ImageView android:id="@+id/android_logo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/android_button" android:focusable="false" android:clickable="false" android:layout_weight="1.0" /> --------- - - res/layout/accessibility.xml:5:Warning: Missing `contentDescription` attribute on image [ContentDescription] - <ImageButton android:importantForAccessibility="yes" android:id="@+id/android_logo2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/android_button" android:focusable="false" android:clickable="false" android:layout_weight="1.0" /> ----------- - - res/layout/accessibility.xml:9:Warning: Do not set both `contentDescription` and `hint`: the `contentDescription` will mask the `hint` [ContentDescription] - <EditText android:hint="@string/label" android:id="@+android:id/summary" android:contentDescription="@string/label" /> ------------------------------------------ - - res/layout/accessibility.xml:12:Warning: Empty `contentDescription` attribute on image [ContentDescription] - <ImageButton android:id="@+android:id/summary" android:contentDescription="TODO" /> --------------------------------- - - res/layout/accessibility.xml:13:Warning: Empty `contentDescription` attribute on image [ContentDescription] - <ImageButton android:id="@+id/summary2" android:contentDescription="" /> ----------------------------- - - res/layout/accessibility.xml:14:Warning: Empty `contentDescription` attribute on image [ContentDescription] - <ImageButton android:id="@+id/summary3" android:contentDescription="TODO" /> --------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/ContextCastToActivity.md.html b/docs/checks/ContextCastToActivity.md.html new file mode 100644 index 00000000..523d3bdd --- /dev/null +++ b/docs/checks/ContextCastToActivity.md.html @@ -0,0 +1,191 @@ + +(#) LocalContext should not be cast to Activity, use LocalActivity instead + +!!! ERROR: LocalContext should not be cast to Activity, use LocalActivity instead + This is an error. + +Id +: `ContextCastToActivity` +Summary +: LocalContext should not be cast to Activity, use LocalActivity instead +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: Jetpack Activity Compose +Identifier +: androidx.activity.compose +Feedback +: https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.7+ +Artifact +: [androidx.activity:activity-compose](androidx_activity_activity-compose.md.html) +Since +: 1.10.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/activity/activity-compose-lint/src/main/java/androidx/activity/compose/lint/LocalContextCastIssueDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/activity/activity-compose-lint/src/test/java/androidx/activity/compose/lint/LocalContextCastIssueDetectorTest.kt) +Copyright Year +: 2024 + +Casting Context to Activity is an error as Contexts are not always +Activities. Use LocalActivity instead. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/com/example/MyActivity.kt:11:Error: LocalContext should not be cast +to Activity, use LocalActivity instead [ContextCastToActivity] + val activity: Activity = LocalContext.current as Activity + -------------------------------- +src/com/example/MyActivity.kt:12:Error: LocalContext should not be cast +to Activity, use LocalActivity instead [ContextCastToActivity] + val activity2 = LocalContext.current as? Activity + --------------------------------- +src/com/example/MyActivity.kt:13:Error: LocalContext should not be cast +to Activity, use LocalActivity instead [ContextCastToActivity] + val activity3 = LocalContext.current as? MyActivity + ----------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/com/example/MyActivity.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package com.example + +import android.app.Activity +import androidx.compose.runtime.Composable +import androidx.compose.ui.platform.LocalContext + +class MyActivity: Activity() + +@Composable +fun Test() { + val activity: Activity = LocalContext.current as Activity + val activity2 = LocalContext.current as? Activity + val activity3 = LocalContext.current as? MyActivity +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/activity/activity-compose-lint/src/test/java/androidx/activity/compose/lint/LocalContextCastIssueDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `LocalContextCastIssueDetector.errors`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=612128. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.activity:activity-compose:1.11.0-rc01") + +// build.gradle +implementation 'androidx.activity:activity-compose:1.11.0-rc01' + +// build.gradle.kts with version catalogs: +implementation(libs.activity.compose) + +# libs.versions.toml +[versions] +activity-compose = "1.11.0-rc01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +activity-compose = { + module = "androidx.activity:activity-compose", + version.ref = "activity-compose" +} +``` + +1.11.0-rc01 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.activity:activity-compose](androidx_activity_activity-compose.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ContextCastToActivity") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ContextCastToActivity") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ContextCastToActivity + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ContextCastToActivity" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ContextCastToActivity' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ContextCastToActivity ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ConvertToWebp.md.html b/docs/checks/ConvertToWebp.md.html index 4f4cabaa..d4d027e2 100644 --- a/docs/checks/ConvertToWebp.md.html +++ b/docs/checks/ConvertToWebp.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 2.3.0 (March 2017) Affects : Kotlin and Java files, manifest files and resource files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/IconDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/IconDetectorTest.java) -Copyright Year -: 2011 The WebP format is typically more compact than PNG and JPEG. As of Android 4.2.1 it supports transparency and lossless conversion as well. diff --git a/docs/checks/CoreLibDesugaringV1.md.html b/docs/checks/CoreLibDesugaringV1.md.html new file mode 100644 index 00000000..36d97929 --- /dev/null +++ b/docs/checks/CoreLibDesugaringV1.md.html @@ -0,0 +1,119 @@ + +(#) Android 15 requires `desugar_jdk_libs` 2.+ + +!!! ERROR: Android 15 requires `desugar_jdk_libs` 2.+ + This is an error. + +Id +: `CoreLibDesugaringV1` +Summary +: Android 15 requires `desugar_jdk_libs` 2.+ +Severity +: Error +Category +: Correctness +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.10.0 (May 2025) +Affects +: Gradle build files and TOML files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GradleDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) + +Core library desugaring with `compileSdk` 35 or later (Android 15) +requires using version 2.+ of the core library desugaring libraries. The +code may compile successfully, but can crash at runtime. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +build.gradle.kts:9:Error: Core library desugaring runtime library +version 1.2.3 does not support compileSdk=35 or later; please upgrade to +version 2.1.4 [CoreLibDesugaringV1] + coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.2.3") // ERROR + ------------------------------------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`build.gradle.kts`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +android { + compileSdk = 35 + compileOptions { + isCoreLibraryDesugaringEnabled = true + } +} +dependencies { + coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.4") // OK + coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.2.3") // ERROR +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `GradleDetector.testCoreLibV1`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=192708. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection CoreLibDesugaringV1 + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="CoreLibDesugaringV1" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'CoreLibDesugaringV1' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore CoreLibDesugaringV1 ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/CoroutineCreationDuringComposition.md.html b/docs/checks/CoroutineCreationDuringComposition.md.html index 88e0a8bd..79349e41 100644 --- a/docs/checks/CoroutineCreationDuringComposition.md.html +++ b/docs/checks/CoroutineCreationDuringComposition.md.html @@ -20,6 +20,14 @@ : androidx.compose.runtime Feedback : https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.runtime:runtime-android](androidx_compose_runtime_runtime-android.md.html) +Since +: 1.5.0 Affects : Kotlin and Java files and test sources Editing @@ -47,171 +55,108 @@ src/androidx/compose/runtime/foo/test.kt:10:Error: Calls to async should happen inside a LaunchedEffect and not composition [CoroutineCreationDuringComposition] - CoroutineScope.async {} ----- - - src/androidx/compose/runtime/foo/test.kt:11:Error: Calls to launch should happen inside a LaunchedEffect and not composition [CoroutineCreationDuringComposition] - CoroutineScope.launch {} ------ - - src/androidx/compose/runtime/foo/test.kt:12:Error: Calls to launchIn should happen inside a LaunchedEffect and not composition [CoroutineCreationDuringComposition] - flowOf(Unit).launchIn(CoroutineScope) -------- - - src/androidx/compose/runtime/foo/test.kt:16:Error: Calls to async should happen inside a LaunchedEffect and not composition [CoroutineCreationDuringComposition] - CoroutineScope.async {} ----- - - src/androidx/compose/runtime/foo/test.kt:17:Error: Calls to launch should happen inside a LaunchedEffect and not composition [CoroutineCreationDuringComposition] - CoroutineScope.launch {} ------ - - src/androidx/compose/runtime/foo/test.kt:18:Error: Calls to launchIn should happen inside a LaunchedEffect and not composition [CoroutineCreationDuringComposition] - flowOf(Unit).launchIn(CoroutineScope) -------- - - src/androidx/compose/runtime/foo/test.kt:22:Error: Calls to async should happen inside a LaunchedEffect and not composition [CoroutineCreationDuringComposition] - CoroutineScope.async {} ----- - - src/androidx/compose/runtime/foo/test.kt:23:Error: Calls to launch should happen inside a LaunchedEffect and not composition [CoroutineCreationDuringComposition] - CoroutineScope.launch {} ------ - - src/androidx/compose/runtime/foo/test.kt:24:Error: Calls to launchIn should happen inside a LaunchedEffect and not composition [CoroutineCreationDuringComposition] - flowOf(Unit).launchIn(CoroutineScope) -------- - - src/androidx/compose/runtime/foo/test.kt:33:Error: Calls to async should happen inside a LaunchedEffect and not composition [CoroutineCreationDuringComposition] - CoroutineScope.async {} ----- - - src/androidx/compose/runtime/foo/test.kt:34:Error: Calls to launch should happen inside a LaunchedEffect and not composition [CoroutineCreationDuringComposition] - CoroutineScope.launch {} ------ - - src/androidx/compose/runtime/foo/test.kt:35:Error: Calls to launchIn should happen inside a LaunchedEffect and not composition [CoroutineCreationDuringComposition] - flowOf(Unit).launchIn(CoroutineScope) -------- - - src/androidx/compose/runtime/foo/test.kt:38:Error: Calls to async should happen inside a LaunchedEffect and not composition [CoroutineCreationDuringComposition] - CoroutineScope.async {} ----- - - src/androidx/compose/runtime/foo/test.kt:39:Error: Calls to launch should happen inside a LaunchedEffect and not composition [CoroutineCreationDuringComposition] - CoroutineScope.launch {} ------ - - src/androidx/compose/runtime/foo/test.kt:40:Error: Calls to launchIn should happen inside a LaunchedEffect and not composition [CoroutineCreationDuringComposition] - flowOf(Unit).launchIn(CoroutineScope) -------- - - src/androidx/compose/runtime/foo/test.kt:46:Error: Calls to async should happen inside a LaunchedEffect and not composition [CoroutineCreationDuringComposition] - CoroutineScope.async {} ----- - - src/androidx/compose/runtime/foo/test.kt:47:Error: Calls to launch should happen inside a LaunchedEffect and not composition [CoroutineCreationDuringComposition] - CoroutineScope.launch {} ------ - - src/androidx/compose/runtime/foo/test.kt:48:Error: Calls to launchIn should happen inside a LaunchedEffect and not composition [CoroutineCreationDuringComposition] - flowOf(Unit).launchIn(CoroutineScope) -------- - - src/androidx/compose/runtime/foo/test.kt:52:Error: Calls to async should happen inside a LaunchedEffect and not composition [CoroutineCreationDuringComposition] - CoroutineScope.async {} ----- - - src/androidx/compose/runtime/foo/test.kt:53:Error: Calls to launch should happen inside a LaunchedEffect and not composition [CoroutineCreationDuringComposition] - CoroutineScope.launch {} ------ - - src/androidx/compose/runtime/foo/test.kt:54:Error: Calls to launchIn should happen inside a LaunchedEffect and not composition [CoroutineCreationDuringComposition] - flowOf(Unit).launchIn(CoroutineScope) -------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -284,6 +229,44 @@ To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=612128. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.runtime:runtime-android:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.runtime:runtime-android:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.runtime.android) + +# libs.versions.toml +[versions] +runtime-android = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +runtime-android = { + module = "androidx.compose.runtime:runtime-android", + version.ref = "runtime-android" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.runtime:runtime-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.runtime:runtime-android](androidx_compose_runtime_runtime-android.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/CredManMissingDal.md.html b/docs/checks/CredManMissingDal.md.html new file mode 100644 index 00000000..0563b165 --- /dev/null +++ b/docs/checks/CredManMissingDal.md.html @@ -0,0 +1,118 @@ + +(#) Missing Digital Asset Link for Credential Manager + +!!! ERROR: Missing Digital Asset Link for Credential Manager + This is an error. + +Id +: `CredManMissingDal` +Summary +: Missing Digital Asset Link for Credential Manager +Severity +: Error +Category +: Correctness +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.7.0 (October 2024) +Affects +: Kotlin and Java files +Editing +: This check can *not* run live in the IDE editor +See +: https://developer.android.com/identity/sign-in/credential-manager#add-support-dal +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/CredentialManagerDigitalAssetLinkDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/CredentialManagerDigitalAssetLinkDetectorTest.kt) + +When using password sign-in through Credential Manager, an asset +statements string resource file that includes the `assetlinks.json` +files to load must be declared in the manifest using a `` +element. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +AndroidManifest.xml:3:Error: Missing tag for asset +statements for Credential Manager [CredManMissingDal] + <application> + ----------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`AndroidManifest.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<manifest package="com.example.app" xmlns:android="http://schemas.android.com/apk/res/android"> + <uses-sdk android:minSdkVersion="33" android:targetSdkVersion="34" /> + <application> + <activity android:name=".MainActivity" android:exported="true"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + </application> +</manifest> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/com/example/app/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package com.example.app + +import androidx.credentials.CreatePasswordRequest + +fun foo() { + val createPasswordRequest = CreatePasswordRequest("user", "pass") +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/CredentialManagerDigitalAssetLinkDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="CredManMissingDal" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'CredManMissingDal' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore CredManMissingDal ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/CredentialDependency.md.html b/docs/checks/CredentialDependency.md.html new file mode 100644 index 00000000..b14224c3 --- /dev/null +++ b/docs/checks/CredentialDependency.md.html @@ -0,0 +1,104 @@ + +(#) `credentials-play-services-auth` is Required + +!!! WARNING: `credentials-play-services-auth` is Required + This is a warning. + +Id +: `CredentialDependency` +Summary +: `credentials-play-services-auth` is Required +Severity +: Warning +Category +: Correctness +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.6.0 (August 2024) +Affects +: Manifest files +Editing +: This check runs on the fly in the IDE editor +See +: https://developer.android.com/jetpack/androidx/releases/credentials +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/CredentialManagerDependencyDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/CredentialManagerDependencyDetectorTest.kt) + +The dependency `androidx.credentials:credentials-play-services-auth` is +required for Android 13 and below to get support from Play services for +the Credential Manager API (`androidx.credentials:credentials`) to work. +For Android 14 and above, this is optional. Please check release notes +for the latest version. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`build.gradle`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~groovy linenumbers +dependencies { + implementation 'androidx.credentials:credentials:+' +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/CredentialManagerDependencyDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute + `tools:ignore="CredentialDependency"` on the problematic XML element + (or one of its enclosing elements). You may also need to add the + following namespace declaration on the root element in the XML file + if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="CredentialDependency" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'CredentialDependency' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore CredentialDependency ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/CredentialManagerMisuse.md.html b/docs/checks/CredentialManagerMisuse.md.html new file mode 100644 index 00000000..f74af78c --- /dev/null +++ b/docs/checks/CredentialManagerMisuse.md.html @@ -0,0 +1,149 @@ + +(#) Misuse of Credential Manager API + +!!! WARNING: Misuse of Credential Manager API + This is a warning. + +Id +: `CredentialManagerMisuse` +Summary +: Misuse of Credential Manager API +Severity +: Warning +Category +: Correctness +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.8.0 (January 2025) +Affects +: Kotlin and Java files +Editing +: This check can *not* run live in the IDE editor +See +: https://developer.android.com/identity/sign-in/credential-manager#handle-exceptions +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/CredentialManagerMisuseDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/CredentialManagerMisuseDetectorTest.kt) + +When calling `CredentialManager.getCredential` or +`CredentialManager.getCredentialAsync`, you should handle +`NoCredentialException` somewhere in your project. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/com/example/app/Foo.kt:26:Warning: Call to +CredentialManager.getCredential without use of NoCredentialException +[CredentialManagerMisuse] + credentialManager.getCredential(context, request) + ------------------------------------------------- +src/com/example/app/Foo.kt:27:Warning: Call to +CredentialManager.getCredential without use of NoCredentialException +[CredentialManagerMisuse] + credentialManager.getCredential(context, prepareGetCredentialResponse.pendingGetCredentialHandle!!) + --------------------------------------------------------------------------------------------------- +src/com/example/app/Foo.kt:28:Warning: Call to +CredentialManager.getCredential without use of NoCredentialException +[CredentialManagerMisuse] + credentialManager.getCredentialAsync(context, request, cancellationSignal, executor, callback) + ---------------------------------------------------------------------------------------------- +src/com/example/app/Foo.kt:29:Warning: Call to +CredentialManager.getCredential without use of NoCredentialException +[CredentialManagerMisuse] + credentialManager.getCredentialAsync(context, prepareGetCredentialResponse.pendingGetCredentialHandle!!, cancellationSignal, executor, callback) + ------------------------------------------------------------------------------------------------------------------------------------------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/com/example/app/Foo.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package com.example.app + +import android.content.Context +import android.os.Build +import android.os.CancellationSignal +import androidx.credentials.CredentialManager +import androidx.credentials.CredentialManagerCallback +import androidx.credentials.GetCredentialRequest +import androidx.credentials.GetCredentialResponse +import androidx.credentials.PrepareGetCredentialResponse +import androidx.credentials.PrepareGetCredentialResponse.PendingGetCredentialHandle +import androidx.credentials.exceptions.GetCredentialException +import androidx.credentials.exceptions.NoCredentialException +import java.util.concurrent.Executor + +class Foo { + suspend fun foo( + credentialManager: CredentialManager, + context: Context, + request: GetCredentialRequest, + cancellationSignal: CancellationSignal, + executor: Executor, + callback: CredentialManagerCallback) { + try { + val prepareGetCredentialResponse = credentialManager.prepareGetCredential(request) + credentialManager.getCredential(context, request) + credentialManager.getCredential(context, prepareGetCredentialResponse.pendingGetCredentialHandle!!) + credentialManager.getCredentialAsync(context, request, cancellationSignal, executor, callback) + credentialManager.getCredentialAsync(context, prepareGetCredentialResponse.pendingGetCredentialHandle!!, cancellationSignal, executor, callback) + } catch (e: GetCredentialException) { + bar(e) + } + } + + fun bar(e: GetCredentialException) { + TODO() + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/CredentialManagerMisuseDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="CredentialManagerMisuse" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'CredentialManagerMisuse' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore CredentialManagerMisuse ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/CredentialManagerSignInWithGoogle.md.html b/docs/checks/CredentialManagerSignInWithGoogle.md.html new file mode 100644 index 00000000..3fd01180 --- /dev/null +++ b/docs/checks/CredentialManagerSignInWithGoogle.md.html @@ -0,0 +1,121 @@ + +(#) Misuse of Sign in with Google API + +!!! WARNING: Misuse of Sign in with Google API + This is a warning. + +Id +: `CredentialManagerSignInWithGoogle` +Summary +: Misuse of Sign in with Google API +Severity +: Warning +Category +: Correctness +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.7.0 (October 2024) +Affects +: Kotlin and Java files +Editing +: This check can *not* run live in the IDE editor +See +: https://developer.android.com/identity/sign-in/credential-manager-siwg#create-sign +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/CredentialManagerSignInWithGoogleDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/CredentialManagerSignInWithGoogleDetectorTest.kt) + +When using `:googleid` classes like `GetGoogleIdOption` and +`GetSignInWithGoogleOption`, you must handle the response using +`GoogleIdTokenCredential.createFrom`. + +This check reports all uses of these `:googleid` classes if there are no +references to `GoogleIdTokenCredential[.Companion].createFrom`. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/com/example/app/Foo.kt:9:Warning: Use of :googleid classes without +use of GoogleIdTokenCredential.createFrom +[CredentialManagerSignInWithGoogle] + val googleIdOption = GetGoogleIdOption.Builder().build() + ----------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/com/example/app/Foo.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package com.example.app + +import androidx.credentials.GetCredentialResponse +import androidx.credentials.PublicKeyCredential +import com.google.android.libraries.identity.googleid.GetGoogleIdOption + +class Foo { + fun foo() { + val googleIdOption = GetGoogleIdOption.Builder().build() + } + + fun handleSignIn(result: GetCredentialResponse) { + when (val credential = result.credential) { + is PublicKeyCredential -> { + bar() + } + else -> {} + } + } + + fun bar() { TODO() } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/CredentialManagerSignInWithGoogleDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="CredentialManagerSignInWithGoogle" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'CredentialManagerSignInWithGoogle' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore CredentialManagerSignInWithGoogle ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/CustomPermissionTypo.md.html b/docs/checks/CustomPermissionTypo.md.html index d5636257..a9f1dff2 100644 --- a/docs/checks/CustomPermissionTypo.md.html +++ b/docs/checks/CustomPermissionTypo.md.html @@ -18,40 +18,39 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.4.0 (January 2023) Affects : Manifest files Editing : This check runs on the fly in the IDE editor +See +: https://goo.gle/CustomPermissionTypo Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/PermissionErrorDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/PermissionErrorDetectorTest.kt) -Copyright Year -: 2022 This check looks for required permissions that *look* like custom permissions defined in the same manifest, but aren't, and may be typos. Please double check the permission value you have supplied. +!!! Tip + This lint check has an associated quickfix available in the IDE. + (##) Example Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text AndroidManifest.xml:9:Warning: Did you mean my.custom.permission.FOOBAR? [CustomPermissionTypo] - <service android:permission="my.custom.permission.FOOBOB" /> ------------------------------------------------------------ - - AndroidManifest.xml:11:Warning: Did you mean my.custom.permission.BAZQUXX? [CustomPermissionTypo] - <activity android:permission="my.custom.permission.BAZQXX" /> ------------------------------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/CustomSplashScreen.md.html b/docs/checks/CustomSplashScreen.md.html index 85d67831..ec284d4d 100644 --- a/docs/checks/CustomSplashScreen.md.html +++ b/docs/checks/CustomSplashScreen.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.0.0 (July 2021) Affects : Kotlin and Java files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/SplashScreenDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/SplashScreenDetectorTest.kt) -Copyright Year -: 2021 Starting in Android 12 (API 31+), the application's Launch Screen is provided by the system and the application should not create its own, @@ -43,11 +43,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/SplashActivity.kt:6:Warning: The application should not provide its own launch screen [CustomSplashScreen] - class SplashActivity : AppCompatActivity() { -------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/CustomViewStyleable.md.html b/docs/checks/CustomViewStyleable.md.html index bea0544e..4d1fc2b5 100644 --- a/docs/checks/CustomViewStyleable.md.html +++ b/docs/checks/CustomViewStyleable.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 0.1.0 (September 2014) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/CustomViewDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/CustomViewDetectorTest.java) -Copyright Year -: 2014 The convention for custom views is to use a `declare-styleable` whose name matches the custom view class name. The IDE relies on this @@ -44,58 +44,40 @@ (CustomView1) and the declare-styleable (MyDeclareStyleable) should have the same name (various editor features rely on this convention) [CustomViewStyleable] - context.obtainStyledAttributes(R.styleable.MyDeclareStyleable); ------------------------------ - - src/test/pkg/CustomView1.java:19:Warning: By convention, the custom view (CustomView1) and the declare-styleable (MyDeclareStyleable) should have the same name (various editor features rely on this convention) [CustomViewStyleable] - context.obtainStyledAttributes(defStyleRes, R.styleable.MyDeclareStyleable); ------------------------------ - - src/test/pkg/CustomView1.java:20:Warning: By convention, the custom view (CustomView1) and the declare-styleable (MyDeclareStyleable) should have the same name (various editor features rely on this convention) [CustomViewStyleable] - context.obtainStyledAttributes(attrs, R.styleable.MyDeclareStyleable); ------------------------------ - - src/test/pkg/CustomView1.java:21:Warning: By convention, the custom view (CustomView1) and the declare-styleable (MyDeclareStyleable) should have the same name (various editor features rely on this convention) [CustomViewStyleable] - context.obtainStyledAttributes(attrs, R.styleable.MyDeclareStyleable, defStyleAttr, ------------------------------ - - src/test/pkg/CustomView1.java:46:Warning: By convention, the declare-styleable (MyLayout) for a layout parameter class (MyLayoutParams) is expected to be the surrounding class (MyLayout) plus "_Layout", e.g. MyLayout_Layout. (Various editor features rely on this convention.) [CustomViewStyleable] - context.obtainStyledAttributes(R.styleable.MyLayout); // Wrong -------------------- - - src/test/pkg/CustomView1.java:47:Warning: By convention, the declare-styleable (MyDeclareStyleable) for a layout parameter class (MyLayoutParams) is expected to be the surrounding class (MyLayout) plus "_Layout", e.g. MyLayout_Layout. (Various editor features rely on this convention.) [CustomViewStyleable] - context.obtainStyledAttributes(R.styleable.MyDeclareStyleable); // Wrong ------------------------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/CustomX509TrustManager.md.html b/docs/checks/CustomX509TrustManager.md.html index e608f541..805461b5 100644 --- a/docs/checks/CustomX509TrustManager.md.html +++ b/docs/checks/CustomX509TrustManager.md.html @@ -18,16 +18,18 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.0.0 (July 2021) Affects : Kotlin and Java files and library bytecode Editing : This check runs on the fly in the IDE editor +See +: https://goo.gle/CustomX509TrustManager Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/X509TrustManagerDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/X509TrustManagerDetectorTest.kt) -Copyright Year -: 2015 This check looks for custom `X509TrustManager` implementations. @@ -40,11 +42,8 @@ likely to disable certificate validation altogether, and is non-trivial to implement correctly without calling Android's default implementation. [CustomX509TrustManager] - TrustManager[] trustAllCerts = new TrustManager[]{ new X509TrustManager() { ---------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/CutPasteId.md.html b/docs/checks/CutPasteId.md.html index a3363d4a..cc0547a8 100644 --- a/docs/checks/CutPasteId.md.html +++ b/docs/checks/CutPasteId.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files Editing @@ -41,300 +43,40 @@ Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -src/test/pkg/PasteError.java:22:Warning: The id R.id.duplicated has +src/test/pkg/PasteError.java:10:Warning: The id R.id.previous has already been looked up in this method; possible cut & paste error? [CutPasteId] - - View view2 = findViewById(R.id.duplicated); - ----------------------------- - - -src/test/pkg/PasteError.java:78:Warning: The id R.id.duplicated has -already been looked up in this method; possible cut & paste error? -[CutPasteId] - - view2 = findViewById(R.id.duplicated); - ----------------------------- - - -src/test/pkg/PasteError.java:85:Warning: The id R.id.duplicated has -already been looked up in this method; possible cut & paste error? -[CutPasteId] - - view2 = findViewById(R.id.duplicated); - ----------------------------- - - -src/test/pkg/PasteError.java:93:Warning: The id R.id.duplicated has -already been looked up in this method; possible cut & paste error? -[CutPasteId] - - view2 = findViewById(R.id.duplicated); - ----------------------------- - - -src/test/pkg/PasteError.java:102:Warning: The id R.id.duplicated has -already been looked up in this method; possible cut & paste error? -[CutPasteId] - - view2 = findViewById(R.id.duplicated); - ----------------------------- - - -src/test/pkg/PasteError.java:148:Warning: The id R.id.duplicated has -already been looked up in this method; possible cut & paste error? -[CutPasteId] - - TextView sectionTitleView = (TextView) root.findViewById(R.id.duplicated); - ---------------------------------- - - -src/test/pkg/PasteError.java:162:Warning: The id R.id.duplicated has -already been looked up in this method; possible cut & paste error? -[CutPasteId] - - TextView sectionTitleView = (TextView) root.findViewById(R.id.duplicated); - ---------------------------------- - - -src/test/pkg/PasteError.java:171:Warning: The id R.id.duplicated has -already been looked up in this method; possible cut & paste error? -[CutPasteId] - - view2 = findViewById(R.id.duplicated); - ----------------------------- - - -src/test/pkg/PasteError.java:182:Warning: The id R.id.duplicated has -already been looked up in this method; possible cut & paste error? -[CutPasteId] - - view2 = requireViewById(R.id.duplicated); - -------------------------------- - - + next = (Button) findViewById(R.id.previous); // TYPO, meant R.id.next + --------------------------- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `src/test/pkg/PasteError.java`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers package test.pkg; - -import android.annotation.SuppressLint; import android.app.Activity; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; import android.widget.Button; -import android.widget.TextView; -@SuppressWarnings({"ConstantConditions", "UnnecessaryLocalVariable", "ConstantIfStatement", - "StatementWithEmptyBody", "FieldCanBeLocal", "unused", "UnusedAssignment"}) public class PasteError extends Activity { - protected void ok() { - Button button1 = (Button) findViewById(R.id.textView1); - mView2 = findViewById(R.id.textView2); - View view3 = findViewById(R.id.activity_main); - } - - protected void error() { - View view1 = findViewById(R.id.duplicated); - View view2 = findViewById(R.id.duplicated); - View view3 = findViewById(R.id.ok); - } - - protected void ok2() { - View view1; - if (true) { - view1 = findViewById(R.id.ok); - } else { - view1 = findViewById(R.id.ok); - } - } - - @SuppressLint("CutPasteId") - protected void suppressed() { - View view1 = findViewById(R.id.duplicated); - View view2 = findViewById(R.id.duplicated); - } - - private void ok3() { - if (view == null || view.findViewById(R.id.city_name) == null) { - view = mInflater.inflate(R.layout.city_list_item, parent, false); - } - TextView name = (TextView) view.findViewById(R.id.city_name); - } - - private void ok4() { - mPrevAlbumWrapper = mPrevTrackLayout.findViewById(R.id.album_wrapper); - mNextAlbumWrapper = mNextTrackLayout.findViewById(R.id.album_wrapper); - } - - public View getView(int position, View convertView, ViewGroup parent) { - View listItem = convertView; - if (getItemViewType(position) == VIEW_TYPE_HEADER) { - TextView header = (TextView) listItem.findViewById(R.id.name); - } else if (getItemViewType(position) == VIEW_TYPE_BOOLEAN) { - TextView filterName = (TextView) listItem.findViewById(R.id.name); - } else { - TextView filterName = (TextView) listItem.findViewById(R.id.name); - } - return null; - } - - protected void ok_branch_1() { - if (true) { - view1 = findViewById(R.id.ok); - } else { - view2 = findViewById(R.id.ok); - } - } - - protected void error_branch_1() { - if (true) { - view1 = findViewById(R.id.duplicated); - } - if (true) { - view2 = findViewById(R.id.duplicated); - } - } - - protected void error_branch_2() { - view1 = findViewById(R.id.duplicated); - if (true) { - view2 = findViewById(R.id.duplicated); - } - } - - protected void error_branch_3() { - view1 = findViewById(R.id.duplicated); - if (true) { - } else { - view2 = findViewById(R.id.duplicated); - } - } - - protected void error_branch_4() { - view1 = findViewById(R.id.duplicated); - if (true) { - } else { - if (true) { - view2 = findViewById(R.id.duplicated); - } - } - } - - protected void ok_branch_2() { - if (true) { - view1 = findViewById(R.id.ok); - } else { - if (true) { - view2 = findViewById(R.id.ok); - } - } - } - - protected void ok_branch3() { - if (true) { - view1 = findViewById(R.id.ok); - return; - } - if (true) { - view2 = findViewById(R.id.ok); - } - } - - public static void ok_switch(View root, int position) { - // mutually exclusive branches - switch (position) { - case 0: { - TextView titleView = (TextView) root.findViewById(R.id.ok); - } - break; - default: { - TextView sectionTitleView = (TextView) root.findViewById(R.id.ok); - } - break; - } - } - - public static void error_switch_fallthrough(View root, int position) { - switch (position) { - case 0: { - TextView titleView = (TextView) root.findViewById(R.id.duplicated); - // fallthrough! - } - default: { - TextView sectionTitleView = (TextView) root.findViewById(R.id.duplicated); - } - break; - } - } - - public static void warning_switch_to_outer(View root, int position) { - switch (position) { - case 0: - { - TextView titleView = (TextView) root.findViewById(R.id.duplicated); - } - break; - } - TextView sectionTitleView = (TextView) root.findViewById(R.id.duplicated); - } - - public void while_loop_error(View root, int position) { - while (position-- > 0) { // here we can flow back - if (true) { - view1 = findViewById(R.id.duplicated); - } else { - if (true) { - view2 = findViewById(R.id.duplicated); - } - } - } - } - - protected void require_by_id_error_branch_1() { - if (true) { - view1 = requireViewById(R.id.duplicated); - } - if (true) { - view2 = requireViewById(R.id.duplicated); - } - } - - public final T requireViewById(int id) { - throw new RuntimeException("Stub!"); - } - - private View view1; - private View mView2; - private View view; - private View view2; - private LayoutInflater mInflater; - private Object mPrevAlbumWrapper; - private Object mNextAlbumWrapper; - private Activity mPrevTrackLayout; - private Activity mNextTrackLayout; - private android.view.ViewGroup parent; - private static final int VIEW_TYPE_HEADER = 1; - private static final int VIEW_TYPE_BOOLEAN = 2; - private int getItemViewType(int position) { - return VIEW_TYPE_BOOLEAN; + private Button next; + private Button previous; + protected void onCreate() { + previous = (Button) findViewById(R.id.previous); + next = (Button) findViewById(R.id.previous); // TYPO, meant R.id.next } } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`test.pkg`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text linenumbers +@id/next +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/CutPasteDetectorTest.java) for the unit tests for this check to see additional scenarios. -The above example was automatically extracted from the first unit test -found for this lint check, `CutPasteDetector.test`. -To report a problem with this extracted sample, visit -https://issuetracker.google.com/issues/new?component=192708. - (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/DalvikOverride.md.html b/docs/checks/DalvikOverride.md.html index 89b894ab..035014cd 100644 --- a/docs/checks/DalvikOverride.md.html +++ b/docs/checks/DalvikOverride.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Class files Editing @@ -50,14 +52,44 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/pkg2/Class2.java:7:Error: This package private method may be unintentionally overriding method in pkg1.Class1 [DalvikOverride] - void method() { // Flag this as an accidental override ------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Here are the relevant source files: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/pkg1/Class1.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package pkg1; + +public class Class1 { + void method() { + } + + void method2(int foo) { + } + + void method3() { + } + + void method4() { + } + + void method5() { + } -Here is the source file referenced above: + void method6() { + } + + void method7() { + } + + public static class Class4 extends Class1 { + void method() { // Not an error: same package + } + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `src/pkg2/Class2.java`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers diff --git a/docs/checks/DataBindingWithoutKapt.md.html b/docs/checks/DataBindingWithoutKapt.md.html index c183baf9..452e0dec 100644 --- a/docs/checks/DataBindingWithoutKapt.md.html +++ b/docs/checks/DataBindingWithoutKapt.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.5.0 (August 2019) Affects : Gradle build files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GradleDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) -Copyright Year -: 2014 Apps that use Kotlin and data binding should also apply the kotlin-kapt plugin. @@ -41,11 +41,8 @@ build.gradle:6:Warning: If you plan to use data binding in a Kotlin project, you should apply the kotlin-kapt plugin. [DataBindingWithoutKapt] - enabled true ------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/DataExtractionRules.md.html b/docs/checks/DataExtractionRules.md.html index 1bb82c8e..0fa0ab95 100644 --- a/docs/checks/DataExtractionRules.md.html +++ b/docs/checks/DataExtractionRules.md.html @@ -18,18 +18,20 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.1.0 (January 2022) Affects : Manifest files Editing : This check runs on the fly in the IDE editor See : https://developer.android.com/about/versions/12/backup-restore#xml-changes +See +: https://goo.gle/DataExtractionRules Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ManifestDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ManifestDetectorTest.kt) -Copyright Year -: 2011 Before Android 12, the attributes `android:allowBackup` and `android:fullBackupContent` were used to configure all forms of backup, @@ -54,14 +56,11 @@ AndroidManifest.xml:11:Warning: The attribute android:allowBackup is deprecated from Android 12 and the default allows backup [DataExtractionRules] - android:allowBackup="true" > ---- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `AndroidManifest.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -81,6 +80,40 @@ </manifest> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/values/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<!-- Copyright (C) 2007 The Android Open Source Project + + 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. +--> + +<resources> + <!-- Home --> + <string name="home_title">Home Sample</string> + <string name="show_all_apps">All</string> + + <!-- Home Menus --> + <string name="menu_wallpaper">Wallpaper</string> + <string name="menu_search">Search</string> + <string name="menu_settings">Settings</string> + <string name="sample" translatable="false">Ignore Me</string> + + <!-- Wallpaper --> + <string name="wallpaper_instructions">Tap picture to set portrait wallpaper</string> +</resources> + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ManifestDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/DeepLinkInActivityDestination.md.html b/docs/checks/DeepLinkInActivityDestination.md.html index 52a7158d..dd797ed4 100644 --- a/docs/checks/DeepLinkInActivityDestination.md.html +++ b/docs/checks/DeepLinkInActivityDestination.md.html @@ -20,6 +20,14 @@ : androidx.navigation.runtime Feedback : https://issuetracker.google.com/issues/new?component=409828 +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.7+ +Artifact +: [androidx.navigation:navigation-runtime](androidx_navigation_navigation-runtime.md.html) +Since +: 2.5.0 Affects : Resource files Editing @@ -31,11 +39,11 @@ Copyright Year : 2022 -Attaching a to an destination will never give +Attaching a to an destination will never give the right behavior when using an implicit deep link on another app's task (where the system back should immediately take the user back to the app that triggered -the deep link). Instead, attach the deep link directly to +the deep link). Instead, attach the deep link directly to the second activity (either by manually writing the appropriate or by adding the to the start destination of a nav host in that second activity). @@ -48,11 +56,8 @@ destination. Attach the deeplink directly to the second activity or the start destination of a nav host in the second activity instead. [DeepLinkInActivityDestination] - <deepLink app:uri="www.example.com" /> -------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -89,6 +94,40 @@ To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=409828. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.navigation:navigation-runtime:2.9.0-rc01") + +// build.gradle +implementation 'androidx.navigation:navigation-runtime:2.9.0-rc01' + +// build.gradle.kts with version catalogs: +implementation(libs.navigation.runtime) + +# libs.versions.toml +[versions] +navigation-runtime = "2.9.0-rc01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +navigation-runtime = { + module = "androidx.navigation:navigation-runtime", + version.ref = "navigation-runtime" +} +``` + +2.9.0-rc01 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.navigation:navigation-runtime](androidx_navigation_navigation-runtime.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/DefaultCleartextTraffic.md.html b/docs/checks/DefaultCleartextTraffic.md.html new file mode 100644 index 00000000..87c7c87b --- /dev/null +++ b/docs/checks/DefaultCleartextTraffic.md.html @@ -0,0 +1,168 @@ + +(#) Application by default permits cleartext traffic + +!!! WARNING: Application by default permits cleartext traffic + This is a warning. + +Id +: `DefaultCleartextTraffic` +Summary +: Application by default permits cleartext traffic +Severity +: Warning +Category +: Security +Platform +: Android +Vendor +: Google - Android 3P Vulnerability Research +Contact +: https://github.com/google/android-security-lints +Feedback +: https://github.com/google/android-security-lints/issues +Min +: Lint 4.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.android.security.lint:lint](com_android_security_lint_lint.md.html) +Since +: 1.0.1 +Affects +: Manifest files +Editing +: This check runs on the fly in the IDE editor +See +: https://goo.gle/DefaultCleartextTraffic +Implementation +: [Source Code](https://github.com/google/android-security-lints/tree/main/checks/src/main/java/com/example/lint/checks/MissingNetworkSecurityConfigDetector.kt) +Tests +: [Source Code](https://github.com/google/android-security-lints/tree/main/checks/src/test/java/com/example/lint/checks/MissingNetworkSecurityConfigDetectorTest.kt) +Copyright Year +: 2023 + +Apps targeting SDK versions earlier than 28 trust cleartext traffic by +default. The application must explicitly opt out of this in order to +only use secure connections. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +AndroidManifest.xml:3:Warning: On SDK versions below 28, the application +by default trusts cleartext traffic. Add a Network Security Config file +to opt out of these insecure connections. [DefaultCleartextTraffic] +<application> + ----------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`AndroidManifest.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<manifest xmlns:android='http://schemas.android.com/apk/res/android' package='test.pkg'> +<uses-sdk android:targetSdkVersion='27'/> +<application> + <activity android:name='com.example.MainActivity'></activity> +</application> +</manifest> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/google/android-security-lints/tree/main/checks/src/test/java/com/example/lint/checks/MissingNetworkSecurityConfigDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MissingNetworkSecurityConfigDetector.testWhenNoNetworkSecurityConfig_defaultCleartextTrafficSdkLevel_showsWarning`. +To report a problem with this extracted sample, visit +https://github.com/google/android-security-lints/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.android.security.lint:lint:1.0.3") + +// build.gradle +lintChecks 'com.android.security.lint:lint:1.0.3' + +// build.gradle.kts with version catalogs: +lintChecks(libs.com.android.security.lint.lint) + +# libs.versions.toml +[versions] +com-android-security-lint-lint = "1.0.3" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +com-android-security-lint-lint = { + module = "com.android.security.lint:lint", + version.ref = "com-android-security-lint-lint" +} +``` + +1.0.3 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.android.security.lint:lint](com_android_security_lint_lint.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute + `tools:ignore="DefaultCleartextTraffic"` on the problematic XML + element (or one of its enclosing elements). You may also need to add + the following namespace declaration on the root element in the XML + file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <manifest xmlns:tools="http://schemas.android.com/tools"> + ... + <application tools:ignore="DefaultCleartextTraffic" .../> + ... + </manifest> + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="DefaultCleartextTraffic" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'DefaultCleartextTraffic' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore DefaultCleartextTraffic ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/DefaultEncoding.md.html b/docs/checks/DefaultEncoding.md.html index 67b97b1e..aef44ccd 100644 --- a/docs/checks/DefaultEncoding.md.html +++ b/docs/checks/DefaultEncoding.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.3.0 (September 2022) Affects : Kotlin and Java files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/DefaultEncodingDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/DefaultEncodingDetectorTest.kt) -Copyright Year -: 2021 Some APIs will implicitly use the default system character encoding instead of UTF-8 when converting to or from bytes, such as when creating @@ -45,9 +45,12 @@ Note that on Android, the default file encoding is always UTF-8 (see https://developer.android.com/reference/java/nio/charset/Charset#defaultCharset() - for more), so this lint check deliberately does not flag any problems -in Android code, since it is always safe to rely on the default -character encoding there. +for more), so this lint check deliberately does not flag any problems in +Android code, since it is always safe to rely on the default character +encoding there. + +!!! Tip + This lint check has an associated quickfix available in the IDE. (##) Example @@ -56,74 +59,50 @@ src/test/pkg/Test.java:14:Error: This file will be written with the default system encoding instead of a specific charset which is usually a mistake; add StandardCharsets.UTF_8? [DefaultEncoding] - new FileWriter("/path"); // ERROR 1 ----------------------- - - src/test/pkg/Test.java:15:Error: This file will be written with the default system encoding instead of a specific charset which is usually a mistake; add charset argument, FileWriter(..., UTF_8)? [DefaultEncoding] - new FileWriter(file); // ERROR 2 -------------------- - - src/test/pkg/Test.java:16:Error: This file will be written with the default system encoding instead of a specific charset which is usually a mistake; add charset argument, FileWriter(..., UTF_8)? [DefaultEncoding] - new FileWriter(file, true); // ERROR 3 -------------------------- - - src/test/pkg/Test.java:17:Error: This file will be written with the default system encoding instead of a specific charset which is usually a mistake; add charset argument, FileWriter(..., UTF_8)? [DefaultEncoding] - new PrintWriter(new BufferedWriter(new FileWriter(file))); // ERROR 4 -------------------- - - src/test/pkg/Test.java:24:Error: This PrintWriter will use the default system encoding instead of a specific charset which is usually a mistake; add charset argument, PrintWriter(..., UTF_8)? [DefaultEncoding] - new PrintWriter(System.out, true); // ERROR 5 --------------------------------- - - src/test/pkg/Test.java:25:Error: This PrintWriter will use the default system encoding instead of a specific charset which is usually a mistake; add charset argument, PrintWriter(..., UTF_8)? [DefaultEncoding] - new PrintWriter("/path"); // ERROR 6 ------------------------ - - src/test/pkg/Test.java:26:Error: This PrintWriter will use the default system encoding instead of a specific charset which is usually a mistake; add charset argument, PrintWriter(..., UTF_8)? [DefaultEncoding] - new PrintWriter(file); // ERROR 7 --------------------- - - src/test/pkg/Test.java:36:Error: This string will be interpreted with the default system encoding instead of a specific charset which is usually a mistake; add charset argument, String(..., UTF_8)? [DefaultEncoding] - new String(bytes); // ERROR 8 ----------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/DefaultLayoutAttribute.md.html b/docs/checks/DefaultLayoutAttribute.md.html new file mode 100644 index 00000000..4631f903 --- /dev/null +++ b/docs/checks/DefaultLayoutAttribute.md.html @@ -0,0 +1,153 @@ + +(#) Flags default layout values + +!!! WARNING: Flags default layout values + This is a warning. + +Id +: `DefaultLayoutAttribute` +Summary +: Flags default layout values +Severity +: Warning +Category +: Correctness +Platform +: Android +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html) +Since +: 0.6.0 +Affects +: Resource files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/main/kotlin/com/vanniktech/lintrules/android/DefaultLayoutAttributeDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/DefaultLayoutAttributeDetectorTest.kt) + +Flags default layout values that are not needed. One for instance is the +textStyle="normal" that can be just removed. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +res/layout/ids.xml:5:Warning: This is the default and hence you don't +need to specify it [DefaultLayoutAttribute] + android:textStyle="normal"/> + ------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`res/layout/ids.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<TextView + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:textStyle="normal"/> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/DefaultLayoutAttributeDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `DefaultLayoutAttributeDetector.textStyleNormal`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-android:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-android:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.android) + +# libs.versions.toml +[versions] +lint-rules-android = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-android = { + module = "com.vanniktech:lint-rules-android", + version.ref = "lint-rules-android" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute + `tools:ignore="DefaultLayoutAttribute"` on the problematic XML + element (or one of its enclosing elements). You may also need to add + the following namespace declaration on the root element in the XML + file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="DefaultLayoutAttribute" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'DefaultLayoutAttribute' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore DefaultLayoutAttribute ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/DefaultLocale.md.html b/docs/checks/DefaultLocale.md.html index ce94e8d3..4420b36b 100644 --- a/docs/checks/DefaultLocale.md.html +++ b/docs/checks/DefaultLocale.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files Editing @@ -39,7 +41,7 @@ locale, the uppercase replacement for `i` is **not** `I`. If you want the methods to just perform ASCII replacement, for example -to convert an enum name, call `String#toUpperCase(Locale.US)` instead. +to convert an enum name, call `String#toUpperCase(Locale.ROOT)` instead. If you really want to use the current locale, call `String#toUpperCase(Locale.getDefault())` instead. @@ -54,76 +56,49 @@ locale is a common source of bugs: Use toUpperCase(Locale) instead. For strings meant to be internal use Locale.ROOT, otherwise Locale.getDefault(). [DefaultLocale] - System.out.println("WRONG".toUpperCase()); ----------- - - src/test/pkg/LocaleTest.java:16:Warning: Implicitly using the default locale is a common source of bugs: Use toLowerCase(Locale) instead. For strings meant to be internal use Locale.ROOT, otherwise Locale.getDefault(). [DefaultLocale] - System.out.println("WRONG".toLowerCase()); ----------- - - src/test/pkg/LocaleTest.java:20:Warning: Implicitly using the default locale is a common source of bugs: Use String.format(Locale, ...) instead [DefaultLocale] - String.format("WRONG: %f", 1.0f); // Implies locale -------------------------------- - - src/test/pkg/LocaleTest.java:21:Warning: Implicitly using the default locale is a common source of bugs: Use String.format(Locale, ...) instead [DefaultLocale] - String.format("WRONG: %1$f", 1.0f); ---------------------------------- - - src/test/pkg/LocaleTest.java:22:Warning: Implicitly using the default locale is a common source of bugs: Use String.format(Locale, ...) instead [DefaultLocale] - String.format("WRONG: %e", 1.0f); -------------------------------- - - src/test/pkg/LocaleTest.java:23:Warning: Implicitly using the default locale is a common source of bugs: Use String.format(Locale, ...) instead [DefaultLocale] - String.format("WRONG: %d", 1.0f); -------------------------------- - - src/test/pkg/LocaleTest.java:24:Warning: Implicitly using the default locale is a common source of bugs: Use String.format(Locale, ...) instead [DefaultLocale] - String.format("WRONG: %g", 1.0f); -------------------------------- - - src/test/pkg/LocaleTest.java:25:Warning: Implicitly using the default locale is a common source of bugs: Use String.format(Locale, ...) instead [DefaultLocale] - String.format("WRONG: %g", 1.0f); -------------------------------- - - src/test/pkg/LocaleTest.java:26:Warning: Implicitly using the default locale is a common source of bugs: Use String.format(Locale, ...) instead [DefaultLocale] - String.format("WRONG: %1$tm %1$te,%1$tY", ^ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/DefaultTrustedUserCerts.md.html b/docs/checks/DefaultTrustedUserCerts.md.html new file mode 100644 index 00000000..ab0551b7 --- /dev/null +++ b/docs/checks/DefaultTrustedUserCerts.md.html @@ -0,0 +1,170 @@ + +(#) Application by default trusts user-added CA certificates + +!!! WARNING: Application by default trusts user-added CA certificates + This is a warning. + +Id +: `DefaultTrustedUserCerts` +Summary +: Application by default trusts user-added CA certificates +Severity +: Warning +Category +: Security +Platform +: Android +Vendor +: Google - Android 3P Vulnerability Research +Contact +: https://github.com/google/android-security-lints +Feedback +: https://github.com/google/android-security-lints/issues +Min +: Lint 4.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.android.security.lint:lint](com_android_security_lint_lint.md.html) +Since +: 1.0.1 +Affects +: Manifest files +Editing +: This check runs on the fly in the IDE editor +See +: https://goo.gle/DefaultTrustedUserCerts +Implementation +: [Source Code](https://github.com/google/android-security-lints/tree/main/checks/src/main/java/com/example/lint/checks/MissingNetworkSecurityConfigDetector.kt) +Tests +: [Source Code](https://github.com/google/android-security-lints/tree/main/checks/src/test/java/com/example/lint/checks/MissingNetworkSecurityConfigDetectorTest.kt) +Copyright Year +: 2023 + +Apps targeting SDK versions earlier than 24 trust user-added CA +certificates by default. In practice, it is better to limit the set of +trusted CAs so only trusted CAs are used for an app's secure +connections. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +AndroidManifest.xml:3:Warning: On SDK versions below 24, the application +by default trusts user-added CA certificates. Add a Network Security +Config file to opt out of this insecure behavior. +[DefaultTrustedUserCerts] +<application> + ----------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`AndroidManifest.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<manifest xmlns:android='http://schemas.android.com/apk/res/android' package='test.pkg'> +<uses-sdk android:targetSdkVersion='23'/> +<application> + <activity android:name='com.example.MainActivity'></activity> +</application> +</manifest> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/google/android-security-lints/tree/main/checks/src/test/java/com/example/lint/checks/MissingNetworkSecurityConfigDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MissingNetworkSecurityConfigDetector.testWhenNoNetworkSecurityConfig_defaultUserCerts_showsWarning`. +To report a problem with this extracted sample, visit +https://github.com/google/android-security-lints/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.android.security.lint:lint:1.0.3") + +// build.gradle +lintChecks 'com.android.security.lint:lint:1.0.3' + +// build.gradle.kts with version catalogs: +lintChecks(libs.com.android.security.lint.lint) + +# libs.versions.toml +[versions] +com-android-security-lint-lint = "1.0.3" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +com-android-security-lint-lint = { + module = "com.android.security.lint:lint", + version.ref = "com-android-security-lint-lint" +} +``` + +1.0.3 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.android.security.lint:lint](com_android_security_lint_lint.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute + `tools:ignore="DefaultTrustedUserCerts"` on the problematic XML + element (or one of its enclosing elements). You may also need to add + the following namespace declaration on the root element in the XML + file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <manifest xmlns:tools="http://schemas.android.com/tools"> + ... + <application tools:ignore="DefaultTrustedUserCerts" .../> + ... + </manifest> + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="DefaultTrustedUserCerts" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'DefaultTrustedUserCerts' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore DefaultTrustedUserCerts ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/DefaultUncaughtExceptionDelegation.md.html b/docs/checks/DefaultUncaughtExceptionDelegation.md.html new file mode 100644 index 00000000..00846ee0 --- /dev/null +++ b/docs/checks/DefaultUncaughtExceptionDelegation.md.html @@ -0,0 +1,111 @@ + +(#) Missing default uncaught exception handler delegation + +!!! WARNING: Missing default uncaught exception handler delegation + This is a warning. + +Id +: `DefaultUncaughtExceptionDelegation` +Summary +: Missing default uncaught exception handler delegation +Severity +: Warning +Category +: Correctness +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.11.0-alpha07 (April 2025) +Affects +: Kotlin and Java files +Editing +: This check can *not* run live in the IDE editor +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/UncaughtExceptionHandlerDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/UncaughtExceptionHandlerDetectorTest.kt) + +A default uncaught exception handler should usually call the existing +(previously set) default uncaught exception handler. This is especially +true on Android, which uses a default uncaught exception handler to +handle crashes. This lint check reports calls to +`setDefaultUncaughtExceptionHandler` unless we can also see a call to +`getDefaultUncaughtExceptionHandler` (to get the existing handler) in +the same module. Make sure you also call +`existingHandler.uncaughtException(thread, throwable)` from your new +handler. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/com/example/app/test.kt:7:Warning: Must call +getDefaultUncaughtExceptionHandler() to get the existing handler, and +call existingHandler.uncaughtException(thread, throwable) from your new +handler [DefaultUncaughtExceptionDelegation] + setDefaultUncaughtExceptionHandler { thread, throwable -> + ^ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/com/example/app/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package com.example.app + +import android.util.Log +import java.lang.Thread.setDefaultUncaughtExceptionHandler + +fun foo() { + setDefaultUncaughtExceptionHandler { thread, throwable -> + Log.e("foo", "Uncaught exception") + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/UncaughtExceptionHandlerDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="DefaultUncaughtExceptionDelegation" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'DefaultUncaughtExceptionDelegation' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore DefaultUncaughtExceptionDelegation ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/DeletedProvider.md.html b/docs/checks/DeletedProvider.md.html index e7307f2f..0eee685b 100644 --- a/docs/checks/DeletedProvider.md.html +++ b/docs/checks/DeletedProvider.md.html @@ -18,18 +18,20 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.2.0 (September 2018) Affects : Kotlin and Java files Editing : This check runs on the fly in the IDE editor See : https://android-developers.googleblog.com/2018/03/cryptography-changes-in-android-p.html +See +: https://goo.gle/DeletedProvider Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/DeletedProviderDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/DeletedProviderDetectorTest.kt) -Copyright Year -: 2018 The `Crypto` provider has been completely removed in Android P (and was deprecated in an earlier release). This means that the code will throw a @@ -44,11 +46,8 @@ src/test/pkg/RemovedGeneratorTest.java:24:Error: The Crypto provider has been deleted in Android P (and was deprecated in Android N), so the code will crash [DeletedProvider] - SecureRandom instance2 = SecureRandom.getInstance("SHA1PRNG", "Crypto"); -------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/DenyListedApi.md.html b/docs/checks/DenyListedApi.md.html new file mode 100644 index 00000000..4e4406e8 --- /dev/null +++ b/docs/checks/DenyListedApi.md.html @@ -0,0 +1,197 @@ + +(#) Deny-listed API + +!!! ERROR: Deny-listed API + This is an error. + +Id +: `DenyListedApi` +Summary +: Deny-listed API +Severity +: Error +Category +: Correctness +Platform +: Android +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files, resource files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/denylistedapis/DenyListedApiDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/denylistedapis/DenyListedApiDetectorTest.kt) +Copyright Year +: 2022 + +This lint check flags usages of APIs in external libraries that we +prefer not to use. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/SomeView.kt:9:Error: Use Context#getDrawableCompat() instead +[DenyListedApi] + ContextCompat.getDrawable(context, 42) + ----------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/SomeView.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package foo + +import android.content.Context +import android.graphics.drawable.Drawable +import androidx.core.content.ContextCompat + +class SomeView(context: Context) { + init { + ContextCompat.getDrawable(context, 42) + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/denylistedapis/DenyListedApiDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `DenyListedApiDetector.flag function with params in deny list`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("DenyListedApi") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("DenyListedApi") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection DenyListedApi + problematicStatement() + ``` + +* Adding the suppression attribute `tools:ignore="DenyListedApi"` on + the problematic XML element (or one of its enclosing elements). You + may also need to add the following namespace declaration on the root + element in the XML file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <java.util.LinkedList xmlns:tools="http://schemas.android.com/tools" + tools:ignore="DenyListedApi" ...> + ... + </java.util.LinkedList> + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="DenyListedApi" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'DenyListedApi' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore DenyListedApi ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/DenyListedBlockingApi.md.html b/docs/checks/DenyListedBlockingApi.md.html new file mode 100644 index 00000000..8be1224f --- /dev/null +++ b/docs/checks/DenyListedBlockingApi.md.html @@ -0,0 +1,197 @@ + +(#) Deny-listed API + +!!! ERROR: Deny-listed API + This is an error. + +Id +: `DenyListedBlockingApi` +Summary +: Deny-listed API +Severity +: Error +Category +: Correctness +Platform +: Android +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.7.0 +Affects +: Kotlin and Java files, resource files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/denylistedapis/DenyListedApiDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/denylistedapis/DenyListedApiDetectorTest.kt) +Copyright Year +: 2022 + +This lint check flags usages of APIs in external libraries that we +prefer not to use. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/SomeClass.kt:6:Error: Blocking calls in coroutines can cause +deadlocks and application jank. Prefer making the enclosing function a +suspend function or refactoring this in a way to use non-blocking calls. +If running in a test, use runTest {} or Turbine to test synchronous +values. [DenyListedBlockingApi] + val result = runBlocking {} + ----------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/SomeClass.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package foo + +import kotlinx.coroutines.runBlocking + +class SomeClass { + val result = runBlocking {} +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/denylistedapis/DenyListedApiDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `DenyListedApiDetector.coroutineRunBlocking`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("DenyListedBlockingApi") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("DenyListedBlockingApi") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection DenyListedBlockingApi + problematicStatement() + ``` + +* Adding the suppression attribute + `tools:ignore="DenyListedBlockingApi"` on the problematic XML + element (or one of its enclosing elements). You may also need to add + the following namespace declaration on the root element in the XML + file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <java.util.LinkedList xmlns:tools="http://schemas.android.com/tools" + tools:ignore="DenyListedBlockingApi" ...> + ... + </java.util.LinkedList> + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="DenyListedBlockingApi" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'DenyListedBlockingApi' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore DenyListedBlockingApi ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/Deprecated.md.html b/docs/checks/Deprecated.md.html index dc8368e2..fe9555ad 100644 --- a/docs/checks/Deprecated.md.html +++ b/docs/checks/Deprecated.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files, manifest files and resource files Editing @@ -32,80 +34,53 @@ Deprecated views, attributes and so on are deprecated because there is a better way to do something. Do it that new way. You've been warned. +!!! Tip + This lint check has an associated quickfix available in the IDE. + (##) Example Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/deprecation.xml:1:Warning: AbsoluteLayout is deprecated [Deprecated] - <AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android" -------------- - - res/layout/deprecation.xml:15:Warning: android:autoText is deprecated: Use inputType instead [Deprecated] - android:autoText="true" ----------------------- - - res/layout/deprecation.xml:16:Warning: android:capitalize is deprecated: Use inputType instead [Deprecated] - android:capitalize="true" ------------------------- - - res/layout/deprecation.xml:17:Warning: android:editable is deprecated: Use an to make it editable [Deprecated] - android:editable="true" ----------------------- - - res/layout/deprecation.xml:19:Warning: android:inputMethod is deprecated: Use inputType instead [Deprecated] - android:inputMethod="@+id/foo" ------------------------------ - - res/layout/deprecation.xml:20:Warning: android:numeric is deprecated: Use inputType instead [Deprecated] - android:numeric="true" ---------------------- - - res/layout/deprecation.xml:21:Warning: android:password is deprecated: Use inputType instead [Deprecated] - android:password="true" ----------------------- - - res/layout/deprecation.xml:22:Warning: android:phoneNumber is deprecated: Use inputType instead [Deprecated] - android:phoneNumber="true" -------------------------- - - res/layout/deprecation.xml:25:Warning: android:editable is deprecated: is already editable [Deprecated] - <EditText android:editable="true" /> ----------------------- - - res/layout/deprecation.xml:26:Warning: android:editable is deprecated: Use inputType instead [Deprecated] - <EditText android:editable="false" /> ------------------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -165,7 +140,7 @@ <?xml version="1.0" encoding="UTF-8"?> <manifest xmlns:tools="http://schemas.android.com/tools"> ... - <AbsoluteLayout editable="..." tools:ignore="Deprecated" .../> + <AbsoluteLayout sharedUserId="..." tools:ignore="Deprecated" .../> ... </manifest> ``` diff --git a/docs/checks/DeprecatedCall.md.html b/docs/checks/DeprecatedCall.md.html new file mode 100644 index 00000000..060e135a --- /dev/null +++ b/docs/checks/DeprecatedCall.md.html @@ -0,0 +1,192 @@ + +(#) This class or method is deprecated; consider using an alternative + +!!! WARNING: This class or method is deprecated; consider using an alternative + This is a warning. + +Id +: `DeprecatedCall` +Summary +: This class or method is deprecated; consider using an alternative +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/DeprecatedAnnotationDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/DeprecatedAnnotationDetectorTest.kt) +Copyright Year +: 2021 + +Using deprecated classes is not advised; please consider using an +alternative. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/test/TestClass.java:8:Warning: This class or method is +deprecated; consider using an alternative. [DeprecatedCall] + new ThisIsDeprecated(); + ---------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`src/slack/test/ThisIsDeprecated.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package slack.test; + +@Deprecated() +class ThisIsDeprecated { + +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/slack/test/TestClass.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package slack.test; + +import slack.test.ThisIsDeprecated; + +public class TestClass { + + public void doStuff() { + new ThisIsDeprecated(); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/DeprecatedAnnotationDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `DeprecatedAnnotationDetector.deprecated class has a warning`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("DeprecatedCall") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("DeprecatedCall") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection DeprecatedCall + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="DeprecatedCall" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'DeprecatedCall' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore DeprecatedCall ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/DeprecatedProvider.md.html b/docs/checks/DeprecatedProvider.md.html index 08e72c41..8ba987bf 100644 --- a/docs/checks/DeprecatedProvider.md.html +++ b/docs/checks/DeprecatedProvider.md.html @@ -18,18 +18,20 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.2.0 (September 2018) Affects : Kotlin and Java files Editing : This check runs on the fly in the IDE editor See : https://android-developers.googleblog.com/2018/03/cryptography-changes-in-android-p.html +See +: https://goo.gle/DeprecatedProvider Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/CipherGetInstanceDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/CipherGetInstanceDetectorTest.kt) -Copyright Year -: 2014 The `BC` provider has been deprecated and will not be provided when `targetSdkVersion` is P or higher. @@ -42,38 +44,26 @@ deprecated and when targetSdkVersion is moved to P this method will throw a NoSuchAlgorithmException. To fix this you should stop specifying a provider and use the default implementation [DeprecatedProvider] - Cipher.getInstance("AES/CBC/PKCS7PADDING", "BC"); // Error ---- - - src/test/pkg/BCProviderTest.java:17:Warning: The BC provider is deprecated and when targetSdkVersion is moved to P this method will throw a NoSuchAlgorithmException. To fix this you should stop specifying a provider and use the default implementation [DeprecatedProvider] - Cipher.getInstance("AES/CBC/PKCS7PADDING", BC_PROVIDER); // Error ----------- - - src/test/pkg/BCProviderTest.java:19:Warning: The BC provider is deprecated and when targetSdkVersion is moved to P this method will throw a NoSuchAlgorithmException. To fix this you should stop specifying a provider and use the default implementation [DeprecatedProvider] - Cipher.getInstance("AES/CBC/PKCS7PADDING", Security.getProvider("BC")); // Error -------------------------- - - src/test/pkg/BCProviderTest.java:20:Warning: The BC provider is deprecated and when targetSdkVersion is moved to P this method will throw a NoSuchAlgorithmException. To fix this you should stop specifying a provider and use the default implementation [DeprecatedProvider] - Cipher.getInstance("AES/CBC/PKCS7PADDING", Security.getProvider(BC_PROVIDER)); // Error --------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/DeprecatedSinceApi.md.html b/docs/checks/DeprecatedSinceApi.md.html index 263e6b48..8feb3e94 100644 --- a/docs/checks/DeprecatedSinceApi.md.html +++ b/docs/checks/DeprecatedSinceApi.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.3.0 (September 2022) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/DeprecatedSinceApiDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/DeprecatedSinceApiDetectorTest.kt) -Copyright Year -: 2022 Some backport methods are only necessary until a specific version of Android. These have been annotated with `@DeprecatedSinceApi`, @@ -39,95 +39,84 @@ Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -src/test/pkg/Api.kt:26:Warning: This method is deprecated as of API -level 25 [DeprecatedSinceApi] - - api.someMethod2(0) // WARN 1 - ------------------ - - -src/test/pkg/Api.kt:27:Warning: This method is deprecated as of API -level 30; Use AlarmManager.notify instead [DeprecatedSinceApi] - - api.someMethod3(0) // WARN 2 - ------------------ - - -src/test/pkg/Api.kt:28:Warning: This field is deprecated as of API level -30 [DeprecatedSinceApi] - - val c = MY_CONSTANT // WARN 3 - ----------- - - -src/test/pkg/Api.kt:29:Warning: This class is deprecated as of API level -28 [DeprecatedSinceApi] - - api2.someMethod1(0) // WARN 4 - ------------------- - - -src/test/pkg/Api.kt:30:Warning: This method is deprecated as of API -level 30 [DeprecatedSinceApi] - - api2.someMethod2(0) // WARN 5 - ------------------- - - -src/test/pkg/Api.kt:31:Warning: This class is deprecated as of API level -28 [DeprecatedSinceApi] - - val clz = Api2::class.java // WARN 6 +src/test/pkg/Test.kt:9:Warning: This method is deprecated as of API +level 21 [DeprecatedSinceApi] + api.noLongerNecessary1(0) // WARN 1 + ------------------------- +src/test/pkg/Test.kt:10:Warning: This method is deprecated as of API +level 23; Use AlarmManager.notify instead [DeprecatedSinceApi] + api.noLongerNecessary2(0) // WARN 2 + ------------------------- +src/test/pkg/Test.kt:11:Warning: This method is deprecated as of API +level 24 [DeprecatedSinceApi] + api.noLongerNecessary3(0) // WARN 3 + ------------------------- +src/test/pkg/Test.kt:18:Warning: This class is deprecated as of API +level 19 [DeprecatedSinceApi] + val clz = Api2::class.java // WARN 4 ----------- - - -src/test/pkg/Api.kt:32:Warning: This method is deprecated as of API -level 25 [DeprecatedSinceApi] - - println(api::someMethod2) // WARN 7 - ---------------- - - +src/test/pkg/Test.kt:19:Warning: This method is deprecated as of API +level 23 [DeprecatedSinceApi] + val method1 = api2::someMethod1 // WARN 5 + ----------------- +src/test/pkg/Test.kt:20:Warning: This method is deprecated as of API +level 21 [DeprecatedSinceApi] + val method2 = api2::someMethod2 // WARN 6 + ----------------- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: -`src/test/pkg/Api.kt`: +`src/test/pkg/Test.kt`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +@file:Suppress("UNUSED_PARAMETER", "UNUSED_VARIABLE", "unused") package test.pkg import androidx.annotation.DeprecatedSinceApi +class Test { + fun test(api: Api, api2: Api2) { + // minSdkVersion = 24: + + api.noLongerNecessary1(0) // WARN 1 + api.noLongerNecessary2(0) // WARN 2 + api.noLongerNecessary3(0) // WARN 3 + + api.unnecessaryInTheFuture1(0) // OK 1 + api.unnecessaryInTheFuture2(0) // OK 2 + + // The above enforced calls (the most common scenario); check + // some other reference types. + val clz = Api2::class.java // WARN 4 + val method1 = api2::someMethod1 // WARN 5 + val method2 = api2::someMethod2 // WARN 6 + } +} + class Api { @DeprecatedSinceApi(api = 21) - fun someMethod1(arg: Int) { } + fun noLongerNecessary1(arg: Int) { } + + @DeprecatedSinceApi(api = 23, message = "Use AlarmManager.notify instead") + fun noLongerNecessary2(arg: Int) { } + + @DeprecatedSinceApi(api = 24) + fun noLongerNecessary3(arg: Int) { } + @DeprecatedSinceApi(api = 25) - fun someMethod2(arg: Int) { } - @DeprecatedSinceApi(api = 30, message = "Use AlarmManager.notify instead") - fun someMethod3(arg: Int) { } + fun unnecessaryInTheFuture1(arg: Int) { } + + @DeprecatedSinceApi(api = 33) + fun unnecessaryInTheFuture2(arg: Int) { } } -@DeprecatedSinceApi(api = 28) +@DeprecatedSinceApi(api = 19) class Api2 { + @DeprecatedSinceApi(api = 23) fun someMethod1(arg: Int) { } - @DeprecatedSinceApi(api = 30) + @DeprecatedSinceApi(api = 21) fun someMethod2(arg: Int) { } } -@DeprecatedSinceApi(30) -const val MY_CONSTANT = "test" - -class Test { - fun test(api: Api, api2: Api2) { - api.someMethod1(0) // OK - api.someMethod2(0) // WARN 1 - api.someMethod3(0) // WARN 2 - val c = MY_CONSTANT // WARN 3 - api2.someMethod1(0) // WARN 4 - api2.someMethod2(0) // WARN 5 - val clz = Api2::class.java // WARN 6 - println(api::someMethod2) // WARN 7 - } -} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can also visit the diff --git a/docs/checks/DeprecatedSqlUsage.md.html b/docs/checks/DeprecatedSqlUsage.md.html new file mode 100644 index 00000000..460a4236 --- /dev/null +++ b/docs/checks/DeprecatedSqlUsage.md.html @@ -0,0 +1,180 @@ + +(#) Use SqlDelight + +!!! WARNING: Use SqlDelight + This is a warning. + +Id +: `DeprecatedSqlUsage` +Summary +: Use SqlDelight +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/DeprecatedSqlUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/DeprecatedSqlUsageDetectorTest.kt) +Copyright Year +: 2021 + +Safer, faster, etc. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/SqlUsageTestFailure.java:7:Warning: All SQL querying should be +performed using SqlDelight [DeprecatedSqlUsage] + db.execSQL("DROP TABLE IF EXISTS foo"); + -------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/SqlUsageTestFailure.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package foo; + +import android.database.sqlite.SQLiteDatabase; + +public static class SqlUsageTestFailure { + public static void delete(SQLiteDatabase db) { + db.execSQL("DROP TABLE IF EXISTS foo"); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/DeprecatedSqlUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `DeprecatedSqlUsageDetector.testJavaInspection`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("DeprecatedSqlUsage") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("DeprecatedSqlUsage") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection DeprecatedSqlUsage + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="DeprecatedSqlUsage" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'DeprecatedSqlUsage' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore DeprecatedSqlUsage ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/DetachAndAttachSameFragment.md.html b/docs/checks/DetachAndAttachSameFragment.md.html index f4a75860..dc9a0348 100644 --- a/docs/checks/DetachAndAttachSameFragment.md.html +++ b/docs/checks/DetachAndAttachSameFragment.md.html @@ -20,6 +20,14 @@ : androidx.fragment Feedback : https://issuetracker.google.com/issues/new?component=460964 +Min +: Lint 7.0 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [androidx.fragment:fragment](androidx_fragment_fragment.md.html) +Since +: 1.4.0 Affects : Kotlin and Java files Editing @@ -31,15 +39,49 @@ Copyright Year : 2019 -When doing a FragmentTransaction that includes both attach() +When doing a FragmentTransaction that includes both attach() and detach() operations being committed on the same fragment instance, it is a no-op. The reason for this is that the FragmentManager optimizes all operations within a single -transaction so the attach() and detach() cancel each other out +transaction so the attach() and detach() cancel each other out and neither is actually executed. To get the desired behavior, you should separate the attach() and detach() calls into separate FragmentTransactions. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.fragment:fragment:1.8.6") + +// build.gradle +implementation 'androidx.fragment:fragment:1.8.6' + +// build.gradle.kts with version catalogs: +implementation(libs.fragment) + +# libs.versions.toml +[versions] +fragment = "1.8.6" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +fragment = { + module = "androidx.fragment:fragment", + version.ref = "fragment" +} +``` + +1.8.6 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.fragment:fragment](androidx_fragment_fragment.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/DevModeObsolete.md.html b/docs/checks/DevModeObsolete.md.html index 9734659f..d2df2794 100644 --- a/docs/checks/DevModeObsolete.md.html +++ b/docs/checks/DevModeObsolete.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.0.0 (October 2017) Affects : Gradle build files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GradleDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) -Copyright Year -: 2014 In the past, our documentation recommended creating a `dev` product flavor with has a minSdkVersion of 21, in order to enable multidexing to @@ -50,19 +50,13 @@ build.gradle:9:Warning: You no longer need a dev mode to enable multi-dexing during development, and this can break API version checks [DevModeObsolete] - minSdkVersion 21 ---------------- - - build.gradle:10:Warning: You no longer need a dev mode to enable multi-dexing during development, and this can break API version checks [DevModeObsolete] - - minSdk 21 - --------- - - + minSdk = 21 + ----------- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -78,7 +72,7 @@ dev { // To avoid using legacy multidex, set minSdkVersion to 21 or higher. minSdkVersion 21 - minSdk 21 + minSdk = 21 versionNameSuffix "-dev" applicationIdSuffix '.dev' } diff --git a/docs/checks/DeviceAdmin.md.html b/docs/checks/DeviceAdmin.md.html index 437a4d2c..66c08305 100644 --- a/docs/checks/DeviceAdmin.md.html +++ b/docs/checks/DeviceAdmin.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Manifest files Editing @@ -48,25 +50,16 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text AndroidManifest.xml:30:Warning: You must have an intent filter for action android.app.action.DEVICE_ADMIN_ENABLED [DeviceAdmin] - <meta-data android:name="android.app.device_admin" --------------------------------------- - - AndroidManifest.xml:43:Warning: You must have an intent filter for action android.app.action.DEVICE_ADMIN_ENABLED [DeviceAdmin] - <meta-data android:name="android.app.device_admin" --------------------------------------- - - AndroidManifest.xml:55:Warning: You must have an intent filter for action android.app.action.DEVICE_ADMIN_ENABLED [DeviceAdmin] - <meta-data android:name="android.app.device_admin" --------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/DialogFragmentCallbacksDetector.md.html b/docs/checks/DialogFragmentCallbacksDetector.md.html index 7d806e44..c7499c4c 100644 --- a/docs/checks/DialogFragmentCallbacksDetector.md.html +++ b/docs/checks/DialogFragmentCallbacksDetector.md.html @@ -20,6 +20,14 @@ : androidx.fragment Feedback : https://issuetracker.google.com/issues/new?component=460964 +Min +: Lint 7.0 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [androidx.fragment:fragment](androidx_fragment_fragment.md.html) +Since +: 1.4.0 Affects : Kotlin and Java files Editing @@ -31,11 +39,11 @@ Copyright Year : 2021 -When using a `DialogFragment`, the `setOnCancelListener` and +When using a `DialogFragment`, the `setOnCancelListener` and `setOnDismissListener` callback functions within the `onCreateDialog` function __must not be used__ because the `DialogFragment` owns these callbacks. Instead the -respective `onCancel` and `onDismiss` functions can be used to +respective `onCancel` and `onDismiss` functions can be used to achieve the desired effect. (##) Example @@ -45,11 +53,8 @@ src/foo/TestFragment.java:11:Warning: Use onCancel() instead of calling setOnCancelListener() from onCreateDialog() [DialogFragmentCallbacksDetector] - dialog.setOnCancelListener({ }); ------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -81,6 +86,40 @@ To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=460964. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.fragment:fragment:1.8.6") + +// build.gradle +implementation 'androidx.fragment:fragment:1.8.6' + +// build.gradle.kts with version catalogs: +implementation(libs.fragment) + +# libs.versions.toml +[versions] +fragment = "1.8.6" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +fragment = { + module = "androidx.fragment:fragment", + version.ref = "fragment" +} +``` + +1.8.6 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.fragment:fragment](androidx_fragment_fragment.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/DiffUtilEquals.md.html b/docs/checks/DiffUtilEquals.md.html index 54816009..78db3853 100644 --- a/docs/checks/DiffUtilEquals.md.html +++ b/docs/checks/DiffUtilEquals.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.4.0 (April 2019) Affects : Kotlin and Java files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/DiffUtilDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/DiffUtilDetectorTest.kt) -Copyright Year -: 2018 `areContentsTheSame` is used by `DiffUtil` to produce diffs. If the method is implemented incorrectly, such as using identity equals instead @@ -42,14 +42,11 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/test.kt:10:Error: Suspicious equality check: Did you mean == instead of === ? [DiffUtilEquals] - oldItem === newItem // ERROR --- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `src/test/pkg/test.kt`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers @@ -66,6 +63,34 @@ } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/test/pkg/MyCallback.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; + +import androidx.recyclerview.widget.DiffUtil; + +public class MyCallback extends DiffUtil.ItemCallback { + @Override + public boolean areItemsTheSame(Cheese oldItem, Cheese newItem) { + return oldItem.getId() == newItem.getId(); + } + + @Override + public boolean areContentsTheSame(Cheese oldItem, Cheese newItem) { + return oldItem == newItem; + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/Cheese.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; + +public class Cheese { + public String id; +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/DiffUtilDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/DisableBaselineAlignment.md.html b/docs/checks/DisableBaselineAlignment.md.html index f9e74772..1d7c1d91 100644 --- a/docs/checks/DisableBaselineAlignment.md.html +++ b/docs/checks/DisableBaselineAlignment.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -43,11 +45,8 @@ res/layout/baseline_weights.xml:2:Warning: Set android:baselineAligned="false" on this element for better performance [DisableBaselineAlignment] - <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" ------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/DisabledAllSafeBrowsing.md.html b/docs/checks/DisabledAllSafeBrowsing.md.html new file mode 100644 index 00000000..9b41cfe4 --- /dev/null +++ b/docs/checks/DisabledAllSafeBrowsing.md.html @@ -0,0 +1,172 @@ + +(#) Application has disabled safe browsing for all WebView objects + +!!! WARNING: Application has disabled safe browsing for all WebView objects + This is a warning. + +Id +: `DisabledAllSafeBrowsing` +Summary +: Application has disabled safe browsing for all WebView objects +Severity +: Warning +Category +: Security +Platform +: Android +Vendor +: Google - Android 3P Vulnerability Research +Contact +: https://github.com/google/android-security-lints +Feedback +: https://github.com/google/android-security-lints/issues +Min +: Lint 4.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.android.security.lint:lint](com_android_security_lint_lint.md.html) +Since +: 1.0.1 +Affects +: Manifest files +Editing +: This check runs on the fly in the IDE editor +See +: https://goo.gle/DisabledAllSafeBrowsing +Implementation +: [Source Code](https://github.com/google/android-security-lints/tree/main/checks/src/main/java/com/example/lint/checks/SafeBrowsingDetector.kt) +Tests +: [Source Code](https://github.com/google/android-security-lints/tree/main/checks/src/test/java/com/example/lint/checks/SafeBrowsingDetectorTest.kt) +Copyright Year +: 2024 + +Safe Browsing is a service to help applications check URLs against a +known list of unsafe web resources. We recommend keeping Safe Browsing +enabled at all times and designing your app around any constraints this +causes. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +AndroidManifest.xml:3:Warning: Safe Browsing should be kept enabled at +all times, as it aims to keep users from unsafe URLs +[DisabledAllSafeBrowsing] + <meta-data android:name='android.webkit.WebView.EnableSafeBrowsing' android:value='false'/> + ------------------------------------------------------------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`AndroidManifest.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<manifest xmlns:android='http://schemas.android.com/apk/res/android' package='test.pkg'> +<application android:debuggable='false'> + <meta-data android:name='android.webkit.WebView.EnableSafeBrowsing' android:value='false'/> + <activity android:name='com.example.MainActivity'></activity> +</application> +</manifest> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/google/android-security-lints/tree/main/checks/src/test/java/com/example/lint/checks/SafeBrowsingDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `SafeBrowsingDetector.testWhenSafeBrowsingDisabledInManifest_showsWarning`. +To report a problem with this extracted sample, visit +https://github.com/google/android-security-lints/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.android.security.lint:lint:1.0.3") + +// build.gradle +lintChecks 'com.android.security.lint:lint:1.0.3' + +// build.gradle.kts with version catalogs: +lintChecks(libs.com.android.security.lint.lint) + +# libs.versions.toml +[versions] +com-android-security-lint-lint = "1.0.3" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +com-android-security-lint-lint = { + module = "com.android.security.lint:lint", + version.ref = "com-android-security-lint-lint" +} +``` + +1.0.3 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.android.security.lint:lint](com_android_security_lint_lint.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute + `tools:ignore="DisabledAllSafeBrowsing"` on the problematic XML + element (or one of its enclosing elements). You may also need to add + the following namespace declaration on the root element in the XML + file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <manifest xmlns:tools="http://schemas.android.com/tools"> + ... + <meta-data tools:ignore="DisabledAllSafeBrowsing" .../> + ... + </manifest> + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="DisabledAllSafeBrowsing" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'DisabledAllSafeBrowsing' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore DisabledAllSafeBrowsing ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/DiscouragedApi.md.html b/docs/checks/DiscouragedApi.md.html index 6d930c36..a2454763 100644 --- a/docs/checks/DiscouragedApi.md.html +++ b/docs/checks/DiscouragedApi.md.html @@ -18,57 +18,49 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.1.0 (January 2022) Affects -: Kotlin and Java files +: Kotlin and Java files, manifest files and resource files Editing : This check runs on the fly in the IDE editor Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/DiscouragedDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/DiscouragedDetectorTest.kt) -Copyright Year -: 2021 Discouraged APIs are allowed and are not deprecated, but they may be unfit for common use (e.g. due to slow performance or subtle behavior). +!!! Tip + This lint check has an associated quickfix available in the IDE. + (##) Example Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -src/test/pkg/MainActivity.kt:13:Warning: don't use this +src/test/pkg/Test1.java:9:Warning: Use of this function is discouraged. +It is more efficient to retrieve resources by identifier than by name. +See getValue(int id, TypedValue outValue, boolean resolveRefs). [DiscouragedApi] - - findViewById<TextView>(R.id.text)?.text = getSomeString() - ------------- - - + Resources.getValue("name", testValue, false); + -------- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: -`src/test/pkg/MainActivity.kt`: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers -package test.pkg - -import android.app.Activity -import android.os.Bundle -import android.widget.TextView -import androidx.annotation.Discouraged -import java.util.UUID - -class MainActivity : Activity() { - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_main) - findViewById(R.id.text)?.text = getSomeString() - } +`src/test/pkg/Test1.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; + +import android.content.res.Resources; +import android.util.TypedValue; - companion object { - @Discouraged(message = "don't use this") - fun getSomeString(): String { - return UUID.randomUUID().toString() - } +public class Test1 { + public void setValue() { + TypedValue testValue; + Resources.getValue("name", testValue, false); + Resources.getValue(0, testValue, false); } } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -77,11 +69,6 @@ [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/DiscouragedDetectorTest.kt) for the unit tests for this check to see additional scenarios. -The above example was automatically extracted from the first unit test -found for this lint check, `DiscouragedDetector.test205800560`. -To report a problem with this extracted sample, visit -https://issuetracker.google.com/issues/new?component=192708. - (##) Suppressing You can suppress false positives using one of the following mechanisms: @@ -93,7 +80,7 @@ // Kotlin @Suppress("DiscouragedApi") fun method() { - problematicStatement() + scheduleAtFixedRate(...) } ``` @@ -103,7 +90,7 @@ // Java @SuppressWarnings("DiscouragedApi") void method() { - problematicStatement(); + scheduleAtFixedRate(...); } ``` @@ -114,6 +101,12 @@ problematicStatement() ``` +* Adding the suppression attribute `tools:ignore="DiscouragedApi"` on + the problematic XML element (or one of its enclosing elements). You + may also need to add the following namespace declaration on the root + element in the XML file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + * Using a special `lint.xml` file in the source tree which turns off the check in that folder and any sub folder. A simple file might look like this: diff --git a/docs/checks/DiscouragedPrivateApi.md.html b/docs/checks/DiscouragedPrivateApi.md.html index 8705501f..7526711d 100644 --- a/docs/checks/DiscouragedPrivateApi.md.html +++ b/docs/checks/DiscouragedPrivateApi.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.5.0 (August 2019) Affects : Kotlin and Java files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/PrivateApiDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/PrivateApiDetectorTest.kt) -Copyright Year -: 2017 Usage of restricted non-SDK interface may throw an exception at runtime. Accessing non-SDK methods or fields through reflection has a high @@ -44,32 +44,23 @@ access to addAssetPath, which is not part of the public SDK and therefore likely to change in future Android releases [DiscouragedPrivateApi] - Method m1 = AssetManager.class.getDeclaredMethod("addAssetPath", String.class); ------------------------------------------------------------------ - - src/test/pkg/application/ReflectionTestJava.java:12:Warning: Reflective access to addAssetPath, which is not part of the public SDK and therefore likely to change in future Android releases [DiscouragedPrivateApi] - Method m2 = assetManager.getClass().getDeclaredMethod("addAssetPath", String.class); ----------------------------------------------------------------------- - - src/test/pkg/application/ReflectionTestJava.java:13:Warning: Reflective access to addAssetPath, which is not part of the public SDK and therefore likely to change in future Android releases [DiscouragedPrivateApi] - Method m3 = AssetManager.class.getDeclaredMethod("addAssetPath", path.getClass()); --------------------------------------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `src/test/pkg/application/ReflectionTestJava.java`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers @@ -96,6 +87,28 @@ } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/test/pkg/application/ReflectionTestKotlin.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg.application; + +import android.content.res.AssetManager + +class ReflectionTestKotlin { + private fun addAssetPath(assetManager: AssetManager) { + val path = "foo/bar" + val m1 = AssetManager::class.java.getDeclaredMethod("addAssetPath", String::class.java) + val m2 = assetManager.javaClass.getDeclaredMethod("invalidateCachesLocked", Int::class.javaPrimitiveType) + val m3 = assetManager.javaClass.getDeclaredMethod("invalidateCachesLocked", Int::class.java) // OK, doesn't exist + val m4 = AssetManager::class.java.getDeclaredMethod("addAssetPath", path.javaClass) + + val activityClass = Class.forName("android.app.Activity") + val bundleClass = Class.forName("android.os.Bundle") + val m5 = activityClass.getDeclaredMethod("dispatchActivityPostCreated", bundleClass) + + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/PrivateApiDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/DoNotCallProviders.md.html b/docs/checks/DoNotCallProviders.md.html new file mode 100644 index 00000000..5f5a0bc3 --- /dev/null +++ b/docs/checks/DoNotCallProviders.md.html @@ -0,0 +1,227 @@ + +(#) Dagger provider methods should not be called directly by user code + +!!! ERROR: Dagger provider methods should not be called directly by user code + This is an error. + +Id +: `DoNotCallProviders` +Summary +: Dagger provider methods should not be called directly by user code +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/DoNotCallProvidersDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/DoNotCallProvidersDetectorTest.kt) +Copyright Year +: 2021 + +Dagger provider methods should not be called directly by user code. +These are intended solely for use by Dagger-generated code and it is +programmer error to call them from user code. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/MyModule.kt:15:Error: Dagger provider methods should not be +called directly by user code. [DoNotCallProviders] + binds1("this is bad") + --------------------- +src/foo/MyModule.kt:16:Error: Dagger provider methods should not be +called directly by user code. [DoNotCallProviders] + "this is bad".binds2() + --------------------- +src/foo/MyModule.kt:17:Error: Dagger provider methods should not be +called directly by user code. [DoNotCallProviders] + provider() + ---------- +src/foo/MyModule.kt:18:Error: Dagger provider methods should not be +called directly by user code. [DoNotCallProviders] + producer() + ---------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/MyModule.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package foo +import dagger.Binds +import dagger.Module +import dagger.Provides +import dagger.producers.Produces +import javax.annotation.Generated + +@Module +abstract class MyModule { + + @Binds fun binds1(input: String): Comparable + @Binds fun String.binds2(): Comparable + + fun badCode() { + binds1("this is bad") + "this is bad".binds2() + provider() + producer() + } + + companion object { + @Provides + fun provider(): String { + return "" + } + @Produces + fun producer(): String { + return "" + } + } +} + +@Generated("Totes generated code") +abstract class GeneratedCode { + fun doStuff() { + moduleInstance().binds1("this is technically fine but would never happen in dagger") + MyModule.provider() + MyModule.producer() + } + + abstract fun moduleInstance(): MyModule +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/DoNotCallProvidersDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `DoNotCallProvidersDetector.kotlin`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("DoNotCallProviders") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("DoNotCallProviders") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection DoNotCallProviders + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="DoNotCallProviders" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'DoNotCallProviders' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore DoNotCallProviders ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/DoNotCallViewToString.md.html b/docs/checks/DoNotCallViewToString.md.html new file mode 100644 index 00000000..b07fc067 --- /dev/null +++ b/docs/checks/DoNotCallViewToString.md.html @@ -0,0 +1,146 @@ + +(#) Do not use `View.toString()` + +!!! ERROR: Do not use `View.toString()` + This is an error. + +Id +: `DoNotCallViewToString` +Summary +: Do not use `View.toString()` +Severity +: Error +Category +: Security +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.8.1 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/ui/DoNotCallViewToString.kt) +Copyright Year +: 2024 + +`View.toString()` and its overrides can often print surprisingly +detailed information about the current view state, and has led to PII +logging issues in the past. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("DoNotCallViewToString") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("DoNotCallViewToString") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection DoNotCallViewToString + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="DoNotCallViewToString" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'DoNotCallViewToString' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore DoNotCallViewToString ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/DoNotExposeEitherNetInRepositories.md.html b/docs/checks/DoNotExposeEitherNetInRepositories.md.html new file mode 100644 index 00000000..b56515df --- /dev/null +++ b/docs/checks/DoNotExposeEitherNetInRepositories.md.html @@ -0,0 +1,216 @@ + +(#) Repository APIs should not expose EitherNet types directly + +!!! ERROR: Repository APIs should not expose EitherNet types directly + This is an error. + +Id +: `DoNotExposeEitherNetInRepositories` +Summary +: Repository APIs should not expose EitherNet types directly +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/eithernet/DoNotExposeEitherNetInRepositoriesDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/eithernet/DoNotExposeEitherNetInRepositoriesDetectorTest.kt) +Copyright Year +: 2022 + +EitherNet (and networking in general) should be an implementation detail +of the repository layer. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test/MyRepository.java:8:Error: Repository APIs should not expose +EitherNet types directly. [DoNotExposeEitherNetInRepositories] + ApiResult<String, Exception> getResult(); + ---------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`src/com/slack/eithernet/ApiResult.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package com.slack.eithernet + +interface ApiResult +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/MyRepository.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test; + +import com.slack.eithernet.ApiResult; + +interface MyRepository { + // Bad + + ApiResult getResult(); + + // Good + + String getString(); +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/MyClassRepository.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test; + +import com.slack.eithernet.ApiResult; + +abstract class MyClassRepository { + // Bad + + public abstract ApiResult getResultPublic(); + public ApiResult resultField = null; + + // Good + + ApiResult resultFieldPackagePrivate = null; + private final ApiResult resultFieldPrivate = null; + protected ApiResult resultFieldProtected = null; + abstract ApiResult getResultPackagePrivate(); + private ApiResult getResultPrivate(); + private ApiResult getResultProtected(); + public abstract String getString(); +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/eithernet/DoNotExposeEitherNetInRepositoriesDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `DoNotExposeEitherNetInRepositoriesDetector.javaTests`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("DoNotExposeEitherNetInRepositories") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("DoNotExposeEitherNetInRepositories") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection DoNotExposeEitherNetInRepositories + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="DoNotExposeEitherNetInRepositories" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'DoNotExposeEitherNetInRepositories' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore DoNotExposeEitherNetInRepositories ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/DoNotMock.md.html b/docs/checks/DoNotMock.md.html new file mode 100644 index 00000000..4278f74d --- /dev/null +++ b/docs/checks/DoNotMock.md.html @@ -0,0 +1,276 @@ + +(#) + +!!! ERROR: + This is an error. + +Id +: `DoNotMock` +Summary +: +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/mocking/MockDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/mocking/DoNotMockMockDetectorTest.kt) +Copyright Year +: 2021 + +Do not mock classes annotated with `@DoNotMock`, as they are explicitly +asking not to be mocked in favor of better options (test fakes, etc). +These types should define explanations/alternatives in their +annotation. + +(##) Options + +You can configure this lint checks using the following options: + +(###) mock-annotations + +A comma-separated list of mock annotations.. +This property should define comma-separated list of mock annotation class names (FQCN). Set this for all issues using this option. + +Default is "org.mockito.Mock,org.mockito.Spy". + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="DoNotMock"> + <option name="mock-annotations" value=""org.mockito.Mock,org.mockito.Spy"" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(###) mock-factories + +A comma-separated list of mock factories (org.mockito.Mockito#methodName).. +A comma-separated list of mock factories (org.mockito.Mockito#methodName). Set this for all issues using this option. + +Default is "org.mockito.Mockito#mock,org.mockito.Mockito#spy,slack.test.mockito.MockitoHelpers#mock,slack.test.mockito.MockitoHelpersKt#mock,org.mockito.kotlin.MockingKt#mock,org.mockito.kotlin.SpyingKt#spy". + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="DoNotMock"> + <option name="mock-factories" value=""org.mockito.Mockito#mock,org.mockito.Mockito#spy,slack.test.mockito.MockitoHelpers#mock,slack.test.mockito.MockitoHelpersKt#mock,org.mockito.kotlin.MockingKt#mock,org.mockito.kotlin.SpyingKt#spy"" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(###) mock-report + +If enabled, writes a mock report to /build/reports/mockdetector/mock-report.csv.. +If enabled, writes a mock report to /build/reports/mockdetector/mock-report.csv. The format of the file is a csv of (type,isError) of mocked classes. Set this for all issues using this option. + +Default is "none". + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="DoNotMock"> + <option name="mock-report" value=""none"" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +test/test/slack/test/TestClass.kt:6:Error: Do not mock TestClass: Use +fake() [DoNotMock] + @Mock lateinit var mock1: TestClass + ----------------------------------- +test/test/slack/test/TestClass.kt:7:Error: Do not mock TestClass2: Use +fake() [DoNotMock] + @Mock lateinit var mock2: TestClass2 + ------------------------------------ +test/test/slack/test/TestClass.kt:8:Error: Do not mock TestClass3: +BECAUSE REASONS [DoNotMock] + @Mock lateinit var mock3: TestClass3 + ------------------------------------ +test/test/slack/test/TestClass.kt:9:Error: Do not mock TestClass4: +BECAUSE REASONS [DoNotMock] + @Mock lateinit var mock4: TestClass4 + ------------------------------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`test/test/slack/test/TestClass.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.test + +@slack.lint.annotations.DoNotMock("Use fake()") +interface TestClass { + fun fake(): TestClass? = null +} + +@com.google.errorprone.annotations.DoNotMock("Use fake()") +interface TestClass2 { + fun fake(): TestClass2? = null +} + +@slack.lint.annotations.DoNotMock +interface TestClass3 { + fun fake(): TestClass3? = null +} + +@com.google.errorprone.annotations.DoNotMock +interface TestClass4 { + fun fake(): TestClass4? = null +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`test/test/slack/test/TestClass.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.test + +import org.mockito.Mock + +class MyTests { + @Mock lateinit var mock1: TestClass + @Mock lateinit var mock2: TestClass2 + @Mock lateinit var mock3: TestClass3 + @Mock lateinit var mock4: TestClass4 +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/mocking/DoNotMockMockDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MockDetector.kotlinTests`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("DoNotMock") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("DoNotMock") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection DoNotMock + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="DoNotMock" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'DoNotMock' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore DoNotMock ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/DoNotMockAnything.md.html b/docs/checks/DoNotMockAnything.md.html new file mode 100644 index 00000000..17e0d171 --- /dev/null +++ b/docs/checks/DoNotMockAnything.md.html @@ -0,0 +1,206 @@ + +(#) Do not add new mocks + +!!! ERROR: Do not add new mocks + This is an error. + +Id +: `DoNotMockAnything` +Summary +: Do not add new mocks +Note +: **This issue is disabled by default**; use `--enable DoNotMockAnything` +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.7.2 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/mocking/MockDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/mocking/DoNotMockMockDetectorTest.kt) +Copyright Year +: 2021 + +Mocking is almost always unnecessary and will make your tests more +brittle. Use real instances (if appropriate) or test fakes instead. This +lint is a catch-all for mocking, and has been enabled in this project to +help prevent new mocking from being added. + +(##) Options + +You can configure this lint checks using the following options: + +(###) mock-annotations + +A comma-separated list of mock annotations.. +This property should define comma-separated list of mock annotation class names (FQCN). Set this for all issues using this option. + +Default is "org.mockito.Mock,org.mockito.Spy". + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="DoNotMockAnything"> + <option name="mock-annotations" value=""org.mockito.Mock,org.mockito.Spy"" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(###) mock-factories + +A comma-separated list of mock factories (org.mockito.Mockito#methodName).. +A comma-separated list of mock factories (org.mockito.Mockito#methodName). Set this for all issues using this option. + +Default is "org.mockito.Mockito#mock,org.mockito.Mockito#spy,slack.test.mockito.MockitoHelpers#mock,slack.test.mockito.MockitoHelpersKt#mock,org.mockito.kotlin.MockingKt#mock,org.mockito.kotlin.SpyingKt#spy". + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="DoNotMockAnything"> + <option name="mock-factories" value=""org.mockito.Mockito#mock,org.mockito.Mockito#spy,slack.test.mockito.MockitoHelpers#mock,slack.test.mockito.MockitoHelpersKt#mock,org.mockito.kotlin.MockingKt#mock,org.mockito.kotlin.SpyingKt#spy"" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(###) mock-report + +If enabled, writes a mock report to /build/reports/mockdetector/mock-report.csv.. +If enabled, writes a mock report to /build/reports/mockdetector/mock-report.csv. The format of the file is a csv of (type,isError) of mocked classes. Set this for all issues using this option. + +Default is "none". + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="DoNotMockAnything"> + <option name="mock-report" value=""none"" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("DoNotMockAnything") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("DoNotMockAnything") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection DoNotMockAnything + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="DoNotMockAnything" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'DoNotMockAnything' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore DoNotMockAnything ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/DoNotMockAutoValue.md.html b/docs/checks/DoNotMockAutoValue.md.html new file mode 100644 index 00000000..31e97a83 --- /dev/null +++ b/docs/checks/DoNotMockAutoValue.md.html @@ -0,0 +1,202 @@ + +(#) AutoValue classes represent pure data classes, so mocking them should not be necessary + +!!! ERROR: AutoValue classes represent pure data classes, so mocking them should not be necessary + This is an error. + +Id +: `DoNotMockAutoValue` +Summary +: AutoValue classes represent pure data classes, so mocking them should not be necessary +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/mocking/MockDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/mocking/DoNotMockMockDetectorTest.kt) +Copyright Year +: 2021 + +`AutoValue` classes represent pure data classes, so mocking them should +not be necessary. Construct a real instance of the class instead. + +(##) Options + +You can configure this lint checks using the following options: + +(###) mock-annotations + +A comma-separated list of mock annotations.. +This property should define comma-separated list of mock annotation class names (FQCN). Set this for all issues using this option. + +Default is "org.mockito.Mock,org.mockito.Spy". + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="DoNotMockAutoValue"> + <option name="mock-annotations" value=""org.mockito.Mock,org.mockito.Spy"" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(###) mock-factories + +A comma-separated list of mock factories (org.mockito.Mockito#methodName).. +A comma-separated list of mock factories (org.mockito.Mockito#methodName). Set this for all issues using this option. + +Default is "org.mockito.Mockito#mock,org.mockito.Mockito#spy,slack.test.mockito.MockitoHelpers#mock,slack.test.mockito.MockitoHelpersKt#mock,org.mockito.kotlin.MockingKt#mock,org.mockito.kotlin.SpyingKt#spy". + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="DoNotMockAutoValue"> + <option name="mock-factories" value=""org.mockito.Mockito#mock,org.mockito.Mockito#spy,slack.test.mockito.MockitoHelpers#mock,slack.test.mockito.MockitoHelpersKt#mock,org.mockito.kotlin.MockingKt#mock,org.mockito.kotlin.SpyingKt#spy"" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(###) mock-report + +If enabled, writes a mock report to /build/reports/mockdetector/mock-report.csv.. +If enabled, writes a mock report to /build/reports/mockdetector/mock-report.csv. The format of the file is a csv of (type,isError) of mocked classes. Set this for all issues using this option. + +Default is "none". + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="DoNotMockAutoValue"> + <option name="mock-report" value=""none"" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("DoNotMockAutoValue") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("DoNotMockAutoValue") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection DoNotMockAutoValue + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="DoNotMockAutoValue" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'DoNotMockAutoValue' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore DoNotMockAutoValue ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/DoNotMockDataClass.md.html b/docs/checks/DoNotMockDataClass.md.html new file mode 100644 index 00000000..61017640 --- /dev/null +++ b/docs/checks/DoNotMockDataClass.md.html @@ -0,0 +1,202 @@ + +(#) data classes represent pure data classes, so mocking them should not be necessary + +!!! ERROR: data classes represent pure data classes, so mocking them should not be necessary + This is an error. + +Id +: `DoNotMockDataClass` +Summary +: data classes represent pure data classes, so mocking them should not be necessary +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/mocking/MockDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/mocking/DoNotMockMockDetectorTest.kt) +Copyright Year +: 2021 + +data classes represent pure data classes, so mocking them should not be +necessary. Construct a real instance of the class instead. + +(##) Options + +You can configure this lint checks using the following options: + +(###) mock-annotations + +A comma-separated list of mock annotations.. +This property should define comma-separated list of mock annotation class names (FQCN). Set this for all issues using this option. + +Default is "org.mockito.Mock,org.mockito.Spy". + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="DoNotMockDataClass"> + <option name="mock-annotations" value=""org.mockito.Mock,org.mockito.Spy"" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(###) mock-factories + +A comma-separated list of mock factories (org.mockito.Mockito#methodName).. +A comma-separated list of mock factories (org.mockito.Mockito#methodName). Set this for all issues using this option. + +Default is "org.mockito.Mockito#mock,org.mockito.Mockito#spy,slack.test.mockito.MockitoHelpers#mock,slack.test.mockito.MockitoHelpersKt#mock,org.mockito.kotlin.MockingKt#mock,org.mockito.kotlin.SpyingKt#spy". + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="DoNotMockDataClass"> + <option name="mock-factories" value=""org.mockito.Mockito#mock,org.mockito.Mockito#spy,slack.test.mockito.MockitoHelpers#mock,slack.test.mockito.MockitoHelpersKt#mock,org.mockito.kotlin.MockingKt#mock,org.mockito.kotlin.SpyingKt#spy"" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(###) mock-report + +If enabled, writes a mock report to /build/reports/mockdetector/mock-report.csv.. +If enabled, writes a mock report to /build/reports/mockdetector/mock-report.csv. The format of the file is a csv of (type,isError) of mocked classes. Set this for all issues using this option. + +Default is "none". + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="DoNotMockDataClass"> + <option name="mock-report" value=""none"" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("DoNotMockDataClass") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("DoNotMockDataClass") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection DoNotMockDataClass + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="DoNotMockDataClass" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'DoNotMockDataClass' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore DoNotMockDataClass ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/DoNotMockObjectClass.md.html b/docs/checks/DoNotMockObjectClass.md.html new file mode 100644 index 00000000..2bac1692 --- /dev/null +++ b/docs/checks/DoNotMockObjectClass.md.html @@ -0,0 +1,202 @@ + +(#) object classes are singletons, so mocking them should not be necessary + +!!! ERROR: object classes are singletons, so mocking them should not be necessary + This is an error. + +Id +: `DoNotMockObjectClass` +Summary +: object classes are singletons, so mocking them should not be necessary +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.3.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/mocking/MockDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/mocking/DoNotMockMockDetectorTest.kt) +Copyright Year +: 2021 + +object classes are global singletons, so mocking them should not be +necessary. Use the object instance instead. + +(##) Options + +You can configure this lint checks using the following options: + +(###) mock-annotations + +A comma-separated list of mock annotations.. +This property should define comma-separated list of mock annotation class names (FQCN). Set this for all issues using this option. + +Default is "org.mockito.Mock,org.mockito.Spy". + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="DoNotMockObjectClass"> + <option name="mock-annotations" value=""org.mockito.Mock,org.mockito.Spy"" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(###) mock-factories + +A comma-separated list of mock factories (org.mockito.Mockito#methodName).. +A comma-separated list of mock factories (org.mockito.Mockito#methodName). Set this for all issues using this option. + +Default is "org.mockito.Mockito#mock,org.mockito.Mockito#spy,slack.test.mockito.MockitoHelpers#mock,slack.test.mockito.MockitoHelpersKt#mock,org.mockito.kotlin.MockingKt#mock,org.mockito.kotlin.SpyingKt#spy". + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="DoNotMockObjectClass"> + <option name="mock-factories" value=""org.mockito.Mockito#mock,org.mockito.Mockito#spy,slack.test.mockito.MockitoHelpers#mock,slack.test.mockito.MockitoHelpersKt#mock,org.mockito.kotlin.MockingKt#mock,org.mockito.kotlin.SpyingKt#spy"" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(###) mock-report + +If enabled, writes a mock report to /build/reports/mockdetector/mock-report.csv.. +If enabled, writes a mock report to /build/reports/mockdetector/mock-report.csv. The format of the file is a csv of (type,isError) of mocked classes. Set this for all issues using this option. + +Default is "none". + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="DoNotMockObjectClass"> + <option name="mock-report" value=""none"" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("DoNotMockObjectClass") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("DoNotMockObjectClass") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection DoNotMockObjectClass + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="DoNotMockObjectClass" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'DoNotMockObjectClass' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore DoNotMockObjectClass ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/DoNotMockPlatformTypes.md.html b/docs/checks/DoNotMockPlatformTypes.md.html new file mode 100644 index 00000000..8120480b --- /dev/null +++ b/docs/checks/DoNotMockPlatformTypes.md.html @@ -0,0 +1,206 @@ + +(#) platform types should not be mocked + +!!! ERROR: platform types should not be mocked + This is an error. + +Id +: `DoNotMockPlatformTypes` +Summary +: platform types should not be mocked +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.4.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/mocking/MockDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/mocking/DoNotMockMockDetectorTest.kt) +Copyright Year +: 2021 + +Platform types (i.e. classes in java.*, android.*, etc) should not be +mocked. Use a real instance or fake instead. Mocking platform types like +these can lead to surprising test failures due to mocks that actually +behave differently than real instances, especially when passed into real +implementations that use them and expect them to behave in a certain +way. If using Robolectric, consider using its shadow APIs. + +(##) Options + +You can configure this lint checks using the following options: + +(###) mock-annotations + +A comma-separated list of mock annotations.. +This property should define comma-separated list of mock annotation class names (FQCN). Set this for all issues using this option. + +Default is "org.mockito.Mock,org.mockito.Spy". + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="DoNotMockPlatformTypes"> + <option name="mock-annotations" value=""org.mockito.Mock,org.mockito.Spy"" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(###) mock-factories + +A comma-separated list of mock factories (org.mockito.Mockito#methodName).. +A comma-separated list of mock factories (org.mockito.Mockito#methodName). Set this for all issues using this option. + +Default is "org.mockito.Mockito#mock,org.mockito.Mockito#spy,slack.test.mockito.MockitoHelpers#mock,slack.test.mockito.MockitoHelpersKt#mock,org.mockito.kotlin.MockingKt#mock,org.mockito.kotlin.SpyingKt#spy". + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="DoNotMockPlatformTypes"> + <option name="mock-factories" value=""org.mockito.Mockito#mock,org.mockito.Mockito#spy,slack.test.mockito.MockitoHelpers#mock,slack.test.mockito.MockitoHelpersKt#mock,org.mockito.kotlin.MockingKt#mock,org.mockito.kotlin.SpyingKt#spy"" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(###) mock-report + +If enabled, writes a mock report to /build/reports/mockdetector/mock-report.csv.. +If enabled, writes a mock report to /build/reports/mockdetector/mock-report.csv. The format of the file is a csv of (type,isError) of mocked classes. Set this for all issues using this option. + +Default is "none". + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="DoNotMockPlatformTypes"> + <option name="mock-report" value=""none"" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("DoNotMockPlatformTypes") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("DoNotMockPlatformTypes") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection DoNotMockPlatformTypes + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="DoNotMockPlatformTypes" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'DoNotMockPlatformTypes' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore DoNotMockPlatformTypes ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/DoNotMockRecordClass.md.html b/docs/checks/DoNotMockRecordClass.md.html new file mode 100644 index 00000000..dd681f34 --- /dev/null +++ b/docs/checks/DoNotMockRecordClass.md.html @@ -0,0 +1,202 @@ + +(#) record classes represent pure data classes, so mocking them should not be necessary + +!!! ERROR: record classes represent pure data classes, so mocking them should not be necessary + This is an error. + +Id +: `DoNotMockRecordClass` +Summary +: record classes represent pure data classes, so mocking them should not be necessary +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.3.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/mocking/MockDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/mocking/DoNotMockMockDetectorTest.kt) +Copyright Year +: 2021 + +record classes represent pure data classes, so mocking them should not +be necessary. Construct a real instance of the class instead. + +(##) Options + +You can configure this lint checks using the following options: + +(###) mock-annotations + +A comma-separated list of mock annotations.. +This property should define comma-separated list of mock annotation class names (FQCN). Set this for all issues using this option. + +Default is "org.mockito.Mock,org.mockito.Spy". + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="DoNotMockRecordClass"> + <option name="mock-annotations" value=""org.mockito.Mock,org.mockito.Spy"" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(###) mock-factories + +A comma-separated list of mock factories (org.mockito.Mockito#methodName).. +A comma-separated list of mock factories (org.mockito.Mockito#methodName). Set this for all issues using this option. + +Default is "org.mockito.Mockito#mock,org.mockito.Mockito#spy,slack.test.mockito.MockitoHelpers#mock,slack.test.mockito.MockitoHelpersKt#mock,org.mockito.kotlin.MockingKt#mock,org.mockito.kotlin.SpyingKt#spy". + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="DoNotMockRecordClass"> + <option name="mock-factories" value=""org.mockito.Mockito#mock,org.mockito.Mockito#spy,slack.test.mockito.MockitoHelpers#mock,slack.test.mockito.MockitoHelpersKt#mock,org.mockito.kotlin.MockingKt#mock,org.mockito.kotlin.SpyingKt#spy"" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(###) mock-report + +If enabled, writes a mock report to /build/reports/mockdetector/mock-report.csv.. +If enabled, writes a mock report to /build/reports/mockdetector/mock-report.csv. The format of the file is a csv of (type,isError) of mocked classes. Set this for all issues using this option. + +Default is "none". + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="DoNotMockRecordClass"> + <option name="mock-report" value=""none"" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("DoNotMockRecordClass") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("DoNotMockRecordClass") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection DoNotMockRecordClass + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="DoNotMockRecordClass" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'DoNotMockRecordClass' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore DoNotMockRecordClass ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/DoNotMockSealedClass.md.html b/docs/checks/DoNotMockSealedClass.md.html new file mode 100644 index 00000000..606113c4 --- /dev/null +++ b/docs/checks/DoNotMockSealedClass.md.html @@ -0,0 +1,203 @@ + +(#) sealed classes have a restricted type hierarchy, use a subtype instead + +!!! ERROR: sealed classes have a restricted type hierarchy, use a subtype instead + This is an error. + +Id +: `DoNotMockSealedClass` +Summary +: sealed classes have a restricted type hierarchy, use a subtype instead +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.3.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/mocking/MockDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/mocking/DoNotMockMockDetectorTest.kt) +Copyright Year +: 2021 + +sealed classes have a restricted type hierarchy, so creating new +unrestricted mocks will break runtime expectations. Mockito also cannot +mock sealed classes in Java 17+. Use a subtype instead. + +(##) Options + +You can configure this lint checks using the following options: + +(###) mock-annotations + +A comma-separated list of mock annotations.. +This property should define comma-separated list of mock annotation class names (FQCN). Set this for all issues using this option. + +Default is "org.mockito.Mock,org.mockito.Spy". + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="DoNotMockSealedClass"> + <option name="mock-annotations" value=""org.mockito.Mock,org.mockito.Spy"" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(###) mock-factories + +A comma-separated list of mock factories (org.mockito.Mockito#methodName).. +A comma-separated list of mock factories (org.mockito.Mockito#methodName). Set this for all issues using this option. + +Default is "org.mockito.Mockito#mock,org.mockito.Mockito#spy,slack.test.mockito.MockitoHelpers#mock,slack.test.mockito.MockitoHelpersKt#mock,org.mockito.kotlin.MockingKt#mock,org.mockito.kotlin.SpyingKt#spy". + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="DoNotMockSealedClass"> + <option name="mock-factories" value=""org.mockito.Mockito#mock,org.mockito.Mockito#spy,slack.test.mockito.MockitoHelpers#mock,slack.test.mockito.MockitoHelpersKt#mock,org.mockito.kotlin.MockingKt#mock,org.mockito.kotlin.SpyingKt#spy"" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(###) mock-report + +If enabled, writes a mock report to /build/reports/mockdetector/mock-report.csv.. +If enabled, writes a mock report to /build/reports/mockdetector/mock-report.csv. The format of the file is a csv of (type,isError) of mocked classes. Set this for all issues using this option. + +Default is "none". + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="DoNotMockSealedClass"> + <option name="mock-report" value=""none"" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("DoNotMockSealedClass") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("DoNotMockSealedClass") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection DoNotMockSealedClass + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="DoNotMockSealedClass" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'DoNotMockSealedClass' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore DoNotMockSealedClass ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/DrawAllocation.md.html b/docs/checks/DrawAllocation.md.html index 64976977..b93f25b3 100644 --- a/docs/checks/DrawAllocation.md.html +++ b/docs/checks/DrawAllocation.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files Editing @@ -44,296 +46,37 @@ Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -src/test/pkg/JavaPerformanceTest.java:31:Warning: Avoid object -allocations during draw/layout operations (preallocate and reuse -instead) [DrawAllocation] - - new String("foo"); - ----------------- - - -src/test/pkg/JavaPerformanceTest.java:32:Warning: Avoid object -allocations during draw/layout operations (preallocate and reuse -instead) [DrawAllocation] - - String s = new String("bar"); - ----------------- - - -src/test/pkg/JavaPerformanceTest.java:95:Warning: Avoid object -allocations during draw/layout operations (preallocate and reuse -instead) [DrawAllocation] - - new String("flag me"); - --------------------- - - -src/test/pkg/JavaPerformanceTest.java:101:Warning: Avoid object -allocations during draw/layout operations (preallocate and reuse -instead) [DrawAllocation] - - new String("flag me"); - --------------------- - - -src/test/pkg/JavaPerformanceTest.java:104:Warning: Avoid object -allocations during draw/layout operations (preallocate and reuse -instead) [DrawAllocation] - - Bitmap.createBitmap(100, 100, null); - ----------------------------------- - - -src/test/pkg/JavaPerformanceTest.java:105:Warning: Avoid object -allocations during draw/layout operations (preallocate and reuse -instead) [DrawAllocation] - - android.graphics.Bitmap.createScaledBitmap(null, 100, 100, false); - ----------------------------------------------------------------- - - -src/test/pkg/JavaPerformanceTest.java:106:Warning: Avoid object -allocations during draw/layout operations (preallocate and reuse -instead) [DrawAllocation] - - BitmapFactory.decodeFile(null); - ------------------------------ - - -src/test/pkg/JavaPerformanceTest.java:108:Warning: Avoid object -allocations during draw operations: Use Canvas.getClipBounds(Rect) -instead of Canvas.getClipBounds() which allocates a temporary Rect -[DrawAllocation] - - canvas.getClipBounds(); // allocates on your behalf - ---------------------- - - -src/test/pkg/JavaPerformanceTest.java:132:Warning: Avoid object -allocations during draw/layout operations (preallocate and reuse -instead) [DrawAllocation] - - new String("foo"); - ----------------- - - +src/test/pkg/MyView.java:18:Warning: Avoid object allocations during +draw/layout operations (preallocate and reuse instead) [DrawAllocation] + bitmap = Bitmap.createBitmap(100, 100, null); + ----------------------------------- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: -`src/test/pkg/JavaPerformanceTest.java`: +`src/test/pkg/MyView.java`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers package test.pkg; -import android.annotation.SuppressLint; import android.content.Context; import android.graphics.Bitmap; -import android.graphics.BitmapFactory; import android.graphics.Canvas; -import android.graphics.LinearGradient; -import android.graphics.Rect; -import android.graphics.Shader.TileMode; import android.util.AttributeSet; -import android.util.SparseArray; -import android.widget.Button; -import java.util.HashMap; -import java.util.Map; +import android.view.View; -/** Some test data for the JavaPerformanceDetector */ -@SuppressWarnings("unused") -public class JavaPerformanceTest extends Button { - public JavaPerformanceTest(Context context, AttributeSet attrs, int defStyle) { +public abstract class MyView extends View { + public MyView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } - private Rect cachedRect; - @Override - protected void onDraw(android.graphics.Canvas canvas) { + protected void onDraw(Canvas canvas) { super.onDraw(canvas); - // Various allocations: - new String("foo"); - String s = new String("bar"); - - // This one should not be reported: - @SuppressLint("DrawAllocation") - Integer i = new Integer(5); - - // Cached object initialized lazily: should not complain about these - if (cachedRect == null) { - cachedRect = new Rect(0, 0, 100, 100); - } - if (cachedRect == null || cachedRect.width() != 50) { - cachedRect = new Rect(0, 0, 50, 100); - } - - boolean b = Boolean.valueOf(true); // auto-boxing - sample(1, 2); - - // Non-allocations - super.animate(); - sample2(1, 2); - int x = 4 + '5'; - - // This will involve allocations, but we don't track - // inter-procedural stuff here - someOtherMethod(); - } - - void sample(Integer foo, int bar) { - sample2(foo, bar); + bitmap = Bitmap.createBitmap(100, 100, null); } - void sample2(int foo, int bar) { - } - - void someOtherMethod() { - // Allocations are okay here - new String("foo"); - String s = new String("bar"); - boolean b = Boolean.valueOf(true); // auto-boxing - } - - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec, - boolean x) { // wrong signature - new String("not an error"); - } - - protected void onMeasure(int widthMeasureSpec) { // wrong signature - new String("not an error"); - } - - protected void onLayout(boolean changed, int left, int top, int right, - int bottom, int wrong) { // wrong signature - new String("not an error"); - } - - protected void onLayout(boolean changed, int left, int top, int right) { - // wrong signature - new String("not an error"); - } - - @Override - protected void onLayout(boolean changed, int left, int top, int right, - int bottom) { - new String("flag me"); - } - - @SuppressWarnings("null") // not real code - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - new String("flag me"); - - // Forbidden factory methods: - Bitmap.createBitmap(100, 100, null); - android.graphics.Bitmap.createScaledBitmap(null, 100, 100, false); - BitmapFactory.decodeFile(null); - Canvas canvas = null; - canvas.getClipBounds(); // allocates on your behalf - canvas.getClipBounds(null); // NOT an error - - final int layoutWidth = getWidth(); - final int layoutHeight = getHeight(); - if (mAllowCrop && (mOverlay == null || mOverlay.getWidth() != layoutWidth || - mOverlay.getHeight() != layoutHeight)) { - mOverlay = Bitmap.createBitmap(layoutWidth, layoutHeight, Bitmap.Config.ARGB_8888); - mOverlayCanvas = new Canvas(mOverlay); - } - - if (widthMeasureSpec == 42) { - throw new IllegalStateException("Test"); // NOT an allocation - } - - // More lazy init tests - boolean initialized = false; - if (!initialized) { - new String("foo"); - initialized = true; - } - - // NOT lazy initialization - if (!initialized || mOverlay == null) { - new String("foo"); - } - } - - void factories() { - Integer i1 = new Integer(42); - Long l1 = new Long(42L); - Boolean b1 = new Boolean(true); - Character c1 = new Character('c'); - Float f1 = new Float(1.0f); - Double d1 = new Double(1.0); - - // The following should not generate errors: - Object i2 = new foo.bar.Integer(42); - Integer i3 = Integer.valueOf(42); - } - - private boolean mAllowCrop; - private Canvas mOverlayCanvas; - private Bitmap mOverlay; -private abstract class JavaPerformanceTest1 extends JavaPerformanceTest { - @Override - public void layout(int l, int t, int r, int b) { - // Using "this." to reference fields - if (this.shader == null) - this.shader = new LinearGradient(0, 0, getWidth(), 0, GRADIENT_COLORS, null, - TileMode.REPEAT); - } -} private abstract class JavaPerformanceTest2 extends JavaPerformanceTest { - @Override - public void layout(int l, int t, int r, int b) { - int width = getWidth(); - int height = getHeight(); - - if ((shader == null) || (lastWidth != width) || (lastHeight != height)) - { - lastWidth = width; - lastHeight = height; - - shader = new LinearGradient(0, 0, width, 0, GRADIENT_COLORS, null, TileMode.REPEAT); - } - } -} private abstract class JavaPerformanceTest3 extends JavaPerformanceTest { - @Override - public void layout(int l, int t, int r, int b) { - if ((shader == null) || (lastWidth != getWidth()) || (lastHeight != getHeight())) { - } - } -} - public void inefficientSparseArray() { - new SparseArray(); // Use SparseIntArray instead - new SparseArray(); // Use SparseLongArray instead - new SparseArray(); // Use SparseBooleanArray instead - new SparseArray(); // OK - } - - public void longSparseArray() { // but only minSdkVersion >= 17 or if has v4 support lib - Map myStringMap = new HashMap(); - } - - public void byteSparseArray() { // bytes easily apply to ints - Map myByteMap = new HashMap(); - } - - protected LinearGradient shader; - protected int lastWidth; - protected int lastHeight; - protected int[] GRADIENT_COLORS; - - private static class foo { - private static class bar { - private static class Integer { - public Integer(int val) { - } - } - } - } - public JavaPerformanceTest() { - super(null); - } + private Bitmap bitmap; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -341,11 +84,6 @@ [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/JavaPerformanceDetectorTest.java) for the unit tests for this check to see additional scenarios. -The above example was automatically extracted from the first unit test -found for this lint check, `JavaPerformanceDetector.test`. -To report a problem with this extracted sample, visit -https://issuetracker.google.com/issues/new?component=192708. - (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/DuplicateActivity.md.html b/docs/checks/DuplicateActivity.md.html index afa1f9ae..fda7075c 100644 --- a/docs/checks/DuplicateActivity.md.html +++ b/docs/checks/DuplicateActivity.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Manifest files Editing @@ -42,14 +44,11 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text AndroidManifest.xml:15:Error: Duplicate registration for activity com.example.helloworld.HelloWorld [DuplicateActivity] - <activity android:name="com.example.helloworld.HelloWorld" ------------------------------------------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `AndroidManifest.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -76,6 +75,40 @@ </manifest> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/values/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<!-- Copyright (C) 2007 The Android Open Source Project + + 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. +--> + +<resources> + <!-- Home --> + <string name="home_title">Home Sample</string> + <string name="show_all_apps">All</string> + + <!-- Home Menus --> + <string name="menu_wallpaper">Wallpaper</string> + <string name="menu_search">Search</string> + <string name="menu_settings">Settings</string> + <string name="sample" translatable="false">Ignore Me</string> + + <!-- Wallpaper --> + <string name="wallpaper_instructions">Tap picture to set portrait wallpaper</string> +</resources> + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ManifestDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/DuplicateDefinition.md.html b/docs/checks/DuplicateDefinition.md.html index 4f788dde..b58c3f0e 100644 --- a/docs/checks/DuplicateDefinition.md.html +++ b/docs/checks/DuplicateDefinition.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -41,14 +43,46 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/values/strings2.xml:19:Error: wallpaper_instructions has already been defined in this folder [DuplicateDefinition] - <string name="wallpaper_instructions">Tap image to set landscape wallpaper</string> ----------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Here are the relevant source files: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/values/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2007 The Android Open Source Project + + 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. +--> + +<resources> + <!-- Home --> + <string name="home_title">Home Sample</string> + <string name="show_all_apps">All</string> + + <!-- Home Menus --> + <string name="menu_wallpaper">Wallpaper</string> + <string name="menu_search">Search</string> + <string name="menu_settings">Settings</string> + <string name="sample" translatable="false">Ignore Me</string> + + <!-- Wallpaper --> + <string name="wallpaper_instructions">Tap picture to set portrait wallpaper</string> +</resources> -Here is the source file referenced above: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `res/values/strings2.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -75,6 +109,41 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/values-cs/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="UTF-8"?> +<resources xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + <string name="home_title">"Domů"</string> + <string name="show_all_apps">"Vše"</string> + <string name="menu_wallpaper">"Tapeta"</string> + <string name="menu_search">"Hledat"</string> + <!-- no translation found for menu_settings (1769059051084007158) --> + <skip /> + <string name="wallpaper_instructions">"Klepnutím na obrázek nastavíte tapetu portrétu"</string> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/values/customattr.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<resources> + <declare-styleable name="ContentFrame"> + <attr name="content" format="reference" /> + <attr name="contentId" format="reference" /> + </declare-styleable> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/values/customattr2.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<resources> + <declare-styleable name="ContentFrame"> + <attr name="content" format="reference" /> + <attr name="contentId" format="reference" /> + </declare-styleable> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/DuplicateResourceDetectorTest.java) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/DuplicateDivider.md.html b/docs/checks/DuplicateDivider.md.html index 401cc656..948738b0 100644 --- a/docs/checks/DuplicateDivider.md.html +++ b/docs/checks/DuplicateDivider.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 2.3.0 (March 2017) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ItemDecoratorDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ItemDecoratorDetectorTest.kt) -Copyright Year -: 2016 Older versions of the RecyclerView library did not include a divider decorator, but one was provided as a sample in the support demos. This @@ -42,13 +42,10 @@ Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/com/example/android/supportv7/widget/decorator/DividerItemDecoration.java:11:Warning: - Replace with android.support.v7.widget.DividerItemDecoration? +Replace with android.support.v7.widget.DividerItemDecoration? [DuplicateDivider] - public abstract class DividerItemDecoration extends RecyclerView.ItemDecoration { --------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/DuplicateIds.md.html b/docs/checks/DuplicateIds.md.html index da242b91..9bf2d504 100644 --- a/docs/checks/DuplicateIds.md.html +++ b/docs/checks/DuplicateIds.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -40,11 +42,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/duplicate.xml:5:Error: Duplicate id @+id/android_logo, already defined earlier in this layout [DuplicateIds] - <ImageButton android:id="@+id/android_logo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/android_button" android:focusable="false" android:clickable="false" android:layout_weight="1.0" /> ------------------------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/DuplicateIncludedIds.md.html b/docs/checks/DuplicateIncludedIds.md.html index 79a4e6ae..347edfac 100644 --- a/docs/checks/DuplicateIncludedIds.md.html +++ b/docs/checks/DuplicateIncludedIds.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -42,14 +44,11 @@ included multiple times in layout/layout1.xml: [layout/layout1.xml defines @+id/button2, layout/layout1.xml => layout/layout2.xml => layout/layout4.xml defines @+id/button2] [DuplicateIncludedIds] - <include ^ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `res/layout/layout1.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -78,6 +77,77 @@ </LinearLayout> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/layout/layout2.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" > + + <RadioButton + android:id="@+id/radioButton1" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="RadioButton" /> + + <include + android:layout_width="wrap_content" + android:layout_height="wrap_content" + layout="@layout/layout3" /> + + <include + android:layout_width="wrap_content" + android:layout_height="wrap_content" + layout="@layout/layout4" /> + +</LinearLayout> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/layout/layout3.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" > + + <Button + android:id="@+id/button1" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Button" /> + + <CheckBox + android:id="@+id/checkBox1" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="CheckBox" /> + +</LinearLayout> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/layout/layout4.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" > + + <Button + android:id="@+id/button1" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Button" /> + + <Button + android:id="@+id/button2" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Button" /> + +</LinearLayout> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/DuplicateIdDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/DuplicatePlatformClasses.md.html b/docs/checks/DuplicatePlatformClasses.md.html index c6480026..50748cbd 100644 --- a/docs/checks/DuplicatePlatformClasses.md.html +++ b/docs/checks/DuplicatePlatformClasses.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.0.0 (October 2017) Affects : Gradle build files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GradleDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) -Copyright Year -: 2014 There are a number of libraries that duplicate not just functionality of the Android platform but using the exact same class names as the ones @@ -45,6 +45,92 @@ !!! Tip This lint check has an associated quickfix available in the IDE. +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +build.gradle:3:Error: xpp3 defines classes that conflict with classes +now provided by Android. Solutions include finding newer versions or +alternative libraries that don't have the same problem (for example, for +httpclient use HttpUrlConnection or okhttp instead), or repackaging the +library using something like jarjar. [DuplicatePlatformClasses] + implementation 'xpp3:xpp3:1.1.4c' + --------------------------------- +build.gradle:4:Error: commons-logging defines classes that conflict with +classes now provided by Android. Solutions include finding newer +versions or alternative libraries that don't have the same problem (for +example, for httpclient use HttpUrlConnection or okhttp instead), or +repackaging the library using something like jarjar. +[DuplicatePlatformClasses] + implementation 'commons-logging:commons-logging:1.2' + ---------------------------------------------------- +build.gradle:5:Error: xmlParserAPIs defines classes that conflict with +classes now provided by Android. Solutions include finding newer +versions or alternative libraries that don't have the same problem (for +example, for httpclient use HttpUrlConnection or okhttp instead), or +repackaging the library using something like jarjar. +[DuplicatePlatformClasses] + implementation 'xerces:xmlParserAPIs:2.6.2' + ------------------------------------------- +build.gradle:6:Error: json defines classes that conflict with classes +now provided by Android. Solutions include finding newer versions or +alternative libraries that don't have the same problem (for example, for +httpclient use HttpUrlConnection or okhttp instead), or repackaging the +library using something like jarjar. [DuplicatePlatformClasses] + implementation 'org.json:json:20170516' + --------------------------------------- +build.gradle:7:Error: opengl-api defines classes that conflict with +classes now provided by Android. Solutions include finding newer +versions or alternative libraries that don't have the same problem (for +example, for httpclient use HttpUrlConnection or okhttp instead), or +repackaging the library using something like jarjar. +[DuplicatePlatformClasses] + implementation 'org.khronos:opengl-api:gl1.1-android-2.1_r1' + ------------------------------------------------------------ +build.gradle:8:Error: android defines classes that conflict with classes +now provided by Android. Solutions include finding newer versions or +alternative libraries that don't have the same problem (for example, for +httpclient use HttpUrlConnection or okhttp instead), or repackaging the +library using something like jarjar. [DuplicatePlatformClasses] + implementation 'com.google.android:android:4.1.1.4' + --------------------------------------------------- +build.gradle:9:Error: httpclient defines classes that conflict with +classes now provided by Android. Solutions include finding newer +versions or alternative libraries that don't have the same problem (for +example, for httpclient use HttpUrlConnection or okhttp instead), or +repackaging the library using something like jarjar. +[DuplicatePlatformClasses] + compile group: 'org.apache.httpcomponents', + ^ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`build.gradle`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~groovy linenumbers +dependencies { + implementation 'my.indirect.dependency:myname:1.2.3' + implementation 'xpp3:xpp3:1.1.4c' + implementation 'commons-logging:commons-logging:1.2' + implementation 'xerces:xmlParserAPIs:2.6.2' + implementation 'org.json:json:20170516' + implementation 'org.khronos:opengl-api:gl1.1-android-2.1_r1' + implementation 'com.google.android:android:4.1.1.4' + compile group: 'org.apache.httpcomponents', + name: 'httpclient', + version: '4.5.3' +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `GradleDetector.testDuplicateWarnings`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=192708. + (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/DuplicateStrings.md.html b/docs/checks/DuplicateStrings.md.html index ad32f506..65b6a302 100644 --- a/docs/checks/DuplicateStrings.md.html +++ b/docs/checks/DuplicateStrings.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.3.0 (January 2019) Affects : Resource files Editing @@ -30,8 +32,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/StringCasingDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/StringCasingDetectorTest.kt) -Copyright Year -: 2018 Duplicate strings can make applications larger unnecessarily. @@ -47,20 +47,14 @@ HELLO, used in hello_caps and hello. Use android:inputType or android:capitalize to treat these as the same and avoid string duplication. [DuplicateStrings] - <string name="hello">hello</string> ----------------------------------- - - res/values/duplicate_strings.xml:5:Warning: Duplicate string value Hello World, used in hello_world and title_casing_hello_world. Use android:inputType or android:capitalize to treat these as the same and avoid string duplication. [DuplicateStrings] - <string name="hello_world">hello world</string> ----------------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/DuplicateUsesFeature.md.html b/docs/checks/DuplicateUsesFeature.md.html index 4fd4edb0..f9e0be48 100644 --- a/docs/checks/DuplicateUsesFeature.md.html +++ b/docs/checks/DuplicateUsesFeature.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Manifest files Editing @@ -37,14 +39,11 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text AndroidManifest.xml:9:Warning: Duplicate declaration of uses-feature android.hardware.camera [DuplicateUsesFeature] - <uses-feature android:name="android.hardware.camera"/> -------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `AndroidManifest.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -66,6 +65,40 @@ </manifest> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/values/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<!-- Copyright (C) 2007 The Android Open Source Project + + 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. +--> + +<resources> + <!-- Home --> + <string name="home_title">Home Sample</string> + <string name="show_all_apps">All</string> + + <!-- Home Menus --> + <string name="menu_wallpaper">Wallpaper</string> + <string name="menu_search">Search</string> + <string name="menu_settings">Settings</string> + <string name="sample" translatable="false">Ignore Me</string> + + <!-- Wallpaper --> + <string name="wallpaper_instructions">Tap picture to set portrait wallpaper</string> +</resources> + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ManifestDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/EagerGradleConfiguration.md.html b/docs/checks/EagerGradleConfiguration.md.html new file mode 100644 index 00000000..da544e11 --- /dev/null +++ b/docs/checks/EagerGradleConfiguration.md.html @@ -0,0 +1,147 @@ + +(#) Avoid using eager task APIs + +!!! ERROR: Avoid using eager task APIs + This is an error. + +Id +: `EagerGradleConfiguration` +Summary +: Avoid using eager task APIs +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: Android Open Source Project +Identifier +: androidx.lint:lint-gradle +Feedback +: https://issuetracker.google.com/issues/new?component=1147525 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.lint:lint-gradle](androidx_lint_lint-gradle.md.html) +Since +: 1.0.0-alpha02 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/lint/lint-gradle/src/main/java/androidx/lint/gradle/DiscouragedGradleMethodDetector.kt) +Copyright Year +: 2024 + +Lazy APIs defer creating and configuring objects until they are needed +instead of +doing unnecessary work in the configuration phase. +See +https://docs.gradle.org/current/userguide/task_configuration_avoidance.html +for +more details. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.lint:lint-gradle:1.0.0-alpha04") + +// build.gradle +implementation 'androidx.lint:lint-gradle:1.0.0-alpha04' + +// build.gradle.kts with version catalogs: +implementation(libs.lint.gradle) + +# libs.versions.toml +[versions] +lint-gradle = "1.0.0-alpha04" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-gradle = { + module = "androidx.lint:lint-gradle", + version.ref = "lint-gradle" +} +``` + +1.0.0-alpha04 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.lint:lint-gradle](androidx_lint_lint-gradle.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("EagerGradleConfiguration") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("EagerGradleConfiguration") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection EagerGradleConfiguration + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="EagerGradleConfiguration" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'EagerGradleConfiguration' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore EagerGradleConfiguration ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/EasterEgg.md.html b/docs/checks/EasterEgg.md.html index fb0eb952..f8de6ffd 100644 --- a/docs/checks/EasterEgg.md.html +++ b/docs/checks/EasterEgg.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Gradle build files, Kotlin and Java files, manifest files, property files and resource files Editing @@ -42,19 +44,13 @@ src/test/pkg/Hidden.java:5:Warning: Code might be hidden here; found unicode escape sequence which is interpreted as comment end, compiled code follows [EasterEgg] - /* \u002a\u002f static { System.out.println("I'm executed on class load"); } \u002f\u002a */ ------------ - - src/test/pkg/Hidden.java:6:Warning: Code might be hidden here; found unicode escape sequence which is interpreted as comment end, compiled code follows [EasterEgg] - /* \u002A\U002F static { System.out.println("I'm executed on class load"); } \u002f\u002a */ ------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/EditedTargetSdkVersion.md.html b/docs/checks/EditedTargetSdkVersion.md.html new file mode 100644 index 00000000..494578e4 --- /dev/null +++ b/docs/checks/EditedTargetSdkVersion.md.html @@ -0,0 +1,101 @@ + +(#) Manually Edited TargetSdkVersion + +!!! ERROR: Manually Edited TargetSdkVersion + This is an error. + +Id +: `EditedTargetSdkVersion` +Summary +: Manually Edited TargetSdkVersion +Severity +: Error +Category +: Correctness +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.1.0 (July 2023) +Affects +: Gradle build files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GradleDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) + +Updating the `targetSdkVersion` of an app is seemingly easy: just +increment the `targetSdkVersion` number in the manifest file! + +But that's not actually safe. The `targetSdkVersion` controls a wide +range of behaviors that change from release to release, and to update, +you should carefully consult the documentation to see what has changed, +how your app may need to adjust, and then of course, carefully test +everything. + +In new versions of Android Studio, there is a special migration +assistant, available from the tools menu (and as a quickfix from this +lint warning) which analyzes your specific app and filters the set of +applicable migration steps to those needed for your app. + +This lint check does something very simple: it just detects whether it +looks like you've manually edited the targetSdkVersion field in a +build.gradle file. Obviously, as part of doing the above careful steps, +you may end up editing the value, which would trigger the check -- and +it's safe to ignore it; this lint check *only* runs in the IDE, not from +the command line; it's sole purpose to bring *awareness* to the (many) +developers who haven't been aware of this issue and have just bumped the +targetSdkVersion, recompiled, and uploaded their updated app to the +Google Play Store, sometimes leading to crashes or other problems on +newer devices. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection EditedTargetSdkVersion + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="EditedTargetSdkVersion" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'EditedTargetSdkVersion' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore EditedTargetSdkVersion ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/EllipsizeMaxLines.md.html b/docs/checks/EllipsizeMaxLines.md.html index 2884fff4..6de85fd2 100644 --- a/docs/checks/EllipsizeMaxLines.md.html +++ b/docs/checks/EllipsizeMaxLines.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.0.0 (October 2017) Affects : Resource files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/EllipsizeMaxLinesDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/EllipsizeMaxLinesDetectorTest.java) -Copyright Year -: 2017 Combining `ellipsize` and `maxLines=1` can lead to crashes on some devices. Earlier versions of lint recommended replacing @@ -45,18 +45,12 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/sample.xml:9:Error: Combining ellipsize=start and lines=1 can lead to crashes. Use singleLine=true instead. [EllipsizeMaxLines] - android:lines="1" ----------------- - - res/layout/sample.xml:16:Error: Combining ellipsize=start and maxLines=1 can lead to crashes. Use singleLine=true instead. [EllipsizeMaxLines] - android:maxLines="1" -------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/EmptyNavDeepLink.md.html b/docs/checks/EmptyNavDeepLink.md.html index 58735ef8..542850ce 100644 --- a/docs/checks/EmptyNavDeepLink.md.html +++ b/docs/checks/EmptyNavDeepLink.md.html @@ -1,13 +1,13 @@ -(#) NavDeepLink must define an uri, action, and/or mimetype to be valid. +(#) NavDeepLink must define an uri, action, and/or mimetype to be valid -!!! ERROR: NavDeepLink must define an uri, action, and/or mimetype to be valid. +!!! ERROR: NavDeepLink must define an uri, action, and/or mimetype to be valid This is an error. Id : `EmptyNavDeepLink` Summary -: NavDeepLink must define an uri, action, and/or mimetype to be valid. +: NavDeepLink must define an uri, action, and/or mimetype to be valid Severity : Error Category @@ -20,6 +20,14 @@ : androidx.navigation.common Feedback : https://issuetracker.google.com/issues/new?component=409828 +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.7+ +Artifact +: [androidx.navigation:navigation-common](androidx_navigation_navigation-common.md.html) +Since +: 2.6.0 Affects : Kotlin and Java files Editing @@ -41,14 +49,11 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/com/example/test.kt:6:Error: Creation of empty NavDeepLink [EmptyNavDeepLink] - navDeepLink { } ----------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `src/com/example/test.kt`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers @@ -61,6 +66,13 @@ } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/androidx/navigation/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package androidx.navigation + +public fun navDeepLink(deepLinkBuilder: NavDeepLinkDslBuilder.() -> Unit): NavDeepLink {} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/navigation/navigation-common-lint/src/test/java/androidx/navigation/common/lint/EmptyNavDeepLinkDetectorTest.kt) for the unit tests for this check to see additional scenarios. @@ -70,6 +82,40 @@ To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=409828. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.navigation:navigation-common:2.9.0-rc01") + +// build.gradle +implementation 'androidx.navigation:navigation-common:2.9.0-rc01' + +// build.gradle.kts with version catalogs: +implementation(libs.navigation.common) + +# libs.versions.toml +[versions] +navigation-common = "2.9.0-rc01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +navigation-common = { + module = "androidx.navigation:navigation-common", + version.ref = "navigation-common" +} +``` + +2.9.0-rc01 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.navigation:navigation-common](androidx_navigation_navigation-common.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/EmptySuperCall.md.html b/docs/checks/EmptySuperCall.md.html index 1ae0eae1..3dabc18d 100644 --- a/docs/checks/EmptySuperCall.md.html +++ b/docs/checks/EmptySuperCall.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.3.0 (September 2022) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/EmptySuperDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/EmptySuperDetectorTest.kt) -Copyright Year -: 2022 For methods annotated with `@EmptySuper`, overriding methods should not also call the super implementation, either because it is empty, or @@ -40,11 +40,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/ParentClass.kt:22:Warning: No need to call super.someOtherMethod; the super method is defined to be empty [EmptySuperCall] - super.someOtherMethod(arg) // ERROR --------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/EnforceUTF8.md.html b/docs/checks/EnforceUTF8.md.html index da8aa96a..552311db 100644 --- a/docs/checks/EnforceUTF8.md.html +++ b/docs/checks/EnforceUTF8.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -49,11 +51,8 @@ res/layout/encoding.xml:1:Error: iso-latin-1: Not using UTF-8 as the file encoding. This can lead to subtle bugs with non-ascii characters [EnforceUTF8] - <?xml version="1.0" encoding="iso-latin-1"?> ----------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/EnqueueWork.md.html b/docs/checks/EnqueueWork.md.html index 3e5028ac..5c21c3fc 100644 --- a/docs/checks/EnqueueWork.md.html +++ b/docs/checks/EnqueueWork.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.2.0 (September 2018) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/WorkManagerDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/WorkManagerDetectorTest.kt) -Copyright Year -: 2018 `WorkContinuations` cannot be enqueued automatically. You must call `enqueue()` on a `WorkContinuation` to have it and its parent @@ -39,39 +39,24 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/WorkManagerTest.java:15:Warning: WorkContinuation cont not enqueued: did you forget to call enqueue()? [EnqueueWork] - WorkContinuation cont = workManager.beginWith(workRequest1, workRequest2); // ERROR ------------------------------------------------- - - src/test/pkg/WorkManagerTest.java:22:Warning: WorkContinuation not enqueued: did you forget to call enqueue()? [EnqueueWork] - workManager.beginWith(workRequest1, workRequest2); // ERROR ------------------------------------------------- - - src/test/pkg/WorkManagerTest.java:46:Warning: WorkContinuation cont2 not enqueued: did you forget to call enqueue()? [EnqueueWork] - WorkContinuation cont2 = cont1.then(workRequest3).then(workRequest4); // ERROR ------------------------------------------- - - src/test/pkg/WorkManagerTest.java:47:Warning: WorkContinuation cont3 not enqueued: did you forget to call enqueue()? [EnqueueWork] - WorkContinuation cont3 = cont1.then(workRequest5); // ERROR ------------------------ - - src/test/pkg/WorkManagerTest.java:59:Warning: WorkContinuation cont4 not enqueued: did you forget to call enqueue()? [EnqueueWork] - WorkContinuation cont4 = WorkContinuation.combine(workRequest6, cont2, cont3); // ERROR ---------------------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/EnsureInitializerMetadata.md.html b/docs/checks/EnsureInitializerMetadata.md.html index 0fce01c9..7b1f527f 100644 --- a/docs/checks/EnsureInitializerMetadata.md.html +++ b/docs/checks/EnsureInitializerMetadata.md.html @@ -1,7 +1,7 @@ -(#) Every Initializer needs to be accompanied by a corresponding entry in the AndroidManifest.xml file. +(#) Every Initializer needs to be accompanied by a corresponding entry in the AndroidManifest.xml file -!!! ERROR: Every Initializer needs to be accompanied by a corresponding entry in the AndroidManifest.xml file. +!!! ERROR: Every Initializer needs to be accompanied by a corresponding entry in the AndroidManifest.xml file This is an error, and is also enforced at build time when supported by the build system. For Android this means it will run during release builds. @@ -9,7 +9,7 @@ Id : `EnsureInitializerMetadata` Summary -: Every Initializer needs to be accompanied by a corresponding entry in the AndroidManifest.xml file. +: Every Initializer needs to be accompanied by a corresponding entry in the AndroidManifest.xml file Severity : Fatal Category @@ -22,18 +22,62 @@ : androidx.startup Feedback : https://issuetracker.google.com/issues/new?component=823348 +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [androidx.startup:startup-runtime](androidx_startup_startup-runtime.md.html) +Since +: 1.0.0 Affects : Kotlin and Java files and manifest files Editing : This check can *not* run live in the IDE editor Implementation : [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/startup/startup-runtime-lint/src/main/java/androidx/startup/lint/EnsureInitializerMetadataDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/startup/startup-runtime-lint/src/test/java/androidx/startup/lint/EnsureInitializerMetadataTest.kt) Copyright Year : 2020 When a library defines a Initializer, it needs to be accompanied by a corresponding entry in the AndroidManifest.xml file. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.startup:startup-runtime:1.2.0") + +// build.gradle +implementation 'androidx.startup:startup-runtime:1.2.0' + +// build.gradle.kts with version catalogs: +implementation(libs.startup.runtime) + +# libs.versions.toml +[versions] +startup-runtime = "1.2.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +startup-runtime = { + module = "androidx.startup:startup-runtime", + version.ref = "startup-runtime" +} +``` + +1.2.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.startup:startup-runtime](androidx_startup_startup-runtime.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/EnsureInitializerNoArgConstr.md.html b/docs/checks/EnsureInitializerNoArgConstr.md.html index 6c6c6f80..6ee46b41 100644 --- a/docs/checks/EnsureInitializerNoArgConstr.md.html +++ b/docs/checks/EnsureInitializerNoArgConstr.md.html @@ -22,17 +22,93 @@ : androidx.startup Feedback : https://issuetracker.google.com/issues/new?component=823348 +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [androidx.startup:startup-runtime](androidx_startup_startup-runtime.md.html) +Since +: 1.0.0 Affects : Kotlin and Java files Editing : This check runs on the fly in the IDE editor Implementation : [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/startup/startup-runtime-lint/src/main/java/androidx/startup/lint/InitializerConstructorDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/startup/startup-runtime-lint/src/test/java/androidx/startup/lint/InitializerConstructorTest.kt) Copyright Year : 2020 Every `Initializer` must have a no argument constructor. +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +com/example/TestInitializer.kt:5:Error: Missing Initializer no-arg +constructor [EnsureInitializerNoArgConstr] +class TestInitializer(val int: Int): Initializer<Unit> { +^ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`com/example/TestInitializer.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package com.example + +import androidx.startup.Initializer + +class TestInitializer(val int: Int): Initializer { + +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/startup/startup-runtime-lint/src/test/java/androidx/startup/lint/InitializerConstructorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `InitializerConstructorDetector.testFailureWhenZeroNoArgumentConstructorsArePresent`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=823348. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.startup:startup-runtime:1.2.0") + +// build.gradle +implementation 'androidx.startup:startup-runtime:1.2.0' + +// build.gradle.kts with version catalogs: +implementation(libs.startup.runtime) + +# libs.versions.toml +[versions] +startup-runtime = "1.2.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +startup-runtime = { + module = "androidx.startup:startup-runtime", + version.ref = "startup-runtime" +} +``` + +1.2.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.startup:startup-runtime](androidx_startup_startup-runtime.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/ErroneousLayoutAttribute.md.html b/docs/checks/ErroneousLayoutAttribute.md.html new file mode 100644 index 00000000..81d27d1d --- /dev/null +++ b/docs/checks/ErroneousLayoutAttribute.md.html @@ -0,0 +1,153 @@ + +(#) Layout attribute that's not applicable to a particular view + +!!! WARNING: Layout attribute that's not applicable to a particular view + This is a warning. + +Id +: `ErroneousLayoutAttribute` +Summary +: Layout attribute that's not applicable to a particular view +Severity +: Warning +Category +: Correctness +Platform +: Android +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html) +Since +: 0.24.0 +Affects +: Resource files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/main/kotlin/com/vanniktech/lintrules/android/ErroneousLayoutAttributeDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/ErroneousLayoutAttributeDetectorTest.kt) + +Flags if a layout attribute is not applicable to a particular view. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +res/layout/ids.xml:5:Warning: Attribute is erroneous on FrameLayout +[ErroneousLayoutAttribute] + android:orientation="horizontal" + -------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`res/layout/ids.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<FrameLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:orientation="horizontal" + /> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/ErroneousLayoutAttributeDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `ErroneousLayoutAttributeDetector.erroneousFrameLayoutOrientation`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-android:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-android:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.android) + +# libs.versions.toml +[versions] +lint-rules-android = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-android = { + module = "com.vanniktech:lint-rules-android", + version.ref = "lint-rules-android" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute + `tools:ignore="ErroneousLayoutAttribute"` on the problematic XML + element (or one of its enclosing elements). You may also need to add + the following namespace declaration on the root element in the XML + file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ErroneousLayoutAttribute" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ErroneousLayoutAttribute' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ErroneousLayoutAttribute ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ErrorProneDoNotMockUsage.md.html b/docs/checks/ErrorProneDoNotMockUsage.md.html new file mode 100644 index 00000000..37772d7c --- /dev/null +++ b/docs/checks/ErrorProneDoNotMockUsage.md.html @@ -0,0 +1,203 @@ + +(#) Use Slack's internal `@DoNotMock` annotation + +!!! ERROR: Use Slack's internal `@DoNotMock` annotation + This is an error. + +Id +: `ErrorProneDoNotMockUsage` +Summary +: Use Slack's internal `@DoNotMock` annotation +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/mocking/ErrorProneDoNotMockDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/mocking/DoNotMockUsageDetectorTest.kt) +Copyright Year +: 2021 + +While error-prone has a `@DoNotMock` annotation, prefer to use Slack's +internal one as it's not specific to error-prone and won't go away in a +Java-less world. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/test/TestClass.kt:10:Error: Use Slack's internal @DoNotMock +annotation. [ErrorProneDoNotMockUsage] +@com.google.errorprone.annotations.DoNotMock("Use fake()") +---------------------------------------------------------- +src/slack/test/TestClass.kt:20:Error: Use Slack's internal @DoNotMock +annotation. [ErrorProneDoNotMockUsage] +@DoNotMock +---------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/test/TestClass.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.test + +import com.google.errorprone.annotations.DoNotMock + +@slack.lint.annotations.DoNotMock("Use fake()") +interface TestClass { + fun fake(): TestClass? = null +} + +@com.google.errorprone.annotations.DoNotMock("Use fake()") +interface TestClass2 { + fun fake(): TestClass2? = null +} + +@slack.lint.annotations.DoNotMock +interface TestClass3 { + fun fake(): TestClass3? = null +} + +@DoNotMock +interface TestClass4 { + fun fake(): TestClass4? = null +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/mocking/DoNotMockUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `ErrorProneDoNotMockDetector.kotlinTests`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ErrorProneDoNotMockUsage") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ErrorProneDoNotMockUsage") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ErrorProneDoNotMockUsage + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ErrorProneDoNotMockUsage" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ErrorProneDoNotMockUsage' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ErrorProneDoNotMockUsage ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ExactAlarm.md.html b/docs/checks/ExactAlarm.md.html new file mode 100644 index 00000000..08e37cdf --- /dev/null +++ b/docs/checks/ExactAlarm.md.html @@ -0,0 +1,148 @@ + +(#) Invalid Usage of Exact Alarms + +!!! ERROR: Invalid Usage of Exact Alarms + This is an error. + +Id +: `ExactAlarm` +Summary +: Invalid Usage of Exact Alarms +Severity +: Error +Category +: Correctness +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.1.0 (July 2023) +Affects +: Kotlin and Java files and manifest files +Editing +: This check runs on the fly in the IDE editor +See +: https://developer.android.com/training/scheduling/alarms +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AlarmDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AlarmDetectorTest.kt) + +The `USE_EXACT_ALARM` permission is only available when targeting API +level 33 and above. Also, note that this permission is only permitted +for apps whose core functionality requires precisely-timed actions for +user facing features. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +AndroidManifest.xml:2:Error: USE_EXACT_ALARM can only be used when +targeting API level 33 or higher [ExactAlarm] + <uses-permission android:name="android.permission.USE_EXACT_ALARM" /> + ---------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`AndroidManifest.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<manifest xmlns:android="http://schemas.android.com/apk/res/android"> + <uses-permission android:name="android.permission.USE_EXACT_ALARM" /> + <uses-sdk android:targetSdkVersion="32" /> +</manifest> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AlarmDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `AlarmDetector.testExactAlarmPermissions`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=192708. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute `tools:ignore="ExactAlarm"` on the + problematic XML element (or one of its enclosing elements). You may + also need to add the following namespace declaration on the root + element in the XML file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <manifest xmlns:tools="http://schemas.android.com/tools"> + ... + <uses-permission tools:ignore="ExactAlarm" .../> + ... + </manifest> + ``` + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ExactAlarm") + fun method() { + setRepeating(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ExactAlarm") + void method() { + setRepeating(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ExactAlarm + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ExactAlarm" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ExactAlarm' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ExactAlarm ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ExceptionMessage.md.html b/docs/checks/ExceptionMessage.md.html new file mode 100644 index 00000000..57435080 --- /dev/null +++ b/docs/checks/ExceptionMessage.md.html @@ -0,0 +1,184 @@ + +(#) Please provide a string for the `lazyMessage` parameter + +!!! ERROR: Please provide a string for the `lazyMessage` parameter + This is an error. + +Id +: `ExceptionMessage` +Summary +: Please provide a string for the `lazyMessage` parameter +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.6.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/ExceptionMessageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/ExceptionMessageDetectorTest.kt) +Copyright Year +: 2023 + +Calls to `check()`, `checkNotNull()`, `require()` and `requireNotNull()` +should include a message string that can be used to debug issues +experienced by users. + +When we read user-supplied logs, the line numbers are sometimes +notsufficient to determine the cause of a bug. Inline functions +cansometimes make it hard to determine which file threw an +exception.Consider supplying a `lazyMessage` parameter to identify the +`check()`or `require()` call. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test/test.kt:5:Error: Please specify a lazyMessage param for check +[ExceptionMessage] + check(true) + ----- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test + +fun content() { + check(true) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/ExceptionMessageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `ExceptionMessageDetector.checkWithoutMessage`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ExceptionMessage") + fun method() { + check(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ExceptionMessage") + void method() { + check(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ExceptionMessage + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ExceptionMessage" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ExceptionMessage' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ExceptionMessage ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ExifInterface.md.html b/docs/checks/ExifInterface.md.html index 7c4e391f..ac63734a 100644 --- a/docs/checks/ExifInterface.md.html +++ b/docs/checks/ExifInterface.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.0.0 (October 2017) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ExifInterfaceDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ExifInterfaceDetectorTest.java) -Copyright Year -: 2016 The `android.media.ExifInterface` implementation has some known security bugs in older versions of Android. There is a new implementation @@ -40,27 +40,18 @@ src/test/pkg/ExifUsage.java:3:Warning: Avoid using android.media.ExifInterface; use androidx.exifinterface.media.ExifInterface instead [ExifInterface] - import android.media.ExifInterface; --------------------------- - - src/test/pkg/ExifUsage.java:13:Warning: Avoid using android.media.ExifInterface; use androidx.exifinterface.media.ExifInterface instead [ExifInterface] - android.media.ExifInterface exif2 = --------------------------- - - src/test/pkg/ExifUsage.java:14:Warning: Avoid using android.media.ExifInterface; use androidx.exifinterface.media.ExifInterface instead [ExifInterface] - new android.media.ExifInterface(path); --------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/ExpensiveAssertion.md.html b/docs/checks/ExpensiveAssertion.md.html index a519bbf2..de35e96c 100644 --- a/docs/checks/ExpensiveAssertion.md.html +++ b/docs/checks/ExpensiveAssertion.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 4.0.0 (May 2020) Affects : Kotlin and Java files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AssertDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AssertDetectorTest.kt) -Copyright Year -: 2014 In Kotlin, assertions are not handled the same way as from the Java programming language. In particular, they're just implemented as a @@ -80,14 +80,11 @@ always evaluated, even when assertions are off. Consider surrounding assertion with if (javaClass.desiredAssertionStatus()) { assert(...) } [ExpensiveAssertion] - assert(expensive()) // WARN ----------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `src/test/pkg/AssertTest.kt`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers @@ -132,6 +129,42 @@ } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +fun testExpensive() { + assert(expensive()) // no suggestion to surround with javaClass from toplevel + assert(cheap()) + assert(cheap2(0)) + assert(cheap3()) +} +private fun expensive(): Boolean { + Thread.sleep(500) + return true +} + +const val DEBUGGING = false +private fun cheap(): Boolean { + return DEBUGGING +} +private fun cheap2(x: Int): Boolean = x < 10 +private fun cheap3() = test.pkg.Utils.isDiagnosing() + +fun castOkay(foo: Any) { + assert(foo is String) // OK +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/Utils.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; +public class Utils { + public static final boolean DIAGNOSE = false; + public static boolean isDiagnosing() { + return DIAGNOSE; + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AssertDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/ExperimentalAnnotationRetention.md.html b/docs/checks/ExperimentalAnnotationRetention.md.html index 393fc52d..c3b2097e 100644 --- a/docs/checks/ExperimentalAnnotationRetention.md.html +++ b/docs/checks/ExperimentalAnnotationRetention.md.html @@ -20,6 +20,14 @@ : androidx.annotation.experimental Feedback : https://issuetracker.google.com/issues/new?component=459778 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.annotation:annotation-experimental](androidx_annotation_annotation-experimental.md.html) +Since +: 1.2.0 Affects : Kotlin and Java files Editing @@ -35,6 +43,40 @@ (`CLASS`) retention, while Kotlin-sourced annotations should use `BINARY` retention. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.annotation:annotation-experimental:1.5.0-rc01") + +// build.gradle +implementation 'androidx.annotation:annotation-experimental:1.5.0-rc01' + +// build.gradle.kts with version catalogs: +implementation(libs.annotation.experimental) + +# libs.versions.toml +[versions] +annotation-experimental = "1.5.0-rc01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +annotation-experimental = { + module = "androidx.annotation:annotation-experimental", + version.ref = "annotation-experimental" +} +``` + +1.5.0-rc01 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.annotation:annotation-experimental](androidx_annotation_annotation-experimental.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/ExpiredTargetSdkVersion.md.html b/docs/checks/ExpiredTargetSdkVersion.md.html index e8eae0b0..9d37833d 100644 --- a/docs/checks/ExpiredTargetSdkVersion.md.html +++ b/docs/checks/ExpiredTargetSdkVersion.md.html @@ -20,8 +20,10 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.2.0 (September 2018) Affects -: Gradle build files +: Gradle build files, TOML files and manifest files Editing : This check runs on the fly in the IDE editor See @@ -32,16 +34,11 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GradleDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) -Copyright Year -: 2014 -As of the second half of 2018, Google Play requires that new apps and -app updates target API level 26 or higher. - -Configuring your app to target a recent API level ensures that users -benefit from significant security and performance improvements, while -still allowing your app to run on older Android versions (down to the -`minSdkVersion`). +Configuring your app or sdk to target a recent API level ensures that +users benefit from significant security and performance improvements, +while still allowing your app to run on older Android versions (down to +the `minSdkVersion`). To update your `targetSdkVersion`, follow the steps from "Meeting Google Play requirements for target API level", @@ -50,6 +47,44 @@ !!! Tip This lint check has an associated quickfix available in the IDE. +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +../gradle/libs.versions.toml:2:Error: Google Play requires that apps +target API level 33 or higher. [ExpiredTargetSdkVersion] +targetSdk = "30" # ERROR 1 + ---- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`settings.gradle.kts`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +android { +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`../gradle/libs.versions.toml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~toml linenumbers +[versions] +targetSdk = "30" # ERROR 1 + +#noinspection ExpiredTargetSdkVersion +targetSdkVersion = "30" # OK 1 +#noinspection ExpiringTargetSdkVersion +target_sdk_version = "30" # OK 2 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `GradleDetector.testTargetExpiringViaToml`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=192708. + (##) Suppressing You can suppress false positives using one of the following mechanisms: @@ -61,6 +96,13 @@ problematicStatement() ``` +* Adding the suppression attribute + `tools:ignore="ExpiredTargetSdkVersion"` on the problematic XML + element (or one of its enclosing elements). You may also need to add + the following namespace declaration on the root element in the XML + file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + * Using a special `lint.xml` file in the source tree which turns off the check in that folder and any sub folder. A simple file might look like this: diff --git a/docs/checks/ExpiringTargetSdkVersion.md.html b/docs/checks/ExpiringTargetSdkVersion.md.html index b8cfde11..74bbbe9d 100644 --- a/docs/checks/ExpiringTargetSdkVersion.md.html +++ b/docs/checks/ExpiringTargetSdkVersion.md.html @@ -1,15 +1,15 @@ (#) TargetSdkVersion Soon Expiring -!!! ERROR: TargetSdkVersion Soon Expiring - This is an error. +!!! WARNING: TargetSdkVersion Soon Expiring + This is a warning. Id : `ExpiringTargetSdkVersion` Summary : TargetSdkVersion Soon Expiring Severity -: Error +: Warning Category : Compliance Platform @@ -18,8 +18,10 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.2.0 (September 2018) Affects -: Gradle build files +: Gradle build files, TOML files and manifest files Editing : This check runs on the fly in the IDE editor See @@ -30,22 +32,11 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GradleDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) -Copyright Year -: 2014 -In the second half of 2018, Google Play will require that new apps and -app updates target API level 26 or higher. This will be required for new -apps in August 2018, and for updates to existing apps in November 2018. - -Configuring your app to target a recent API level ensures that users -benefit from significant security and performance improvements, while -still allowing your app to run on older Android versions (down to the -`minSdkVersion`). - -This lint check starts warning you some months **before** these changes -go into effect if your `targetSdkVersion` is 25 or lower. This is -intended to give you a heads up to update your app, since depending on -your current `targetSdkVersion` the work can be nontrivial. +Configuring your app or sdk to target a recent API level ensures that +users benefit from significant security and performance improvements, +while still allowing your app or sdk to run on older Android versions +(down to the `minSdkVersion`). To update your `targetSdkVersion`, follow the steps from "Meeting Google Play requirements for target API level", @@ -58,14 +49,11 @@ Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -build.gradle:6:Error: Google Play will soon require that apps target API -level or higher. This will be required for new apps in August , and for -updates to existing apps in November . [ExpiringTargetSdkVersion] - - targetSdkVersion +build.gradle:6:Warning: Google Play will soon require that apps target +API level 33 or higher. This will be required for new apps and updates +starting on August 31, 2023. [ExpiringTargetSdkVersion] + targetSdkVersion 31 ------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -77,9 +65,9 @@ android { defaultConfig { // Already meeting last year's requirement but not this year's requirement - targetSdkVersion - targetSdkVersion // OK - // OK + targetSdkVersion 31 + targetSdkVersion 2023 // OK + targetSdkVersion 2024 // OK } } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -104,6 +92,13 @@ problematicStatement() ``` +* Adding the suppression attribute + `tools:ignore="ExpiringTargetSdkVersion"` on the problematic XML + element (or one of its enclosing elements). You may also need to add + the following namespace declaration on the root element in the XML + file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + * Using a special `lint.xml` file in the source tree which turns off the check in that folder and any sub folder. A simple file might look like this: diff --git a/docs/checks/ExportedContentProvider.md.html b/docs/checks/ExportedContentProvider.md.html index 1aba0209..85398661 100644 --- a/docs/checks/ExportedContentProvider.md.html +++ b/docs/checks/ExportedContentProvider.md.html @@ -18,10 +18,14 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Manifest files Editing : This check runs on the fly in the IDE editor +See +: https://goo.gle/ExportedContentProvider Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/SecurityDetector.java) Tests @@ -44,21 +48,15 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text AndroidManifest.xml:14:Warning: Exported content providers can provide access to potentially sensitive data [ExportedContentProvider] - <provider -------- - - AndroidManifest.xml:20:Warning: Exported content providers can provide access to potentially sensitive data [ExportedContentProvider] - <provider -------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `AndroidManifest.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -97,6 +95,41 @@ </manifest> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/values/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2007 The Android Open Source Project + + 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. +--> + +<resources> + <!-- Home --> + <string name="home_title">Home Sample</string> + <string name="show_all_apps">All</string> + + <!-- Home Menus --> + <string name="menu_wallpaper">Wallpaper</string> + <string name="menu_search">Search</string> + <string name="menu_settings">Settings</string> + <string name="sample" translatable="false">Ignore Me</string> + + <!-- Wallpaper --> + <string name="wallpaper_instructions">Tap picture to set portrait wallpaper</string> +</resources> + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/SecurityDetectorTest.java) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/ExportedPreferenceActivity.md.html b/docs/checks/ExportedPreferenceActivity.md.html index 38f3044f..a0d127ae 100644 --- a/docs/checks/ExportedPreferenceActivity.md.html +++ b/docs/checks/ExportedPreferenceActivity.md.html @@ -18,12 +18,16 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files and manifest files Editing : This check runs on the fly in the IDE editor See : http://securityintelligence.com/new-vulnerability-android-framework-fragment-injection +See +: https://goo.gle/ExportedPreferenceActivity Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/PreferenceActivityDetector.kt) Tests @@ -41,11 +45,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text AndroidManifest.xml:28:Warning: PreferenceActivity should not be exported [ExportedPreferenceActivity] - <activity ^ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/ExportedReceiver.md.html b/docs/checks/ExportedReceiver.md.html index a13b8848..84fa79a8 100644 --- a/docs/checks/ExportedReceiver.md.html +++ b/docs/checks/ExportedReceiver.md.html @@ -18,10 +18,14 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Manifest files Editing : This check runs on the fly in the IDE editor +See +: https://goo.gle/ExportedReceiver Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/SecurityDetector.java) Tests @@ -44,14 +48,11 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text AndroidManifest.xml:12:Warning: Exported receiver does not require permission [ExportedReceiver] - <receiver -------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `AndroidManifest.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -80,6 +81,41 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/values/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2007 The Android Open Source Project + + 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. +--> + +<resources> + <!-- Home --> + <string name="home_title">Home Sample</string> + <string name="show_all_apps">All</string> + + <!-- Home Menus --> + <string name="menu_wallpaper">Wallpaper</string> + <string name="menu_search">Search</string> + <string name="menu_settings">Settings</string> + <string name="sample" translatable="false">Ignore Me</string> + + <!-- Wallpaper --> + <string name="wallpaper_instructions">Tap picture to set portrait wallpaper</string> +</resources> + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/SecurityDetectorTest.java) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/ExportedService.md.html b/docs/checks/ExportedService.md.html index e73476ac..ab9b62d6 100644 --- a/docs/checks/ExportedService.md.html +++ b/docs/checks/ExportedService.md.html @@ -18,10 +18,14 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Manifest files Editing : This check runs on the fly in the IDE editor +See +: https://goo.gle/ExportedService Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/SecurityDetector.java) Tests @@ -43,14 +47,11 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text AndroidManifest.xml:12:Warning: Exported service does not require permission [ExportedService] - <service ------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `AndroidManifest.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -81,6 +82,41 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/values/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2007 The Android Open Source Project + + 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. +--> + +<resources> + <!-- Home --> + <string name="home_title">Home Sample</string> + <string name="show_all_apps">All</string> + + <!-- Home Menus --> + <string name="menu_wallpaper">Wallpaper</string> + <string name="menu_search">Search</string> + <string name="menu_settings">Settings</string> + <string name="sample" translatable="false">Ignore Me</string> + + <!-- Wallpaper --> + <string name="wallpaper_instructions">Tap picture to set portrait wallpaper</string> +</resources> + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/SecurityDetectorTest.java) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/ExposedRootPath.md.html b/docs/checks/ExposedRootPath.md.html new file mode 100644 index 00000000..265fef08 --- /dev/null +++ b/docs/checks/ExposedRootPath.md.html @@ -0,0 +1,160 @@ + +(#) Application specifies the device root directory + +!!! WARNING: Application specifies the device root directory + This is a warning. + +Id +: `ExposedRootPath` +Summary +: Application specifies the device root directory +Severity +: Warning +Category +: Security +Platform +: Android +Vendor +: Google - Android 3P Vulnerability Research +Contact +: https://github.com/google/android-security-lints +Feedback +: https://github.com/google/android-security-lints/issues +Min +: Lint 4.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.android.security.lint:lint](com_android_security_lint_lint.md.html) +Since +: 1.0.1 +Affects +: Resource files +Editing +: This check runs on the fly in the IDE editor +See +: https://goo.gle/ExposedRootPath +Implementation +: [Source Code](https://github.com/google/android-security-lints/tree/main/checks/src/main/java/com/example/lint/checks/MisconfiguredFileProviderDetector.kt) +Tests +: [Source Code](https://github.com/google/android-security-lints/tree/main/checks/src/test/java/com/example/lint/checks/MisconfiguredFileProviderDetectorTest.kt) +Copyright Year +: 2023 + +Allowing the device root directory in the `FileProvider` configuration +provides arbitrary access to files and folders for attackers, thereby +increasing the attack surface. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +res/xml/file_paths.xml:5:Warning: Do not use as it provides +arbitrary access to device files and folders [ExposedRootPath] + <root-path name="root" path="/"/> + --------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`res/xml/file_paths.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> + <paths xmlns:android="http://schemas.android.com/apk/res/android"> + <files-path name="my_images" path="images/"/> + <files-path name="my_docs" path="docs/"/> + <root-path name="root" path="/"/> + </paths> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/google/android-security-lints/tree/main/checks/src/test/java/com/example/lint/checks/MisconfiguredFileProviderDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MisconfiguredFileProviderDetector.testWhenRootPathUsedInConfig_showsWarningAndQuickFix`. +To report a problem with this extracted sample, visit +https://github.com/google/android-security-lints/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.android.security.lint:lint:1.0.3") + +// build.gradle +lintChecks 'com.android.security.lint:lint:1.0.3' + +// build.gradle.kts with version catalogs: +lintChecks(libs.com.android.security.lint.lint) + +# libs.versions.toml +[versions] +com-android-security-lint-lint = "1.0.3" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +com-android-security-lint-lint = { + module = "com.android.security.lint:lint", + version.ref = "com-android-security-lint-lint" +} +``` + +1.0.3 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.android.security.lint:lint](com_android_security_lint_lint.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute `tools:ignore="ExposedRootPath"` on + the problematic XML element (or one of its enclosing elements). You + may also need to add the following namespace declaration on the root + element in the XML file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ExposedRootPath" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ExposedRootPath' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ExposedRootPath ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ExtraText.md.html b/docs/checks/ExtraText.md.html index 15087222..522bba73 100644 --- a/docs/checks/ExtraText.md.html +++ b/docs/checks/ExtraText.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Manifest files and resource files Editing @@ -41,18 +43,12 @@ AndroidManifest.xml:7:Error: Unexpected text found in manifest file: "android:label="Android AdServices" android:forceQueryable="true" android:directBootAware="true">" [ExtraText] - android:label="Android AdServices" ^ - - res/drawable/icon.xml:1:Warning: Unexpected text found in drawable file: ">" [ExtraText] - <shape>> - - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here are the relevant source files: diff --git a/docs/checks/ExtraTranslation.md.html b/docs/checks/ExtraTranslation.md.html index c2c3899a..2eb9515d 100644 --- a/docs/checks/ExtraTranslation.md.html +++ b/docs/checks/ExtraTranslation.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Binary resource files, resource files and resource folders Editing @@ -50,14 +52,61 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/values-de-rDE/strings.xml:11:Error: "continue_skip_label" is translated here but not found in default locale [ExtraTranslation] - <string name="continue_skip_label">"Weiter"</string> -------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`res/values/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2007 The Android Open Source Project + 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. +--> + +<resources> + <!-- Home --> + <string name="home_title">Home Sample</string> + <string name="show_all_apps">All</string> + + <!-- Home Menus --> + <string name="menu_wallpaper">Wallpaper</string> + <string name="menu_search">Search</string> + <string name="menu_settings">Settings</string> + <string name="sample" translatable="false">Ignore Me</string> + + <!-- Wallpaper --> + <string name="wallpaper_instructions">Tap picture to set portrait wallpaper</string> +</resources> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +`res/values-cs/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="UTF-8"?> +<resources xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + <string name="home_title">"Domů"</string> + <string name="show_all_apps">"Vše"</string> + <string name="menu_wallpaper">"Tapeta"</string> + <string name="menu_search">"Hledat"</string> + <!-- no translation found for menu_settings (1769059051084007158) --> + <skip /> + <string name="wallpaper_instructions">"Klepnutím na obrázek nastavíte tapetu portrétu"</string> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `res/values-de-rDE/strings.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -75,6 +124,115 @@ </resources> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/values-es/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="UTF-8"?> +<resources xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + <string name="home_title">"Casa"</string> + <string name="show_all_apps">"Todo"</string> + <string name="menu_wallpaper">"Papel tapiz"</string> + <string name="menu_search">"Búsqueda"</string> + <!-- no translation found for menu_settings (1769059051084007158) --> + <skip /> + <string name="wallpaper_instructions">"Puntee en la imagen para establecer papel tapiz vertical"</string> + + <string-array name="security_questions"> + <item>"Comida favorita"</item> + <item>"Ciudad de nacimiento"</item> + <item>"Nombre de tu mejor amigo/a de la infancia"</item> + <item>"Nombre de tu colegio"</item> + </string-array> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/values-es-rUS/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="UTF-8"?> +<resources xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + <string name="menu_search">"Búsqueda"</string> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/values-land/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2007 The Android Open Source Project + + 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. +--> + +<resources> + <!-- Wallpaper --> + <string name="wallpaper_instructions">Tap image to set landscape wallpaper</string> +</resources> + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/values-cs/arrays.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<resources xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + <string-array name="security_questions"> + <item>"Oblíbené jídlo?"</item> + <item>"Město narození."</item> + <item>"Jméno nejlepšího kamaráda z dětství?"</item> + <item>"Název střední školy"</item> + </string-array> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/values-es/donottranslate.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + <string name="full_wday_month_day_no_year">EEEE, d MMMM</string> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/values-nl-rNL/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="UTF-8"?> +<resources xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + <string name="home_title">"Start"</string> + <!-- Commented out in the unit test to generate extra warnings: + <string name="show_all_apps">"Alles"</string> + <string name="menu_wallpaper">"Achtergrond"</string> + --> + <string name="menu_search">"Zoeken"</string> + <!-- no translation found for menu_settings (1769059051084007158) --> + <skip /> + <string name="wallpaper_instructions">"Tik op afbeelding om portretachtergrond in te stellen"</string> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/values/public.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<resources><public /></resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/layout/foo.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<LinearLayout/> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/layout-ja/foo.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<LinearLayout/> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/TranslationDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/FieldSiteTargetOnQualifierAnnotation.md.html b/docs/checks/FieldSiteTargetOnQualifierAnnotation.md.html new file mode 100644 index 00000000..8fc95bda --- /dev/null +++ b/docs/checks/FieldSiteTargetOnQualifierAnnotation.md.html @@ -0,0 +1,279 @@ + +(#) Redundant 'field:' used for Dagger qualifier annotation + +!!! WARNING: Redundant 'field:' used for Dagger qualifier annotation + This is a warning. + +Id +: `FieldSiteTargetOnQualifierAnnotation` +Summary +: Redundant 'field:' used for Dagger qualifier annotation +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: Google +Identifier +: com.google.dagger:dagger-lint +Contact +: https://github.com/google/dagger +Feedback +: https://github.com/google/dagger/issues +Min +: Lint 7.3 and 7.4 +Compiled +: Lint 7.1 +Artifact +: [com.google.dagger:dagger-lint](com_google_dagger_dagger-lint.md.html) +Since +: 2.40.2 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/google/dagger/tree/master/java/dagger/lint/DaggerKotlinIssueDetector.kt) +Tests +: [Source Code](https://github.com/google/dagger/tree/master/javatests/dagger/lint/DaggerKotlinIssueDetectorTest.kt) +Copyright Year +: 2020 + +It's redundant to use 'field:' site-targets for qualifier annotations. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/MyQualifier.kt:14:Warning: Redundant 'field:' used for Dagger +qualifier annotation. [FieldSiteTargetOnQualifierAnnotation] + @field:MyQualifier + ------------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/MyQualifier.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package foo +import javax.inject.Inject +import javax.inject.Qualifier +import kotlin.jvm.JvmStatic +import dagger.Provides +import dagger.Module + +@Qualifier +annotation class MyQualifier + +class InjectedTest { + // This should fail because of `:field` + @Inject + @field:MyQualifier + lateinit var prop: String + + // This is fine! + @Inject + @MyQualifier + lateinit var prop2: String +} + +@Module +object ObjectModule { + // This should fail because it uses `@JvmStatic` + @JvmStatic + @Provides + fun provideFoo(): String { + + } + + // This is fine! + @Provides + fun provideBar(): String { + + } +} + +@Module +class ClassModule { + companion object { + // This should fail because the companion object is part of ClassModule, so this is unnecessary. + @JvmStatic + @Provides + fun provideBaz(): String { + + } + } +} + +@Module +class ClassModuleQualified { + companion object { + // This should fail because the companion object is part of ClassModule, so this is unnecessary. + // This specifically tests a fully qualified annotation + @kotlin.jvm.JvmStatic + @Provides + fun provideBaz(): String { + + } + } +} + +@Module +class ClassModule2 { + // This should fail because the companion object is part of ClassModule + @Module + companion object { + @Provides + fun provideBaz(): String { + + } + } +} + +@Module +class ClassModule2Qualified { + // This should fail because the companion object is part of ClassModule + // This specifically tests a fully qualified annotation + @dagger.Module + companion object { + @Provides + fun provideBaz(): String { + + } + } +} + +// This is correct as of Dagger 2.26! +@Module +class ClassModule3 { + companion object { + @Provides + fun provideBaz(): String { + + } + } +} + +class ClassModule4 { + // This is should fail because this should be extracted to a standalone object. + @Module + companion object { + @Provides + fun provideBaz(): String { + + } + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/google/dagger/tree/master/javatests/dagger/lint/DaggerKotlinIssueDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `DaggerKotlinIssueDetector.simpleSmokeTestForQualifiersAndProviders`. +To report a problem with this extracted sample, visit +https://github.com/google/dagger/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("com.google.dagger:dagger-lint:2.56.2") + +// build.gradle +implementation 'com.google.dagger:dagger-lint:2.56.2' + +// build.gradle.kts with version catalogs: +implementation(libs.dagger.lint) + +# libs.versions.toml +[versions] +dagger-lint = "2.56.2" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +dagger-lint = { + module = "com.google.dagger:dagger-lint", + version.ref = "dagger-lint" +} +``` + +2.56.2 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.google.dagger:dagger-lint](com_google_dagger_dagger-lint.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("FieldSiteTargetOnQualifierAnnotation") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("FieldSiteTargetOnQualifierAnnotation") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection FieldSiteTargetOnQualifierAnnotation + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="FieldSiteTargetOnQualifierAnnotation" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'FieldSiteTargetOnQualifierAnnotation' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore FieldSiteTargetOnQualifierAnnotation ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/FileEndsWithExt.md.html b/docs/checks/FileEndsWithExt.md.html index bf7dd952..ea48d515 100644 --- a/docs/checks/FileEndsWithExt.md.html +++ b/docs/checks/FileEndsWithExt.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.1.0 (January 2022) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/FileEndsWithDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/FileEndsWithDetectorTest.kt) -Copyright Year -: 2021 The Kotlin extension method `File.endsWith(suffix)` checks whole path components, not just string suffixes. This means that @@ -41,25 +41,16 @@ src/test.kt:4:Warning: File.endsWith compares whole filenames, not just file extensions; did you mean file.path.endsWith(".xml") ? [FileEndsWithExt] - fun File.isXml() = endsWith(".xml") ---------------- - - src/test.kt:7:Warning: File.extension does not include the leading dot; did you mean "json" ? [FileEndsWithExt] - fun File.isJson() = extension == ".json" - ----- - - + ------- src/test.kt:8:Warning: File.extension does not include the leading dot; did you mean "webp" ? [FileEndsWithExt] - fun isWebp(path: File) = path.extension.startsWith(".webp") - ----- - - + ------- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/FilePropertyDetector.md.html b/docs/checks/FilePropertyDetector.md.html new file mode 100644 index 00000000..ddcbeeac --- /dev/null +++ b/docs/checks/FilePropertyDetector.md.html @@ -0,0 +1,144 @@ + +(#) Avoid using Property + +!!! ERROR: Avoid using Property + This is an error. + +Id +: `FilePropertyDetector` +Summary +: Avoid using Property +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: Android Open Source Project +Identifier +: androidx.lint:lint-gradle +Feedback +: https://issuetracker.google.com/issues/new?component=1147525 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.lint:lint-gradle](androidx_lint_lint-gradle.md.html) +Since +: 1.0.0-alpha03 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/lint/lint-gradle/src/main/java/androidx/lint/gradle/FilePropertyDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/lint/lint-gradle/src/test/java/androidx/lint/gradle/FilePropertyDetectorTest.kt) +Copyright Year +: 2024 + +`Property` is discouraged. Use `RegularFileProperty` for files or +`DirectoryProperty` for directories to enforce better type safety. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.lint:lint-gradle:1.0.0-alpha04") + +// build.gradle +implementation 'androidx.lint:lint-gradle:1.0.0-alpha04' + +// build.gradle.kts with version catalogs: +implementation(libs.lint.gradle) + +# libs.versions.toml +[versions] +lint-gradle = "1.0.0-alpha04" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-gradle = { + module = "androidx.lint:lint-gradle", + version.ref = "lint-gradle" +} +``` + +1.0.0-alpha04 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.lint:lint-gradle](androidx_lint_lint-gradle.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("FilePropertyDetector") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("FilePropertyDetector") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection FilePropertyDetector + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="FilePropertyDetector" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'FilePropertyDetector' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore FilePropertyDetector ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/FindViewByIdCast.md.html b/docs/checks/FindViewByIdCast.md.html index b22a0f84..cb9bde6b 100644 --- a/docs/checks/FindViewByIdCast.md.html +++ b/docs/checks/FindViewByIdCast.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.0.0 (October 2017) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ViewTypeDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ViewTypeDetectorTest.kt) -Copyright Year -: 2011 In Android O, the `findViewById` signature switched to using generics, which means that most of the time you can leave out explicit casts and @@ -49,14 +49,11 @@ src/main/java/test/pkg/ImplicitCastTest2.java:9:Warning: Add explicit cast here; won't compile with Java language level 1.8 without it [FindViewByIdCast] - checkNotNull1(findViewById(R.id.textView)).setAlpha(0.5f); // WARN --------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `src/main/java/test/pkg/ImplicitCastTest2.java`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers @@ -64,23 +61,23 @@ import android.view.View; -import test.pkg.myapplication.R; +import test.pkg.R; public class ImplicitCastTest2 extends MyActivityStub { public void test() { checkNotNull1(findViewById(R.id.textView)).setAlpha(0.5f); // WARN - checkNotNull2(findViewById(R.id.textView)).setAlpha(0.5f); // OK - checkNotNull3(findViewById(R.id.textView)).setAlpha(0.5f); // OK - checkNotNull1(findViewById(R.id.textView)); // OK - checkNotNull2(findViewById(R.id.textView)); // OK - checkNotNull3(findViewById(R.id.textView)); // OK - checkNotNull1((View)findViewById(R.id.textView)); // OK - checkNotNull2((View)findViewById(R.id.textView)); // OK - checkNotNull3((View)findViewById(R.id.textView)); // OK - View view1 = checkNotNull1(findViewById(R.id.textView)); // OK - View view2 = checkNotNull2(findViewById(R.id.textView)); // OK - View view3 = checkNotNull3(findViewById(R.id.textView)); // OK - findViewById(R.id.textView); // OK + checkNotNull2(findViewById(R.id.textView)).setAlpha(0.5f); // OK 1 + checkNotNull3(findViewById(R.id.textView)).setAlpha(0.5f); // OK 2 + checkNotNull1(findViewById(R.id.textView)); // OK 3 + checkNotNull2(findViewById(R.id.textView)); // OK 4 + checkNotNull3(findViewById(R.id.textView)); // OK 5 + checkNotNull1((View)findViewById(R.id.textView)); // OK 6 + checkNotNull2((View)findViewById(R.id.textView)); // OK 7 + checkNotNull3((View)findViewById(R.id.textView)); // OK 8 + View view1 = checkNotNull1(findViewById(R.id.textView)); // OK 9 + View view2 = checkNotNull2(findViewById(R.id.textView)); // OK 10 + View view3 = checkNotNull3(findViewById(R.id.textView)); // OK 11 + findViewById(R.id.textView); // OK 12 } public static T checkNotNull1(T reference) { @@ -109,6 +106,16 @@ } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`build.gradle`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~groovy linenumbers +android { + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ViewTypeDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/FlowOperatorInvokedInComposition.md.html b/docs/checks/FlowOperatorInvokedInComposition.md.html index 7dfb3042..330e385e 100644 --- a/docs/checks/FlowOperatorInvokedInComposition.md.html +++ b/docs/checks/FlowOperatorInvokedInComposition.md.html @@ -20,6 +20,14 @@ : androidx.compose.runtime Feedback : https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.runtime:runtime-android](androidx_compose_runtime_runtime-android.md.html) +Since +: 1.5.0 Affects : Kotlin and Java files and test sources Editing @@ -44,163 +52,103 @@ src/androidx/compose/runtime/foo/test.kt:15:Error: Flow operator functions should not be invoked within composition [FlowOperatorInvokedInComposition] - .customOperator(true) -------------- - - src/androidx/compose/runtime/foo/test.kt:16:Error: Flow operator functions should not be invoked within composition [FlowOperatorInvokedInComposition] - .drop(0) ---- - - src/androidx/compose/runtime/foo/test.kt:21:Error: Flow operator functions should not be invoked within composition [FlowOperatorInvokedInComposition] - .map { true } --- - - src/androidx/compose/runtime/foo/test.kt:22:Error: Flow operator functions should not be invoked within composition [FlowOperatorInvokedInComposition] - .customOperator(true) -------------- - - src/androidx/compose/runtime/foo/test.kt:23:Error: Flow operator functions should not be invoked within composition [FlowOperatorInvokedInComposition] - .drop(0) ---- - - src/androidx/compose/runtime/foo/test.kt:28:Error: Flow operator functions should not be invoked within composition [FlowOperatorInvokedInComposition] - .map { true } --- - - src/androidx/compose/runtime/foo/test.kt:29:Error: Flow operator functions should not be invoked within composition [FlowOperatorInvokedInComposition] - .customOperator(true) -------------- - - src/androidx/compose/runtime/foo/test.kt:30:Error: Flow operator functions should not be invoked within composition [FlowOperatorInvokedInComposition] - .drop(0) ---- - - src/androidx/compose/runtime/foo/test.kt:40:Error: Flow operator functions should not be invoked within composition [FlowOperatorInvokedInComposition] - .map { true } --- - - src/androidx/compose/runtime/foo/test.kt:41:Error: Flow operator functions should not be invoked within composition [FlowOperatorInvokedInComposition] - .customOperator(true) -------------- - - src/androidx/compose/runtime/foo/test.kt:42:Error: Flow operator functions should not be invoked within composition [FlowOperatorInvokedInComposition] - .drop(0) ---- - - src/androidx/compose/runtime/foo/test.kt:46:Error: Flow operator functions should not be invoked within composition [FlowOperatorInvokedInComposition] - .map { true } --- - - src/androidx/compose/runtime/foo/test.kt:47:Error: Flow operator functions should not be invoked within composition [FlowOperatorInvokedInComposition] - .customOperator(true) -------------- - - src/androidx/compose/runtime/foo/test.kt:48:Error: Flow operator functions should not be invoked within composition [FlowOperatorInvokedInComposition] - .drop(0) ---- - - src/androidx/compose/runtime/foo/test.kt:55:Error: Flow operator functions should not be invoked within composition [FlowOperatorInvokedInComposition] - .map { true } --- - - src/androidx/compose/runtime/foo/test.kt:56:Error: Flow operator functions should not be invoked within composition [FlowOperatorInvokedInComposition] - .customOperator(true) -------------- - - src/androidx/compose/runtime/foo/test.kt:57:Error: Flow operator functions should not be invoked within composition [FlowOperatorInvokedInComposition] - .drop(0) ---- - - src/androidx/compose/runtime/foo/test.kt:62:Error: Flow operator functions should not be invoked within composition [FlowOperatorInvokedInComposition] - .map { true } --- - - src/androidx/compose/runtime/foo/test.kt:63:Error: Flow operator functions should not be invoked within composition [FlowOperatorInvokedInComposition] - .customOperator(true) -------------- - - src/androidx/compose/runtime/foo/test.kt:64:Error: Flow operator functions should not be invoked within composition [FlowOperatorInvokedInComposition] - .drop(0) ---- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -283,6 +231,44 @@ To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=612128. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.runtime:runtime-android:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.runtime:runtime-android:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.runtime.android) + +# libs.versions.toml +[versions] +runtime-android = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +runtime-android = { + module = "androidx.compose.runtime:runtime-android", + version.ref = "runtime-android" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.runtime:runtime-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.runtime:runtime-android](androidx_compose_runtime_runtime-android.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/FontValidation.md.html b/docs/checks/FontValidation.md.html index c010997b..d93e4daa 100644 --- a/docs/checks/FontValidation.md.html +++ b/docs/checks/FontValidation.md.html @@ -6,10 +6,6 @@ Id : `FontValidation` -Previously -: FontValidationWarning -Previously -: FontValidationError Summary : Validation of font files Severity @@ -22,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.0.0 (July 2021) Affects : Resource files Editing @@ -32,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/FontDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/FontDetectorTest.java) -Copyright Year -: 2017 Look for problems in various font files. @@ -46,11 +42,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/font/font1.xml:4:Error: A downloadable font cannot have a sub tag [FontValidation] - <font ---- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/ForegroundServicePermission.md.html b/docs/checks/ForegroundServicePermission.md.html new file mode 100644 index 00000000..6398827f --- /dev/null +++ b/docs/checks/ForegroundServicePermission.md.html @@ -0,0 +1,203 @@ + +(#) Missing permissions required by foregroundServiceType + +!!! ERROR: Missing permissions required by foregroundServiceType + This is an error. + +Id +: `ForegroundServicePermission` +Summary +: Missing permissions required by foregroundServiceType +Severity +: Error +Category +: Correctness +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.2.0 (November 2023) +Affects +: Kotlin and Java files and manifest files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ForegroundServicePermissionDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ForegroundServicePermissionDetectorTest.kt) + +For targetSdkVersion >= 34, each `foregroundServiceType` listed in the +`` element requires specific sets of permissions to be declared +in the manifest. If permissions are missing, then when the foreground +service is started with a `foregroundServiceType` that has missing +permissions, a `SecurityException` will be thrown. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +AndroidManifest.xml:13:Error: foregroundServiceType:camera requires +permission:[android.permission.FOREGROUND_SERVICE_CAMERA] AND any +permission in list:[android.permission.CAMERA, +android.permission.SYSTEM_CAMERA] [ForegroundServicePermission] + <service + ^ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`AndroidManifest.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="foo.bar2" + android:versionCode="1" + android:versionName="1.0" > + + <uses-sdk android:targetSdkVersion="34" /> + <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> + + <application + android:icon="@drawable/ic_launcher" + android:label="@string/app_name" > + <service + android:exported="true" + android:label="@string/app_name" + android:name="com.sample.service.serviceClass" + android:foregroundServiceType="camera" + android:process=":remote" > + <intent-filter > + <action android:name="com.sample.service.serviceClass" > + </action> + </intent-filter> + </service> + </application> + +</manifest> + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/values/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2007 The Android Open Source Project + + 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. +--> + +<resources> + <!-- Home --> + <string name="home_title">Home Sample</string> + <string name="show_all_apps">All</string> + + <!-- Home Menus --> + <string name="menu_wallpaper">Wallpaper</string> + <string name="menu_search">Search</string> + <string name="menu_settings">Settings</string> + <string name="sample" translatable="false">Ignore Me</string> + + <!-- Wallpaper --> + <string name="wallpaper_instructions">Tap picture to set portrait wallpaper</string> +</resources> + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ForegroundServicePermissionDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute + `tools:ignore="ForegroundServicePermission"` on the problematic XML + element (or one of its enclosing elements). You may also need to add + the following namespace declaration on the root element in the XML + file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <manifest xmlns:tools="http://schemas.android.com/tools"> + ... + <service tools:ignore="ForegroundServicePermission" .../> + ... + </manifest> + ``` + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ForegroundServicePermission") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ForegroundServicePermission") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ForegroundServicePermission + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ForegroundServicePermission" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ForegroundServicePermission' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ForegroundServicePermission ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ForegroundServiceType.md.html b/docs/checks/ForegroundServiceType.md.html new file mode 100644 index 00000000..3eac4fb1 --- /dev/null +++ b/docs/checks/ForegroundServiceType.md.html @@ -0,0 +1,161 @@ + +(#) Missing `foregroundServiceType` attribute in manifest + +!!! ERROR: Missing `foregroundServiceType` attribute in manifest + This is an error. + +Id +: `ForegroundServiceType` +Summary +: Missing `foregroundServiceType` attribute in manifest +Severity +: Error +Category +: Correctness +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.2.0 (November 2023) +Affects +: Kotlin and Java files and manifest files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ForegroundServiceTypesDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ForegroundServiceTypesDetectorTest.kt) + +For `targetSdkVersion` >= 34, to call `Service.startForeground()`, the + element in the manifest file must have the +`foregroundServiceType` attribute specified. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test/pkg/MyService.java:8:Error: To call Service.startForeground(), +the element of manifest file must have the +foregroundServiceType attribute specified [ForegroundServiceType] + startForeground(1, null); + --------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`AndroidManifest.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="test.pkg"> + <uses-sdk android:targetSdkVersion="34" /> + <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> + <application> + <service + android:exported="true" + android:name="test.pkg.MyService"> + </service> + </application> +</manifest> + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/MyService.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; +public class MyService extends Service { + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + startForeground(1, null); + return START_NOT_STICKY; + } + @Override + public IBinder onBind(Intent intent) { + return null; + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ForegroundServiceTypesDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute + `tools:ignore="ForegroundServiceType"` on the problematic XML + element (or one of its enclosing elements). You may also need to add + the following namespace declaration on the root element in the XML + file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ForegroundServiceType") + fun method() { + startForeground(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ForegroundServiceType") + void method() { + startForeground(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ForegroundServiceType + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ForegroundServiceType" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ForegroundServiceType' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ForegroundServiceType ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/FormalGerman.md.html b/docs/checks/FormalGerman.md.html new file mode 100644 index 00000000..d140bebe --- /dev/null +++ b/docs/checks/FormalGerman.md.html @@ -0,0 +1,175 @@ + +(#) Marks strings which contain formal German words + +!!! WARNING: Marks strings which contain formal German words + This is a warning. + +Id +: `FormalGerman` +Summary +: Marks strings which contain formal German words +Severity +: Warning +Category +: Correctness +Platform +: Android +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html) +Since +: 0.24.0 +Affects +: Resource files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/main/kotlin/com/vanniktech/lintrules/android/FormalGermanDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/FormalGermanDetectorTest.kt) + +Informal language should be used at all times. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +res/values/config.xml:2:Warning: Formal language "Ihr" detected +[FormalGerman] + <string name="my_string_1">Wie lautet Ihr Name?</string> + ^ +res/values/config.xml:3:Warning: Formal language "Sie?" detected +[FormalGerman] + <string name="my_string_2">Wie heissen Sie?</string> + ^ +res/values/config.xml:4:Warning: Formal language "Ihrem" detected +[FormalGerman] + <string name="my_string_3">Frag nach Ihrem Namen.</string> + ^ +res/values/config.xml:5:Warning: Formal language "Sie" detected +[FormalGerman] + <string name="my_string_4">Wie Sie möchten</string> + ^ +res/values/config.xml:6:Warning: Formal language "Ihre" detected +[FormalGerman] + <string name="my_string_5">Ihre Historie</string> + ^ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`res/values/config.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<resources> + <string name="my_string_1">Wie lautet Ihr Name?</string> + <string name="my_string_2">Wie heissen Sie?</string> + <string name="my_string_3">Frag nach Ihrem Namen.</string> + <string name="my_string_4">Wie Sie möchten</string> + <string name="my_string_5">Ihre Historie</string> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/FormalGermanDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `FormalGermanDetector.formal`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-android:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-android:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.android) + +# libs.versions.toml +[versions] +lint-rules-android = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-android = { + module = "com.vanniktech:lint-rules-android", + version.ref = "lint-rules-android" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute `tools:ignore="FormalGerman"` on + the problematic XML element (or one of its enclosing elements). You + may also need to add the following namespace declaration on the root + element in the XML file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <resources xmlns:tools="http://schemas.android.com/tools"> + ... + <string tools:ignore="FormalGerman" .../> + ... + </resources> + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="FormalGerman" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'FormalGerman' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore FormalGerman ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/FragmentAddMenuProvider.md.html b/docs/checks/FragmentAddMenuProvider.md.html index f1194a07..835a0cd0 100644 --- a/docs/checks/FragmentAddMenuProvider.md.html +++ b/docs/checks/FragmentAddMenuProvider.md.html @@ -1,13 +1,13 @@ -(#) Use getViewLifecycleOwner() as the LifecycleOwner instead of a Fragment instance. +(#) Use getViewLifecycleOwner() as the LifecycleOwner instead of a Fragment instance -!!! ERROR: Use getViewLifecycleOwner() as the LifecycleOwner instead of a Fragment instance. +!!! ERROR: Use getViewLifecycleOwner() as the LifecycleOwner instead of a Fragment instance This is an error. Id : `FragmentAddMenuProvider` Summary -: Use getViewLifecycleOwner() as the LifecycleOwner instead of a Fragment instance. +: Use getViewLifecycleOwner() as the LifecycleOwner instead of a Fragment instance Severity : Error Category @@ -20,24 +20,68 @@ : androidx.fragment Feedback : https://issuetracker.google.com/issues/new?component=460964 +Min +: Lint 7.0 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [androidx.fragment:fragment](androidx_fragment_fragment.md.html) +Since +: 1.4.0 Affects : Kotlin and Java files Editing : This check runs on the fly in the IDE editor Implementation : [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/fragment/fragment-lint/src/main/java/androidx/fragment/lint/UnsafeFragmentLifecycleObserverDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/fragment/fragment-lint/src/test/java/androidx/fragment/lint/AddMenuProviderDetectorTest.kt) Copyright Year : 2019 -The Fragment lifecycle can result in a Fragment being active +The Fragment lifecycle can result in a Fragment being active longer than its view. This can lead to unexpected behavior from lifecycle aware objects remaining active longer than the -Fragment's view. To solve this issue, +Fragment's view. To solve this issue, getViewLifecycleOwner() should be used as a LifecycleOwner rather than the Fragment instance once it is safe to access the view lifecycle in a Fragment's onCreateView, onViewCreated, onActivityCreated, or onViewStateRestored methods. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.fragment:fragment:1.8.6") + +// build.gradle +implementation 'androidx.fragment:fragment:1.8.6' + +// build.gradle.kts with version catalogs: +implementation(libs.fragment) + +# libs.versions.toml +[versions] +fragment = "1.8.6" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +fragment = { + module = "androidx.fragment:fragment", + version.ref = "fragment" +} +``` + +1.8.6 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.fragment:fragment](androidx_fragment_fragment.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/FragmentBackPressedCallback.md.html b/docs/checks/FragmentBackPressedCallback.md.html index 1586fe45..3360c695 100644 --- a/docs/checks/FragmentBackPressedCallback.md.html +++ b/docs/checks/FragmentBackPressedCallback.md.html @@ -1,13 +1,13 @@ -(#) Use getViewLifecycleOwner() as the LifecycleOwner instead of a Fragment instance. +(#) Use getViewLifecycleOwner() as the LifecycleOwner instead of a Fragment instance -!!! ERROR: Use getViewLifecycleOwner() as the LifecycleOwner instead of a Fragment instance. +!!! ERROR: Use getViewLifecycleOwner() as the LifecycleOwner instead of a Fragment instance This is an error. Id : `FragmentBackPressedCallback` Summary -: Use getViewLifecycleOwner() as the LifecycleOwner instead of a Fragment instance. +: Use getViewLifecycleOwner() as the LifecycleOwner instead of a Fragment instance Severity : Error Category @@ -20,24 +20,68 @@ : androidx.fragment Feedback : https://issuetracker.google.com/issues/new?component=460964 +Min +: Lint 7.0 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [androidx.fragment:fragment](androidx_fragment_fragment.md.html) +Since +: 1.2.2 Affects : Kotlin and Java files Editing : This check runs on the fly in the IDE editor Implementation : [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/fragment/fragment-lint/src/main/java/androidx/fragment/lint/UnsafeFragmentLifecycleObserverDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/fragment/fragment-lint/src/test/java/androidx/fragment/lint/BackPressedDispatcherCallbackDetectorTest.kt) Copyright Year : 2019 -The Fragment lifecycle can result in a Fragment being active +The Fragment lifecycle can result in a Fragment being active longer than its view. This can lead to unexpected behavior from lifecycle aware objects remaining active longer than the -Fragment's view. To solve this issue, +Fragment's view. To solve this issue, getViewLifecycleOwner() should be used as a LifecycleOwner rather than the Fragment instance once it is safe to access the view lifecycle in a Fragment's onCreateView, onViewCreated, onActivityCreated, or onViewStateRestored methods. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.fragment:fragment:1.8.6") + +// build.gradle +implementation 'androidx.fragment:fragment:1.8.6' + +// build.gradle.kts with version catalogs: +implementation(libs.fragment) + +# libs.versions.toml +[versions] +fragment = "1.8.6" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +fragment = { + module = "androidx.fragment:fragment", + version.ref = "fragment" +} +``` + +1.8.6 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.fragment:fragment](androidx_fragment_fragment.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/FragmentConstructorInjection.md.html b/docs/checks/FragmentConstructorInjection.md.html new file mode 100644 index 00000000..fa7c557d --- /dev/null +++ b/docs/checks/FragmentConstructorInjection.md.html @@ -0,0 +1,224 @@ + +(#) Fragment dependencies should be injected using constructor injections only + +!!! ERROR: Fragment dependencies should be injected using constructor injections only + This is an error. + +Id +: `FragmentConstructorInjection` +Summary +: Fragment dependencies should be injected using constructor injections only +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/FragmentDaggerFieldInjectionDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/FragmentDaggerFieldInjectionDetectorTest.kt) +Copyright Year +: 2021 + +This Fragment has been set up to inject its dependencies through the +constructor. This dependency should be declared in the constructor where +dagger will handle the injection at runtime. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/MyFragment.kt:14:Error: Fragment dependencies should be injected +using constructor injections only. [FragmentConstructorInjection] + @Inject + ^ +src/foo/MyFragment.kt:16:Error: Fragment dependencies should be injected +using constructor injections only. [FragmentConstructorInjection] + @Inject + ^ +src/foo/MyFragment.kt:31:Error: Fragment dependencies should be injected +using constructor injections only. [FragmentConstructorInjection] + @Inject + ^ +src/foo/MyFragment.kt:33:Error: Fragment dependencies should be injected +using constructor injections only. [FragmentConstructorInjection] + @Inject + ^ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/MyFragment.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package foo + +import javax.inject.Inject +import dagger.assisted.AssistedInject +import slack.coreui.fragment.ViewBindingFragment + +class MyFragment @Inject constructor( + private val flag: Boolean +): ViewBindingFragment() { + + private lateinit var notAnnotated: String + private val defaulted: String = "defaulted" + + @Inject + private lateinit var stringValue1: String + @Inject + private lateinit var intValue1: Int + + fun onCreate() { + notAnnotated = "fast" + } +} + +class MyFragmentAssistedInject @AssistedInject constructor( + private val flag: Boolean +): ViewBindingFragment() { + + private lateinit var notAnnotated: String + private val defaulted: String = "defaulted" + + @Inject + private lateinit var stringValue1: String + @Inject + private lateinit var intValue1: Int + + fun onCreate() { + notAnnotated = "fast" + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/FragmentDaggerFieldInjectionDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `FragmentDaggerFieldInjectionDetector.Kotlin - fragment has field injection errors when constructor injection exists`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("FragmentConstructorInjection") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("FragmentConstructorInjection") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection FragmentConstructorInjection + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="FragmentConstructorInjection" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'FragmentConstructorInjection' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore FragmentConstructorInjection ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/FragmentFieldInjection.md.html b/docs/checks/FragmentFieldInjection.md.html new file mode 100644 index 00000000..20dedecf --- /dev/null +++ b/docs/checks/FragmentFieldInjection.md.html @@ -0,0 +1,201 @@ + +(#) Fragment dependencies should be injected using the Fragment's constructor + +!!! ERROR: Fragment dependencies should be injected using the Fragment's constructor + This is an error. + +Id +: `FragmentFieldInjection` +Summary +: Fragment dependencies should be injected using the Fragment's constructor +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/FragmentDaggerFieldInjectionDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/FragmentDaggerFieldInjectionDetectorTest.kt) +Copyright Year +: 2021 + +This dependency should be injected by dagger via the constructor. Add +this field's type into the parameter list of the Fragment's constructor. +This constructor should be annotated with either `@AssistedInject` or +`@Inject`. Annotate with `@AssistedInject` if this Fragment requires +runtime arguments via a `Bundle`. Annotate with `@Inject` if this +Fragment does not require any runtime arguments. If this is an abstract +class, the constructor does not need to be annotated with `@Inject` or +`@AssistedInject`. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/MyFragment.kt:11:Error: Fragment dependencies should be injected +using the Fragment's constructor. [FragmentFieldInjection] + @Inject + ^ +src/foo/MyFragment.kt:13:Error: Fragment dependencies should be injected +using the Fragment's constructor. [FragmentFieldInjection] + @Inject + ^ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/MyFragment.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package foo + +import javax.inject.Inject +import slack.coreui.fragment.ViewBindingFragment + +class MyFragment : ViewBindingFragment() { + + private lateinit var notAnnotated: String + private val defaulted: String = "defaulted" + + @Inject + private lateinit var stringValue1: String + @Inject + private lateinit var intValue1: Int + + fun onCreate() { + notAnnotated = "fast" + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/FragmentDaggerFieldInjectionDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `FragmentDaggerFieldInjectionDetector.Kotlin - fragment has field injection warnings`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("FragmentFieldInjection") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("FragmentFieldInjection") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection FragmentFieldInjection + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="FragmentFieldInjection" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'FragmentFieldInjection' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore FragmentFieldInjection ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/FragmentGradleConfiguration-2.md.html b/docs/checks/FragmentGradleConfiguration-2.md.html new file mode 100644 index 00000000..d48efc07 --- /dev/null +++ b/docs/checks/FragmentGradleConfiguration-2.md.html @@ -0,0 +1,155 @@ + +(#) Include the fragment-testing-manifest library using the debugImplementation configuration + +!!! ERROR: Include the fragment-testing-manifest library using the debugImplementation configuration + This is an error. + +Id +: `FragmentGradleConfiguration` +Summary +: Include the fragment-testing-manifest library using the debugImplementation configuration +Severity +: Error +Category +: Correctness +Platform +: Android +Vendor +: Android Open Source Project +Identifier +: androidx.fragment.testing.manifest +Feedback +: https://issuetracker.google.com/issues/new?component=460964 +Min +: Lint 7.0 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [androidx.fragment:fragment-testing-manifest](androidx_fragment_fragment-testing-manifest.md.html) +Since +: 1.6.0 +Affects +: Gradle build files +Editing +: This check runs on the fly in the IDE editor +See +: https://d.android.com/training/basics/fragments/testing#configure +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/fragment/fragment-testing-manifest-lint/src/main/java/androidx/fragment/testing/manifest/lint/GradleConfigurationDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/fragment/fragment-testing-manifest-lint/src/test/java/androidx/fragment/testing/manifest/lint/GradleConfigurationDetectorTest.kt) +Copyright Year +: 2019 + +The fragment-testing-manifest library defines an EmptyActivity + used when using FragmentScenario. Howver, it only needs to be +present in testing configurations therefore use this +dependency with the debugImplementation configuration. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +build.gradle:2:Error: Replace with debugImplementation. +[FragmentGradleConfiguration] + androidTestImplementation("androidx.fragment:fragment-testing-manifest:1.2.0-beta02") + ------------------------------------------------------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`build.gradle`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~groovy linenumbers +dependencies { + androidTestImplementation("androidx.fragment:fragment-testing-manifest:1.2.0-beta02") +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/fragment/fragment-testing-manifest-lint/src/test/java/androidx/fragment/testing/manifest/lint/GradleConfigurationDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `GradleConfigurationDetector.expectFail`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=460964. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.fragment:fragment-testing-manifest:1.8.6") + +// build.gradle +implementation 'androidx.fragment:fragment-testing-manifest:1.8.6' + +// build.gradle.kts with version catalogs: +implementation(libs.fragment.testing.manifest) + +# libs.versions.toml +[versions] +fragment-testing-manifest = "1.8.6" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +fragment-testing-manifest = { + module = "androidx.fragment:fragment-testing-manifest", + version.ref = "fragment-testing-manifest" +} +``` + +1.8.6 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.fragment:fragment-testing-manifest](androidx_fragment_fragment-testing-manifest.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection FragmentGradleConfiguration + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="FragmentGradleConfiguration" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'FragmentGradleConfiguration' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore FragmentGradleConfiguration ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/FragmentGradleConfiguration.md.html b/docs/checks/FragmentGradleConfiguration.md.html index 8f71b9c2..8f95f0f3 100644 --- a/docs/checks/FragmentGradleConfiguration.md.html +++ b/docs/checks/FragmentGradleConfiguration.md.html @@ -1,13 +1,13 @@ -(#) Include the fragment-testing library using the debugImplementation configuration. +(#) Include the fragment-testing library using the debugImplementation configuration -!!! ERROR: Include the fragment-testing library using the debugImplementation configuration. +!!! ERROR: Include the fragment-testing library using the debugImplementation configuration This is an error. Id : `FragmentGradleConfiguration` Summary -: Include the fragment-testing library using the debugImplementation configuration. +: Include the fragment-testing library using the debugImplementation configuration Severity : Error Category @@ -20,6 +20,14 @@ : androidx.fragment.testing Feedback : https://issuetracker.google.com/issues/new?component=460964 +Min +: Lint 7.0 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [androidx.fragment:fragment-testing](androidx_fragment_fragment-testing.md.html) +Since +: 1.6.0 Affects : Gradle build files Editing @@ -27,13 +35,13 @@ See : https://d.android.com/training/basics/fragments/testing#configure Implementation -: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/fragment/fragment-testing-lint/src/main/java/androidx/fragment/testing/lint/GradleConfigurationDetector.kt) +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/fragment/fragment-testing-manifest-lint/src/main/java/androidx/fragment/testing/manifest/lint/GradleConfigurationDetector.kt) Tests -: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/fragment/fragment-testing-lint/src/test/java/androidx/fragment/testing/lint/GradleConfigurationDetectorTest.kt) +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/fragment/fragment-testing-manifest-lint/src/test/java/androidx/fragment/testing/manifest/lint/GradleConfigurationDetectorTest.kt) Copyright Year : 2019 -The fragment-testing library contains a FragmentScenario class that +The fragment-testing library contains a FragmentScenario class that creates an Activity that must exist in the runtime APK. To include the fragment-testing library in the runtime APK it must be added using the debugImplementation @@ -45,11 +53,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text build.gradle:2:Error: Replace with debugImplementation. [FragmentGradleConfiguration] - - androidTestImplementation("androidx.fragment:fragment-testing:1.2.0-beta02") - ---------------------------------------------------------------------------- - - + androidTestImplementation("androidx.fragment:fragment-testing-manifest:1.2.0-beta02") + ------------------------------------------------------------------------------------- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -57,12 +62,12 @@ `build.gradle`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~groovy linenumbers dependencies { - androidTestImplementation("androidx.fragment:fragment-testing:1.2.0-beta02") + androidTestImplementation("androidx.fragment:fragment-testing-manifest:1.2.0-beta02") } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can also visit the -[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/fragment/fragment-testing-lint/src/test/java/androidx/fragment/testing/lint/GradleConfigurationDetectorTest.kt) +[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/fragment/fragment-testing-manifest-lint/src/test/java/androidx/fragment/testing/manifest/lint/GradleConfigurationDetectorTest.kt) for the unit tests for this check to see additional scenarios. The above example was automatically extracted from the first unit test @@ -70,6 +75,40 @@ To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=460964. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.fragment:fragment-testing:1.8.6") + +// build.gradle +implementation 'androidx.fragment:fragment-testing:1.8.6' + +// build.gradle.kts with version catalogs: +implementation(libs.fragment.testing) + +# libs.versions.toml +[versions] +fragment-testing = "1.8.6" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +fragment-testing = { + module = "androidx.fragment:fragment-testing", + version.ref = "fragment-testing" +} +``` + +1.8.6 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.fragment:fragment-testing](androidx_fragment_fragment-testing.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/FragmentLiveDataObserve.md.html b/docs/checks/FragmentLiveDataObserve.md.html index e7dea8b3..f7fa7979 100644 --- a/docs/checks/FragmentLiveDataObserve.md.html +++ b/docs/checks/FragmentLiveDataObserve.md.html @@ -1,13 +1,13 @@ -(#) Use getViewLifecycleOwner() as the LifecycleOwner instead of a Fragment instance when observing a LiveData object. +(#) Use getViewLifecycleOwner() as the LifecycleOwner instead of a Fragment instance when observing a LiveData object -!!! ERROR: Use getViewLifecycleOwner() as the LifecycleOwner instead of a Fragment instance when observing a LiveData object. +!!! ERROR: Use getViewLifecycleOwner() as the LifecycleOwner instead of a Fragment instance when observing a LiveData object This is an error. Id : `FragmentLiveDataObserve` Summary -: Use getViewLifecycleOwner() as the LifecycleOwner instead of a Fragment instance when observing a LiveData object. +: Use getViewLifecycleOwner() as the LifecycleOwner instead of a Fragment instance when observing a LiveData object Severity : Error Category @@ -20,24 +20,68 @@ : androidx.fragment Feedback : https://issuetracker.google.com/issues/new?component=460964 +Min +: Lint 7.0 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [androidx.fragment:fragment](androidx_fragment_fragment.md.html) +Since +: 1.2.0 Affects : Kotlin and Java files Editing : This check runs on the fly in the IDE editor Implementation : [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/fragment/fragment-lint/src/main/java/androidx/fragment/lint/UnsafeFragmentLifecycleObserverDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/fragment/fragment-lint/src/test/java/androidx/fragment/lint/FragmentLiveDataObserveDetectorTest.kt) Copyright Year : 2019 -When observing a LiveData object from a fragment's onCreateView, - onViewCreated, onActivityCreated, or onViewStateRestored method +When observing a LiveData object from a fragment's onCreateView, + onViewCreated, onActivityCreated, or onViewStateRestored method getViewLifecycleOwner() should be used as the LifecycleOwner rather than the Fragment instance. The -Fragment lifecycle can result in the Fragment being -active longer than its view. This can lead to unexpected behavior from +Fragment lifecycle can result in the Fragment being +active longer than its view. This can lead to unexpected behavior from LiveData objects being observed longer than the Fragment's view is active. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.fragment:fragment:1.8.6") + +// build.gradle +implementation 'androidx.fragment:fragment:1.8.6' + +// build.gradle.kts with version catalogs: +implementation(libs.fragment) + +# libs.versions.toml +[versions] +fragment = "1.8.6" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +fragment = { + module = "androidx.fragment:fragment", + version.ref = "fragment" +} +``` + +1.8.6 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.fragment:fragment](androidx_fragment_fragment.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/FragmentTagUsage.md.html b/docs/checks/FragmentTagUsage.md.html index 45d7907a..16e9a4c7 100644 --- a/docs/checks/FragmentTagUsage.md.html +++ b/docs/checks/FragmentTagUsage.md.html @@ -20,6 +20,14 @@ : androidx.fragment Feedback : https://issuetracker.google.com/issues/new?component=460964 +Min +: Lint 7.0 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [androidx.fragment:fragment](androidx_fragment_fragment.md.html) +Since +: 1.2.0 Affects : Resource files Editing @@ -33,10 +41,10 @@ Copyright Year : 2019 -FragmentContainerView replaces the tag as the preferred +FragmentContainerView replaces the tag as the preferred way of adding fragments via XML. Unlike the tag, FragmentContainerView uses a normal -`FragmentTransaction` under the hood to add the initial fragment, +`FragmentTransaction` under the hood to add the initial fragment, allowing further FragmentTransaction operations on the FragmentContainerView and providing a consistent timing for lifecycle events. @@ -47,11 +55,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/layout.xml:5:Warning: Replace the tag with FragmentContainerView. [FragmentTagUsage] - <fragment android:name="androidx.fragment.app.Test'$'InflatedFragment" -------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -77,6 +82,40 @@ To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=460964. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.fragment:fragment:1.8.6") + +// build.gradle +implementation 'androidx.fragment:fragment:1.8.6' + +// build.gradle.kts with version catalogs: +implementation(libs.fragment) + +# libs.versions.toml +[versions] +fragment = "1.8.6" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +fragment = { + module = "androidx.fragment:fragment", + version.ref = "fragment" +} +``` + +1.8.6 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.fragment:fragment](androidx_fragment_fragment.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/FrequentlyChangedStateReadInComposition.md.html b/docs/checks/FrequentlyChangedStateReadInComposition.md.html index 24ab046c..6fc6a490 100644 --- a/docs/checks/FrequentlyChangedStateReadInComposition.md.html +++ b/docs/checks/FrequentlyChangedStateReadInComposition.md.html @@ -1,197 +1,8 @@ -(#) Frequently changing state should not be directly read in composable function +(#) FrequentlyChangedStateReadInComposition -!!! WARNING: Frequently changing state should not be directly read in composable function - This is a warning. - -Id -: `FrequentlyChangedStateReadInComposition` -Summary -: Frequently changing state should not be directly read in composable function -Severity -: Warning -Category -: Performance -Platform -: Any -Vendor -: Jetpack Compose -Identifier -: androidx.compose.foundation -Feedback -: https://issuetracker.google.com/issues/new?component=612128 -Affects -: Kotlin and Java files and test sources -Editing -: This check runs on the fly in the IDE editor -Implementation -: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/foundation/foundation-lint/src/main/java/androidx/compose/foundation/lint/LazyLayoutStateReadInCompositionDetector.kt) -Tests -: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/foundation/foundation-lint/src/test/java/androidx/compose/foundation/lint/LazyLayoutStateReadInCompositionDetectorTest.kt) -Copyright Year -: 2022 - -This property is observable and is updated after every scroll or -remeasure. If you use it in the composable function directly, it will be -recomposed on every change, causing potential performance issues -including infinity recomposition loops. Prefer wrapping it with -derivedStateOf to use calculation based on this property in composition -or collect changes inside LaunchedEffect instead. - -!!! Tip - This lint check has an associated quickfix available in the IDE. - -(##) Example - -Here is an example of lint warnings produced by this check: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -src/androidx/compose/foundation/foo/test.kt:10:Warning: Frequently -changing state should not be directly read in composable function -[FrequentlyChangedStateReadInComposition] - - val index = state.firstVisibleItemIndex - --------------------------- - - -src/androidx/compose/foundation/foo/test.kt:11:Warning: Frequently -changing state should not be directly read in composable function -[FrequentlyChangedStateReadInComposition] - - val offset = state.firstVisibleItemScrollOffset - ---------------------------------- - - -src/androidx/compose/foundation/foo/test.kt:12:Warning: Frequently -changing state should not be directly read in composable function -[FrequentlyChangedStateReadInComposition] - - val layoutInfo = state.layoutInfo - ---------------- - - -src/androidx/compose/foundation/foo/test.kt:17:Warning: Frequently -changing state should not be directly read in composable function -[FrequentlyChangedStateReadInComposition] - - val index = state.firstVisibleItemIndex - --------------------------- - - -src/androidx/compose/foundation/foo/test.kt:18:Warning: Frequently -changing state should not be directly read in composable function -[FrequentlyChangedStateReadInComposition] - - val offset = state.firstVisibleItemScrollOffset - ---------------------------------- - - -src/androidx/compose/foundation/foo/test.kt:19:Warning: Frequently -changing state should not be directly read in composable function -[FrequentlyChangedStateReadInComposition] - - val layoutInfo = state.layoutInfo - ---------------- - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Here is the source file referenced above: - -`src/androidx/compose/foundation/foo/test.kt`: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers -package androidx.compose.foundation.foo - -import androidx.compose.runtime.Composable -import androidx.compose.foundation.lazy.grid.LazyGridState -import androidx.compose.foundation.lazy.LazyListState - -@Composable -fun TestGrid(state: LazyGridState) { - val index = state.firstVisibleItemIndex - val offset = state.firstVisibleItemScrollOffset - val layoutInfo = state.layoutInfo -} - -@Composable -fun TestList(state: LazyListState) { - val index = state.firstVisibleItemIndex - val offset = state.firstVisibleItemScrollOffset - val layoutInfo = state.layoutInfo -} -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -You can also visit the -[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/foundation/foundation-lint/src/test/java/androidx/compose/foundation/lint/LazyLayoutStateReadInCompositionDetectorTest.kt) -for the unit tests for this check to see additional scenarios. - -The above example was automatically extracted from the first unit test -found for this lint check, `LazyLayoutStateReadInCompositionDetector.observablePropertiesUsedInComposableFunction`. -To report a problem with this extracted sample, visit -https://issuetracker.google.com/issues/new?component=612128. - -(##) Suppressing - -You can suppress false positives using one of the following mechanisms: - -* Using a suppression annotation like this on the enclosing - element: - - ```kt - // Kotlin - @Suppress("FrequentlyChangedStateReadInComposition") - fun method() { - problematicStatement() - } - ``` - - or - - ```java - // Java - @SuppressWarnings("FrequentlyChangedStateReadInComposition") - void method() { - problematicStatement(); - } - ``` - -* Using a suppression comment like this on the line above: - - ```kt - //noinspection FrequentlyChangedStateReadInComposition - problematicStatement() - ``` - -* Using a special `lint.xml` file in the source tree which turns off - the check in that folder and any sub folder. A simple file might look - like this: - ```xml - <?xml version="1.0" encoding="UTF-8"?> - <lint> - <issue id="FrequentlyChangedStateReadInComposition" severity="ignore" /> - </lint> - ``` - Instead of `ignore` you can also change the severity here, for - example from `error` to `warning`. You can find additional - documentation on how to filter issues by path, regular expression and - so on - [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). - -* In Gradle projects, using the DSL syntax to configure lint. For - example, you can use something like - ```gradle - lintOptions { - disable 'FrequentlyChangedStateReadInComposition' - } - ``` - In Android projects this should be nested inside an `android { }` - block. - -* For manual invocations of `lint`, using the `--ignore` flag: - ``` - $ lint --ignore FrequentlyChangedStateReadInComposition ...` - ``` - -* Last, but not least, using baselines, as discussed - [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). +The issue for this id has been deleted or marked obsolete and can now be +ignored. +(Additional metadata not available.) \ No newline at end of file diff --git a/docs/checks/FrequentlyChangingValue.md.html b/docs/checks/FrequentlyChangingValue.md.html new file mode 100644 index 00000000..ed77dc9d --- /dev/null +++ b/docs/checks/FrequentlyChangingValue.md.html @@ -0,0 +1,508 @@ + +(#) Reading a value annotated with @FrequentlyChangingValue inside composition + +!!! WARNING: Reading a value annotated with @FrequentlyChangingValue inside composition + This is a warning. + +Id +: `FrequentlyChangingValue` +Summary +: Reading a value annotated with @FrequentlyChangingValue inside composition +Severity +: Warning +Category +: Performance +Platform +: Any +Vendor +: Jetpack Compose +Identifier +: androidx.compose.runtime +Feedback +: https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.runtime:runtime-android](androidx_compose_runtime_runtime-android.md.html) +Since +: 1.9.0-alpha01 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/runtime/runtime-lint/src/main/java/androidx/compose/runtime/lint/FrequentlyChangingValueDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/runtime/runtime-lint/src/test/java/androidx/compose/runtime/lint/FrequentlyChangingValueDetectorTest.kt) +Copyright Year +: 2025 + +Reading a value annotated with @FrequentlyChangingValue inside +composition can cause performance issues due to frequent recompositions. +To avoid frequent recompositions, instead consider: + +- Using derivedStateOf to filter state changes based on a provided + calculation. For example, rather than recomposing on every scroll + position change, only recomposing if the scroll position changes + from 0 (at the top of the list) to greater than 0 (not at the top of + the list), and vice versa. +- Using snapshotFlow to create a flow of changes from a provided state. + This can then be collected inside a LaunchedEffect, and used to make + changes without needing to recompose. +- If using Compose UI, read this value inside measure / layout / draw, + depending on where it is needed. This will cause invalidation of the + corresponding phase, instead of a recomposition. See + developer.android.com for more information on Jetpack Compose + phases. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/androidx/compose/runtime/foo/{.kt:8:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + test() + ---- +src/androidx/compose/runtime/foo/{.kt:10:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + val fooValue = foo.value + ----- +src/androidx/compose/runtime/foo/{.kt:11:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + bar.calculateValue() + -------------- +src/androidx/compose/runtime/foo/{.kt:12:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + val barValue = bar.value + ----- +src/androidx/compose/runtime/foo/{.kt:14:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + barImpl.calculateValue() + -------------- +src/androidx/compose/runtime/foo/{.kt:15:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + val barImplValue = barImpl.value + ----- +src/androidx/compose/runtime/foo/{.kt:19:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + test() + ---- +src/androidx/compose/runtime/foo/{.kt:21:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + val fooValue = foo.value + ----- +src/androidx/compose/runtime/foo/{.kt:22:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + bar.calculateValue() + -------------- +src/androidx/compose/runtime/foo/{.kt:23:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + val barValue = bar.value + ----- +src/androidx/compose/runtime/foo/{.kt:25:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + barImpl.calculateValue() + -------------- +src/androidx/compose/runtime/foo/{.kt:26:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + val barImplValue = barImpl.value + ----- +src/androidx/compose/runtime/foo/{.kt:30:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + test() + ---- +src/androidx/compose/runtime/foo/{.kt:32:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + val fooValue = foo.value + ----- +src/androidx/compose/runtime/foo/{.kt:33:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + bar.calculateValue() + -------------- +src/androidx/compose/runtime/foo/{.kt:34:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + val barValue = bar.value + ----- +src/androidx/compose/runtime/foo/{.kt:36:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + barImpl.calculateValue() + -------------- +src/androidx/compose/runtime/foo/{.kt:37:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + val barImplValue = barImpl.value + ----- +src/androidx/compose/runtime/foo/{.kt:46:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + test() + ---- +src/androidx/compose/runtime/foo/{.kt:48:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + val fooValue = foo.value + ----- +src/androidx/compose/runtime/foo/{.kt:49:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + bar.calculateValue() + -------------- +src/androidx/compose/runtime/foo/{.kt:50:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + val barValue = bar.value + ----- +src/androidx/compose/runtime/foo/{.kt:52:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + barImpl.calculateValue() + -------------- +src/androidx/compose/runtime/foo/{.kt:53:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + val barImplValue = barImpl.value + ----- +src/androidx/compose/runtime/foo/{.kt:56:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + test() + ---- +src/androidx/compose/runtime/foo/{.kt:58:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + val fooValue = foo.value + ----- +src/androidx/compose/runtime/foo/{.kt:59:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + bar.calculateValue() + -------------- +src/androidx/compose/runtime/foo/{.kt:60:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + val barValue = bar.value + ----- +src/androidx/compose/runtime/foo/{.kt:62:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + barImpl.calculateValue() + -------------- +src/androidx/compose/runtime/foo/{.kt:63:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + val barImplValue = barImpl.value + ----- +src/androidx/compose/runtime/foo/{.kt:69:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + test() + ---- +src/androidx/compose/runtime/foo/{.kt:71:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + val fooValue = foo.value + ----- +src/androidx/compose/runtime/foo/{.kt:72:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + bar.calculateValue() + -------------- +src/androidx/compose/runtime/foo/{.kt:73:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + val barValue = bar.value + ----- +src/androidx/compose/runtime/foo/{.kt:75:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + barImpl.calculateValue() + -------------- +src/androidx/compose/runtime/foo/{.kt:76:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + val barImplValue = barImpl.value + ----- +src/androidx/compose/runtime/foo/{.kt:80:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + test() + ---- +src/androidx/compose/runtime/foo/{.kt:82:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + val fooValue = foo.value + ----- +src/androidx/compose/runtime/foo/{.kt:83:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + bar.calculateValue() + -------------- +src/androidx/compose/runtime/foo/{.kt:84:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + val barValue = bar.value + ----- +src/androidx/compose/runtime/foo/{.kt:86:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + barImpl.calculateValue() + -------------- +src/androidx/compose/runtime/foo/{.kt:87:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + val barImplValue = barImpl.value + ----- +src/androidx/compose/runtime/foo/{.kt:95:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + val fooValue = foo.value + ----- +src/androidx/compose/runtime/foo/{.kt:96:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + val barValue = bar.value + ----- +src/androidx/compose/runtime/foo/{.kt:98:Warning: Reading a value +annotated with @FrequentlyChangingValue inside composition +[FrequentlyChangingValue] + val barImplValue = barImpl.value + ----- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/androidx/compose/runtime/foo/{.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package androidx.compose.runtime.foo + +import androidx.compose.runtime.* + +@Composable +fun Test(bar: Bar) { + test() + val foo = Foo() + val fooValue = foo.value + bar.calculateValue() + val barValue = bar.value + val barImpl = BarImpl() + barImpl.calculateValue() + val barImplValue = barImpl.value +} + +val lambda = @Composable { bar: Bar -> + test() + val foo = Foo() + val fooValue = foo.value + bar.calculateValue() + val barValue = bar.value + val barImpl = BarImpl() + barImpl.calculateValue() + val barImplValue = barImpl.value +} + +val lambda2: @Composable (bar: Bar) -> Unit = { bar -> + test() + val foo = Foo() + val fooValue = foo.value + bar.calculateValue() + val barValue = bar.value + val barImpl = BarImpl() + barImpl.calculateValue() + val barImplValue = barImpl.value +} + +@Composable +fun LambdaParameter(content: @Composable () -> Unit) {} + +@Composable +fun Test2(bar: Bar) { + LambdaParameter(content = { + test() + val foo = Foo() + val fooValue = foo.value + bar.calculateValue() + val barValue = bar.value + val barImpl = BarImpl() + barImpl.calculateValue() + val barImplValue = barImpl.value + }) + LambdaParameter { + test() + val foo = Foo() + val fooValue = foo.value + bar.calculateValue() + val barValue = bar.value + val barImpl = BarImpl() + barImpl.calculateValue() + val barImplValue = barImpl.value + } +} + +fun test3(bar: Bar) { + val localLambda1 = @Composable { + test() + val foo = Foo() + val fooValue = foo.value + bar.calculateValue() + val barValue = bar.value + val barImpl = BarImpl() + barImpl.calculateValue() + val barImplValue = barImpl.value + } + + val localLambda2: @Composable () -> Unit = { + test() + val foo = Foo() + val fooValue = foo.value + bar.calculateValue() + val barValue = bar.value + val barImpl = BarImpl() + barImpl.calculateValue() + val barImplValue = barImpl.value + } +} + +@Composable +fun Test4(bar: Bar) { + val localObject = object { + val foo = Foo() + val fooValue = foo.value + val barValue = bar.value + val barImpl = BarImpl() + val barImplValue = barImpl.value + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/runtime/runtime-lint/src/test/java/androidx/compose/runtime/lint/FrequentlyChangingValueDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `FrequentlyChangingValueDetector.errors`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=612128. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.runtime:runtime-android:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.runtime:runtime-android:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.runtime.android) + +# libs.versions.toml +[versions] +runtime-android = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +runtime-android = { + module = "androidx.compose.runtime:runtime-android", + version.ref = "runtime-android" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.runtime:runtime-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.runtime:runtime-android](androidx_compose_runtime_runtime-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("FrequentlyChangingValue") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("FrequentlyChangingValue") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection FrequentlyChangingValue + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="FrequentlyChangingValue" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'FrequentlyChangingValue' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore FrequentlyChangingValue ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/FullBackupContent.md.html b/docs/checks/FullBackupContent.md.html index 3aff7b5f..328003d4 100644 --- a/docs/checks/FullBackupContent.md.html +++ b/docs/checks/FullBackupContent.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 1.3.0 (July 2015) Affects : Resource files Editing @@ -30,8 +32,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/FullBackupContentDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/FullBackupContentDetectorTest.kt) -Copyright Year -: 2015 Ensures that ` and `` files, which configure backup options, are valid. @@ -42,18 +42,12 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/xml/data_extraction_rules.xml:6:Error: foo.xml is not in an included path [FullBackupContent] - <exclude domain="sharedpref" path="foo.xml"/> ------- - - res/xml/full_backup_content.xml:5:Error: foo.xml is not in an included path [FullBackupContent] - <exclude domain="sharedpref" path="foo.xml"/> ------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here are the relevant source files: diff --git a/docs/checks/FullyQualifiedResource.md.html b/docs/checks/FullyQualifiedResource.md.html new file mode 100644 index 00000000..a5de0f0d --- /dev/null +++ b/docs/checks/FullyQualifiedResource.md.html @@ -0,0 +1,207 @@ + +(#) Resources should use an import alias instead of being fully qualified + +!!! ERROR: Resources should use an import alias instead of being fully qualified + This is an error. + +Id +: `FullyQualifiedResource` +Summary +: Resources should use an import alias instead of being fully qualified +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/resources/FullyQualifiedResourceDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/resources/FullyQualifiedResourceDetectorTest.kt) +Copyright Year +: 2022 + +Resources should use an import alias instead of being fully qualified. +For example: +import slack.l10n.R as L10nR +... +...getString(L10nR.string.app_name) + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Options + +You can configure this lint checks using the following options: + +(###) import-aliases + +A comma-separated list of package name and their import aliases.. +This property should define a comma-separated list of package name and their import aliases in the format: packageName as importAlias + + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="FullyQualifiedResource"> + <option name="import-aliases" value="some string" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/pkg/subpackage/MyClass.kt:6:Error: Use L10nR as an import +alias instead [FullyQualifiedResource] + val appName = getString(slack.l10n.R.string.app_name) + ------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/pkg/subpackage/MyClass.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.pkg.subpackage + +class MyClass { + + init { + val appName = getString(slack.l10n.R.string.app_name) + } + + } +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/resources/FullyQualifiedResourceDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `FullyQualifiedResourceDetector.test failure no imports`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("FullyQualifiedResource") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("FullyQualifiedResource") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection FullyQualifiedResource + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="FullyQualifiedResource" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'FullyQualifiedResource' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore FullyQualifiedResource ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/GestureBackNavigation.md.html b/docs/checks/GestureBackNavigation.md.html index cae653e3..775d3a0d 100644 --- a/docs/checks/GestureBackNavigation.md.html +++ b/docs/checks/GestureBackNavigation.md.html @@ -18,40 +18,40 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.4.0 (January 2023) Affects : Kotlin and Java files Editing : This check runs on the fly in the IDE editor See -: https://developer.android.com/about/versions/13/features/predictive-back-gesture +: https://developer.android.com/guide/navigation/custom-back/predictive-back-gesture Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GestureBackNavDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GestureBackNavDetectorTest.kt) -Copyright Year -: 2022 -Starting in Android 13 (API 33+), the handling of back events is moving -to an ahead-of-time callback model. Use -`OnBackInvokedDispatcher.registerOnBackInvokedCallback(...)` and -`onBackInvokedCallback` or AndroidX's `OnBackPressedDispatcher` with an -implemented `onBackPressedCallback` to handle back gestures and key -presses. +For apps targeting and running on Android 16+ (API 36+), predictive back +animations are enabled by default. A back gesture does not trigger +`{Activity,Dialog}.onBackPressed`, and does not dispatch +`KeyEvent.KEYCODE_BACK`. + +Apps should migrate to AndroidX's backward compatible +`OnBackPressedDispatcher`. + +This lint check does not consider per-activity opt-in/opt-out, so you +may need to suppress or baseline reported incidents if migrating +per-activity. (##) Example Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -src/test/pkg/KeyEventKeyCodeBackTest.java:11:Warning: If intercepting -back events, this should be handled through the registration of -callbacks on the window level; Please see -https://developer.android.com/about/versions/13/features/predictive-back-gesture - [GestureBackNavigation] - - if (KeyEvent.KEYCODE_BACK == keyCode) { - --------------------- - - +src/test/pkg/KeyEventKeyCodeBackTest.java:17:Warning: onBackPressed is +no longer called for back gestures; migrate to AndroidX's backward +compatible OnBackPressedDispatcher [GestureBackNavigation] + public void onBackPressed() { + ------------- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here are the relevant source files: @@ -61,7 +61,7 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="test.pkg"> - <uses-permission-sdk-33 android:name="foo.bar.BAZ" /> + <uses-sdk android:minSdkVersion="24" android:targetSdkVersion="35" /> <application android:icon="@drawable/ic_launcher" @@ -69,7 +69,8 @@ android:enableOnBackInvokedCallback="true" > <activity android:name=".KeyEventKeyCodeBackTest" - android:label="@string/app_name" > + android:label="@string/app_name" + android:exported="true" > <intent-filter> <action android:name="android.intent.action.MAIN" /> @@ -77,7 +78,6 @@ </intent-filter> </activity> </application> - </manifest> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -97,6 +97,11 @@ return true; } } + + @Override + public void onBackPressed() { + // handle back + } } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/checks/GetContentDescriptionOverride.md.html b/docs/checks/GetContentDescriptionOverride.md.html index 89dc2138..51630a32 100644 --- a/docs/checks/GetContentDescriptionOverride.md.html +++ b/docs/checks/GetContentDescriptionOverride.md.html @@ -18,20 +18,58 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.0.0 (October 2017) Affects : Kotlin and Java files Editing : This check runs on the fly in the IDE editor Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GetContentDescriptionOverrideDetector.java) -Copyright Year -: 2016 +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GetContentDescriptionOverrideDetectorTest.kt) Overriding `getContentDescription()` may prevent some accessibility services from properly navigating content exposed by your view. Instead, call `setContentDescription()` when the content description needs to be changed. +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test/pkg/MyView.java:13:Error: Overriding getContentDescription() on +a View is not recommended [GetContentDescriptionOverride] + public CharSequence getContentDescription() { + --------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test/pkg/MyView.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; + +import android.content.Context; +import android.view.View; + +public class MyView extends View { + + public MyView(Context context) { + super(context); + } + + @Override + public CharSequence getContentDescription() { + return ""; + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GetContentDescriptionOverrideDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/GetInstance.md.html b/docs/checks/GetInstance.md.html index dc5e424c..900f198f 100644 --- a/docs/checks/GetInstance.md.html +++ b/docs/checks/GetInstance.md.html @@ -18,10 +18,14 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files Editing : This check runs on the fly in the IDE editor +See +: https://goo.gle/GetInstance Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/CipherGetInstanceDetector.kt) Tests @@ -40,11 +44,8 @@ src/test/pkg/CipherGetInstanceAES.java:8:Warning: Cipher.getInstance should not be called without setting the encryption mode and padding [GetInstance] - Cipher.getInstance("AES"); ----- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/GetLocales.md.html b/docs/checks/GetLocales.md.html index 5e527829..921679fc 100644 --- a/docs/checks/GetLocales.md.html +++ b/docs/checks/GetLocales.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.0.0 (October 2017) Affects : Kotlin and Java files, library bytecode and resource folders Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/LocaleFolderDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/LocaleFolderDetectorTest.kt) -Copyright Year -: 2014 This check looks for usage of Lollipop-style locale folders (e.g. 3 letter language codes, or BCP 47 qualifiers) combined with an @@ -42,14 +42,11 @@ AssetManager#getLocales is called and it contains one or more v21-style (3-letter or BCP47 locale) folders: values-b+kok+IN, values-fil [GetLocales] - String[] locales = assets.getLocales(); ------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `src/test/pkg/myapplication/MyLibrary.java`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers @@ -66,6 +63,24 @@ } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/values-no/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<resources> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/values-fil/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<resources> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/values-b+kok+IN/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<resources> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/LocaleFolderDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/GifUsage.md.html b/docs/checks/GifUsage.md.html index 57e72649..3a66bea2 100644 --- a/docs/checks/GifUsage.md.html +++ b/docs/checks/GifUsage.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing diff --git a/docs/checks/GradleCompatible.md.html b/docs/checks/GradleCompatible.md.html index 4fd8be05..9cbd894d 100644 --- a/docs/checks/GradleCompatible.md.html +++ b/docs/checks/GradleCompatible.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Gradle build files Editing @@ -44,13 +46,12 @@ Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -build.gradle:25:Error: This support library should not use a different -version (13) than the compileSdkVersion (19) [GradleCompatible] - - compile 'com.android.support:appcompat-v7:13.0.0' - ----------------------------------------- - - +build.gradle:26:Error: Project depends on +com.google.android.support:wearable:1.2.0, so it must also depend (as a +provided dependency) on com.google.android.wearable:wearable:1.2.0 +[GradleCompatible] + compile 'com.google.android.support:wearable:1.2.0' + ----------------------------------------- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -60,7 +61,7 @@ apply plugin: 'android' android { - compileSdkVersion 19 + compileSdkVersion 36 buildToolsVersion "19.0.0" defaultConfig { diff --git a/docs/checks/GradleDependency.md.html b/docs/checks/GradleDependency.md.html index ea590fc8..fd50c613 100644 --- a/docs/checks/GradleDependency.md.html +++ b/docs/checks/GradleDependency.md.html @@ -18,8 +18,10 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects -: Gradle build files +: Gradle build files and TOML files Editing : This check runs on the fly in the IDE editor Implementation @@ -43,43 +45,28 @@ Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text build.gradle:24:Warning: A newer version of com.google.guava:guava than -11.0.2 is available: 21.0 [GradleDependency] - +11.0.2 is available: 17.0 [GradleDependency] freeCompile 'com.google.guava:guava:11.0.2' ------------------------------- - - build.gradle:25:Warning: A newer version of -com.android.support:appcompat-v7 than 13.0.0 is available: 19.1.0 +com.android.support:appcompat-v7 than 13.0.0 is available: 25.3.1 [GradleDependency] - compile 'com.android.support:appcompat-v7:13.0.0' ----------------------------------------- - - build.gradle:26:Warning: A newer version of com.google.android.support:wearable than 1.2.0 is available: 1.3.0 [GradleDependency] - compile 'com.google.android.support:wearable:1.2.0' ------------------------------------------- - - build.gradle:27:Warning: A newer version of com.android.support:multidex than 1.0.0 is available: 1.0.1 [GradleDependency] - compile 'com.android.support:multidex:1.0.0' ------------------------------------ - - build.gradle:29:Warning: A newer version of com.android.support.test:runner than 0.3 is available: 0.5 [GradleDependency] - androidTestCompile 'com.android.support.test:runner:0.3' ------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -89,7 +76,7 @@ apply plugin: 'android' android { - compileSdkVersion 19 + compileSdkVersion 36 buildToolsVersion "19.0.0" defaultConfig { diff --git a/docs/checks/GradleDeprecated.md.html b/docs/checks/GradleDeprecated.md.html index 4ebbb2b2..07964fc0 100644 --- a/docs/checks/GradleDeprecated.md.html +++ b/docs/checks/GradleDeprecated.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Gradle build files Editing @@ -41,11 +43,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text build.gradle:1:Warning: 'android' is deprecated; use 'com.android.application' instead [GradleDeprecated] - apply plugin: 'android' ----------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -55,7 +54,7 @@ apply plugin: 'android' android { - compileSdkVersion 19 + compileSdkVersion 36 buildToolsVersion "19.0.0" defaultConfig { diff --git a/docs/checks/GradleDeprecatedConfiguration.md.html b/docs/checks/GradleDeprecatedConfiguration.md.html index c3feaba6..61a284c1 100644 --- a/docs/checks/GradleDeprecatedConfiguration.md.html +++ b/docs/checks/GradleDeprecatedConfiguration.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.5.0 (August 2019) Affects : Gradle build files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GradleDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) -Copyright Year -: 2014 Some Gradle configurations have been deprecated since Android Gradle Plugin 3.0.0 and will be removed in a future version of the Android @@ -46,20 +46,14 @@ to maintain current behavior, or implementation to improve build performance by not sharing this dependency transitively. [GradleDeprecatedConfiguration] - compile 'androidx.appcompat:appcompat:1.0.0' ------- - - build.gradle:10:Warning: debugCompile is deprecated; replace with either debugApi to maintain current behavior, or debugImplementation to improve build performance by not sharing this dependency transitively. [GradleDeprecatedConfiguration] - debugCompile 'androidx.appcompat:appcompat:1.0.0' ------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/GradleDynamicVersion.md.html b/docs/checks/GradleDynamicVersion.md.html index bfbc0db8..a590a600 100644 --- a/docs/checks/GradleDynamicVersion.md.html +++ b/docs/checks/GradleDynamicVersion.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Gradle build files Editing @@ -46,11 +48,8 @@ build.gradle:23:Warning: Avoid using + in version numbers; can lead to unpredictable and unrepeatable builds (com.android.support:appcompat-v7:+) [GradleDynamicVersion] - compile 'com.android.support:appcompat-v7:+' ------------------------------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -60,7 +59,7 @@ apply plugin: 'android' android { - compileSdkVersion 19 + compileSdkVersion 36 buildToolsVersion "19.0.0" defaultConfig { diff --git a/docs/checks/GradleGetter.md.html b/docs/checks/GradleGetter.md.html index 160effc7..e92002d4 100644 --- a/docs/checks/GradleGetter.md.html +++ b/docs/checks/GradleGetter.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Gradle build files Editing @@ -50,20 +52,14 @@ does not conflict with the implicit getters for the defaultConfig properties. For example, try using the prefix compute- instead of get-. [GradleGetter] - versionCode getVersionCode -------------------------- - - build.gradle:19:Error: Bad method name: pick a unique method name which does not conflict with the implicit getters for the defaultConfig properties. For example, try using the prefix compute- instead of get-. [GradleGetter] - versionName getVersionName -------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/GradleIdeError.md.html b/docs/checks/GradleIdeError.md.html index bf26396d..0ccec2a7 100644 --- a/docs/checks/GradleIdeError.md.html +++ b/docs/checks/GradleIdeError.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Gradle build files Editing diff --git a/docs/checks/GradleLikelyBug.md.html b/docs/checks/GradleLikelyBug.md.html new file mode 100644 index 00000000..ff33a816 --- /dev/null +++ b/docs/checks/GradleLikelyBug.md.html @@ -0,0 +1,145 @@ + +(#) Use of this API is likely a bug + +!!! ERROR: Use of this API is likely a bug + This is an error. + +Id +: `GradleLikelyBug` +Summary +: Use of this API is likely a bug +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: Android Open Source Project +Identifier +: androidx.lint:lint-gradle +Feedback +: https://issuetracker.google.com/issues/new?component=1147525 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.lint:lint-gradle](androidx_lint_lint-gradle.md.html) +Since +: 1.0.0-alpha04 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/lint/lint-gradle/src/main/java/androidx/lint/gradle/DiscouragedGradleMethodDetector.kt) +Copyright Year +: 2024 + +Calling Provider.toString() will return you a generic hash of the +instance of this provider. +You most likely want to call Provider.get() method to get the actual +value instead of the +provider. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.lint:lint-gradle:1.0.0-alpha04") + +// build.gradle +implementation 'androidx.lint:lint-gradle:1.0.0-alpha04' + +// build.gradle.kts with version catalogs: +implementation(libs.lint.gradle) + +# libs.versions.toml +[versions] +lint-gradle = "1.0.0-alpha04" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-gradle = { + module = "androidx.lint:lint-gradle", + version.ref = "lint-gradle" +} +``` + +1.0.0-alpha04 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.lint:lint-gradle](androidx_lint_lint-gradle.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("GradleLikelyBug") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("GradleLikelyBug") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection GradleLikelyBug + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="GradleLikelyBug" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'GradleLikelyBug' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore GradleLikelyBug ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/GradleOverrides.md.html b/docs/checks/GradleOverrides.md.html index 7d4b6de0..ae52b8e3 100644 --- a/docs/checks/GradleOverrides.md.html +++ b/docs/checks/GradleOverrides.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Manifest files Editing @@ -41,14 +43,11 @@ src/main/AndroidManifest.xml:2:Warning: Cannot use placeholder for the package in the manifest; set applicationId in build.gradle instead [GradleOverrides] - package="${packageName}" > ------------------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `src/main/AndroidManifest.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -62,6 +61,12 @@ </manifest> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`build.gradle`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~groovy linenumbers +android { +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ManifestDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/GradlePath.md.html b/docs/checks/GradlePath.md.html index 467e83c9..c5e5b74c 100644 --- a/docs/checks/GradlePath.md.html +++ b/docs/checks/GradlePath.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Gradle build files Editing @@ -45,18 +47,12 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text build.gradle:4:Warning: Do not use Windows file separators in .gradle files; use / instead [GradlePath] - compile files('my\\libs\\http.jar') --------------------------- - - build.gradle:5:Warning: Avoid using absolute paths in .gradle files [GradlePath] - compile files('/libs/android-support-v4.jar') ------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/GradlePluginVersion.md.html b/docs/checks/GradlePluginVersion.md.html index 9c4f8d3a..d7c50db1 100644 --- a/docs/checks/GradlePluginVersion.md.html +++ b/docs/checks/GradlePluginVersion.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 2.0.0 (April 2016) Affects : Gradle build files Editing @@ -26,14 +28,15 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GradleDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) -Copyright Year -: 2014 Not all versions of the Android Gradle plugin are compatible with all versions of the SDK. If you update your tools, or if you are trying to open a project that was built with an old version of the tools, you may need to update your plugin version number. +!!! Tip + This lint check has an associated quickfix available in the IDE. + (##) Example Here is an example of lint warnings produced by this check: @@ -41,11 +44,8 @@ build.gradle:6:Error: You must use a newer version of the Android Gradle plugin. The minimum supported version is 3.2.0 and the recommended version is 7.0.3 [GradlePluginVersion] - classpath 'com.android.tools.build:gradle:0.1.0' ------------------------------------------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/GradleProjectIsolation.md.html b/docs/checks/GradleProjectIsolation.md.html new file mode 100644 index 00000000..4f53dc67 --- /dev/null +++ b/docs/checks/GradleProjectIsolation.md.html @@ -0,0 +1,146 @@ + +(#) Avoid using APIs that are not project isolation safe + +!!! ERROR: Avoid using APIs that are not project isolation safe + This is an error. + +Id +: `GradleProjectIsolation` +Summary +: Avoid using APIs that are not project isolation safe +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: Android Open Source Project +Identifier +: androidx.lint:lint-gradle +Feedback +: https://issuetracker.google.com/issues/new?component=1147525 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.lint:lint-gradle](androidx_lint_lint-gradle.md.html) +Since +: 1.0.0-alpha02 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/lint/lint-gradle/src/main/java/androidx/lint/gradle/DiscouragedGradleMethodDetector.kt) +Copyright Year +: 2024 + +Using APIs that reach out cross projects makes it not safe for Gradle +project +isolation. +See https://docs.gradle.org/nightly/userguide/isolated_projects.html +for +more details. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.lint:lint-gradle:1.0.0-alpha04") + +// build.gradle +implementation 'androidx.lint:lint-gradle:1.0.0-alpha04' + +// build.gradle.kts with version catalogs: +implementation(libs.lint.gradle) + +# libs.versions.toml +[versions] +lint-gradle = "1.0.0-alpha04" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-gradle = { + module = "androidx.lint:lint-gradle", + version.ref = "lint-gradle" +} +``` + +1.0.0-alpha04 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.lint:lint-gradle](androidx_lint_lint-gradle.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("GradleProjectIsolation") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("GradleProjectIsolation") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection GradleProjectIsolation + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="GradleProjectIsolation" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'GradleProjectIsolation' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore GradleProjectIsolation ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/GrantAllUris.md.html b/docs/checks/GrantAllUris.md.html index a37e9bd8..c55febe5 100644 --- a/docs/checks/GrantAllUris.md.html +++ b/docs/checks/GrantAllUris.md.html @@ -18,10 +18,14 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Manifest files Editing : This check runs on the fly in the IDE editor +See +: https://goo.gle/GrantAllUris Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/SecurityDetector.java) Tests @@ -39,21 +43,15 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text AndroidManifest.xml:25:Warning: Content provider shares everything; this is potentially dangerous [GrantAllUris] - <grant-uri-permission android:path="/"/> ---------------- - - AndroidManifest.xml:26:Warning: Content provider shares everything; this is potentially dangerous [GrantAllUris] - <grant-uri-permission android:pathPrefix="/"/> ---------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `AndroidManifest.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -89,6 +87,41 @@ </manifest> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/values/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2007 The Android Open Source Project + + 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. +--> + +<resources> + <!-- Home --> + <string name="home_title">Home Sample</string> + <string name="show_all_apps">All</string> + + <!-- Home Menus --> + <string name="menu_wallpaper">Wallpaper</string> + <string name="menu_search">Search</string> + <string name="menu_settings">Settings</string> + <string name="sample" translatable="false">Ignore Me</string> + + <!-- Wallpaper --> + <string name="wallpaper_instructions">Tap picture to set portrait wallpaper</string> +</resources> + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/SecurityDetectorTest.java) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/GridLayout.md.html b/docs/checks/GridLayout.md.html index 0df7b744..087eee4b 100644 --- a/docs/checks/GridLayout.md.html +++ b/docs/checks/GridLayout.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -44,11 +46,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/gridlayout.xml:36:Error: Column attribute (3) exceeds declared grid column count (2) [GridLayout] - android:layout_column="3" ------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/GuavaChecksUsed.md.html b/docs/checks/GuavaChecksUsed.md.html new file mode 100644 index 00000000..c081c084 --- /dev/null +++ b/docs/checks/GuavaChecksUsed.md.html @@ -0,0 +1,206 @@ + +(#) Use Slack's JavaPreconditions instead of Guava's Preconditions checks + +!!! ERROR: Use Slack's JavaPreconditions instead of Guava's Preconditions checks + This is an error. + +Id +: `GuavaChecksUsed` +Summary +: Use Slack's JavaPreconditions instead of Guava's Preconditions checks +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/GuavaPreconditionsDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/GuavaPreconditionsDetectorTest.kt) +Copyright Year +: 2021 + +Precondition checks in Java should use Slack's internal +`JavaPreconditions.kt` instead of Guava's Preconditions. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/Foo.java:7:Error: Use Slack's JavaPreconditions instead of +Guava's Preconditions checks [GuavaChecksUsed] + boolean isTrue = Preconditions.checkState(1 == 1); + ---------- +src/foo/Foo.java:10:Error: Use Slack's JavaPreconditions instead of +Guava's Preconditions checks [GuavaChecksUsed] + Preconditions.checkState(1 == 1); + ---------- +src/foo/Foo.java:11:Error: Use Slack's JavaPreconditions instead of +Guava's Preconditions checks [GuavaChecksUsed] + Preconditions.checkArgument(1 == 1); + ------------- +src/foo/Foo.java:12:Error: Use Slack's JavaPreconditions instead of +Guava's Preconditions checks [GuavaChecksUsed] + Preconditions.checkNotNull("Hello"); + ------------ +src/foo/Foo.java:13:Error: Use Slack's JavaPreconditions instead of +Guava's Preconditions checks [GuavaChecksUsed] + Preconditions.checkElementIndex(0, 1); + ----------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/Foo.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package foo; + +import com.google.common.base.Preconditions; + +public class Foo { + + boolean isTrue = Preconditions.checkState(1 == 1); + + void act() { + Preconditions.checkState(1 == 1); + Preconditions.checkArgument(1 == 1); + Preconditions.checkNotNull("Hello"); + Preconditions.checkElementIndex(0, 1); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/GuavaPreconditionsDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `GuavaPreconditionsDetector.Java - Using Guava Preconditions with static reference will show warnings`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("GuavaChecksUsed") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("GuavaChecksUsed") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection GuavaChecksUsed + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="GuavaChecksUsed" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'GuavaChecksUsed' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore GuavaChecksUsed ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/GuavaPreconditionsUsedInKotlin.md.html b/docs/checks/GuavaPreconditionsUsedInKotlin.md.html new file mode 100644 index 00000000..2d6b3981 --- /dev/null +++ b/docs/checks/GuavaPreconditionsUsedInKotlin.md.html @@ -0,0 +1,207 @@ + +(#) Kotlin precondition checks should use the Kotlin standard library checks + +!!! ERROR: Kotlin precondition checks should use the Kotlin standard library checks + This is an error. + +Id +: `GuavaPreconditionsUsedInKotlin` +Summary +: Kotlin precondition checks should use the Kotlin standard library checks +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/GuavaPreconditionsDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/GuavaPreconditionsDetectorTest.kt) +Copyright Year +: 2021 + +All Kotlin classes that require precondition checks should use the + preconditions checks that are available in the Kotlin standard library +in Preconditions.kt. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/Foo.kt:7:Error: Kotlin precondition checks should use the Kotlin +standard library checks [GuavaPreconditionsUsedInKotlin] + val isTrue = Preconditions.checkState(false) + ---------- +src/foo/Foo.kt:10:Error: Kotlin precondition checks should use the +Kotlin standard library checks [GuavaPreconditionsUsedInKotlin] + Preconditions.checkState(true) + ---------- +src/foo/Foo.kt:11:Error: Kotlin precondition checks should use the +Kotlin standard library checks [GuavaPreconditionsUsedInKotlin] + Preconditions.checkArgument(false) + ------------- +src/foo/Foo.kt:12:Error: Kotlin precondition checks should use the +Kotlin standard library checks [GuavaPreconditionsUsedInKotlin] + Preconditions.checkNotNull("Hello") + ------------ +src/foo/Foo.kt:13:Error: Kotlin precondition checks should use the +Kotlin standard library checks [GuavaPreconditionsUsedInKotlin] + Preconditions.checkElementIndex(0, 1) + ----------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/Foo.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package foo + +import com.google.common.base.Preconditions + +class Foo { + + val isTrue = Preconditions.checkState(false) + + fun act() { + Preconditions.checkState(true) + Preconditions.checkArgument(false) + Preconditions.checkNotNull("Hello") + Preconditions.checkElementIndex(0, 1) + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/GuavaPreconditionsDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `GuavaPreconditionsDetector.Kotlin - Using Guava Preconditions with static reference will show warnings`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("GuavaPreconditionsUsedInKotlin") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("GuavaPreconditionsUsedInKotlin") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection GuavaPreconditionsUsedInKotlin + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="GuavaPreconditionsUsedInKotlin" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'GuavaPreconditionsUsedInKotlin' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore GuavaPreconditionsUsedInKotlin ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/HalfFloat.md.html b/docs/checks/HalfFloat.md.html index e9d53866..71dd6cb7 100644 --- a/docs/checks/HalfFloat.md.html +++ b/docs/checks/HalfFloat.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.1.0 (March 2018) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ResourceTypeDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ResourceTypeDetectorTest.kt) -Copyright Year -: 2017 Half-precision floating point are stored in a short data type, and should be manipulated using the `android.util.Half` class. This check @@ -39,53 +39,32 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/HalfFloatTest.java:23:Error: Expected a half float here, not a resource id [HalfFloat] - method1(getDimension1()); // ERROR --------------- - - src/test/pkg/HalfFloatTest.java:24:Error: Expected a half float here, not a dimension [HalfFloat] - method1(getDimension2()); // ERROR --------------- - - src/test/pkg/HalfFloatTest.java:25:Error: Expected a half float here, not a color [HalfFloat] - method1(getActualColor()); // ERROR ---------------- - - src/test/pkg/HalfFloatTest.java:26:Error: Expected a half float here, not a resource id [HalfFloat] - method1(getTextId()); // ERROR ----------- - - src/test/pkg/HalfFloatTest.java:43:Error: Half-float type in expression widened to int [HalfFloat] - int result3 = float1 + 1; // error: widening ------ - - src/test/pkg/HalfFloatTest.java:44:Error: Half-float type in expression widened to int [HalfFloat] - boolean result4 = float1 + 1 > 5; // error: widening ------ - - src/test/pkg/HalfFloatTest.java:50:Error: Half-float type in expression widened to int [HalfFloat] - Math.round(float1); // Error: should use Half.round ------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/HandlerLeak.md.html b/docs/checks/HandlerLeak.md.html index 835759cd..190d1fd8 100644 --- a/docs/checks/HandlerLeak.md.html +++ b/docs/checks/HandlerLeak.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files Editing @@ -46,19 +48,13 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/HandlerTest.java:12:Warning: This Handler class should be static or leaks might occur (test.pkg.HandlerTest.Inner) [HandlerLeak] - public class Inner extends Handler { // ERROR ----- - - src/test/pkg/HandlerTest.java:18:Warning: This Handler class should be static or leaks might occur (anonymous android.os.Handler) [HandlerLeak] - Handler anonymous = new Handler() { // ERROR ^ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/HardcodedDebugMode.md.html b/docs/checks/HardcodedDebugMode.md.html index 66092e41..72ef6098 100644 --- a/docs/checks/HardcodedDebugMode.md.html +++ b/docs/checks/HardcodedDebugMode.md.html @@ -20,10 +20,14 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Manifest files Editing : This check runs on the fly in the IDE editor +See +: https://goo.gle/HardcodedDebugMode Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/HardcodedDebugModeDetector.java) Tests @@ -48,11 +52,8 @@ AndroidManifest.xml:10:Error: Avoid hardcoding the debug mode; leaving it out allows debug and release builds to automatically assign one [HardcodedDebugMode] - android:debuggable="true" ------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/HardcodedText.md.html b/docs/checks/HardcodedText.md.html index 23fc8a93..658156ff 100644 --- a/docs/checks/HardcodedText.md.html +++ b/docs/checks/HardcodedText.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -48,18 +50,12 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/accessibility.xml:2:Warning: Hardcoded string "Button", should use @string resource [HardcodedText] - <Button android:text="Button" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> --------------------- - - res/layout/accessibility.xml:5:Warning: Hardcoded string "Button", should use @string resource [HardcodedText] - <Button android:text="Button" android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> --------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/HardwareIds.md.html b/docs/checks/HardwareIds.md.html index c1243da5..7afef299 100644 --- a/docs/checks/HardwareIds.md.html +++ b/docs/checks/HardwareIds.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 2.2.0 (September 2016) Affects : Kotlin and Java files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/HardwareIdDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/HardwareIdDetectorTest.kt) -Copyright Year -: 2016 Using these device identifiers is not recommended other than for high value fraud prevention and advanced telephony use-cases. For advertising @@ -42,11 +42,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/AppUtils.java:8:Warning: Using getAddress to get device identifiers is not recommended [HardwareIds] - return adapter.getAddress(); -------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/HighAppVersionCode.md.html b/docs/checks/HighAppVersionCode.md.html index cdbb7748..6247c792 100644 --- a/docs/checks/HighAppVersionCode.md.html +++ b/docs/checks/HighAppVersionCode.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 2.3.0 (March 2017) Affects : Gradle build files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GradleDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) -Copyright Year -: 2014 The declared `versionCode` is an Integer. Ensure that the version number is not close to the limit. It is recommended to monotonically increase @@ -42,11 +42,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text build.gradle:5:Error: The 'versionCode' is very high and close to the max allowed value [HighAppVersionCode] - versionCode 2146435071 ---------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/HighSamplingRate.md.html b/docs/checks/HighSamplingRate.md.html index a12f0e4c..da7c449f 100644 --- a/docs/checks/HighSamplingRate.md.html +++ b/docs/checks/HighSamplingRate.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.0.0 (July 2021) Affects : Manifest files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/HighSensorSamplingRateDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/HighSensorSamplingRateDetectorTest.kt) -Copyright Year -: 2021 Most apps don't need access to high sensor sampling rate. Double check your use case to ensure your app absolutely needs access to sensor @@ -41,11 +41,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text AndroidManifest.xml:4:Warning: Most apps don't need access to high sensor sampling rate. [HighSamplingRate] - <uses-permission android:name="android.permission.HIGH_SAMPLING_RATE_SENSORS"/> --------------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/IconColors.md.html b/docs/checks/IconColors.md.html index 2504caf3..7b47d8fc 100644 --- a/docs/checks/IconColors.md.html +++ b/docs/checks/IconColors.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files, manifest files and resource files Editing @@ -34,7 +36,8 @@ Lint decides whether an icon is an action bar icon or a notification icon is based on the filename prefix: `ic_menu_` for action bar icons, `ic_stat_` for notification icons etc. These correspond to the naming -conventions documented in https://material.io/design/iconography/ +conventions documented in +https://d.android.com/r/studio-ui/designer/material/iconography. (##) Suppressing diff --git a/docs/checks/IconDensities.md.html b/docs/checks/IconDensities.md.html index 675fa40f..facd0e32 100644 --- a/docs/checks/IconDensities.md.html +++ b/docs/checks/IconDensities.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -41,33 +43,6 @@ `ANDROID_LINT_INCLUDE_LDPI=true`. For more information on current density usage, see https://developer.android.com/about/dashboards. -(##) Example - -Here is an example of lint warnings produced by this check: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -res/drawable-hdpi/.svn:Warning: Missing the following drawables in -drawable-hdpi: sample_icon.gif (found in drawable-mdpi) [IconDensities] - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Here is the source file referenced above: - -`res/drawable-hdpi/.svn`: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ linenumbers - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -You can also visit the -[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/IconDetectorTest.java) -for the unit tests for this check to see additional scenarios. - -The above example was automatically extracted from the first unit test -found for this lint check, `IconDetector.test`. -To report a problem with this extracted sample, visit -https://issuetracker.google.com/issues/new?component=192708. - (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/IconDipSize.md.html b/docs/checks/IconDipSize.md.html index 925ca46f..b890d181 100644 --- a/docs/checks/IconDipSize.md.html +++ b/docs/checks/IconDipSize.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -42,19 +44,16 @@ my_lossy_72dp.webp: The implied 72 dp size does not match the actual dp size (pixel size 58×56 in a drawable-mdpi folder computes to 58×56 dp) [IconDipSize] - 0 errors, 3 warnings +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Here are the relevant test files: +![res/drawable-mdpi/my_lossy_72dp.webp](examples/drawable-mdpi/my_lossy_72dp.webp) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +![res/mipmap-mdpi/my_lossy2_72dp.webp](examples/mipmap-mdpi/my_lossy2_72dp.webp) -Here is the source file referenced above: - -`res/drawable-mdpi/my_lossy_72dp.webp`: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ linenumbers -H4sIAAAAAAAAAAvydHPzYGBgCHd1CggLsFCwAbIvMDPMZdSyYrBgsJvoscBHdYmykhIHwwYhzkyGMgYGhbxlC7g+chcxMPw7vf3/Wx8ht6D//wV23zjUANTKAADVeQHzUAAAAA== -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +![res/drawable-mdpi/my_lossless_72dp.webp](examples/drawable-mdpi/my_lossless_72dp.webp) You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/IconDetectorTest.java) diff --git a/docs/checks/IconDuplicates.md.html b/docs/checks/IconDuplicates.md.html index edff464c..f950ceb1 100644 --- a/docs/checks/IconDuplicates.md.html +++ b/docs/checks/IconDuplicates.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing diff --git a/docs/checks/IconDuplicatesConfig.md.html b/docs/checks/IconDuplicatesConfig.md.html index fe6e0bbd..5c6c827a 100644 --- a/docs/checks/IconDuplicatesConfig.md.html +++ b/docs/checks/IconDuplicatesConfig.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing diff --git a/docs/checks/IconExpectedSize.md.html b/docs/checks/IconExpectedSize.md.html index a4ec8aee..fcf32040 100644 --- a/docs/checks/IconExpectedSize.md.html +++ b/docs/checks/IconExpectedSize.md.html @@ -20,12 +20,14 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files, manifest files and resource files Editing : This check can *not* run live in the IDE editor See -: https://material.io/design/iconography/ +: https://d.android.com/r/studio-ui/designer/material/iconography Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/IconDetector.java) Tests diff --git a/docs/checks/IconExtension.md.html b/docs/checks/IconExtension.md.html index 51a9ff0e..f8c8979e 100644 --- a/docs/checks/IconExtension.md.html +++ b/docs/checks/IconExtension.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -39,19 +41,14 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/drawable-mdpi/foo.png:Warning: Misleading file extension; named .png but the file format is webp [IconExtension] - 0 errors, 1 warnings - - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant test files: -`res/drawable-mdpi/foo.png`: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ linenumbers -H4sIAAAAAAAAAAvydHNTYWBgCHd1CggLsPARB7L1LQ/wMrBf2O/3ddt/RgXFP/XrXb/Yf2VkAABv2HPZLAAAAA== -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +![res/drawable-mdpi/foo.png](examples/drawable-mdpi/foo.png) + +![res/drawable-mdpi/ok.webp](examples/drawable-mdpi/ok.webp) You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/IconDetectorTest.java) diff --git a/docs/checks/IconLauncherShape.md.html b/docs/checks/IconLauncherShape.md.html index 1f48545b..987289b0 100644 --- a/docs/checks/IconLauncherShape.md.html +++ b/docs/checks/IconLauncherShape.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files, manifest files and resource files Editing @@ -30,10 +32,10 @@ : 2011 According to the Android Design Guide -(https://material.io/design/iconography/) your launcher icons should -"use a distinct silhouette", a "three-dimensional, front view, with a -slight perspective as if viewed from above, so that users perceive some -depth." +(https://d.android.com/r/studio-ui/designer/material/iconography) your +launcher icons should "use a distinct silhouette", a "three-dimensional, +front view, with a slight perspective as if viewed from above, so that +users perceive some depth." The unique silhouette implies that your launcher icon should not be a filled square. diff --git a/docs/checks/IconLocation.md.html b/docs/checks/IconLocation.md.html index 15ca68bb..f61a035a 100644 --- a/docs/checks/IconLocation.md.html +++ b/docs/checks/IconLocation.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing diff --git a/docs/checks/IconMissingDensityFolder.md.html b/docs/checks/IconMissingDensityFolder.md.html index 5c227f84..b8ccb15c 100644 --- a/docs/checks/IconMissingDensityFolder.md.html +++ b/docs/checks/IconMissingDensityFolder.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -45,20 +47,23 @@ Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -res/drawable-hdpi/.svn:Warning: Missing density variation folders in -res: drawable-xhdpi, drawable-xxhdpi [IconMissingDensityFolder] - -0 errors, 5 warnings - - - +res/drawable-nodpi/frame.xml:Warning: Missing density variation folders +in res: drawable-hdpi, drawable-xhdpi, drawable-xxhdpi +[IconMissingDensityFolder] +0 errors, 3 warnings ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: -`res/drawable-hdpi/.svn`: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ linenumbers - +`res/drawable-nodpi/frame.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:color="#ff000000"/> <!-- WRONG, SHOULD BE LAST --> + <item android:state_pressed="true" + android:color="#ffff0000"/> <!-- pressed --> + <item android:state_focused="true" + android:color="#ff0000ff"/> <!-- focused --> +</selector> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can also visit the @@ -66,7 +71,7 @@ for the unit tests for this check to see additional scenarios. The above example was automatically extracted from the first unit test -found for this lint check, `IconDetector.test`. +found for this lint check, `IconDetector.testNoDpiMix`. To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=192708. diff --git a/docs/checks/IconMixedNinePatch.md.html b/docs/checks/IconMixedNinePatch.md.html index 58751e12..1890e16a 100644 --- a/docs/checks/IconMixedNinePatch.md.html +++ b/docs/checks/IconMixedNinePatch.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing diff --git a/docs/checks/IconNoDpi.md.html b/docs/checks/IconNoDpi.md.html index 4c69300f..2986519c 100644 --- a/docs/checks/IconNoDpi.md.html +++ b/docs/checks/IconNoDpi.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing diff --git a/docs/checks/IconXmlAndPng.md.html b/docs/checks/IconXmlAndPng.md.html index 32efc887..915d2b60 100644 --- a/docs/checks/IconXmlAndPng.md.html +++ b/docs/checks/IconXmlAndPng.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -42,11 +44,8 @@ density independent .xml files and as bitmap files: res/drawable-mdpi/background.png, res/drawable/background.xml [IconXmlAndPng] - res/drawable-mdpi/background.png: <No location-specific message> 0 errors, 1 warnings - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/IdleBatteryChargingConstraints.md.html b/docs/checks/IdleBatteryChargingConstraints.md.html index 6271777b..2551c222 100644 --- a/docs/checks/IdleBatteryChargingConstraints.md.html +++ b/docs/checks/IdleBatteryChargingConstraints.md.html @@ -20,6 +20,14 @@ : androidx.work Feedback : https://issuetracker.google.com/issues/new?component=409906 +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.7+ +Artifact +: [androidx.work:work-runtime](androidx_work_work-runtime.md.html) +Since +: 2.4.0 Affects : Kotlin and Java files Editing @@ -34,6 +42,76 @@ Some devices are never considered charging and idle at the same time. Consider removing one of these constraints. +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +com/example/App.kt:8:Warning: Constraints may not be met for some +devices [IdleBatteryChargingConstraints] + builder.setRequiresDeviceIdle(true) + ^ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`com/example/App.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package com.example + +import androidx.work.Constraints + +class App { + fun onCreate() { + val builder = Constraints.Builder() + builder.setRequiresDeviceIdle(true) + .setRequiresCharging(true) + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/work/work-lint/src/test/java/androidx/work/lint/IdleBatteryChargingConstraintsDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `IdleBatteryChargingConstraintsDetector.testWarnWithIdleCharging`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=409906. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.work:work-runtime:2.10.1") + +// build.gradle +implementation 'androidx.work:work-runtime:2.10.1' + +// build.gradle.kts with version catalogs: +implementation(libs.work.runtime) + +# libs.versions.toml +[versions] +work-runtime = "2.10.1" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +work-runtime = { + module = "androidx.work:work-runtime", + version.ref = "work-runtime" +} +``` + +2.10.1 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.work:work-runtime](androidx_work_work-runtime.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/IgnoreWithoutReason.md.html b/docs/checks/IgnoreWithoutReason.md.html index 54d3c8d3..6df95a14 100644 --- a/docs/checks/IgnoreWithoutReason.md.html +++ b/docs/checks/IgnoreWithoutReason.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.4.0 (April 2019) Affects : Kotlin and Java files and test sources Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/IgnoreWithoutReasonDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/IgnoreWithoutReasonDetectorTest.kt) -Copyright Year -: 2018 Ignoring a test without a reason makes it difficult to figure out the problem later. Please define an explicit reason why it is ignored, and @@ -63,11 +63,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/foo/MyTest.java:7:Warning: Test is ignored without giving any explanation [IgnoreWithoutReason] - @Ignore class MyTest { ------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/IllegalResourceRef.md.html b/docs/checks/IllegalResourceRef.md.html index 390d0fa8..d194e5c8 100644 --- a/docs/checks/IllegalResourceRef.md.html +++ b/docs/checks/IllegalResourceRef.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Manifest files Editing @@ -40,19 +42,13 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text AndroidManifest.xml:3:Warning: The android:versionCode cannot be a resource url, it must be a literal integer [IllegalResourceRef] - android:versionCode="@dimen/versionCode" ---------------------------------------- - - AndroidManifest.xml:6:Warning: The android:targetSdkVersion cannot be a resource url, it must be a literal integer (or string if a preview codename) [IllegalResourceRef] - <uses-sdk android:minSdkVersion="@dimen/minSdkVersion" android:targetSdkVersion="@dimen/targetSdkVersion" /> -------------------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/ImplicitSamInstance.md.html b/docs/checks/ImplicitSamInstance.md.html index 8ad9f1d7..0f79ebb5 100644 --- a/docs/checks/ImplicitSamInstance.md.html +++ b/docs/checks/ImplicitSamInstance.md.html @@ -8,8 +8,6 @@ : `ImplicitSamInstance` Summary : Implicit SAM Instances -Note -: **This issue is disabled by default**; use `--enable ImplicitSamInstance` Severity : Warning Category @@ -20,23 +18,29 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.4.0 (April 2019) Affects : Kotlin and Java files Editing : This check runs on the fly in the IDE editor +See +: https://kotlinlang.org/docs/fun-interfaces.html#sam-conversions Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/SamDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/SamDetectorTest.kt) -Copyright Year -: 2018 -Kotlin's support for SAM (single accessor method) interfaces lets you +Kotlin's support for SAM (single abstract method) interfaces lets you pass a lambda to the interface. This will create a new instance on the fly even though there is no explicit constructor call. If you pass one of these lambdas or method references into a method which (for example) stores or compares the object identity, unexpected results may happen. +In particular, passing a lambda variable in as a listener, and then +later attempting to remove the listener will not work because a +different instance is passed in. + !!! Tip This lint check has an associated quickfix available in the IDE. @@ -44,49 +48,34 @@ Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -src/test/pkg/test.kt:17:Warning: Implicit new MyInterface instance being +src/test/pkg/test.kt:21:Warning: Implicit new MyInterface instance being passed to method which ends up checking instance equality; this can lead to subtle bugs [ImplicitSamInstance] - - handler.stash(lambda, list) // WARN - ------ - - -src/test/pkg/test.kt:18:Warning: Implicit new MyInterface instance being + handler.delete(lambda) // ERROR 1 + ------ +src/test/pkg/test.kt:22:Warning: Implicit new MyInterface instance being passed to method which ends up checking instance equality; this can lead to subtle bugs [ImplicitSamInstance] - - handler.store(lambda) // WARN - ------ - - -src/test/pkg/test.kt:19:Warning: Implicit new MyInterface instance being + handler.compareIdentity1(lambda) // ERROR 2 + ------ +src/test/pkg/test.kt:23:Warning: Implicit new MyInterface instance being passed to method which ends up checking instance equality; this can lead to subtle bugs [ImplicitSamInstance] - - handler.compareIdentity1(lambda) // WARN + handler.compareIdentity2(lambda) // ERROR 3 ------ - - -src/test/pkg/test.kt:20:Warning: Implicit new MyInterface instance being +src/test/pkg/test.kt:31:Warning: Implicit new MyInterface instance being passed to method which ends up checking instance equality; this can lead to subtle bugs [ImplicitSamInstance] - - handler.compareIdentity2(lambda) // WARN - ------ - - -src/test/pkg/test.kt:27:Warning: Implicit new MyInterface instance being + handler.delete(lambda2) // ERROR 4 + ------- +src/test/pkg/test.kt:35:Warning: Implicit new MyInterface instance being passed to method which ends up checking instance equality; this can lead to subtle bugs [ImplicitSamInstance] - - handler.stash(lambda2, list) // WARN - ------- - - + handler.delete(lambda3) // ERROR 5 + ------- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `src/test/pkg/test.kt`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers @@ -100,23 +89,31 @@ handler.stash(MyInterface { println("hello") }, list) // OK handler.stash({ println("hello") }, list) // OK handler.store({ println("hello") }) // OK + handler.delete({ println("hello") }) // OK + handler.delete(MyInterface { println("hello") }) // OK handler.compareIdentity1({ println("hello") }) // OK handler.compareIdentity2({ println("hello") }) // OK handler.compareEquals1({ println("hello") }) // OK handler.compareEquals2({ println("hello") }) // OK val lambda = { println("hello") } - handler.stash(lambda, list) // WARN - handler.store(lambda) // WARN - handler.compareIdentity1(lambda) // WARN - handler.compareIdentity2(lambda) // WARN + handler.stash(lambda, list) // OK + handler.store(lambda) // OK + handler.delete(lambda) // ERROR 1 + handler.compareIdentity1(lambda) // ERROR 2 + handler.compareIdentity2(lambda) // ERROR 3 handler.compareEquals1(lambda) // OK handler.compareEquals2(lambda) // OK @Suppress("CanBeVal", "JoinDeclarationAndAssignment") var lambda2: () -> Unit lambda2 = { println("hello") } - handler.stash(lambda2, list) // WARN + handler.stash(lambda2, list) // OK + handler.delete(lambda2) // ERROR 4 + + val lambda3: () -> Unit = { println("hello") } + handler.stash(lambda3, list) // OK + handler.delete(lambda3) // ERROR 5 handler.act({ println("hello") }) // OK handler.act(::callback) // OK @@ -129,6 +126,97 @@ } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/test/pkg/JavaTest.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; + +import java.util.List; + +public class JavaTest { + public void test(MyHandler handler, List list) { + handler.handle(() -> System.out.println("hello")); // OK + handler.stash(() -> System.out.println("hello"), list); // OK + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/MyInterface.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; + +public interface MyInterface { + void act(); +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/MyHandler.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; + +import java.util.List; + +public class MyHandler { + public void handle(MyInterface actor) { + actor.act(); + System.out.println(actor); + MyInterface copy = actor; + System.out.println(copy); + } + + public void stash(MyInterface actor, List actors) { + actors.add(actor); + } + + public void store(MyInterface actor) { + last = actor; + } + + private MyInterface last; + + private void removeActor(MyInterface actor) { + } + + public fun delete(MyInterface actor) { + remove(actor); + } + + public void compareIdentity1(MyInterface actor) { + if (actor == last) { + System.out.println("last"); + } + } + + public void compareIdentity2(MyInterface actor) { + if (actor != last) { + System.out.println("not last"); + } + } + + public void compareEquals1(MyInterface actor) { + if (actor.equals(last)) { + System.out.println("last"); + } + } + + public void compareEquals2(MyInterface actor) { + if (last.equals(actor)) { + System.out.println("last"); + } + } + + public void act(MyInterface actor) { + if (actor != null) { + actor.act(); + } + //noinspection StatementWithEmptyBody + if (actor == null) { + } else { + actor.act(); + } + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/SamDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/ImplicitStringPlaceholder.md.html b/docs/checks/ImplicitStringPlaceholder.md.html new file mode 100644 index 00000000..6f38a644 --- /dev/null +++ b/docs/checks/ImplicitStringPlaceholder.md.html @@ -0,0 +1,159 @@ + +(#) Marks implicit placeholders in strings without an index + +!!! WARNING: Marks implicit placeholders in strings without an index + This is a warning. + +Id +: `ImplicitStringPlaceholder` +Summary +: Marks implicit placeholders in strings without an index +Severity +: Warning +Category +: Correctness +Platform +: Android +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html) +Since +: 0.24.0 +Affects +: Resource files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/main/kotlin/com/vanniktech/lintrules/android/ImplicitStringPlaceholderDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/ImplicitStringPlaceholderDetectorTest.kt) + +It's better and more explicit to use numbered placeholders. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +res/values/strings.xml:2:Warning: Implicit placeholder +[ImplicitStringPlaceholder] + <string name="my_string">Hello %s</string> + ^ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`res/values/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<resources> + <string name="my_string">Hello %s</string> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/ImplicitStringPlaceholderDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `ImplicitStringPlaceholderDetector.invalid`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-android:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-android:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.android) + +# libs.versions.toml +[versions] +lint-rules-android = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-android = { + module = "com.vanniktech:lint-rules-android", + version.ref = "lint-rules-android" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute + `tools:ignore="ImplicitStringPlaceholder"` on the problematic XML + element (or one of its enclosing elements). You may also need to add + the following namespace declaration on the root element in the XML + file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <resources xmlns:tools="http://schemas.android.com/tools"> + ... + <string tools:ignore="ImplicitStringPlaceholder" .../> + ... + </resources> + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ImplicitStringPlaceholder" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ImplicitStringPlaceholder' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ImplicitStringPlaceholder ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ImpliedQuantity.md.html b/docs/checks/ImpliedQuantity.md.html index 182f9a61..92e842e9 100644 --- a/docs/checks/ImpliedQuantity.md.html +++ b/docs/checks/ImpliedQuantity.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -51,14 +53,46 @@ 701, 1001, …), but the message did not include a formatting argument (such as %d). This is usually an internationalization error. See full issue explanation for more. [ImpliedQuantity] - <item quantity="one">Znaleziono jedną piosenkę.</item> ------------------------------------------------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Here are the relevant source files: +`res/values/plurals.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<resources> + <plurals name="my_plural"> + <item quantity="one">@string/hello</item> + <item quantity="few">@string/hello</item> + <item quantity="other">@string/hello</item> + </plurals> +</resources> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +`res/values/plurals2.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<resources> + <plurals name="numberOfSongsAvailable"> + <item quantity="one">One song found.</item> + <item quantity="other">%d songs found.</item> + </plurals> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/values-pl/plurals2.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<resources> + <plurals name="numberOfSongsAvailable"> + <item quantity="one">Znaleziono jedną piosenkę.</item> + <item quantity="few">Znaleziono %d piosenki.</item> + <item quantity="other">Znaleziono %d piosenek.</item> + </plurals> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `res/values-sl/plurals2.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers diff --git a/docs/checks/ImpliedTouchscreenHardware.md.html b/docs/checks/ImpliedTouchscreenHardware.md.html index 0efb2a14..462cd0fd 100644 --- a/docs/checks/ImpliedTouchscreenHardware.md.html +++ b/docs/checks/ImpliedTouchscreenHardware.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 2.3.0 (March 2017) Affects : Manifest files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AndroidTvDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AndroidTvDetectorTest.java) -Copyright Year -: 2015 Apps require the `android.hardware.touchscreen` feature by default. If you want your app to be available on TV, you must also explicitly @@ -42,13 +42,10 @@ Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text AndroidManifest.xml:2:Error: Hardware feature -android.hardware.touchscreen not explicitly marked as optional +android.hardware.touchscreen not explicitly marked as optional [ImpliedTouchscreenHardware] - <manifest xmlns:android="http://schemas.android.com/apk/res/android" -------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/InOrMmUsage.md.html b/docs/checks/InOrMmUsage.md.html index 459bf450..f2e28ef0 100644 --- a/docs/checks/InOrMmUsage.md.html +++ b/docs/checks/InOrMmUsage.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -44,19 +46,13 @@ res/layout/now_playing_after.xml:49:Warning: Avoid using "mm" as units (it does not work accurately on all devices); use "dp" instead [InOrMmUsage] - android:layout_width="100mm" ---------------------------- - - res/layout/now_playing_after.xml:50:Warning: Avoid using "in" as units (it does not work accurately on all devices); use "dp" instead [InOrMmUsage] - android:layout_height="120in" ----------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/IncludeLayoutParam.md.html b/docs/checks/IncludeLayoutParam.md.html index 4e72802b..216cbbcd 100644 --- a/docs/checks/IncludeLayoutParam.md.html +++ b/docs/checks/IncludeLayoutParam.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -45,51 +47,33 @@ res/layout/include_params.xml:43:Error: Layout parameter layout_margin ignored unless both layout_width and layout_height are also specified on tag [IncludeLayoutParam] - android:layout_margin="20dp" ---------------------------- - - res/layout/include_params.xml:44:Error: Layout parameter layout_weight ignored unless both layout_width and layout_height are also specified on tag [IncludeLayoutParam] - android:layout_weight="1.5" --------------------------- - - res/layout/include_params.xml:51:Error: Layout parameter layout_weight ignored unless layout_width is also specified on tag [IncludeLayoutParam] - android:layout_weight="1.5" --------------------------- - - res/layout/include_params.xml:58:Error: Layout parameter layout_weight ignored unless layout_height is also specified on tag [IncludeLayoutParam] - android:layout_weight="1.5" --------------------------- - - res/layout/include_params.xml:65:Error: Layout parameter layout_width ignored unless layout_height is also specified on tag [IncludeLayoutParam] - android:layout_width="fill_parent" ---------------------------------- - - res/layout/include_params.xml:72:Error: Layout parameter layout_height ignored unless layout_width is also specified on tag [IncludeLayoutParam] - android:layout_height="fill_parent" ----------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/InclusiveNaming.md.html b/docs/checks/InclusiveNaming.md.html new file mode 100644 index 00000000..a68e4494 --- /dev/null +++ b/docs/checks/InclusiveNaming.md.html @@ -0,0 +1,154 @@ + +(#) Use inclusive naming + +!!! ERROR: Use inclusive naming + This is an error. + +Id +: `InclusiveNaming` +Summary +: Use inclusive naming +Severity +: Error +Category +: Correctness +Platform +: Android +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Resource files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/inclusive/InclusiveNamingResourceScanner.kt) +Copyright Year +: 2021 + +We try to use inclusive naming at Slack. Terms such as blacklist, +whitelist, master, slave, etc, while maybe widely used today, can be +socially charged and make others feel excluded or uncomfortable. + +(##) Options + +You can configure this lint checks using the following options: + +(###) block-list + +A comma-separated list of words that should not be used in source code.. +This property should define a comma-separated list of words that should not be used in source code. + + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="InclusiveNaming"> + <option name="block-list" value="some string" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(##) Conflicts + +This issue id has also been used by other, unrelated lint checks. Issue +id's must be unique, so you cannot combine these libraries. Also defined +in: +* InclusiveNaming: Use inclusive naming (this issue) +* [InclusiveNaming from com.slack.lint:slack-lint-checks:0.9.0](InclusiveNaming.md.html) +* [InclusiveNaming from com.slack.lint:slack-lint-checks:0.9.0](InclusiveNaming.md.html) + + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute `tools:ignore="InclusiveNaming"` on + the problematic XML element (or one of its enclosing elements). You + may also need to add the following namespace declaration on the root + element in the XML file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="InclusiveNaming" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'InclusiveNaming' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore InclusiveNaming ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/IncompatibleMediaBrowserServiceCompatVersion.md.html b/docs/checks/IncompatibleMediaBrowserServiceCompatVersion.md.html index 9321cb93..f9731305 100644 --- a/docs/checks/IncompatibleMediaBrowserServiceCompatVersion.md.html +++ b/docs/checks/IncompatibleMediaBrowserServiceCompatVersion.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.0.0 (October 2017) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/MediaBrowserServiceCompatVersionDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/MediaBrowserServiceCompatVersionDetectorTest.kt) -Copyright Year -: 2016 `MediaBrowserServiceCompat` from version 23.2.0 to 23.4.0 of the Support v4 Library used private APIs and will not be compatible with future @@ -40,21 +40,42 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text build.gradle:4:Warning: Using a version of the class that is not forward compatible [IncompatibleMediaBrowserServiceCompatVersion] - - compile 'com.android.support:support-v4:23.4.0' + compile 'com.android.support:support-v4:23.4.0' ------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Here are the relevant source files: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/test/pkg/MyBrowserService.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; + +import android.os.Bundle; +import android.support.v4.media.MediaBrowserCompat; +import android.support.v4.media.MediaBrowserServiceCompat; + +import java.util.List; + +public class MyBrowserService extends MediaBrowserServiceCompat { -Here is the source file referenced above: + @Override + public BrowserRoot onGetRoot(String clientPackageName, int clientUid, Bundle rootHints) { + return null; + } + + @Override + public void onLoadChildren(String parentId, Result> result) { + + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `build.gradle`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~groovy linenumbers apply plugin: 'com.android.application' dependencies { - compile 'com.android.support:support-v4:23.4.0' + compile 'com.android.support:support-v4:23.4.0' } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -71,13 +92,6 @@ You can suppress false positives using one of the following mechanisms: -* Using a suppression comment like this on the line above: - - ```kt - //noinspection IncompatibleMediaBrowserServiceCompatVersion - problematicStatement() - ``` - * Using a suppression annotation like this on the enclosing element: @@ -99,6 +113,13 @@ } ``` +* Using a suppression comment like this on the line above: + + ```kt + //noinspection IncompatibleMediaBrowserServiceCompatVersion + problematicStatement() + ``` + * Using a special `lint.xml` file in the source tree which turns off the check in that folder and any sub folder. A simple file might look like this: diff --git a/docs/checks/InconsistentArrays.md.html b/docs/checks/InconsistentArrays.md.html index ce956fc9..f6af0927 100644 --- a/docs/checks/InconsistentArrays.md.html +++ b/docs/checks/InconsistentArrays.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -50,22 +52,16 @@ res/values/arrays.xml:3:Warning: Array security_questions has an inconsistent number of items (3 in values-nl-rNL/arrays.xml, 4 in values-cs/arrays.xml) [InconsistentArrays] - <string-array name="security_questions"> ^ - - res/values/arrays.xml:10:Warning: Array signal_strength has an inconsistent number of items (5 in values/arrays.xml, 6 in values-land/arrays.xml) [InconsistentArrays] - <array name="signal_strength"> ^ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `res/values/arrays.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -89,6 +85,68 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/values-cs/arrays.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<resources xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + <string-array name="security_questions"> + <item>"Oblíbené jídlo?"</item> + <item>"Město narození."</item> + <item>"Jméno nejlepšího kamaráda z dětství?"</item> + <item>"Název střední školy"</item> + </string-array> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/values-land/arrays.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<resources> + <array name="signal_strength"> + <item>@drawable/ic_setups_signal_0</item> + <item>@drawable/ic_setups_signal_1</item> + <item>@drawable/ic_setups_signal_2</item> + <item>@drawable/ic_setups_signal_3</item> + <item>@drawable/ic_setups_signal_4</item> + <item>@drawable/extra</item> + </array> +</resources> + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/values-nl-rNL/arrays.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<resources xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + <string-array name="security_questions"> + <item>"Favoriete eten?"</item> + <item>"Geboorteplaats?"</item> + <item>"Naam van middelbare school?"</item> + </string-array> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/values-es/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers + +<resources xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + <string name="home_title">"Casa"</string> + <string name="show_all_apps">"Todo"</string> + <string name="menu_wallpaper">"Papel tapiz"</string> + <string name="menu_search">"Búsqueda"</string> + <!-- no translation found for menu_settings (1769059051084007158) --> + <skip /> + <string name="wallpaper_instructions">"Puntee en la imagen para establecer papel tapiz vertical"</string> + + <string-array name="security_questions"> + <item>"Comida favorita"</item> + <item>"Ciudad de nacimiento"</item> + <item>"Nombre de tu mejor amigo/a de la infancia"</item> + <item>"Nombre de tu colegio"</item> + </string-array> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ArraySizeDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/InconsistentLayout.md.html b/docs/checks/InconsistentLayout.md.html index 971f0daa..750ea37e 100644 --- a/docs/checks/InconsistentLayout.md.html +++ b/docs/checks/InconsistentLayout.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files and resource files Editing @@ -50,23 +52,28 @@ res/layout/layout1.xml:11:Warning: The id "button1" in layout "layout1" is missing from the following layout configurations: layout-xlarge (present in layout) [InconsistentLayout] - android:id="@+id/button1" ------------------------- - - res/layout/layout1.xml:38:Warning: The id "button4" in layout "layout1" is missing from the following layout configurations: layout-xlarge (present in layout) [InconsistentLayout] - android:id="@+id/button4" ------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Here are the relevant source files: +`src/test/pkg/X.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; +public class X { + public void X(Y parent) { + parent.foo(R.id.button1); + parent.foo(R.id.button4); + } +} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: - `res/layout/layout1.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers <?xml version="1.0" encoding="utf-8"?> @@ -116,6 +123,23 @@ </RelativeLayout> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/layout-xlarge/layout1.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" > + + <Button + android:id="@+id/my_id2" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Button" /> + +</LinearLayout> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/LayoutConsistencyDetectorTest.java) for the unit tests for this check to see additional scenarios. @@ -129,12 +153,6 @@ You can suppress false positives using one of the following mechanisms: -* Adding the suppression attribute `tools:ignore="InconsistentLayout"` - on the problematic XML element (or one of its enclosing elements). - You may also need to add the following namespace declaration on the - root element in the XML file if it's not already there: - `xmlns:tools="http://schemas.android.com/tools"`. - * Using a suppression annotation like this on the enclosing element: @@ -163,6 +181,12 @@ problematicStatement() ``` +* Adding the suppression attribute `tools:ignore="InconsistentLayout"` + on the problematic XML element (or one of its enclosing elements). + You may also need to add the following namespace declaration on the + root element in the XML file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + * Using a special `lint.xml` file in the source tree which turns off the check in that folder and any sub folder. A simple file might look like this: diff --git a/docs/checks/IncorrectChainMarginsUsage.md.html b/docs/checks/IncorrectChainMarginsUsage.md.html new file mode 100644 index 00000000..6ca716b7 --- /dev/null +++ b/docs/checks/IncorrectChainMarginsUsage.md.html @@ -0,0 +1,147 @@ + +(#) Use `LayoutReference.withChainParams()` to define margins for elements in a Chain + +!!! WARNING: Use `LayoutReference.withChainParams()` to define margins for elements in a Chain + This is a warning. + +Id +: `IncorrectChainMarginsUsage` +Summary +: Use `LayoutReference.withChainParams()` to define margins for elements in a Chain +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: Android Open Source Project +Identifier +: androidx.constraintlayout.compose +Feedback +: https://issuetracker.google.com/issues/new?component=323867&template=1023345 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.constraintlayout:constraintlayout-compose](androidx_constraintlayout_constraintlayout-compose.md.html) +Since +: 1.1.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/constraintlayout/constraintlayout-compose-lint/src/main/java/androidx/constraintlayout/compose/lint/ConstraintLayoutDslDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/constraintlayout/constraintlayout-compose-lint/src/test/java/androidx/constraintlayout/compose/lint/ConstraintLayoutDslDetectorTest.kt) +Copyright Year +: 2022 + +If you understand how a chain works, it might seem obvious to add +margins by re-creating the constraints with the desired margin. However, +in Compose, helpers will ignore custom constraints in favor of their +layout implementation. So instead, use +`LayoutReference.withChainParams()` to define margins for Chains. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.constraintlayout:constraintlayout-compose:1.1.1") + +// build.gradle +implementation 'androidx.constraintlayout:constraintlayout-compose:1.1.1' + +// build.gradle.kts with version catalogs: +implementation(libs.constraintlayout.compose) + +# libs.versions.toml +[versions] +constraintlayout-compose = "1.1.1" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +constraintlayout-compose = { + module = "androidx.constraintlayout:constraintlayout-compose", + version.ref = "constraintlayout-compose" +} +``` + +1.1.1 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.constraintlayout:constraintlayout-compose](androidx_constraintlayout_constraintlayout-compose.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("IncorrectChainMarginsUsage") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("IncorrectChainMarginsUsage") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection IncorrectChainMarginsUsage + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="IncorrectChainMarginsUsage" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'IncorrectChainMarginsUsage' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore IncorrectChainMarginsUsage ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/IncorrectMatchParentUsage.md.html b/docs/checks/IncorrectMatchParentUsage.md.html new file mode 100644 index 00000000..3991a428 --- /dev/null +++ b/docs/checks/IncorrectMatchParentUsage.md.html @@ -0,0 +1,146 @@ + +(#) Prefer using `Dimension.percent(1f)` when defining custom constraints + +!!! WARNING: Prefer using `Dimension.percent(1f)` when defining custom constraints + This is a warning. + +Id +: `IncorrectMatchParentUsage` +Summary +: Prefer using `Dimension.percent(1f)` when defining custom constraints +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: Android Open Source Project +Identifier +: androidx.constraintlayout.compose +Feedback +: https://issuetracker.google.com/issues/new?component=323867&template=1023345 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.constraintlayout:constraintlayout-compose](androidx_constraintlayout_constraintlayout-compose.md.html) +Since +: 1.1.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/constraintlayout/constraintlayout-compose-lint/src/main/java/androidx/constraintlayout/compose/lint/ConstraintLayoutDslDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/constraintlayout/constraintlayout-compose-lint/src/test/java/androidx/constraintlayout/compose/lint/ConstraintLayoutDslDetectorTest.kt) +Copyright Year +: 2022 + +`Dimension.matchParent` forces the constraints to be an equivalent of +`centerHorizontallyTo(parent)` or `centerVerticallyTo(parent)` according +to the assigned dimension which can lead to unexpected behavior. To +avoid that, prefer using `Dimension.percent(1f)` + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.constraintlayout:constraintlayout-compose:1.1.1") + +// build.gradle +implementation 'androidx.constraintlayout:constraintlayout-compose:1.1.1' + +// build.gradle.kts with version catalogs: +implementation(libs.constraintlayout.compose) + +# libs.versions.toml +[versions] +constraintlayout-compose = "1.1.1" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +constraintlayout-compose = { + module = "androidx.constraintlayout:constraintlayout-compose", + version.ref = "constraintlayout-compose" +} +``` + +1.1.1 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.constraintlayout:constraintlayout-compose](androidx_constraintlayout_constraintlayout-compose.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("IncorrectMatchParentUsage") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("IncorrectMatchParentUsage") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection IncorrectMatchParentUsage + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="IncorrectMatchParentUsage" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'IncorrectMatchParentUsage' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore IncorrectMatchParentUsage ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/IncorrectReferencesDeclaration.md.html b/docs/checks/IncorrectReferencesDeclaration.md.html new file mode 100644 index 00000000..28ad1ced --- /dev/null +++ b/docs/checks/IncorrectReferencesDeclaration.md.html @@ -0,0 +1,209 @@ + +(#) `createRefsFor(vararg ids: Any)` should have at least one argument and match assigned variables + +!!! ERROR: `createRefsFor(vararg ids: Any)` should have at least one argument and match assigned variables + This is an error. + +Id +: `IncorrectReferencesDeclaration` +Summary +: `createRefsFor(vararg ids: Any)` should have at least one argument and match assigned variables +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: Android Open Source Project +Identifier +: androidx.constraintlayout.compose +Feedback +: https://issuetracker.google.com/issues/new?component=323867&template=1023345 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.constraintlayout:constraintlayout-compose](androidx_constraintlayout_constraintlayout-compose.md.html) +Since +: 1.1.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/constraintlayout/constraintlayout-compose-lint/src/main/java/androidx/constraintlayout/compose/lint/ConstraintLayoutDslDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/constraintlayout/constraintlayout-compose-lint/src/test/java/androidx/constraintlayout/compose/lint/ConstraintLayoutDslDetectorTest.kt) +Copyright Year +: 2022 + +`createRefsFor(vararg ids: Any)` conveniently allows creating multiple +references using destructuring. However, providing an un-equal amount of +arguments to the assigned variables will result in unexpected behavior +since the variables may reference a ConstrainedLayoutReference with +unknown ID. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/example/test.kt:8:Error: Arguments of createRefsFor (2) do not match +assigned variables (3) [IncorrectReferencesDeclaration] + val (box1, text1, image1) = createRefsFor("box", "text") + ------------- +src/example/test.kt:9:Error: Arguments of createRefsFor (3) do not match +assigned variables (2) [IncorrectReferencesDeclaration] + val (box2, text2) = createRefsFor("box", "text", "image") + ------------- +src/example/test.kt:19:Error: Arguments of createRefsFor (2) do not +match assigned variables (3) [IncorrectReferencesDeclaration] + val (box1, text1, image1) = createRefsFor("box", "text") + ------------- +src/example/test.kt:20:Error: Arguments of createRefsFor (3) do not +match assigned variables (2) [IncorrectReferencesDeclaration] + val (box2, text2) = createRefsFor("box", "text", "image") + ------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/example/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package example + +import androidx.constraintlayout.compose.* + +fun Test() { + val scopeApplier: ConstraintSetScope.() -> Unit = { + val (box, text) = createRefsFor("box", "text") + val (box1, text1, image1) = createRefsFor("box", "text") + val (box2, text2) = createRefsFor("box", "text", "image") + + val ids = arrayOf("box", "text") + val (box3, text3, image3) = createRefsFor(*ids) + } +} + +fun Test2() { + val scopeApplier: MotionSceneScope.() -> Unit = { + val (box, text) = createRefsFor("box", "text") + val (box1, text1, image1) = createRefsFor("box", "text") + val (box2, text2) = createRefsFor("box", "text", "image") + + val ids = arrayOf("box", "text") + val (box3, text3, image3) = createRefsFor(*ids) + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/constraintlayout/constraintlayout-compose-lint/src/test/java/androidx/constraintlayout/compose/lint/ConstraintLayoutDslDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `ConstraintLayoutDslDetector.createRefsForArgumentTest`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=323867&template=1023345. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.constraintlayout:constraintlayout-compose:1.1.1") + +// build.gradle +implementation 'androidx.constraintlayout:constraintlayout-compose:1.1.1' + +// build.gradle.kts with version catalogs: +implementation(libs.constraintlayout.compose) + +# libs.versions.toml +[versions] +constraintlayout-compose = "1.1.1" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +constraintlayout-compose = { + module = "androidx.constraintlayout:constraintlayout-compose", + version.ref = "constraintlayout-compose" +} +``` + +1.1.1 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.constraintlayout:constraintlayout-compose](androidx_constraintlayout_constraintlayout-compose.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("IncorrectReferencesDeclaration") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("IncorrectReferencesDeclaration") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection IncorrectReferencesDeclaration + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="IncorrectReferencesDeclaration" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'IncorrectReferencesDeclaration' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore IncorrectReferencesDeclaration ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/InefficientWeight.md.html b/docs/checks/InefficientWeight.md.html index 85c7ee98..2cbc8364 100644 --- a/docs/checks/InefficientWeight.md.html +++ b/docs/checks/InefficientWeight.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -43,18 +45,12 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/inefficient_weight.xml:10:Warning: Use a layout_width of 0dp instead of match_parent for better performance [InefficientWeight] - android:layout_width="match_parent" ----------------------------------- - - res/layout/inefficient_weight.xml:24:Warning: Use a layout_height of 0dp instead of wrap_content for better performance [InefficientWeight] - android:layout_height="wrap_content" ------------------------------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/InflateParams.md.html b/docs/checks/InflateParams.md.html index 57ba62dc..37eb24ce 100644 --- a/docs/checks/InflateParams.md.html +++ b/docs/checks/InflateParams.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files and resource files Editing @@ -42,22 +44,16 @@ src/test/pkg/LayoutInflationTest.java:13:Warning: Avoid passing null as the view root (needed to resolve layout parameters on the inflated layout's root element) [InflateParams] - convertView = mInflater.inflate(R.layout.your_layout, null); ---- - - src/test/pkg/LayoutInflationTest.java:14:Warning: Avoid passing null as the view root (needed to resolve layout parameters on the inflated layout's root element) [InflateParams] - convertView = mInflater.inflate(R.layout.your_layout, null, true); ---- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `src/test/pkg/LayoutInflationTest.java`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers @@ -103,6 +99,23 @@ } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/layout/your_layout.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:id="@+id/LinearLayout1" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" /> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/layout-port/your_layout.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<TextView xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@id/text1" + style="?android:attr/listSeparatorTextViewStyle" /> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/LayoutInflationDetectorTest.java) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/InflationInItemDecoration.md.html b/docs/checks/InflationInItemDecoration.md.html new file mode 100644 index 00000000..ef12c0a8 --- /dev/null +++ b/docs/checks/InflationInItemDecoration.md.html @@ -0,0 +1,147 @@ + +(#) Avoid inflating a view to display text + +!!! WARNING: Avoid inflating a view to display text + This is a warning. + +Id +: `InflationInItemDecoration` +Summary +: Avoid inflating a view to display text +Severity +: Warning +Category +: Accessibility +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.8.1 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/ui/ItemDecorationViewBindingDetector.kt) +Copyright Year +: 2024 + +ViewBinding should not be used in `ItemDecoration`. If an inflated view +contains meaningful textual information, it will not be visible to +TalkBack. This means that screen reader users will not be able to know +what is on the screen. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("InflationInItemDecoration") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("InflationInItemDecoration") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection InflationInItemDecoration + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="InflationInItemDecoration" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'InflationInItemDecoration' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore InflationInItemDecoration ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/InjectInJava.md.html b/docs/checks/InjectInJava.md.html new file mode 100644 index 00000000..3882a2ff --- /dev/null +++ b/docs/checks/InjectInJava.md.html @@ -0,0 +1,228 @@ + +(#) Only Kotlin classes should be injected in order for Anvil to work + +!!! ERROR: Only Kotlin classes should be injected in order for Anvil to work + This is an error. + +Id +: `InjectInJava` +Summary +: Only Kotlin classes should be injected in order for Anvil to work +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/InjectInJavaDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/InjectInJavaDetectorTest.kt) +Copyright Year +: 2021 + +Only Kotlin classes should be injected in order for Anvil to work. If +you cannot easily convert this to Kotlin, consider manually providing it +via a Kotlin `@Module`-annotated object. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test/pkg/JavaClass.java:9:Error: Only Kotlin classes should be +injected in order for Anvil to work. [InjectInJava] + @Inject String memberInjected; + ------- +src/test/pkg/JavaClass.java:11:Error: Only Kotlin classes should be +injected in order for Anvil to work. [InjectInJava] + @Inject JavaClass(String constructorInjected) { + ------- +src/test/pkg/JavaClass.java:15:Error: Only Kotlin classes should be +injected in order for Anvil to work. [InjectInJava] + @Inject void methodInject(String value) { + ------- +src/test/pkg/JavaClass.java:21:Error: Only Kotlin classes should be +injected in order for Anvil to work. [InjectInJava] + @AssistedInject JavaAssistedClass(@Assisted String assistedParam) { + --------------- +src/test/pkg/JavaClass.java:25:Error: Only Kotlin classes should be +injected in order for Anvil to work. [InjectInJava] + @AssistedFactory + ---------------- +src/test/pkg/JavaClass.java:31:Error: Only Kotlin classes should be +injected in order for Anvil to work. [InjectInJava] + @Module static abstract class ExampleModule { + ------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test/pkg/JavaClass.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; + +import javax.inject.Inject; +import dagger.Module; +import dagger.assisted.AssistedInject; +import dagger.assisted.AssistedFactory; + +class JavaClass { + @Inject String memberInjected; + + @Inject JavaClass(String constructorInjected) { + + } + + @Inject void methodInject(String value) { + + } + + static class JavaAssistedClass { + + @AssistedInject JavaAssistedClass(@Assisted String assistedParam) { + + } + + @AssistedFactory + interface Factory { + JavaAssistedClass create(String assistedParam); + } + } + + @Module static abstract class ExampleModule { + + } +} + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/InjectInJavaDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `InjectInJavaDetector.javaIsNotOk`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("InjectInJava") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("InjectInJava") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection InjectInJava + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="InjectInJava" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'InjectInJava' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore InjectInJava ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/InlinedApi.md.html b/docs/checks/InlinedApi.md.html index f2036387..16ea1fc9 100644 --- a/docs/checks/InlinedApi.md.html +++ b/docs/checks/InlinedApi.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files Editing @@ -59,11 +61,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test.kt:8:Warning: Field requires API level 29 (current min is 21): android.media.MediaFormat#MIMETYPE_AUDIO_AC4 [InlinedApi] - val format: String = MediaFormat.MIMETYPE_AUDIO_AC4 ------------------------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here are the relevant source files: diff --git a/docs/checks/InnerclassSeparator.md.html b/docs/checks/InnerclassSeparator.md.html index 40ddafea..d08f1dcf 100644 --- a/docs/checks/InnerclassSeparator.md.html +++ b/docs/checks/InnerclassSeparator.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Manifest files and resource files Editing @@ -46,14 +48,11 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text AndroidManifest.xml:5:Warning: Use '$' instead of '.' for inner classes; replace ".Foo.Bar" with ".Foo$Bar" [InnerclassSeparator] - android:name=".Foo.Bar" -------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `AndroidManifest.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -68,6 +67,18 @@ </manifest> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/test/pkg/Foo.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; + +import android.app.Activity; + +public class Foo { + public static class Bar extends Activity { + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/MissingClassDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/InsecureBaseConfiguration.md.html b/docs/checks/InsecureBaseConfiguration.md.html index e48b43e5..d1c84664 100644 --- a/docs/checks/InsecureBaseConfiguration.md.html +++ b/docs/checks/InsecureBaseConfiguration.md.html @@ -18,23 +18,25 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.5.0 (August 2019) Affects : Resource files Editing : This check runs on the fly in the IDE editor See +: https://goo.gle/InsecureBaseConfiguration +See : https://developer.android.com/preview/features/security-config.html Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/NetworkSecurityConfigDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/NetworkSecurityConfigDetectorTest.java) -Copyright Year -: 2016 Permitting cleartext traffic could allow eavesdroppers to intercept data sent by your app, which impacts the privacy of your users. Consider only allowing encrypted traffic by setting the `cleartextTrafficPermitted` -tag to `"false"`. +tag to `false`. !!! Tip This lint check has an associated quickfix available in the IDE. @@ -45,11 +47,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/xml/network_config.xml:3:Warning: Insecure Base Configuration [InsecureBaseConfiguration] - <base-config cleartextTrafficPermitted="true"> ---- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/InsecureDnsSdkLevel.md.html b/docs/checks/InsecureDnsSdkLevel.md.html new file mode 100644 index 00000000..0ed54b40 --- /dev/null +++ b/docs/checks/InsecureDnsSdkLevel.md.html @@ -0,0 +1,170 @@ + +(#) Application vulnerable to DNS spoofing attacks + +!!! WARNING: Application vulnerable to DNS spoofing attacks + This is a warning. + +Id +: `InsecureDnsSdkLevel` +Summary +: Application vulnerable to DNS spoofing attacks +Severity +: Warning +Category +: Security +Platform +: Android +Vendor +: Google - Android 3P Vulnerability Research +Contact +: https://github.com/google/android-security-lints +Feedback +: https://github.com/google/android-security-lints/issues +Min +: Lint 4.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.android.security.lint:lint](com_android_security_lint_lint.md.html) +Since +: 1.0.1 +Affects +: Manifest files +Editing +: This check runs on the fly in the IDE editor +See +: https://goo.gle/InsecureDnsSdkLevel +Implementation +: [Source Code](https://github.com/google/android-security-lints/tree/main/checks/src/main/java/com/example/lint/checks/DnsConfigDetector.kt) +Tests +: [Source Code](https://github.com/google/android-security-lints/tree/main/checks/src/test/java/com/example/lint/checks/DnsConfigDetectorTest.kt) +Copyright Year +: 2024 + +Apps targeting SDK versions earlier than 28 are susceptible to DNS +attacks like DNS spoofing or cache poisoning. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +AndroidManifest.xml:2:Warning: Update your application's target SDK +version to 28 and above to make use of the Android OS's built-in +transport security features [InsecureDnsSdkLevel] +<uses-sdk android:targetSdkVersion='27'/> + -- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`AndroidManifest.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<manifest xmlns:android='http://schemas.android.com/apk/res/android' package='test.pkg'> +<uses-sdk android:targetSdkVersion='27'/> +<application android:debuggable='false'> + <activity android:name='com.example.MainActivity'></activity> +</application> +</manifest> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/google/android-security-lints/tree/main/checks/src/test/java/com/example/lint/checks/DnsConfigDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `DnsConfigDetector.testWhenTargetSdkBelowSecureDnsTransportPatch_showsWarning`. +To report a problem with this extracted sample, visit +https://github.com/google/android-security-lints/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.android.security.lint:lint:1.0.3") + +// build.gradle +lintChecks 'com.android.security.lint:lint:1.0.3' + +// build.gradle.kts with version catalogs: +lintChecks(libs.com.android.security.lint.lint) + +# libs.versions.toml +[versions] +com-android-security-lint-lint = "1.0.3" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +com-android-security-lint-lint = { + module = "com.android.security.lint:lint", + version.ref = "com-android-security-lint-lint" +} +``` + +1.0.3 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.android.security.lint:lint](com_android_security_lint_lint.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute + `tools:ignore="InsecureDnsSdkLevel"` on the problematic XML element + (or one of its enclosing elements). You may also need to add the + following namespace declaration on the root element in the XML file + if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <manifest xmlns:tools="http://schemas.android.com/tools"> + ... + <uses-sdk tools:ignore="InsecureDnsSdkLevel" .../> + ... + </manifest> + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="InsecureDnsSdkLevel" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'InsecureDnsSdkLevel' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore InsecureDnsSdkLevel ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/InsecurePermissionProtectionLevel.md.html b/docs/checks/InsecurePermissionProtectionLevel.md.html new file mode 100644 index 00000000..29147a02 --- /dev/null +++ b/docs/checks/InsecurePermissionProtectionLevel.md.html @@ -0,0 +1,173 @@ + +(#) Custom permission created with a normal `protectionLevel` + +!!! WARNING: Custom permission created with a normal `protectionLevel` + This is a warning. + +Id +: `InsecurePermissionProtectionLevel` +Summary +: Custom permission created with a normal `protectionLevel` +Severity +: Warning +Category +: Security +Platform +: Android +Vendor +: Google - Android 3P Vulnerability Research +Contact +: https://github.com/google/android-security-lints +Feedback +: https://github.com/google/android-security-lints/issues +Min +: Lint 4.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.android.security.lint:lint](com_android_security_lint_lint.md.html) +Since +: 1.0.1 +Affects +: Manifest files +Editing +: This check runs on the fly in the IDE editor +See +: https://goo.gle/InsecurePermissionProtectionLevel +Implementation +: [Source Code](https://github.com/google/android-security-lints/tree/main/checks/src/main/java/com/example/lint/checks/PermissionDetector.kt) +Tests +: [Source Code](https://github.com/google/android-security-lints/tree/main/checks/src/test/java/com/example/lint/checks/PermissionDetectorTest.kt) +Copyright Year +: 2024 + +Custom permissions are designed for sharing resources and capabilities +with other apps. However, typos and insufficient protection levels can +negate the usage of these custom permissions altogether. In general, use +`signature` or higher protection levels whenever possible, as this +ensures only other apps signed with the same certificate can access +these protected features. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +AndroidManifest.xml:2:Warning: Custom permissions should have signature +`protectionLevel`s or higher [InsecurePermissionProtectionLevel] +<permission android:name="com.android.example.permission.CUSTOM_PERMISSION" /> +------------------------------------------------------------------------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`AndroidManifest.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<manifest xmlns:android='http://schemas.android.com/apk/res/android' package='test.pkg'> +<permission android:name="com.android.example.permission.CUSTOM_PERMISSION" /> +<application android:debuggable='false'> + <activity android:name='com.example.MainActivity'></activity> +</application> +</manifest> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/google/android-security-lints/tree/main/checks/src/test/java/com/example/lint/checks/PermissionDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `PermissionDetector.testWhenCustomPermissionNoSpecifiedProtectionLevel_showsWarning`. +To report a problem with this extracted sample, visit +https://github.com/google/android-security-lints/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.android.security.lint:lint:1.0.3") + +// build.gradle +lintChecks 'com.android.security.lint:lint:1.0.3' + +// build.gradle.kts with version catalogs: +lintChecks(libs.com.android.security.lint.lint) + +# libs.versions.toml +[versions] +com-android-security-lint-lint = "1.0.3" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +com-android-security-lint-lint = { + module = "com.android.security.lint:lint", + version.ref = "com-android-security-lint-lint" +} +``` + +1.0.3 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.android.security.lint:lint](com_android_security_lint_lint.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute + `tools:ignore="InsecurePermissionProtectionLevel"` on the + problematic XML element (or one of its enclosing elements). You may + also need to add the following namespace declaration on the root + element in the XML file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <manifest xmlns:tools="http://schemas.android.com/tools"> + ... + <permission tools:ignore="InsecurePermissionProtectionLevel" .../> + ... + </manifest> + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="InsecurePermissionProtectionLevel" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'InsecurePermissionProtectionLevel' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore InsecurePermissionProtectionLevel ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/InsecureStickyBroadcastsMethod.md.html b/docs/checks/InsecureStickyBroadcastsMethod.md.html new file mode 100644 index 00000000..6f5ce93f --- /dev/null +++ b/docs/checks/InsecureStickyBroadcastsMethod.md.html @@ -0,0 +1,189 @@ + +(#) Usage of insecure sticky broadcasts + +!!! WARNING: Usage of insecure sticky broadcasts + This is a warning. + +Id +: `InsecureStickyBroadcastsMethod` +Summary +: Usage of insecure sticky broadcasts +Severity +: Warning +Category +: Security +Platform +: Any +Vendor +: Google - Android 3P Vulnerability Research +Contact +: https://github.com/google/android-security-lints +Feedback +: https://github.com/google/android-security-lints/issues +Min +: Lint 4.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.android.security.lint:lint](com_android_security_lint_lint.md.html) +Since +: 1.0.2 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +See +: https://goo.gle/InsecureStickyBroadcastsMethod +Implementation +: [Source Code](https://github.com/google/android-security-lints/tree/main/checks/src/main/java/com/example/lint/checks/StickyBroadcastsDetector.kt) +Tests +: [Source Code](https://github.com/google/android-security-lints/tree/main/checks/src/test/java/com/example/lint/checks/StickyBroadcastsDetectorTest.kt) +Copyright Year +: 2024 + +Sticky broadcasts can be accessed, sent, or modified by anyone, +resulting in potential security issues. For this reason, it was +deprecated in API level 21 and other mechanisms such as databases or +non-sticky broadcasts should be used instead. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/fake/pkg/MainActivity.java:12:Warning: Sticky broadcasts can be +accessed, sent or modified by anyone. Use non-sticky broadcasts instead. +[InsecureStickyBroadcastsMethod] + sendStickyOrderedBroadcast(); + ---------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/fake/pkg/MainActivity.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package fake.pkg; + +import android.app.Activity; +import android.os.Bundle; + +@Suppress("DEPRECATION") +public class MainActivity extends Activity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + sendStickyOrderedBroadcast(); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/google/android-security-lints/tree/main/checks/src/test/java/com/example/lint/checks/StickyBroadcastsDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `StickyBroadcastsDetector.stickyBroadcastMethodCall_showsWarning`. +To report a problem with this extracted sample, visit +https://github.com/google/android-security-lints/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.android.security.lint:lint:1.0.3") + +// build.gradle +lintChecks 'com.android.security.lint:lint:1.0.3' + +// build.gradle.kts with version catalogs: +lintChecks(libs.com.android.security.lint.lint) + +# libs.versions.toml +[versions] +com-android-security-lint-lint = "1.0.3" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +com-android-security-lint-lint = { + module = "com.android.security.lint:lint", + version.ref = "com-android-security-lint-lint" +} +``` + +1.0.3 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.android.security.lint:lint](com_android_security_lint_lint.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("InsecureStickyBroadcastsMethod") + fun method() { + sendStickyOrderedBroadcast(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("InsecureStickyBroadcastsMethod") + void method() { + sendStickyOrderedBroadcast(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection InsecureStickyBroadcastsMethod + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="InsecureStickyBroadcastsMethod" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'InsecureStickyBroadcastsMethod' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore InsecureStickyBroadcastsMethod ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/InsecureStickyBroadcastsPermission.md.html b/docs/checks/InsecureStickyBroadcastsPermission.md.html new file mode 100644 index 00000000..398ed902 --- /dev/null +++ b/docs/checks/InsecureStickyBroadcastsPermission.md.html @@ -0,0 +1,169 @@ + +(#) Usage of insecure sticky broadcasts + +!!! WARNING: Usage of insecure sticky broadcasts + This is a warning. + +Id +: `InsecureStickyBroadcastsPermission` +Summary +: Usage of insecure sticky broadcasts +Severity +: Warning +Category +: Security +Platform +: Android +Vendor +: Google - Android 3P Vulnerability Research +Contact +: https://github.com/google/android-security-lints +Feedback +: https://github.com/google/android-security-lints/issues +Min +: Lint 4.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.android.security.lint:lint](com_android_security_lint_lint.md.html) +Since +: 1.0.2 +Affects +: Manifest files +Editing +: This check runs on the fly in the IDE editor +See +: https://goo.gle/InsecureStickyBroadcastsPermission +Implementation +: [Source Code](https://github.com/google/android-security-lints/tree/main/checks/src/main/java/com/example/lint/checks/StickyBroadcastsDetector.kt) +Tests +: [Source Code](https://github.com/google/android-security-lints/tree/main/checks/src/test/java/com/example/lint/checks/StickyBroadcastsDetectorTest.kt) +Copyright Year +: 2024 + +Sticky broadcasts can be accessed, sent, or modified by anyone, +resulting in potential security issues. For this reason, it was +deprecated in API level 21 and other mechanisms such as databases or +non-sticky broadcasts should be used instead. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +AndroidManifest.xml:2:Warning: Sticky broadcasts can be accessed, sent +or modified by anyone. Use non-sticky broadcasts instead. +[InsecureStickyBroadcastsPermission] + <uses-permission android:name="android.permission.BROADCAST_STICKY"/> + --------------------------------------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`AndroidManifest.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<manifest xmlns:android='http://schemas.android.com/apk/res/android' package='test.pkg'> + <uses-permission android:name="android.permission.BROADCAST_STICKY"/> + <application> + <activity android:name='com.example.MainActivity'></activity> + </application> + </manifest> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/google/android-security-lints/tree/main/checks/src/test/java/com/example/lint/checks/StickyBroadcastsDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `StickyBroadcastsDetector.stickyBroadcastPermissionInManifest_showsWarning`. +To report a problem with this extracted sample, visit +https://github.com/google/android-security-lints/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.android.security.lint:lint:1.0.3") + +// build.gradle +lintChecks 'com.android.security.lint:lint:1.0.3' + +// build.gradle.kts with version catalogs: +lintChecks(libs.com.android.security.lint.lint) + +# libs.versions.toml +[versions] +com-android-security-lint-lint = "1.0.3" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +com-android-security-lint-lint = { + module = "com.android.security.lint:lint", + version.ref = "com-android-security-lint-lint" +} +``` + +1.0.3 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.android.security.lint:lint](com_android_security_lint_lint.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute + `tools:ignore="InsecureStickyBroadcastsPermission"` on the + problematic XML element (or one of its enclosing elements). You may + also need to add the following namespace declaration on the root + element in the XML file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <manifest xmlns:tools="http://schemas.android.com/tools"> + ... + <uses-permission tools:ignore="InsecureStickyBroadcastsPermission" .../> + ... + </manifest> + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="InsecureStickyBroadcastsPermission" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'InsecureStickyBroadcastsPermission' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore InsecureStickyBroadcastsPermission ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/InstantApps.md.html b/docs/checks/InstantApps.md.html index 55d11b41..c0308175 100644 --- a/docs/checks/InstantApps.md.html +++ b/docs/checks/InstantApps.md.html @@ -1,185 +1,8 @@ -(#) Instant App Issues +(#) InstantApps -!!! WARNING: Instant App Issues - This is a warning. - -Id -: `InstantApps` -Summary -: Instant App Issues -Severity -: Warning -Category -: Correctness -Platform -: Android -Vendor -: Android Open Source Project -Feedback -: https://issuetracker.google.com/issues/new?component=192708 -Affects -: Kotlin and Java files and manifest files -Editing -: This check runs on the fly in the IDE editor -Implementation -: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/InstantAppDetector.java) -Tests -: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/InstantAppDetectorTest.java) -Copyright Year -: 2017 - -This issue flags code that will not work correctly in Instant Apps. - -(##) Example - -Here is an example of lint warnings produced by this check: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -src/main/AndroidManifest.xml:10:Warning: Instant Apps are not allowed to -export services, receivers, and providers [InstantApps] - - <service android:name=".WearMessageListenerService"> - ^ - - -src/main/AndroidManifest.xml:15:Warning: Instant Apps are not allowed to -export services, receivers, and providers [InstantApps] - - <provider android:name=".TestService" /> - ---------------------------------------- - - -src/main/AndroidManifest.xml:16:Warning: Instant Apps are not allowed to -export services, receivers, and providers [InstantApps] - - <receiver android:name=".DeviceAdminTestReceiver" - ^ - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Here is the source file referenced above: - -`src/main/AndroidManifest.xml`: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers -<?xml version="1.0" encoding="utf-8"?> -<manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="test.pkg" > - <uses-sdk android:targetSdkVersion="23" /> - - <application - android:label="@string/app_name" - android:allowBackup="false" - android:theme="@style/AppTheme" > - <service android:name=".WearMessageListenerService"> - <intent-filter> - <action android:name="com.google.android.gms.wearable.BIND_LISTENER" /> - </intent-filter> - </service> - <provider android:name=".TestService" /> - <receiver android:name=".DeviceAdminTestReceiver" - android:label="@string/app_name" - android:description="@string/app_name" - android:permission="android.permission.BIND_DEVICE_ADMIN"> - <meta-data android:name="android.app.device_admin" - android:resource="@xml/device_admin"/> - <intent-filter> - <action android:name="android.app.action.DEVICE_ADMIN_ENABLED"/> - </intent-filter> - </receiver> - - </application> - -</manifest> -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -You can also visit the -[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/InstantAppDetectorTest.java) -for the unit tests for this check to see additional scenarios. - -The above example was automatically extracted from the first unit test -found for this lint check, `InstantAppDetector.testForbiddenManifestTags`. -To report a problem with this extracted sample, visit -https://issuetracker.google.com/issues/new?component=192708. - -(##) Suppressing - -You can suppress false positives using one of the following mechanisms: - -* Adding the suppression attribute `tools:ignore="InstantApps"` on the - problematic XML element (or one of its enclosing elements). You may - also need to add the following namespace declaration on the root - element in the XML file if it's not already there: - `xmlns:tools="http://schemas.android.com/tools"`. - - ```xml - <?xml version="1.0" encoding="UTF-8"?> - <manifest xmlns:tools="http://schemas.android.com/tools"> - ... - <provider tools:ignore="InstantApps" .../> - ... - </manifest> - ``` - -* Using a suppression annotation like this on the enclosing - element: - - ```kt - // Kotlin - @Suppress("InstantApps") - fun method() { - notify(...) - } - ``` - - or - - ```java - // Java - @SuppressWarnings("InstantApps") - void method() { - notify(...); - } - ``` - -* Using a suppression comment like this on the line above: - - ```kt - //noinspection InstantApps - problematicStatement() - ``` - -* Using a special `lint.xml` file in the source tree which turns off - the check in that folder and any sub folder. A simple file might look - like this: - ```xml - <?xml version="1.0" encoding="UTF-8"?> - <lint> - <issue id="InstantApps" severity="ignore" /> - </lint> - ``` - Instead of `ignore` you can also change the severity here, for - example from `error` to `warning`. You can find additional - documentation on how to filter issues by path, regular expression and - so on - [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). - -* In Gradle projects, using the DSL syntax to configure lint. For - example, you can use something like - ```gradle - lintOptions { - disable 'InstantApps' - } - ``` - In Android projects this should be nested inside an `android { }` - block. - -* For manual invocations of `lint`, using the `--ignore` flag: - ``` - $ lint --ignore InstantApps ...` - ``` - -* Last, but not least, using baselines, as discussed - [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). +The issue for this id has been deleted or marked obsolete and can now be +ignored. +(Additional metadata not available.) \ No newline at end of file diff --git a/docs/checks/Instantiatable.md.html b/docs/checks/Instantiatable.md.html index 7b18f5b9..ac5600db 100644 --- a/docs/checks/Instantiatable.md.html +++ b/docs/checks/Instantiatable.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Manifest files and resource files Editing @@ -37,20 +39,21 @@ public, it must have an empty public constructor, and if it's an inner class, it must be a static inner class. +If you use a custom `AppComponentFactory` to instantiate app components +yourself, consider disabling this Lint issue in order to avoid false +positives. + (##) Example Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/menu/my_menu.xml:13:Error: NotView must extend android.view.View [Instantiatable] - android:actionViewClass="test.pkg.NotView" /> ---------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `res/menu/my_menu.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -70,6 +73,19 @@ </menu> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/test/pkg/SearchView.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg +import android.widget.TextView +abstract class SearchView : TextView(null) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/NotView.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg +abstract class NotView : android.app.Fragment() +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/MissingClassDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/IntentFilterExportedReceiver.md.html b/docs/checks/IntentFilterExportedReceiver.md.html index a9222f0c..ddf206e6 100644 --- a/docs/checks/IntentFilterExportedReceiver.md.html +++ b/docs/checks/IntentFilterExportedReceiver.md.html @@ -18,16 +18,18 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.2.0 (May 2022) Affects : Manifest files Editing : This check runs on the fly in the IDE editor +See +: https://goo.gle/IntentFilterExportedReceiver Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ExportedFlagDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ExportedFlagDetectorTest.kt) -Copyright Year -: 2020 Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an @@ -63,11 +65,8 @@ AndroidManifest.xml:7:Warning: As of Android 12, android:exported must be set; use true to make the activity available to other apps, and false otherwise. [IntentFilterExportedReceiver] - <receiver android:name="com.google.android.c2dm.C2DMBroadcastReceiver"> -------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/IntentFilterUniqueDataAttributes.md.html b/docs/checks/IntentFilterUniqueDataAttributes.md.html index 876d4700..59c66a4e 100644 --- a/docs/checks/IntentFilterUniqueDataAttributes.md.html +++ b/docs/checks/IntentFilterUniqueDataAttributes.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.1.0 (January 2022) Affects : Manifest files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AppLinksValidDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AppLinksValidDetectorTest.kt) -Copyright Year -: 2017 `` `` tags should only declare a single unique attribute (i.e. scheme OR host, but not both). This better matches the @@ -80,96 +80,25 @@ AndroidManifest.xml:5:Warning: Consider splitting data tag into multiple tags with individual attributes to avoid confusion [IntentFilterUniqueDataAttributes] - - <data android:scheme="https" android:host="example.com"/> - --------------------------------------------------------- - - + <data alt-android:scheme="https" alt-android:host="example.com"/> + ----------------------------------------------------------------- AndroidManifest.xml:6:Warning: Consider splitting data tag into multiple tags with individual attributes to avoid confusion [IntentFilterUniqueDataAttributes] - - <data android:scheme="http" android:host="example.org"/> - -------------------------------------------------------- - - -AndroidManifest.xml:12:Warning: Consider splitting data tag into -multiple tags with individual attributes to avoid confusion -[IntentFilterUniqueDataAttributes] - - <data - ^ - - -AndroidManifest.xml:24:Warning: Consider splitting data tag into -multiple tags with individual attributes to avoid confusion -[IntentFilterUniqueDataAttributes] - - <data android:host="example.com" android:port="41" android:path="/sub"/> - ------------------------------------------------------------------------ - - -AndroidManifest.xml:30:Warning: Consider splitting data tag into -multiple tags with individual attributes to avoid confusion -[IntentFilterUniqueDataAttributes] - - <data android:host="example.com" android:mimeType="image/jpeg"/> + <data alt-android:scheme="http" alt-android:host="example.org"/> ---------------------------------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: `AndroidManifest.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers -<manifest xmlns:android="http://schemas.android.com/apk/res/android" +<manifest xmlns:alt-android="http://schemas.android.com/apk/res/android" package="com.example.helloworld" > - <activity android:name="com.example.Activity"> + <activity alt-android:name="com.example.Activity"> <intent-filter> - <data android:scheme="https" android:host="example.com"/> - <data android:scheme="http" android:host="example.org"/> - </intent-filter> - </activity> - <receiver android:name="com.example.Receiver"> - <intent-filter> - <data android:scheme="https"/> - <data - android:host="example.com" - android:path="/path" - android:scheme="https" - /> - </intent-filter> - </receiver> - <service android:name="com.example.Service"> - <intent-filter> - <data android:scheme="https"/> - <!-- Don't warn on only host and port --> - <data android:host="example.com" android:port="40"/> - <data android:host="example.com" android:port="41" android:path="/sub"/> - </intent-filter> - </service> - <provider android:name="com.example.Provider"> - <intent-filter> - <data android:scheme="https"/> - <data android:host="example.com" android:mimeType="image/jpeg"/> - </intent-filter> - </provider> - <activity android:name="com.example.Activity2"> - <intent-filter> - <data android:scheme="https" android:host="example.com"/> - <!-- Don't warn on multiple attributes of only path variants--> - <data - android:pathPrefix="/prefix" - android:path="/path" - android:pathPattern="/pattern/*" - /> - </intent-filter> - </activity> - <activity android:name="com.example.Activity3"> - <intent-filter> - <!-- Don't warn on only 1 data tag --> - <data android:scheme="https" android:host="example.com"/> + <data alt-android:scheme="https" alt-android:host="example.com"/> + <data alt-android:scheme="http" alt-android:host="example.org"/> </intent-filter> </activity> </manifest> @@ -179,11 +108,6 @@ [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AppLinksValidDetectorTest.kt) for the unit tests for this check to see additional scenarios. -The above example was automatically extracted from the first unit test -found for this lint check, `AppLinksValidDetector.testIntentFilterDataDeclaration`. -To report a problem with this extracted sample, visit -https://issuetracker.google.com/issues/new?component=192708. - (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/IntentReset.md.html b/docs/checks/IntentReset.md.html index b0bbd45f..74c35927 100644 --- a/docs/checks/IntentReset.md.html +++ b/docs/checks/IntentReset.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.2.0 (September 2018) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/IntentDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/IntentDetectorTest.kt) -Copyright Year -: 2018 Intent provides the following APIs: `setData(Uri)` and `setType(String)`. Unfortunately, setting one clears the other. If you @@ -38,20 +38,14 @@ Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -src/test/pkg/IntentTest.java:19:Warning: Calling setType after calling +src/test/pkg/IntentTest.java:18:Warning: Calling setType after calling setData will clear the data: Call setDataAndType instead? [IntentReset] - intent.setType(type); // ERROR 1.1 ------------- - - -src/test/pkg/IntentTest.java:26:Warning: Calling setData after calling +src/test/pkg/IntentTest.java:25:Warning: Calling setData after calling setType will clear the type: Call setDataAndType instead? [IntentReset] - intent.setData(uri); // ERROR 2.1 ------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -63,7 +57,6 @@ import android.content.Intent; import android.net.Uri; -@SuppressWarnings({"ClassNameDiffersFromFileName", "MethodMayBeStatic"}) public class IntentTest { public void test1() { // OK: Nulls are allowed diff --git a/docs/checks/IntentWithNullActionLaunch.md.html b/docs/checks/IntentWithNullActionLaunch.md.html new file mode 100644 index 00000000..4ee39ff7 --- /dev/null +++ b/docs/checks/IntentWithNullActionLaunch.md.html @@ -0,0 +1,151 @@ + +(#) Unsafe intent launched with no action set + +!!! WARNING: Unsafe intent launched with no action set + This is a warning. + +Id +: `IntentWithNullActionLaunch` +Summary +: Unsafe intent launched with no action set +Severity +: Warning +Category +: Security +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.2.0 (November 2023) +Affects +: Kotlin and Java files and manifest files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/IntentWillNullActionDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/IntentWillNullActionDetectorTest.kt) + +Intents that have no action and do not specify a component are a +potential security risk, and using them will result in a crash in an +upcoming version of Android. If a specific app is being targeted +(including the case where the current app is the target) then set the +targeted component using `setComponent()`, `setClass()`, +`setClassName()`, or the Intent constructors that take a Class +parameter. If the intent is not intended for a specific app then the +action name should be set. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test/pkg/TestActivity.java:10:Warning: This intent has no action set +and is not explicit by component. You should either make this intent +explicit by component or set an action matching the targeted intent +filter. [IntentWithNullActionLaunch] + Intent intent = new Intent(); + ------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test/pkg/TestActivity.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; + +import android.content.Intent; +import android.app.Activity; + +public class TestActivity extends Activity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + Intent intent = new Intent(); + startActivity(intent); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/IntentWillNullActionDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("IntentWithNullActionLaunch") + fun method() { + Intent(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("IntentWithNullActionLaunch") + void method() { + new Intent(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection IntentWithNullActionLaunch + problematicStatement() + ``` + +* Adding the suppression attribute + `tools:ignore="IntentWithNullActionLaunch"` on the problematic XML + element (or one of its enclosing elements). You may also need to add + the following namespace declaration on the root element in the XML + file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="IntentWithNullActionLaunch" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'IntentWithNullActionLaunch' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore IntentWithNullActionLaunch ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/InternalAgpApiUsage.md.html b/docs/checks/InternalAgpApiUsage.md.html new file mode 100644 index 00000000..edb0f919 --- /dev/null +++ b/docs/checks/InternalAgpApiUsage.md.html @@ -0,0 +1,173 @@ + +(#) Avoid using internal Android Gradle Plugin APIs + +!!! ERROR: Avoid using internal Android Gradle Plugin APIs + This is an error. + +Id +: `InternalAgpApiUsage` +Summary +: Avoid using internal Android Gradle Plugin APIs +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: Android Open Source Project +Identifier +: androidx.lint:lint-gradle +Feedback +: https://issuetracker.google.com/issues/new?component=1147525 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.lint:lint-gradle](androidx_lint_lint-gradle.md.html) +Since +: 1.0.0-alpha02 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/lint/lint-gradle/src/main/java/androidx/lint/gradle/InternalApiUsageDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/lint/lint-gradle/src/test/java/androidx/lint/gradle/InternalApiUsageDetectorTest.kt) +Copyright Year +: 2024 + +Using internal APIs results in fragile plugin behavior as these types +have no binary +compatibility guarantees. It is best to create a feature request to open +up these +APIs if you find them useful. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test.kt:1:Error: Avoid using internal Android Gradle Plugin APIs +[InternalAgpApiUsage] +import com.android.build.gradle.internal.lint.VariantInputs +----------------------------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +import com.android.build.gradle.internal.lint.VariantInputs +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/lint/lint-gradle/src/test/java/androidx/lint/gradle/InternalApiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `InternalApiUsageDetector.Test usage of internal Android Gradle API`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=1147525. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.lint:lint-gradle:1.0.0-alpha04") + +// build.gradle +implementation 'androidx.lint:lint-gradle:1.0.0-alpha04' + +// build.gradle.kts with version catalogs: +implementation(libs.lint.gradle) + +# libs.versions.toml +[versions] +lint-gradle = "1.0.0-alpha04" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-gradle = { + module = "androidx.lint:lint-gradle", + version.ref = "lint-gradle" +} +``` + +1.0.0-alpha04 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.lint:lint-gradle](androidx_lint_lint-gradle.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("InternalAgpApiUsage") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("InternalAgpApiUsage") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection InternalAgpApiUsage + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="InternalAgpApiUsage" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'InternalAgpApiUsage' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore InternalAgpApiUsage ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/InternalGradleApiUsage.md.html b/docs/checks/InternalGradleApiUsage.md.html new file mode 100644 index 00000000..e5bf7e01 --- /dev/null +++ b/docs/checks/InternalGradleApiUsage.md.html @@ -0,0 +1,182 @@ + +(#) Avoid using internal Gradle APIs + +!!! ERROR: Avoid using internal Gradle APIs + This is an error. + +Id +: `InternalGradleApiUsage` +Summary +: Avoid using internal Gradle APIs +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: Android Open Source Project +Identifier +: androidx.lint:lint-gradle +Feedback +: https://issuetracker.google.com/issues/new?component=1147525 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.lint:lint-gradle](androidx_lint_lint-gradle.md.html) +Since +: 1.0.0-alpha02 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/lint/lint-gradle/src/main/java/androidx/lint/gradle/InternalApiUsageDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/lint/lint-gradle/src/test/java/androidx/lint/gradle/InternalApiUsageDetectorTest.kt) +Copyright Year +: 2024 + +Using internal APIs results in fragile plugin behavior as these types +have no binary +compatibility guarantees. It is best to create a feature request to open +up these +APIs if you find them useful. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test.kt:2:Error: Avoid using internal Gradle APIs +[InternalGradleApiUsage] +import org.gradle.api.internal.component.SoftwareComponentInternal +------------------------------------------------------------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +import org.gradle.api.component.SoftwareComponent +import org.gradle.api.internal.component.SoftwareComponentInternal + +fun getSoftwareComponent() : SoftwareComponent { + return object : SoftwareComponentInternal { + override fun getUsages(): Set { + TODO() + } + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/lint/lint-gradle/src/test/java/androidx/lint/gradle/InternalApiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `InternalApiUsageDetector.Test usage of internal Gradle API`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=1147525. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.lint:lint-gradle:1.0.0-alpha04") + +// build.gradle +implementation 'androidx.lint:lint-gradle:1.0.0-alpha04' + +// build.gradle.kts with version catalogs: +implementation(libs.lint.gradle) + +# libs.versions.toml +[versions] +lint-gradle = "1.0.0-alpha04" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-gradle = { + module = "androidx.lint:lint-gradle", + version.ref = "lint-gradle" +} +``` + +1.0.0-alpha04 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.lint:lint-gradle](androidx_lint_lint-gradle.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("InternalGradleApiUsage") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("InternalGradleApiUsage") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection InternalGradleApiUsage + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="InternalGradleApiUsage" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'InternalGradleApiUsage' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore InternalGradleApiUsage ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/InternalInsetResource.md.html b/docs/checks/InternalInsetResource.md.html index 3296b556..f877a998 100644 --- a/docs/checks/InternalInsetResource.md.html +++ b/docs/checks/InternalInsetResource.md.html @@ -18,14 +18,16 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.3.0 (September 2022) Affects : Kotlin and Java files Editing : This check runs on the fly in the IDE editor Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/InternalInsetResourceDetector.kt) -Copyright Year -: 2022 +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/InternalInsetResourceDetectorTest.kt) The internal inset dimension resources are not a supported way to retrieve the relevant insets for your application. The insets are @@ -34,6 +36,32 @@ for your app and listen to updates, use `androidx.core.view.WindowInsetsCompat` and related APIs. +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test/pkg/test.kt:6:Warning: Using internal inset dimension resource +status_bar_height is not supported [InternalInsetResource] + getIdentifier("status_bar_height", "dimen", "android") + ------------------------------------------------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test/pkg/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg + +import android.content.res.Resources + +fun Resources.getStatusBarHeightIdentifier(): Int = + getIdentifier("status_bar_height", "dimen", "android") +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/InternalInsetResourceDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/InvalidAccessibility.md.html b/docs/checks/InvalidAccessibility.md.html new file mode 100644 index 00000000..5713a093 --- /dev/null +++ b/docs/checks/InvalidAccessibility.md.html @@ -0,0 +1,152 @@ + +(#) Marks invalid accessibility usages + +!!! WARNING: Marks invalid accessibility usages + This is a warning. + +Id +: `InvalidAccessibility` +Summary +: Marks invalid accessibility usages +Severity +: Warning +Category +: Correctness +Platform +: Android +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html) +Since +: 0.24.0 +Affects +: Resource files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/main/kotlin/com/vanniktech/lintrules/android/InvalidAccessibilityDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/InvalidAccessibilityDetectorTest.kt) + +Marks usages of invalid accessibility and suggests corrections. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +res/layout/ids.xml:5:Warning: Either set a proper accessibility text or +use importantForAccessibility [InvalidAccessibility] + android:contentDescription="@null"/> + ----- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`res/layout/ids.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<ImageView + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:contentDescription="@null"/> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/InvalidAccessibilityDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `InvalidAccessibilityDetector.contentDescriptionNull`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-android:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-android:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.android) + +# libs.versions.toml +[versions] +lint-rules-android = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-android = { + module = "com.vanniktech:lint-rules-android", + version.ref = "lint-rules-android" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute + `tools:ignore="InvalidAccessibility"` on the problematic XML element + (or one of its enclosing elements). You may also need to add the + following namespace declaration on the root element in the XML file + if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="InvalidAccessibility" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'InvalidAccessibility' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore InvalidAccessibility ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/InvalidAnalyticsName.md.html b/docs/checks/InvalidAnalyticsName.md.html index ac3ce8bc..e074271b 100644 --- a/docs/checks/InvalidAnalyticsName.md.html +++ b/docs/checks/InvalidAnalyticsName.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 2.3.0 (March 2017) Affects : Kotlin and Java files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/FirebaseAnalyticsDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/FirebaseAnalyticsDetectorTest.java) -Copyright Year -: 2016 Event names and parameters must follow the naming conventions defined in the`FirebaseAnalytics#logEvent()` documentation. @@ -41,11 +41,8 @@ src/test/pkg/MainActivity.java:6:Error: Analytics event name must only consist of letters, numbers and underscores (found a;) [InvalidAnalyticsName] - FirebaseAnalytics.getInstance(this).logEvent("a;", new Bundle()); ---------------------------------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/InvalidColorHexValue.md.html b/docs/checks/InvalidColorHexValue.md.html index 23bf7ee8..966632d9 100644 --- a/docs/checks/InvalidColorHexValue.md.html +++ b/docs/checks/InvalidColorHexValue.md.html @@ -20,6 +20,14 @@ : androidx.compose.ui.graphics Feedback : https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.ui:ui-graphics-android](androidx_compose_ui_ui-graphics-android.md.html) +Since +: 1.5.0 Affects : Kotlin and Java files and test sources Editing @@ -35,31 +43,25 @@ 0xFF000000), with 8 bits being used per channel (ARGB). Not passing a full 32 bit value will result in channels being undefined / incorrect. +!!! Tip + This lint check has an associated quickfix available in the IDE. + (##) Example Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/test.kt:6:Warning: Invalid Color hex value [InvalidColorHexValue] - val color = Color(0x00000) ------- - - src/test/test.kt:7:Warning: Invalid Color hex value [InvalidColorHexValue] - val color2 = Color(0xEEEEE) ------- - - src/test/test.kt:8:Warning: Invalid Color hex value [InvalidColorHexValue] - val color3 = Color(0x00_0_0_0L) ----------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -84,6 +86,44 @@ To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=612128. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.ui:ui-graphics-android:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.ui:ui-graphics-android:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.ui.graphics.android) + +# libs.versions.toml +[versions] +ui-graphics-android = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +ui-graphics-android = { + module = "androidx.compose.ui:ui-graphics-android", + version.ref = "ui-graphics-android" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.ui:ui-graphics-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.ui:ui-graphics-android](androidx_compose_ui_ui-graphics-android.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/InvalidFragmentVersionForActivityResult.md.html b/docs/checks/InvalidFragmentVersionForActivityResult.md.html index bc2db804..ee40536f 100644 --- a/docs/checks/InvalidFragmentVersionForActivityResult.md.html +++ b/docs/checks/InvalidFragmentVersionForActivityResult.md.html @@ -22,6 +22,14 @@ : androidx.activity Feedback : https://issuetracker.google.com/issues/new?component=527362 +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.7+ +Artifact +: [androidx.activity:activity](androidx_activity_activity.md.html) +Since +: 1.2.0 Affects : Gradle build files and Kotlin and Java files Editing @@ -35,8 +43,8 @@ Copyright Year : 2020 -In order to use the ActivityResult APIs you must upgrade your - Fragment version to 1.3.0. Previous versions of FragmentActivity +In order to use the ActivityResult APIs you must upgrade your + Fragment version to 1.3.0. Previous versions of FragmentActivity failed to call super.onRequestPermissionsResult() and used invalid request codes. @@ -46,15 +54,19 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/main/kotlin/com/example/test.kt:6:Error: Upgrade Fragment version to at least . [InvalidFragmentVersionForActivityResult] - val launcher = ActivityResultCaller().registerForActivityResult(ActivityResultContract()) -------------------------------------------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Here are the relevant source files: +`build.gradle`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~groovy linenumbers +dependencies { + api("androidx.fragment:fragment:1.2.4") +} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: - `src/main/kotlin/com/example/test.kt`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers package com.example @@ -74,10 +86,51 @@ To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=527362. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.activity:activity:1.11.0-rc01") + +// build.gradle +implementation 'androidx.activity:activity:1.11.0-rc01' + +// build.gradle.kts with version catalogs: +implementation(libs.activity) + +# libs.versions.toml +[versions] +activity = "1.11.0-rc01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +activity = { + module = "androidx.activity:activity", + version.ref = "activity" +} +``` + +1.11.0-rc01 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.activity:activity](androidx_activity_activity.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: +* Using a suppression comment like this on the line above: + + ```kt + //noinspection InvalidFragmentVersionForActivityResult + problematicStatement() + ``` + * Using a suppression annotation like this on the enclosing element: @@ -99,13 +152,6 @@ } ``` -* Using a suppression comment like this on the line above: - - ```kt - //noinspection InvalidFragmentVersionForActivityResult - problematicStatement() - ``` - * Using a special `lint.xml` file in the source tree which turns off the check in that folder and any sub folder. A simple file might look like this: diff --git a/docs/checks/InvalidId.md.html b/docs/checks/InvalidId.md.html index ec0fdae7..c580250e 100644 --- a/docs/checks/InvalidId.md.html +++ b/docs/checks/InvalidId.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -45,32 +47,20 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/invalid_ids.xml:23:Error: ID definitions must be of the form @+id/name; try using @+id/menu_Reload [InvalidId] - android:id="@+menu/Reload" -------------------------- - - res/layout/invalid_ids.xml:31:Error: ID definitions must be of the form @+id/name; try using @+id/_id_foo [InvalidId] - android:id="@+/id_foo" ---------------------- - - res/layout/invalid_ids.xml:37:Error: ID definitions must be of the form @+id/name; try using @+id/myid_button5 [InvalidId] - android:id="@+myid/button5" --------------------------- - - res/layout/invalid_ids.xml:43:Error: ID definitions must be of the form @+id/name; try using @+id/string_whatevs [InvalidId] - android:id="@+string/whatevs" ----------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/InvalidImeActionId.md.html b/docs/checks/InvalidImeActionId.md.html index 8cc7c891..b02a34c3 100644 --- a/docs/checks/InvalidImeActionId.md.html +++ b/docs/checks/InvalidImeActionId.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.0.0 (October 2017) Affects : Resource files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/InvalidImeActionIdDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/InvalidImeActionIdDetectorTest.kt) -Copyright Year -: 2017 `android:imeActionId` should not be a resource ID such as `@+id/resName`. It must be an integer constant, or an integer resource @@ -41,11 +41,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/namespace.xml:2:Error: Invalid resource type, expected integer value [InvalidImeActionId] - <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:imeActionId="@+id/login"/> -------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/InvalidImport.md.html b/docs/checks/InvalidImport.md.html new file mode 100644 index 00000000..6dba29fb --- /dev/null +++ b/docs/checks/InvalidImport.md.html @@ -0,0 +1,172 @@ + +(#) Flags invalid imports + +!!! WARNING: Flags invalid imports + This is a warning. + +Id +: `InvalidImport` +Summary +: Flags invalid imports +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html) +Since +: 0.6.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/main/kotlin/com/vanniktech/lintrules/android/InvalidImportDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/InvalidImportDetectorTest.kt) + +Flags invalid imports. One example is com.foo.bar.R.drawable. Instead +just the generated class R should be imported and not R.drawable. Also +you should never import anything that's in an internal package. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/Example.java:3:Warning: Forbidden import [InvalidImport] +import foo.R.drawable; + -------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/Example.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package foo; + +import foo.R.drawable; + +class Example { +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/InvalidImportDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `InvalidImportDetector.rDrawableImport`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-android:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-android:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.android) + +# libs.versions.toml +[versions] +lint-rules-android = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-android = { + module = "com.vanniktech:lint-rules-android", + version.ref = "lint-rules-android" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("InvalidImport") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("InvalidImport") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection InvalidImport + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="InvalidImport" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'InvalidImport' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore InvalidImport ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/InvalidLanguageTagDelimiter.md.html b/docs/checks/InvalidLanguageTagDelimiter.md.html new file mode 100644 index 00000000..dd1461f8 --- /dev/null +++ b/docs/checks/InvalidLanguageTagDelimiter.md.html @@ -0,0 +1,182 @@ + +(#) Underscore (`_`) is an unsupported delimiter for subtags + +!!! ERROR: Underscore (`_`) is an unsupported delimiter for subtags + This is an error. + +Id +: `InvalidLanguageTagDelimiter` +Summary +: Underscore (`_`) is an unsupported delimiter for subtags +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: Jetpack Compose +Identifier +: androidx.compose.ui.text +Feedback +: https://issuetracker.google.com/issues/new?component=779818 +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.ui:ui-text-android](androidx_compose_ui_ui-text-android.md.html) +Since +: 1.7.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/ui/ui-text-lint/src/main/java/androidx/compose/ui/text/lint/LocaleInvalidLanguageTagDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/ui/ui-text-lint/src/test/java/androidx/compose/ui/text/lint/LocaleInvalidLanguageTagDetectorTest.kt) +Copyright Year +: 2024 + +A language tag must be compliant with IETF BCP47, specifically a +sequence of subtags must be separated by hyphens (-) instead of +underscores (_) + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test/test.kt:8:Error: A hyphen (-), not an underscore (_) delimiter +should be used in a language tag [InvalidLanguageTagDelimiter] + bar(Locale("en_UK")) + ------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test + +import androidx.compose.ui.text.intl.Locale + +fun bar(locale: Locale) {} +fun foo() { + bar(Locale("en_UK")) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/ui/ui-text-lint/src/test/java/androidx/compose/ui/text/lint/LocaleInvalidLanguageTagDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `LocaleInvalidLanguageTagDetector.underscoreDelimiter_locale_shouldWarn`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=779818. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.ui:ui-text-android:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.ui:ui-text-android:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.ui.text.android) + +# libs.versions.toml +[versions] +ui-text-android = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +ui-text-android = { + module = "androidx.compose.ui:ui-text-android", + version.ref = "ui-text-android" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.ui:ui-text-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.ui:ui-text-android](androidx_compose_ui_ui-text-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("InvalidLanguageTagDelimiter") + fun method() { + LocaleList(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("InvalidLanguageTagDelimiter") + void method() { + new LocaleList(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection InvalidLanguageTagDelimiter + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="InvalidLanguageTagDelimiter" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'InvalidLanguageTagDelimiter' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore InvalidLanguageTagDelimiter ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/InvalidNavigation.md.html b/docs/checks/InvalidNavigation.md.html index d5795ece..d8c8b0eb 100644 --- a/docs/checks/InvalidNavigation.md.html +++ b/docs/checks/InvalidNavigation.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.2.0 (September 2018) Affects : Resource files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/StartDestinationDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/StartDestinationDetectorTest.kt) -Copyright Year -: 2018 All `` elements must have a start destination specified, and it must be a direct child of that ``. @@ -38,14 +38,11 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/navigation/navigation.xml:5:Warning: Invalid start destination @id/includedId [InvalidNavigation] - app:startDestination="@id/includedId"> -------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `res/navigation/navigation.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -58,6 +55,18 @@ </navigation> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/navigation/foo.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> + <navigation + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:android="http://schemas.android.com/apk/res/android" + android:id='@+id/includedId2' + app:startDestination="@id/foo2"> + <fragment android:id="@+id/foo2"/> + </navigation> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/StartDestinationDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/InvalidPackage.md.html b/docs/checks/InvalidPackage.md.html index 73f12844..2f053a02 100644 --- a/docs/checks/InvalidPackage.md.html +++ b/docs/checks/InvalidPackage.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Library bytecode Editing @@ -53,20 +55,89 @@ libs/unsupported.jar:Error: Invalid package reference in library; not included in Android: javax.swing. Referenced from test.pkg.LibraryClass. [InvalidPackage] - 2 errors, 0 warnings +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant test files: + +`res/layout/layout.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="fill_parent" + android:layout_height="match_parent" + android:orientation="vertical" > + + <!-- Requires API 5 --> + + <QuickContactBadge + android:layout_width="wrap_content" + android:layout_height="wrap_content" /> + + <!-- Requires API 11 --> + + <CalendarView + android:layout_width="fill_parent" + android:layout_height="fill_parent" /> + + <!-- Requires API 14 --> + <GridLayout + foo="@android:attr/actionBarSplitStyle" + bar="@android:color/holo_red_light" + android:layout_width="fill_parent" + android:layout_height="fill_parent" > + <Button + android:layout_width="fill_parent" + android:layout_height="fill_parent" /> + </GridLayout> +</LinearLayout> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +`res/values/themes.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<resources> + <style name="Theme" parent="android:Theme"/> -`libs/unsupported.jar`: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ linenumbers -H4sIAAAAAAAAAAvwZmYRYeAAwmMzkxwZkAAnAwuDr2uIo66nn5v+v1MMDMwMAd7sHCApJqiSAJyaRYAYrtnX0c/TzTU4RM/X7bPvmdM+3rp6F3m9dbXOnTm/OcjgivGDp0V6Xr46nr4XS1excM54KXlEerZ2hoWYyJMlWhXPVF9nfir6WMQItt1tYdofG6DZNlDbucC27UWznRWIS1KLS/RxK+GEKSnITtdH+GM6mjJpZGU+mUlFiUWVzjmJxcV6ySAyNyjaX9hR5N+y7bnXs/QDHC5yPVq69ITD0exefpMZGWEmKzOfFG67O+Xg3chNc7n+Kv/jr93Q6fuH8Z/G45u5jpk32i2Nn8/5qZf+7fv8+fsZrgSaCyRrZC5f//Pjc7ntS2Q7Em6UuO7PVzg4wV4onqW89dXH798mXr7Is3J6kOffLsW4ldskhXz3v57RoTzZVUizbY7q1M32H3LUf2jkXE/UiKpz35EreOKDja/al4VvjHWipk8ylzC6d2FuCs8TyWdOqsv31Ct5nr59t/HaPqOJzmrNllN4zsQL3Jb6tvVx6sYGV6FX/B7lJ7tOXXouz7SyxJu974OU2rrkmwd6NQ/6WHbP3nE0QaZdM1zQ4+isuR6Lb5kV/H6zz+LiHs2mdaptR7IW9fQ0WvN8Drwq/GvC+1P3pJfOnSe8pHD6wTvr7G9V/nnycvPzaLWwQnuZx82SakHO26Qf7gkuS/l75vwZl4y8Yyufv1vZeHyD2dsFLNuXvipaOGV967R9j+ar+V6ZX6S88jnzrhcNUo+2vTHUiZhuuWDTzU/sjscrdQ+H6/753zH7Ie8mFwGO/RJvX4gvvLpAePkJDbXr7h713afU1q7UmHlMNGrzZLaucE2jGOv9f6YqTBYxP3ZCtqfjm3XXVvmIpPcZmx1nG56aEn9TPvnrgh1mh/aKd9bLPOU43BNR1BKn8EfVKX5hMO/Pjur0Jvuny6Y7sYYm6SdIvr4iuvidzlX5SZOknpqfDGh6FHZk019xUFL9+WuOhgQwpyQzg5IqI5MIA2pWYYKnRBYGVICS69C1IucAERRttjjyHMgELgbcOQUBdiPyDW4tnCha7qHmI4RbQTkJOQikUbSxMuLNVwHerGwQ57EyGACVpjGDeADV4J9drAQAAA== + <style name="Theme.Test" parent="android:style/Theme.Light"> + <item name="android:windowNoTitle">true</item> + <item name="android:windowContentOverlay">@null</item> + <!-- Requires API 14 --> + <item name="android:windowBackground"> @android:color/holo_red_light </item> + </style> + + <style name="Theme.Test.Transparent"> + <item name="android:windowBackground">@android:color/transparent</item> + </style> + +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/color/colors.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<resources> + <style name="Theme" parent="android:Theme"/> + + <style name="Theme.Test" parent="android:style/Theme.Light"> + <item name="android:windowNoTitle">true</item> + <item name="android:windowContentOverlay">@null</item> + <!-- Requires API 14 --> + <item name="android:windowBackground"> @android:color/holo_red_light </item> + </style> + + <style name="Theme.Test.Transparent"> + <item name="android:windowBackground">@android:color/transparent</item> + </style> + +</resources> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +[libs/unsupported.jar](examples/libs/unsupported.jar) + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/InvalidPackageDetectorTest.java) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/InvalidPeriodicWorkRequestInterval.md.html b/docs/checks/InvalidPeriodicWorkRequestInterval.md.html index 56b347b0..986cda09 100644 --- a/docs/checks/InvalidPeriodicWorkRequestInterval.md.html +++ b/docs/checks/InvalidPeriodicWorkRequestInterval.md.html @@ -22,6 +22,14 @@ : androidx.work Feedback : https://issuetracker.google.com/issues/new?component=409906 +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.7+ +Artifact +: [androidx.work:work-runtime](androidx_work_work-runtime.md.html) +Since +: 2.3.4 Affects : Kotlin and Java files Editing @@ -36,6 +44,86 @@ The interval duration for a `PeriodicWorkRequest` must be at least 15 minutes. +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +com/example/Test.kt:9:Error: Interval duration for +`PeriodicWorkRequest`s must be at least 15 minutes. +[InvalidPeriodicWorkRequestInterval] + val builder = PeriodicWorkRequest.Builder(TestWorker::class.java, 15L, TimeUnit.MILLISECONDS) + ------------------------------------------------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`com/example/TestWorker.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package com.example + +import androidx.work.ListenableWorker + +class TestWorker: ListenableWorker() +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`com/example/Test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package com.example + +import androidx.work.PeriodicWorkRequest +import com.example.TestWorker +import java.util.concurrent.TimeUnit + +class Test { + fun enqueue() { + val builder = PeriodicWorkRequest.Builder(TestWorker::class.java, 15L, TimeUnit.MILLISECONDS) + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/work/work-lint/src/test/java/androidx/work/lint/InvalidPeriodicWorkRequestIntervalDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `InvalidPeriodicWorkRequestIntervalDetector.testWithInvalidDurationTimeUnits`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=409906. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.work:work-runtime:2.10.1") + +// build.gradle +implementation 'androidx.work:work-runtime:2.10.1' + +// build.gradle.kts with version catalogs: +implementation(libs.work.runtime) + +# libs.versions.toml +[versions] +work-runtime = "2.10.1" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +work-runtime = { + module = "androidx.work:work-runtime", + version.ref = "work-runtime" +} +``` + +2.10.1 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.work:work-runtime](androidx_work_work-runtime.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/InvalidPermission.md.html b/docs/checks/InvalidPermission.md.html index fb606ca9..1e43e41c 100644 --- a/docs/checks/InvalidPermission.md.html +++ b/docs/checks/InvalidPermission.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 2.3.0 (March 2017) Affects : Manifest files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ManifestPermissionAttributeDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ManifestPermissionAttributeDetectorTest.kt) -Copyright Year -: 2016 Not all elements support the permission attribute. If a permission is set on an invalid element, it is a no-op and ignored. Ensure that this @@ -40,18 +40,12 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text AndroidManifest.xml:19:Error: Protecting an unsupported element with a permission is a no-op and potentially dangerous [InvalidPermission] - android:permission="android.permission.READ_CONTACTS"/> ----------------------------------------------------- - - AndroidManifest.xml:22:Error: Protecting an unsupported element with a permission is a no-op and potentially dangerous [InvalidPermission] - android:permission="android.permission.SET_WALLPAPER"/> ----------------------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/InvalidResourceFolder.md.html b/docs/checks/InvalidResourceFolder.md.html index 758de225..b793fdea 100644 --- a/docs/checks/InvalidResourceFolder.md.html +++ b/docs/checks/InvalidResourceFolder.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 1.1.0 (February 2015) Affects : Resource folders Editing @@ -30,8 +32,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/LocaleFolderDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/LocaleFolderDetectorTest.kt) -Copyright Year -: 2014 This lint check looks for a folder name that is not a valid resource folder name; these will be ignored and not packaged by the Android @@ -52,16 +52,32 @@ res/values-ldtrl-mnc123/strings.xml:Error: Invalid resource folder: make sure qualifiers appear in the correct order, are spelled correctly, etc. [InvalidResourceFolder] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Here are the relevant source files: +`res/values/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<resources> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/values-ldtrl-mnc123/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<resources> +</resources> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +`res/values-kok-rIN/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<resources> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -`res/values-ldtrl-mnc123/strings.xml`: +`res/values-no-rNOR/strings.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers -<resources></resources> +<resources> +</resources> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can also visit the diff --git a/docs/checks/InvalidSetHasFixedSize.md.html b/docs/checks/InvalidSetHasFixedSize.md.html index 406fdb24..61d7b0eb 100644 --- a/docs/checks/InvalidSetHasFixedSize.md.html +++ b/docs/checks/InvalidSetHasFixedSize.md.html @@ -1,18 +1,15 @@ -(#) When using `setHasFixedSize() in an `RecyclerView`, `wrap_content` cannot be used as \ -a value for `size` in the scrolling direction. +(#) When using `setHasFixedSize()` in an `RecyclerView`, `wrap_content` cannot be used as a value for `size` in the scrolling direction. - !!! ERROR: When using `setHasFixedSize() in an `RecyclerView`, `wrap_content` cannot be used as \ -a value for `size` in the scrolling direction. - This is an error, and is also enforced at build time when - supported by the build system. For Android this means it will - run during release builds. +!!! ERROR: When using `setHasFixedSize()` in an `RecyclerView`, `wrap_content` cannot be used as a value for `size` in the scrolling direction. + This is an error, and is also enforced at build time when + supported by the build system. For Android this means it will + run during release builds. Id : `InvalidSetHasFixedSize` Summary -: When using `setHasFixedSize() in an `RecyclerView`, `wrap_content` cannot be used as \ -a value for `size` in the scrolling direction. +: When using `setHasFixedSize()` in an `RecyclerView`, `wrap_content` cannot be used as a value for `size` in the scrolling direction. Severity : Fatal Category @@ -25,18 +22,121 @@ : androidx.recyclerview Feedback : https://issuetracker.google.com/issues/new?component=460887 +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [androidx.recyclerview:recyclerview](androidx_recyclerview_recyclerview.md.html) +Since +: 1.2.0 Affects : Kotlin and Java files and resource files Editing : This check can *not* run live in the IDE editor Implementation : [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/recyclerview/recyclerview-lint/src/main/java/androidx/recyclerview/lint/InvalidSetHasFixedSizeDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/recyclerview/recyclerview-lint/src/test/java/androidx/recyclerview/lint/InvalidSetHasFixedSizeTest.kt) Copyright Year : 2020 When a RecyclerView uses `setHasFixedSize(...)` you cannot use `wrap_content` for size in the scrolling direction. +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +com/example/Example.kt:10:Error: When using `setHasFixedSize() in an +RecyclerView, wrap_content cannot be used as a value for size in the +scrolling direction. [InvalidSetHasFixedSize] + recyclerView?.setHasFixedSize(true) + ----------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`layout/recycler_view.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> + <androidx.recyclerview.widget.RecyclerView + xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/my_recycler_view" + android:layout_width="match_parent" + android:layout_height="wrap_content"/> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`com/example/R.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package com.example + +object R { + object id { + const val my_recycler_view = 0 + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`com/example/Example.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package com.example + +import android.view.View +import androidx.recyclerview.widget.RecyclerView + +class Example { + fun main() { + val view: View = TODO() + val recyclerView = view.findViewById(R.id.my_recycler_view) + recyclerView?.setHasFixedSize(true) + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/recyclerview/recyclerview-lint/src/test/java/androidx/recyclerview/lint/InvalidSetHasFixedSizeTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `InvalidSetHasFixedSizeDetector.testInCorrectUsageOfFixedSize`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=460887. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.recyclerview:recyclerview:1.4.0") + +// build.gradle +implementation 'androidx.recyclerview:recyclerview:1.4.0' + +// build.gradle.kts with version catalogs: +implementation(libs.recyclerview) + +# libs.versions.toml +[versions] +recyclerview = "1.4.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +recyclerview = { + module = "androidx.recyclerview:recyclerview", + version.ref = "recyclerview" +} +``` + +1.4.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.recyclerview:recyclerview](androidx_recyclerview_recyclerview.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/InvalidSingleLineComment.md.html b/docs/checks/InvalidSingleLineComment.md.html new file mode 100644 index 00000000..b0959813 --- /dev/null +++ b/docs/checks/InvalidSingleLineComment.md.html @@ -0,0 +1,176 @@ + +(#) Marks single line comments that are not sentences + +!!! WARNING: Marks single line comments that are not sentences + This is a warning. + +Id +: `InvalidSingleLineComment` +Summary +: Marks single line comments that are not sentences +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html) +Since +: 0.6.0 +Affects +: Gradle build files and Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/main/kotlin/com/vanniktech/lintrules/android/InvalidSingleLineCommentDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/InvalidSingleLineCommentDetectorTest.kt) + +Single line comments should always be sentences. They're part of the +code and hence they deserve as much detail and respect as code. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/Example.java:5:Warning: Comment does not contain a space at the +beginning [InvalidSingleLineComment] + //Something. + --- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/Example.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package foo; + +class Example { + public void foo() { + //Something. + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/InvalidSingleLineCommentDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `InvalidSingleLineCommentDetector.invalidSingleLineCommentNoSpace`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-android:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-android:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.android) + +# libs.versions.toml +[versions] +lint-rules-android = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-android = { + module = "com.vanniktech:lint-rules-android", + version.ref = "lint-rules-android" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("InvalidSingleLineComment") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("InvalidSingleLineComment") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection InvalidSingleLineComment + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="InvalidSingleLineComment" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'InvalidSingleLineComment' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore InvalidSingleLineComment ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/InvalidString.md.html b/docs/checks/InvalidString.md.html new file mode 100644 index 00000000..2cb78097 --- /dev/null +++ b/docs/checks/InvalidString.md.html @@ -0,0 +1,160 @@ + +(#) Marks invalid translation strings + +!!! WARNING: Marks invalid translation strings + This is a warning. + +Id +: `InvalidString` +Summary +: Marks invalid translation strings +Severity +: Warning +Category +: Correctness +Platform +: Android +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html) +Since +: 0.6.0 +Affects +: Resource files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/main/kotlin/com/vanniktech/lintrules/android/InvalidStringDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/InvalidStringDetectorTest.kt) + +A translation string is invalid if it contains new lines instead of the +escaped \n or if it contains trailing whitespace. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +res/values/strings.xml:2:Warning: Text contains new line. +[InvalidString] + <string name="my_string">My string" + ^ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`res/values/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<resources> + <string name="my_string">My string" +</string> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/InvalidStringDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `InvalidStringDetector.stringContainingNewLine`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-android:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-android:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.android) + +# libs.versions.toml +[versions] +lint-rules-android = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-android = { + module = "com.vanniktech:lint-rules-android", + version.ref = "lint-rules-android" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute `tools:ignore="InvalidString"` on + the problematic XML element (or one of its enclosing elements). You + may also need to add the following namespace declaration on the root + element in the XML file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <resources xmlns:tools="http://schemas.android.com/tools"> + ... + <string tools:ignore="InvalidString" .../> + ... + </resources> + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="InvalidString" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'InvalidString' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore InvalidString ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/InvalidUseOfOnBackPressed.md.html b/docs/checks/InvalidUseOfOnBackPressed.md.html new file mode 100644 index 00000000..01998e86 --- /dev/null +++ b/docs/checks/InvalidUseOfOnBackPressed.md.html @@ -0,0 +1,194 @@ + +(#) Do not call onBackPressed() within OnBackPressedDisptacher + +!!! WARNING: Do not call onBackPressed() within OnBackPressedDisptacher + This is a warning. + +Id +: `InvalidUseOfOnBackPressed` +Summary +: Do not call onBackPressed() within OnBackPressedDisptacher +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: Android Open Source Project +Identifier +: androidx.activity +Feedback +: https://issuetracker.google.com/issues/new?component=527362 +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.7+ +Artifact +: [androidx.activity:activity](androidx_activity_activity.md.html) +Since +: 1.9.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +See +: https://developer.android.com/guide/navigation/custom-back/predictive-back-gesture#ui-logic +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/activity/activity-lint/src/main/java/androidx/activity/lint/OnBackPressedDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/activity/activity-lint/src/test/java/androidx/activity/lint/OnBackPressedDispatcherTest.kt) +Copyright Year +: 2024 + +You should not used OnBackPressedCallback for non-UI cases. If you + |add a callback, you have to handle back completely in +the callback. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/com/example/test.kt:12:Warning: Should not call onBackPressed inside +of OnBackPressedCallback.handledOnBackPressed +[InvalidUseOfOnBackPressed] + activity.onBackPressed() + ------------------------ +src/com/example/test.kt:14:Warning: Should not call onBackPressed inside +of OnBackPressedCallback.handledOnBackPressed +[InvalidUseOfOnBackPressed] + dispatcher.onBackPressed() + -------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/com/example/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package com.example + +import androidx.activity.ComponentActivity +import androidx.activity.OnBackPressedCallback +import androidx.activity.OnBackPressedDispatcher + +fun test() { + object: OnBackPressedCallback { + override fun handledOnBackPressed() { + val activity = ComponentActivity() + activity.onBackPressed() + val dispatcher = OnBackPressedDispatcher() + dispatcher.onBackPressed() + } + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/activity/activity-lint/src/test/java/androidx/activity/lint/OnBackPressedDispatcherTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `OnBackPressedDetector.expectFailOnBackPressed`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=527362. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.activity:activity:1.11.0-rc01") + +// build.gradle +implementation 'androidx.activity:activity:1.11.0-rc01' + +// build.gradle.kts with version catalogs: +implementation(libs.activity) + +# libs.versions.toml +[versions] +activity = "1.11.0-rc01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +activity = { + module = "androidx.activity:activity", + version.ref = "activity" +} +``` + +1.11.0-rc01 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.activity:activity](androidx_activity_activity.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("InvalidUseOfOnBackPressed") + fun method() { + onBackPressed(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("InvalidUseOfOnBackPressed") + void method() { + onBackPressed(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection InvalidUseOfOnBackPressed + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="InvalidUseOfOnBackPressed" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'InvalidUseOfOnBackPressed' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore InvalidUseOfOnBackPressed ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/InvalidUsesTagAttribute.md.html b/docs/checks/InvalidUsesTagAttribute.md.html index 66919767..980b4c90 100644 --- a/docs/checks/InvalidUsesTagAttribute.md.html +++ b/docs/checks/InvalidUsesTagAttribute.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 1.5.0 (November 2015) Affects : Kotlin and Java files, manifest files and resource files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AndroidAutoDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AndroidAutoDetectorTest.java) -Copyright Year -: 2015 The element in `` should contain a valid value for the `name` attribute. Valid values are `media`, `notification`, or @@ -45,15 +45,46 @@ res/xml/automotive_app_desc.xml:3:Error: Expecting one of media, notification, sms, or template for the name attribute in uses tag [InvalidUsesTagAttribute] - <uses name="medias"/> ------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Here are the relevant source files: +`AndroidManifest.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + package="com.example.android.uamp"> + + <application + android:name=".UAMPApplication" + android:label="@string/app_name" + android:theme="@style/UAmpAppTheme"> + + <meta-data + android:name="com.google.android.gms.car.application" + android:resource="@xml/automotive_app_desc"/> + + <service + android:name=".MusicService" + android:exported="true" + tools:ignore="ExportedService"> + <intent-filter> + <action android:name="android.media.browse.MediaBrowserService"/> + </intent-filter> + <intent-filter> + <action android:name="android.media.action.MEDIA_PLAY_FROM_SEARCH"/> + <category android:name="android.intent.category.DEFAULT"/> + </intent-filter> + </service> + + </application> + +</manifest> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: - `res/xml/automotive_app_desc.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers <?xml version="1.0" encoding="utf-8"?> diff --git a/docs/checks/InvalidVectorPath.md.html b/docs/checks/InvalidVectorPath.md.html index e09ac1ea..b53e5dd9 100644 --- a/docs/checks/InvalidVectorPath.md.html +++ b/docs/checks/InvalidVectorPath.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.0.0 (October 2017) Affects : Resource files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/VectorPathDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/VectorPathDetectorTest.java) -Copyright Year -: 2017 This check ensures that vector paths are valid. For example, it makes sure that the numbers are not using scientific notation (such as 1.0e3) @@ -47,11 +47,8 @@ res/drawable/my_vector.xml:7:Error: Avoid scientific notation (1.05e-4) in vector paths because it can lead to crashes on some devices. Use 0.000105 instead. [InvalidVectorPath] - android:pathData="m 1.05e-4,2.75448" /> ------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/InvalidWakeLockTag.md.html b/docs/checks/InvalidWakeLockTag.md.html index 22fdc34d..05e1af87 100644 --- a/docs/checks/InvalidWakeLockTag.md.html +++ b/docs/checks/InvalidWakeLockTag.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.2.0 (September 2018) Affects : Kotlin and Java files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/PowerManagerDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/PowerManagerDetectorTest.java) -Copyright Year -: 2018 Wake Lock tags must follow the naming conventions defined in the`PowerManager` documentation. @@ -40,11 +40,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/WakelockActivity.java:12:Error: Tag name should not be empty to make wake lock problems easier to debug [InvalidWakeLockTag] - mWakeLock = manager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, ""); ------------------------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/InvalidWearFeatureAttribute.md.html b/docs/checks/InvalidWearFeatureAttribute.md.html index 4b45d0b5..95f52432 100644 --- a/docs/checks/InvalidWearFeatureAttribute.md.html +++ b/docs/checks/InvalidWearFeatureAttribute.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.0.0 (October 2017) Affects : Manifest files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/WearStandaloneAppDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/WearStandaloneAppDetectorTest.java) -Copyright Year -: 2016 For the `android.hardware.type.watch` uses-feature, android:required="false" is disallowed. A single APK for Wear and @@ -41,11 +41,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text AndroidManifest.xml:4:Error: android:required="false" is not supported for this feature [InvalidWearFeatureAttribute] - <uses-feature android:name="android.hardware.type.watch" android:required="false"/> ------------------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -57,8 +54,8 @@ <uses-sdk android:targetSdkVersion="23" /> <uses-feature android:name="android.hardware.type.watch" android:required="false"/> <application> - <meta-data - android:name="com.google.android.wearable.standalone" + <meta-data + android:name="com.google.android.wearable.standalone" android:value="true" /> </application> </manifest> diff --git a/docs/checks/JCenter.md.html b/docs/checks/JCenter.md.html new file mode 100644 index 00000000..baca7f0c --- /dev/null +++ b/docs/checks/JCenter.md.html @@ -0,0 +1,153 @@ + +(#) Marks usage of the jcenter() repository + +!!! WARNING: Marks usage of the jcenter() repository + This is a warning. + +Id +: `JCenter` +Summary +: Marks usage of the jcenter() repository +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html) +Since +: 0.8.0 +Affects +: Gradle build files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/main/kotlin/com/vanniktech/lintrules/android/JcenterDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/JcenterDetectorTest.kt) + +JCenter has gotten less and less reliable and it's best to avoid if +possible. This check will flag usages of jcenter() in your gradle +files. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +build.gradle:3:Warning: Don't use jcenter() [JCenter] + jcenter() + --------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`build.gradle`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~groovy linenumbers +buildscript { + repositories { + jcenter() + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/JcenterDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `JcenterDetector.jcenter`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-android:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-android:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.android) + +# libs.versions.toml +[versions] +lint-rules-android = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-android = { + module = "com.vanniktech:lint-rules-android", + version.ref = "lint-rules-android" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection JCenter + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="JCenter" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'JCenter' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore JCenter ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/JavaOnlyDetector.md.html b/docs/checks/JavaOnlyDetector.md.html new file mode 100644 index 00000000..48f8a0ea --- /dev/null +++ b/docs/checks/JavaOnlyDetector.md.html @@ -0,0 +1,193 @@ + +(#) Using @JavaOnly elements in Kotlin code + +!!! ERROR: Using @JavaOnly elements in Kotlin code + This is an error. + +Id +: `JavaOnlyDetector` +Summary +: Using @JavaOnly elements in Kotlin code +Severity +: Error +Category +: Interoperability: Kotlin Interoperability +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/JavaOnlyDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/JavaOnlyDetectorTest.kt) +Copyright Year +: 2020 + +This should not be called from Kotlin code. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +test/test/pkg/Test.kt:7:Error: This method should not be called from +Kotlin, see its documentation for details. [JavaOnlyDetector] + g() + --- +test/test/pkg/Test.kt:8:Error: This method should not be called from +Kotlin: satisfying explanation [JavaOnlyDetector] + f() + --- +test/test/pkg/Test.kt:9:Error: This method should not be called from +Kotlin, see its documentation for details. [JavaOnlyDetector] + val r = this::g + ------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`test/test/pkg/Test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg +import slack.lint.annotations.JavaOnly +class Test { + @JavaOnly fun g() {} + @JavaOnly("satisfying explanation") fun f() {} + fun m() { + g() + f() + val r = this::g + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/JavaOnlyDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `JavaOnlyDetector.positive`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("JavaOnlyDetector") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("JavaOnlyDetector") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection JavaOnlyDetector + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="JavaOnlyDetector" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'JavaOnlyDetector' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore JavaOnlyDetector ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/JavaPluginLanguageLevel.md.html b/docs/checks/JavaPluginLanguageLevel.md.html index 3cc6a926..012018cd 100644 --- a/docs/checks/JavaPluginLanguageLevel.md.html +++ b/docs/checks/JavaPluginLanguageLevel.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 4.2.0 (May 2021) Affects : Gradle build files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GradleDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) -Copyright Year -: 2014 In modules using plugins deriving from the Gradle `java` plugin (e.g. `java-library` or `application`), the java source and target @@ -48,11 +48,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text build.gradle:2:Warning: no Java sourceCompatibility directive [JavaPluginLanguageLevel] - id 'java' --------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/JavascriptInterface.md.html b/docs/checks/JavascriptInterface.md.html index aa982a08..3d91dde9 100644 --- a/docs/checks/JavascriptInterface.md.html +++ b/docs/checks/JavascriptInterface.md.html @@ -18,12 +18,16 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files Editing : This check runs on the fly in the IDE editor See : https://developer.android.com/reference/android/webkit/WebView.html#addJavascriptInterface(java.lang.Object, java.lang.String) +See +: https://goo.gle/JavascriptInterface Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/JavaScriptInterfaceDetector.kt) Tests @@ -43,41 +47,83 @@ added interface (NonAnnotatedObject) have been annotated with @android.webkit.JavascriptInterface; they will not be visible in API 17 [JavascriptInterface] - webview.addJavascriptInterface(new NonAnnotatedObject(), "myobj"); ---------------------- - - src/test/pkg/JavaScriptTest.java:14:Error: None of the methods in the added interface (NonAnnotatedObject) have been annotated with @android.webkit.JavascriptInterface; they will not be visible in API 17 [JavascriptInterface] - webview.addJavascriptInterface(o, "myobj"); ---------------------- - - src/test/pkg/JavaScriptTest.java:21:Error: None of the methods in the added interface (NonAnnotatedObject) have been annotated with @android.webkit.JavascriptInterface; they will not be visible in API 17 [JavascriptInterface] - webview.addJavascriptInterface(object2, "myobj"); ---------------------- - - src/test/pkg/JavaScriptTest.java:32:Error: None of the methods in the added interface (NonAnnotatedObject) have been annotated with @android.webkit.JavascriptInterface; they will not be visible in API 17 [JavascriptInterface] - webview.addJavascriptInterface(t, "myobj"); ---------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`src/test/pkg/AnnotatedObject.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; +import android.webkit.JavascriptInterface; +@SuppressWarnings("ClassNameDiffersFromFileName") +public class AnnotatedObject { + @JavascriptInterface + public void test1() { + } + + public void test2() { + } + + @JavascriptInterface + public void test3() { + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/InheritsFromAnnotated.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; + +import android.webkit.JavascriptInterface; + +@SuppressWarnings("ClassNameDiffersFromFileName") +public class InheritsFromAnnotated extends AnnotatedObject { + + @Override + public void test1() { + } + + @Override + public void test2() { + } + +} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +`src/test/pkg/NonAnnotatedObject.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; + +@SuppressWarnings("ClassNameDiffersFromFileName") +public class NonAnnotatedObject { + public void test1() { + } + public void test2() { + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `src/test/pkg/JavaScriptTest.java`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers diff --git a/docs/checks/JcenterRepositoryObsolete.md.html b/docs/checks/JcenterRepositoryObsolete.md.html index 7ea7f0e3..935e431f 100644 --- a/docs/checks/JcenterRepositoryObsolete.md.html +++ b/docs/checks/JcenterRepositoryObsolete.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 4.2.0 (May 2021) Affects : Gradle build files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GradleDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) -Copyright Year -: 2014 The JCenter Maven repository is no longer accepting submissions of Maven artifacts since 31st March 2021. Ensure that the project is configured @@ -45,19 +45,13 @@ build.gradle:7:Warning: JCenter Maven repository is no longer receiving updates: newer library versions may be available elsewhere [JcenterRepositoryObsolete] - jcenter() --------- - - build.gradle:14:Warning: JCenter Maven repository is no longer receiving updates: newer library versions may be available elsewhere [JcenterRepositoryObsolete] - jcenter() --------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/JobSchedulerService.md.html b/docs/checks/JobSchedulerService.md.html index d5d0796e..35425e71 100644 --- a/docs/checks/JobSchedulerService.md.html +++ b/docs/checks/JobSchedulerService.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.0.0 (October 2017) Affects : Kotlin and Java files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/JobSchedulerDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/JobSchedulerDetectorTest.java) -Copyright Year -: 2017 This check looks for various common mistakes in using the JobScheduler API: the service class must extend `JobService`, the service must be @@ -43,22 +43,16 @@ src/test/pkg/JobSchedulerTest.java:21:Warning: Scheduled job class NotAJobService must extend android.app.job.JobService [JobSchedulerService] - new ComponentName(this, NotAJobService.class)); --------------------------------------------- - - src/test/pkg/JobSchedulerTest.java:29:Warning: Scheduled job class NotAJobService must extend android.app.job.JobService [JobSchedulerService] - new ComponentName(this, NotAJobService.class)); --------------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `src/test/pkg/JobSchedulerTest.java`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers @@ -89,7 +83,7 @@ } public void testWrongInlined(JobScheduler jobScheduler) { - JobInfo.Builder builder = new JobInfo.Builder(MY_ID, + JobInfo.Builder builder = new JobInfo.Builder(MY_ID, new ComponentName(this, NotAJobService.class)); jobScheduler.schedule(builder .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY) @@ -98,6 +92,55 @@ } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/test/pkg/MyJobService.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; + +import android.annotation.TargetApi; +import android.app.job.JobParameters; +import android.app.job.JobService; +import android.os.Build; + +@TargetApi(Build.VERSION_CODES.LOLLIPOP) +public class MyJobService extends JobService { + @Override + public boolean onStartJob(JobParameters jobParameters) { + return false; + } + + @Override + public boolean onStopJob(JobParameters jobParameters) { + return false; + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/NotAJobService.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; + +import android.app.Service; + +public abstract class NotAJobService extends Service { +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/AndroidManifest.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="test.pkg"> + + <application> + <service android:name=".MyJobService" + android:permission="android.permission.BIND_JOB_SERVICE" + android:exported="true" /> + <service android:name=".NotAJobService" + android:exported="true" /> + </application> + +</manifest> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/JobSchedulerDetectorTest.java) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/JvmStaticProvidesInObjectDetector.md.html b/docs/checks/JvmStaticProvidesInObjectDetector.md.html new file mode 100644 index 00000000..dbfcb5ec --- /dev/null +++ b/docs/checks/JvmStaticProvidesInObjectDetector.md.html @@ -0,0 +1,288 @@ + +(#) @JvmStatic used for @Provides function in an object class + +!!! WARNING: @JvmStatic used for @Provides function in an object class + This is a warning. + +Id +: `JvmStaticProvidesInObjectDetector` +Summary +: @JvmStatic used for @Provides function in an object class +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: Google +Identifier +: com.google.dagger:dagger-lint +Contact +: https://github.com/google/dagger +Feedback +: https://github.com/google/dagger/issues +Min +: Lint 7.3 and 7.4 +Compiled +: Lint 7.1 +Artifact +: [com.google.dagger:dagger-lint](com_google_dagger_dagger-lint.md.html) +Since +: 2.40.2 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/google/dagger/tree/master/java/dagger/lint/DaggerKotlinIssueDetector.kt) +Tests +: [Source Code](https://github.com/google/dagger/tree/master/javatests/dagger/lint/DaggerKotlinIssueDetectorTest.kt) +Copyright Year +: 2020 + +It's redundant to annotate @Provides functions in object classes with +@JvmStatic. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/MyQualifier.kt:26:Warning: @JvmStatic used for @Provides +function in an object class [JvmStaticProvidesInObjectDetector] + @JvmStatic + ---------- +src/foo/MyQualifier.kt:43:Warning: @JvmStatic used for @Provides +function in an object class [JvmStaticProvidesInObjectDetector] + @JvmStatic + ---------- +src/foo/MyQualifier.kt:56:Warning: @JvmStatic used for @Provides +function in an object class [JvmStaticProvidesInObjectDetector] + @kotlin.jvm.JvmStatic + --------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/MyQualifier.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package foo +import javax.inject.Inject +import javax.inject.Qualifier +import kotlin.jvm.JvmStatic +import dagger.Provides +import dagger.Module + +@Qualifier +annotation class MyQualifier + +class InjectedTest { + // This should fail because of `:field` + @Inject + @field:MyQualifier + lateinit var prop: String + + // This is fine! + @Inject + @MyQualifier + lateinit var prop2: String +} + +@Module +object ObjectModule { + // This should fail because it uses `@JvmStatic` + @JvmStatic + @Provides + fun provideFoo(): String { + + } + + // This is fine! + @Provides + fun provideBar(): String { + + } +} + +@Module +class ClassModule { + companion object { + // This should fail because the companion object is part of ClassModule, so this is unnecessary. + @JvmStatic + @Provides + fun provideBaz(): String { + + } + } +} + +@Module +class ClassModuleQualified { + companion object { + // This should fail because the companion object is part of ClassModule, so this is unnecessary. + // This specifically tests a fully qualified annotation + @kotlin.jvm.JvmStatic + @Provides + fun provideBaz(): String { + + } + } +} + +@Module +class ClassModule2 { + // This should fail because the companion object is part of ClassModule + @Module + companion object { + @Provides + fun provideBaz(): String { + + } + } +} + +@Module +class ClassModule2Qualified { + // This should fail because the companion object is part of ClassModule + // This specifically tests a fully qualified annotation + @dagger.Module + companion object { + @Provides + fun provideBaz(): String { + + } + } +} + +// This is correct as of Dagger 2.26! +@Module +class ClassModule3 { + companion object { + @Provides + fun provideBaz(): String { + + } + } +} + +class ClassModule4 { + // This is should fail because this should be extracted to a standalone object. + @Module + companion object { + @Provides + fun provideBaz(): String { + + } + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/google/dagger/tree/master/javatests/dagger/lint/DaggerKotlinIssueDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `DaggerKotlinIssueDetector.simpleSmokeTestForQualifiersAndProviders`. +To report a problem with this extracted sample, visit +https://github.com/google/dagger/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("com.google.dagger:dagger-lint:2.56.2") + +// build.gradle +implementation 'com.google.dagger:dagger-lint:2.56.2' + +// build.gradle.kts with version catalogs: +implementation(libs.dagger.lint) + +# libs.versions.toml +[versions] +dagger-lint = "2.56.2" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +dagger-lint = { + module = "com.google.dagger:dagger-lint", + version.ref = "dagger-lint" +} +``` + +2.56.2 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.google.dagger:dagger-lint](com_google_dagger_dagger-lint.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("JvmStaticProvidesInObjectDetector") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("JvmStaticProvidesInObjectDetector") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection JvmStaticProvidesInObjectDetector + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="JvmStaticProvidesInObjectDetector" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'JvmStaticProvidesInObjectDetector' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore JvmStaticProvidesInObjectDetector ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/KaptUsageInsteadOfKsp.md.html b/docs/checks/KaptUsageInsteadOfKsp.md.html new file mode 100644 index 00000000..c02c93b7 --- /dev/null +++ b/docs/checks/KaptUsageInsteadOfKsp.md.html @@ -0,0 +1,144 @@ + +(#) Kapt usage should be replaced with KSP + +!!! WARNING: Kapt usage should be replaced with KSP + This is a warning. + +Id +: `KaptUsageInsteadOfKsp` +Summary +: Kapt usage should be replaced with KSP +Severity +: Warning +Category +: Performance +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.1.0 (July 2023) +Affects +: Gradle build files +Editing +: This check runs on the fly in the IDE editor +See +: https://developer.android.com/studio/build/migrate-to-ksp +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GradleDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) + +KSP is a more efficient replacement for kapt. For libraries that support +both, KSP should be used to improve build times. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +build.gradle:9:Warning: This library supports using KSP instead of kapt, +which greatly improves performance. Learn more: +https://developer.android.com/studio/build/migrate-to-ksp +[KaptUsageInsteadOfKsp] + kapt 'androidx.room:room-compiler:2.5.0' + ---------------------------------------- +build.gradle:10:Warning: This library supports using KSP instead of +kapt, which greatly improves performance. Learn more: +https://developer.android.com/studio/build/migrate-to-ksp +[KaptUsageInsteadOfKsp] + kapt "androidx.room:room-compiler:$room_version" + ------------------------------------------------ +build.gradle:13:Warning: This library supports using KSP instead of +kapt, which greatly improves performance. Learn more: +https://developer.android.com/studio/build/migrate-to-ksp +[KaptUsageInsteadOfKsp] + kapt 'com.github.bumptech.glide:compiler:4.14.2' + ------------------------------------------------ +build.gradle:14:Warning: This library supports using KSP instead of +kapt, which greatly improves performance. Learn more: +https://developer.android.com/studio/build/migrate-to-ksp +[KaptUsageInsteadOfKsp] + kapt("com.github.bumptech.glide:compiler:glide_version") + -------------------------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`build.gradle`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~groovy linenumbers +plugins { + id 'com.android.application' + id 'kotlin-android' + id 'kotlin-kapt' + id 'com.google.devtools.ksp' +} +dependencies { + def room_version = "2.5.0" + kapt 'androidx.room:room-compiler:2.5.0' + kapt "androidx.room:room-compiler:$room_version" + + def glide_version = "4.14.2" + kapt 'com.github.bumptech.glide:compiler:4.14.2' + kapt("com.github.bumptech.glide:compiler:glide_version") +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `GradleDetector.testKaptToKspMigration`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=192708. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection KaptUsageInsteadOfKsp + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="KaptUsageInsteadOfKsp" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'KaptUsageInsteadOfKsp' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore KaptUsageInsteadOfKsp ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/KeyboardInaccessibleWidget.md.html b/docs/checks/KeyboardInaccessibleWidget.md.html index 68a6c985..44c261a8 100644 --- a/docs/checks/KeyboardInaccessibleWidget.md.html +++ b/docs/checks/KeyboardInaccessibleWidget.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.0.0 (October 2017) Affects : Resource files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/KeyboardNavigationDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/KeyboardNavigationDetectorTest.java) -Copyright Year -: 2017 A widget that is declared to be clickable but not declared to be focusable is not accessible via the keyboard. Please add the `focusable` @@ -42,11 +42,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/mywidget.xml:2:Warning: 'clickable' attribute found, please also add 'focusable' [KeyboardInaccessibleWidget] - android:clickable="true" /> ------------------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/KnownPermissionError.md.html b/docs/checks/KnownPermissionError.md.html index a2104822..2229de66 100644 --- a/docs/checks/KnownPermissionError.md.html +++ b/docs/checks/KnownPermissionError.md.html @@ -18,16 +18,18 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.4.0 (January 2023) Affects : Manifest files Editing : This check runs on the fly in the IDE editor +See +: https://goo.gle/KnownPermissionError Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/PermissionErrorDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/PermissionErrorDetectorTest.kt) -Copyright Year -: 2022 This check looks for values specified in component permissions that are known errors, such as `android:permission="true"`. @@ -36,52 +38,37 @@ is expected to be a permission string from the system, another app, or your own, NOT a boolean. +!!! Tip + This lint check has an associated quickfix available in the IDE. + (##) Example Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text AndroidManifest.xml:4:Error: true is not a valid permission value [KnownPermissionError] - <application android:permission="true"> ---- - - AndroidManifest.xml:5:Error: TRUE is not a valid permission value [KnownPermissionError] - <activity android:permission="TRUE" /> ---- - - AndroidManifest.xml:6:Error: True is not a valid permission value [KnownPermissionError] - <activity-alias android:permission="True" /> ---- - - AndroidManifest.xml:7:Error: true is not a valid permission value [KnownPermissionError] - <receiver android:permission="true" /> ---- - - AndroidManifest.xml:8:Error: false is not a valid permission value [KnownPermissionError] - <service android:permission="false" /> ----- - - AndroidManifest.xml:9:Error: false is not a valid permission value [KnownPermissionError] - <provider android:permission="false" /> ----- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/KotlinNullnessAnnotation.md.html b/docs/checks/KotlinNullnessAnnotation.md.html index 74260e7d..28f3ec24 100644 --- a/docs/checks/KotlinNullnessAnnotation.md.html +++ b/docs/checks/KotlinNullnessAnnotation.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.3.0 (September 2022) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/KotlinNullnessAnnotationDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/KotlinNullnessAnnotationDetectorTest.kt) -Copyright Year -: 2022 In Kotlin, nullness is part of the type system; `s: String` is **never** null and `s: String?` is sometimes null, whether or not you add in @@ -44,29 +44,20 @@ src/test/pkg/test.kt:7:Warning: Do not use @NonNull in Kotlin; the nullability is already implied by the Kotlin type String not ending with ? [KotlinNullnessAnnotation] - fun testWarning(@NonNull string: String) { } -------- - - src/test/pkg/test.kt:11:Error: Do not use @Nullable in Kotlin; the nullability is determined by the Kotlin type String not ending with ? which declares it not nullable, contradicting the annotation [KotlinNullnessAnnotation] - fun testError(@Nullable string: String) { } --------- - - src/test/pkg/test.kt:15:Error: Do not use @NonNull in Kotlin; the nullability is determined by the Kotlin type Number? ending with ? which declares it nullable, contradicting the annotation [KotlinNullnessAnnotation] - fun testError(@NonNull number: Number?) { } -------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/KotlinPairNotCreated.md.html b/docs/checks/KotlinPairNotCreated.md.html new file mode 100644 index 00000000..df07a83b --- /dev/null +++ b/docs/checks/KotlinPairNotCreated.md.html @@ -0,0 +1,188 @@ + +(#) Use Kotlin's kotlin.Pair instead of other Pair types from other libraries like AndroidX and Slack commons + +!!! WARNING: Use Kotlin's kotlin.Pair instead of other Pair types from other libraries like AndroidX and Slack commons + This is a warning. + +Id +: `KotlinPairNotCreated` +Summary +: Use Kotlin's kotlin.Pair instead of other Pair types from other libraries like AndroidX and Slack commons +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/NonKotlinPairDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/NonKotlinPairDetectorTest.kt) +Copyright Year +: 2021 + +We should consolidate to create and use a single type of Pair in the +code base. Kotlin's Pair is preferred as it works well with Java and +Kotlin. It comes with extension functions that Slack's Pair doesn't +offer. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/test/TestClass.java:10:Warning: Use Kotlin's kotlin.Pair +instead of other Pair types from other libraries like AndroidX and Slack +commons [KotlinPairNotCreated] + Pair pair = Pair.create("first", "second"); + ------------------------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/test/TestClass.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package slack.test; + +import androidx.core.util.Pair; + +public class TestClass { + + public void doStuff() { + new Integer(5); + new String("TestString").toString(); + Pair pair = Pair.create("first", "second"); + pair.first.toString(); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/NonKotlinPairDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `NonKotlinPairDetector.Java - AndroidX Pair create shows warning`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("KotlinPairNotCreated") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("KotlinPairNotCreated") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection KotlinPairNotCreated + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="KotlinPairNotCreated" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'KotlinPairNotCreated' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore KotlinPairNotCreated ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/KotlinPropertyAccess.md.html b/docs/checks/KotlinPropertyAccess.md.html index 4c162022..1ca4f3be 100644 --- a/docs/checks/KotlinPropertyAccess.md.html +++ b/docs/checks/KotlinPropertyAccess.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.2.0 (September 2018) Affects : Kotlin and Java files Editing @@ -30,8 +32,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/InteroperabilityDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/InteroperabilityDetectorTest.kt) -Copyright Year -: 2018 For a method to be represented as a property in Kotlin, strict “bean”-style prefixing must be used. @@ -48,71 +48,50 @@ see https://android.github.io/kotlin-guides/interop.html#property-prefixes [KotlinPropertyAccess] - public String hasError1() { return ""; } --------- - - src/test/pkg/GetterSetter.java:34:Warning: This method should be called getError2 such that error2 can be accessed as a property from Kotlin; see https://android.github.io/kotlin-guides/interop.html#property-prefixes [KotlinPropertyAccess] - public String error2() { return ""; } ------ - - src/test/pkg/GetterSetter.java:38:Warning: This method should be called getError3 such that error3 can be accessed as a property from Kotlin; see https://android.github.io/kotlin-guides/interop.html#property-prefixes [KotlinPropertyAccess] - public String hazzError3() { return ""; } ---------- - - src/test/pkg/GetterSetter.java:42:Warning: The getter return type (Integer) and setter parameter type (String) getter and setter methods for property error4 should have exactly the same type to allow be accessed as a property from Kotlin; see https://android.github.io/kotlin-guides/interop.html#property-prefixes [KotlinPropertyAccess] - public Integer getError4() { return 0; } --------- - - src/test/pkg/GetterSetter.java:46:Warning: This getter should be public such that error5 can be accessed as a property from Kotlin; see https://android.github.io/kotlin-guides/interop.html#property-prefixes [KotlinPropertyAccess] - protected String getError5() { return ""; } --------- - - src/test/pkg/GetterSetter.java:50:Warning: This getter should not be static such that error6 can be accessed as a property from Kotlin; see https://android.github.io/kotlin-guides/interop.html#property-prefixes [KotlinPropertyAccess] - public static String getError6() { return ""; } ------ - - src/test/pkg/GetterSetter.java:70:Warning: The getter return type (Float) is not the same as the super return type (Number); they should have exactly the same type to allow number3 be accessed as a property from Kotlin; see https://android.github.io/kotlin-guides/interop.html#property-prefixes [KotlinPropertyAccess] - @Override public Float getNumber3() { return 0.0f; } // ERROR (even though we have corresponding setter) ---------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/KotlinRequireNotNullUseMessage.md.html b/docs/checks/KotlinRequireNotNullUseMessage.md.html new file mode 100644 index 00000000..76853c8f --- /dev/null +++ b/docs/checks/KotlinRequireNotNullUseMessage.md.html @@ -0,0 +1,169 @@ + +(#) Marks usage of the requireNotNull method without lazy messages + +!!! WARNING: Marks usage of the requireNotNull method without lazy messages + This is a warning. + +Id +: `KotlinRequireNotNullUseMessage` +Summary +: Marks usage of the requireNotNull method without lazy messages +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-kotlin](com_vanniktech_lint-rules-kotlin.md.html) +Since +: 0.22.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-kotlin-lint/src/main/kotlin/com/vanniktech/lintrules/kotlin/KotlinRequireNotNullUseMessageDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-kotlin-lint/src/test/kotlin/com/vanniktech/lintrules/rxjava2/KotlinRequireNotNullUseMessageDetectorTest.kt) + +The default generated message from requireNotNull often lacks context, +hence it's best to provide a custom message. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test.kt:2:Warning: Provide a message +[KotlinRequireNotNullUseMessage] + requireNotNull(value) + -------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +fun test(value: Int?) { + requireNotNull(value) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-kotlin-lint/src/test/kotlin/com/vanniktech/lintrules/rxjava2/KotlinRequireNotNullUseMessageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `KotlinRequireNotNullUseMessageDetector.requireNotNull`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-kotlin:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-kotlin:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.kotlin) + +# libs.versions.toml +[versions] +lint-rules-kotlin = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-kotlin = { + module = "com.vanniktech:lint-rules-kotlin", + version.ref = "lint-rules-kotlin" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-kotlin](com_vanniktech_lint-rules-kotlin.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("KotlinRequireNotNullUseMessage") + fun method() { + requireNotNull(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("KotlinRequireNotNullUseMessage") + void method() { + requireNotNull(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection KotlinRequireNotNullUseMessage + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="KotlinRequireNotNullUseMessage" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'KotlinRequireNotNullUseMessage' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore KotlinRequireNotNullUseMessage ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/KotlincFE10.md.html b/docs/checks/KotlincFE10.md.html new file mode 100644 index 00000000..da349885 --- /dev/null +++ b/docs/checks/KotlincFE10.md.html @@ -0,0 +1,217 @@ + +(#) Avoid using old K1 Kotlin compiler APIs + +!!! WARNING: Avoid using old K1 Kotlin compiler APIs + This is a warning. + +Id +: `KotlincFE10` +Summary +: Avoid using old K1 Kotlin compiler APIs +Note +: **This issue is disabled by default**; use `--enable KotlincFE10` +Severity +: Warning +Category +: Lint Implementation Issues +Platform +: JDK +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.1.0 (July 2023) +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/KotlincFE10Detector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/KotlincFE10DetectorTest.kt) + +K2, the new version of Kotlin compiler, which encompasses the new +frontend, is coming. Try to avoid using internal APIs from the old +frontend if possible. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test/pkg/TestVisitor.kt:28:Warning: +org.jetbrains.kotlin.resolve.BindingContext appears to be part of the +old K1 Kotlin compiler. Avoid using it if possible; K1 will be going +away soon. [KotlincFE10] + val bindingContext = service.getBindingContext(declaration) // ERROR + -------------------------------------- +src/test/pkg/TestVisitor.kt:29:Warning: +org.jetbrains.kotlin.resolve.BindingContext appears to be part of the +old K1 Kotlin compiler. Avoid using it if possible; K1 will be going +away soon. [KotlincFE10] + val type = bindingContext.getType(expression) ?: return // ERROR + -------------- +src/test/pkg/TestVisitor.kt:30:Warning: +org.jetbrains.kotlin.types.KotlinType appears to be part of the old K1 +Kotlin compiler. Avoid using it if possible; K1 will be going away soon. +[KotlincFE10] + if (type.isDynamic()) return // ERROR + ---- +src/test/pkg/TestVisitor.kt:37:Warning: +org.jetbrains.kotlin.resolve.BindingContext appears to be part of the +old K1 Kotlin compiler. Avoid using it if possible; K1 will be going +away soon. [KotlincFE10] + bindingContext: BindingContext, // ERROR + -------------- +src/test/pkg/TestVisitor.kt:41:Warning: +org.jetbrains.kotlin.resolve.BindingContext appears to be part of the +old K1 Kotlin compiler. Avoid using it if possible; K1 will be going +away soon. [KotlincFE10] + val descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, node.sourcePsi) // ERROR + -------------- +src/test/pkg/TestVisitor.kt:42:Warning: +org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithVisibility +appears to be part of the old K1 Kotlin compiler. Avoid using it if +possible; K1 will be going away soon. [KotlincFE10] + if (descriptor is DeclarationDescriptorWithVisibility) { // ERROR + ----------------------------------- +src/test/pkg/TestVisitor.kt:43:Warning: +org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithVisibility +appears to be part of the old K1 Kotlin compiler. Avoid using it if +possible; K1 will be going away soon. [KotlincFE10] + val effectiveVisibility = descriptor.visibility.effectiveVisibility(descriptor, false) // ERROR + ---------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test/pkg/TestVisitor.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg + +import com.android.tools.lint.client.api.UElementHandler +import com.android.tools.lint.detector.api.JavaContext +import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithVisibility +import org.jetbrains.kotlin.descriptors.EffectiveVisibility +import org.jetbrains.kotlin.descriptors.effectiveVisibility +import org.jetbrains.kotlin.psi.KtElement +import org.jetbrains.kotlin.psi.KtCallableDeclaration +import org.jetbrains.kotlin.psi.KtFunction +import org.jetbrains.kotlin.psi.KtProperty +import org.jetbrains.kotlin.resolve.BindingContext +import org.jetbrains.kotlin.types.isDynamic +import org.jetbrains.uast.UElement +import org.jetbrains.uast.UMethod +import org.jetbrains.uast.kotlin.KotlinUastResolveProviderService + +class TestVisitor(val context: JavaContext) : UElementHandler() { + // Example from [InteroperabilityDetector.KotlinVisitor#visitMethod] + override fun visitMethod(node: UMethod) { + val declaration = node.sourcePsi as? KtCallableDeclaration ?: return + val expression = when (declaration) { + is KtProperty -> declaration.initializer ?: declaration.delegateExpression ?: return + is KtFunction -> declaration.bodyExpression ?: declaration.bodyBlockExpression ?: return + else -> return + } + val service = declaration.project.getService(KotlinUastResolveProviderService::class.java) + val bindingContext = service.getBindingContext(declaration) // ERROR + val type = bindingContext.getType(expression) ?: return // ERROR + if (type.isDynamic()) return // ERROR + // report something at the end + } + + // Example from [PsiModifierItem#computeFlag] in Metalava + private fun computeFlag( + node: UElement, + bindingContext: BindingContext, // ERROR + ) : Int { + var visibilityFlag = PACKAGE_PRIVATE + if (node.sourcePsi is KtElement) { + val descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, node.sourcePsi) // ERROR + if (descriptor is DeclarationDescriptorWithVisibility) { // ERROR + val effectiveVisibility = descriptor.visibility.effectiveVisibility(descriptor, false) // ERROR + if (effectiveVisibility == EffectiveVisibility.Internal) { + visibilityFlag = INTERNAL + } + } + } + return visibilityFlag + } + + companion object { + private const val INTERNAL = 1 + private const val PACKAGE_PRIVATE = 2 + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/KotlincFE10DetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("KotlincFE10") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("KotlincFE10") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection KotlincFE10 + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="KotlincFE10" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'KotlincFE10' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore KotlincFE10 ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/KtxExtensionAvailable.md.html b/docs/checks/KtxExtensionAvailable.md.html index 0c2be2dd..38fd7336 100644 --- a/docs/checks/KtxExtensionAvailable.md.html +++ b/docs/checks/KtxExtensionAvailable.md.html @@ -2,14 +2,14 @@ (#) KTX Extension Available !!! Tip: KTX Extension Available - Advice from this check is just a tip. + Advice from this check is just a hint; it's a "weak" warning. Id : `KtxExtensionAvailable` Summary : KTX Extension Available Severity -: Information +: Hint Category : Productivity Platform @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 4.1.0 (October 2020) Affects : Gradle build files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GradleDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) -Copyright Year -: 2014 Android KTX extensions augment some libraries with support for modern Kotlin language features like extension functions, extension properties, @@ -46,13 +46,10 @@ Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -build.gradle:7:Information: Add suffix -ktx to enable the Kotlin -extensions for this library [KtxExtensionAvailable] - +build.gradle:7:Hint: Add suffix -ktx to enable the Kotlin extensions for +this library [KtxExtensionAvailable] implementation "androidx.core:core:1.2.0" -------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/LabelFor.md.html b/docs/checks/LabelFor.md.html index 8a92b056..8b4805d7 100644 --- a/docs/checks/LabelFor.md.html +++ b/docs/checks/LabelFor.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -48,25 +50,16 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/labelfororhint_empty_hint.xml:11:Warning: Empty android:hint attribute [LabelFor] - android:hint="" --------------- - - res/layout/labelfororhint_empty_hint.xml:21:Warning: Empty android:hint attribute [LabelFor] - android:hint="" --------------- - - res/layout/labelfororhint_empty_hint.xml:29:Warning: Empty android:hint attribute [LabelFor] - android:hint="" --------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/LambdaLast.md.html b/docs/checks/LambdaLast.md.html index 4554935c..debda033 100644 --- a/docs/checks/LambdaLast.md.html +++ b/docs/checks/LambdaLast.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.2.0 (September 2018) Affects : Kotlin and Java files Editing @@ -30,8 +32,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/InteroperabilityDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/InteroperabilityDetectorTest.kt) -Copyright Year -: 2018 To improve calling this code from Kotlin, parameter types eligible for SAM conversion should be last. @@ -45,24 +45,18 @@ improve Kotlin interoperability; see https://kotlinlang.org/docs/reference/java-interop.html#sam-conversions [LambdaLast] - public void error1(Runnable run, int x) { } ----- - - src/test/pkg/Test.java:12:Warning: Functional interface parameters (such as parameter 1, "sam", in test.pkg.Test.error2) should be last to improve Kotlin interoperability; see https://kotlinlang.org/docs/reference/java-interop.html#sam-conversions [LambdaLast] - public void error2(SamInterface sam, int x) { } ----- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `src/test/pkg/Test.java`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers @@ -87,6 +81,19 @@ } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/test/pkg/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg + +fun ok1(bar: (Int) -> Int) { } +fun ok2(foo: Int) { } +fun ok3(foo: Int, bar: (Int) -> Int) { } +fun ok4(foo: Int, bar: (Int) -> Int, baz: (Int) -> Int) { } +// Lamda not last, but we're not flagging issues in Kotlin files for the +// interoperability issue +fun error(bar: (Int) -> Int, foo: Int) { } +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/InteroperabilityDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/LaunchActivityFromNotification.md.html b/docs/checks/LaunchActivityFromNotification.md.html index 287c6f9f..e92b19f3 100644 --- a/docs/checks/LaunchActivityFromNotification.md.html +++ b/docs/checks/LaunchActivityFromNotification.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 4.3.0-alpha01 (December 2020) Affects : Kotlin and Java files Editing @@ -25,15 +27,13 @@ See : https://developer.android.com/guide/topics/ui/notifiers/notifications?hl=en#Actions See -: https://material.io/design/platform-guidance/android-notifications.html#behavior +: https://d.android.com/r/studio-ui/designer/material/notifications-behavior See : https://developer.android.com/guide/topics/ui/notifiers/notifications?hl=en Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/NotificationTrampolineDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/NotificationTrampolineDetectorTest.kt) -Copyright Year -: 2020 Notifications should only launch activities -- that's what users expect (and has been the guidance in both the Android SDK and Material Design @@ -50,14 +50,31 @@ src/test/pkg/NotificationTest.java:22:Warning: Notifications should only launch a Service from notification actions (addAction) [LaunchActivityFromNotification] - .setContentIntent(serviceIntent) ------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Here are the relevant source files: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/test/pkg/BroadcastTrampoline.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; -Here is the source file referenced above: +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; + +public class BroadcastTrampoline extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + // The start below will be blocked + Intent i = new Intent(); + i.setClassName("test.pkg", "test.pkg.SecondActivity"); + i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(i); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `src/test/pkg/NotificationTest.java`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers diff --git a/docs/checks/LaunchDuringComposition.md.html b/docs/checks/LaunchDuringComposition.md.html index 0844caaf..35a257a5 100644 --- a/docs/checks/LaunchDuringComposition.md.html +++ b/docs/checks/LaunchDuringComposition.md.html @@ -20,6 +20,14 @@ : androidx.activity.compose Feedback : https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.7+ +Artifact +: [androidx.activity:activity-compose](androidx_activity_activity-compose.md.html) +Since +: 1.4.0 Affects : Kotlin and Java files and test sources Editing @@ -42,53 +50,32 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/com/example/test.kt:10:Error: Calls to launch should happen inside of a SideEffect and not during composition [LaunchDuringComposition] - launcher.launch("test") ------ - - src/com/example/test.kt:15:Error: Calls to launch should happen inside of a SideEffect and not during composition [LaunchDuringComposition] - launcher.launch("test") ------ - - src/com/example/test.kt:20:Error: Calls to launch should happen inside of a SideEffect and not during composition [LaunchDuringComposition] - launcher.launch("test") ------ - - src/com/example/test.kt:30:Error: Calls to launch should happen inside of a SideEffect and not during composition [LaunchDuringComposition] - launcher.launch("test") ------ - - src/com/example/test.kt:34:Error: Calls to launch should happen inside of a SideEffect and not during composition [LaunchDuringComposition] - launcher.launch("test") ------ - - src/com/example/test.kt:41:Error: Calls to launch should happen inside of a SideEffect and not during composition [LaunchDuringComposition] - launcher.launch("test") ------ - - src/com/example/test.kt:46:Error: Calls to launch should happen inside of a SideEffect and not during composition [LaunchDuringComposition] - launcher.launch("test") ------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -153,6 +140,40 @@ To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=612128. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.activity:activity-compose:1.11.0-rc01") + +// build.gradle +implementation 'androidx.activity:activity-compose:1.11.0-rc01' + +// build.gradle.kts with version catalogs: +implementation(libs.activity.compose) + +# libs.versions.toml +[versions] +activity-compose = "1.11.0-rc01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +activity-compose = { + module = "androidx.activity:activity-compose", + version.ref = "activity-compose" +} +``` + +1.11.0-rc01 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.activity:activity-compose](androidx_activity_activity-compose.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/LayoutFileNameMatchesClass.md.html b/docs/checks/LayoutFileNameMatchesClass.md.html new file mode 100644 index 00000000..126aee32 --- /dev/null +++ b/docs/checks/LayoutFileNameMatchesClass.md.html @@ -0,0 +1,190 @@ + +(#) Checks that the layout file matches the class name + +!!! WARNING: Checks that the layout file matches the class name + This is a warning. + +Id +: `LayoutFileNameMatchesClass` +Summary +: Checks that the layout file matches the class name +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html) +Since +: 0.7.1 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/main/kotlin/com/vanniktech/lintrules/android/LayoutFileNameMatchesClassDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/LayoutFileNameMatchesClassDetectorTest.kt) + +Layout file names should always match the name of the class. FooActivity +should have a layout file named activity_foo hence. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/main/java/foo/FooActivity.java:5:Warning: Parameter should be named +R.layout.unit_test_activity_foo [LayoutFileNameMatchesClass] + setContentView(R.layout.activity_bar); + --------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`src/foo/Activity.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package foo; + +public abstract class Activity { + public void setContentView(int viewId) { } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/main/java/foo/FooActivity.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package foo; + +class FooActivity extends Activity { + void foo() { + setContentView(R.layout.activity_bar); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`null`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text linenumbers +unit_test_ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/LayoutFileNameMatchesClassDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `LayoutFileNameMatchesClassDetector.fooActivityUsesActivityBarWithResourcePrefix`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-android:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-android:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.android) + +# libs.versions.toml +[versions] +lint-rules-android = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-android = { + module = "com.vanniktech:lint-rules-android", + version.ref = "lint-rules-android" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("LayoutFileNameMatchesClass") + fun method() { + setContentView(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("LayoutFileNameMatchesClass") + void method() { + setContentView(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection LayoutFileNameMatchesClass + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="LayoutFileNameMatchesClass" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'LayoutFileNameMatchesClass' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore LayoutFileNameMatchesClass ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/LeanbackUsesWifi.md.html b/docs/checks/LeanbackUsesWifi.md.html index f93b8ffd..2aaa12c1 100644 --- a/docs/checks/LeanbackUsesWifi.md.html +++ b/docs/checks/LeanbackUsesWifi.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.0.0 (July 2021) Affects : Manifest files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/LeanbackWifiUsageDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/LeanbackWifiUsageDetectorTest.kt) -Copyright Year -: 2021 WiFi is not required for Android TV and many devices connect to the internet via alternative methods e.g. Ethernet. @@ -47,11 +47,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text AndroidManifest.xml:4:Warning: Requiring Wifi permissions limits app availability on TVs that support only Ethernet [LeanbackUsesWifi] - <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> ---------------------------------------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/LibraryCustomView.md.html b/docs/checks/LibraryCustomView.md.html index d691ef61..81b95611 100644 --- a/docs/checks/LibraryCustomView.md.html +++ b/docs/checks/LibraryCustomView.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Manifest files and resource files Editing @@ -45,11 +47,8 @@ res/layout/customview.xml:5:Error: When using a custom namespace attribute in a library project, use the namespace "http://schemas.android.com/apk/res-auto" instead [LibraryCustomView] - xmlns:foo="http://schemas.android.com/apk/res/foo" -------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/LifecycleAnnotationProcessorWithJava8.md.html b/docs/checks/LifecycleAnnotationProcessorWithJava8.md.html index 0d98f2c4..a5d87098 100644 --- a/docs/checks/LifecycleAnnotationProcessorWithJava8.md.html +++ b/docs/checks/LifecycleAnnotationProcessorWithJava8.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.5.0 (August 2019) Affects : Gradle build files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GradleDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) -Copyright Year -: 2014 For faster incremental build, switch to the Lifecycle Java 8 API with these steps: @@ -53,11 +53,8 @@ build.gradle:3:Warning: Use the Lifecycle Java 8 API provided by the lifecycle-common library instead of Lifecycle annotations for faster incremental build. [LifecycleAnnotationProcessorWithJava8] - annotationProcessor "android.arch.lifecycle:compiler:1.1.1" --------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/LifecycleCurrentStateInComposition.md.html b/docs/checks/LifecycleCurrentStateInComposition.md.html new file mode 100644 index 00000000..c603d657 --- /dev/null +++ b/docs/checks/LifecycleCurrentStateInComposition.md.html @@ -0,0 +1,249 @@ + +(#) Lifecycle.currentState should not be called within composition + +!!! ERROR: Lifecycle.currentState should not be called within composition + This is an error. + +Id +: `LifecycleCurrentStateInComposition` +Summary +: Lifecycle.currentState should not be called within composition +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: Android Open Source Project +Identifier +: androidx.lifecycle +Feedback +: https://issuetracker.google.com/issues/new?component=413132 +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.7+ +Artifact +: [androidx.lifecycle:lifecycle-runtime-compose-android](androidx_lifecycle_lifecycle-runtime-compose-android.md.html) +Since +: 2.9.0-alpha10 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/lifecycle/lifecycle-runtime-compose-lint/src/main/java/androidx/lifecycle/runtime/compose/lint/ComposableLifecycleCurrentStateDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/lifecycle/lifecycle-runtime-compose-lint/src/test/java/androidx/lifecycle/runtime/compose/lint/ComposableLifecycleCurrentStateDetectorTest.kt) +Copyright Year +: 2025 + +Calling Lifecycle.currentState within composition will not observe +changes to the Lifecycle, so changes might not be reflected within the +composition. Instead you should use lifecycle.currentStateAsState() to +observe changes to the Lifecycle, and recompose when it changes. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/androidx/lifecycle/foo/test.kt:12:Error: Lifecycle.currentState +should not be called within composition +[LifecycleCurrentStateInComposition] + lifecycle.currentState + ------------ +src/androidx/lifecycle/foo/test.kt:16:Error: Lifecycle.currentState +should not be called within composition +[LifecycleCurrentStateInComposition] + lifecycle.currentState + ------------ +src/androidx/lifecycle/foo/test.kt:20:Error: Lifecycle.currentState +should not be called within composition +[LifecycleCurrentStateInComposition] + lifecycle.currentState + ------------ +src/androidx/lifecycle/foo/test.kt:29:Error: Lifecycle.currentState +should not be called within composition +[LifecycleCurrentStateInComposition] + lifecycle.currentState + ------------ +src/androidx/lifecycle/foo/test.kt:32:Error: Lifecycle.currentState +should not be called within composition +[LifecycleCurrentStateInComposition] + lifecycle.currentState + ------------ +src/androidx/lifecycle/foo/test.kt:38:Error: Lifecycle.currentState +should not be called within composition +[LifecycleCurrentStateInComposition] + lifecycle.currentState + ------------ +src/androidx/lifecycle/foo/test.kt:42:Error: Lifecycle.currentState +should not be called within composition +[LifecycleCurrentStateInComposition] + lifecycle.currentState + ------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/androidx/lifecycle/foo/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package androidx.lifecycle.foo + +import androidx.compose.runtime.Composable +import androidx.lifecycle.Lifecycle + +val lifecycle: Lifecycle = object : Lifecycle() { + override val currentState get() = Lifecycle.State.CREATED +} + +@Composable +fun Test() { + lifecycle.currentState +} + +val lambda = @Composable { + lifecycle.currentState +} + +val lambda2: @Composable () -> Unit = { + lifecycle.currentState +} + +@Composable +fun LambdaParameter(content: @Composable () -> Unit) {} + +@Composable +fun Test2() { + LambdaParameter(content = { + lifecycle.currentState + }) + LambdaParameter { + lifecycle.currentState + } +} + +fun test3() { + val localLambda1 = @Composable { + lifecycle.currentState + } + + val localLambda2: @Composable () -> Unit = { + lifecycle.currentState + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/lifecycle/lifecycle-runtime-compose-lint/src/test/java/androidx/lifecycle/runtime/compose/lint/ComposableLifecycleCurrentStateDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `ComposableLifecycleCurrentStateDetector.errors`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=413132. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.lifecycle:lifecycle-runtime-compose-android:2.9.0-rc01") + +// build.gradle +implementation 'androidx.lifecycle:lifecycle-runtime-compose-android:2.9.0-rc01' + +// build.gradle.kts with version catalogs: +implementation(libs.lifecycle.runtime.compose.android) + +# libs.versions.toml +[versions] +lifecycle-runtime-compose-android = "2.9.0-rc01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lifecycle-runtime-compose-android = { + module = "androidx.lifecycle:lifecycle-runtime-compose-android", + version.ref = "lifecycle-runtime-compose-android" +} +``` + +2.9.0-rc01 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.lifecycle:lifecycle-runtime-compose-android](androidx_lifecycle_lifecycle-runtime-compose-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("LifecycleCurrentStateInComposition") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("LifecycleCurrentStateInComposition") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection LifecycleCurrentStateInComposition + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="LifecycleCurrentStateInComposition" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'LifecycleCurrentStateInComposition' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore LifecycleCurrentStateInComposition ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/LintDocExample.md.html b/docs/checks/LintDocExample.md.html index f1d7d9a1..cecc7dd8 100644 --- a/docs/checks/LintDocExample.md.html +++ b/docs/checks/LintDocExample.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.0.0 (July 2021) Affects : Kotlin and Java files and test sources Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/LintDetectorDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/LintDetectorDetectorTest.kt) -Copyright Year -: 2020 Lint's tool for generating documentation for each issue has special support for including a code example which shows how to trigger the @@ -51,14 +51,236 @@ find a documentation example test (testDocumentationExample) which shows a simple, typical scenario which triggers the test, and which will be extracted into lint's per-issue documentation pages [LintDocExample] - fun testBasic() { ^ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Here are the relevant source files: +`src/test/pkg/MyJavaLintDetector.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +/* Copyright (C) 2020 The Android Open Source Project */ +package test.pkg; +import com.intellij.psi.PsiClass; +import com.intellij.psi.PsiCallExpression; +import com.intellij.psi.PsiExpression; +import com.intellij.psi.PsiField; +import com.intellij.psi.PsiMethod; +import com.intellij.psi.util.PsiTreeUtil; +import com.android.tools.lint.detector.api.Detector; +import org.jetbrains.uast.UFile; +import org.jetbrains.uast.UMethod; +import org.jetbrains.uast.UField; +import com.android.tools.lint.detector.api.Category; +import com.android.tools.lint.detector.api.Detector; +import com.android.tools.lint.detector.api.Implementation; +import com.android.tools.lint.detector.api.Issue; +import com.android.tools.lint.detector.api.JavaContext; +import com.android.tools.lint.detector.api.Scope; +import com.android.tools.lint.detector.api.Severity; +import org.jetbrains.uast.UCallExpression; +import java.util.EnumSet; + +@SuppressWarnings({"MethodMayBeStatic", "ClassNameDiffersFromFileName", "StatementWithEmptyBody", "deprecation"}) +public class MyJavaLintDetector extends Detector { + public static final Issue ISSUE = + Issue.create( + "com.android.namespaced.lint.check.FooDetector", + "Wrong use of ", + "As described in " + + "https://code.google.com/p/android/issues/detail?id=65351 blah blah blah.", + Category.A11Y, + 3, + Severity.WARNING, + new Implementation(MyJavaLintDetector.class, EnumSet.of(Scope.RESOURCE_FILE, Scope.JAVA_FILE))) + .addMoreInfo("file://explanation.doc") + .addMoreInfo("http://my.personal.blogger.com/aboutme.htm") + .addMoreInfo("mailto:lint@example.com"); + public void testGetBody(PsiMethod method) { + method.getBody(); // ERROR - must use UAST + } + public void testGetBody(UMethod method) { + method.getBody(); // ERROR - must use UAST + } + public void testGetContainingClass(UMethod method, UField field) { + method.getContainingClass(); // ERROR - must use UAST + field.getContainingClass(); // ERROR - must use UAST + } + public void testGetContainingClass(PsiMethod method, PsiField field) { + method.getContainingClass(); // OK - legitimate uses after resolve + field.getContainingClass(); // OK - legitimate uses after resolve + } + public void testEquals(PsiCallExpression element1, PsiExpression element2) { + if (element1.equals(element2)) { } + if (element2.equals(element1)) { } + if (element1 == element2) { } + if (element1 != element2) { } + } + public void testGetInitializer(PsiField field) { + field.getInitializer(); // ERROR - must use UAST + } + public void testParents(PsiField field, UMethod method) { + PsiElement parent = field.getParent(); // OK + PsiElement parent = method.getParent(); // ERROR + PsiTreeUtil.getParentOfType(field, PsiClass.class); // OK + PsiTreeUtil.getParentOfType(method, PsiClass.class); // ERROR + } + + public void testReport(JavaContext context, UCallExpression node) { + context.report(ISSUE, node, context.getLocation(node), + "Wrong use of LinearLayout."); + context.report(ISSUE, node, context.getLocation(node), + "First problem. Second problem."); + context.report(ISSUE, node, context.getLocation(node), + "This is teh typo"); + String message = "Welcome to Andriod"; + context.report(ISSUE, node, context.getLocation(node), message); + context.report(ISSUE, node, context.getLocation(node), + "Should you use `x ?: y` instead of ```foo ? 1 : 0``` ?"); + } +} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +`src/test/pkg/MyKotlinLintDetector.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +/* Copyright (C) 2020 The Android Open Source Project */ +package test.pkg +import com.intellij.psi.PsiCallExpression +import com.intellij.psi.PsiExpression +import com.intellij.psi.PsiField +import com.intellij.psi.PsiMethod +import com.intellij.psi.util.PsiTreeUtil +import com.android.tools.lint.detector.api.Category +import com.android.tools.lint.detector.api.Detector +import com.android.tools.lint.detector.api.Implementation +import com.android.tools.lint.detector.api.Issue +import com.android.tools.lint.detector.api.JavaContext +import com.android.tools.lint.detector.api.Scope +import com.android.tools.lint.detector.api.Severity +import org.jetbrains.uast.UCallExpression + +class MyKotlinLintDetector : Detector() { + fun testGetBody(method: PsiMethod) { + val body = method.body // ERROR - must use UAST + } + @Suppress("ReplaceCallWithBinaryOperator","ControlFlowWithEmptyBody") + fun testEquals(element1: PsiCallExpression, element2: PsiExpression) { + if (element1.equals(element2)) { } + if (element2.equals(element1)) { } + if (element1 == element2) { } + if (element1 === element2) { } + if (element1 != element2) { } + if (element1 !== element2) { } + if (element1 == null) { } // OK + if (element1 === null) { } // OK + if (element1 != null) { } // OK + if (element1 !== null) { } // OK + } + @Suppress("UsePropertyAccessSyntax") + fun testGetInitializer(field: PsiField) { + field.getInitializer() // ERROR - must use UAST + field.initializer // ERROR - must use UAST + } + fun testParents(field: PsiField) { + val parent = field.parent + val method = PsiTreeUtil.getParentOfType(field, PsiMethod::class.java) + } + + fun testReport(context: JavaContext, node: UCallExpression) { + context.report(ISSUE, node, context.getLocation(node), + """ + |Instead you should call foo().bar().baz() here. + |""".trimIndent()) + } + + companion object { + private val IMPLEMENTATION = + Implementation( + MyKotlinLintDetector::class.java, + Scope.JAVA_FILE_SCOPE + ) + + val ISSUE = + Issue.create( + id = "badlyCapitalized id", + briefDescription = "checks MyLintDetector.", + explanation = """ + Some description here. + Here's a call: foo.bar.baz(args). + This line continuation is okay. \ + But this one is missing a space.\ + Okay? + """.trimIndent(), + category = Category.INTEROPERABILITY_KOTLIN, + moreInfo = "https://code.google.com/p/android/issues/detail?id=65351", // OBSOLETE + priority = 4, + severity = Severity.WARNING, + implementation = IMPLEMENTATION + ) + .addMoreInfo("https://issuetracker.google.com/issues/3733548") // ERROR - missing digit + .addMoreInfo("https://issuetracker.google.com/issues/373354878") // OK - including digit + .addMoreInfo("http://issuetracker.google.com/issues/37335487") // ERROR - http instead of https + .addMoreInfo("https://b.corp.google.com/issues/139153781") // ERROR - don't point to buganizer with internal link + .addMoreInfo("https://goo.gle/policy-storage-help") // OK - regression test for goo.gle + } + + override fun visitAnnotationUsage( + context: JavaContext, + element: org.jetbrains.uast.UElement.UElement, + annotationInfo: com.android.tools.lint.detector.api.AnnotationInfo, + usageInfo: com.android.tools.lint.detector.api.AnnotationUsageInfo + ) { + // Invalid recursion! + super.visitAnnotationUsage(context, element, annotationInfo, usageInfo) + } + + fun misc() { + System.out.print("Debugging") + println("Debugging code") + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/MyIssueRegistry.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg +import com.android.tools.lint.client.api.IssueRegistry +class MyIssueRegistry : IssueRegistry() { + override val issues = listOf( + MyJavaLintDetector.ISSUE, + MyKotlinLintDetector.Companion.ISSUE + ) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/MyVendorIssueRegistry.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg +import com.android.tools.lint.client.api.IssueRegistry +import com.android.tools.lint.client.api.Vendor +class MyVendorIssueRegistry : IssueRegistry() { + // Supplies a vendor: no warning + override var vendor: Vendor? = Vendor("Unit test") + override val issues = listOf( + MyJavaLintDetector.ISSUE, + MyKotlinLintDetector.Companion.ISSUE + ) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/InheritingRegistry.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg +import com.android.tools.lint.client.api.IssueRegistry +import com.android.tools.lint.client.api.Vendor +class InheritingRegistry : MyVendorIssueRegistry() { // NO WARNING + // This registry doesn't supply a vendor but inherits one; no warning + override val issues = listOf( + MyJavaLintDetector.ISSUE, + MyKotlinLintDetector.Companion.ISSUE + ) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `src/test/pkg/MyKotlinLintDetectorTest.kt`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers diff --git a/docs/checks/LintImplBadUrl.md.html b/docs/checks/LintImplBadUrl.md.html index 66cbdf93..e932a807 100644 --- a/docs/checks/LintImplBadUrl.md.html +++ b/docs/checks/LintImplBadUrl.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 4.1.0 (October 2020) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/LintDetectorDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/LintDetectorDetectorTest.kt) -Copyright Year -: 2020 More Info URLs let a link check point to additional resources about the problem and solution it's checking for. @@ -43,21 +43,15 @@ src/test/pkg/MyJavaLintDetector.java:30:Error: Don't point to old http://b.android.com links; should be using https://issuetracker.google.com instead [LintImplBadUrl] - + "https://code.google.com/p/android/issues/detail?id=65351 blah blah blah.", -------------------------------------------------------- - - src/test/pkg/MyJavaLintDetector.java:35:Error: Unexpected protocol file in file://explanation.doc [LintImplBadUrl] - .addMoreInfo("file://explanation.doc") ---------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `src/test/pkg/MyJavaLintDetector.java`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers @@ -143,6 +137,201 @@ } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/test/pkg/MyKotlinLintDetector.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +/* Copyright (C) 2020 The Android Open Source Project */ +package test.pkg +import com.intellij.psi.PsiCallExpression +import com.intellij.psi.PsiExpression +import com.intellij.psi.PsiField +import com.intellij.psi.PsiMethod +import com.intellij.psi.util.PsiTreeUtil +import com.android.tools.lint.detector.api.Category +import com.android.tools.lint.detector.api.Detector +import com.android.tools.lint.detector.api.Implementation +import com.android.tools.lint.detector.api.Issue +import com.android.tools.lint.detector.api.JavaContext +import com.android.tools.lint.detector.api.Scope +import com.android.tools.lint.detector.api.Severity +import org.jetbrains.uast.UCallExpression + +class MyKotlinLintDetector : Detector() { + fun testGetBody(method: PsiMethod) { + val body = method.body // ERROR - must use UAST + } + @Suppress("ReplaceCallWithBinaryOperator","ControlFlowWithEmptyBody") + fun testEquals(element1: PsiCallExpression, element2: PsiExpression) { + if (element1.equals(element2)) { } + if (element2.equals(element1)) { } + if (element1 == element2) { } + if (element1 === element2) { } + if (element1 != element2) { } + if (element1 !== element2) { } + if (element1 == null) { } // OK + if (element1 === null) { } // OK + if (element1 != null) { } // OK + if (element1 !== null) { } // OK + } + @Suppress("UsePropertyAccessSyntax") + fun testGetInitializer(field: PsiField) { + field.getInitializer() // ERROR - must use UAST + field.initializer // ERROR - must use UAST + } + fun testParents(field: PsiField) { + val parent = field.parent + val method = PsiTreeUtil.getParentOfType(field, PsiMethod::class.java) + } + + fun testReport(context: JavaContext, node: UCallExpression) { + context.report(ISSUE, node, context.getLocation(node), + """ + |Instead you should call foo().bar().baz() here. + |""".trimIndent()) + } + + companion object { + private val IMPLEMENTATION = + Implementation( + MyKotlinLintDetector::class.java, + Scope.JAVA_FILE_SCOPE + ) + + val ISSUE = + Issue.create( + id = "badlyCapitalized id", + briefDescription = "checks MyLintDetector.", + explanation = """ + Some description here. + Here's a call: foo.bar.baz(args). + This line continuation is okay. \ + But this one is missing a space.\ + Okay? + """.trimIndent(), + category = Category.INTEROPERABILITY_KOTLIN, + moreInfo = "https://code.google.com/p/android/issues/detail?id=65351", // OBSOLETE + priority = 4, + severity = Severity.WARNING, + implementation = IMPLEMENTATION + ) + .addMoreInfo("https://issuetracker.google.com/issues/3733548") // ERROR - missing digit + .addMoreInfo("https://issuetracker.google.com/issues/373354878") // OK - including digit + .addMoreInfo("http://issuetracker.google.com/issues/37335487") // ERROR - http instead of https + .addMoreInfo("https://b.corp.google.com/issues/139153781") // ERROR - don't point to buganizer with internal link + .addMoreInfo("https://goo.gle/policy-storage-help") // OK - regression test for goo.gle + } + + override fun visitAnnotationUsage( + context: JavaContext, + element: org.jetbrains.uast.UElement.UElement, + annotationInfo: com.android.tools.lint.detector.api.AnnotationInfo, + usageInfo: com.android.tools.lint.detector.api.AnnotationUsageInfo + ) { + // Invalid recursion! + super.visitAnnotationUsage(context, element, annotationInfo, usageInfo) + } + + fun misc() { + System.out.print("Debugging") + println("Debugging code") + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/MyIssueRegistry.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg +import com.android.tools.lint.client.api.IssueRegistry +class MyIssueRegistry : IssueRegistry() { + override val issues = listOf( + MyJavaLintDetector.ISSUE, + MyKotlinLintDetector.Companion.ISSUE + ) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/MyVendorIssueRegistry.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg +import com.android.tools.lint.client.api.IssueRegistry +import com.android.tools.lint.client.api.Vendor +class MyVendorIssueRegistry : IssueRegistry() { + // Supplies a vendor: no warning + override var vendor: Vendor? = Vendor("Unit test") + override val issues = listOf( + MyJavaLintDetector.ISSUE, + MyKotlinLintDetector.Companion.ISSUE + ) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/InheritingRegistry.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg +import com.android.tools.lint.client.api.IssueRegistry +import com.android.tools.lint.client.api.Vendor +class InheritingRegistry : MyVendorIssueRegistry() { // NO WARNING + // This registry doesn't supply a vendor but inherits one; no warning + override val issues = listOf( + MyJavaLintDetector.ISSUE, + MyKotlinLintDetector.Companion.ISSUE + ) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/MyKotlinLintDetectorTest.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +// Copyright (C) 2021 The Android Open Source Project +package test.pkg +import com.android.tools.lint.checks.infrastructure.LintDetectorTest +import com.android.tools.lint.detector.api.Detector +class MyKotlinLintDetectorTest : LintDetectorTest() { + override fun getDetector(): Detector { + return MyKotlinLintDetector() + } + + fun testBasic() { + val expected = """ + src/test/pkg/AlarmTest.java:9: Warning: Value will be forced up to 5000 as of Android 5.1; don't rely on this to be exact [ShortAlarm] + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 50, 10, null); // ERROR + ~~ + 0 errors, 1 warnings + """ + + lint().files( + kotlin( + """ + fun test() { + println("Value=${"$"}") + } + """ + ), + java( + "src/test/pkg/AlarmTest.java", + """ + package test.pkg; + + import android.app.AlarmManager; + @SuppressWarnings("ClassNameDiffersFromFileName") + public class AlarmTest { + public void test(AlarmManager alarmManager) { + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 5000, 60000, null); // OK + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 6000, 70000, null); // OK + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 50, 10, null); // ERROR + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 5000, // ERROR + OtherClass.MY_INTERVAL, null); // ERROR + } + + private static class OtherClass { + public static final long MY_INTERVAL = 1000L; + } + } + """.trimIndent() + ) + ).run().expect(expected) + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/LintDetectorDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/LintImplDollarEscapes.md.html b/docs/checks/LintImplDollarEscapes.md.html index 16c67f56..6e98b7e2 100644 --- a/docs/checks/LintImplDollarEscapes.md.html +++ b/docs/checks/LintImplDollarEscapes.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 4.1.0 (October 2020) Affects : Kotlin and Java files and test sources Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/LintDetectorDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/LintDetectorDetectorTest.kt) -Copyright Year -: 2020 Instead of putting `${"$"}` in your Kotlin raw string literals you can simply use $. This looks like the dollar sign but is instead the full @@ -53,14 +53,236 @@ src/test/pkg/MyKotlinLintDetectorTest.kt:22:Error: In unit tests, use the fullwidth dollar sign, $, instead of $, to avoid having to use cumbersome escapes. Lint will treat a $ as a $. [LintImplDollarEscapes] - println("Value=${"$"}") ------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`src/test/pkg/MyJavaLintDetector.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +/* Copyright (C) 2020 The Android Open Source Project */ +package test.pkg; +import com.intellij.psi.PsiClass; +import com.intellij.psi.PsiCallExpression; +import com.intellij.psi.PsiExpression; +import com.intellij.psi.PsiField; +import com.intellij.psi.PsiMethod; +import com.intellij.psi.util.PsiTreeUtil; +import com.android.tools.lint.detector.api.Detector; +import org.jetbrains.uast.UFile; +import org.jetbrains.uast.UMethod; +import org.jetbrains.uast.UField; +import com.android.tools.lint.detector.api.Category; +import com.android.tools.lint.detector.api.Detector; +import com.android.tools.lint.detector.api.Implementation; +import com.android.tools.lint.detector.api.Issue; +import com.android.tools.lint.detector.api.JavaContext; +import com.android.tools.lint.detector.api.Scope; +import com.android.tools.lint.detector.api.Severity; +import org.jetbrains.uast.UCallExpression; +import java.util.EnumSet; + +@SuppressWarnings({"MethodMayBeStatic", "ClassNameDiffersFromFileName", "StatementWithEmptyBody", "deprecation"}) +public class MyJavaLintDetector extends Detector { + public static final Issue ISSUE = + Issue.create( + "com.android.namespaced.lint.check.FooDetector", + "Wrong use of ", + "As described in " + + "https://code.google.com/p/android/issues/detail?id=65351 blah blah blah.", + Category.A11Y, + 3, + Severity.WARNING, + new Implementation(MyJavaLintDetector.class, EnumSet.of(Scope.RESOURCE_FILE, Scope.JAVA_FILE))) + .addMoreInfo("file://explanation.doc") + .addMoreInfo("http://my.personal.blogger.com/aboutme.htm") + .addMoreInfo("mailto:lint@example.com"); + public void testGetBody(PsiMethod method) { + method.getBody(); // ERROR - must use UAST + } + public void testGetBody(UMethod method) { + method.getBody(); // ERROR - must use UAST + } + public void testGetContainingClass(UMethod method, UField field) { + method.getContainingClass(); // ERROR - must use UAST + field.getContainingClass(); // ERROR - must use UAST + } + public void testGetContainingClass(PsiMethod method, PsiField field) { + method.getContainingClass(); // OK - legitimate uses after resolve + field.getContainingClass(); // OK - legitimate uses after resolve + } + public void testEquals(PsiCallExpression element1, PsiExpression element2) { + if (element1.equals(element2)) { } + if (element2.equals(element1)) { } + if (element1 == element2) { } + if (element1 != element2) { } + } + public void testGetInitializer(PsiField field) { + field.getInitializer(); // ERROR - must use UAST + } + public void testParents(PsiField field, UMethod method) { + PsiElement parent = field.getParent(); // OK + PsiElement parent = method.getParent(); // ERROR + PsiTreeUtil.getParentOfType(field, PsiClass.class); // OK + PsiTreeUtil.getParentOfType(method, PsiClass.class); // ERROR + } + + public void testReport(JavaContext context, UCallExpression node) { + context.report(ISSUE, node, context.getLocation(node), + "Wrong use of LinearLayout."); + context.report(ISSUE, node, context.getLocation(node), + "First problem. Second problem."); + context.report(ISSUE, node, context.getLocation(node), + "This is teh typo"); + String message = "Welcome to Andriod"; + context.report(ISSUE, node, context.getLocation(node), message); + context.report(ISSUE, node, context.getLocation(node), + "Should you use `x ?: y` instead of ```foo ? 1 : 0``` ?"); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/MyKotlinLintDetector.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +/* Copyright (C) 2020 The Android Open Source Project */ +package test.pkg +import com.intellij.psi.PsiCallExpression +import com.intellij.psi.PsiExpression +import com.intellij.psi.PsiField +import com.intellij.psi.PsiMethod +import com.intellij.psi.util.PsiTreeUtil +import com.android.tools.lint.detector.api.Category +import com.android.tools.lint.detector.api.Detector +import com.android.tools.lint.detector.api.Implementation +import com.android.tools.lint.detector.api.Issue +import com.android.tools.lint.detector.api.JavaContext +import com.android.tools.lint.detector.api.Scope +import com.android.tools.lint.detector.api.Severity +import org.jetbrains.uast.UCallExpression + +class MyKotlinLintDetector : Detector() { + fun testGetBody(method: PsiMethod) { + val body = method.body // ERROR - must use UAST + } + @Suppress("ReplaceCallWithBinaryOperator","ControlFlowWithEmptyBody") + fun testEquals(element1: PsiCallExpression, element2: PsiExpression) { + if (element1.equals(element2)) { } + if (element2.equals(element1)) { } + if (element1 == element2) { } + if (element1 === element2) { } + if (element1 != element2) { } + if (element1 !== element2) { } + if (element1 == null) { } // OK + if (element1 === null) { } // OK + if (element1 != null) { } // OK + if (element1 !== null) { } // OK + } + @Suppress("UsePropertyAccessSyntax") + fun testGetInitializer(field: PsiField) { + field.getInitializer() // ERROR - must use UAST + field.initializer // ERROR - must use UAST + } + fun testParents(field: PsiField) { + val parent = field.parent + val method = PsiTreeUtil.getParentOfType(field, PsiMethod::class.java) + } + + fun testReport(context: JavaContext, node: UCallExpression) { + context.report(ISSUE, node, context.getLocation(node), + """ + |Instead you should call foo().bar().baz() here. + |""".trimIndent()) + } + + companion object { + private val IMPLEMENTATION = + Implementation( + MyKotlinLintDetector::class.java, + Scope.JAVA_FILE_SCOPE + ) + + val ISSUE = + Issue.create( + id = "badlyCapitalized id", + briefDescription = "checks MyLintDetector.", + explanation = """ + Some description here. + Here's a call: foo.bar.baz(args). + This line continuation is okay. \ + But this one is missing a space.\ + Okay? + """.trimIndent(), + category = Category.INTEROPERABILITY_KOTLIN, + moreInfo = "https://code.google.com/p/android/issues/detail?id=65351", // OBSOLETE + priority = 4, + severity = Severity.WARNING, + implementation = IMPLEMENTATION + ) + .addMoreInfo("https://issuetracker.google.com/issues/3733548") // ERROR - missing digit + .addMoreInfo("https://issuetracker.google.com/issues/373354878") // OK - including digit + .addMoreInfo("http://issuetracker.google.com/issues/37335487") // ERROR - http instead of https + .addMoreInfo("https://b.corp.google.com/issues/139153781") // ERROR - don't point to buganizer with internal link + .addMoreInfo("https://goo.gle/policy-storage-help") // OK - regression test for goo.gle + } + override fun visitAnnotationUsage( + context: JavaContext, + element: org.jetbrains.uast.UElement.UElement, + annotationInfo: com.android.tools.lint.detector.api.AnnotationInfo, + usageInfo: com.android.tools.lint.detector.api.AnnotationUsageInfo + ) { + // Invalid recursion! + super.visitAnnotationUsage(context, element, annotationInfo, usageInfo) + } + fun misc() { + System.out.print("Debugging") + println("Debugging code") + } +} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +`src/test/pkg/MyIssueRegistry.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg +import com.android.tools.lint.client.api.IssueRegistry +class MyIssueRegistry : IssueRegistry() { + override val issues = listOf( + MyJavaLintDetector.ISSUE, + MyKotlinLintDetector.Companion.ISSUE + ) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/MyVendorIssueRegistry.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg +import com.android.tools.lint.client.api.IssueRegistry +import com.android.tools.lint.client.api.Vendor +class MyVendorIssueRegistry : IssueRegistry() { + // Supplies a vendor: no warning + override var vendor: Vendor? = Vendor("Unit test") + override val issues = listOf( + MyJavaLintDetector.ISSUE, + MyKotlinLintDetector.Companion.ISSUE + ) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/InheritingRegistry.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg +import com.android.tools.lint.client.api.IssueRegistry +import com.android.tools.lint.client.api.Vendor +class InheritingRegistry : MyVendorIssueRegistry() { // NO WARNING + // This registry doesn't supply a vendor but inherits one; no warning + override val issues = listOf( + MyJavaLintDetector.ISSUE, + MyKotlinLintDetector.Companion.ISSUE + ) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `src/test/pkg/MyKotlinLintDetectorTest.kt`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers diff --git a/docs/checks/LintImplIdFormat.md.html b/docs/checks/LintImplIdFormat.md.html index 1a7a9b85..6fb3b93a 100644 --- a/docs/checks/LintImplIdFormat.md.html +++ b/docs/checks/LintImplIdFormat.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 4.1.0 (October 2020) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/LintDetectorDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/LintDetectorDetectorTest.kt) -Copyright Year -: 2020 This check looks at lint issue id registrations and makes sure the id follows the expected conventions: capitalized, camel case, no spaces, @@ -55,14 +55,95 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/MyKotlinLintDetector.kt:60:Error: Lint issue IDs should use capitalized camel case, such as MyIssueId [LintImplIdFormat] - id = "badlyCapitalized id", - ------------------- + --------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Here are the relevant source files: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/test/pkg/MyJavaLintDetector.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +/* Copyright (C) 2020 The Android Open Source Project */ +package test.pkg; +import com.intellij.psi.PsiClass; +import com.intellij.psi.PsiCallExpression; +import com.intellij.psi.PsiExpression; +import com.intellij.psi.PsiField; +import com.intellij.psi.PsiMethod; +import com.intellij.psi.util.PsiTreeUtil; +import com.android.tools.lint.detector.api.Detector; +import org.jetbrains.uast.UFile; +import org.jetbrains.uast.UMethod; +import org.jetbrains.uast.UField; +import com.android.tools.lint.detector.api.Category; +import com.android.tools.lint.detector.api.Detector; +import com.android.tools.lint.detector.api.Implementation; +import com.android.tools.lint.detector.api.Issue; +import com.android.tools.lint.detector.api.JavaContext; +import com.android.tools.lint.detector.api.Scope; +import com.android.tools.lint.detector.api.Severity; +import org.jetbrains.uast.UCallExpression; +import java.util.EnumSet; + +@SuppressWarnings({"MethodMayBeStatic", "ClassNameDiffersFromFileName", "StatementWithEmptyBody", "deprecation"}) +public class MyJavaLintDetector extends Detector { + public static final Issue ISSUE = + Issue.create( + "com.android.namespaced.lint.check.FooDetector", + "Wrong use of ", + "As described in " + + "https://code.google.com/p/android/issues/detail?id=65351 blah blah blah.", + Category.A11Y, + 3, + Severity.WARNING, + new Implementation(MyJavaLintDetector.class, EnumSet.of(Scope.RESOURCE_FILE, Scope.JAVA_FILE))) + .addMoreInfo("file://explanation.doc") + .addMoreInfo("http://my.personal.blogger.com/aboutme.htm") + .addMoreInfo("mailto:lint@example.com"); + public void testGetBody(PsiMethod method) { + method.getBody(); // ERROR - must use UAST + } + public void testGetBody(UMethod method) { + method.getBody(); // ERROR - must use UAST + } + public void testGetContainingClass(UMethod method, UField field) { + method.getContainingClass(); // ERROR - must use UAST + field.getContainingClass(); // ERROR - must use UAST + } + public void testGetContainingClass(PsiMethod method, PsiField field) { + method.getContainingClass(); // OK - legitimate uses after resolve + field.getContainingClass(); // OK - legitimate uses after resolve + } + public void testEquals(PsiCallExpression element1, PsiExpression element2) { + if (element1.equals(element2)) { } + if (element2.equals(element1)) { } + if (element1 == element2) { } + if (element1 != element2) { } + } + public void testGetInitializer(PsiField field) { + field.getInitializer(); // ERROR - must use UAST + } + public void testParents(PsiField field, UMethod method) { + PsiElement parent = field.getParent(); // OK + PsiElement parent = method.getParent(); // ERROR + PsiTreeUtil.getParentOfType(field, PsiClass.class); // OK + PsiTreeUtil.getParentOfType(method, PsiClass.class); // ERROR + } -Here is the source file referenced above: + public void testReport(JavaContext context, UCallExpression node) { + context.report(ISSUE, node, context.getLocation(node), + "Wrong use of LinearLayout."); + context.report(ISSUE, node, context.getLocation(node), + "First problem. Second problem."); + context.report(ISSUE, node, context.getLocation(node), + "This is teh typo"); + String message = "Welcome to Andriod"; + context.report(ISSUE, node, context.getLocation(node), message); + context.report(ISSUE, node, context.getLocation(node), + "Should you use `x ?: y` instead of ```foo ? 1 : 0``` ?"); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `src/test/pkg/MyKotlinLintDetector.kt`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers @@ -130,6 +211,9 @@ explanation = """ Some description here. Here's a call: foo.bar.baz(args). + This line continuation is okay. \ + But this one is missing a space.\ + Okay? """.trimIndent(), category = Category.INTEROPERABILITY_KOTLIN, moreInfo = "https://code.google.com/p/android/issues/detail?id=65351", // OBSOLETE @@ -161,6 +245,101 @@ } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/test/pkg/MyIssueRegistry.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg +import com.android.tools.lint.client.api.IssueRegistry +class MyIssueRegistry : IssueRegistry() { + override val issues = listOf( + MyJavaLintDetector.ISSUE, + MyKotlinLintDetector.Companion.ISSUE + ) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/MyVendorIssueRegistry.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg +import com.android.tools.lint.client.api.IssueRegistry +import com.android.tools.lint.client.api.Vendor +class MyVendorIssueRegistry : IssueRegistry() { + // Supplies a vendor: no warning + override var vendor: Vendor? = Vendor("Unit test") + override val issues = listOf( + MyJavaLintDetector.ISSUE, + MyKotlinLintDetector.Companion.ISSUE + ) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/InheritingRegistry.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg +import com.android.tools.lint.client.api.IssueRegistry +import com.android.tools.lint.client.api.Vendor +class InheritingRegistry : MyVendorIssueRegistry() { // NO WARNING + // This registry doesn't supply a vendor but inherits one; no warning + override val issues = listOf( + MyJavaLintDetector.ISSUE, + MyKotlinLintDetector.Companion.ISSUE + ) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/MyKotlinLintDetectorTest.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +// Copyright (C) 2021 The Android Open Source Project +package test.pkg +import com.android.tools.lint.checks.infrastructure.LintDetectorTest +import com.android.tools.lint.detector.api.Detector +class MyKotlinLintDetectorTest : LintDetectorTest() { + override fun getDetector(): Detector { + return MyKotlinLintDetector() + } + + fun testBasic() { + val expected = """ + src/test/pkg/AlarmTest.java:9: Warning: Value will be forced up to 5000 as of Android 5.1; don't rely on this to be exact [ShortAlarm] + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 50, 10, null); // ERROR + ~~ + 0 errors, 1 warnings + """ + + lint().files( + kotlin( + """ + fun test() { + println("Value=${"$"}") + } + """ + ), + java( + "src/test/pkg/AlarmTest.java", + """ + package test.pkg; + + import android.app.AlarmManager; + @SuppressWarnings("ClassNameDiffersFromFileName") + public class AlarmTest { + public void test(AlarmManager alarmManager) { + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 5000, 60000, null); // OK + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 6000, 70000, null); // OK + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 50, 10, null); // ERROR + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 5000, // ERROR + OtherClass.MY_INTERVAL, null); // ERROR + } + + private static class OtherClass { + public static final long MY_INTERVAL = 1000L; + } + } + """.trimIndent() + ) + ).run().expect(expected) + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/LintDetectorDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/LintImplPsiEquals.md.html b/docs/checks/LintImplPsiEquals.md.html index 786e0acc..f1a8f5a1 100644 --- a/docs/checks/LintImplPsiEquals.md.html +++ b/docs/checks/LintImplPsiEquals.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 4.1.0 (October 2020) Affects : Kotlin and Java files Editing @@ -28,11 +30,10 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/LintDetectorDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/LintDetectorDetectorTest.kt) -Copyright Year -: 2020 You should never compare two PSI elements for equality with `equals`; -use `isEquivalentTo(PsiElement)` instead. +use `PsiEquivalenceUtil.areElementsEquivalent(PsiElement, PsiElement)` +instead. (##) Example @@ -40,21 +41,15 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/MyJavaLintDetector.java:53:Error: Don't compare PsiElements with equals, use isEquivalentTo(PsiElement) instead [LintImplPsiEquals] - if (element1.equals(element2)) { } ------------------------- - - src/test/pkg/MyJavaLintDetector.java:54:Error: Don't compare PsiElements with equals, use isEquivalentTo(PsiElement) instead [LintImplPsiEquals] - if (element2.equals(element1)) { } ------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `src/test/pkg/MyJavaLintDetector.java`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers @@ -140,6 +135,201 @@ } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/test/pkg/MyKotlinLintDetector.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +/* Copyright (C) 2020 The Android Open Source Project */ +package test.pkg +import com.intellij.psi.PsiCallExpression +import com.intellij.psi.PsiExpression +import com.intellij.psi.PsiField +import com.intellij.psi.PsiMethod +import com.intellij.psi.util.PsiTreeUtil +import com.android.tools.lint.detector.api.Category +import com.android.tools.lint.detector.api.Detector +import com.android.tools.lint.detector.api.Implementation +import com.android.tools.lint.detector.api.Issue +import com.android.tools.lint.detector.api.JavaContext +import com.android.tools.lint.detector.api.Scope +import com.android.tools.lint.detector.api.Severity +import org.jetbrains.uast.UCallExpression + +class MyKotlinLintDetector : Detector() { + fun testGetBody(method: PsiMethod) { + val body = method.body // ERROR - must use UAST + } + @Suppress("ReplaceCallWithBinaryOperator","ControlFlowWithEmptyBody") + fun testEquals(element1: PsiCallExpression, element2: PsiExpression) { + if (element1.equals(element2)) { } + if (element2.equals(element1)) { } + if (element1 == element2) { } + if (element1 === element2) { } + if (element1 != element2) { } + if (element1 !== element2) { } + if (element1 == null) { } // OK + if (element1 === null) { } // OK + if (element1 != null) { } // OK + if (element1 !== null) { } // OK + } + @Suppress("UsePropertyAccessSyntax") + fun testGetInitializer(field: PsiField) { + field.getInitializer() // ERROR - must use UAST + field.initializer // ERROR - must use UAST + } + fun testParents(field: PsiField) { + val parent = field.parent + val method = PsiTreeUtil.getParentOfType(field, PsiMethod::class.java) + } + + fun testReport(context: JavaContext, node: UCallExpression) { + context.report(ISSUE, node, context.getLocation(node), + """ + |Instead you should call foo().bar().baz() here. + |""".trimIndent()) + } + + companion object { + private val IMPLEMENTATION = + Implementation( + MyKotlinLintDetector::class.java, + Scope.JAVA_FILE_SCOPE + ) + + val ISSUE = + Issue.create( + id = "badlyCapitalized id", + briefDescription = "checks MyLintDetector.", + explanation = """ + Some description here. + Here's a call: foo.bar.baz(args). + This line continuation is okay. \ + But this one is missing a space.\ + Okay? + """.trimIndent(), + category = Category.INTEROPERABILITY_KOTLIN, + moreInfo = "https://code.google.com/p/android/issues/detail?id=65351", // OBSOLETE + priority = 4, + severity = Severity.WARNING, + implementation = IMPLEMENTATION + ) + .addMoreInfo("https://issuetracker.google.com/issues/3733548") // ERROR - missing digit + .addMoreInfo("https://issuetracker.google.com/issues/373354878") // OK - including digit + .addMoreInfo("http://issuetracker.google.com/issues/37335487") // ERROR - http instead of https + .addMoreInfo("https://b.corp.google.com/issues/139153781") // ERROR - don't point to buganizer with internal link + .addMoreInfo("https://goo.gle/policy-storage-help") // OK - regression test for goo.gle + } + + override fun visitAnnotationUsage( + context: JavaContext, + element: org.jetbrains.uast.UElement.UElement, + annotationInfo: com.android.tools.lint.detector.api.AnnotationInfo, + usageInfo: com.android.tools.lint.detector.api.AnnotationUsageInfo + ) { + // Invalid recursion! + super.visitAnnotationUsage(context, element, annotationInfo, usageInfo) + } + + fun misc() { + System.out.print("Debugging") + println("Debugging code") + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/MyIssueRegistry.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg +import com.android.tools.lint.client.api.IssueRegistry +class MyIssueRegistry : IssueRegistry() { + override val issues = listOf( + MyJavaLintDetector.ISSUE, + MyKotlinLintDetector.Companion.ISSUE + ) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/MyVendorIssueRegistry.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg +import com.android.tools.lint.client.api.IssueRegistry +import com.android.tools.lint.client.api.Vendor +class MyVendorIssueRegistry : IssueRegistry() { + // Supplies a vendor: no warning + override var vendor: Vendor? = Vendor("Unit test") + override val issues = listOf( + MyJavaLintDetector.ISSUE, + MyKotlinLintDetector.Companion.ISSUE + ) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/InheritingRegistry.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg +import com.android.tools.lint.client.api.IssueRegistry +import com.android.tools.lint.client.api.Vendor +class InheritingRegistry : MyVendorIssueRegistry() { // NO WARNING + // This registry doesn't supply a vendor but inherits one; no warning + override val issues = listOf( + MyJavaLintDetector.ISSUE, + MyKotlinLintDetector.Companion.ISSUE + ) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/MyKotlinLintDetectorTest.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +// Copyright (C) 2021 The Android Open Source Project +package test.pkg +import com.android.tools.lint.checks.infrastructure.LintDetectorTest +import com.android.tools.lint.detector.api.Detector +class MyKotlinLintDetectorTest : LintDetectorTest() { + override fun getDetector(): Detector { + return MyKotlinLintDetector() + } + + fun testBasic() { + val expected = """ + src/test/pkg/AlarmTest.java:9: Warning: Value will be forced up to 5000 as of Android 5.1; don't rely on this to be exact [ShortAlarm] + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 50, 10, null); // ERROR + ~~ + 0 errors, 1 warnings + """ + + lint().files( + kotlin( + """ + fun test() { + println("Value=${"$"}") + } + """ + ), + java( + "src/test/pkg/AlarmTest.java", + """ + package test.pkg; + + import android.app.AlarmManager; + @SuppressWarnings("ClassNameDiffersFromFileName") + public class AlarmTest { + public void test(AlarmManager alarmManager) { + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 5000, 60000, null); // OK + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 6000, 70000, null); // OK + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 50, 10, null); // ERROR + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 5000, // ERROR + OtherClass.MY_INTERVAL, null); // ERROR + } + + private static class OtherClass { + public static final long MY_INTERVAL = 1000L; + } + } + """.trimIndent() + ) + ).run().expect(expected) + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/LintDetectorDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/LintImplTextFormat.md.html b/docs/checks/LintImplTextFormat.md.html index 203abced..0de1cdd4 100644 --- a/docs/checks/LintImplTextFormat.md.html +++ b/docs/checks/LintImplTextFormat.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 4.1.0 (October 2020) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/LintDetectorDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/LintDetectorDetectorTest.kt) -Copyright Year -: 2020 Lint supports various markdown like formatting directives in all of its strings (issue explanations, reported error messages, etc). @@ -52,35 +52,23 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/MyJavaLintDetector.java:70:Warning: Single sentence error messages should not end with a period [LintImplTextFormat] - "Wrong use of LinearLayout."); -------------------------- - - src/test/pkg/MyJavaLintDetector.java:74:Warning: "teh" is a common misspelling; did you mean "the"? [LintImplTextFormat] - "This is teh typo"); --- - - src/test/pkg/MyJavaLintDetector.java:76:Warning: "Andriod" is a common misspelling; did you mean "Android"? [LintImplTextFormat] - context.report(ISSUE, node, context.getLocation(node), message); ------- - - src/test/pkg/MyJavaLintDetector.java:78:Warning: Question marks should not be separated by a space [LintImplTextFormat] - "Should you use `x ?: y` instead of ```foo ? 1 : 0``` ?"); - - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `src/test/pkg/MyJavaLintDetector.java`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers @@ -166,6 +154,201 @@ } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/test/pkg/MyKotlinLintDetector.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +/* Copyright (C) 2020 The Android Open Source Project */ +package test.pkg +import com.intellij.psi.PsiCallExpression +import com.intellij.psi.PsiExpression +import com.intellij.psi.PsiField +import com.intellij.psi.PsiMethod +import com.intellij.psi.util.PsiTreeUtil +import com.android.tools.lint.detector.api.Category +import com.android.tools.lint.detector.api.Detector +import com.android.tools.lint.detector.api.Implementation +import com.android.tools.lint.detector.api.Issue +import com.android.tools.lint.detector.api.JavaContext +import com.android.tools.lint.detector.api.Scope +import com.android.tools.lint.detector.api.Severity +import org.jetbrains.uast.UCallExpression + +class MyKotlinLintDetector : Detector() { + fun testGetBody(method: PsiMethod) { + val body = method.body // ERROR - must use UAST + } + @Suppress("ReplaceCallWithBinaryOperator","ControlFlowWithEmptyBody") + fun testEquals(element1: PsiCallExpression, element2: PsiExpression) { + if (element1.equals(element2)) { } + if (element2.equals(element1)) { } + if (element1 == element2) { } + if (element1 === element2) { } + if (element1 != element2) { } + if (element1 !== element2) { } + if (element1 == null) { } // OK + if (element1 === null) { } // OK + if (element1 != null) { } // OK + if (element1 !== null) { } // OK + } + @Suppress("UsePropertyAccessSyntax") + fun testGetInitializer(field: PsiField) { + field.getInitializer() // ERROR - must use UAST + field.initializer // ERROR - must use UAST + } + fun testParents(field: PsiField) { + val parent = field.parent + val method = PsiTreeUtil.getParentOfType(field, PsiMethod::class.java) + } + + fun testReport(context: JavaContext, node: UCallExpression) { + context.report(ISSUE, node, context.getLocation(node), + """ + |Instead you should call foo().bar().baz() here. + |""".trimIndent()) + } + + companion object { + private val IMPLEMENTATION = + Implementation( + MyKotlinLintDetector::class.java, + Scope.JAVA_FILE_SCOPE + ) + + val ISSUE = + Issue.create( + id = "badlyCapitalized id", + briefDescription = "checks MyLintDetector.", + explanation = """ + Some description here. + Here's a call: foo.bar.baz(args). + This line continuation is okay. \ + But this one is missing a space.\ + Okay? + """.trimIndent(), + category = Category.INTEROPERABILITY_KOTLIN, + moreInfo = "https://code.google.com/p/android/issues/detail?id=65351", // OBSOLETE + priority = 4, + severity = Severity.WARNING, + implementation = IMPLEMENTATION + ) + .addMoreInfo("https://issuetracker.google.com/issues/3733548") // ERROR - missing digit + .addMoreInfo("https://issuetracker.google.com/issues/373354878") // OK - including digit + .addMoreInfo("http://issuetracker.google.com/issues/37335487") // ERROR - http instead of https + .addMoreInfo("https://b.corp.google.com/issues/139153781") // ERROR - don't point to buganizer with internal link + .addMoreInfo("https://goo.gle/policy-storage-help") // OK - regression test for goo.gle + } + + override fun visitAnnotationUsage( + context: JavaContext, + element: org.jetbrains.uast.UElement.UElement, + annotationInfo: com.android.tools.lint.detector.api.AnnotationInfo, + usageInfo: com.android.tools.lint.detector.api.AnnotationUsageInfo + ) { + // Invalid recursion! + super.visitAnnotationUsage(context, element, annotationInfo, usageInfo) + } + + fun misc() { + System.out.print("Debugging") + println("Debugging code") + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/MyIssueRegistry.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg +import com.android.tools.lint.client.api.IssueRegistry +class MyIssueRegistry : IssueRegistry() { + override val issues = listOf( + MyJavaLintDetector.ISSUE, + MyKotlinLintDetector.Companion.ISSUE + ) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/MyVendorIssueRegistry.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg +import com.android.tools.lint.client.api.IssueRegistry +import com.android.tools.lint.client.api.Vendor +class MyVendorIssueRegistry : IssueRegistry() { + // Supplies a vendor: no warning + override var vendor: Vendor? = Vendor("Unit test") + override val issues = listOf( + MyJavaLintDetector.ISSUE, + MyKotlinLintDetector.Companion.ISSUE + ) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/InheritingRegistry.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg +import com.android.tools.lint.client.api.IssueRegistry +import com.android.tools.lint.client.api.Vendor +class InheritingRegistry : MyVendorIssueRegistry() { // NO WARNING + // This registry doesn't supply a vendor but inherits one; no warning + override val issues = listOf( + MyJavaLintDetector.ISSUE, + MyKotlinLintDetector.Companion.ISSUE + ) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/MyKotlinLintDetectorTest.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +// Copyright (C) 2021 The Android Open Source Project +package test.pkg +import com.android.tools.lint.checks.infrastructure.LintDetectorTest +import com.android.tools.lint.detector.api.Detector +class MyKotlinLintDetectorTest : LintDetectorTest() { + override fun getDetector(): Detector { + return MyKotlinLintDetector() + } + + fun testBasic() { + val expected = """ + src/test/pkg/AlarmTest.java:9: Warning: Value will be forced up to 5000 as of Android 5.1; don't rely on this to be exact [ShortAlarm] + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 50, 10, null); // ERROR + ~~ + 0 errors, 1 warnings + """ + + lint().files( + kotlin( + """ + fun test() { + println("Value=${"$"}") + } + """ + ), + java( + "src/test/pkg/AlarmTest.java", + """ + package test.pkg; + + import android.app.AlarmManager; + @SuppressWarnings("ClassNameDiffersFromFileName") + public class AlarmTest { + public void test(AlarmManager alarmManager) { + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 5000, 60000, null); // OK + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 6000, 70000, null); // OK + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 50, 10, null); // ERROR + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 5000, // ERROR + OtherClass.MY_INTERVAL, null); // ERROR + } + + private static class OtherClass { + public static final long MY_INTERVAL = 1000L; + } + } + """.trimIndent() + ) + ).run().expect(expected) + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/LintDetectorDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/LintImplTrimIndent.md.html b/docs/checks/LintImplTrimIndent.md.html index 5a52f990..7da57ea1 100644 --- a/docs/checks/LintImplTrimIndent.md.html +++ b/docs/checks/LintImplTrimIndent.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 4.1.0 (October 2020) Affects : Kotlin and Java files and test sources Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/LintDetectorDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/LintDetectorDetectorTest.kt) -Copyright Year -: 2020 Lint implicitly calls `.trimIndent()` (lazily, at the last minute) in a number of places: @@ -53,17 +53,98 @@ Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -src/test/pkg/MyKotlinLintDetector.kt:65:Error: No need to call +src/test/pkg/MyKotlinLintDetector.kt:68:Error: No need to call .trimIndent() in issue registration strings; they are already trimmed by indent by lint when displaying to users [LintImplTrimIndent] - """.trimIndent(), ------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Here are the relevant source files: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/test/pkg/MyJavaLintDetector.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +/* Copyright (C) 2020 The Android Open Source Project */ +package test.pkg; +import com.intellij.psi.PsiClass; +import com.intellij.psi.PsiCallExpression; +import com.intellij.psi.PsiExpression; +import com.intellij.psi.PsiField; +import com.intellij.psi.PsiMethod; +import com.intellij.psi.util.PsiTreeUtil; +import com.android.tools.lint.detector.api.Detector; +import org.jetbrains.uast.UFile; +import org.jetbrains.uast.UMethod; +import org.jetbrains.uast.UField; +import com.android.tools.lint.detector.api.Category; +import com.android.tools.lint.detector.api.Detector; +import com.android.tools.lint.detector.api.Implementation; +import com.android.tools.lint.detector.api.Issue; +import com.android.tools.lint.detector.api.JavaContext; +import com.android.tools.lint.detector.api.Scope; +import com.android.tools.lint.detector.api.Severity; +import org.jetbrains.uast.UCallExpression; +import java.util.EnumSet; + +@SuppressWarnings({"MethodMayBeStatic", "ClassNameDiffersFromFileName", "StatementWithEmptyBody", "deprecation"}) +public class MyJavaLintDetector extends Detector { + public static final Issue ISSUE = + Issue.create( + "com.android.namespaced.lint.check.FooDetector", + "Wrong use of ", + "As described in " + + "https://code.google.com/p/android/issues/detail?id=65351 blah blah blah.", + Category.A11Y, + 3, + Severity.WARNING, + new Implementation(MyJavaLintDetector.class, EnumSet.of(Scope.RESOURCE_FILE, Scope.JAVA_FILE))) + .addMoreInfo("file://explanation.doc") + .addMoreInfo("http://my.personal.blogger.com/aboutme.htm") + .addMoreInfo("mailto:lint@example.com"); + public void testGetBody(PsiMethod method) { + method.getBody(); // ERROR - must use UAST + } + public void testGetBody(UMethod method) { + method.getBody(); // ERROR - must use UAST + } + public void testGetContainingClass(UMethod method, UField field) { + method.getContainingClass(); // ERROR - must use UAST + field.getContainingClass(); // ERROR - must use UAST + } + public void testGetContainingClass(PsiMethod method, PsiField field) { + method.getContainingClass(); // OK - legitimate uses after resolve + field.getContainingClass(); // OK - legitimate uses after resolve + } + public void testEquals(PsiCallExpression element1, PsiExpression element2) { + if (element1.equals(element2)) { } + if (element2.equals(element1)) { } + if (element1 == element2) { } + if (element1 != element2) { } + } + public void testGetInitializer(PsiField field) { + field.getInitializer(); // ERROR - must use UAST + } + public void testParents(PsiField field, UMethod method) { + PsiElement parent = field.getParent(); // OK + PsiElement parent = method.getParent(); // ERROR + PsiTreeUtil.getParentOfType(field, PsiClass.class); // OK + PsiTreeUtil.getParentOfType(method, PsiClass.class); // ERROR + } -Here is the source file referenced above: + public void testReport(JavaContext context, UCallExpression node) { + context.report(ISSUE, node, context.getLocation(node), + "Wrong use of LinearLayout."); + context.report(ISSUE, node, context.getLocation(node), + "First problem. Second problem."); + context.report(ISSUE, node, context.getLocation(node), + "This is teh typo"); + String message = "Welcome to Andriod"; + context.report(ISSUE, node, context.getLocation(node), message); + context.report(ISSUE, node, context.getLocation(node), + "Should you use `x ?: y` instead of ```foo ? 1 : 0``` ?"); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `src/test/pkg/MyKotlinLintDetector.kt`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers @@ -131,6 +212,9 @@ explanation = """ Some description here. Here's a call: foo.bar.baz(args). + This line continuation is okay. \ + But this one is missing a space.\ + Okay? """.trimIndent(), category = Category.INTEROPERABILITY_KOTLIN, moreInfo = "https://code.google.com/p/android/issues/detail?id=65351", // OBSOLETE @@ -162,6 +246,101 @@ } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/test/pkg/MyIssueRegistry.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg +import com.android.tools.lint.client.api.IssueRegistry +class MyIssueRegistry : IssueRegistry() { + override val issues = listOf( + MyJavaLintDetector.ISSUE, + MyKotlinLintDetector.Companion.ISSUE + ) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/MyVendorIssueRegistry.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg +import com.android.tools.lint.client.api.IssueRegistry +import com.android.tools.lint.client.api.Vendor +class MyVendorIssueRegistry : IssueRegistry() { + // Supplies a vendor: no warning + override var vendor: Vendor? = Vendor("Unit test") + override val issues = listOf( + MyJavaLintDetector.ISSUE, + MyKotlinLintDetector.Companion.ISSUE + ) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/InheritingRegistry.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg +import com.android.tools.lint.client.api.IssueRegistry +import com.android.tools.lint.client.api.Vendor +class InheritingRegistry : MyVendorIssueRegistry() { // NO WARNING + // This registry doesn't supply a vendor but inherits one; no warning + override val issues = listOf( + MyJavaLintDetector.ISSUE, + MyKotlinLintDetector.Companion.ISSUE + ) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/MyKotlinLintDetectorTest.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +// Copyright (C) 2021 The Android Open Source Project +package test.pkg +import com.android.tools.lint.checks.infrastructure.LintDetectorTest +import com.android.tools.lint.detector.api.Detector +class MyKotlinLintDetectorTest : LintDetectorTest() { + override fun getDetector(): Detector { + return MyKotlinLintDetector() + } + + fun testBasic() { + val expected = """ + src/test/pkg/AlarmTest.java:9: Warning: Value will be forced up to 5000 as of Android 5.1; don't rely on this to be exact [ShortAlarm] + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 50, 10, null); // ERROR + ~~ + 0 errors, 1 warnings + """ + + lint().files( + kotlin( + """ + fun test() { + println("Value=${"$"}") + } + """ + ), + java( + "src/test/pkg/AlarmTest.java", + """ + package test.pkg; + + import android.app.AlarmManager; + @SuppressWarnings("ClassNameDiffersFromFileName") + public class AlarmTest { + public void test(AlarmManager alarmManager) { + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 5000, 60000, null); // OK + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 6000, 70000, null); // OK + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 50, 10, null); // ERROR + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 5000, // ERROR + OtherClass.MY_INTERVAL, null); // ERROR + } + + private static class OtherClass { + public static final long MY_INTERVAL = 1000L; + } + } + """.trimIndent() + ) + ).run().expect(expected) + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/LintDetectorDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/LintImplUnexpectedDomain.md.html b/docs/checks/LintImplUnexpectedDomain.md.html index e8d2a36a..f9747f7c 100644 --- a/docs/checks/LintImplUnexpectedDomain.md.html +++ b/docs/checks/LintImplUnexpectedDomain.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 4.1.0 (October 2020) Affects : Kotlin and Java files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/LintDetectorDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/LintDetectorDetectorTest.kt) -Copyright Year -: 2020 This checks flags URLs to domains that have not been explicitly allowed for use as a documentation source. @@ -42,14 +42,11 @@ my.personal.blogger.com; for the builtin Android Lint checks make sure to use an authoritative link (http://my.personal.blogger.com/aboutme.htm) [LintImplUnexpectedDomain] - .addMoreInfo("http://my.personal.blogger.com/aboutme.htm") ------------------------------------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `src/test/pkg/MyJavaLintDetector.java`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers @@ -135,6 +132,201 @@ } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/test/pkg/MyKotlinLintDetector.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +/* Copyright (C) 2020 The Android Open Source Project */ +package test.pkg +import com.intellij.psi.PsiCallExpression +import com.intellij.psi.PsiExpression +import com.intellij.psi.PsiField +import com.intellij.psi.PsiMethod +import com.intellij.psi.util.PsiTreeUtil +import com.android.tools.lint.detector.api.Category +import com.android.tools.lint.detector.api.Detector +import com.android.tools.lint.detector.api.Implementation +import com.android.tools.lint.detector.api.Issue +import com.android.tools.lint.detector.api.JavaContext +import com.android.tools.lint.detector.api.Scope +import com.android.tools.lint.detector.api.Severity +import org.jetbrains.uast.UCallExpression + +class MyKotlinLintDetector : Detector() { + fun testGetBody(method: PsiMethod) { + val body = method.body // ERROR - must use UAST + } + @Suppress("ReplaceCallWithBinaryOperator","ControlFlowWithEmptyBody") + fun testEquals(element1: PsiCallExpression, element2: PsiExpression) { + if (element1.equals(element2)) { } + if (element2.equals(element1)) { } + if (element1 == element2) { } + if (element1 === element2) { } + if (element1 != element2) { } + if (element1 !== element2) { } + if (element1 == null) { } // OK + if (element1 === null) { } // OK + if (element1 != null) { } // OK + if (element1 !== null) { } // OK + } + @Suppress("UsePropertyAccessSyntax") + fun testGetInitializer(field: PsiField) { + field.getInitializer() // ERROR - must use UAST + field.initializer // ERROR - must use UAST + } + fun testParents(field: PsiField) { + val parent = field.parent + val method = PsiTreeUtil.getParentOfType(field, PsiMethod::class.java) + } + + fun testReport(context: JavaContext, node: UCallExpression) { + context.report(ISSUE, node, context.getLocation(node), + """ + |Instead you should call foo().bar().baz() here. + |""".trimIndent()) + } + + companion object { + private val IMPLEMENTATION = + Implementation( + MyKotlinLintDetector::class.java, + Scope.JAVA_FILE_SCOPE + ) + + val ISSUE = + Issue.create( + id = "badlyCapitalized id", + briefDescription = "checks MyLintDetector.", + explanation = """ + Some description here. + Here's a call: foo.bar.baz(args). + This line continuation is okay. \ + But this one is missing a space.\ + Okay? + """.trimIndent(), + category = Category.INTEROPERABILITY_KOTLIN, + moreInfo = "https://code.google.com/p/android/issues/detail?id=65351", // OBSOLETE + priority = 4, + severity = Severity.WARNING, + implementation = IMPLEMENTATION + ) + .addMoreInfo("https://issuetracker.google.com/issues/3733548") // ERROR - missing digit + .addMoreInfo("https://issuetracker.google.com/issues/373354878") // OK - including digit + .addMoreInfo("http://issuetracker.google.com/issues/37335487") // ERROR - http instead of https + .addMoreInfo("https://b.corp.google.com/issues/139153781") // ERROR - don't point to buganizer with internal link + .addMoreInfo("https://goo.gle/policy-storage-help") // OK - regression test for goo.gle + } + + override fun visitAnnotationUsage( + context: JavaContext, + element: org.jetbrains.uast.UElement.UElement, + annotationInfo: com.android.tools.lint.detector.api.AnnotationInfo, + usageInfo: com.android.tools.lint.detector.api.AnnotationUsageInfo + ) { + // Invalid recursion! + super.visitAnnotationUsage(context, element, annotationInfo, usageInfo) + } + + fun misc() { + System.out.print("Debugging") + println("Debugging code") + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/MyIssueRegistry.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg +import com.android.tools.lint.client.api.IssueRegistry +class MyIssueRegistry : IssueRegistry() { + override val issues = listOf( + MyJavaLintDetector.ISSUE, + MyKotlinLintDetector.Companion.ISSUE + ) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/MyVendorIssueRegistry.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg +import com.android.tools.lint.client.api.IssueRegistry +import com.android.tools.lint.client.api.Vendor +class MyVendorIssueRegistry : IssueRegistry() { + // Supplies a vendor: no warning + override var vendor: Vendor? = Vendor("Unit test") + override val issues = listOf( + MyJavaLintDetector.ISSUE, + MyKotlinLintDetector.Companion.ISSUE + ) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/InheritingRegistry.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg +import com.android.tools.lint.client.api.IssueRegistry +import com.android.tools.lint.client.api.Vendor +class InheritingRegistry : MyVendorIssueRegistry() { // NO WARNING + // This registry doesn't supply a vendor but inherits one; no warning + override val issues = listOf( + MyJavaLintDetector.ISSUE, + MyKotlinLintDetector.Companion.ISSUE + ) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/MyKotlinLintDetectorTest.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +// Copyright (C) 2021 The Android Open Source Project +package test.pkg +import com.android.tools.lint.checks.infrastructure.LintDetectorTest +import com.android.tools.lint.detector.api.Detector +class MyKotlinLintDetectorTest : LintDetectorTest() { + override fun getDetector(): Detector { + return MyKotlinLintDetector() + } + + fun testBasic() { + val expected = """ + src/test/pkg/AlarmTest.java:9: Warning: Value will be forced up to 5000 as of Android 5.1; don't rely on this to be exact [ShortAlarm] + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 50, 10, null); // ERROR + ~~ + 0 errors, 1 warnings + """ + + lint().files( + kotlin( + """ + fun test() { + println("Value=${"$"}") + } + """ + ), + java( + "src/test/pkg/AlarmTest.java", + """ + package test.pkg; + + import android.app.AlarmManager; + @SuppressWarnings("ClassNameDiffersFromFileName") + public class AlarmTest { + public void test(AlarmManager alarmManager) { + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 5000, 60000, null); // OK + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 6000, 70000, null); // OK + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 50, 10, null); // ERROR + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 5000, // ERROR + OtherClass.MY_INTERVAL, null); // ERROR + } + + private static class OtherClass { + public static final long MY_INTERVAL = 1000L; + } + } + """.trimIndent() + ) + ).run().expect(expected) + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/LintDetectorDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/LintImplUseKotlin.md.html b/docs/checks/LintImplUseKotlin.md.html index fd3eaa1d..07d0cdbd 100644 --- a/docs/checks/LintImplUseKotlin.md.html +++ b/docs/checks/LintImplUseKotlin.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 4.1.0 (October 2020) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/LintDetectorDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/LintDetectorDetectorTest.kt) -Copyright Year -: 2020 New lint checks should be written in Kotlin; the Lint API is written in Kotlin and uses a number of language features that makes it beneficial @@ -43,14 +43,11 @@ src/test/pkg/MyJavaLintDetector.java:24:Warning: New lint checks should be implemented in Kotlin to take advantage of a lot of Kotlin-specific mechanisms in the Lint API [LintImplUseKotlin] - public class MyJavaLintDetector extends Detector { ------------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `src/test/pkg/MyJavaLintDetector.java`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers @@ -136,6 +133,201 @@ } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/test/pkg/MyKotlinLintDetector.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +/* Copyright (C) 2020 The Android Open Source Project */ +package test.pkg +import com.intellij.psi.PsiCallExpression +import com.intellij.psi.PsiExpression +import com.intellij.psi.PsiField +import com.intellij.psi.PsiMethod +import com.intellij.psi.util.PsiTreeUtil +import com.android.tools.lint.detector.api.Category +import com.android.tools.lint.detector.api.Detector +import com.android.tools.lint.detector.api.Implementation +import com.android.tools.lint.detector.api.Issue +import com.android.tools.lint.detector.api.JavaContext +import com.android.tools.lint.detector.api.Scope +import com.android.tools.lint.detector.api.Severity +import org.jetbrains.uast.UCallExpression + +class MyKotlinLintDetector : Detector() { + fun testGetBody(method: PsiMethod) { + val body = method.body // ERROR - must use UAST + } + @Suppress("ReplaceCallWithBinaryOperator","ControlFlowWithEmptyBody") + fun testEquals(element1: PsiCallExpression, element2: PsiExpression) { + if (element1.equals(element2)) { } + if (element2.equals(element1)) { } + if (element1 == element2) { } + if (element1 === element2) { } + if (element1 != element2) { } + if (element1 !== element2) { } + if (element1 == null) { } // OK + if (element1 === null) { } // OK + if (element1 != null) { } // OK + if (element1 !== null) { } // OK + } + @Suppress("UsePropertyAccessSyntax") + fun testGetInitializer(field: PsiField) { + field.getInitializer() // ERROR - must use UAST + field.initializer // ERROR - must use UAST + } + fun testParents(field: PsiField) { + val parent = field.parent + val method = PsiTreeUtil.getParentOfType(field, PsiMethod::class.java) + } + + fun testReport(context: JavaContext, node: UCallExpression) { + context.report(ISSUE, node, context.getLocation(node), + """ + |Instead you should call foo().bar().baz() here. + |""".trimIndent()) + } + + companion object { + private val IMPLEMENTATION = + Implementation( + MyKotlinLintDetector::class.java, + Scope.JAVA_FILE_SCOPE + ) + + val ISSUE = + Issue.create( + id = "badlyCapitalized id", + briefDescription = "checks MyLintDetector.", + explanation = """ + Some description here. + Here's a call: foo.bar.baz(args). + This line continuation is okay. \ + But this one is missing a space.\ + Okay? + """.trimIndent(), + category = Category.INTEROPERABILITY_KOTLIN, + moreInfo = "https://code.google.com/p/android/issues/detail?id=65351", // OBSOLETE + priority = 4, + severity = Severity.WARNING, + implementation = IMPLEMENTATION + ) + .addMoreInfo("https://issuetracker.google.com/issues/3733548") // ERROR - missing digit + .addMoreInfo("https://issuetracker.google.com/issues/373354878") // OK - including digit + .addMoreInfo("http://issuetracker.google.com/issues/37335487") // ERROR - http instead of https + .addMoreInfo("https://b.corp.google.com/issues/139153781") // ERROR - don't point to buganizer with internal link + .addMoreInfo("https://goo.gle/policy-storage-help") // OK - regression test for goo.gle + } + + override fun visitAnnotationUsage( + context: JavaContext, + element: org.jetbrains.uast.UElement.UElement, + annotationInfo: com.android.tools.lint.detector.api.AnnotationInfo, + usageInfo: com.android.tools.lint.detector.api.AnnotationUsageInfo + ) { + // Invalid recursion! + super.visitAnnotationUsage(context, element, annotationInfo, usageInfo) + } + + fun misc() { + System.out.print("Debugging") + println("Debugging code") + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/MyIssueRegistry.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg +import com.android.tools.lint.client.api.IssueRegistry +class MyIssueRegistry : IssueRegistry() { + override val issues = listOf( + MyJavaLintDetector.ISSUE, + MyKotlinLintDetector.Companion.ISSUE + ) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/MyVendorIssueRegistry.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg +import com.android.tools.lint.client.api.IssueRegistry +import com.android.tools.lint.client.api.Vendor +class MyVendorIssueRegistry : IssueRegistry() { + // Supplies a vendor: no warning + override var vendor: Vendor? = Vendor("Unit test") + override val issues = listOf( + MyJavaLintDetector.ISSUE, + MyKotlinLintDetector.Companion.ISSUE + ) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/InheritingRegistry.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg +import com.android.tools.lint.client.api.IssueRegistry +import com.android.tools.lint.client.api.Vendor +class InheritingRegistry : MyVendorIssueRegistry() { // NO WARNING + // This registry doesn't supply a vendor but inherits one; no warning + override val issues = listOf( + MyJavaLintDetector.ISSUE, + MyKotlinLintDetector.Companion.ISSUE + ) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/MyKotlinLintDetectorTest.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +// Copyright (C) 2021 The Android Open Source Project +package test.pkg +import com.android.tools.lint.checks.infrastructure.LintDetectorTest +import com.android.tools.lint.detector.api.Detector +class MyKotlinLintDetectorTest : LintDetectorTest() { + override fun getDetector(): Detector { + return MyKotlinLintDetector() + } + + fun testBasic() { + val expected = """ + src/test/pkg/AlarmTest.java:9: Warning: Value will be forced up to 5000 as of Android 5.1; don't rely on this to be exact [ShortAlarm] + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 50, 10, null); // ERROR + ~~ + 0 errors, 1 warnings + """ + + lint().files( + kotlin( + """ + fun test() { + println("Value=${"$"}") + } + """ + ), + java( + "src/test/pkg/AlarmTest.java", + """ + package test.pkg; + + import android.app.AlarmManager; + @SuppressWarnings("ClassNameDiffersFromFileName") + public class AlarmTest { + public void test(AlarmManager alarmManager) { + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 5000, 60000, null); // OK + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 6000, 70000, null); // OK + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 50, 10, null); // ERROR + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 5000, // ERROR + OtherClass.MY_INTERVAL, null); // ERROR + } + + private static class OtherClass { + public static final long MY_INTERVAL = 1000L; + } + } + """.trimIndent() + ) + ).run().expect(expected) + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/LintDetectorDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/LintImplUseUast.md.html b/docs/checks/LintImplUseUast.md.html index 8478a344..47478f5c 100644 --- a/docs/checks/LintImplUseUast.md.html +++ b/docs/checks/LintImplUseUast.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 4.1.0 (October 2020) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/LintDetectorDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/LintDetectorDetectorTest.kt) -Copyright Year -: 2020 UAST is a library that sits on top of PSI, and in many cases PSI is part of the UAST API; for example, UResolvable#resolve returns a PsiElement. @@ -50,54 +50,41 @@ src/test/pkg/MyJavaLintDetector.java:39:Error: Don't call PsiMethod#getBody(); you must use UAST instead. If you don't have a UMethod call UastFacade.getMethodBody(method) [LintImplUseUast] - method.getBody(); // ERROR - must use UAST ---------------- - - +src/test/pkg/MyJavaLintDetector.java:42:Error: Don't call +PsiMethod#getBody(); you must use UAST instead. If you don't have a +UMethod call UastFacade.getMethodBody(method) [LintImplUseUast] + method.getBody(); // ERROR - must use UAST + ---------------- src/test/pkg/MyJavaLintDetector.java:45:Error: Don't call PsiMember#getContainingClass(); you should use UAST instead and call getContainingUClass() [LintImplUseUast] - method.getContainingClass(); // ERROR - must use UAST --------------------------- - - src/test/pkg/MyJavaLintDetector.java:46:Error: Don't call PsiMember#getContainingClass(); you should use UAST instead and call getContainingUClass() [LintImplUseUast] - field.getContainingClass(); // ERROR - must use UAST -------------------------- - - src/test/pkg/MyJavaLintDetector.java:59:Error: Don't call PsiField#getInitializer(); you must use UAST instead. If you don't have a UField call UastFacade.getInitializerBody(field) [LintImplUseUast] - field.getInitializer(); // ERROR - must use UAST ---------------------- - - src/test/pkg/MyJavaLintDetector.java:63:Error: Don't call PsiElement#getParent(); you should use UAST instead and call getUastParent() [LintImplUseUast] - PsiElement parent = method.getParent(); // ERROR ------------------ - - src/test/pkg/MyJavaLintDetector.java:65:Error: Don't call PsiTreeUtil#getParentOfType(); you should use UAST instead and call UElement.parentOfType [LintImplUseUast] - PsiTreeUtil.getParentOfType(method, PsiClass.class); // ERROR --------------------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `src/test/pkg/MyJavaLintDetector.java`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers @@ -183,6 +170,201 @@ } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/test/pkg/MyKotlinLintDetector.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +/* Copyright (C) 2020 The Android Open Source Project */ +package test.pkg +import com.intellij.psi.PsiCallExpression +import com.intellij.psi.PsiExpression +import com.intellij.psi.PsiField +import com.intellij.psi.PsiMethod +import com.intellij.psi.util.PsiTreeUtil +import com.android.tools.lint.detector.api.Category +import com.android.tools.lint.detector.api.Detector +import com.android.tools.lint.detector.api.Implementation +import com.android.tools.lint.detector.api.Issue +import com.android.tools.lint.detector.api.JavaContext +import com.android.tools.lint.detector.api.Scope +import com.android.tools.lint.detector.api.Severity +import org.jetbrains.uast.UCallExpression + +class MyKotlinLintDetector : Detector() { + fun testGetBody(method: PsiMethod) { + val body = method.body // ERROR - must use UAST + } + @Suppress("ReplaceCallWithBinaryOperator","ControlFlowWithEmptyBody") + fun testEquals(element1: PsiCallExpression, element2: PsiExpression) { + if (element1.equals(element2)) { } + if (element2.equals(element1)) { } + if (element1 == element2) { } + if (element1 === element2) { } + if (element1 != element2) { } + if (element1 !== element2) { } + if (element1 == null) { } // OK + if (element1 === null) { } // OK + if (element1 != null) { } // OK + if (element1 !== null) { } // OK + } + @Suppress("UsePropertyAccessSyntax") + fun testGetInitializer(field: PsiField) { + field.getInitializer() // ERROR - must use UAST + field.initializer // ERROR - must use UAST + } + fun testParents(field: PsiField) { + val parent = field.parent + val method = PsiTreeUtil.getParentOfType(field, PsiMethod::class.java) + } + + fun testReport(context: JavaContext, node: UCallExpression) { + context.report(ISSUE, node, context.getLocation(node), + """ + |Instead you should call foo().bar().baz() here. + |""".trimIndent()) + } + + companion object { + private val IMPLEMENTATION = + Implementation( + MyKotlinLintDetector::class.java, + Scope.JAVA_FILE_SCOPE + ) + + val ISSUE = + Issue.create( + id = "badlyCapitalized id", + briefDescription = "checks MyLintDetector.", + explanation = """ + Some description here. + Here's a call: foo.bar.baz(args). + This line continuation is okay. \ + But this one is missing a space.\ + Okay? + """.trimIndent(), + category = Category.INTEROPERABILITY_KOTLIN, + moreInfo = "https://code.google.com/p/android/issues/detail?id=65351", // OBSOLETE + priority = 4, + severity = Severity.WARNING, + implementation = IMPLEMENTATION + ) + .addMoreInfo("https://issuetracker.google.com/issues/3733548") // ERROR - missing digit + .addMoreInfo("https://issuetracker.google.com/issues/373354878") // OK - including digit + .addMoreInfo("http://issuetracker.google.com/issues/37335487") // ERROR - http instead of https + .addMoreInfo("https://b.corp.google.com/issues/139153781") // ERROR - don't point to buganizer with internal link + .addMoreInfo("https://goo.gle/policy-storage-help") // OK - regression test for goo.gle + } + + override fun visitAnnotationUsage( + context: JavaContext, + element: org.jetbrains.uast.UElement.UElement, + annotationInfo: com.android.tools.lint.detector.api.AnnotationInfo, + usageInfo: com.android.tools.lint.detector.api.AnnotationUsageInfo + ) { + // Invalid recursion! + super.visitAnnotationUsage(context, element, annotationInfo, usageInfo) + } + + fun misc() { + System.out.print("Debugging") + println("Debugging code") + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/MyIssueRegistry.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg +import com.android.tools.lint.client.api.IssueRegistry +class MyIssueRegistry : IssueRegistry() { + override val issues = listOf( + MyJavaLintDetector.ISSUE, + MyKotlinLintDetector.Companion.ISSUE + ) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/MyVendorIssueRegistry.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg +import com.android.tools.lint.client.api.IssueRegistry +import com.android.tools.lint.client.api.Vendor +class MyVendorIssueRegistry : IssueRegistry() { + // Supplies a vendor: no warning + override var vendor: Vendor? = Vendor("Unit test") + override val issues = listOf( + MyJavaLintDetector.ISSUE, + MyKotlinLintDetector.Companion.ISSUE + ) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/InheritingRegistry.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg +import com.android.tools.lint.client.api.IssueRegistry +import com.android.tools.lint.client.api.Vendor +class InheritingRegistry : MyVendorIssueRegistry() { // NO WARNING + // This registry doesn't supply a vendor but inherits one; no warning + override val issues = listOf( + MyJavaLintDetector.ISSUE, + MyKotlinLintDetector.Companion.ISSUE + ) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/MyKotlinLintDetectorTest.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +// Copyright (C) 2021 The Android Open Source Project +package test.pkg +import com.android.tools.lint.checks.infrastructure.LintDetectorTest +import com.android.tools.lint.detector.api.Detector +class MyKotlinLintDetectorTest : LintDetectorTest() { + override fun getDetector(): Detector { + return MyKotlinLintDetector() + } + + fun testBasic() { + val expected = """ + src/test/pkg/AlarmTest.java:9: Warning: Value will be forced up to 5000 as of Android 5.1; don't rely on this to be exact [ShortAlarm] + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 50, 10, null); // ERROR + ~~ + 0 errors, 1 warnings + """ + + lint().files( + kotlin( + """ + fun test() { + println("Value=${"$"}") + } + """ + ), + java( + "src/test/pkg/AlarmTest.java", + """ + package test.pkg; + + import android.app.AlarmManager; + @SuppressWarnings("ClassNameDiffersFromFileName") + public class AlarmTest { + public void test(AlarmManager alarmManager) { + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 5000, 60000, null); // OK + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 6000, 70000, null); // OK + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 50, 10, null); // ERROR + alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 5000, // ERROR + OtherClass.MY_INTERVAL, null); // ERROR + } + + private static class OtherClass { + public static final long MY_INTERVAL = 1000L; + } + } + """.trimIndent() + ) + ).run().expect(expected) + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/LintDetectorDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/LocalContextConfigurationRead.md.html b/docs/checks/LocalContextConfigurationRead.md.html new file mode 100644 index 00000000..a468bf2e --- /dev/null +++ b/docs/checks/LocalContextConfigurationRead.md.html @@ -0,0 +1,194 @@ + +(#) Reading Configuration using LocalContext.current.resources.configuration + +!!! ERROR: Reading Configuration using LocalContext.current.resources.configuration + This is an error. + +Id +: `LocalContextConfigurationRead` +Summary +: Reading Configuration using LocalContext.current.resources.configuration +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: Jetpack Compose +Identifier +: androidx.compose.ui +Feedback +: https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.ui:ui-android](androidx_compose_ui_ui-android.md.html) +Since +: 1.8.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/ui/ui-lint/src/main/java/androidx/compose/ui/lint/LocalContextResourcesConfigurationReadDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/ui/ui-lint/src/test/java/androidx/compose/ui/lint/LocalContextResourcesConfigurationReadDetectorTest.kt) +Copyright Year +: 2024 + +Changes to the Configuration object will not cause LocalContext reads to +be invalidated, so you may end up with stale values when the +Configuration changes. Instead, use LocalConfiguration.current to +retrieve the Configuration - this will recompose callers when the +Configuration object changes. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test/test.kt:11:Error: Reading Configuration using +LocalContext.current.resources.configuration +[LocalContextConfigurationRead] + LocalContext.current.resources.configuration + -------------------------------------------- +src/test/test.kt:12:Error: Reading Configuration using +LocalContext.current.resources.configuration +[LocalContextConfigurationRead] + LocalContext.current.getResources().getConfiguration() + ------------------------------------------------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test + +import androidx.compose.runtime.Composable +import androidx.compose.ui.platform.LocalContext + +@Composable +fun Test() { + LocalContext.current.resources + LocalContext.current.getResources() + LocalContext.current.resources.configuration + LocalContext.current.getResources().getConfiguration() +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/ui/ui-lint/src/test/java/androidx/compose/ui/lint/LocalContextResourcesConfigurationReadDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `LocalContextResourcesConfigurationReadDetector.error`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=612128. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.ui:ui-android:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.ui:ui-android:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.ui.android) + +# libs.versions.toml +[versions] +ui-android = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +ui-android = { + module = "androidx.compose.ui:ui-android", + version.ref = "ui-android" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.ui:ui-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.ui:ui-android](androidx_compose_ui_ui-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("LocalContextConfigurationRead") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("LocalContextConfigurationRead") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection LocalContextConfigurationRead + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="LocalContextConfigurationRead" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'LocalContextConfigurationRead' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore LocalContextConfigurationRead ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ComposableModifierFactory.md.html b/docs/checks/LocalContextResourcesRead.md.html similarity index 51% rename from docs/checks/ComposableModifierFactory.md.html rename to docs/checks/LocalContextResourcesRead.md.html index 450c8222..50fd1fe5 100644 --- a/docs/checks/ComposableModifierFactory.md.html +++ b/docs/checks/LocalContextResourcesRead.md.html @@ -1,13 +1,13 @@ -(#) Modifier factory functions should not be @Composable +(#) Reading Resources using LocalContext.current.resources -!!! WARNING: Modifier factory functions should not be @Composable +!!! WARNING: Reading Resources using LocalContext.current.resources This is a warning. Id -: `ComposableModifierFactory` +: `LocalContextResourcesRead` Summary -: Modifier factory functions should not be @Composable +: Reading Resources using LocalContext.current.resources Severity : Warning Category @@ -20,105 +20,111 @@ : androidx.compose.ui Feedback : https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.ui:ui-android](androidx_compose_ui_ui-android.md.html) +Since +: 1.9.0-alpha01 Affects : Kotlin and Java files and test sources Editing : This check runs on the fly in the IDE editor Implementation -: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/ui/ui-lint/src/main/java/androidx/compose/ui/lint/ModifierDeclarationDetector.kt) +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/ui/ui-lint/src/main/java/androidx/compose/ui/lint/LocalContextResourcesConfigurationReadDetector.kt) Tests -: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/ui/ui-lint/src/test/java/androidx/compose/ui/lint/ModifierDeclarationDetectorTest.kt) +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/ui/ui-lint/src/test/java/androidx/compose/ui/lint/LocalContextResourcesConfigurationReadDetectorTest.kt) Copyright Year -: 2020 +: 2024 -Modifier factory functions that need to be aware of the composition -should use androidx.compose.ui.composed {} in their implementation -instead of being marked as @Composable. This allows Modifiers to be -referenced in top level variables and constructed outside of the -composition. +Changes to the Configuration object will not cause +LocalContext.current.resources reads to be invalidated, so calls to APIs +suchas Resources.getString() will not be updated when the Configuration +changes. Instead, use LocalResources.current to retrieve the Resources - +this will invalidate callers when the Configuration changes, to ensure +that these calls reflect the latest values. (##) Example Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -src/androidx/compose/ui/foo/TestModifier.kt:13:Warning: Modifier factory -functions should not be marked as @Composable, and should use composed -instead [ComposableModifierFactory] - - fun Modifier.fooModifier1(): Modifier { - ------------ - - -src/androidx/compose/ui/foo/TestModifier.kt:19:Warning: Modifier factory -functions should not be marked as @Composable, and should use composed -instead [ComposableModifierFactory] - - fun Modifier.fooModifier2(): Modifier = - ------------ - - -src/androidx/compose/ui/foo/TestModifier.kt:23:Warning: Modifier factory -functions should not be marked as @Composable, and should use composed -instead [ComposableModifierFactory] - - val Modifier.fooModifier3: Modifier get() { - ------------ - - -src/androidx/compose/ui/foo/TestModifier.kt:29:Warning: Modifier factory -functions should not be marked as @Composable, and should use composed -instead [ComposableModifierFactory] - - val Modifier.fooModifier4: Modifier get() = - ------------ - - +src/test/test.kt:9:Warning: Reading Resources using +LocalContext.current.resources [LocalContextResourcesRead] + LocalContext.current.resources + ------------------------------ +src/test/test.kt:10:Warning: Reading Resources using +LocalContext.current.resources [LocalContextResourcesRead] + LocalContext.current.getResources() + ----------------------------------- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: -`src/androidx/compose/ui/foo/TestModifier.kt`: +`src/test/test.kt`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers -package androidx.compose.ui.foo +package test import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier - -class TestModifier(val value: Int) : Modifier.Element +import androidx.compose.ui.platform.LocalContext @Composable -fun someComposableCall(int: Int) = 5 - -@Composable -fun Modifier.fooModifier1(): Modifier { - val value = someComposableCall(3) - return this.then(TestModifier(value)) -} - -@Composable -fun Modifier.fooModifier2(): Modifier = - this.then(TestModifier(someComposableCall(3))) - -@get:Composable -val Modifier.fooModifier3: Modifier get() { - val value = someComposableCall(3) - return this.then(TestModifier(value)) +fun Test() { + LocalContext.current.resources + LocalContext.current.getResources() + LocalContext.current.resources.configuration + LocalContext.current.getResources().getConfiguration() } - -@get:Composable -val Modifier.fooModifier4: Modifier get() = - this.then(TestModifier(someComposableCall(3))) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can also visit the -[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/ui/ui-lint/src/test/java/androidx/compose/ui/lint/ModifierDeclarationDetectorTest.kt) +[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/ui/ui-lint/src/test/java/androidx/compose/ui/lint/LocalContextResourcesConfigurationReadDetectorTest.kt) for the unit tests for this check to see additional scenarios. The above example was automatically extracted from the first unit test -found for this lint check, `ModifierDeclarationDetector.composableModifierFactories`. +found for this lint check, `LocalContextResourcesConfigurationReadDetector.error`. To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=612128. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.ui:ui-android:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.ui:ui-android:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.ui.android) + +# libs.versions.toml +[versions] +ui-android = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +ui-android = { + module = "androidx.compose.ui:ui-android", + version.ref = "ui-android" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.ui:ui-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.ui:ui-android](androidx_compose_ui_ui-android.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: @@ -128,7 +134,7 @@ ```kt // Kotlin - @Suppress("ComposableModifierFactory") + @Suppress("LocalContextResourcesRead") fun method() { problematicStatement() } @@ -138,7 +144,7 @@ ```java // Java - @SuppressWarnings("ComposableModifierFactory") + @SuppressWarnings("LocalContextResourcesRead") void method() { problematicStatement(); } @@ -147,7 +153,7 @@ * Using a suppression comment like this on the line above: ```kt - //noinspection ComposableModifierFactory + //noinspection LocalContextResourcesRead problematicStatement() ``` @@ -157,7 +163,7 @@ ```xml <?xml version="1.0" encoding="UTF-8"?> <lint> - <issue id="ComposableModifierFactory" severity="ignore" /> + <issue id="LocalContextResourcesRead" severity="ignore" /> </lint> ``` Instead of `ignore` you can also change the severity here, for @@ -170,7 +176,7 @@ example, you can use something like ```gradle lintOptions { - disable 'ComposableModifierFactory' + disable 'LocalContextResourcesRead' } ``` In Android projects this should be nested inside an `android { }` @@ -178,7 +184,7 @@ * For manual invocations of `lint`, using the `--ignore` flag: ``` - $ lint --ignore ComposableModifierFactory ...` + $ lint --ignore LocalContextResourcesRead ...` ``` * Last, but not least, using baselines, as discussed diff --git a/docs/checks/LocalSuppress.md.html b/docs/checks/LocalSuppress.md.html index 6f12a498..d89c4b50 100644 --- a/docs/checks/LocalSuppress.md.html +++ b/docs/checks/LocalSuppress.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files Editing @@ -45,51 +47,33 @@ src/test/pkg/WrongAnnotation.java:10:Error: The @SuppressLint annotation cannot be used on a local variable with the lint check 'NewApi': move out to the surrounding method [LocalSuppress] - public static void foobar(View view, @SuppressLint("NewApi") int foo) { // $ Invalid: class-file check ----------------------- - - src/test/pkg/WrongAnnotation.java:11:Error: The @SuppressLint annotation cannot be used on a local variable with the lint check 'NewApi': move out to the surrounding method [LocalSuppress] - @SuppressLint("NewApi") // Invalid ----------------------- - - src/test/pkg/WrongAnnotation.java:13:Error: The @SuppressLint annotation cannot be used on a local variable with the lint check 'NewApi': move out to the surrounding method [LocalSuppress] - @SuppressLint({"SdCardPath", "NewApi"}) // Invalid: class-file based check on local variable --------------------------------------- - - src/test/pkg/WrongAnnotation.java:15:Error: The @SuppressLint annotation cannot be used on a local variable with the lint check 'NewApi': move out to the surrounding method [LocalSuppress] - @android.annotation.SuppressLint({"SdCardPath", "NewApi"}) // Invalid (FQN) ---------------------------------------------------------- - - src/test/pkg/WrongAnnotation.java:29:Error: The @SuppressLint annotation cannot be used on a local variable with the lint check 'NewApi': move out to the surrounding method [LocalSuppress] - @SuppressLint("NewApi") ----------------------- - - src/test/pkg/WrongAnnotation.java:34:Error: The @SuppressLint annotation cannot be used on a local variable with the lint check 'NewApi': move out to the surrounding method [LocalSuppress] - @SuppressLint("NewApi") // Invalid ----------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/LocaleFolder.md.html b/docs/checks/LocaleFolder.md.html index 63416342..9d42a4b7 100644 --- a/docs/checks/LocaleFolder.md.html +++ b/docs/checks/LocaleFolder.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource folders Editing @@ -52,16 +54,38 @@ res/values-he/strings.xml:Warning: The locale folder "he" should be called "iw" instead; see the java.util.Locale documentation [LocaleFolder] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Here are the relevant source files: - +`res/values/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<resources> +</resources> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +`res/values-no/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<resources> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `res/values-he/strings.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers -<resources></resources> +<resources> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/values-id/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<resources> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/values-yi/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<resources> +</resources> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can also visit the diff --git a/docs/checks/LockedOrientationActivity.md.html b/docs/checks/LockedOrientationActivity.md.html index d9808ca5..81111c30 100644 --- a/docs/checks/LockedOrientationActivity.md.html +++ b/docs/checks/LockedOrientationActivity.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.6.0 (February 2020) Affects : Manifest files Editing @@ -28,14 +30,12 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ChromeOsDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ChromeOsDetectorTest.java) -Copyright Year -: 2016 The `` element should not be locked to any orientation so that users can take advantage of the multi-window environments and larger screens available on Android. To fix the issue, consider declaring the corresponding activity element with `screenOrientation="unspecified"`or -`"fullSensor"` attribute. +`fullSensor` attribute. !!! Tip This lint check has an associated quickfix available in the IDE. @@ -49,11 +49,8 @@ activity so the user can use the application in any orientation and provide a great experience on Chrome OS devices [LockedOrientationActivity] - <activity android:name=".MainActivity" android:screenOrientation="portrait"/> ------------------------------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/LogConditional.md.html b/docs/checks/LogConditional.md.html index e09d373b..1a09b6e7 100644 --- a/docs/checks/LogConditional.md.html +++ b/docs/checks/LogConditional.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 1.1.0 (February 2015) Affects : Kotlin and Java files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/LogDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/LogDetectorTest.kt) -Copyright Year -: 2015 The `BuildConfig` class provides a constant, `DEBUG`, which indicates whether the code is being built in release mode or in debug mode. In @@ -49,11 +49,8 @@ src/LogExample.kt:7:Warning: The log call Log.i(...) should be conditional: surround with if (Log.isLoggable(...)) or if (BuildConfig.DEBUG) { ... } [LogConditional] - Log.i(TAG, "message" + m) // string is not constant; computed each time ------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/LogNotTimber.md.html b/docs/checks/LogNotTimber.md.html new file mode 100644 index 00000000..3251ab3d --- /dev/null +++ b/docs/checks/LogNotTimber.md.html @@ -0,0 +1,189 @@ + +(#) Logging call to Log instead of Timber + +!!! WARNING: Logging call to Log instead of Timber + This is a warning. + +Id +: `LogNotTimber` +Summary +: Logging call to Log instead of Timber +Severity +: Warning +Category +: Correctness: Messages +Platform +: Any +Vendor +: JakeWharton/timber +Identifier +: com.jakewharton.timber:timber:{version} +Feedback +: https://github.com/JakeWharton/timber/issues +Min +: Lint 4.0 +Compiled +: Lint 7.0 +Artifact +: [com.jakewharton.timber:timber](com_jakewharton_timber_timber.md.html) +Since +: 4.6.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/JakeWharton/timber/tree/trunk/timber-lint/src/main/java/timber/lint/WrongTimberUsageDetector.kt) +Tests +: [Source Code](https://github.com/JakeWharton/timber/tree/trunk/timber-lint/src/test/java/timber/lint/WrongTimberUsageDetectorTest.kt) + +Since Timber is included in the project, it is likely that calls to Log +should instead be going to Timber. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/Example.java:5:Warning: Using 'Log' instead of 'Timber' +[LogNotTimber] + Log.d("TAG", "msg"); + ------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`src/foo/Example.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package foo; +import android.util.Log; +public class Example { + public void log() { + Log.d("TAG", "msg"); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/foo/Example.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package foo +import android.util.Log +class Example { + fun log() { + Log.d("TAG", "msg") + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/JakeWharton/timber/tree/trunk/timber-lint/src/test/java/timber/lint/WrongTimberUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `WrongTimberUsageDetector.usingAndroidLogWithTwoArguments`. +To report a problem with this extracted sample, visit +https://github.com/JakeWharton/timber/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +implementation("com.jakewharton.timber:timber:5.0.1") + +// build.gradle +implementation 'com.jakewharton.timber:timber:5.0.1' + +// build.gradle.kts with version catalogs: +implementation(libs.timber) + +# libs.versions.toml +[versions] +timber = "5.0.1" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +timber = { + module = "com.jakewharton.timber:timber", + version.ref = "timber" +} +``` + +5.0.1 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.jakewharton.timber:timber](com_jakewharton_timber_timber.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("LogNotTimber") + fun method() { + tag(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("LogNotTimber") + void method() { + tag(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection LogNotTimber + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="LogNotTimber" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'LogNotTimber' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore LogNotTimber ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/LogTagMismatch.md.html b/docs/checks/LogTagMismatch.md.html index 3bdd3973..333d0829 100644 --- a/docs/checks/LogTagMismatch.md.html +++ b/docs/checks/LogTagMismatch.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 1.1.0 (February 2015) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/LogDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/LogDetectorTest.kt) -Copyright Year -: 2015 When guarding a `Log.v(tag, ...)` call with `Log.isLoggable(tag)`, the tag passed to both calls should be the same. Similarly, the level passed @@ -42,11 +42,8 @@ src/LogExample.kt:9:Error: Mismatched tags: the d() and isLoggable() calls typically should pass the same tag: TAG1 versus TAG2 [LogTagMismatch] - Log.d(TAG2, "message") // warn: mismatched tags - TAG1 and TAG2 ---- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/LongLogTag.md.html b/docs/checks/LongLogTag.md.html index e23d646f..cef6216d 100644 --- a/docs/checks/LongLogTag.md.html +++ b/docs/checks/LongLogTag.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 1.1.0 (February 2015) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/LogDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/LogDetectorTest.kt) -Copyright Year -: 2015 Log tags are only allowed to be at most 23 tag characters long. @@ -38,11 +38,8 @@ src/pkg1/pkg2/pkg3/pkg4/pkg5/LogExampleInLongClassName.kt:9:Error: The logging tag can be at most 23 characters, was 35 (SuperSuperLongLogTagWhichExceedsMax) [LongLogTag] - Log.d(TAG, "message") --- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/MainScopeUsage.md.html b/docs/checks/MainScopeUsage.md.html new file mode 100644 index 00000000..8b04087c --- /dev/null +++ b/docs/checks/MainScopeUsage.md.html @@ -0,0 +1,182 @@ + +(#) Use slack.foundation.coroutines.android.MainScope + +!!! ERROR: Use slack.foundation.coroutines.android.MainScope + This is an error. + +Id +: `MainScopeUsage` +Summary +: Use slack.foundation.coroutines.android.MainScope +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MainScopeUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MainScopeUsageDetectorTest.kt) +Copyright Year +: 2021 + +Prefer using Slack's internal `MainScope` function, which supports +`SlackDispatchers` and uses Dispatchers.Main.immediate under the hood. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test/pkg/test.kt:6:Error: Use +slack.foundation.coroutines.android.MainScope. [MainScopeUsage] + val scope = MainScope() + ----------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test/pkg/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg + +import kotlinx.coroutines.MainScope + +fun example() { + val scope = MainScope() +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MainScopeUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MainScopeUsageDetector.simple`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MainScopeUsage") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MainScopeUsage") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MainScopeUsage + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MainScopeUsage" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MainScopeUsage' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MainScopeUsage ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MangledCRLF.md.html b/docs/checks/MangledCRLF.md.html index cc1a7ffc..ce6cd6ac 100644 --- a/docs/checks/MangledCRLF.md.html +++ b/docs/checks/MangledCRLF.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -47,19 +49,13 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/crcrlf.xml:4:Error: Incorrect line ending: found carriage return (\r) without corresponding newline (\n) [MangledCRLF] - android:layout_height="match_parent" > ^ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: -`res/layout/crcrlf.xml`: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers -PFJlbGF0aXZlTGF5b3V0IHhtbG5zOmFuZHJvaWQ9Imh0dHA6Ly9zY2hlbWFzLmFuZHJvaWQuY29tL2Fway9yZXMvYW5kcm9pZCINCiAgICB4bWxuczp0b29scz0iaHR0cDovL3NjaGVtYXMuYW5kcm9pZC5jb20vdG9vbHMiDQogICAgYW5kcm9pZDpsYXlvdXRfd2lkdGg9Im1hdGNoX3BhcmVudCINCiAgICBhbmRyb2lkOmxheW91dF9oZWlnaHQ9Im1hdGNoX3BhcmVudCIgPg0KDQ0KICAgIDxUZXh0Vmlldw0KICAgICAgICBhbmRyb2lkOmxheW91dF93aWR0aD0id3JhcF9jb250ZW50Ig0KICAgICAgICBhbmRyb2lkOmxheW91dF9oZWlnaHQ9IndyYXBfY29udGVudCINCiAgICAgICAgYW5kcm9pZDpsYXlvdXRfY2VudGVySG9yaXpvbnRhbD0idHJ1ZSINCiAgICAgICAgYW5kcm9pZDpsYXlvdXRfY2VudGVyVmVydGljYWw9InRydWUiDQogICAgICAgIGFuZHJvaWQ6dGV4dD0iSGVsbG8iDQogICAgICAgIHRvb2xzOmNvbnRleHQ9Ii5NYWluQWN0aXZpdHkiIC8+DQoNCjwvUmVsYXRpdmVMYXlvdXQ+DQo= -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +[res/layout/crcrlf.xml](examples/layout/crcrlf.xml) You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/DosLineEndingDetectorTest.kt) diff --git a/docs/checks/ManifestOrder.md.html b/docs/checks/ManifestOrder.md.html index 79764c10..6198da3e 100644 --- a/docs/checks/ManifestOrder.md.html +++ b/docs/checks/ManifestOrder.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Manifest files Editing @@ -42,14 +44,11 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text AndroidManifest.xml:15:Warning: tag appears after tag [ManifestOrder] - <uses-sdk android:minSdkVersion="Froyo" /> -------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `AndroidManifest.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -72,6 +71,40 @@ </manifest> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/values/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<!-- Copyright (C) 2007 The Android Open Source Project + + 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. +--> + +<resources> + <!-- Home --> + <string name="home_title">Home Sample</string> + <string name="show_all_apps">All</string> + + <!-- Home Menus --> + <string name="menu_wallpaper">Wallpaper</string> + <string name="menu_search">Search</string> + <string name="menu_settings">Settings</string> + <string name="sample" translatable="false">Ignore Me</string> + + <!-- Wallpaper --> + <string name="wallpaper_instructions">Tap picture to set portrait wallpaper</string> +</resources> + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ManifestDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/ManifestResource.md.html b/docs/checks/ManifestResource.md.html index 6d5f1e31..511ecd33 100644 --- a/docs/checks/ManifestResource.md.html +++ b/docs/checks/ManifestResource.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 1.5.0 (November 2015) Affects : Manifest files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ManifestResourceDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ManifestResourceDetectorTest.kt) -Copyright Year -: 2015 Elements in the manifest can reference resources, but those resources cannot vary across configurations (except as a special case, by version, @@ -43,30 +43,21 @@ AndroidManifest.xml:6:Error: Resources referenced from the manifest cannot vary by configuration (except for version qualifiers, e.g. -v21). Found variation in mcc [ManifestResource] - <application android:fullBackupContent="@xml/backup"> ----------- - - AndroidManifest.xml:8:Error: Resources referenced from the manifest cannot vary by configuration (except for version qualifiers, e.g. -v21). Found variation in en-rUS [ManifestResource] - android:process="@string/location_process" ------------------------ - - AndroidManifest.xml:9:Error: Resources referenced from the manifest cannot vary by configuration (except for version qualifiers, e.g. -v21). Found variation in watch-v20 [ManifestResource] - android:enabled="@bool/enable_wearable_location_service"> -------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `AndroidManifest.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -84,6 +75,50 @@ </manifest> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/values/values.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<resources> + <string name="location_process">Location Process</string> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/values/bools.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + <bool name="enable_wearable_location_service">true</bool> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/values-en-rUS/values.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<resources> + <string name="location_process">Location Process (English)</string> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/values-watch/bools.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + <bool name="enable_wearable_location_service">false</bool> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/xml/backup.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<full-backup-content> + <include domain="file" path="dd"/> + <exclude domain="file" path="dd/fo3o.txt"/> + <exclude domain="file" path="dd/ss/foo.txt"/> +</full-backup-content> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/xml-mcc/backup.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<full-backup-content> + <include domain="file" path="mcc"/> +</full-backup-content> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ManifestResourceDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/ManifestTypo.md.html b/docs/checks/ManifestTypo.md.html index 6ab09b36..ccb7e5b8 100644 --- a/docs/checks/ManifestTypo.md.html +++ b/docs/checks/ManifestTypo.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Manifest files Editing @@ -40,14 +42,11 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text AndroidManifest.xml:7:Error: Misspelled tag : Did you mean ? [ManifestTypo] - <use-sdk android:minSdkVersion="14" /> -------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `AndroidManifest.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -81,6 +80,41 @@ </manifest> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/values/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2007 The Android Open Source Project + + 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. +--> + +<resources> + <!-- Home --> + <string name="home_title">Home Sample</string> + <string name="show_all_apps">All</string> + + <!-- Home Menus --> + <string name="menu_wallpaper">Wallpaper</string> + <string name="menu_search">Search</string> + <string name="menu_settings">Settings</string> + <string name="sample" translatable="false">Ignore Me</string> + + <!-- Wallpaper --> + <string name="wallpaper_instructions">Tap picture to set portrait wallpaper</string> +</resources> + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ManifestTypoDetectorTest.java) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/MatchingMenuId.md.html b/docs/checks/MatchingMenuId.md.html new file mode 100644 index 00000000..b8297f04 --- /dev/null +++ b/docs/checks/MatchingMenuId.md.html @@ -0,0 +1,151 @@ + +(#) Flags menu ids that don't match with the file name + +!!! WARNING: Flags menu ids that don't match with the file name + This is a warning. + +Id +: `MatchingMenuId` +Summary +: Flags menu ids that don't match with the file name +Severity +: Warning +Category +: Correctness +Platform +: Android +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html) +Since +: 0.6.0 +Affects +: Resource files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/main/kotlin/com/vanniktech/lintrules/android/MatchingMenuIdDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/MatchingMenuIdDetectorTest.kt) + +When the layout file is named menu_home all of the containing ids should +be prefixed with menuHome to avoid ambiguity between different menu +files across different menu items. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +res/menu/menu_main.xml:2:Warning: Id should start with: menuMain +[MatchingMenuId] + <item android:id="@+id/something"/> + -------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`res/menu/menu_main.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<menu xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:id="@+id/something"/> +</menu> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/MatchingMenuIdDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MatchingMenuIdDetector.idWithoutPrefix`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-android:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-android:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.android) + +# libs.versions.toml +[versions] +lint-rules-android = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-android = { + module = "com.vanniktech:lint-rules-android", + version.ref = "lint-rules-android" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute `tools:ignore="MatchingMenuId"` on + the problematic XML element (or one of its enclosing elements). You + may also need to add the following namespace declaration on the root + element in the XML file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MatchingMenuId" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MatchingMenuId' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MatchingMenuId ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MatchingViewId.md.html b/docs/checks/MatchingViewId.md.html new file mode 100644 index 00000000..dc177b76 --- /dev/null +++ b/docs/checks/MatchingViewId.md.html @@ -0,0 +1,149 @@ + +(#) Flags view ids that don't match with the file name + +!!! WARNING: Flags view ids that don't match with the file name + This is a warning. + +Id +: `MatchingViewId` +Summary +: Flags view ids that don't match with the file name +Severity +: Warning +Category +: Correctness +Platform +: Android +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html) +Since +: 0.6.0 +Affects +: Resource files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/main/kotlin/com/vanniktech/lintrules/android/MatchingViewIdDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/MatchingViewIdDetectorTest.kt) + +When the layout file is named activity_home all of the containing ids +should be prefixed with activityHome to avoid ambiguity between +different layout files across different views. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +res/layout/activity_main.xml:1:Warning: Id should start with: +activityMain [MatchingViewId] +<TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/text"/> + --------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`res/layout/activity_main.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/text"/> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/MatchingViewIdDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MatchingViewIdDetector.idWithoutPrefix`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-android:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-android:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.android) + +# libs.versions.toml +[versions] +lint-rules-android = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-android = { + module = "com.vanniktech:lint-rules-android", + version.ref = "lint-rules-android" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute `tools:ignore="MatchingViewId"` on + the problematic XML element (or one of its enclosing elements). You + may also need to add the following namespace declaration on the root + element in the XML file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MatchingViewId" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MatchingViewId' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MatchingViewId ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MemberExtensionConflict.md.html b/docs/checks/MemberExtensionConflict.md.html new file mode 100644 index 00000000..d140606c --- /dev/null +++ b/docs/checks/MemberExtensionConflict.md.html @@ -0,0 +1,175 @@ + +(#) Conflict applicable candidates of member and extension + +!!! WARNING: Conflict applicable candidates of member and extension + This is a warning. + +Id +: `MemberExtensionConflict` +Summary +: Conflict applicable candidates of member and extension +Note +: **This issue is disabled by default**; use `--enable MemberExtensionConflict` +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.11.0-alpha03 (March 2025) +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/MemberExtensionConflictDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/MemberExtensionConflictDetectorTest.kt) + +When both member and extension declarations are applicable, the +resolution takes the member. This also implies that, if an extension +existed first, but then a member is added later, the same call-site may +end up with different call resolutions depending on target environment. +This results in a potential runtime exception if the generated binary +(library or app) targets earlier environment (i.e., without the new +member, but only extension). More concrete example is found at: +https://issuetracker.google.com/issues/350432371 + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/ListWrapper.kt:10:Warning: `magicCount` is defined both as a member +in class `ListWrapper` and an extension in package `users.own`. The +defined behavior for this is to use the member, but since the extension +is explicitly imported into this file, there's a chance that this was +not expected. (One common way this happens is for members to be added to +a class after code was already written to use an extension). +[MemberExtensionConflict] + val x = l.magicCount // WARNING 1 + ---------- +src/ListWrapper.kt:11:Warning: `removeMiddle` is defined both as a +member in class `ListWrapper` and an extension in package `users.own`. +The defined behavior for this is to use the member, but since the +extension is explicitly imported into this file, there's a chance that +this was not expected. (One common way this happens is for members to be +added to a class after code was already written to use an extension). +[MemberExtensionConflict] + l.removeMiddle() // WARNING 2 + ---------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`src/my/cool/lib/MyList.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package my.cool.lib +interface MyList { + val magicCount: Int + fun removeMiddle() +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/users/own/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package users.own + +import my.cool.lib.MyList + +val MyList.magicCount: Int + get() = 42 + +fun MyList.removeMiddle() {} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/ListWrapper.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +import my.cool.lib.MyList +import users.own.magicCount +import users.own.removeMiddle + +class ListWrapper( + private val base: MyList +) : MyList by base + +fun test(l : ListWrapper) { + val x = l.magicCount // WARNING 1 + l.removeMiddle() // WARNING 2 +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/MemberExtensionConflictDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MemberExtensionConflict") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MemberExtensionConflict") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MemberExtensionConflict + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MemberExtensionConflict" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MemberExtensionConflict' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MemberExtensionConflict ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MenuTitle.md.html b/docs/checks/MenuTitle.md.html index 79a93ec0..6a3d8458 100644 --- a/docs/checks/MenuTitle.md.html +++ b/docs/checks/MenuTitle.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -54,18 +56,12 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/menu/titles.xml:3:Error: Menu items should specify a title [MenuTitle] - <item android:id="@+id/action_bar_progress_spinner" ---- - - res/menu/titles.xml:12:Error: Menu items should specify a title [MenuTitle] - <item android:id="@+id/menu_plus_one" ---- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/MergeMarker.md.html b/docs/checks/MergeMarker.md.html index 111a37b5..1191ad0b 100644 --- a/docs/checks/MergeMarker.md.html +++ b/docs/checks/MergeMarker.md.html @@ -18,14 +18,14 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 2.3.0 (March 2017) Editing : This check can *not* run live in the IDE editor Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/MergeMarkerDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/MergeMarkerDetectorTest.kt) -Copyright Year -: 2016 Many version control systems leave unmerged files with markers such as <<< in the source code. This check looks for these markers, which are @@ -37,23 +37,14 @@ Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/values/strings.xml:5:Error: Missing merge marker? [MergeMarker] - <<<<<<< HEAD ------- - - res/values/strings.xml:7:Error: Missing merge marker? [MergeMarker] - ======= ------- - - res/values/strings.xml:9:Error: Missing merge marker? [MergeMarker] - >>>>>>> branch-a ------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/MergeRootFrame.md.html b/docs/checks/MergeRootFrame.md.html index e413c487..a06459ec 100644 --- a/docs/checks/MergeRootFrame.md.html +++ b/docs/checks/MergeRootFrame.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files and resource files Editing @@ -42,14 +44,11 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/simple.xml:1:Warning: This can be replaced with a tag [MergeRootFrame] - <FrameLayout ^ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `res/layout/simple.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -59,6 +58,22 @@ android:layout_height="match_parent" /> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/test/pkg/ImportFrameActivity.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; + +import android.app.Activity; +import android.os.Bundle; + +public class ImportFrameActivity extends Activity { + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.simple); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/MergeRootFrameLayoutDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/MinSdkTooLow.md.html b/docs/checks/MinSdkTooLow.md.html index 2cce8fd8..b2934a13 100644 --- a/docs/checks/MinSdkTooLow.md.html +++ b/docs/checks/MinSdkTooLow.md.html @@ -20,16 +20,16 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.0.0 (October 2017) Affects -: Gradle build files +: Gradle build files and TOML files Editing : This check runs on the fly in the IDE editor Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GradleDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) -Copyright Year -: 2014 The value of the `minSdkVersion` property is too low and can be incremented without noticeably reducing the number of supported @@ -42,42 +42,53 @@ Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -build.gradle:8:Warning: The value of minSdkVersion is too low. It can be -incremented without noticeably reducing the number of supported devices. -[MinSdkTooLow] - - minSdkVersion 7 - --------------- - +build.gradle.kts:5:Warning: The value of minSdkVersion (15) is too low. +It can be incremented without noticeably reducing the number of +supported devices. [MinSdkTooLow] + minSdk = libs.versions.keys.msv.get().toInt() // ERROR 14 + --------------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -build.gradle:9:Warning: The value of minSdkVersion is too low. It can be -incremented without noticeably reducing the number of supported devices. -[MinSdkTooLow] +Here are the relevant source files: - minSdk 7 - -------- +`build.gradle.kts`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +android { + compileSdk = libs.versions.compile.sdk.version.get().toInt() // ERROR 12 + compileSdk = libs.versions.keys.csv.get().toInt() // ERROR 13 + defaultConfig { + minSdk = libs.versions.keys.msv.get().toInt() // ERROR 14 + targetSdk = libs.versions.keys.tsv.get().toInt() // ERROR 15 + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`../gradle/libs.versions.toml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~toml linenumbers +[versions] +compile_sdk_version = "34" # ERROR 1 +min_sdk_version = "15" # ERROR 2 +target_sdk_version = "34" # ERROR 3 -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +compileSdkVersion = "34" # ERROR 4 +minSdkVersion = "15" # ERROR 5 +targetSdkVersion = "34" # ERROR 6 -Here is the source file referenced above: +compileSdk = "34" # ERROR 7 +minSdk = "15" # ERROR 8 +targetSdk = "34" # ERROR 9 -`build.gradle`: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~groovy linenumbers -apply plugin: 'com.android.application' +# https://github.com/Kotlin/multiplatform-library-template/blob/main/gradle/libs.versions.toml +android-minSdk = "15" # ERROR 10 +android-compileSdk = "34" # ERROR 11 -android { - compileSdkVersion 19 - buildToolsVersion "19.0.0" +# Unusual keys, referenced via KTS +keys-csv = "34" # ERROR 12 +keys-msv = "15" # ERROR 13 +keys-tsv = "34" # ERROR 14 - defaultConfig { - minSdkVersion 7 - minSdk 7 - targetSdkVersion 19 - versionCode 1 - versionName "1.0" - } -} +javaCompileSdk = "17" # OK 1 +other-compileSdk = "15" # OK 2 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can also visit the @@ -85,7 +96,7 @@ for the unit tests for this check to see additional scenarios. The above example was automatically extracted from the first unit test -found for this lint check, `GradleDetector.testMinSdkVersion`. +found for this lint check, `GradleDetector.testCompileSdkViaVersionCatalog`. To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=192708. diff --git a/docs/checks/MipmapIcons.md.html b/docs/checks/MipmapIcons.md.html index be5cd003..3fdbb0e3 100644 --- a/docs/checks/MipmapIcons.md.html +++ b/docs/checks/MipmapIcons.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 1.1.0 (February 2015) Affects : Manifest files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ManifestDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ManifestDetectorTest.kt) -Copyright Year -: 2011 Launcher icons should be provided in the `mipmap` resource directory. This is the same as the `drawable` resource directory, except resources @@ -55,21 +55,15 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/main/AndroidManifest.xml:8:Warning: Should use @mipmap instead of @drawable for launcher icons [MipmapIcons] - android:icon="@drawable/ic_launcher" ------------------------------------ - - src/main/AndroidManifest.xml:13:Warning: Should use @mipmap instead of @drawable for launcher icons [MipmapIcons] - android:icon="@drawable/activity1" ---------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `src/main/AndroidManifest.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -109,6 +103,26 @@ </manifest> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`build.gradle`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~groovy linenumbers +android { + defaultConfig { + resConfigs "cs" + } + flavorDimensions "pricing", "releaseType" + productFlavors { + beta { + dimension "releaseType" + resConfig "en", "de" + resConfigs "nodpi", "hdpi" + } + normal { dimension "releaseType" } + free { dimension "pricing" } + paid { dimension "pricing" } + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ManifestDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/MissingApplicationIcon.md.html b/docs/checks/MissingApplicationIcon.md.html index 21c7b610..4dafc5a5 100644 --- a/docs/checks/MissingApplicationIcon.md.html +++ b/docs/checks/MissingApplicationIcon.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Manifest files Editing @@ -44,14 +46,11 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text AndroidManifest.xml:8:Warning: Should explicitly set android:icon, there is no default [MissingApplicationIcon] - <application ----------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `AndroidManifest.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -78,6 +77,40 @@ </manifest> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/values/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<!-- Copyright (C) 2007 The Android Open Source Project + + 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. +--> + +<resources> + <!-- Home --> + <string name="home_title">Home Sample</string> + <string name="show_all_apps">All</string> + + <!-- Home Menus --> + <string name="menu_wallpaper">Wallpaper</string> + <string name="menu_search">Search</string> + <string name="menu_settings">Settings</string> + <string name="sample" translatable="false">Ignore Me</string> + + <!-- Wallpaper --> + <string name="wallpaper_instructions">Tap picture to set portrait wallpaper</string> +</resources> + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ManifestDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/MissingAutoVerifyAttribute.md.html b/docs/checks/MissingAutoVerifyAttribute.md.html new file mode 100644 index 00000000..c9a8a9e3 --- /dev/null +++ b/docs/checks/MissingAutoVerifyAttribute.md.html @@ -0,0 +1,176 @@ + +(#) Application has custom scheme intent filters with missing `autoVerify` attributes + +!!! WARNING: Application has custom scheme intent filters with missing `autoVerify` attributes + This is a warning. + +Id +: `MissingAutoVerifyAttribute` +Summary +: Application has custom scheme intent filters with missing `autoVerify` attributes +Severity +: Warning +Category +: Security +Platform +: Android +Vendor +: Google - Android 3P Vulnerability Research +Contact +: https://github.com/google/android-security-lints +Feedback +: https://github.com/google/android-security-lints/issues +Min +: Lint 4.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.android.security.lint:lint](com_android_security_lint_lint.md.html) +Since +: 1.0.1 +Affects +: Manifest files +Editing +: This check runs on the fly in the IDE editor +See +: https://goo.gle/MissingAutoVerifyAttribute +Implementation +: [Source Code](https://github.com/google/android-security-lints/tree/main/checks/src/main/java/com/example/lint/checks/CustomSchemeDetector.kt) +Tests +: [Source Code](https://github.com/google/android-security-lints/tree/main/checks/src/test/java/com/example/lint/checks/CustomSchemeDetectorTest.kt) +Copyright Year +: 2024 + +Intent filters should contain the `autoVerify` attribute and explicitly +set it to true, in order to signal to the system to automatically verify +the associated hosts in your app's intent filters. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +AndroidManifest.xml:5:Warning: Custom scheme intent filters should +explicitly set the autoVerify attribute to true +[MissingAutoVerifyAttribute] + <intent-filter android:autoVerify='false'> + ^ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`AndroidManifest.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<manifest xmlns:android='http://schemas.android.com/apk/res/android' package='test.pkg'> +<application android:debuggable='false'> +<meta-data android:name='android.webkit.WebView.EnableSafeBrowsing'/> + <activity android:name='com.example.MainActivity'> + <intent-filter android:autoVerify='false'> + <action android:name='android.intent.action.VIEW' /> + <data android:scheme='telegram://' /> + </intent-filter> + </activity> +</application> +</manifest> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/google/android-security-lints/tree/main/checks/src/test/java/com/example/lint/checks/CustomSchemeDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `CustomSchemeDetector.testWhenFalseAutoVerifyAttributeSpecifiedOnCustomSchemeIntentFilter_showsWarning`. +To report a problem with this extracted sample, visit +https://github.com/google/android-security-lints/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.android.security.lint:lint:1.0.3") + +// build.gradle +lintChecks 'com.android.security.lint:lint:1.0.3' + +// build.gradle.kts with version catalogs: +lintChecks(libs.com.android.security.lint.lint) + +# libs.versions.toml +[versions] +com-android-security-lint-lint = "1.0.3" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +com-android-security-lint-lint = { + module = "com.android.security.lint:lint", + version.ref = "com-android-security-lint-lint" +} +``` + +1.0.3 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.android.security.lint:lint](com_android_security_lint_lint.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute + `tools:ignore="MissingAutoVerifyAttribute"` on the problematic XML + element (or one of its enclosing elements). You may also need to add + the following namespace declaration on the root element in the XML + file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <manifest xmlns:tools="http://schemas.android.com/tools"> + ... + <intent-filter tools:ignore="MissingAutoVerifyAttribute" .../> + ... + </manifest> + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MissingAutoVerifyAttribute" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MissingAutoVerifyAttribute' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MissingAutoVerifyAttribute ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MissingBackupPin.md.html b/docs/checks/MissingBackupPin.md.html index fbf1940f..72316bef 100644 --- a/docs/checks/MissingBackupPin.md.html +++ b/docs/checks/MissingBackupPin.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 2.3.0 (March 2017) Affects : Resource files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/NetworkSecurityConfigDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/NetworkSecurityConfigDetectorTest.java) -Copyright Year -: 2016 It is highly recommended to declare a backup `` element. Not having a second pin defined can cause connection failures when the particular @@ -41,11 +41,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/xml/network_config.xml:5:Warning: A backup declaration is highly recommended [MissingBackupPin] - <pin-set> ------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/MissingClass.md.html b/docs/checks/MissingClass.md.html index 587af9b5..d8c2f4f4 100644 --- a/docs/checks/MissingClass.md.html +++ b/docs/checks/MissingClass.md.html @@ -6,8 +6,6 @@ Id : `MissingClass` -Previously -: MissingRegistered Summary : Missing registered class Severity @@ -20,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 4.0.0 (May 2020) Affects : Manifest files and resource files Editing @@ -30,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/MissingClassDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/MissingClassDetectorTest.kt) -Copyright Year -: 2012 If a class is referenced in the manifest or in a layout file, it must also exist in the project (or in one of the libraries included by the @@ -46,14 +44,11 @@ res/layout/customview.xml:5:Error: Class referenced in the layout file, foo.bar.Baz, was not found in the project or the libraries [MissingClass] - <foo.bar.Baz /> --------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `res/layout/customview.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -67,6 +62,21 @@ </LinearLayout> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/test/pkg/MyView.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg + +abstract class MyView : I, androic.view.View(null) + +interface I +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/NotView.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg +abstract class NotView : android.app.Fragment() +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/MissingClassDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/MissingColorAlphaChannel.md.html b/docs/checks/MissingColorAlphaChannel.md.html index aa5e9cd6..42671e8d 100644 --- a/docs/checks/MissingColorAlphaChannel.md.html +++ b/docs/checks/MissingColorAlphaChannel.md.html @@ -20,6 +20,14 @@ : androidx.compose.ui.graphics Feedback : https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.ui:ui-graphics-android](androidx_compose_ui_ui-graphics-android.md.html) +Since +: 1.5.0 Affects : Kotlin and Java files and test sources Editing @@ -37,45 +45,33 @@ passing 0xFF0000 will result in a missing alpha channel, so the color will not appear visible. +!!! Tip + This lint check has an associated quickfix available in the IDE. + (##) Example Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/test.kt:6:Warning: Missing Color alpha channel [MissingColorAlphaChannel] - val color = Color(0x000000) -------- - - src/test/test.kt:8:Warning: Missing Color alpha channel [MissingColorAlphaChannel] - val color2 = Color(0xEEEEEE) -------- - - src/test/test.kt:10:Warning: Missing Color alpha channel [MissingColorAlphaChannel] - val color3 = Color(0xeeeeee) -------- - - src/test/test.kt:12:Warning: Missing Color alpha channel [MissingColorAlphaChannel] - val color3 = Color(0xeEeeEE) -------- - - src/test/test.kt:14:Warning: Missing Color alpha channel [MissingColorAlphaChannel] - val color4 = Color(0x00_00_00L) ----------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -106,6 +102,44 @@ To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=612128. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.ui:ui-graphics-android:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.ui:ui-graphics-android:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.ui.graphics.android) + +# libs.versions.toml +[versions] +ui-graphics-android = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +ui-graphics-android = { + module = "androidx.compose.ui:ui-graphics-android", + version.ref = "ui-graphics-android" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.ui:ui-graphics-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.ui:ui-graphics-android](androidx_compose_ui_ui-graphics-android.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/MissingConstraints.md.html b/docs/checks/MissingConstraints.md.html index eb963163..8b2eccb1 100644 --- a/docs/checks/MissingConstraints.md.html +++ b/docs/checks/MissingConstraints.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 2.2.0 (September 2016) Affects : Resource files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ConstraintLayoutDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ConstraintLayoutDetectorTest.kt) -Copyright Year -: 2018 The layout editor allows you to place widgets anywhere on the canvas, and it records the current position with designtime attributes (such as @@ -44,35 +44,23 @@ res/layout/layout1.xml:11:Error: This view is not constrained. It only has designtime positions, so it will jump to (0,0) at runtime unless you add the constraints [MissingConstraints] - <TextView -------- - - res/layout/layout1.xml:16:Error: This view is not constrained. It only has designtime positions, so it will jump to (0,0) at runtime unless you add the constraints [MissingConstraints] - <TextView -------- - - res/layout/layout1.xml:38:Error: This view is not constrained vertically: at runtime it will jump to the top unless you add a vertical constraint [MissingConstraints] - <TextView -------- - - res/layout/layout1.xml:47:Error: This view is not constrained horizontally: at runtime it will jump to the left unless you add a horizontal constraint [MissingConstraints] - <TextView -------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/MissingDefaultResource.md.html b/docs/checks/MissingDefaultResource.md.html index 69082ae8..46d686f9 100644 --- a/docs/checks/MissingDefaultResource.md.html +++ b/docs/checks/MissingDefaultResource.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.2.0 (September 2018) Affects : Binary resource files, resource files and resource folders Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/TranslationDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/TranslationDetectorTest.kt) -Copyright Year -: 2018 If a resource is only defined in folders with qualifiers like `-land` or `-en`, and there is no default declaration in the base folder (`layout` @@ -68,15 +68,20 @@ values-land has no declaration in the base values folder; this can lead to crashes when the resource is queried in a configuration that does not match this qualifier [MissingDefaultResource] - <dimen name="extra_dimen1">1pt</dimen> <!-- error --> ------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Here are the relevant source files: +`res/values/dimen.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<resources> + <dimen name="ok_dimen">base</dimen> <!-- ok --> + <style name="ok_style"></style> <!-- ok --> +</resources> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: - `res/values-land/dimen.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers <resources> @@ -87,6 +92,45 @@ </resources> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/values-v21/dimen.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<resources> + <!-- We allow common scenario of having dedicated + resources for API levels, often used for theming --> + <dimen name="ok_extra_dimen">1pt</dimen> <!-- ok --> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/values-land-v21/dimen.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<resources> + <dimen name="ok_extra_dimen">2pt</dimen> <!-- ok --> + <dimen name="extra_dimen2">1pt</dimen> <!-- error --> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/drawable-mdpi/ok_drawable.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<resources> + <drawable name="color_drawable">#ffffffff</drawable> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/color/ok_color.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<color xmlns:android="http://schemas.android.com/apk/res/android" android:color="#ff0000" /> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/color-port/extra_color.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<color xmlns:android="http://schemas.android.com/apk/res/android" android:color="#ff0000" /> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/layout-land/extra_layout.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<merge/> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/TranslationDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/MissingFirebaseInstanceTokenRefresh.md.html b/docs/checks/MissingFirebaseInstanceTokenRefresh.md.html index 8c8de30f..396960c0 100644 --- a/docs/checks/MissingFirebaseInstanceTokenRefresh.md.html +++ b/docs/checks/MissingFirebaseInstanceTokenRefresh.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 2.3.0 (March 2017) Affects : Kotlin and Java files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/FirebaseMessagingDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/FirebaseMessagingDetectorTest.java) -Copyright Year -: 2016 Apps that use Firebase Cloud Messaging should implement the `FirebaseMessagingService#onNewToken()` callback in order to observe @@ -40,13 +40,10 @@ Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/com/google/firebase/samples/messaging/advanced/services/MessagingService.java:5:Warning: - Apps that use Firebase Cloud Messaging should implement onNewToken() in +Apps that use Firebase Cloud Messaging should implement onNewToken() in order to observe token changes [MissingFirebaseInstanceTokenRefresh] - public class MessagingService extends FirebaseMessagingService { ---------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/MissingId.md.html b/docs/checks/MissingId.md.html index 0879901f..7a060370 100644 --- a/docs/checks/MissingId.md.html +++ b/docs/checks/MissingId.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -55,11 +57,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/fragment.xml:7:Warning: This tag should specify an id or a tag to preserve state across activity restarts [MissingId] - <fragment -------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/MissingInflatedId.md.html b/docs/checks/MissingInflatedId.md.html index 8c4adc03..f19ee7a4 100644 --- a/docs/checks/MissingInflatedId.md.html +++ b/docs/checks/MissingInflatedId.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.3.0 (September 2022) Affects : Kotlin and Java files and resource files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/MissingInflatedIdDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/MissingInflatedIdDetectorTest.kt) -Copyright Year -: 2022 Checks calls to layout inflation and makes sure that the referenced ids are found in the corresponding layout (or at least one of them, if the @@ -39,18 +39,12 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/MyActivity.kt:15:Error: @layout/activity_main does not contain a declaration with id text_field [MissingInflatedId] - requireViewById<EditText>(R.id.text_field).isEnabled = false --------------- - - src/test/pkg/MyActivity.kt:21:Error: @layout/list_item does not contain a declaration with id image_view [MissingInflatedId] - val imgView = rootView.findViewById<ImageView>(R.id.image_view) --------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here are the relevant source files: @@ -97,7 +91,7 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `test.pkg`: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ linenumbers +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text linenumbers @id/text_field ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/checks/MissingIntentFilterForMediaSearch.md.html b/docs/checks/MissingIntentFilterForMediaSearch.md.html index 5c30bdf3..ced8da8b 100644 --- a/docs/checks/MissingIntentFilterForMediaSearch.md.html +++ b/docs/checks/MissingIntentFilterForMediaSearch.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 1.5.0 (November 2015) Affects : Kotlin and Java files, manifest files and resource files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AndroidAutoDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AndroidAutoDetectorTest.java) -Copyright Year -: 2015 To support voice searches on Android Auto, you should also register an `intent-filter` for the action @@ -50,14 +50,11 @@ AndroidManifest.xml:6:Error: Missing intent-filter for action android.media.action.MEDIA_PLAY_FROM_SEARCH. [MissingIntentFilterForMediaSearch] - <application ^ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `AndroidManifest.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -89,6 +86,14 @@ </manifest> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/xml/automotive_app_desc.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<automotiveApp> + <uses name="media"/> +</automotiveApp> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AndroidAutoDetectorTest.java) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/MissingKeepAnnotation-2.md.html b/docs/checks/MissingKeepAnnotation-2.md.html new file mode 100644 index 00000000..098b3403 --- /dev/null +++ b/docs/checks/MissingKeepAnnotation-2.md.html @@ -0,0 +1,150 @@ + +(#) In minified builds, Enum classes used as type-safe Navigation arguments should be annotated with @androidx.annotation.Keep + +!!! WARNING: In minified builds, Enum classes used as type-safe Navigation arguments should be annotated with @androidx.annotation.Keep + This is a warning. + +Id +: `MissingKeepAnnotation` +Summary +: In minified builds, Enum classes used as type-safe Navigation arguments should be annotated with @androidx.annotation.Keep +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: Jetpack Navigation Compose +Identifier +: androidx.navigation.compose +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.7+ +Artifact +: [androidx.navigation:navigation-compose](androidx_navigation_navigation-compose.md.html) +Since +: 2.8.3 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/navigation/navigation-runtime-lint/src/main/java/androidx/navigation/runtime/lint/TypeSafeDestinationMissingAnnotationDetector.kt) +Copyright Year +: 2024 + +Type-safe nav arguments such as Enum types can get incorrectly +obfuscated in minified builds when not referenced directly. + +(##) Conflicts + +This issue id has also been used by other, unrelated lint checks. Issue +id's must be unique, so you cannot combine these libraries. Also defined +in: +* MissingKeepAnnotation: In minified builds, Enum classes used as type-safe Navigation arguments should be annotated with @androidx.annotation.Keep (this issue) +* [MissingKeepAnnotation from androidx.navigation:navigation-common:2.9.0-rc01](MissingKeepAnnotation.md.html) +* [MissingKeepAnnotation from androidx.navigation:navigation-runtime:2.9.0-rc01](MissingKeepAnnotation-3.md.html) + + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.navigation:navigation-compose:2.9.0-rc01") + +// build.gradle +implementation 'androidx.navigation:navigation-compose:2.9.0-rc01' + +// build.gradle.kts with version catalogs: +implementation(libs.navigation.compose) + +# libs.versions.toml +[versions] +navigation-compose = "2.9.0-rc01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +navigation-compose = { + module = "androidx.navigation:navigation-compose", + version.ref = "navigation-compose" +} +``` + +2.9.0-rc01 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.navigation:navigation-compose](androidx_navigation_navigation-compose.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MissingKeepAnnotation") + fun method() { + composable(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MissingKeepAnnotation") + void method() { + composable(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MissingKeepAnnotation + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MissingKeepAnnotation" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MissingKeepAnnotation' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MissingKeepAnnotation ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MissingKeepAnnotation-3.md.html b/docs/checks/MissingKeepAnnotation-3.md.html new file mode 100644 index 00000000..7d3ae75f --- /dev/null +++ b/docs/checks/MissingKeepAnnotation-3.md.html @@ -0,0 +1,152 @@ + +(#) In minified builds, Enum classes used as type-safe Navigation arguments should be annotated with @androidx.annotation.Keep + +!!! WARNING: In minified builds, Enum classes used as type-safe Navigation arguments should be annotated with @androidx.annotation.Keep + This is a warning. + +Id +: `MissingKeepAnnotation` +Summary +: In minified builds, Enum classes used as type-safe Navigation arguments should be annotated with @androidx.annotation.Keep +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: Android Open Source Project +Identifier +: androidx.navigation.runtime +Feedback +: https://issuetracker.google.com/issues/new?component=409828 +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.7+ +Artifact +: [androidx.navigation:navigation-runtime](androidx_navigation_navigation-runtime.md.html) +Since +: 2.8.3 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/navigation/navigation-runtime-lint/src/main/java/androidx/navigation/runtime/lint/TypeSafeDestinationMissingAnnotationDetector.kt) +Copyright Year +: 2024 + +Type-safe nav arguments such as Enum types can get incorrectly +obfuscated in minified builds when not referenced directly. + +(##) Conflicts + +This issue id has also been used by other, unrelated lint checks. Issue +id's must be unique, so you cannot combine these libraries. Also defined +in: +* MissingKeepAnnotation: In minified builds, Enum classes used as type-safe Navigation arguments should be annotated with @androidx.annotation.Keep (this issue) +* [MissingKeepAnnotation from androidx.navigation:navigation-common:2.9.0-rc01](MissingKeepAnnotation.md.html) +* [MissingKeepAnnotation from androidx.navigation:navigation-compose:2.9.0-rc01](MissingKeepAnnotation-2.md.html) + + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.navigation:navigation-runtime:2.9.0-rc01") + +// build.gradle +implementation 'androidx.navigation:navigation-runtime:2.9.0-rc01' + +// build.gradle.kts with version catalogs: +implementation(libs.navigation.runtime) + +# libs.versions.toml +[versions] +navigation-runtime = "2.9.0-rc01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +navigation-runtime = { + module = "androidx.navigation:navigation-runtime", + version.ref = "navigation-runtime" +} +``` + +2.9.0-rc01 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.navigation:navigation-runtime](androidx_navigation_navigation-runtime.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MissingKeepAnnotation") + fun method() { + activity(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MissingKeepAnnotation") + void method() { + activity(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MissingKeepAnnotation + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MissingKeepAnnotation" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MissingKeepAnnotation' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MissingKeepAnnotation ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MissingKeepAnnotation.md.html b/docs/checks/MissingKeepAnnotation.md.html new file mode 100644 index 00000000..051629bf --- /dev/null +++ b/docs/checks/MissingKeepAnnotation.md.html @@ -0,0 +1,152 @@ + +(#) In minified builds, Enum classes used as type-safe Navigation arguments should be annotated with @androidx.annotation.Keep + +!!! WARNING: In minified builds, Enum classes used as type-safe Navigation arguments should be annotated with @androidx.annotation.Keep + This is a warning. + +Id +: `MissingKeepAnnotation` +Summary +: In minified builds, Enum classes used as type-safe Navigation arguments should be annotated with @androidx.annotation.Keep +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: Android Open Source Project +Identifier +: androidx.navigation.common +Feedback +: https://issuetracker.google.com/issues/new?component=409828 +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.7+ +Artifact +: [androidx.navigation:navigation-common](androidx_navigation_navigation-common.md.html) +Since +: 2.8.3 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/navigation/navigation-runtime-lint/src/main/java/androidx/navigation/runtime/lint/TypeSafeDestinationMissingAnnotationDetector.kt) +Copyright Year +: 2024 + +Type-safe nav arguments such as Enum types can get incorrectly +obfuscated in minified builds when not referenced directly. + +(##) Conflicts + +This issue id has also been used by other, unrelated lint checks. Issue +id's must be unique, so you cannot combine these libraries. Also defined +in: +* MissingKeepAnnotation: In minified builds, Enum classes used as type-safe Navigation arguments should be annotated with @androidx.annotation.Keep (this issue) +* [MissingKeepAnnotation from androidx.navigation:navigation-compose:2.9.0-rc01](MissingKeepAnnotation-2.md.html) +* [MissingKeepAnnotation from androidx.navigation:navigation-runtime:2.9.0-rc01](MissingKeepAnnotation-3.md.html) + + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.navigation:navigation-common:2.9.0-rc01") + +// build.gradle +implementation 'androidx.navigation:navigation-common:2.9.0-rc01' + +// build.gradle.kts with version catalogs: +implementation(libs.navigation.common) + +# libs.versions.toml +[versions] +navigation-common = "2.9.0-rc01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +navigation-common = { + module = "androidx.navigation:navigation-common", + version.ref = "navigation-common" +} +``` + +2.9.0-rc01 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.navigation:navigation-common](androidx_navigation_navigation-common.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MissingKeepAnnotation") + fun method() { + navigation(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MissingKeepAnnotation") + void method() { + navigation(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MissingKeepAnnotation + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MissingKeepAnnotation" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MissingKeepAnnotation' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MissingKeepAnnotation ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MissingLeanbackLauncher.md.html b/docs/checks/MissingLeanbackLauncher.md.html index bd4db6dd..1cea1404 100644 --- a/docs/checks/MissingLeanbackLauncher.md.html +++ b/docs/checks/MissingLeanbackLauncher.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 1.5.0 (November 2015) Affects : Manifest files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AndroidTvDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AndroidTvDetectorTest.java) -Copyright Year -: 2015 An application intended to run on TV devices must declare a launcher activity for TV in its manifest using a @@ -42,11 +42,8 @@ AndroidManifest.xml:2:Error: Expecting an activity to have android.intent.category.LEANBACK_LAUNCHER intent filter [MissingLeanbackLauncher] - <manifest xmlns:android="http://schemas.android.com/apk/res/android" -------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/MissingLeanbackSupport.md.html b/docs/checks/MissingLeanbackSupport.md.html index a76bbad4..2421c690 100644 --- a/docs/checks/MissingLeanbackSupport.md.html +++ b/docs/checks/MissingLeanbackSupport.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 1.5.0 (November 2015) Affects : Manifest files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AndroidTvDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AndroidTvDetectorTest.java) -Copyright Year -: 2015 The manifest should declare the use of the Leanback user interface required by Android TV. @@ -51,11 +51,8 @@ AndroidManifest.xml:2:Error: Expecting tag [MissingLeanbackSupport] - <manifest xmlns:android="http://schemas.android.com/apk/res/android" -------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/MissingMediaBrowserServiceIntentFilter.md.html b/docs/checks/MissingMediaBrowserServiceIntentFilter.md.html index 80c495c4..825b40b6 100644 --- a/docs/checks/MissingMediaBrowserServiceIntentFilter.md.html +++ b/docs/checks/MissingMediaBrowserServiceIntentFilter.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 1.5.0 (November 2015) Affects : Kotlin and Java files, manifest files and resource files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AndroidAutoDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AndroidAutoDetectorTest.java) -Copyright Year -: 2015 An Automotive Media App requires an exported service that extends `android.service.media.MediaBrowserService` with an `intent-filter` for @@ -51,14 +51,11 @@ AndroidManifest.xml:6:Error: Missing intent-filter for action android.media.browse.MediaBrowserService that is required for android auto support [MissingMediaBrowserServiceIntentFilter] - <application ^ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `AndroidManifest.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -87,6 +84,14 @@ </manifest> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/xml/automotive_app_desc.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<automotiveApp> + <uses name="media"/> +</automotiveApp> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AndroidAutoDetectorTest.java) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/MissingOnPlayFromSearch.md.html b/docs/checks/MissingOnPlayFromSearch.md.html index fbb67efd..8e05eb7e 100644 --- a/docs/checks/MissingOnPlayFromSearch.md.html +++ b/docs/checks/MissingOnPlayFromSearch.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 1.5.0 (November 2015) Affects : Kotlin and Java files, manifest files and resource files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AndroidAutoDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AndroidAutoDetectorTest.java) -Copyright Year -: 2015 To support voice searches on Android Auto, in addition to adding an `intent-filter` for the action `onPlayFromSearch`, you also need to @@ -43,14 +43,53 @@ does not override onPlayFromSearch from MediaSession.Callback The method should be overridden and implemented to support Voice search on Android Auto. [MissingOnPlayFromSearch] - public class MSessionCallback extends Callback { ---------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - +Here are the relevant source files: + +`AndroidManifest.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + package="com.example.android.uamp"> + + <application + android:name=".UAMPApplication" + android:label="@string/app_name" + android:theme="@style/UAmpAppTheme"> + + <meta-data + android:name="com.google.android.gms.car.application" + android:resource="@xml/automotive_app_desc"/> + + <service + android:name=".MusicService" + android:exported="true" + tools:ignore="ExportedService"> + <intent-filter> + <action android:name="android.media.browse.MediaBrowserService"/> + </intent-filter> + <intent-filter> + <action android:name="android.media.action.MEDIA_PLAY_FROM_SEARCH"/> + <category android:name="android.intent.category.DEFAULT"/> + </intent-filter> + </service> + + </application> + +</manifest> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +`res/xml/automotive_app_desc.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<automotiveApp> + <uses name="media"/> +</automotiveApp> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `src/com/example/android/uamp/MSessionCallback.java`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers @@ -79,6 +118,22 @@ You can suppress false positives using one of the following mechanisms: +* Adding the suppression attribute + `tools:ignore="MissingOnPlayFromSearch"` on the problematic XML + element (or one of its enclosing elements). You may also need to add + the following namespace declaration on the root element in the XML + file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <manifest xmlns:tools="http://schemas.android.com/tools"> + ... + <automotiveApp tools:ignore="MissingOnPlayFromSearch" .../> + ... + </manifest> + ``` + * Using a suppression annotation like this on the enclosing element: @@ -107,22 +162,6 @@ problematicStatement() ``` -* Adding the suppression attribute - `tools:ignore="MissingOnPlayFromSearch"` on the problematic XML - element (or one of its enclosing elements). You may also need to add - the following namespace declaration on the root element in the XML - file if it's not already there: - `xmlns:tools="http://schemas.android.com/tools"`. - - ```xml - <?xml version="1.0" encoding="UTF-8"?> - <manifest xmlns:tools="http://schemas.android.com/tools"> - ... - <automotiveApp tools:ignore="MissingOnPlayFromSearch" .../> - ... - </manifest> - ``` - * Using a special `lint.xml` file in the source tree which turns off the check in that folder and any sub folder. A simple file might look like this: diff --git a/docs/checks/MissingPermission.md.html b/docs/checks/MissingPermission.md.html index cb2c91fe..80c2fe9f 100644 --- a/docs/checks/MissingPermission.md.html +++ b/docs/checks/MissingPermission.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.1.0 (March 2018) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/PermissionDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/PermissionDetectorTest.kt) -Copyright Year -: 2017 This check scans through your code and libraries and looks at the APIs being used, and checks this against the set of permissions required to @@ -48,11 +48,8 @@ src/test/pkg/PermissionTest.java:7:Error: Missing permissions required by LocationManager.myMethod: android.permission.ACCESS_FINE_LOCATION or android.permission.ACCESS_COARSE_LOCATION [MissingPermission] - LocationManager.Location location = locationManager.myMethod(provider); ---------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/MissingPrefix.md.html b/docs/checks/MissingPrefix.md.html index f622c65c..d0a009e1 100644 --- a/docs/checks/MissingPrefix.md.html +++ b/docs/checks/MissingPrefix.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.0.0 (July 2021) Affects : Manifest files and resource files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/MissingPrefixDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/MissingPrefixDetectorTest.kt) -Copyright Year -: 2011 Most Android views have attributes in the Android namespace. When referencing these attributes you **must** include the namespace prefix, @@ -46,18 +46,12 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/namespace.xml:2:Error: Attribute is missing the Android namespace prefix [MissingPrefix] - <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:other="http://foo.bar" android:id="@+id/newlinear" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" orientation="true"> ------------------ - - res/layout/namespace.xml:3:Error: Attribute is missing the Android namespace prefix [MissingPrefix] - <Button style="@style/setupWizardOuterFrame" android.text="Button" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"/> --------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/MissingQuantity.md.html b/docs/checks/MissingQuantity.md.html index 15f98473..cc763f3c 100644 --- a/docs/checks/MissingQuantity.md.html +++ b/docs/checks/MissingQuantity.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -52,14 +54,34 @@ res/values-pl/plurals2.xml:3:Error: For locale "pl" (Polish) the following quantity should also be defined: many (e.g. "5 miesięcy") [MissingQuantity] - <plurals name="numberOfSongsAvailable"> ^ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Here are the relevant source files: +`res/values/plurals.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<resources> + <plurals name="my_plural"> + <item quantity="one">@string/hello</item> + <item quantity="few">@string/hello</item> + <item quantity="other">@string/hello</item> + </plurals> +</resources> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +`res/values/plurals2.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<resources> + <plurals name="numberOfSongsAvailable"> + <item quantity="one">One song found.</item> + <item quantity="other">%d songs found.</item> + </plurals> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `res/values-pl/plurals2.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers diff --git a/docs/checks/MissingResourceImportAlias.md.html b/docs/checks/MissingResourceImportAlias.md.html new file mode 100644 index 00000000..8bf67c9e --- /dev/null +++ b/docs/checks/MissingResourceImportAlias.md.html @@ -0,0 +1,201 @@ + +(#) Missing import alias for R class + +!!! ERROR: Missing import alias for R class + This is an error. + +Id +: `MissingResourceImportAlias` +Summary +: Missing import alias for R class +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/resources/MissingResourceImportAliasDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/resources/MissingResourceImportAliasDetectorTest.kt) +Copyright Year +: 2022 + +Only the local module's R class is allowed to be imported without an +alias. Add an import alias for this. For example, import slack.l10n.R as +L10nR. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Options + +You can configure this lint checks using the following options: + +(###) import-aliases + +A comma-separated list of package name and their import aliases.. +This property should define a comma-separated list of package name and their import aliases in the format: packageName as importAlias + + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="MissingResourceImportAlias"> + <option name="import-aliases" value="some string" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/lint/test/pkg/MyClass.kt:3:Error: Use an import alias for R classes +from other modules [MissingResourceImportAlias] +import slack.l10n.R +------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/lint/test/pkg/MyClass.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package lint.test.pkg + +import slack.l10n.R + +class MyClass +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/resources/MissingResourceImportAliasDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MissingResourceImportAliasDetector.test failure no references`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MissingResourceImportAlias") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MissingResourceImportAlias") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MissingResourceImportAlias + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MissingResourceImportAlias" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MissingResourceImportAlias' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MissingResourceImportAlias ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MissingResourcesProperties.md.html b/docs/checks/MissingResourcesProperties.md.html new file mode 100644 index 00000000..2108e532 --- /dev/null +++ b/docs/checks/MissingResourcesProperties.md.html @@ -0,0 +1,108 @@ + +(#) Missing resources.properties file + +!!! WARNING: Missing resources.properties file + This is a warning. + +Id +: `MissingResourcesProperties` +Summary +: Missing resources.properties file +Severity +: Warning +Category +: Correctness +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.9.0 (March 2025) +Affects +: Gradle build files +Editing +: This check runs on the fly in the IDE editor +See +: https://developer.android.com/r/studio-ui/build/automatic-per-app-languages +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/MissingResourcesPropertiesDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/MissingResourcesPropertiesDetectorTest.kt) + +When `generateLocaleConfig` is turned on, the default locale must be +specified in a resources.properties file. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +build.gradle:5:Warning: Missing resources.properties file +[MissingResourcesProperties] + generateLocaleConfig true + -------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`build.gradle`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~groovy linenumbers +apply plugin: 'com.android.application' + +android { + androidResources { + generateLocaleConfig true + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/MissingResourcesPropertiesDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MissingResourcesProperties + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MissingResourcesProperties" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MissingResourcesProperties' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MissingResourcesProperties ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MissingScrollbars.md.html b/docs/checks/MissingScrollbars.md.html new file mode 100644 index 00000000..e8811395 --- /dev/null +++ b/docs/checks/MissingScrollbars.md.html @@ -0,0 +1,152 @@ + +(#) Scroll views should declare a scrollbar + +!!! WARNING: Scroll views should declare a scrollbar + This is a warning. + +Id +: `MissingScrollbars` +Summary +: Scroll views should declare a scrollbar +Severity +: Warning +Category +: Correctness +Platform +: Android +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html) +Since +: 0.24.0 +Affects +: Resource files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/main/kotlin/com/vanniktech/lintrules/android/MissingScrollbarsDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/MissingScrollbarsDetectorTest.kt) + +Every scroll view should explicitly define whether it has scrollbars +(none | vertical | horizontal). + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +res/layout/ids.xml:1:Warning: Missing scrollbars on ScrollView +[MissingScrollbars] +<ScrollView +^ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`res/layout/ids.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<ScrollView + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + /> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/MissingScrollbarsDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MissingScrollbarsDetector.scrollView`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-android:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-android:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.android) + +# libs.versions.toml +[versions] +lint-rules-android = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-android = { + module = "com.vanniktech:lint-rules-android", + version.ref = "lint-rules-android" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute `tools:ignore="MissingScrollbars"` + on the problematic XML element (or one of its enclosing elements). + You may also need to add the following namespace declaration on the + root element in the XML file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MissingScrollbars" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MissingScrollbars' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MissingScrollbars ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MissingSerializableAnnotation-2.md.html b/docs/checks/MissingSerializableAnnotation-2.md.html new file mode 100644 index 00000000..ad5ad41a --- /dev/null +++ b/docs/checks/MissingSerializableAnnotation-2.md.html @@ -0,0 +1,151 @@ + +(#) Type-safe NavDestinations must be annotated with @kotlinx.serialization.Serializable + +!!! ERROR: Type-safe NavDestinations must be annotated with @kotlinx.serialization.Serializable + This is an error. + +Id +: `MissingSerializableAnnotation` +Summary +: Type-safe NavDestinations must be annotated with @kotlinx.serialization.Serializable +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: Jetpack Navigation Compose +Identifier +: androidx.navigation.compose +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.7+ +Artifact +: [androidx.navigation:navigation-compose](androidx_navigation_navigation-compose.md.html) +Since +: 2.8.3 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/navigation/navigation-runtime-lint/src/main/java/androidx/navigation/runtime/lint/TypeSafeDestinationMissingAnnotationDetector.kt) +Copyright Year +: 2024 + +The destination needs to be annotated with @Serializable in order for +Navigation library to convert the class or object declaration into a +NavDestination. + +(##) Conflicts + +This issue id has also been used by other, unrelated lint checks. Issue +id's must be unique, so you cannot combine these libraries. Also defined +in: +* MissingSerializableAnnotation: Type-safe NavDestinations must be annotated with @kotlinx.serialization.Serializable (this issue) +* [MissingSerializableAnnotation from androidx.navigation:navigation-common:2.9.0-rc01](MissingSerializableAnnotation.md.html) +* [MissingSerializableAnnotation from androidx.navigation:navigation-runtime:2.9.0-rc01](MissingSerializableAnnotation-3.md.html) + + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.navigation:navigation-compose:2.9.0-rc01") + +// build.gradle +implementation 'androidx.navigation:navigation-compose:2.9.0-rc01' + +// build.gradle.kts with version catalogs: +implementation(libs.navigation.compose) + +# libs.versions.toml +[versions] +navigation-compose = "2.9.0-rc01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +navigation-compose = { + module = "androidx.navigation:navigation-compose", + version.ref = "navigation-compose" +} +``` + +2.9.0-rc01 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.navigation:navigation-compose](androidx_navigation_navigation-compose.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MissingSerializableAnnotation") + fun method() { + composable(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MissingSerializableAnnotation") + void method() { + composable(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MissingSerializableAnnotation + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MissingSerializableAnnotation" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MissingSerializableAnnotation' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MissingSerializableAnnotation ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MissingSerializableAnnotation-3.md.html b/docs/checks/MissingSerializableAnnotation-3.md.html new file mode 100644 index 00000000..1d0e458c --- /dev/null +++ b/docs/checks/MissingSerializableAnnotation-3.md.html @@ -0,0 +1,153 @@ + +(#) Type-safe NavDestinations must be annotated with @kotlinx.serialization.Serializable + +!!! ERROR: Type-safe NavDestinations must be annotated with @kotlinx.serialization.Serializable + This is an error. + +Id +: `MissingSerializableAnnotation` +Summary +: Type-safe NavDestinations must be annotated with @kotlinx.serialization.Serializable +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: Android Open Source Project +Identifier +: androidx.navigation.runtime +Feedback +: https://issuetracker.google.com/issues/new?component=409828 +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.7+ +Artifact +: [androidx.navigation:navigation-runtime](androidx_navigation_navigation-runtime.md.html) +Since +: 2.8.3 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/navigation/navigation-runtime-lint/src/main/java/androidx/navigation/runtime/lint/TypeSafeDestinationMissingAnnotationDetector.kt) +Copyright Year +: 2024 + +The destination needs to be annotated with @Serializable in order for +Navigation library to convert the class or object declaration into a +NavDestination. + +(##) Conflicts + +This issue id has also been used by other, unrelated lint checks. Issue +id's must be unique, so you cannot combine these libraries. Also defined +in: +* MissingSerializableAnnotation: Type-safe NavDestinations must be annotated with @kotlinx.serialization.Serializable (this issue) +* [MissingSerializableAnnotation from androidx.navigation:navigation-common:2.9.0-rc01](MissingSerializableAnnotation.md.html) +* [MissingSerializableAnnotation from androidx.navigation:navigation-compose:2.9.0-rc01](MissingSerializableAnnotation-2.md.html) + + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.navigation:navigation-runtime:2.9.0-rc01") + +// build.gradle +implementation 'androidx.navigation:navigation-runtime:2.9.0-rc01' + +// build.gradle.kts with version catalogs: +implementation(libs.navigation.runtime) + +# libs.versions.toml +[versions] +navigation-runtime = "2.9.0-rc01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +navigation-runtime = { + module = "androidx.navigation:navigation-runtime", + version.ref = "navigation-runtime" +} +``` + +2.9.0-rc01 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.navigation:navigation-runtime](androidx_navigation_navigation-runtime.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MissingSerializableAnnotation") + fun method() { + activity(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MissingSerializableAnnotation") + void method() { + activity(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MissingSerializableAnnotation + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MissingSerializableAnnotation" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MissingSerializableAnnotation' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MissingSerializableAnnotation ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MissingSerializableAnnotation.md.html b/docs/checks/MissingSerializableAnnotation.md.html new file mode 100644 index 00000000..41946204 --- /dev/null +++ b/docs/checks/MissingSerializableAnnotation.md.html @@ -0,0 +1,153 @@ + +(#) Type-safe NavDestinations must be annotated with @kotlinx.serialization.Serializable + +!!! ERROR: Type-safe NavDestinations must be annotated with @kotlinx.serialization.Serializable + This is an error. + +Id +: `MissingSerializableAnnotation` +Summary +: Type-safe NavDestinations must be annotated with @kotlinx.serialization.Serializable +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: Android Open Source Project +Identifier +: androidx.navigation.common +Feedback +: https://issuetracker.google.com/issues/new?component=409828 +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.7+ +Artifact +: [androidx.navigation:navigation-common](androidx_navigation_navigation-common.md.html) +Since +: 2.8.3 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/navigation/navigation-runtime-lint/src/main/java/androidx/navigation/runtime/lint/TypeSafeDestinationMissingAnnotationDetector.kt) +Copyright Year +: 2024 + +The destination needs to be annotated with @Serializable in order for +Navigation library to convert the class or object declaration into a +NavDestination. + +(##) Conflicts + +This issue id has also been used by other, unrelated lint checks. Issue +id's must be unique, so you cannot combine these libraries. Also defined +in: +* MissingSerializableAnnotation: Type-safe NavDestinations must be annotated with @kotlinx.serialization.Serializable (this issue) +* [MissingSerializableAnnotation from androidx.navigation:navigation-compose:2.9.0-rc01](MissingSerializableAnnotation-2.md.html) +* [MissingSerializableAnnotation from androidx.navigation:navigation-runtime:2.9.0-rc01](MissingSerializableAnnotation-3.md.html) + + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.navigation:navigation-common:2.9.0-rc01") + +// build.gradle +implementation 'androidx.navigation:navigation-common:2.9.0-rc01' + +// build.gradle.kts with version catalogs: +implementation(libs.navigation.common) + +# libs.versions.toml +[versions] +navigation-common = "2.9.0-rc01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +navigation-common = { + module = "androidx.navigation:navigation-common", + version.ref = "navigation-common" +} +``` + +2.9.0-rc01 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.navigation:navigation-common](androidx_navigation_navigation-common.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MissingSerializableAnnotation") + fun method() { + navigation(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MissingSerializableAnnotation") + void method() { + navigation(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MissingSerializableAnnotation + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MissingSerializableAnnotation" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MissingSerializableAnnotation' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MissingSerializableAnnotation ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MissingSuperCall.md.html b/docs/checks/MissingSuperCall.md.html index 9066ba39..73b36641 100644 --- a/docs/checks/MissingSuperCall.md.html +++ b/docs/checks/MissingSuperCall.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files Editing @@ -41,11 +43,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/ParentClass.kt:11:Error: Overriding method should call super.someMethod [MissingSuperCall] - override fun someMethod(arg: Int) { ---------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/MissingTranslation.md.html b/docs/checks/MissingTranslation.md.html index 43949a60..92a533f9 100644 --- a/docs/checks/MissingTranslation.md.html +++ b/docs/checks/MissingTranslation.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Binary resource files, resource files and resource folders Editing @@ -54,29 +56,20 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/values/strings.xml:20:Error: "show_all_apps" is not translated in "nl" (Dutch) [MissingTranslation] - <string name="show_all_apps">All</string> -------------------- - - res/values/strings.xml:23:Error: "menu_wallpaper" is not translated in "nl" (Dutch) [MissingTranslation] - <string name="menu_wallpaper">Wallpaper</string> --------------------- - - res/values/strings.xml:25:Error: "menu_settings" is not translated in "cs" (Czech), "de" (German), "es" (Spanish), "nl" (Dutch) [MissingTranslation] - <string name="menu_settings">Settings</string> -------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `res/values/strings.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -113,6 +106,146 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/values-cs/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="UTF-8"?> +<resources xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + <string name="home_title">"Domů"</string> + <string name="show_all_apps">"Vše"</string> + <string name="menu_wallpaper">"Tapeta"</string> + <string name="menu_search">"Hledat"</string> + <!-- no translation found for menu_settings (1769059051084007158) --> + <skip /> + <string name="wallpaper_instructions">"Klepnutím na obrázek nastavíte tapetu portrétu"</string> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/values-de-rDE/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="UTF-8"?> +<resources xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + <string name="home_title">"Startseite"</string> + <string name="show_all_apps">"Alle"</string> + <string name="menu_wallpaper">"Bildschirmhintergrund"</string> + <string name="menu_search">"Suchen"</string> + <!-- no translation found for menu_settings (1769059051084007158) --> + <skip /> + <string name="wallpaper_instructions">"Tippen Sie auf Bild, um Porträt-Bildschirmhintergrund einzustellen"</string> + <string name="continue_skip_label">"Weiter"</string> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/values-es/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="UTF-8"?> +<resources xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + <string name="home_title">"Casa"</string> + <string name="show_all_apps">"Todo"</string> + <string name="menu_wallpaper">"Papel tapiz"</string> + <string name="menu_search">"Búsqueda"</string> + <!-- no translation found for menu_settings (1769059051084007158) --> + <skip /> + <string name="wallpaper_instructions">"Puntee en la imagen para establecer papel tapiz vertical"</string> + + <string-array name="security_questions"> + <item>"Comida favorita"</item> + <item>"Ciudad de nacimiento"</item> + <item>"Nombre de tu mejor amigo/a de la infancia"</item> + <item>"Nombre de tu colegio"</item> + </string-array> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/values-es-rUS/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="UTF-8"?> +<resources xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + <string name="menu_search">"Búsqueda"</string> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/values-land/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2007 The Android Open Source Project + + 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. +--> + +<resources> + <!-- Wallpaper --> + <string name="wallpaper_instructions">Tap image to set landscape wallpaper</string> +</resources> + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/values-cs/arrays.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<resources xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + <string-array name="security_questions"> + <item>"Oblíbené jídlo?"</item> + <item>"Město narození."</item> + <item>"Jméno nejlepšího kamaráda z dětství?"</item> + <item>"Název střední školy"</item> + </string-array> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/values-es/donottranslate.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + <string name="full_wday_month_day_no_year">EEEE, d MMMM</string> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/values-nl-rNL/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="UTF-8"?> +<resources xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + <string name="home_title">"Start"</string> + <!-- Commented out in the unit test to generate extra warnings: + <string name="show_all_apps">"Alles"</string> + <string name="menu_wallpaper">"Achtergrond"</string> + --> + <string name="menu_search">"Zoeken"</string> + <!-- no translation found for menu_settings (1769059051084007158) --> + <skip /> + <string name="wallpaper_instructions">"Tik op afbeelding om portretachtergrond in te stellen"</string> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/values/public.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<resources><public /></resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/layout/foo.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<LinearLayout/> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/layout-ja/foo.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<LinearLayout/> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/TranslationDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/MissingTvBanner.md.html b/docs/checks/MissingTvBanner.md.html index dec9a5a6..cd667135 100644 --- a/docs/checks/MissingTvBanner.md.html +++ b/docs/checks/MissingTvBanner.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 1.5.0 (November 2015) Affects : Manifest files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AndroidTvDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AndroidTvDetectorTest.java) -Copyright Year -: 2015 A TV application must provide a home screen banner for each localization if it includes a Leanback launcher intent filter. The banner is the app @@ -45,11 +45,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text AndroidManifest.xml:5:Error: Expecting android:banner with the tag or each Leanback launcher activity [MissingTvBanner] - <application> ----------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/MissingVersion.md.html b/docs/checks/MissingVersion.md.html index ba860a4e..f9e04dea 100644 --- a/docs/checks/MissingVersion.md.html +++ b/docs/checks/MissingVersion.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Manifest files Editing @@ -48,11 +50,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text AndroidManifest.xml:1:Warning: Should set android:versionName to specify the application version [MissingVersion] - <manifest xmlns:android="http://schemas.android.com/apk/res/android" -------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/MissingXmlHeader.md.html b/docs/checks/MissingXmlHeader.md.html new file mode 100644 index 00000000..136c9832 --- /dev/null +++ b/docs/checks/MissingXmlHeader.md.html @@ -0,0 +1,148 @@ + +(#) Flags xml files that don't have a header + +!!! WARNING: Flags xml files that don't have a header + This is a warning. + +Id +: `MissingXmlHeader` +Summary +: Flags xml files that don't have a header +Severity +: Warning +Category +: Correctness +Platform +: Android +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html) +Since +: 0.6.0 +Affects +: Resource files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/main/kotlin/com/vanniktech/lintrules/android/MissingXmlHeaderDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/MissingXmlHeaderDetectorTest.kt) + +An xml file should always have the xml header to declare that it is an +xml file despite the file ending. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +res/values/strings.xml:1:Warning: Missing an xml header +[MissingXmlHeader] +<resources/> +------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`res/values/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<resources/> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/MissingXmlHeaderDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MissingXmlHeaderDetector.missingHeader`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-android:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-android:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.android) + +# libs.versions.toml +[versions] +lint-rules-android = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-android = { + module = "com.vanniktech:lint-rules-android", + version.ref = "lint-rules-android" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute `tools:ignore="MissingXmlHeader"` + on the problematic XML element (or one of its enclosing elements). + You may also need to add the following namespace declaration on the + root element in the XML file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MissingXmlHeader" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MissingXmlHeader' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MissingXmlHeader ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MockLocation.md.html b/docs/checks/MockLocation.md.html index 6cbe6a08..4e075a68 100644 --- a/docs/checks/MockLocation.md.html +++ b/docs/checks/MockLocation.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Manifest files Editing @@ -51,16 +53,41 @@ src/main/AndroidManifest.xml:8:Error: Mock locations should only be requested in a test or debug-specific manifest file (typically src/debug/AndroidManifest.xml) [MockLocation] - <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" /> ------------------------------------------------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Here are the relevant source files: +`src/main/AndroidManifest.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="foo.bar2" + android:versionCode="1" + android:versionName="1.0" > + + <uses-sdk android:minSdkVersion="14" /> + <uses-permission android:name="com.example.helloworld.permission" /> + <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" /> + +</manifest> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +`src/debug/AndroidManifest.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="foo.bar2" + android:versionCode="1" + android:versionName="1.0" > -`src/main/AndroidManifest.xml`: + <uses-sdk android:minSdkVersion="14" /> + <uses-permission android:name="com.example.helloworld.permission" /> + <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" /> + +</manifest> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/AndroidManifest.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="foo.bar2" @@ -74,6 +101,20 @@ </manifest> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`build.gradle`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~groovy linenumbers +android { + compileSdkVersion 25 + defaultConfig { + applicationId "com.android.tools.test" + minSdkVersion 5 + targetSdkVersion 16 + versionCode 2 + versionName "MyName" + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ManifestDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/ModifierFactoryExtensionFunction.md.html b/docs/checks/ModifierFactoryExtensionFunction.md.html index f09a711c..b9456d7c 100644 --- a/docs/checks/ModifierFactoryExtensionFunction.md.html +++ b/docs/checks/ModifierFactoryExtensionFunction.md.html @@ -20,6 +20,14 @@ : androidx.compose.ui Feedback : https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.ui:ui-android](androidx_compose_ui_ui-android.md.html) +Since +: 1.5.0 Affects : Kotlin and Java files and test sources Editing @@ -34,67 +42,56 @@ Modifier factory functions should be defined as extension functions on Modifier to allow modifiers to be fluently chained. +!!! Tip + This lint check has an associated quickfix available in the IDE. + (##) Example Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -src/androidx/compose/ui/foo/TestModifier.kt:8:Warning: Modifier factory +src/androidx/compose/ui/foo/test.kt:6:Warning: Modifier factory functions should be extensions on Modifier [ModifierFactoryExtensionFunction] - fun fooModifier(): Modifier { ----------- - - -src/androidx/compose/ui/foo/TestModifier.kt:12:Warning: Modifier factory +src/androidx/compose/ui/foo/test.kt:10:Warning: Modifier factory functions should be extensions on Modifier [ModifierFactoryExtensionFunction] - val fooModifier get(): Modifier { ----------- - - -src/androidx/compose/ui/foo/TestModifier.kt:16:Warning: Modifier factory +src/androidx/compose/ui/foo/test.kt:14:Warning: Modifier factory functions should be extensions on Modifier [ModifierFactoryExtensionFunction] - val fooModifier2: Modifier get() { ------------ - - -src/androidx/compose/ui/foo/TestModifier.kt:20:Warning: Modifier factory +src/androidx/compose/ui/foo/test.kt:18:Warning: Modifier factory functions should be extensions on Modifier [ModifierFactoryExtensionFunction] - - val fooModifier3: Modifier get() = TestModifier + val fooModifier3: Modifier get() = Modifier ------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: -`src/androidx/compose/ui/foo/TestModifier.kt`: +`src/androidx/compose/ui/foo/test.kt`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers package androidx.compose.ui.foo import androidx.compose.ui.Modifier -object TestModifier : Modifier.Element - fun fooModifier(): Modifier { - return this.then(TestModifier) + return Modifier } val fooModifier get(): Modifier { - return this.then(TestModifier) + return Modifier } val fooModifier2: Modifier get() { - return this.then(TestModifier) + return Modifier } -val fooModifier3: Modifier get() = TestModifier +val fooModifier3: Modifier get() = Modifier ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can also visit the @@ -106,6 +103,44 @@ To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=612128. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.ui:ui-android:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.ui:ui-android:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.ui.android) + +# libs.versions.toml +[versions] +ui-android = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +ui-android = { + module = "androidx.compose.ui:ui-android", + version.ref = "ui-android" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.ui:ui-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.ui:ui-android](androidx_compose_ui_ui-android.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/ModifierFactoryReturnType.md.html b/docs/checks/ModifierFactoryReturnType.md.html index 5084ddaf..a0e9149c 100644 --- a/docs/checks/ModifierFactoryReturnType.md.html +++ b/docs/checks/ModifierFactoryReturnType.md.html @@ -20,6 +20,14 @@ : androidx.compose.ui Feedback : https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.ui:ui-android](androidx_compose_ui_ui-android.md.html) +Since +: 1.5.0 Affects : Kotlin and Java files and test sources Editing @@ -41,11 +49,8 @@ src/androidx/compose/ui/foo/TestModifier.kt:8:Warning: Modifier factory functions should have a return type of Modifier [ModifierFactoryReturnType] - fun Modifier.fooModifier(): Modifier.Element { ----------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -59,7 +64,7 @@ object TestModifier : Modifier.Element fun Modifier.fooModifier(): Modifier.Element { - return this.then(TestModifier) + return TestModifier } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -72,6 +77,44 @@ To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=612128. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.ui:ui-android:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.ui:ui-android:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.ui.android) + +# libs.versions.toml +[versions] +ui-android = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +ui-android = { + module = "androidx.compose.ui:ui-android", + version.ref = "ui-android" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.ui:ui-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.ui:ui-android](androidx_compose_ui_ui-android.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/ModifierFactoryUnreferencedReceiver.md.html b/docs/checks/ModifierFactoryUnreferencedReceiver.md.html index 51f44583..687cc0aa 100644 --- a/docs/checks/ModifierFactoryUnreferencedReceiver.md.html +++ b/docs/checks/ModifierFactoryUnreferencedReceiver.md.html @@ -20,6 +20,14 @@ : androidx.compose.ui Feedback : https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.ui:ui-android](androidx_compose_ui_ui-android.md.html) +Since +: 1.5.0 Affects : Kotlin and Java files and test sources Editing @@ -48,11 +56,8 @@ src/androidx/compose/ui/foo/TestModifier.kt:8:Error: Modifier factory functions must use the receiver Modifier instance [ModifierFactoryUnreferencedReceiver] - - fun Modifier.fooModifier() = TestModifier + fun Modifier.fooModifier(): Modifier.Element { ----------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -65,7 +70,9 @@ object TestModifier : Modifier.Element -fun Modifier.fooModifier() = TestModifier +fun Modifier.fooModifier(): Modifier.Element { + return TestModifier +} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can also visit the @@ -73,10 +80,48 @@ for the unit tests for this check to see additional scenarios. The above example was automatically extracted from the first unit test -found for this lint check, `ModifierDeclarationDetector.functionImplicitlyReturnsModifierElement`. +found for this lint check, `ModifierDeclarationDetector.functionReturnsModifierElement`. To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=612128. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.ui:ui-android:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.ui:ui-android:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.ui.android) + +# libs.versions.toml +[versions] +ui-android = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +ui-android = { + module = "androidx.compose.ui:ui-android", + version.ref = "ui-android" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.ui:ui-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.ui:ui-android](androidx_compose_ui_ui-android.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/ModifierNodeInspectableProperties.md.html b/docs/checks/ModifierNodeInspectableProperties.md.html new file mode 100644 index 00000000..2dc83874 --- /dev/null +++ b/docs/checks/ModifierNodeInspectableProperties.md.html @@ -0,0 +1,190 @@ + +(#) ModifierNodeElement missing inspectableProperties + +!!! Tip: ModifierNodeElement missing inspectableProperties + Advice from this check is just a hint; it's a "weak" warning. + +Id +: `ModifierNodeInspectableProperties` +Summary +: ModifierNodeElement missing inspectableProperties +Severity +: Hint +Category +: Productivity +Platform +: Any +Vendor +: Jetpack Compose +Identifier +: androidx.compose.ui +Feedback +: https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.ui:ui-android](androidx_compose_ui_ui-android.md.html) +Since +: 1.5.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/ui/ui-lint/src/main/java/androidx/compose/ui/lint/ModifierNodeInspectablePropertiesDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/ui/ui-lint/src/test/java/androidx/compose/ui/lint/ModifierNodeInspectablePropertiesDetectorTest.kt) +Copyright Year +: 2023 + +ModifierNodeElements may override inspectableProperties() to provide +information about the modifier in the layout inspector. The default +implementation attempts to read all of the properties on the class +reflectively, which may not comprehensively or effectively describe the +modifier. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test/Element.kt:8:Information: Element does not override +inspectableProperties(). The layout inspector will use the default +implementation of this function, which will attempt to read Element's +properties reflectively. Override inspectableProperties() if you'd like +to customize this modifier's presentation in the layout inspector. +[ModifierNodeInspectableProperties] + class Element : ModifierNodeElement<Modifier.Node>() { + ------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test/Element.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test + +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.InspectableValue +import androidx.compose.ui.node.ModifierNodeElement + +class Element : ModifierNodeElement() { + override fun create() = object : Modifier.Node() {} + override fun update(node: Modifier.Node) = node +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/ui/ui-lint/src/test/java/androidx/compose/ui/lint/ModifierNodeInspectablePropertiesDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `ModifierNodeInspectablePropertiesDetector.testNodeElementWithNoInspectableValues_flagsError`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=612128. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.ui:ui-android:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.ui:ui-android:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.ui.android) + +# libs.versions.toml +[versions] +ui-android = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +ui-android = { + module = "androidx.compose.ui:ui-android", + version.ref = "ui-android" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.ui:ui-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.ui:ui-android](androidx_compose_ui_ui-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ModifierNodeInspectableProperties") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ModifierNodeInspectableProperties") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ModifierNodeInspectableProperties + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ModifierNodeInspectableProperties" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ModifierNodeInspectableProperties' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ModifierNodeInspectableProperties ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ModifierParameter.md.html b/docs/checks/ModifierParameter.md.html index 8cb113e3..5960babe 100644 --- a/docs/checks/ModifierParameter.md.html +++ b/docs/checks/ModifierParameter.md.html @@ -20,6 +20,14 @@ : androidx.compose.ui Feedback : https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.ui:ui-android](androidx_compose_ui_ui-android.md.html) +Since +: 1.5.0 Affects : Kotlin and Java files and test sources Editing @@ -47,11 +55,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/androidx/compose/ui/foo/test.kt:10:Warning: Modifier parameter should be named modifier [ModifierParameter] - buttonModifier: Modifier = Modifier, -------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -81,6 +86,44 @@ To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=612128. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.ui:ui-android:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.ui:ui-android:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.ui.android) + +# libs.versions.toml +[versions] +ui-android = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +ui-android = { + module = "androidx.compose.ui:ui-android", + version.ref = "ui-android" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.ui:ui-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.ui:ui-android](androidx_compose_ui_ui-android.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/ModuleCompanionObjects.md.html b/docs/checks/ModuleCompanionObjects.md.html new file mode 100644 index 00000000..e6ed3885 --- /dev/null +++ b/docs/checks/ModuleCompanionObjects.md.html @@ -0,0 +1,288 @@ + +(#) Module companion objects should not be annotated with @Module + +!!! WARNING: Module companion objects should not be annotated with @Module + This is a warning. + +Id +: `ModuleCompanionObjects` +Summary +: Module companion objects should not be annotated with @Module +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: Google +Identifier +: com.google.dagger:dagger-lint +Contact +: https://github.com/google/dagger +Feedback +: https://github.com/google/dagger/issues +Min +: Lint 7.3 and 7.4 +Compiled +: Lint 7.1 +Artifact +: [com.google.dagger:dagger-lint](com_google_dagger_dagger-lint.md.html) +Since +: 2.40.2 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/google/dagger/tree/master/java/dagger/lint/DaggerKotlinIssueDetector.kt) +Tests +: [Source Code](https://github.com/google/dagger/tree/master/javatests/dagger/lint/DaggerKotlinIssueDetectorTest.kt) +Copyright Year +: 2020 + +Companion objects in @Module-annotated classes are considered part of +the API. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/MyQualifier.kt:66:Warning: Module companion objects should not +be annotated with @Module. [ModuleCompanionObjects] + // This should fail because the companion object is part of ClassModule + ^ +src/foo/MyQualifier.kt:78:Warning: Module companion objects should not +be annotated with @Module. [ModuleCompanionObjects] + // This should fail because the companion object is part of ClassModule + ^ +src/foo/MyQualifier.kt:101:Warning: Module companion objects should not +be annotated with @Module. [ModuleCompanionObjects] + // This is should fail because this should be extracted to a standalone object. + ^ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/MyQualifier.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package foo +import javax.inject.Inject +import javax.inject.Qualifier +import kotlin.jvm.JvmStatic +import dagger.Provides +import dagger.Module + +@Qualifier +annotation class MyQualifier + +class InjectedTest { + // This should fail because of `:field` + @Inject + @field:MyQualifier + lateinit var prop: String + + // This is fine! + @Inject + @MyQualifier + lateinit var prop2: String +} + +@Module +object ObjectModule { + // This should fail because it uses `@JvmStatic` + @JvmStatic + @Provides + fun provideFoo(): String { + + } + + // This is fine! + @Provides + fun provideBar(): String { + + } +} + +@Module +class ClassModule { + companion object { + // This should fail because the companion object is part of ClassModule, so this is unnecessary. + @JvmStatic + @Provides + fun provideBaz(): String { + + } + } +} + +@Module +class ClassModuleQualified { + companion object { + // This should fail because the companion object is part of ClassModule, so this is unnecessary. + // This specifically tests a fully qualified annotation + @kotlin.jvm.JvmStatic + @Provides + fun provideBaz(): String { + + } + } +} + +@Module +class ClassModule2 { + // This should fail because the companion object is part of ClassModule + @Module + companion object { + @Provides + fun provideBaz(): String { + + } + } +} + +@Module +class ClassModule2Qualified { + // This should fail because the companion object is part of ClassModule + // This specifically tests a fully qualified annotation + @dagger.Module + companion object { + @Provides + fun provideBaz(): String { + + } + } +} + +// This is correct as of Dagger 2.26! +@Module +class ClassModule3 { + companion object { + @Provides + fun provideBaz(): String { + + } + } +} + +class ClassModule4 { + // This is should fail because this should be extracted to a standalone object. + @Module + companion object { + @Provides + fun provideBaz(): String { + + } + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/google/dagger/tree/master/javatests/dagger/lint/DaggerKotlinIssueDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `DaggerKotlinIssueDetector.simpleSmokeTestForQualifiersAndProviders`. +To report a problem with this extracted sample, visit +https://github.com/google/dagger/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("com.google.dagger:dagger-lint:2.56.2") + +// build.gradle +implementation 'com.google.dagger:dagger-lint:2.56.2' + +// build.gradle.kts with version catalogs: +implementation(libs.dagger.lint) + +# libs.versions.toml +[versions] +dagger-lint = "2.56.2" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +dagger-lint = { + module = "com.google.dagger:dagger-lint", + version.ref = "dagger-lint" +} +``` + +2.56.2 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.google.dagger:dagger-lint](com_google_dagger_dagger-lint.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ModuleCompanionObjects") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ModuleCompanionObjects") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ModuleCompanionObjects + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ModuleCompanionObjects" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ModuleCompanionObjects' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ModuleCompanionObjects ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ModuleCompanionObjectsNotInModuleParent.md.html b/docs/checks/ModuleCompanionObjectsNotInModuleParent.md.html new file mode 100644 index 00000000..86ed952a --- /dev/null +++ b/docs/checks/ModuleCompanionObjectsNotInModuleParent.md.html @@ -0,0 +1,151 @@ + +(#) Companion objects should not be annotated with @Module + +!!! WARNING: Companion objects should not be annotated with @Module + This is a warning. + +Id +: `ModuleCompanionObjectsNotInModuleParent` +Summary +: Companion objects should not be annotated with @Module +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: Google +Identifier +: com.google.dagger:dagger-lint +Contact +: https://github.com/google/dagger +Feedback +: https://github.com/google/dagger/issues +Min +: Lint 7.3 and 7.4 +Compiled +: Lint 7.1 +Artifact +: [com.google.dagger:dagger-lint](com_google_dagger_dagger-lint.md.html) +Since +: 2.40.2 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/google/dagger/tree/master/java/dagger/lint/DaggerKotlinIssueDetector.kt) +Tests +: [Source Code](https://github.com/google/dagger/tree/master/javatests/dagger/lint/DaggerKotlinIssueDetectorTest.kt) +Copyright Year +: 2020 + +Companion objects in @Module-annotated classes are considered part of +the API. This +companion object is not a companion to an @Module-annotated class +though, and should be +moved to a top-level object declaration instead otherwise Dagger will +ignore companion +object. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("com.google.dagger:dagger-lint:2.56.2") + +// build.gradle +implementation 'com.google.dagger:dagger-lint:2.56.2' + +// build.gradle.kts with version catalogs: +implementation(libs.dagger.lint) + +# libs.versions.toml +[versions] +dagger-lint = "2.56.2" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +dagger-lint = { + module = "com.google.dagger:dagger-lint", + version.ref = "dagger-lint" +} +``` + +2.56.2 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.google.dagger:dagger-lint](com_google_dagger_dagger-lint.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ModuleCompanionObjectsNotInModuleParent") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ModuleCompanionObjectsNotInModuleParent") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ModuleCompanionObjectsNotInModuleParent + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ModuleCompanionObjectsNotInModuleParent" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ModuleCompanionObjectsNotInModuleParent' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ModuleCompanionObjectsNotInModuleParent ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MonochromeLauncherIcon.md.html b/docs/checks/MonochromeLauncherIcon.md.html index 903e37c2..2cff9ecd 100644 --- a/docs/checks/MonochromeLauncherIcon.md.html +++ b/docs/checks/MonochromeLauncherIcon.md.html @@ -18,16 +18,16 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.4.0 (January 2023) Affects -: Manifest files and resource files +: Resource files Editing -: This check can *not* run live in the IDE editor +: This check runs on the fly in the IDE editor Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/MonochromeLauncherIconDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/MonochromeLauncherIconDetectorTest.kt) -Copyright Year -: 2022 If `android:roundIcon` and `android:icon` are both in your manifest, you must either remove the reference to `android:roundIcon` if it is not @@ -46,18 +46,12 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/drawable-ldpi/ic_icon.xml:2:Warning: The application adaptive icon is missing a monochrome tag [MonochromeLauncherIcon] - <adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> ^ - - res/drawable-ldpi/ic_round_icon.xml:2:Warning: The application adaptive roundIcon is missing a monochrome tag [MonochromeLauncherIcon] - <adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> ^ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here are the relevant source files: @@ -106,11 +100,10 @@ ```xml <?xml version="1.0" encoding="UTF-8"?> - <manifest xmlns:tools="http://schemas.android.com/tools"> - ... - <application tools:ignore="MonochromeLauncherIcon" .../> + <adaptive-icon xmlns:tools="http://schemas.android.com/tools" + tools:ignore="MonochromeLauncherIcon" ...> ... - </manifest> + </adaptive-icon> ``` * Using a special `lint.xml` file in the source tree which turns off diff --git a/docs/checks/MoshiUsageAdaptedByRequiresAdapter.md.html b/docs/checks/MoshiUsageAdaptedByRequiresAdapter.md.html new file mode 100644 index 00000000..774b5275 --- /dev/null +++ b/docs/checks/MoshiUsageAdaptedByRequiresAdapter.md.html @@ -0,0 +1,209 @@ + +(#) @AdaptedBy.adapter must be a JsonAdapter or JsonAdapter.Factory + +!!! ERROR: @AdaptedBy.adapter must be a JsonAdapter or JsonAdapter.Factory + This is an error. + +Id +: `MoshiUsageAdaptedByRequiresAdapter` +Summary +: @AdaptedBy.adapter must be a JsonAdapter or JsonAdapter.Factory +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +@AdaptedBy.adapter must be a subclass of JsonAdapter or implement +JsonAdapter.Factory. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/Example1.kt:14:Error: @AdaptedBy.adapter must be a +JsonAdapter or JsonAdapter.Factory. +[MoshiUsageAdaptedByRequiresAdapter] +@AdaptedBy(NotAnAdapter::class) + ------------------- +src/slack/model/Example1.kt:20:Error: @AdaptedBy.adapter must be a +JsonAdapter or JsonAdapter.Factory. +[MoshiUsageAdaptedByRequiresAdapter] + @AdaptedBy(NotAnAdapter::class) val value2: String + ------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/model/Example1.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import androidx.annotation.Keep +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.JsonClass +import dev.zacsweers.moshix.adapters.AdaptedBy + +@AdaptedBy(CustomFactory::class) +class Example1(val value: String) + +@AdaptedBy(CustomAdapter::class) +class Example2(val value: String) + +@AdaptedBy(NotAnAdapter::class) +class Example3 + +@JsonClass(generateAdapter = true) +data class Example3( + @AdaptedBy(CustomAdapter::class) val value1: String, + @AdaptedBy(NotAnAdapter::class) val value2: String +) + +@AdaptedBy(CustomAdapterMissingKeep::class) +class Example4 + +@Keep +abstract class CustomFactory : JsonAdapter.Factory +@Keep +abstract class CustomAdapter : JsonAdapter() +class NotAnAdapter +abstract class CustomAdapterMissingKeep : JsonAdapter() +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.valid_adapters`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageAdaptedByRequiresAdapter") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageAdaptedByRequiresAdapter") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageAdaptedByRequiresAdapter + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageAdaptedByRequiresAdapter" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageAdaptedByRequiresAdapter' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageAdaptedByRequiresAdapter ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageAdaptedByRequiresKeep.md.html b/docs/checks/MoshiUsageAdaptedByRequiresKeep.md.html new file mode 100644 index 00000000..c88b0d01 --- /dev/null +++ b/docs/checks/MoshiUsageAdaptedByRequiresKeep.md.html @@ -0,0 +1,203 @@ + +(#) Adapters targeted by @AdaptedBy must have @Keep + +!!! ERROR: Adapters targeted by @AdaptedBy must have @Keep + This is an error. + +Id +: `MoshiUsageAdaptedByRequiresKeep` +Summary +: Adapters targeted by @AdaptedBy must have @Keep +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +Adapters targeted by @AdaptedBy must be annotated with @Keep in order to +be reflectively looked up at runtime. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/Example1.kt:23:Error: Adapters targeted by @AdaptedBy +must have @Keep. [MoshiUsageAdaptedByRequiresKeep] +@AdaptedBy(CustomAdapterMissingKeep::class) + ------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/model/Example1.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import androidx.annotation.Keep +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.JsonClass +import dev.zacsweers.moshix.adapters.AdaptedBy + +@AdaptedBy(CustomFactory::class) +class Example1(val value: String) + +@AdaptedBy(CustomAdapter::class) +class Example2(val value: String) + +@AdaptedBy(NotAnAdapter::class) +class Example3 + +@JsonClass(generateAdapter = true) +data class Example3( + @AdaptedBy(CustomAdapter::class) val value1: String, + @AdaptedBy(NotAnAdapter::class) val value2: String +) + +@AdaptedBy(CustomAdapterMissingKeep::class) +class Example4 + +@Keep +abstract class CustomFactory : JsonAdapter.Factory +@Keep +abstract class CustomAdapter : JsonAdapter() +class NotAnAdapter +abstract class CustomAdapterMissingKeep : JsonAdapter() +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.valid_adapters`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageAdaptedByRequiresKeep") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageAdaptedByRequiresKeep") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageAdaptedByRequiresKeep + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageAdaptedByRequiresKeep" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageAdaptedByRequiresKeep' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageAdaptedByRequiresKeep ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageArray.md.html b/docs/checks/MoshiUsageArray.md.html new file mode 100644 index 00000000..2d03812d --- /dev/null +++ b/docs/checks/MoshiUsageArray.md.html @@ -0,0 +1,268 @@ + +(#) Prefer List over Array + +!!! WARNING: Prefer List over Array + This is a warning. + +Id +: `MoshiUsageArray` +Summary +: Prefer List over Array +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +Array types are not supported by Moshi, please use a List instead. +Arrays are expensive to manage in JSON as we don't know lengths ahead of +time and they are a mutable code smell in what should be immutable value +classes. Otherwise, moshi-gson-interop will hand serialization of this +property to Gson, which may or may not handle it. This will eventually +become an error after GSON is removed. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/Example.kt:43:Warning: Prefer List over Array. +[MoshiUsageArray] + val arrayType: Array<String>, + ------------- +src/slack/model/Example.kt:44:Warning: Prefer List over Array. +[MoshiUsageArray] + val intArray: IntArray, + -------- +src/slack/model/Example.kt:45:Warning: Prefer List over Array. +[MoshiUsageArray] + val boolArray: BooleanArray, + ------------ +src/slack/model/Example.kt:46:Warning: Prefer List over Array. +[MoshiUsageArray] + val complexArray: Array<List<String>>, + ------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`src/external/ExternalType.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package external + +class ExternalType +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/external/ExternalTypeAnnotated.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package external + +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class ExternalTypeAnnotated(val value: String) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/slack/model/Example.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import androidx.annotation.Keep +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.JsonClass +import java.util.ArrayList +import java.util.HashSet +import java.util.HashMap +import java.util.Date +import external.ExternalType +import external.ExternalTypeAnnotated +import slack.InternalType +import slack.InternalTypeAnnotated +import slack.InternalTypeAnnotated2 +import dev.zacsweers.moshix.adapters.AdaptedBy +import test.CustomQualifier + +@JsonClass(generateAdapter = true) +data class Example( + // collections + val okList: List, + val okSet: Set, + val okCollection: Collection, + val okMap: Map, + val concreteList: ArrayList, + val concreteSet: HashSet, + val concreteMap: HashMap, + // platform + val platformType: Date, + @AdaptedBy(DateFactory::class) val adaptedByOk: Date, + // external + val externalType: ExternalType, + val externalTypeAnnotated: ExternalTypeAnnotated, + // internal + val internalType: InternalType, + val internalTypeAnnotated: InternalTypeAnnotated, + val internalTypeAnnotated2: InternalTypeAnnotated2, + val int: Int, + val string: String, + val nullableString: String?, + val any: Any, + // Arrays + val arrayType: Array, + val intArray: IntArray, + val boolArray: BooleanArray, + val complexArray: Array>, + val badGeneric: List, + val badGeneric2: CustomGenericType, + val badNestedGeneric: CustomGenericType>, + // This would normally error but since it has a custom qualifier we skip the check + @CustomQualifier val customQualifier: Date, + // Mutable collections + val mutableList: MutableList, + val mutableSet: MutableSet, + val mutableCollection: MutableCollection, + val mutableMap: MutableMap +) + +@Keep +abstract class DateFactory : JsonAdapter.Factory + +@JsonClass(generateAdapter = true) +data class CustomGenericType(val value: T) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.propertyTypes`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageArray") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageArray") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageArray + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageArray" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageArray' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageArray ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageBlankGenerator.md.html b/docs/checks/MoshiUsageBlankGenerator.md.html new file mode 100644 index 00000000..94b5a8e6 --- /dev/null +++ b/docs/checks/MoshiUsageBlankGenerator.md.html @@ -0,0 +1,178 @@ + +(#) Don't use blank JsonClass.generator values + +!!! ERROR: Don't use blank JsonClass.generator values + This is an error. + +Id +: `MoshiUsageBlankGenerator` +Summary +: Don't use blank JsonClass.generator values +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +The default for JsonClass.generator is "", it's redundant to specify an +empty one and an error to specify a blank one. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/Example.kt:5:Error: Don't use blank JsonClass.generator +values. [MoshiUsageBlankGenerator] +@JsonClass(generateAdapter = true, generator = "") + -- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/model/Example.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true, generator = "") +data class Example(val value: String) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.empty_generator`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageBlankGenerator") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageBlankGenerator") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageBlankGenerator + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageBlankGenerator" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageBlankGenerator' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageBlankGenerator ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageBlankJsonName.md.html b/docs/checks/MoshiUsageBlankJsonName.md.html new file mode 100644 index 00000000..0c573097 --- /dev/null +++ b/docs/checks/MoshiUsageBlankJsonName.md.html @@ -0,0 +1,180 @@ + +(#) Don't use blank names in `@Json` + +!!! ERROR: Don't use blank names in `@Json` + This is an error. + +Id +: `MoshiUsageBlankJsonName` +Summary +: Don't use blank names in `@Json` +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +Blank names in `@Json`, while technically legal, are likely a programmer +error and +likely to cause encoding issues. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/Example.kt:7:Error: Don't use blank names in @Json. +[MoshiUsageBlankJsonName] +data class Example(@Json(name = "") val value: String) + -- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/model/Example.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import com.squareup.moshi.JsonClass +import com.squareup.moshi.Json + +@JsonClass(generateAdapter = true) +data class Example(@Json(name = "") val value: String) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.empty_json_name`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageBlankJsonName") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageBlankJsonName") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageBlankJsonName + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageBlankJsonName" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageBlankJsonName' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageBlankJsonName ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageBlankTypeLabel.md.html b/docs/checks/MoshiUsageBlankTypeLabel.md.html new file mode 100644 index 00000000..fab1192d --- /dev/null +++ b/docs/checks/MoshiUsageBlankTypeLabel.md.html @@ -0,0 +1,178 @@ + +(#) Moshi-sealed requires a type label specified after the 'sealed:' prefix + +!!! ERROR: Moshi-sealed requires a type label specified after the 'sealed:' prefix + This is an error. + +Id +: `MoshiUsageBlankTypeLabel` +Summary +: Moshi-sealed requires a type label specified after the 'sealed:' prefix +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +Moshi-sealed requires a type label specified after the 'sealed:' +prefix. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/BaseType.kt:5:Error: Moshi-sealed requires a type label +specified after the 'sealed:' prefix. [MoshiUsageBlankTypeLabel] +@JsonClass(generateAdapter = true, generator = "sealed:") + ------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/model/BaseType.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true, generator = "sealed:") +sealed class BaseType +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.sealed_blank_type`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageBlankTypeLabel") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageBlankTypeLabel") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageBlankTypeLabel + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageBlankTypeLabel" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageBlankTypeLabel' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageBlankTypeLabel ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageClassVisibility.md.html b/docs/checks/MoshiUsageClassVisibility.md.html new file mode 100644 index 00000000..2bae1d28 --- /dev/null +++ b/docs/checks/MoshiUsageClassVisibility.md.html @@ -0,0 +1,192 @@ + +(#) @JsonClass-annotated types must be public, package-private, or internal + +!!! ERROR: @JsonClass-annotated types must be public, package-private, or internal + This is an error. + +Id +: `MoshiUsageClassVisibility` +Summary +: @JsonClass-annotated types must be public, package-private, or internal +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +@JsonClass-annotated types must be public, package-private, or internal. +Otherwise, Moshi +will not be able to access them from generated adapters. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/PrivateClass.kt:6:Error: @JsonClass-annotated types must +be public, package-private, or internal. [MoshiUsageClassVisibility] +private data class PrivateClass(val value: String) +------- +src/slack/model/PrivateClass.kt:10:Error: @JsonClass-annotated types +must be public, package-private, or internal. +[MoshiUsageClassVisibility] + protected data class ProtectedClass(val value: String) + --------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/model/PrivateClass.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +private data class PrivateClass(val value: String) + +open class EnclosingClass { + @JsonClass(generateAdapter = true) + protected data class ProtectedClass(val value: String) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.unsupported_visibility`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageClassVisibility") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageClassVisibility") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageClassVisibility + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageClassVisibility" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageClassVisibility' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageClassVisibility ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageDoubleClassAnnotation.md.html b/docs/checks/MoshiUsageDoubleClassAnnotation.md.html new file mode 100644 index 00000000..4d53bd38 --- /dev/null +++ b/docs/checks/MoshiUsageDoubleClassAnnotation.md.html @@ -0,0 +1,192 @@ + +(#) Only use one of @AdaptedBy or @JsonClass + +!!! ERROR: Only use one of @AdaptedBy or @JsonClass + This is an error. + +Id +: `MoshiUsageDoubleClassAnnotation` +Summary +: Only use one of @AdaptedBy or @JsonClass +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +Only one of @AdaptedBy and @JsonClass annotations should be present. It +is an error to declare both! + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/Example.kt:8:Error: Only use one of @AdaptedBy or +@JsonClass. [MoshiUsageDoubleClassAnnotation] +@JsonClass(generateAdapter = true) +---------------------------------- +src/slack/model/Example.kt:9:Error: Only use one of @AdaptedBy or +@JsonClass. [MoshiUsageDoubleClassAnnotation] +@AdaptedBy(CustomFactory::class) +-------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/model/Example.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import androidx.annotation.Keep +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.JsonClass +import dev.zacsweers.moshix.adapters.AdaptedBy + +@JsonClass(generateAdapter = true) +@AdaptedBy(CustomFactory::class) +data class Example(val value: String) + +@Keep +abstract class CustomFactory : JsonAdapter.Factory +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.double_class_annotation`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageDoubleClassAnnotation") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageDoubleClassAnnotation") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageDoubleClassAnnotation + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageDoubleClassAnnotation" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageDoubleClassAnnotation' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageDoubleClassAnnotation ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageDoubleTypeLabel.md.html b/docs/checks/MoshiUsageDoubleTypeLabel.md.html new file mode 100644 index 00000000..4e40cd58 --- /dev/null +++ b/docs/checks/MoshiUsageDoubleTypeLabel.md.html @@ -0,0 +1,191 @@ + +(#) Only use one of @TypeLabel or @DefaultObject + +!!! ERROR: Only use one of @TypeLabel or @DefaultObject + This is an error. + +Id +: `MoshiUsageDoubleTypeLabel` +Summary +: Only use one of @TypeLabel or @DefaultObject +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +Only one of @TypeLabel and @DefaultObject annotations should be present. +It is an error to declare both! + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/BaseType.kt:10:Error: Only use one of @TypeLabel or +@DefaultObject. [MoshiUsageDoubleTypeLabel] +@TypeLabel(label = "one") +------------------------- +src/slack/model/BaseType.kt:11:Error: Only use one of @TypeLabel or +@DefaultObject. [MoshiUsageDoubleTypeLabel] +@DefaultObject +-------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/model/BaseType.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import com.squareup.moshi.JsonClass +import dev.zacsweers.moshix.sealed.annotations.TypeLabel +import dev.zacsweers.moshix.sealed.annotations.DefaultObject + +@JsonClass(generateAdapter = true, generator = "sealed:type") +sealed class BaseType + +@TypeLabel(label = "one") +@DefaultObject +object Default : BaseType() +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.sealed_double_annotation`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageDoubleTypeLabel") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageDoubleTypeLabel") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageDoubleTypeLabel + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageDoubleTypeLabel" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageDoubleTypeLabel' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageDoubleTypeLabel ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageDuplicateJsonName.md.html b/docs/checks/MoshiUsageDuplicateJsonName.md.html new file mode 100644 index 00000000..ac8c9c94 --- /dev/null +++ b/docs/checks/MoshiUsageDuplicateJsonName.md.html @@ -0,0 +1,196 @@ + +(#) Duplicate JSON names are errors as JSON does not allow duplicate keys in objects + +!!! ERROR: Duplicate JSON names are errors as JSON does not allow duplicate keys in objects + This is an error. + +Id +: `MoshiUsageDuplicateJsonName` +Summary +: Duplicate JSON names are errors as JSON does not allow duplicate keys in objects +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +Duplicate JSON names are errors as JSON does not allow duplicate keys in +objects. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/Example.kt:8:Error: Name 'value' is duplicated by member +'anotherValue'. [MoshiUsageDuplicateJsonName] + val value: String, + ----- +src/slack/model/Example.kt:9:Error: Name 'value' is duplicated by member +'value'. [MoshiUsageDuplicateJsonName] + @Json(name = "value") val anotherValue: String, + ------------ +src/slack/model/Example.kt:10:Error: Name 'value2' is duplicated by +member 'anotherValue3'. [MoshiUsageDuplicateJsonName] + @Json(name = "value2") val anotherValue2: String, + ------------- +src/slack/model/Example.kt:11:Error: Name 'value2' is duplicated by +member 'anotherValue2'. [MoshiUsageDuplicateJsonName] + @Json(name = "value2") val anotherValue3: String + ------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/model/Example.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class Example( + val value: String, + @Json(name = "value") val anotherValue: String, + @Json(name = "value2") val anotherValue2: String, + @Json(name = "value2") val anotherValue3: String +) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.duplicateNames`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageDuplicateJsonName") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageDuplicateJsonName") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageDuplicateJsonName + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageDuplicateJsonName" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageDuplicateJsonName' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageDuplicateJsonName ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageEnumAnnotatedUnknown.md.html b/docs/checks/MoshiUsageEnumAnnotatedUnknown.md.html new file mode 100644 index 00000000..2524acc0 --- /dev/null +++ b/docs/checks/MoshiUsageEnumAnnotatedUnknown.md.html @@ -0,0 +1,148 @@ + +(#) UNKNOWN members in @JsonClass-annotated enums should not be annotated with @Json + +!!! ERROR: UNKNOWN members in @JsonClass-annotated enums should not be annotated with @Json + This is an error. + +Id +: `MoshiUsageEnumAnnotatedUnknown` +Summary +: UNKNOWN members in @JsonClass-annotated enums should not be annotated with @Json +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +UNKNOWN members in @JsonClass-annotated enums should not be annotated +with @Json. These members are only used as a fallback and never expected +in actual JSON bodies. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageEnumAnnotatedUnknown") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageEnumAnnotatedUnknown") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageEnumAnnotatedUnknown + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageEnumAnnotatedUnknown" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageEnumAnnotatedUnknown' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageEnumAnnotatedUnknown ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageEnumCasing.md.html b/docs/checks/MoshiUsageEnumCasing.md.html new file mode 100644 index 00000000..5b4fe95a --- /dev/null +++ b/docs/checks/MoshiUsageEnumCasing.md.html @@ -0,0 +1,148 @@ + +(#) Consider using `@Json(name = ...)` rather than lower casing + +!!! WARNING: Consider using `@Json(name = ...)` rather than lower casing + This is a warning. + +Id +: `MoshiUsageEnumCasing` +Summary +: Consider using `@Json(name = ...)` rather than lower casing +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +Moshi offers `@Json` annotations to specify names to use in JSON +serialization, similar to Gson's `@SerializedName`. This can help avoid +lower-casing enum properties in source directly. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageEnumCasing") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageEnumCasing") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageEnumCasing + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageEnumCasing" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageEnumCasing' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageEnumCasing ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageEnumJsonClassGenerated.md.html b/docs/checks/MoshiUsageEnumJsonClassGenerated.md.html new file mode 100644 index 00000000..49c945ec --- /dev/null +++ b/docs/checks/MoshiUsageEnumJsonClassGenerated.md.html @@ -0,0 +1,147 @@ + +(#) Enums annotated with @JsonClass must not set `generateAdapter` to true + +!!! ERROR: Enums annotated with @JsonClass must not set `generateAdapter` to true + This is an error. + +Id +: `MoshiUsageEnumJsonClassGenerated` +Summary +: Enums annotated with @JsonClass must not set `generateAdapter` to true +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +Enums annotated with @JsonClass do not need to set "generateAdapter" to +true and should set it to false. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageEnumJsonClassGenerated") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageEnumJsonClassGenerated") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageEnumJsonClassGenerated + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageEnumJsonClassGenerated" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageEnumJsonClassGenerated' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageEnumJsonClassGenerated ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageEnumMissingJsonClass.md.html b/docs/checks/MoshiUsageEnumMissingJsonClass.md.html new file mode 100644 index 00000000..083c5165 --- /dev/null +++ b/docs/checks/MoshiUsageEnumMissingJsonClass.md.html @@ -0,0 +1,148 @@ + +(#) Enums serialized with Moshi should be annotated with @JsonClass + +!!! ERROR: Enums serialized with Moshi should be annotated with @JsonClass + This is an error. + +Id +: `MoshiUsageEnumMissingJsonClass` +Summary +: Enums serialized with Moshi should be annotated with @JsonClass +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +This enum appears to use Moshi for serialization. Please also add an +@JsonClass annotation to it to ensure safe handling with unknown values +and R8 optimization. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageEnumMissingJsonClass") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageEnumMissingJsonClass") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageEnumMissingJsonClass + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageEnumMissingJsonClass" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageEnumMissingJsonClass' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageEnumMissingJsonClass ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageEnumMissingUnknown.md.html b/docs/checks/MoshiUsageEnumMissingUnknown.md.html new file mode 100644 index 00000000..7bab1eff --- /dev/null +++ b/docs/checks/MoshiUsageEnumMissingUnknown.md.html @@ -0,0 +1,148 @@ + +(#) Enums serialized with Moshi must reserve the first member as UNKNOWN + +!!! ERROR: Enums serialized with Moshi must reserve the first member as UNKNOWN + This is an error. + +Id +: `MoshiUsageEnumMissingUnknown` +Summary +: Enums serialized with Moshi must reserve the first member as UNKNOWN +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +For backward compatibility, enums serialized with Moshi must reserve the +first member as "UNKNOWN". We will automatically substitute this when +encountering an unrecognized value for this enum during decoding. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageEnumMissingUnknown") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageEnumMissingUnknown") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageEnumMissingUnknown + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageEnumMissingUnknown" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageEnumMissingUnknown' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageEnumMissingUnknown ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageEnumPropertyCouldBeMoshi.md.html b/docs/checks/MoshiUsageEnumPropertyCouldBeMoshi.md.html new file mode 100644 index 00000000..8dd678d0 --- /dev/null +++ b/docs/checks/MoshiUsageEnumPropertyCouldBeMoshi.md.html @@ -0,0 +1,184 @@ + +(#) Consider making enum properties also use Moshi + +!!! WARNING: Consider making enum properties also use Moshi + This is a warning. + +Id +: `MoshiUsageEnumPropertyCouldBeMoshi` +Summary +: Consider making enum properties also use Moshi +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +While we have Gson interop, it's convenient to move enums used by Moshi +classes to also use Moshi so that you can leverage built-in support for +UNKNOWN handling and get lint checks for it. Simply add `@JsonClass` to +this enum class and the appropriate lint will guide you. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/Example.kt:6:Warning: Consider making enum properties +also use Moshi. [MoshiUsageEnumPropertyCouldBeMoshi] +data class Example(val value: TestEnum) + -------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/model/Example.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class Example(val value: TestEnum) + +enum class TestEnum { + VALUE +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.enum_prop_suggest_moshi`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageEnumPropertyCouldBeMoshi") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageEnumPropertyCouldBeMoshi") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageEnumPropertyCouldBeMoshi + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageEnumPropertyCouldBeMoshi" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageEnumPropertyCouldBeMoshi' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageEnumPropertyCouldBeMoshi ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageEnumPropertyDefaultUnknown.md.html b/docs/checks/MoshiUsageEnumPropertyDefaultUnknown.md.html new file mode 100644 index 00000000..73573297 --- /dev/null +++ b/docs/checks/MoshiUsageEnumPropertyDefaultUnknown.md.html @@ -0,0 +1,203 @@ + +(#) Suspicious default value to 'UNKNOWN' for a Moshi enum + +!!! ERROR: Suspicious default value to 'UNKNOWN' for a Moshi enum + This is an error. + +Id +: `MoshiUsageEnumPropertyDefaultUnknown` +Summary +: Suspicious default value to 'UNKNOWN' for a Moshi enum +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +The enum type of this property is handled by Moshi. This means it will +default to 'UNKNOWN' if an unrecognized enum is encountered in decoding. +At best, it is redundant to default a property to this value. At worst, +it can change nullability semantics if the enum should actually allow +nullable values or null on absence. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/Example.kt:9:Error: Suspicious default value to +'UNKNOWN' for a Moshi enum. [MoshiUsageEnumPropertyDefaultUnknown] + val value3: TestEnum? = UNKNOWN, + ------- +src/slack/model/Example.kt:10:Error: Suspicious default value to +'UNKNOWN' for a Moshi enum. [MoshiUsageEnumPropertyDefaultUnknown] + val value4: TestEnum = UNKNOWN, + ------- +src/slack/model/Example.kt:11:Error: Suspicious default value to +'UNKNOWN' for a Moshi enum. [MoshiUsageEnumPropertyDefaultUnknown] + val value5: TestEnum = TestEnum.UNKNOWN, + ---------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/model/Example.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class Example( + val value1: TestEnum?, + val value2: TestEnum? = null, + val value3: TestEnum? = UNKNOWN, + val value4: TestEnum = UNKNOWN, + val value5: TestEnum = TestEnum.UNKNOWN, +) + +@JsonClass(generateAdapter = false) +enum class TestEnum { + UNKNOWN, VALUE +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.enum_prop_default_unknown`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageEnumPropertyDefaultUnknown") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageEnumPropertyDefaultUnknown") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageEnumPropertyDefaultUnknown + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageEnumPropertyDefaultUnknown" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageEnumPropertyDefaultUnknown' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageEnumPropertyDefaultUnknown ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageGenerateAdapterShouldBeTrue.md.html b/docs/checks/MoshiUsageGenerateAdapterShouldBeTrue.md.html new file mode 100644 index 00000000..35a30bf3 --- /dev/null +++ b/docs/checks/MoshiUsageGenerateAdapterShouldBeTrue.md.html @@ -0,0 +1,179 @@ + +(#) JsonClass.generateAdapter must be true in order for Moshi code gen to run + +!!! ERROR: JsonClass.generateAdapter must be true in order for Moshi code gen to run + This is an error. + +Id +: `MoshiUsageGenerateAdapterShouldBeTrue` +Summary +: JsonClass.generateAdapter must be true in order for Moshi code gen to run +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +JsonClass.generateAdapter must be true in order for Moshi code gen to +run. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/Example.kt:5:Error: JsonClass.generateAdapter must be +true in order for Moshi code gen to run. +[MoshiUsageGenerateAdapterShouldBeTrue] +@JsonClass(generateAdapter = false) + ----- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/model/Example.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = false) +data class Example(val value: String) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.generateAdapter_should_be_true`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageGenerateAdapterShouldBeTrue") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageGenerateAdapterShouldBeTrue") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageGenerateAdapterShouldBeTrue + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageGenerateAdapterShouldBeTrue" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageGenerateAdapterShouldBeTrue' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageGenerateAdapterShouldBeTrue ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageGenericSealedSubtype.md.html b/docs/checks/MoshiUsageGenericSealedSubtype.md.html new file mode 100644 index 00000000..5a56edca --- /dev/null +++ b/docs/checks/MoshiUsageGenericSealedSubtype.md.html @@ -0,0 +1,189 @@ + +(#) Sealed subtypes used with moshi-sealed cannot be generic + +!!! ERROR: Sealed subtypes used with moshi-sealed cannot be generic + This is an error. + +Id +: `MoshiUsageGenericSealedSubtype` +Summary +: Sealed subtypes used with moshi-sealed cannot be generic +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +Moshi has no way of conveying generics information to sealed subtypes +when we create an adapter from the base type. As a result, you should +remove generics from this subtype. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/BaseType.kt:11:Error: Sealed subtypes used with +moshi-sealed cannot be generic. [MoshiUsageGenericSealedSubtype] +data class Subtype<T>(val foo: T) : BaseType<T>() + --- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/model/BaseType.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import com.squareup.moshi.JsonClass +import dev.zacsweers.moshix.sealed.annotations.TypeLabel + +@JsonClass(generateAdapter = true, generator = "sealed:type") +sealed class BaseType + +@TypeLabel(label = "one") +@JsonClass(generateAdapter = true) +data class Subtype(val foo: T) : BaseType() + +// This is "ok" generics use because the subtype itself has none +@TypeLabel(label = "two") +@JsonClass(generateAdapter = true) +data class SubtypeTwo(val foo: String) : BaseType() +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.sealed_generic`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageGenericSealedSubtype") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageGenericSealedSubtype") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageGenericSealedSubtype + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageGenericSealedSubtype" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageGenericSealedSubtype' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageGenericSealedSubtype ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageInappropriateTypeLabel.md.html b/docs/checks/MoshiUsageInappropriateTypeLabel.md.html new file mode 100644 index 00000000..9878a87f --- /dev/null +++ b/docs/checks/MoshiUsageInappropriateTypeLabel.md.html @@ -0,0 +1,199 @@ + +(#) Inappropriate @TypeLabel or @DefaultObject annotation + +!!! ERROR: Inappropriate @TypeLabel or @DefaultObject annotation + This is an error. + +Id +: `MoshiUsageInappropriateTypeLabel` +Summary +: Inappropriate @TypeLabel or @DefaultObject annotation +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +This class declares a @TypeLabel or @DefaultObject annotation but does +not appear to subclass a sealed Moshi type. Please remove these +annotations or extend the appropriate sealed Moshi-serialized class. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/Subtype.kt:7:Error: Inappropriate @TypeLabel or +@DefaultObject annotation. [MoshiUsageInappropriateTypeLabel] +@TypeLabel(label = "one") +------------------------- +src/slack/model/Subtype.kt:11:Error: Inappropriate @TypeLabel or +@DefaultObject annotation. [MoshiUsageInappropriateTypeLabel] +@TypeLabel(label = "two") +------------------------- +src/slack/model/Subtype.kt:14:Error: Inappropriate @TypeLabel or +@DefaultObject annotation. [MoshiUsageInappropriateTypeLabel] +@DefaultObject +-------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/model/Subtype.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import com.squareup.moshi.JsonClass +import dev.zacsweers.moshix.sealed.annotations.TypeLabel +import dev.zacsweers.moshix.sealed.annotations.DefaultObject + +@TypeLabel(label = "one") +@JsonClass(generateAdapter = true) +data class Subtype(val foo: String) + +@TypeLabel(label = "two") +object ObjectSubType + +@DefaultObject +object Default +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.sealed_missing_base_type`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageInappropriateTypeLabel") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageInappropriateTypeLabel") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageInappropriateTypeLabel + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageInappropriateTypeLabel" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageInappropriateTypeLabel' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageInappropriateTypeLabel ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageMissingPrimary.md.html b/docs/checks/MoshiUsageMissingPrimary.md.html new file mode 100644 index 00000000..a0210d83 --- /dev/null +++ b/docs/checks/MoshiUsageMissingPrimary.md.html @@ -0,0 +1,180 @@ + +(#) @JsonClass-annotated types must have a primary constructor or be sealed + +!!! ERROR: @JsonClass-annotated types must have a primary constructor or be sealed + This is an error. + +Id +: `MoshiUsageMissingPrimary` +Summary +: @JsonClass-annotated types must have a primary constructor or be sealed +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +@JsonClass-annotated types must have a primary constructor or be sealed. +Otherwise, they either have no serializable properties or all the +potentially serializable properties are mutable (which is not a case we +want!). + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/Example.kt:6:Error: @JsonClass-annotated types must have +a primary constructor or be sealed. [MoshiUsageMissingPrimary] +class Example + ------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/model/Example.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +class Example +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.missing_primary`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageMissingPrimary") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageMissingPrimary") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageMissingPrimary + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageMissingPrimary" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageMissingPrimary' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageMissingPrimary ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageMissingTypeLabel.md.html b/docs/checks/MoshiUsageMissingTypeLabel.md.html new file mode 100644 index 00000000..34899556 --- /dev/null +++ b/docs/checks/MoshiUsageMissingTypeLabel.md.html @@ -0,0 +1,189 @@ + +(#) Sealed Moshi subtypes must be annotated with @TypeLabel or @DefaultObject + +!!! ERROR: Sealed Moshi subtypes must be annotated with @TypeLabel or @DefaultObject + This is an error. + +Id +: `MoshiUsageMissingTypeLabel` +Summary +: Sealed Moshi subtypes must be annotated with @TypeLabel or @DefaultObject +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +moshi-sealed requires sealed subtypes to be annotated with @TypeLabel or +@DefaultObject. Otherwise, moshi-sealed will fail to compile. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/BaseType.kt:9:Error: Sealed Moshi subtypes must be +annotated with @TypeLabel or @DefaultObject. +[MoshiUsageMissingTypeLabel] +data class Subtype(val foo: String) : BaseType() + ------- +src/slack/model/BaseType.kt:11:Error: Sealed Moshi subtypes must be +annotated with @TypeLabel or @DefaultObject. +[MoshiUsageMissingTypeLabel] +object ObjectSubType : BaseType() + ------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/model/BaseType.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true, generator = "sealed:type") +sealed class BaseType + +@JsonClass(generateAdapter = true) +data class Subtype(val foo: String) : BaseType() + +object ObjectSubType : BaseType() +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.sealed_missing_type_label`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageMissingTypeLabel") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageMissingTypeLabel") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageMissingTypeLabel + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageMissingTypeLabel" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageMissingTypeLabel' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageMissingTypeLabel ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageMutableCollections.md.html b/docs/checks/MoshiUsageMutableCollections.md.html new file mode 100644 index 00000000..cd57d683 --- /dev/null +++ b/docs/checks/MoshiUsageMutableCollections.md.html @@ -0,0 +1,265 @@ + +(#) Use immutable collections rather than mutable versions + +!!! ERROR: Use immutable collections rather than mutable versions + This is an error. + +Id +: `MoshiUsageMutableCollections` +Summary +: Use immutable collections rather than mutable versions +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +While mutable collections are technically possible, they should not be +used with Moshi classes as it can lead to asymmetric encoding and +thread-safety issues. Please make them immutable versions instead. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/Example.kt:53:Error: Use immutable collections rather +than mutable versions. [MoshiUsageMutableCollections] + val mutableList: MutableList<Int>, + ---------------- +src/slack/model/Example.kt:54:Error: Use immutable collections rather +than mutable versions. [MoshiUsageMutableCollections] + val mutableSet: MutableSet<Int>, + --------------- +src/slack/model/Example.kt:55:Error: Use immutable collections rather +than mutable versions. [MoshiUsageMutableCollections] + val mutableCollection: MutableCollection<Int>, + ---------------------- +src/slack/model/Example.kt:56:Error: Use immutable collections rather +than mutable versions. [MoshiUsageMutableCollections] + val mutableMap: MutableMap<String, String> + -------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`src/external/ExternalType.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package external + +class ExternalType +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/external/ExternalTypeAnnotated.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package external + +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class ExternalTypeAnnotated(val value: String) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/slack/model/Example.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import androidx.annotation.Keep +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.JsonClass +import java.util.ArrayList +import java.util.HashSet +import java.util.HashMap +import java.util.Date +import external.ExternalType +import external.ExternalTypeAnnotated +import slack.InternalType +import slack.InternalTypeAnnotated +import slack.InternalTypeAnnotated2 +import dev.zacsweers.moshix.adapters.AdaptedBy +import test.CustomQualifier + +@JsonClass(generateAdapter = true) +data class Example( + // collections + val okList: List, + val okSet: Set, + val okCollection: Collection, + val okMap: Map, + val concreteList: ArrayList, + val concreteSet: HashSet, + val concreteMap: HashMap, + // platform + val platformType: Date, + @AdaptedBy(DateFactory::class) val adaptedByOk: Date, + // external + val externalType: ExternalType, + val externalTypeAnnotated: ExternalTypeAnnotated, + // internal + val internalType: InternalType, + val internalTypeAnnotated: InternalTypeAnnotated, + val internalTypeAnnotated2: InternalTypeAnnotated2, + val int: Int, + val string: String, + val nullableString: String?, + val any: Any, + // Arrays + val arrayType: Array, + val intArray: IntArray, + val boolArray: BooleanArray, + val complexArray: Array>, + val badGeneric: List, + val badGeneric2: CustomGenericType, + val badNestedGeneric: CustomGenericType>, + // This would normally error but since it has a custom qualifier we skip the check + @CustomQualifier val customQualifier: Date, + // Mutable collections + val mutableList: MutableList, + val mutableSet: MutableSet, + val mutableCollection: MutableCollection, + val mutableMap: MutableMap +) + +@Keep +abstract class DateFactory : JsonAdapter.Factory + +@JsonClass(generateAdapter = true) +data class CustomGenericType(val value: T) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.propertyTypes`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageMutableCollections") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageMutableCollections") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageMutableCollections + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageMutableCollections" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageMutableCollections' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageMutableCollections ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageNonMoshiClassCollection.md.html b/docs/checks/MoshiUsageNonMoshiClassCollection.md.html new file mode 100644 index 00000000..a046009c --- /dev/null +++ b/docs/checks/MoshiUsageNonMoshiClassCollection.md.html @@ -0,0 +1,261 @@ + +(#) Concrete Collection type '%HINT%' is not natively supported by Moshi + +!!! Tip: Concrete Collection type '%HINT%' is not natively supported by Moshi + Advice from this check is just a hint; it's a "weak" warning. + +Id +: `MoshiUsageNonMoshiClassCollection` +Summary +: Concrete Collection type '%HINT%' is not natively supported by Moshi +Severity +: Hint +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +The property type is concrete Collection type (i.e. ArrayList, HashSet, +etc). Moshi only natively supports their interface types (List, Set, +etc). Consider upcasting to the +interface type. Otherwise, moshi-gson-interop will hand serialization of +this property to Gson, which may or may not handle it. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/Example.kt:25:Information: Concrete Collection type +'ArrayList' is not natively supported by Moshi. +[MoshiUsageNonMoshiClassCollection] + val concreteList: ArrayList<Int>, + -------------- +src/slack/model/Example.kt:26:Information: Concrete Collection type +'HashSet' is not natively supported by Moshi. +[MoshiUsageNonMoshiClassCollection] + val concreteSet: HashSet<Int>, + ------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`src/external/ExternalType.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package external + +class ExternalType +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/external/ExternalTypeAnnotated.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package external + +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class ExternalTypeAnnotated(val value: String) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/slack/model/Example.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import androidx.annotation.Keep +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.JsonClass +import java.util.ArrayList +import java.util.HashSet +import java.util.HashMap +import java.util.Date +import external.ExternalType +import external.ExternalTypeAnnotated +import slack.InternalType +import slack.InternalTypeAnnotated +import slack.InternalTypeAnnotated2 +import dev.zacsweers.moshix.adapters.AdaptedBy +import test.CustomQualifier + +@JsonClass(generateAdapter = true) +data class Example( + // collections + val okList: List, + val okSet: Set, + val okCollection: Collection, + val okMap: Map, + val concreteList: ArrayList, + val concreteSet: HashSet, + val concreteMap: HashMap, + // platform + val platformType: Date, + @AdaptedBy(DateFactory::class) val adaptedByOk: Date, + // external + val externalType: ExternalType, + val externalTypeAnnotated: ExternalTypeAnnotated, + // internal + val internalType: InternalType, + val internalTypeAnnotated: InternalTypeAnnotated, + val internalTypeAnnotated2: InternalTypeAnnotated2, + val int: Int, + val string: String, + val nullableString: String?, + val any: Any, + // Arrays + val arrayType: Array, + val intArray: IntArray, + val boolArray: BooleanArray, + val complexArray: Array>, + val badGeneric: List, + val badGeneric2: CustomGenericType, + val badNestedGeneric: CustomGenericType>, + // This would normally error but since it has a custom qualifier we skip the check + @CustomQualifier val customQualifier: Date, + // Mutable collections + val mutableList: MutableList, + val mutableSet: MutableSet, + val mutableCollection: MutableCollection, + val mutableMap: MutableMap +) + +@Keep +abstract class DateFactory : JsonAdapter.Factory + +@JsonClass(generateAdapter = true) +data class CustomGenericType(val value: T) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.propertyTypes`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageNonMoshiClassCollection") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageNonMoshiClassCollection") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageNonMoshiClassCollection + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageNonMoshiClassCollection" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageNonMoshiClassCollection' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageNonMoshiClassCollection ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageNonMoshiClassExternal.md.html b/docs/checks/MoshiUsageNonMoshiClassExternal.md.html new file mode 100644 index 00000000..f9b3bee4 --- /dev/null +++ b/docs/checks/MoshiUsageNonMoshiClassExternal.md.html @@ -0,0 +1,269 @@ + +(#) External type '%HINT%' is not natively supported by Moshi + +!!! ERROR: External type '%HINT%' is not natively supported by Moshi + This is an error. + +Id +: `MoshiUsageNonMoshiClassExternal` +Summary +: External type '%HINT%' is not natively supported by Moshi +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +The property type is an external type (i.e. not a Slack or built-in +type). Moshi will try +to serialize these reflectively, which is not something we want. Either +write a custom adapter and annotating this property with `@AdaptedBy` or +exclude/remove this type's use. Otherwise, moshi-gson-interop will hand +serialization of this property to Gson, which may or may not handle it +(also with reflection). + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/Example.kt:32:Error: External type 'ExternalType' is not +natively supported by Moshi. [MoshiUsageNonMoshiClassExternal] + val externalType: ExternalType, + ------------ +src/slack/model/Example.kt:47:Error: External type 'ExternalType' is not +natively supported by Moshi. [MoshiUsageNonMoshiClassExternal] + val badGeneric: List<ExternalType>, + ------------------ +src/slack/model/Example.kt:48:Error: External type 'ExternalType' is not +natively supported by Moshi. [MoshiUsageNonMoshiClassExternal] + val badGeneric2: CustomGenericType<ExternalType>, + ------------------------------- +src/slack/model/Example.kt:49:Error: External type 'ExternalType' is not +natively supported by Moshi. [MoshiUsageNonMoshiClassExternal] + val badNestedGeneric: CustomGenericType<List<ExternalType>>, + ------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`src/external/ExternalType.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package external + +class ExternalType +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/external/ExternalTypeAnnotated.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package external + +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class ExternalTypeAnnotated(val value: String) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/slack/model/Example.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import androidx.annotation.Keep +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.JsonClass +import java.util.ArrayList +import java.util.HashSet +import java.util.HashMap +import java.util.Date +import external.ExternalType +import external.ExternalTypeAnnotated +import slack.InternalType +import slack.InternalTypeAnnotated +import slack.InternalTypeAnnotated2 +import dev.zacsweers.moshix.adapters.AdaptedBy +import test.CustomQualifier + +@JsonClass(generateAdapter = true) +data class Example( + // collections + val okList: List, + val okSet: Set, + val okCollection: Collection, + val okMap: Map, + val concreteList: ArrayList, + val concreteSet: HashSet, + val concreteMap: HashMap, + // platform + val platformType: Date, + @AdaptedBy(DateFactory::class) val adaptedByOk: Date, + // external + val externalType: ExternalType, + val externalTypeAnnotated: ExternalTypeAnnotated, + // internal + val internalType: InternalType, + val internalTypeAnnotated: InternalTypeAnnotated, + val internalTypeAnnotated2: InternalTypeAnnotated2, + val int: Int, + val string: String, + val nullableString: String?, + val any: Any, + // Arrays + val arrayType: Array, + val intArray: IntArray, + val boolArray: BooleanArray, + val complexArray: Array>, + val badGeneric: List, + val badGeneric2: CustomGenericType, + val badNestedGeneric: CustomGenericType>, + // This would normally error but since it has a custom qualifier we skip the check + @CustomQualifier val customQualifier: Date, + // Mutable collections + val mutableList: MutableList, + val mutableSet: MutableSet, + val mutableCollection: MutableCollection, + val mutableMap: MutableMap +) + +@Keep +abstract class DateFactory : JsonAdapter.Factory + +@JsonClass(generateAdapter = true) +data class CustomGenericType(val value: T) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.propertyTypes`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageNonMoshiClassExternal") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageNonMoshiClassExternal") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageNonMoshiClassExternal + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageNonMoshiClassExternal" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageNonMoshiClassExternal' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageNonMoshiClassExternal ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageNonMoshiClassInternal.md.html b/docs/checks/MoshiUsageNonMoshiClassInternal.md.html new file mode 100644 index 00000000..57000e93 --- /dev/null +++ b/docs/checks/MoshiUsageNonMoshiClassInternal.md.html @@ -0,0 +1,255 @@ + +(#) Non-Moshi internal type '%HINT%' is not natively supported by Moshi + +!!! Tip: Non-Moshi internal type '%HINT%' is not natively supported by Moshi + Advice from this check is just a hint; it's a "weak" warning. + +Id +: `MoshiUsageNonMoshiClassInternal` +Summary +: Non-Moshi internal type '%HINT%' is not natively supported by Moshi +Severity +: Hint +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +The property type is an internal type (i.e. slack.*) but is not a Moshi +class itself. moshi-gson-interop will hand serialization of this +property to Gson, but consider converting this type to Moshi as well to +improve runtime performance and consistency. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/Example.kt:35:Information: Non-Moshi internal type +'InternalType' is not natively supported by Moshi. +[MoshiUsageNonMoshiClassInternal] + val internalType: InternalType, + ------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`src/external/ExternalType.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package external + +class ExternalType +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/external/ExternalTypeAnnotated.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package external + +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class ExternalTypeAnnotated(val value: String) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/slack/model/Example.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import androidx.annotation.Keep +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.JsonClass +import java.util.ArrayList +import java.util.HashSet +import java.util.HashMap +import java.util.Date +import external.ExternalType +import external.ExternalTypeAnnotated +import slack.InternalType +import slack.InternalTypeAnnotated +import slack.InternalTypeAnnotated2 +import dev.zacsweers.moshix.adapters.AdaptedBy +import test.CustomQualifier + +@JsonClass(generateAdapter = true) +data class Example( + // collections + val okList: List, + val okSet: Set, + val okCollection: Collection, + val okMap: Map, + val concreteList: ArrayList, + val concreteSet: HashSet, + val concreteMap: HashMap, + // platform + val platformType: Date, + @AdaptedBy(DateFactory::class) val adaptedByOk: Date, + // external + val externalType: ExternalType, + val externalTypeAnnotated: ExternalTypeAnnotated, + // internal + val internalType: InternalType, + val internalTypeAnnotated: InternalTypeAnnotated, + val internalTypeAnnotated2: InternalTypeAnnotated2, + val int: Int, + val string: String, + val nullableString: String?, + val any: Any, + // Arrays + val arrayType: Array, + val intArray: IntArray, + val boolArray: BooleanArray, + val complexArray: Array>, + val badGeneric: List, + val badGeneric2: CustomGenericType, + val badNestedGeneric: CustomGenericType>, + // This would normally error but since it has a custom qualifier we skip the check + @CustomQualifier val customQualifier: Date, + // Mutable collections + val mutableList: MutableList, + val mutableSet: MutableSet, + val mutableCollection: MutableCollection, + val mutableMap: MutableMap +) + +@Keep +abstract class DateFactory : JsonAdapter.Factory + +@JsonClass(generateAdapter = true) +data class CustomGenericType(val value: T) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.propertyTypes`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageNonMoshiClassInternal") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageNonMoshiClassInternal") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageNonMoshiClassInternal + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageNonMoshiClassInternal" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageNonMoshiClassInternal' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageNonMoshiClassInternal ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageNonMoshiClassMap.md.html b/docs/checks/MoshiUsageNonMoshiClassMap.md.html new file mode 100644 index 00000000..674ffb5f --- /dev/null +++ b/docs/checks/MoshiUsageNonMoshiClassMap.md.html @@ -0,0 +1,254 @@ + +(#) Concrete Map type '%HINT%' is not natively supported by Moshi + +!!! Tip: Concrete Map type '%HINT%' is not natively supported by Moshi + Advice from this check is just a hint; it's a "weak" warning. + +Id +: `MoshiUsageNonMoshiClassMap` +Summary +: Concrete Map type '%HINT%' is not natively supported by Moshi +Severity +: Hint +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +The property type is concrete Map type (i.e. LinkedHashMap, HashMap, +etc). Moshi only natively supports their interface type (Map). Consider +upcasting to the interface type. Otherwise, moshi-gson-interop will hand +serialization of this property to Gson, which may or may not handle it. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/Example.kt:27:Information: Concrete Map type 'HashMap' +is not natively supported by Moshi. [MoshiUsageNonMoshiClassMap] + val concreteMap: HashMap<String, String>, + ----------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`src/external/ExternalType.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package external + +class ExternalType +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/external/ExternalTypeAnnotated.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package external + +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class ExternalTypeAnnotated(val value: String) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/slack/model/Example.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import androidx.annotation.Keep +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.JsonClass +import java.util.ArrayList +import java.util.HashSet +import java.util.HashMap +import java.util.Date +import external.ExternalType +import external.ExternalTypeAnnotated +import slack.InternalType +import slack.InternalTypeAnnotated +import slack.InternalTypeAnnotated2 +import dev.zacsweers.moshix.adapters.AdaptedBy +import test.CustomQualifier + +@JsonClass(generateAdapter = true) +data class Example( + // collections + val okList: List, + val okSet: Set, + val okCollection: Collection, + val okMap: Map, + val concreteList: ArrayList, + val concreteSet: HashSet, + val concreteMap: HashMap, + // platform + val platformType: Date, + @AdaptedBy(DateFactory::class) val adaptedByOk: Date, + // external + val externalType: ExternalType, + val externalTypeAnnotated: ExternalTypeAnnotated, + // internal + val internalType: InternalType, + val internalTypeAnnotated: InternalTypeAnnotated, + val internalTypeAnnotated2: InternalTypeAnnotated2, + val int: Int, + val string: String, + val nullableString: String?, + val any: Any, + // Arrays + val arrayType: Array, + val intArray: IntArray, + val boolArray: BooleanArray, + val complexArray: Array>, + val badGeneric: List, + val badGeneric2: CustomGenericType, + val badNestedGeneric: CustomGenericType>, + // This would normally error but since it has a custom qualifier we skip the check + @CustomQualifier val customQualifier: Date, + // Mutable collections + val mutableList: MutableList, + val mutableSet: MutableSet, + val mutableCollection: MutableCollection, + val mutableMap: MutableMap +) + +@Keep +abstract class DateFactory : JsonAdapter.Factory + +@JsonClass(generateAdapter = true) +data class CustomGenericType(val value: T) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.propertyTypes`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageNonMoshiClassMap") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageNonMoshiClassMap") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageNonMoshiClassMap + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageNonMoshiClassMap" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageNonMoshiClassMap' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageNonMoshiClassMap ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageNonMoshiClassPlatform.md.html b/docs/checks/MoshiUsageNonMoshiClassPlatform.md.html new file mode 100644 index 00000000..7cfca1dd --- /dev/null +++ b/docs/checks/MoshiUsageNonMoshiClassPlatform.md.html @@ -0,0 +1,256 @@ + +(#) Platform type '%HINT%' is not natively supported by Moshi + +!!! WARNING: Platform type '%HINT%' is not natively supported by Moshi + This is a warning. + +Id +: `MoshiUsageNonMoshiClassPlatform` +Summary +: Platform type '%HINT%' is not natively supported by Moshi +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +The property type is a platform type (i.e. from java.*, kotlin.*, +android.*). Moshi only natively supports a small subset of these +(primitives, String, and collection interfaces). Otherwise, +moshi-gson-interop will hand serialization of this property to Gson, +which may or may not handle it. This will eventually become an error +after GSON is removed. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/Example.kt:29:Warning: Platform type 'Date' is not +natively supported by Moshi. [MoshiUsageNonMoshiClassPlatform] + val platformType: Date, + ---- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`src/external/ExternalType.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package external + +class ExternalType +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/external/ExternalTypeAnnotated.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package external + +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class ExternalTypeAnnotated(val value: String) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/slack/model/Example.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import androidx.annotation.Keep +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.JsonClass +import java.util.ArrayList +import java.util.HashSet +import java.util.HashMap +import java.util.Date +import external.ExternalType +import external.ExternalTypeAnnotated +import slack.InternalType +import slack.InternalTypeAnnotated +import slack.InternalTypeAnnotated2 +import dev.zacsweers.moshix.adapters.AdaptedBy +import test.CustomQualifier + +@JsonClass(generateAdapter = true) +data class Example( + // collections + val okList: List, + val okSet: Set, + val okCollection: Collection, + val okMap: Map, + val concreteList: ArrayList, + val concreteSet: HashSet, + val concreteMap: HashMap, + // platform + val platformType: Date, + @AdaptedBy(DateFactory::class) val adaptedByOk: Date, + // external + val externalType: ExternalType, + val externalTypeAnnotated: ExternalTypeAnnotated, + // internal + val internalType: InternalType, + val internalTypeAnnotated: InternalTypeAnnotated, + val internalTypeAnnotated2: InternalTypeAnnotated2, + val int: Int, + val string: String, + val nullableString: String?, + val any: Any, + // Arrays + val arrayType: Array, + val intArray: IntArray, + val boolArray: BooleanArray, + val complexArray: Array>, + val badGeneric: List, + val badGeneric2: CustomGenericType, + val badNestedGeneric: CustomGenericType>, + // This would normally error but since it has a custom qualifier we skip the check + @CustomQualifier val customQualifier: Date, + // Mutable collections + val mutableList: MutableList, + val mutableSet: MutableSet, + val mutableCollection: MutableCollection, + val mutableMap: MutableMap +) + +@Keep +abstract class DateFactory : JsonAdapter.Factory + +@JsonClass(generateAdapter = true) +data class CustomGenericType(val value: T) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.propertyTypes`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageNonMoshiClassPlatform") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageNonMoshiClassPlatform") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageNonMoshiClassPlatform + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageNonMoshiClassPlatform" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageNonMoshiClassPlatform' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageNonMoshiClassPlatform ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageObject.md.html b/docs/checks/MoshiUsageObject.md.html new file mode 100644 index 00000000..263daa3d --- /dev/null +++ b/docs/checks/MoshiUsageObject.md.html @@ -0,0 +1,183 @@ + +(#) Object types cannot be annotated with @JsonClass + +!!! ERROR: Object types cannot be annotated with @JsonClass + This is an error. + +Id +: `MoshiUsageObject` +Summary +: Object types cannot be annotated with @JsonClass +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +Object types cannot be annotated with @JsonClass. The only way they are +permitted to participate in Moshi serialization is if they are a sealed +subtype of a Moshi sealed class and annotated with `@TypeLabel` or +`@DefaultObject` accordingly. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/Example.kt:5:Error: Object types cannot be annotated +with @JsonClass. [MoshiUsageObject] +@JsonClass(generateAdapter = true) +---------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/model/Example.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +object Example +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.objects_cannot_jsonClass`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageObject") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageObject") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageObject + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageObject" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageObject' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageObject ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageParamNeedsInit.md.html b/docs/checks/MoshiUsageParamNeedsInit.md.html new file mode 100644 index 00000000..31f60e5f --- /dev/null +++ b/docs/checks/MoshiUsageParamNeedsInit.md.html @@ -0,0 +1,180 @@ + +(#) Constructor non-property parameters in Moshi classes must have default values + +!!! ERROR: Constructor non-property parameters in Moshi classes must have default values + This is an error. + +Id +: `MoshiUsageParamNeedsInit` +Summary +: Constructor non-property parameters in Moshi classes must have default values +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +Constructor non-property parameters in Moshi classes must have default +values. Since these parameters do not participate in serialization, +Moshi cannot fulfill them otherwise during construction. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/Example.kt:7:Error: Constructor non-property parameters +in Moshi classes must have default values. [MoshiUsageParamNeedsInit] +class Example(val value: String, nonProp: String, @Transient val transientProp: String) + --------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/model/Example.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import com.squareup.moshi.JsonClass +import kotlin.jvm.Transient + +@JsonClass(generateAdapter = true) +class Example(val value: String, nonProp: String, @Transient val transientProp: String) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.params_that_need_init`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageParamNeedsInit") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageParamNeedsInit") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageParamNeedsInit + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageParamNeedsInit" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageParamNeedsInit' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageParamNeedsInit ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsagePrivateConstructor.md.html b/docs/checks/MoshiUsagePrivateConstructor.md.html new file mode 100644 index 00000000..ddc0458b --- /dev/null +++ b/docs/checks/MoshiUsagePrivateConstructor.md.html @@ -0,0 +1,188 @@ + +(#) Constructors in Moshi classes cannot be private + +!!! ERROR: Constructors in Moshi classes cannot be private + This is an error. + +Id +: `MoshiUsagePrivateConstructor` +Summary +: Constructors in Moshi classes cannot be private +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +Constructors in Moshi classes cannot be private. Otherwise Moshi cannot +invoke it during decoding. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/Example.kt:6:Error: Constructors in Moshi classes cannot +be private. [MoshiUsagePrivateConstructor] +data class Example private constructor(val value: String) + ------- +src/slack/model/Example.kt:9:Error: Constructors in Moshi classes cannot +be private. [MoshiUsagePrivateConstructor] +data class Example2 protected constructor(val value: String) + --------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/model/Example.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class Example private constructor(val value: String) + +@JsonClass(generateAdapter = true) +data class Example2 protected constructor(val value: String) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.private_constructor`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsagePrivateConstructor") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsagePrivateConstructor") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsagePrivateConstructor + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsagePrivateConstructor" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsagePrivateConstructor' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsagePrivateConstructor ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsagePrivateConstructorProperty.md.html b/docs/checks/MoshiUsagePrivateConstructorProperty.md.html new file mode 100644 index 00000000..63306831 --- /dev/null +++ b/docs/checks/MoshiUsagePrivateConstructorProperty.md.html @@ -0,0 +1,181 @@ + +(#) Constructor parameter properties in Moshi classes cannot be private + +!!! ERROR: Constructor parameter properties in Moshi classes cannot be private + This is an error. + +Id +: `MoshiUsagePrivateConstructorProperty` +Summary +: Constructor parameter properties in Moshi classes cannot be private +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +Constructor parameter properties in Moshi classes cannot be private. +Otherwise these properties will not be visible in serialization. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/Example.kt:6:Error: Constructor parameter properties in +Moshi classes cannot be private. [MoshiUsagePrivateConstructorProperty] +data class Example(private val value: String, protected val value2: String) + --------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/model/Example.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class Example(private val value: String, protected val value2: String) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.private_prop`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsagePrivateConstructorProperty") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsagePrivateConstructorProperty") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsagePrivateConstructorProperty + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsagePrivateConstructorProperty" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsagePrivateConstructorProperty' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsagePrivateConstructorProperty ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageQualifierRetention.md.html b/docs/checks/MoshiUsageQualifierRetention.md.html new file mode 100644 index 00000000..14619c07 --- /dev/null +++ b/docs/checks/MoshiUsageQualifierRetention.md.html @@ -0,0 +1,213 @@ + +(#) JsonQualifiers must have RUNTIME retention + +!!! ERROR: JsonQualifiers must have RUNTIME retention + This is an error. + +Id +: `MoshiUsageQualifierRetention` +Summary +: JsonQualifiers must have RUNTIME retention +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +Moshi uses these annotations at runtime, as such they must be available +at runtime. In Kotlin, this is the default and you can just remove the +Retention annotation. In Java, you must specify it explicitly with +@Retention(RUNTIME). + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/NoAnnotationsIsOk.kt:37:Error: JsonQualifiers must have +RUNTIME retention. [MoshiUsageQualifierRetention] +@Retention(AnnotationRetention.BINARY) +-------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/model/NoAnnotationsIsOk.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import com.squareup.moshi.JsonQualifier +import kotlin.annotation.Retention +import kotlin.annotation.AnnotationRetention +import kotlin.annotation.AnnotationRetention.RUNTIME +import kotlin.annotation.AnnotationTarget.PROPERTY +import kotlin.annotation.AnnotationTarget +import kotlin.annotation.AnnotationTarget.FIELD + +@JsonQualifier +annotation class NoAnnotationsIsOk + +@Target(FIELD) +@JsonQualifier +annotation class NoRetentionIsOk + +@Target(AnnotationRetention.FIELD) +@Retention(AnnotationRetention.RUNTIME) +@JsonQualifier +annotation class CorrectTargetAndRetention + +@Target(PROPERTY, AnnotationRetention.FIELD) +@Retention(RUNTIME) +@JsonQualifier +annotation class CorrectTargetAndRetention2 + +@Target([PROPERTY, FIELD]) +@Retention(RUNTIME) +@JsonQualifier +annotation class CorrectTargetAndRetention3 + +@Target(PROPERTY) +@JsonQualifier +annotation class MissingTarget + +@Retention(AnnotationRetention.BINARY) +@JsonQualifier +annotation class WrongRetention +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.kotlin_jsonQualifierAnnotation_ok`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageQualifierRetention") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageQualifierRetention") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageQualifierRetention + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageQualifierRetention" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageQualifierRetention' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageQualifierRetention ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageQualifierTarget.md.html b/docs/checks/MoshiUsageQualifierTarget.md.html new file mode 100644 index 00000000..6ea5bb99 --- /dev/null +++ b/docs/checks/MoshiUsageQualifierTarget.md.html @@ -0,0 +1,212 @@ + +(#) JsonQualifiers must include FIELD targeting + +!!! ERROR: JsonQualifiers must include FIELD targeting + This is an error. + +Id +: `MoshiUsageQualifierTarget` +Summary +: JsonQualifiers must include FIELD targeting +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +Moshi code gen stores these annotations on generated adapter fields, as +such they must be allowed on fields. Please specify it explicitly as +@Target(FIELD). + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/NoAnnotationsIsOk.kt:33:Error: JsonQualifiers must +include FIELD targeting. [MoshiUsageQualifierTarget] +@Target(PROPERTY) +----------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/model/NoAnnotationsIsOk.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import com.squareup.moshi.JsonQualifier +import kotlin.annotation.Retention +import kotlin.annotation.AnnotationRetention +import kotlin.annotation.AnnotationRetention.RUNTIME +import kotlin.annotation.AnnotationTarget.PROPERTY +import kotlin.annotation.AnnotationTarget +import kotlin.annotation.AnnotationTarget.FIELD + +@JsonQualifier +annotation class NoAnnotationsIsOk + +@Target(FIELD) +@JsonQualifier +annotation class NoRetentionIsOk + +@Target(AnnotationRetention.FIELD) +@Retention(AnnotationRetention.RUNTIME) +@JsonQualifier +annotation class CorrectTargetAndRetention + +@Target(PROPERTY, AnnotationRetention.FIELD) +@Retention(RUNTIME) +@JsonQualifier +annotation class CorrectTargetAndRetention2 + +@Target([PROPERTY, FIELD]) +@Retention(RUNTIME) +@JsonQualifier +annotation class CorrectTargetAndRetention3 + +@Target(PROPERTY) +@JsonQualifier +annotation class MissingTarget + +@Retention(AnnotationRetention.BINARY) +@JsonQualifier +annotation class WrongRetention +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.kotlin_jsonQualifierAnnotation_ok`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageQualifierTarget") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageQualifierTarget") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageQualifierTarget + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageQualifierTarget" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageQualifierTarget' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageQualifierTarget ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageRedundantJsonName.md.html b/docs/checks/MoshiUsageRedundantJsonName.md.html new file mode 100644 index 00000000..a1ca2695 --- /dev/null +++ b/docs/checks/MoshiUsageRedundantJsonName.md.html @@ -0,0 +1,184 @@ + +(#) Json.name with the same value as the property/enum member name is redundant + +!!! WARNING: Json.name with the same value as the property/enum member name is redundant + This is a warning. + +Id +: `MoshiUsageRedundantJsonName` +Summary +: Json.name with the same value as the property/enum member name is redundant +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +Redundant Json.name values can make code noisier and harder to read, +consider removing it or suppress this warning with a commented +suppression explaining why it's needed. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/Example.kt:7:Warning: Json.name with the same value as +the property/enum member name is redundant. +[MoshiUsageRedundantJsonName] +data class Example(@Json(name = "value") val value: String) + ----- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/model/Example.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class Example(@Json(name = "value") val value: String) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.redundantJsonName`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageRedundantJsonName") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageRedundantJsonName") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageRedundantJsonName + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageRedundantJsonName" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageRedundantJsonName' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageRedundantJsonName ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageRedundantSiteTarget.md.html b/docs/checks/MoshiUsageRedundantSiteTarget.md.html new file mode 100644 index 00000000..e6754c38 --- /dev/null +++ b/docs/checks/MoshiUsageRedundantSiteTarget.md.html @@ -0,0 +1,184 @@ + +(#) Use of site-targets on @Json are redundant + +!!! ERROR: Use of site-targets on @Json are redundant + This is an error. + +Id +: `MoshiUsageRedundantSiteTarget` +Summary +: Use of site-targets on @Json are redundant +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +Use of site-targets on @Json are redundant and can be removed. Only one, +target-less @Json annotation is necessary. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/Example.kt:8:Error: Use of site-targets on @Json are +redundant. [MoshiUsageRedundantSiteTarget] + @field:Json(name = "foo") val value: String + ----- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/model/Example.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import com.squareup.moshi.JsonClass +import com.squareup.moshi.Json + +@JsonClass(generateAdapter = true) +data class Example( + @field:Json(name = "foo") val value: String +) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.jsonNameSiteTargets`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageRedundantSiteTarget") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageRedundantSiteTarget") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageRedundantSiteTarget + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageRedundantSiteTarget" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageRedundantSiteTarget' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageRedundantSiteTarget ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageSealedMustBeSealed.md.html b/docs/checks/MoshiUsageSealedMustBeSealed.md.html new file mode 100644 index 00000000..8b21cd72 --- /dev/null +++ b/docs/checks/MoshiUsageSealedMustBeSealed.md.html @@ -0,0 +1,177 @@ + +(#) Moshi-sealed can only be applied to 'sealed' types + +!!! ERROR: Moshi-sealed can only be applied to 'sealed' types + This is an error. + +Id +: `MoshiUsageSealedMustBeSealed` +Summary +: Moshi-sealed can only be applied to 'sealed' types +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +Moshi-sealed can only be applied to 'sealed' types. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/BaseType.kt:6:Error: Moshi-sealed can only be applied to +'sealed' types. [MoshiUsageSealedMustBeSealed] +abstract class BaseType + -------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/model/BaseType.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true, generator = "sealed:type") +abstract class BaseType +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.sealed_must_be_sealed`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageSealedMustBeSealed") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageSealedMustBeSealed") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageSealedMustBeSealed + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageSealedMustBeSealed" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageSealedMustBeSealed' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageSealedMustBeSealed ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageSerializedName.md.html b/docs/checks/MoshiUsageSerializedName.md.html new file mode 100644 index 00000000..33b21834 --- /dev/null +++ b/docs/checks/MoshiUsageSerializedName.md.html @@ -0,0 +1,208 @@ + +(#) Use Moshi's @Json rather than Gson's @SerializedName + +!!! ERROR: Use Moshi's @Json rather than Gson's @SerializedName + This is an error. + +Id +: `MoshiUsageSerializedName` +Summary +: Use Moshi's @Json rather than Gson's @SerializedName +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +@SerializedName is specific to Gson and will not work with Moshi. +Replace it with Moshi's equivalent @Json annotation instead (or remove +it if @Json is defined already). + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/Example.kt:11:Error: Use Moshi's @Json rather than +Gson's @SerializedName. [MoshiUsageSerializedName] + @SerializedName("full_gson") val fullGson: String, + ---------------------------- +src/slack/model/Example.kt:12:Error: Use Moshi's @Json rather than +Gson's @SerializedName. [MoshiUsageSerializedName] + @SerializedName("full_gson_alts", alternate = ["foo"]) val fullGsonAlternates: String, + ------------------------------------------------------ +src/slack/model/Example.kt:13:Error: Use Moshi's @Json rather than +Gson's @SerializedName. [MoshiUsageSerializedName] + @Json(name = "mixed") @SerializedName("mixed") val mixedSame: String, + ------------------------ +src/slack/model/Example.kt:14:Error: Use Moshi's @Json rather than +Gson's @SerializedName. [MoshiUsageSerializedName] + @Json(name = "mixed_diff") @SerializedName("mixed_diff_2") val mixedDiff: String, + ------------------------------- +src/slack/model/Example.kt:15:Error: Use Moshi's @Json rather than +Gson's @SerializedName. [MoshiUsageSerializedName] + @Json(name = "mixed_alts") @SerializedName("mixed_alts", alternate = ["foo"]) val mixedAlternates: String, + -------------------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/model/Example.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass +import com.google.gson.annotations.SerializedName + +@JsonClass(generateAdapter = true) +data class Example( + val noAnnotations: String, + @Json(name = "full_moshi") val fullMoshi: String, + @SerializedName("full_gson") val fullGson: String, + @SerializedName("full_gson_alts", alternate = ["foo"]) val fullGsonAlternates: String, + @Json(name = "mixed") @SerializedName("mixed") val mixedSame: String, + @Json(name = "mixed_diff") @SerializedName("mixed_diff_2") val mixedDiff: String, + @Json(name = "mixed_alts") @SerializedName("mixed_alts", alternate = ["foo"]) val mixedAlternates: String, +) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.serializedNameIssues`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageSerializedName") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageSerializedName") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageSerializedName + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageSerializedName" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageSerializedName' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageSerializedName ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageSnakeCase.md.html b/docs/checks/MoshiUsageSnakeCase.md.html new file mode 100644 index 00000000..0a9cfa3f --- /dev/null +++ b/docs/checks/MoshiUsageSnakeCase.md.html @@ -0,0 +1,186 @@ + +(#) Consider using `@Json(name = ...)` rather than direct snake casing + +!!! WARNING: Consider using `@Json(name = ...)` rather than direct snake casing + This is a warning. + +Id +: `MoshiUsageSnakeCase` +Summary +: Consider using `@Json(name = ...)` rather than direct snake casing +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +Moshi offers `@Json` annotations to specify names to use in JSON +serialization, similar to Gson's `@SerializedName`. This can help avoid +snake_case properties in source directly. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/Example.kt:8:Warning: Consider using @Json(name = ...) +rather than direct snake casing. [MoshiUsageSnakeCase] + val snake_case: String, + ---------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/model/Example.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import com.squareup.moshi.JsonClass +import com.squareup.moshi.Json + +@JsonClass(generateAdapter = true) +data class Example( + val snake_case: String, + @Json(name = "taken") val already_annotated_is_ignored: String +) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.snake_case_name`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageSnakeCase") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageSnakeCase") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageSnakeCase + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageSnakeCase" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageSnakeCase' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageSnakeCase ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageTransientNeedsInit.md.html b/docs/checks/MoshiUsageTransientNeedsInit.md.html new file mode 100644 index 00000000..0dd8cac6 --- /dev/null +++ b/docs/checks/MoshiUsageTransientNeedsInit.md.html @@ -0,0 +1,180 @@ + +(#) Transient constructor properties must have default values + +!!! ERROR: Transient constructor properties must have default values + This is an error. + +Id +: `MoshiUsageTransientNeedsInit` +Summary +: Transient constructor properties must have default values +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +Transient constructor property parameters in Moshi classes must have +default values. Since these parameters do not participate in +serialization, Moshi cannot fulfill them otherwise during construction. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/Example.kt:7:Error: Transient constructor properties +must have default values. [MoshiUsageTransientNeedsInit] +class Example(val value: String, nonProp: String, @Transient val transientProp: String) + ------------------------------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/model/Example.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import com.squareup.moshi.JsonClass +import kotlin.jvm.Transient + +@JsonClass(generateAdapter = true) +class Example(val value: String, nonProp: String, @Transient val transientProp: String) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.params_that_need_init`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageTransientNeedsInit") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageTransientNeedsInit") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageTransientNeedsInit + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageTransientNeedsInit" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageTransientNeedsInit' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageTransientNeedsInit ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageUnsupportedType.md.html b/docs/checks/MoshiUsageUnsupportedType.md.html new file mode 100644 index 00000000..9adb548e --- /dev/null +++ b/docs/checks/MoshiUsageUnsupportedType.md.html @@ -0,0 +1,205 @@ + +(#) This type cannot be annotated with @JsonClass + +!!! ERROR: This type cannot be annotated with @JsonClass + This is an error. + +Id +: `MoshiUsageUnsupportedType` +Summary +: This type cannot be annotated with @JsonClass +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +Abstract, interface, annotation, and inner class types cannot be +annotated with @JsonClass. If you intend to decode this with a custom +adapter, use @AdaptedBy. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/Example.kt:6:Error: This type cannot be annotated with +@JsonClass. [MoshiUsageUnsupportedType] + @JsonClass(generateAdapter = true) + ---------------------------------- +src/slack/model/Example.kt:9:Error: This type cannot be annotated with +@JsonClass. [MoshiUsageUnsupportedType] + @JsonClass(generateAdapter = true) + ---------------------------------- +src/slack/model/Example.kt:12:Error: This type cannot be annotated with +@JsonClass. [MoshiUsageUnsupportedType] + @JsonClass(generateAdapter = true) + ---------------------------------- +src/slack/model/Example.kt:15:Error: This type cannot be annotated with +@JsonClass. [MoshiUsageUnsupportedType] + @JsonClass(generateAdapter = true) + ---------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/model/Example.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import com.squareup.moshi.JsonClass + +class Example { + @JsonClass(generateAdapter = true) + annotation class UnsupportedAnnotation + + @JsonClass(generateAdapter = true) + inner class UnsupportedInner + + @JsonClass(generateAdapter = true) + abstract class UnsupportedAbstract + + @JsonClass(generateAdapter = true) + interface UnsupportedInterface +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.unsupportedClasses`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageUnsupportedType") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageUnsupportedType") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageUnsupportedType + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageUnsupportedType" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageUnsupportedType' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageUnsupportedType ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageUseData.md.html b/docs/checks/MoshiUsageUseData.md.html new file mode 100644 index 00000000..c8531a69 --- /dev/null +++ b/docs/checks/MoshiUsageUseData.md.html @@ -0,0 +1,182 @@ + +(#) Model classes should be immutable data classes + +!!! ERROR: Model classes should be immutable data classes + This is an error. + +Id +: `MoshiUsageUseData` +Summary +: Model classes should be immutable data classes +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +@JsonClass-annotated models should be immutable data classes unless +there's a very specific reason not to. If you want a custom +equals/hashcode/toString impls, make it data anyway and override the +ones you need. If you want non-property parameter values, consider +making them `@Transient` properties instead with default values. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/Example.kt:7:Error: Model classes should be immutable +data classes. [MoshiUsageUseData] +class Example(val value: String, nonProp: String, @Transient val transientProp: String) + ------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/model/Example.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import com.squareup.moshi.JsonClass +import kotlin.jvm.Transient + +@JsonClass(generateAdapter = true) +class Example(val value: String, nonProp: String, @Transient val transientProp: String) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.params_that_need_init`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageUseData") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageUseData") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageUseData + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageUseData" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageUseData' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageUseData ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MoshiUsageVarProperty.md.html b/docs/checks/MoshiUsageVarProperty.md.html new file mode 100644 index 00000000..0fbc2939 --- /dev/null +++ b/docs/checks/MoshiUsageVarProperty.md.html @@ -0,0 +1,182 @@ + +(#) Moshi properties should be immutable + +!!! WARNING: Moshi properties should be immutable + This is a warning. + +Id +: `MoshiUsageVarProperty` +Summary +: Moshi properties should be immutable +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MoshiUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +Copyright Year +: 2021 + +While var properties are technically possible, they should not be used +with Moshi classes as it can lead to asymmetric encoding and +thread-safety issues. Consider making this val. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/model/Example.kt:6:Warning: Moshi properties should be +immutable. [MoshiUsageVarProperty] +data class Example(var value: String) + --- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/model/Example.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.model + +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class Example(var value: String) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MoshiUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MoshiUsageDetector.mutable_prop`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MoshiUsageVarProperty") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MoshiUsageVarProperty") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MoshiUsageVarProperty + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MoshiUsageVarProperty" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MoshiUsageVarProperty' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MoshiUsageVarProperty ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MotionLayoutInvalidSceneFileReference.md.html b/docs/checks/MotionLayoutInvalidSceneFileReference.md.html index fbc5f0ef..46d9f168 100644 --- a/docs/checks/MotionLayoutInvalidSceneFileReference.md.html +++ b/docs/checks/MotionLayoutInvalidSceneFileReference.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 4.0.0 (May 2020) Affects : Resource files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/MotionLayoutDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/MotionLayoutDetectorTest.kt) -Copyright Year -: 2019 A motion scene file specifies the animations used in a `MotionLayout`. The `layoutDescription` is required to specify a valid motion scene @@ -42,11 +42,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/motion_test.xml:5:Error: The motion scene file: @xml/motion_scene doesn't exist [MotionLayoutInvalidSceneFileReference] - app:layoutDescription="@xml/motion_scene" ----------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/MotionLayoutMissingId.md.html b/docs/checks/MotionLayoutMissingId.md.html index bc1f4906..5af48547 100644 --- a/docs/checks/MotionLayoutMissingId.md.html +++ b/docs/checks/MotionLayoutMissingId.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.2.0 (May 2022) Affects : Resource files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/MotionLayoutIdDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/MotionLayoutIdDetectorTest.kt) -Copyright Year -: 2021 Views inside `MotionLayout` require an `android:id`. @@ -40,11 +40,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/motion_test.xml:9:Error: Views inside MotionLayout require an android:id attribute [MotionLayoutMissingId] - <View ---- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here are the relevant source files: diff --git a/docs/checks/MotionSceneFileValidationError.md.html b/docs/checks/MotionSceneFileValidationError.md.html index 08f61969..edd40473 100644 --- a/docs/checks/MotionSceneFileValidationError.md.html +++ b/docs/checks/MotionSceneFileValidationError.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 4.0.0 (May 2020) Affects : Resource files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/MotionSceneDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/MotionSceneDetectorTest.kt) -Copyright Year -: 2019 A motion scene file specifies the animations used in a `MotionLayout`. This check performs various serious correctness checks in a motion scene @@ -42,11 +42,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/xml/missing_custom_attribute_name.xml:7:Error: attributeName should be defined [MotionSceneFileValidationError] - <CustomAttribute app:customPixelDimension="2sp"/> --------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/MultipleAwaitPointerEventScopes.md.html b/docs/checks/MultipleAwaitPointerEventScopes.md.html new file mode 100644 index 00000000..0fb1decd --- /dev/null +++ b/docs/checks/MultipleAwaitPointerEventScopes.md.html @@ -0,0 +1,151 @@ + +(#) Suspicious use of multiple awaitPointerEventScope blocks. Using multiple awaitPointerEventScope blocks may cause some input events to be dropped. + +!!! WARNING: Suspicious use of multiple awaitPointerEventScope blocks. Using multiple awaitPointerEventScope blocks may cause some input events to be dropped. + This is a warning. + +Id +: `MultipleAwaitPointerEventScopes` +Summary +: Suspicious use of multiple awaitPointerEventScope blocks. Using multiple awaitPointerEventScope blocks may cause some input events to be dropped. +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: Jetpack Compose +Identifier +: androidx.compose.ui +Feedback +: https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.ui:ui-android](androidx_compose_ui_ui-android.md.html) +Since +: 1.5.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/ui/ui-lint/src/main/java/androidx/compose/ui/lint/MultipleAwaitPointerEventScopesDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/ui/ui-lint/src/test/java/androidx/compose/ui/lint/MultipleAwaitPointerEventScopesDetectorTest.kt) +Copyright Year +: 2022 + +Pointer Input events are queued inside awaitPointerEventScope. Multiple +calls to awaitPointerEventScope may exit the scope. During this time +there is no guarantee that the events will be queued and some events may +be dropped. It is recommended to use a single top-level block and +perform the pointer events processing within such block. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.ui:ui-android:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.ui:ui-android:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.ui.android) + +# libs.versions.toml +[versions] +ui-android = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +ui-android = { + module = "androidx.compose.ui:ui-android", + version.ref = "ui-android" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.ui:ui-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.ui:ui-android](androidx_compose_ui_ui-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MultipleAwaitPointerEventScopes") + fun method() { + awaitPointerEventScope(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MultipleAwaitPointerEventScopes") + void method() { + awaitPointerEventScope(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MultipleAwaitPointerEventScopes + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MultipleAwaitPointerEventScopes" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MultipleAwaitPointerEventScopes' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MultipleAwaitPointerEventScopes ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MultipleUsesSdk.md.html b/docs/checks/MultipleUsesSdk.md.html index c292dea9..b3472055 100644 --- a/docs/checks/MultipleUsesSdk.md.html +++ b/docs/checks/MultipleUsesSdk.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Manifest files Editing @@ -45,14 +47,11 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text AndroidManifest.xml:7:Error: There should only be a single element in the manifest: merge these together [MultipleUsesSdk] - <uses-sdk android:targetSdkVersion="14" /> -------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `AndroidManifest.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -82,6 +81,40 @@ </manifest> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/values/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<!-- Copyright (C) 2007 The Android Open Source Project + + 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. +--> + +<resources> + <!-- Home --> + <string name="home_title">Home Sample</string> + <string name="show_all_apps">All</string> + + <!-- Home Menus --> + <string name="menu_wallpaper">Wallpaper</string> + <string name="menu_search">Search</string> + <string name="menu_settings">Settings</string> + <string name="sample" translatable="false">Ignore Me</string> + + <!-- Wallpaper --> + <string name="wallpaper_instructions">Tap picture to set portrait wallpaper</string> +</resources> + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ManifestDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/MustBeInModule.md.html b/docs/checks/MustBeInModule.md.html new file mode 100644 index 00000000..1769eba3 --- /dev/null +++ b/docs/checks/MustBeInModule.md.html @@ -0,0 +1,221 @@ + +(#) @Binds/@Provides functions must be in modules + +!!! ERROR: @Binds/@Provides functions must be in modules + This is an error. + +Id +: `MustBeInModule` +Summary +: @Binds/@Provides functions must be in modules +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.5.1 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/DaggerIssuesDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/DaggerIssuesDetectorTest.kt) +Copyright Year +: 2021 + +@Binds/@Provides functions must be in `@Module`-annotated classes. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/MyModule.kt:7:Error: @Binds/@Provides functions must be in +modules [MustBeInModule] + @Binds fun invalidBind(real: Int): Number + ----------------------------------------- +src/foo/MyModule.kt:10:Error: @Binds/@Provides functions must be in +modules [MustBeInModule] + @Provides fun invalidBind(): Int = 3 + ------------------------------------ +src/foo/MyModule.kt:15:Error: @Binds/@Provides functions must be in +modules [MustBeInModule] + @Binds abstract fun invalidBind(real: Int): Number + -------------------------------------------------- +src/foo/MyModule.kt:18:Error: @Binds/@Provides functions must be in +modules [MustBeInModule] + @Provides fun invalidBind(): Int = 3 + ------------------------------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/MyModule.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package foo +import dagger.Binds +import dagger.Provides +import dagger.Module + +interface MyModule { + @Binds fun invalidBind(real: Int): Number + + companion object { + @Provides fun invalidBind(): Int = 3 + } +} + +abstract class MyModule2 { + @Binds abstract fun invalidBind(real: Int): Number + + companion object { + @Provides fun invalidBind(): Int = 3 + } +} + +@Module +interface MyModule3 { + @Binds fun validBind(real: Int): Number + + companion object { + @Provides fun validBind(): Int = 3 + } +} + +@Module +abstract class MyModule4 { + @Binds abstract fun validBind(real: Int): Number + + companion object { + @Provides fun validBind(): Int = 3 + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/DaggerIssuesDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `DaggerIssuesDetector.must be in a module`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MustBeInModule") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MustBeInModule") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MustBeInModule + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MustBeInModule" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MustBeInModule' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MustBeInModule ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MustUseNamedParams.md.html b/docs/checks/MustUseNamedParams.md.html new file mode 100644 index 00000000..600e805a --- /dev/null +++ b/docs/checks/MustUseNamedParams.md.html @@ -0,0 +1,194 @@ + +(#) Calls to @MustUseNamedParams-annotated methods must name all parameters + +!!! ERROR: Calls to @MustUseNamedParams-annotated methods must name all parameters + This is an error. + +Id +: `MustUseNamedParams` +Summary +: Calls to @MustUseNamedParams-annotated methods must name all parameters +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.7.1 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/MustUseNamedParamsDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MustUseNamedParamsDetectorTest.kt) +Copyright Year +: 2022 + +Calls to @MustUseNamedParams-annotated methods must name all +parameters. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/TestFile.kt:16:Error: Calls to @MustUseNamedParams-annotated +methods must name all parameters. [MustUseNamedParams] + methodWithAnnotation("Zac") + --------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/TestFile.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package foo + +import slack.lint.annotations.MustUseNamedParams + +class TestFile { + @MustUseNamedParams + fun methodWithAnnotation(name: String) { + // Do nothing. + } + + fun methodWithoutAnnotation(name: String) { + // Do nothing. + } + + fun useMethod() { + methodWithAnnotation("Zac") + methodWithAnnotation(name = "Sean") + + methodWithoutAnnotation("Yifan") + methodWithoutAnnotation(name = "Sean2") + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/MustUseNamedParamsDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MustUseNamedParamsDetector.simpleTest`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MustUseNamedParams") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MustUseNamedParams") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MustUseNamedParams + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MustUseNamedParams" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MustUseNamedParams' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MustUseNamedParams ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MutableCollectionMutableState.md.html b/docs/checks/MutableCollectionMutableState.md.html index d940e581..be4fa6a4 100644 --- a/docs/checks/MutableCollectionMutableState.md.html +++ b/docs/checks/MutableCollectionMutableState.md.html @@ -20,6 +20,14 @@ : androidx.compose.runtime Feedback : https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.runtime:runtime-android](androidx_compose_runtime_runtime-android.md.html) +Since +: 1.5.0 Affects : Kotlin and Java files and test sources Editing @@ -45,74 +53,44 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/test.kt:12:Warning: Creating a MutableState object with a mutable collection type [MutableCollectionMutableState] - val listProperty = mutableStateOf(list) -------------- - - src/test/test.kt:14:Warning: Creating a MutableState object with a mutable collection type [MutableCollectionMutableState] - val setFunction = mutableStateOf(mutableSetOf(1)) -------------- - - src/test/test.kt:15:Warning: Creating a MutableState object with a mutable collection type [MutableCollectionMutableState] - val setProperty = mutableStateOf(set) -------------- - - src/test/test.kt:17:Warning: Creating a MutableState object with a mutable collection type [MutableCollectionMutableState] - val mapFunction = mutableStateOf(mutableMapOf(1 to 1)) -------------- - - src/test/test.kt:18:Warning: Creating a MutableState object with a mutable collection type [MutableCollectionMutableState] - val mapProperty = mutableStateOf(map) -------------- - - src/test/test.kt:20:Warning: Creating a MutableState object with a mutable collection type [MutableCollectionMutableState] - val collectionProperty = mutableStateOf(collection) -------------- - - src/test/test.kt:28:Warning: Creating a MutableState object with a mutable collection type [MutableCollectionMutableState] - val listParameter = mutableStateOf(listParam) -------------- - - src/test/test.kt:29:Warning: Creating a MutableState object with a mutable collection type [MutableCollectionMutableState] - val setParameter = mutableStateOf(setParam) -------------- - - src/test/test.kt:30:Warning: Creating a MutableState object with a mutable collection type [MutableCollectionMutableState] - val mapParameter = mutableStateOf(mapParam) -------------- - - src/test/test.kt:31:Warning: Creating a MutableState object with a mutable collection type [MutableCollectionMutableState] - val collectionProperty = mutableStateOf(collectionParam) -------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -161,6 +139,44 @@ To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=612128. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.runtime:runtime-android:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.runtime:runtime-android:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.runtime.android) + +# libs.versions.toml +[versions] +runtime-android = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +runtime-android = { + module = "androidx.compose.runtime:runtime-android", + version.ref = "runtime-android" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.runtime:runtime-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.runtime:runtime-android](androidx_compose_runtime_runtime-android.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/MutableImplicitPendingIntent.md.html b/docs/checks/MutableImplicitPendingIntent.md.html new file mode 100644 index 00000000..fa902c5e --- /dev/null +++ b/docs/checks/MutableImplicitPendingIntent.md.html @@ -0,0 +1,216 @@ + +(#) Mutable Implicit PendingIntent is disallowed + +!!! ERROR: Mutable Implicit PendingIntent is disallowed + This is an error. + +Id +: `MutableImplicitPendingIntent` +Summary +: Mutable Implicit PendingIntent is disallowed +Severity +: Error +Category +: Security +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.2.0 (November 2023) +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/PendingIntentMutableImplicitDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/PendingIntentMutableImplicitDetectorTest.kt) + +Apps targeting Android 14 and above are not allowed to create +`PendingIntents` with `FLAG_MUTABLE` and an implicit intent within for +security reasons. + +To retrieve an existing PendingIntent, use `FLAG_NO_CREATE`. To create a +new `PendingIntent`, either make the intent explicit, or make it +immutable with `FLAG_IMMUTABLE`. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test/pkg/PendingIntentJavaTest.java:10:Error: Mutable implicit +PendingIntent will throw an exception, follow either of these +recommendations: for an existing PendingIntent use FLAG_NO_CREATE and +for a new PendingIntent either make it immutable or make the Intent +within explicit [MutableImplicitPendingIntent] + PendingIntent.getActivity(null, 0, new Intent(), PendingIntent.FLAG_MUTABLE); + ---------------------------------------------------------------------------- +src/test/pkg/PendingIntentJavaTest.java:11:Error: Mutable implicit +PendingIntent will throw an exception, follow either of these +recommendations: for an existing PendingIntent use FLAG_NO_CREATE and +for a new PendingIntent either make it immutable or make the Intent +within explicit [MutableImplicitPendingIntent] + PendingIntent.getBroadcast(null, 0, new Intent("TEST"), PendingIntent.FLAG_MUTABLE); + ----------------------------------------------------------------------------------- +src/test/pkg/PendingIntentJavaTest.java:13:Error: Mutable implicit +PendingIntent will throw an exception, follow either of these +recommendations: for an existing PendingIntent use FLAG_NO_CREATE and +for a new PendingIntent either make it immutable or make the Intent +within explicit [MutableImplicitPendingIntent] + PendingIntent.getService(null, 0, mIntent, PendingIntent.FLAG_MUTABLE); + ---------------------------------------------------------------------- +src/test/pkg/PendingIntentJavaTest.java:14:Error: Mutable implicit +PendingIntent will throw an exception, follow either of these +recommendations: for an existing PendingIntent use FLAG_NO_CREATE and +for a new PendingIntent either make it immutable or make the Intent +within explicit [MutableImplicitPendingIntent] + PendingIntent.getActivities(null, 0, { new Intent(), mIntent }, PendingIntent.FLAG_MUTABLE); + ------------------------------------------------------------------------------------------- +src/test/pkg/PendingIntentKotlinTest.kt:10:Error: Mutable implicit +PendingIntent will throw an exception, follow either of these +recommendations: for an existing PendingIntent use FLAG_NO_CREATE and +for a new PendingIntent either make it immutable or make the Intent +within explicit [MutableImplicitPendingIntent] + PendingIntent.getActivity(null, 0, Intent(), PendingIntent.FLAG_MUTABLE) + ------------------------------------------------------------------------ +src/test/pkg/PendingIntentKotlinTest.kt:11:Error: Mutable implicit +PendingIntent will throw an exception, follow either of these +recommendations: for an existing PendingIntent use FLAG_NO_CREATE and +for a new PendingIntent either make it immutable or make the Intent +within explicit [MutableImplicitPendingIntent] + PendingIntent.getBroadcast(null, 0, Intent("TEST"), PendingIntent.FLAG_MUTABLE) + ------------------------------------------------------------------------------- +src/test/pkg/PendingIntentKotlinTest.kt:13:Error: Mutable implicit +PendingIntent will throw an exception, follow either of these +recommendations: for an existing PendingIntent use FLAG_NO_CREATE and +for a new PendingIntent either make it immutable or make the Intent +within explicit [MutableImplicitPendingIntent] + PendingIntent.getService(null, 0, mIntent, PendingIntent.FLAG_MUTABLE) + ---------------------------------------------------------------------- +src/test/pkg/PendingIntentKotlinTest.kt:14:Error: Mutable implicit +PendingIntent will throw an exception, follow either of these +recommendations: for an existing PendingIntent use FLAG_NO_CREATE and +for a new PendingIntent either make it immutable or make the Intent +within explicit [MutableImplicitPendingIntent] + PendingIntent.getActivities(null, 0, listOf(Intent(), mIntent), PendingIntent.FLAG_MUTABLE) + ------------------------------------------------------------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`src/test/pkg/PendingIntentJavaTest.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; + +import android.app.PendingIntent; +import android.content.Intent; +import android.net.Uri; + +public class PendingIntentJavaTest { + Uri mUri; + protected void test() { + PendingIntent.getActivity(null, 0, new Intent(), PendingIntent.FLAG_MUTABLE); + PendingIntent.getBroadcast(null, 0, new Intent("TEST"), PendingIntent.FLAG_MUTABLE); + Intent mIntent = new Intent("TEST", mUri); + PendingIntent.getService(null, 0, mIntent, PendingIntent.FLAG_MUTABLE); + PendingIntent.getActivities(null, 0, { new Intent(), mIntent }, PendingIntent.FLAG_MUTABLE); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/PendingIntentKotlinTest.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg + +import android.app.PendingIntent +import android.content.Intent +import android.net.Uri + +class PendingIntentKotlinTest { + val mUri: Uri + fun test() { + PendingIntent.getActivity(null, 0, Intent(), PendingIntent.FLAG_MUTABLE) + PendingIntent.getBroadcast(null, 0, Intent("TEST"), PendingIntent.FLAG_MUTABLE) + val mIntent = Intent("TEST", mUri) + PendingIntent.getService(null, 0, mIntent, PendingIntent.FLAG_MUTABLE) + PendingIntent.getActivities(null, 0, listOf(Intent(), mIntent), PendingIntent.FLAG_MUTABLE) + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/PendingIntentMutableImplicitDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("MutableImplicitPendingIntent") + fun method() { + getActivity(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("MutableImplicitPendingIntent") + void method() { + getActivity(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection MutableImplicitPendingIntent + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="MutableImplicitPendingIntent" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'MutableImplicitPendingIntent' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore MutableImplicitPendingIntent ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/MutatingSharedPrefs.md.html b/docs/checks/MutatingSharedPrefs.md.html index 7c72dd3a..183537f3 100644 --- a/docs/checks/MutatingSharedPrefs.md.html +++ b/docs/checks/MutatingSharedPrefs.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 4.2.0 (May 2021) Affects : Kotlin and Java files Editing @@ -26,14 +28,12 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/SharedPrefsDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/SharedPrefsDetectorTest.kt) -Copyright Year -: 2020 As stated in the docs for `SharedPreferences.getStringSet`, you must not modify the set returned by `getStringSet`: - "Note that you must not modify the set instance returned -by this call. The consistency of the stored data is not guaranteed + "Note that you must not modify the set instance returned +by this call. The consistency of the stored data is not guaranteed if you do, nor is your ability to modify the instance at all." (##) Example @@ -42,18 +42,12 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/test.kt:11:Warning: Do not modify the set returned by SharedPreferences.getStringSet()` [MutatingSharedPrefs] - s.removeIf { it.length < 3 } ---------------------------- - - src/test/pkg/test.kt:12:Warning: Do not modify the set returned by SharedPreferences.getStringSet()` [MutatingSharedPrefs] - s.add("error") -------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/NamespaceTypo.md.html b/docs/checks/NamespaceTypo.md.html index 2550ca55..d8c90dda 100644 --- a/docs/checks/NamespaceTypo.md.html +++ b/docs/checks/NamespaceTypo.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Manifest files and resource files Editing @@ -45,11 +47,8 @@ res/layout/wrong_namespace.xml:2:Error: Unexpected namespace URI bound to the "android" prefix, was http://schemas.android.com/apk/res/andriod, expected http://schemas.android.com/apk/res/android [NamespaceTypo] - <LinearLayout xmlns:android="http://schemas.android.com/apk/res/andriod" ------------------------------------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/NamingPattern.md.html b/docs/checks/NamingPattern.md.html new file mode 100644 index 00000000..fc0101f0 --- /dev/null +++ b/docs/checks/NamingPattern.md.html @@ -0,0 +1,175 @@ + +(#) Names should be well named + +!!! WARNING: Names should be well named + This is a warning. + +Id +: `NamingPattern` +Summary +: Names should be well named +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html) +Since +: 0.6.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/main/kotlin/com/vanniktech/lintrules/android/NamingPatternDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/NamingPatternDetectorTest.kt) + +Sometimes there is more than one reasonable way to convert an English +phrase into camel case, such as when acronyms or unusual constructs like +"IPv6" or "iOS" are present. XML HTTP request becomes XmlHttpRequest. +XMLHTTPRequest would be incorrect. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/Foo.java:5:Warning: iOSVersion is not named in defined camel +case [NamingPattern] + String iOSVersion; + ---------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/Foo.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package foo; + +class Foo { + private void fun() { + String iOSVersion; + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/NamingPatternDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `NamingPatternDetector.incorrectVariableName`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-android:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-android:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.android) + +# libs.versions.toml +[versions] +lint-rules-android = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-android = { + module = "com.vanniktech:lint-rules-android", + version.ref = "lint-rules-android" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("NamingPattern") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("NamingPattern") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection NamingPattern + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="NamingPattern" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'NamingPattern' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore NamingPattern ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/NegativeMargin.md.html b/docs/checks/NegativeMargin.md.html index 0fd8c2eb..927f1423 100644 --- a/docs/checks/NegativeMargin.md.html +++ b/docs/checks/NegativeMargin.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 0.2.0 (October 2014) Affects : Resource files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/NegativeMarginDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/NegativeMarginDetectorTest.kt) -Copyright Year -: 2014 Margin values should be positive. Negative values are generally a sign that you are making assumptions about views surrounding the current one, @@ -46,11 +46,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/negative_margins.xml:11:Warning: Margin values should not be negative [NegativeMargin] - <TextView android:layout_marginTop="-1dp"/> <!-- WARNING --> ------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/NestedScrolling.md.html b/docs/checks/NestedScrolling.md.html index 60441783..b1ae05de 100644 --- a/docs/checks/NestedScrolling.md.html +++ b/docs/checks/NestedScrolling.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -39,11 +41,8 @@ res/layout/scrolling.xml:11:Warning: The vertically scrolling ScrollView should not contain another vertically scrolling widget (ListView) [NestedScrolling] - <ListView -------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/NestedWeights.md.html b/docs/checks/NestedWeights.md.html index f8e5b944..78b32772 100644 --- a/docs/checks/NestedWeights.md.html +++ b/docs/checks/NestedWeights.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -40,11 +42,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/nested_weights.xml:23:Warning: Nested weights are bad for performance [NestedWeights] - android:layout_weight="1" ------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/NetworkSecurityConfig.md.html b/docs/checks/NetworkSecurityConfig.md.html index 3b92d4f7..3c2d6512 100644 --- a/docs/checks/NetworkSecurityConfig.md.html +++ b/docs/checks/NetworkSecurityConfig.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 2.3.0 (March 2017) Affects : Resource files Editing @@ -30,8 +32,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/NetworkSecurityConfigDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/NetworkSecurityConfigDetectorTest.java) -Copyright Year -: 2016 Ensures that a `` file, which is pointed to by an `android:networkSecurityConfig` attribute in the manifest file, is @@ -46,25 +46,16 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/xml/network_config.xml:4:Error: Unexpected element [NetworkSecurityConfig] - <include domain="file"/> ------- - - res/xml/network_config.xml:7:Error: Nested elements are not allowed in base-config [NetworkSecurityConfig] - <domain-config> ------------- - - res/xml/network_config.xml:12:Error: No elements in [NetworkSecurityConfig] - <domain-config> ------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/NewApi.md.html b/docs/checks/NewApi.md.html index cc574b09..ae38be06 100644 --- a/docs/checks/NewApi.md.html +++ b/docs/checks/NewApi.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files, manifest files and resource files Editing @@ -63,11 +65,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test.kt:6:Error: Call requires API level 23 (current min is 21): android.net.ConnectivityManager#getActiveNetwork [NewApi] - val network = cm.activeNetwork // Error: Requires API 23 ------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here are the relevant source files: diff --git a/docs/checks/NewerVersionAvailable.md.html b/docs/checks/NewerVersionAvailable.md.html index d1662669..b4c3c65e 100644 --- a/docs/checks/NewerVersionAvailable.md.html +++ b/docs/checks/NewerVersionAvailable.md.html @@ -8,8 +8,6 @@ : `NewerVersionAvailable` Summary : Newer Library Versions Available -Note -: **This issue is disabled by default**; use `--enable NewerVersionAvailable` Severity : Warning Category @@ -20,8 +18,10 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects -: Gradle build files +: Gradle build files and TOML files Editing : This check runs on the fly in the IDE editor Implementation @@ -45,52 +45,53 @@ Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -build.gradle:8:Warning: A newer version of com.google.guava:guava than -24.1-android is available: 30.1-android [NewerVersionAvailable] - - compile 'com.google.guava:guava:24.1-android' - ------------------------------------- - - -build.gradle:9:Warning: A newer version of com.google.guava:guava than -24.1-jre is available: 30.1-jre [NewerVersionAvailable] - - compile 'com.google.guava:guava:24.1-jre' - --------------------------------- - - -build.gradle:10:Warning: A newer version of com.google.guava:guava than -16.0-rc1 is available: 30.1-android [NewerVersionAvailable] - - compile 'com.google.guava:guava:16.0-rc1' - --------------------------------- - - -build.gradle:11:Warning: A newer version of com.google.guava:guava than -16.0 is available: 30.1-android [NewerVersionAvailable] - - compile 'com.google.guava:guava:16.0' - ----------------------------- - - +../gradle/libs.versions.toml:2:Warning: A newer version of +com.google.guava:guava than 11.0.2 is available: 30.1-android +[NewerVersionAvailable] +guavaVersion = "11.0.2" + -------- +../gradle/libs.versions.toml:12:Warning: A newer version of +com.autonomousapps.dependency-analysis than 1.0.0 is available: 1.20.0 +[NewerVersionAvailable] +gradlePlugins-dependency-analysis = "1.0.0" + ------- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: -`build.gradle`: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~groovy linenumbers -apply plugin: 'com.android.application' - -android { - compileSdkVersion 29 -} - -dependencies { - compile 'com.google.guava:guava:24.1-android' - compile 'com.google.guava:guava:24.1-jre' - compile 'com.google.guava:guava:16.0-rc1' - compile 'com.google.guava:guava:16.0' -} +`../gradle/libs.versions.toml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~toml linenumbers +[versions] +guavaVersion = "11.0.2" +appCompatVersion="13.0.0" +wearableVersion=" 1.2.0 " +# Test comment suppression: +#noinspection GradleDependency +multi-dex="1.0.0" +gradlePlugins-agp = "8.0.0" +gradlePlugins-agp-alpha = "8.1.0-alpha01" +gradlePlugins-agp-dev = "8.2.0-dev" +gradlePlugins-crashlytics = "2.9.2" +gradlePlugins-dependency-analysis = "1.0.0" + +[libraries] +com-google-guava = { module = "com.google.guava:guava", version.ref = "guavaVersion"} +appcompat = { module = "com.android.support:appcompat-v7", version.ref = "appCompatVersion" } +wearable-support = { group = " com.google.android.support ", name =" wearable ", version.ref = " wearableVersion " } +multidex-lib = { module = "com.android.support:multidex", version.ref = "multi-dex" } + +[bundles] +misc = [ + "com-google-guava", + "appcompat", +] + +[plugins] +android-application = { id = "com.android.application", version.ref = "gradlePlugins-agp" } +android-application2 = { id = "com.android.application", version.ref = "gradlePlugins-agp-alpha" } +android-application3 = { id = "com.android.application", version.ref = "gradlePlugins-agp-dev" } +crashlytics = { id = "com.google.firebase.crashlytics", version.ref = "gradlePlugins-crashlytics" } +dependency-analysis = { id = "com.autonomousapps.dependency-analysis", version.ref = "gradlePlugins-dependency-analysis" } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can also visit the @@ -98,7 +99,7 @@ for the unit tests for this check to see additional scenarios. The above example was automatically extracted from the first unit test -found for this lint check, `GradleDetector.testGuavaVersionsAndroidVsJre`. +found for this lint check, `GradleDetector.testTomlVersionCatalogFile`. To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=192708. diff --git a/docs/checks/NfcTechWhitespace.md.html b/docs/checks/NfcTechWhitespace.md.html index 90b27afb..5702ed70 100644 --- a/docs/checks/NfcTechWhitespace.md.html +++ b/docs/checks/NfcTechWhitespace.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -46,25 +48,16 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/xml/nfc_tech_list_formatted.xml:6:Error: There should not be any whitespace inside elements [NfcTechWhitespace] - android.nfc.tech.NfcA --------------------- - - res/xml/nfc_tech_list_formatted.xml:12:Error: There should not be any whitespace inside elements [NfcTechWhitespace] - android.nfc.tech.MifareUltralight --------------------------------- - - res/xml/nfc_tech_list_formatted.xml:18:Error: There should not be any whitespace inside elements [NfcTechWhitespace] - android.nfc.tech.ndefformatable ------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/NioDesugaring.md.html b/docs/checks/NioDesugaring.md.html new file mode 100644 index 00000000..38548e0e --- /dev/null +++ b/docs/checks/NioDesugaring.md.html @@ -0,0 +1,104 @@ + +(#) Unsupported `java.nio` operations + +!!! ERROR: Unsupported `java.nio` operations + This is an error. + +Id +: `NioDesugaring` +Summary +: Unsupported `java.nio` operations +Severity +: Error +Category +: Correctness +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.9.0 (March 2025) +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ApiDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ApiDetectorTest.java) + +Core library desugaring handles most of the `java.nio` APIs, but prior +to API level 26, a handful of APIs are not fully supported. + +This is detailed in the documentation at +https://developer.android.com/studio/write/java11-nio-support-table#java-nio-customizations +. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("NioDesugaring") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("NioDesugaring") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection NioDesugaring + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="NioDesugaring" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'NioDesugaring' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore NioDesugaring ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/NoCollectCallFound.md.html b/docs/checks/NoCollectCallFound.md.html new file mode 100644 index 00000000..9a993b7c --- /dev/null +++ b/docs/checks/NoCollectCallFound.md.html @@ -0,0 +1,236 @@ + +(#) You must call collect on the given progress flow when using PredictiveBackHandler + +!!! ERROR: You must call collect on the given progress flow when using PredictiveBackHandler + This is an error. + +Id +: `NoCollectCallFound` +Summary +: You must call collect on the given progress flow when using PredictiveBackHandler +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: Jetpack Activity Compose +Identifier +: androidx.activity.compose +Feedback +: https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.7+ +Artifact +: [androidx.activity:activity-compose](androidx_activity_activity-compose.md.html) +Since +: 1.8.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/activity/activity-compose-lint/src/main/java/androidx/activity/compose/lint/CollectProgressDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/activity/activity-compose-lint/src/test/java/androidx/activity/compose/lint/CollectProgressDetectorTest.kt) +Copyright Year +: 2023 + +You must call collect on the progress in the onBack function. The +collect call is what properly splits the callback so it knows what to do +when the back gestures is started vs when it is completed. Failing to +call collect will cause all code in the block to run when the gesture is +started. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/com/example/test.kt:9:Error: You must call collect() on Flow +progress [NoCollectCallFound] + PredictiveBackHandler { progress -> } + -------- +src/com/example/test.kt:13:Error: You must call collect() on Flow +progress [NoCollectCallFound] + PredictiveBackHandler { progress -> } + -------- +src/com/example/test.kt:17:Error: You must call collect() on Flow +progress [NoCollectCallFound] + PredictiveBackHandler { progress -> } + -------- +src/com/example/test.kt:26:Error: You must call collect() on Flow +progress [NoCollectCallFound] + PredictiveBackHandler { progress -> } + -------- +src/com/example/test.kt:29:Error: You must call collect() on Flow +progress [NoCollectCallFound] + PredictiveBackHandler { progress -> } + -------- +src/com/example/test.kt:35:Error: You must call collect() on Flow +progress [NoCollectCallFound] + PredictiveBackHandler { progress -> } + -------- +src/com/example/test.kt:39:Error: You must call collect() on Flow +progress [NoCollectCallFound] + PredictiveBackHandler { progress -> } + -------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/com/example/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package com.example + +import androidx.compose.runtime.Composable +import androidx.activity.compose.PredictiveBackHandler + +@Composable +fun Test() { + PredictiveBackHandler { progress -> } +} + +val lambda = @Composable { + PredictiveBackHandler { progress -> } +} + +val lambda2: @Composable () -> Unit = { + PredictiveBackHandler { progress -> } +} + +@Composable +fun LambdaParameter(content: @Composable () -> Unit) {} + +@Composable +fun Test2() { + LambdaParameter(content = { + PredictiveBackHandler { progress -> } + }) + LambdaParameter { + PredictiveBackHandler { progress -> } + } +} + +fun test3() { + val localLambda1 = @Composable { + PredictiveBackHandler { progress -> } + } + + val localLambda2: @Composable () -> Unit = { + PredictiveBackHandler { progress -> } + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/activity/activity-compose-lint/src/test/java/androidx/activity/compose/lint/CollectProgressDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `CollectProgressDetector.errors`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=612128. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.activity:activity-compose:1.11.0-rc01") + +// build.gradle +implementation 'androidx.activity:activity-compose:1.11.0-rc01' + +// build.gradle.kts with version catalogs: +implementation(libs.activity.compose) + +# libs.versions.toml +[versions] +activity-compose = "1.11.0-rc01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +activity-compose = { + module = "androidx.activity:activity-compose", + version.ref = "activity-compose" +} +``` + +1.11.0-rc01 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.activity:activity-compose](androidx_activity_activity-compose.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("NoCollectCallFound") + fun method() { + PredictiveBackHandler(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("NoCollectCallFound") + void method() { + PredictiveBackHandler(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection NoCollectCallFound + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="NoCollectCallFound" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'NoCollectCallFound' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore NoCollectCallFound ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/NoHardKeywords.md.html b/docs/checks/NoHardKeywords.md.html index 1ec1ed04..0568c8f6 100644 --- a/docs/checks/NoHardKeywords.md.html +++ b/docs/checks/NoHardKeywords.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.2.0 (September 2018) Affects : Kotlin and Java files Editing @@ -30,8 +32,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/InteroperabilityDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/InteroperabilityDetectorTest.kt) -Copyright Year -: 2018 Do not use Kotlin’s hard keywords as the name of methods or fields. These require the use of backticks to escape when calling from Kotlin. @@ -51,23 +51,17 @@ hard keywords ("fun"); see https://android.github.io/kotlin-guides/interop.html#no-hard-keywords [NoHardKeywords] - public void fun() { } --- - - src/test/pkg/Test.java:7:Warning: Avoid field names that are Kotlin hard keywords ("object"); see https://android.github.io/kotlin-guides/interop.html#no-hard-keywords [NoHardKeywords] - public Object object = null; ------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `src/test/pkg/Test.java`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers @@ -81,6 +75,23 @@ } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/test/pkg/Keywords.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; + +import org.json.JSONException; +import org.json.JSONStringer; + +@SuppressWarnings("ClassNameDiffersFromFileName") + public class Keywords extends JSONStringer { + // Using Kotlin hard keyword, but can't be helped; overrides library name + @Override + public JSONStringer object() throws JSONException { + return super.object(); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/InteroperabilityDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/NoOp.md.html b/docs/checks/NoOp.md.html new file mode 100644 index 00000000..4fd3e77e --- /dev/null +++ b/docs/checks/NoOp.md.html @@ -0,0 +1,157 @@ + +(#) NoOp Code + +!!! WARNING: NoOp Code + This is a warning. + +Id +: `NoOp` +Summary +: NoOp Code +Note +: **This issue is disabled by default**; use `--enable NoOp` +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.1.0 (July 2023) +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/NoOpDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/NoOpDetectorTest.kt) + +This check looks for code which looks like it's a no-op -- usually +leftover expressions from interactive debugging, but in some cases bugs +where you had intended to do something with the expression such as +assign it to a field. + +(##) Options + +You can configure this lint checks using the following options: + +(###) pure-getters + +Whether to assume methods with getter-names have no side effects. +Getter methods (where names start with `get` or `is`, and have non-void return types, and no arguments) should not have side effects. With this option turned on, lint will assume that is the case and will list any getter calls whose results are ignored as suspicious code. + +Default is false. + +Example `lint.xml`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<lint> + <issue id="NoOp"> + <option name="pure-getters" value="false" /> + </issue> +</lint> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/Test.kt:3:Warning: This reference is unused: s === o [NoOp] + s === o // ERROR 1 + ------- +src/Test.kt:4:Warning: This call result is unused: toString [NoOp] + o.toString() // ERROR 2 + ------------ +src/Test.kt:5:Warning: This reference is unused: length [NoOp] + s.length // ERROR 3 + ------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/Test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +class Test { + fun test(s: String, o: Any) { + s === o // ERROR 1 + o.toString() // ERROR 2 + s.length // ERROR 3 + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/NoOpDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("NoOp") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("NoOp") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection NoOp + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="NoOp" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'NoOp' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore NoOp ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/NonConstantResourceId.md.html b/docs/checks/NonConstantResourceId.md.html index fe038d52..0229b578 100644 --- a/docs/checks/NonConstantResourceId.md.html +++ b/docs/checks/NonConstantResourceId.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 4.1.0 (October 2020) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/NonConstantResourceIdDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/NonConstantResourceIdDetectorTest.kt) -Copyright Year -: 2020 Avoid the usage of resource IDs where constant expressions are required. @@ -43,19 +43,13 @@ src/test/pkg/SwitchTest.java:13:Warning: Resource IDs will be non-final by default in Android Gradle Plugin version 8.0, avoid using them in switch case statements [NonConstantResourceId] - case R.styleable.FontFamilyFont_android_fontWeight: someValue = 1; break; --------------------------------------------- - - src/test/pkg/SwitchTest.java:17:Warning: Resource IDs will be non-final by default in Android Gradle Plugin version 8.0, avoid using them in switch case statements [NonConstantResourceId] - case R.id.text: someValue = 3; break; --------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/NonResizeableActivity.md.html b/docs/checks/NonResizeableActivity.md.html index 386cdfde..fe6c5980 100644 --- a/docs/checks/NonResizeableActivity.md.html +++ b/docs/checks/NonResizeableActivity.md.html @@ -1,13 +1,13 @@ -(#) Activity is set to be non resizeable +(#) Activity is set to be non-resizeable -!!! WARNING: Activity is set to be non resizeable +!!! WARNING: Activity is set to be non-resizeable This is a warning. Id : `NonResizeableActivity` Summary -: Activity is set to be non resizeable +: Activity is set to be non-resizeable Severity : Warning Category @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.6.0 (February 2020) Affects : Manifest files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ChromeOsDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ChromeOsDetectorTest.java) -Copyright Year -: 2016 The `` element should be allowed to be resized to allow users to take advantage of the multi-window environments available on larger @@ -50,11 +50,8 @@ advantage of the multi-window environment on all devices. NOTE: beginning with Android 12, all apps run in multi-window mode on large screen devices. [NonResizeableActivity] - <activity android:name=".MainActivity" android:resizeableActivity="false"/> ---------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/NotConstructor.md.html b/docs/checks/NotConstructor.md.html index d2856cc0..fe1e4178 100644 --- a/docs/checks/NotConstructor.md.html +++ b/docs/checks/NotConstructor.md.html @@ -6,8 +6,6 @@ Id : `NotConstructor` -Alias -: MethodNameSameAsClassName Summary : Not a Constructor Severity @@ -20,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.2.0 (May 2022) Affects : Kotlin and Java files Editing @@ -28,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/WrongConstructorDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/WrongConstructorDetectorTest.kt) -Copyright Year -: 2021 This check catches methods that look like they were intended to be constructors, but aren't. @@ -40,11 +38,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/PnrUtils.java:4:Warning: Method PnrUtils looks like a constructor but is a normal method [NotConstructor] - public PnrUtils PnrUtils() { ^ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/NotInterpolated.md.html b/docs/checks/NotInterpolated.md.html index d32c3432..9e4ac7bc 100644 --- a/docs/checks/NotInterpolated.md.html +++ b/docs/checks/NotInterpolated.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 2.0.0 (April 2016) Affects : Gradle build files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GradleDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) -Copyright Year -: 2014 To insert the value of a variable, you can use `${variable}` inside a string literal, but **only** if you are using double quotes! @@ -44,11 +44,8 @@ build.gradle:5:Error: It looks like you are trying to substitute a version variable, but using single quotes ('). For Groovy string interpolation you must use double quotes ("). [NotInterpolated] - compile 'com.android.support:design:${supportLibVersion}' --------------------------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/NotSibling.md.html b/docs/checks/NotSibling.md.html index 06b360b1..ce1a41a2 100644 --- a/docs/checks/NotSibling.md.html +++ b/docs/checks/NotSibling.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -41,14 +43,11 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/layout1.xml:18:Error: @id/my_id1 is not a sibling in the same RelativeLayout [NotSibling] - android:layout_alignTop="@id/my_id1" ------------------------------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `res/layout/layout1.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -99,6 +98,33 @@ </RelativeLayout> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/layout/layout2.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" > + + <Button + android:id="@+id/my_id2" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Button" /> + +</LinearLayout> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/values/ids.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers + +<resources> + + <item name="my_id0" type="id"/> + <item name="my_id1" type="id"/> + +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/WrongIdDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/NotificationIconCompatibility.md.html b/docs/checks/NotificationIconCompatibility.md.html index c3bf3e67..796d6af6 100644 --- a/docs/checks/NotificationIconCompatibility.md.html +++ b/docs/checks/NotificationIconCompatibility.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.2.0 (September 2018) Affects : Kotlin and Java files, manifest files and resource files Editing @@ -26,14 +28,12 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/IconDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/IconDetectorTest.java) -Copyright Year -: 2011 Notification icons should define a raster image to support Android versions below 5.0 (API 21). Note that the way Lint decides whether an icon is a notification icon is based on the filename prefix `ic_stat_`. This corresponds to the naming convention documented in -https://material.io/design/iconography/ +https://d.android.com/r/studio-ui/designer/material/iconography. (##) Example @@ -42,14 +42,53 @@ res/drawable/icon1.xml:Warning: Notification icon icon1 has to have a raster image to support Android versions below 5.0 (API 21) [NotificationIconCompatibility] - 0 errors, 1 warnings - - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: + +`src/test/pkg/NotificationTest.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; + +import android.app.Notification; +import android.app.Notification.Builder; +import android.content.Context; +import android.graphics.Bitmap; + +@SuppressWarnings({ "deprecation", "unused", "javadoc" }) +class NotificationTest { + public void test1() { + Notification notification = new Notification(R.drawable.icon1, "Test1", 0); + } + + public void test2() { + int resource = R.drawable.icon2; + Notification notification = new Notification(resource, "Test1", 0); + } + + public void test3() { + int icon = R.drawable.icon3; + CharSequence tickerText = "Hello"; + long when = System.currentTimeMillis(); + Notification notification = new Notification(icon, tickerText, when); + } + + public void test4(Context context, String sender, String subject, Bitmap bitmap) { + Notification notification = new Notification.Builder(context) + .setContentTitle("New mail from " + sender.toString()) + .setContentText(subject).setSmallIcon(R.drawable.icon4) + .setLargeIcon(bitmap).build(); + } + + public void test5(Context context, String sender, String subject, Bitmap bitmap) { + Notification notification = new Builder(context) + .setContentTitle("New mail from " + sender.toString()) + .setContentText(subject).setSmallIcon(R.drawable.icon5) + .setLargeIcon(bitmap).build(); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `res/drawable/icon1.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -69,22 +108,6 @@ You can suppress false positives using one of the following mechanisms: -* Adding the suppression attribute - `tools:ignore="NotificationIconCompatibility"` on the problematic - XML element (or one of its enclosing elements). You may also need to - add the following namespace declaration on the root element in the - XML file if it's not already there: - `xmlns:tools="http://schemas.android.com/tools"`. - - ```xml - <?xml version="1.0" encoding="UTF-8"?> - <manifest xmlns:tools="http://schemas.android.com/tools"> - ... - <application tools:ignore="NotificationIconCompatibility" .../> - ... - </manifest> - ``` - * Using a suppression annotation like this on the enclosing element: @@ -113,6 +136,22 @@ problematicStatement() ``` +* Adding the suppression attribute + `tools:ignore="NotificationIconCompatibility"` on the problematic + XML element (or one of its enclosing elements). You may also need to + add the following namespace declaration on the root element in the + XML file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <manifest xmlns:tools="http://schemas.android.com/tools"> + ... + <application tools:ignore="NotificationIconCompatibility" .../> + ... + </manifest> + ``` + * Using a special `lint.xml` file in the source tree which turns off the check in that folder and any sub folder. A simple file might look like this: diff --git a/docs/checks/NotificationId0.md.html b/docs/checks/NotificationId0.md.html index 399a94fb..642a1581 100644 --- a/docs/checks/NotificationId0.md.html +++ b/docs/checks/NotificationId0.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.3.0 (September 2022) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/InvalidNotificationIdDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/InvalidNotificationIdDetectorTest.kt) -Copyright Year -: 2022 The notification id **cannot** be 0; using 0 here can make the service not run in the foreground. @@ -38,18 +38,12 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/ServiceTest.kt:13:Error: The notification id cannot be 0 [NotificationId0] - service.startForeground(0, notification) // ERROR 1: cannot be zero - - - src/test/pkg/ServiceTest.kt:14:Error: The notification id cannot be 0 [NotificationId0] - service.startForeground(MY_ID, notification, 1) // ERROR 2: cannot be zero ----- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/NotificationPermission.md.html b/docs/checks/NotificationPermission.md.html index dc16cb01..d5217bc4 100644 --- a/docs/checks/NotificationPermission.md.html +++ b/docs/checks/NotificationPermission.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.4.0 (January 2023) Affects : Kotlin and Java files and library bytecode Editing @@ -26,12 +28,13 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/NotificationPermissionDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/NotificationPermissionDetectorTest.kt) -Copyright Year -: 2022 When targeting Android 13 and higher, posting permissions requires holding the runtime permission `android.permission.POST_NOTIFICATIONS`. +!!! Tip + This lint check has an associated quickfix available in the IDE. + (##) Example Here is an example of lint warnings produced by this check: @@ -39,11 +42,8 @@ src/test/pkg/NotificationTestAndroidx.java:21:Error: When targeting Android 13 or higher, posting a permission requires holding the POST_NOTIFICATIONS permission [NotificationPermission] - notificationManager.notify(id, notification); -------------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here are the relevant source files: diff --git a/docs/checks/NotificationTrampoline.md.html b/docs/checks/NotificationTrampoline.md.html index b1737e4c..bef3c2ee 100644 --- a/docs/checks/NotificationTrampoline.md.html +++ b/docs/checks/NotificationTrampoline.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 4.3.0-alpha01 (December 2020) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/NotificationTrampolineDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/NotificationTrampolineDetectorTest.kt) -Copyright Year -: 2020 Activities should not be launched indirectly from a notification via an intermediate `BroadcastReceiver` or `Service`. This can lead to @@ -44,23 +44,37 @@ BroadcastReceiver (BroadcastTrampoline) which launches activities; this indirection is bad for performance, and activities should be launched directly from the notification [NotificationTrampoline] - .setContentIntent(notificationPendingIntent) ------------------------------------------- - - src/test/pkg/NotificationTest.java:38:Error: This intent launches a BroadcastReceiver (BroadcastTrampoline) which launches activities; this indirection is bad for performance, and activities should be launched directly from the notification [NotificationTrampoline] - .addAction(android.R.drawable.ic_dialog_email, "Launch Receiver From Action", ^ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Here are the relevant source files: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/test/pkg/BroadcastTrampoline.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; -Here is the source file referenced above: +public class BroadcastTrampoline extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + // The start below will be blocked + Intent i = new Intent(); + i.setClassName("test.pkg", "test.pkg.SecondActivity"); + i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(i); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `src/test/pkg/NotificationTest.java`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers diff --git a/docs/checks/NotifyDataSetChanged.md.html b/docs/checks/NotifyDataSetChanged.md.html index 856b2693..ee61cbc8 100644 --- a/docs/checks/NotifyDataSetChanged.md.html +++ b/docs/checks/NotifyDataSetChanged.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.0.0 (July 2021) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/RecyclerViewDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/RecyclerViewDetectorTest.kt) -Copyright Year -: 2015 The `RecyclerView` adapter's `onNotifyDataSetChanged` method does not specify what about the data set has changed, forcing any observers to @@ -42,11 +42,8 @@ src/test/pkg/RecyclerViewTest.java:24:Warning: It will always be more efficient to use more specific change events if you can. Rely on notifyDataSetChanged as a last resort. [NotifyDataSetChanged] - notifyDataSetChanged(); ---------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/NullSafeMutableLiveData-2.md.html b/docs/checks/NullSafeMutableLiveData-2.md.html new file mode 100644 index 00000000..f4d95a27 --- /dev/null +++ b/docs/checks/NullSafeMutableLiveData-2.md.html @@ -0,0 +1,167 @@ + +(#) LiveData value assignment nullability mismatch + +!!! ERROR: LiveData value assignment nullability mismatch + This is an error, and is also enforced at build time when + supported by the build system. For Android this means it will + run during release builds. + +Id +: `NullSafeMutableLiveData` +Summary +: LiveData value assignment nullability mismatch +Severity +: Fatal +Category +: Interoperability: Kotlin Interoperability +Platform +: Android +Vendor +: Android Open Source Project +Identifier +: androidx.lifecycle +Feedback +: https://issuetracker.google.com/issues/new?component=413132 +Min +: Lint 7.0 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [androidx.lifecycle:lifecycle-livedata-core-ktx](androidx_lifecycle_lifecycle-livedata-core-ktx.md.html) +Since +: 2.3.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/lifecycle/lifecycle-livedata-core-lint/src/main/java/androidx/lifecycle/lint/NonNullableMutableLiveDataDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/lifecycle/lifecycle-livedata-core-lint/src/test/java/androidx/lifecycle/livedata/core/lint/NonNullableMutableLiveDataDetectorTest.kt) +Copyright Year +: 2019 + +This check ensures that LiveData values are not null when explicitly + declared as non-nullable. + + Kotlin interoperability does not support enforcing +explicit null-safety when using generic Java type +parameters. Since LiveData is a Java class its value can always + be null even when its type is explicitly declared as +non-nullable. This can lead to runtime exceptions from +reading a null LiveData value that is assumed to be +non-nullable. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Repackaged + +This lint check appears to have been packaged in other artifacts as +well. Issue id's must be unique, so you cannot combine these libraries. +Also defined in: +* NullSafeMutableLiveData: LiveData value assignment nullability mismatch (this issue) +* [NullSafeMutableLiveData from androidx.lifecycle:lifecycle-livedata-core:2.9.0-rc01](NullSafeMutableLiveData.md.html) +* [NullSafeMutableLiveData from androidx.lifecycle:lifecycle-livedata-core-ktx:2.8.0-alpha01](NullSafeMutableLiveData-2.md.html) + + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.lifecycle:lifecycle-livedata-core-ktx:2.8.0-alpha01") + +// build.gradle +implementation 'androidx.lifecycle:lifecycle-livedata-core-ktx:2.8.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.lifecycle.livedata.core.ktx) + +# libs.versions.toml +[versions] +lifecycle-livedata-core-ktx = "2.8.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lifecycle-livedata-core-ktx = { + module = "androidx.lifecycle:lifecycle-livedata-core-ktx", + version.ref = "lifecycle-livedata-core-ktx" +} +``` + +2.8.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.lifecycle:lifecycle-livedata-core-ktx](androidx_lifecycle_lifecycle-livedata-core-ktx.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("NullSafeMutableLiveData") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("NullSafeMutableLiveData") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection NullSafeMutableLiveData + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="NullSafeMutableLiveData" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'NullSafeMutableLiveData' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore NullSafeMutableLiveData ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/NullSafeMutableLiveData.md.html b/docs/checks/NullSafeMutableLiveData.md.html index 0d00822a..129653a8 100644 --- a/docs/checks/NullSafeMutableLiveData.md.html +++ b/docs/checks/NullSafeMutableLiveData.md.html @@ -22,26 +22,83 @@ : androidx.lifecycle Feedback : https://issuetracker.google.com/issues/new?component=413132 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.lifecycle:lifecycle-livedata-core](androidx_lifecycle_lifecycle-livedata-core.md.html) +Since +: 2.3.0 Affects : Kotlin and Java files Editing : This check runs on the fly in the IDE editor Implementation -: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/lifecycle/lifecycle-livedata-core-ktx-lint/src/main/java/androidx/lifecycle/lint/NonNullableMutableLiveDataDetector.kt) +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/lifecycle/lifecycle-livedata-core-lint/src/main/java/androidx/lifecycle/lint/NonNullableMutableLiveDataDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/lifecycle/lifecycle-livedata-core-lint/src/test/java/androidx/lifecycle/livedata/core/lint/NonNullableMutableLiveDataDetectorTest.kt) Copyright Year : 2019 -This check ensures that LiveData values are not null when explicitly +This check ensures that LiveData values are not null when explicitly declared as non-nullable. Kotlin interoperability does not support enforcing explicit null-safety when using generic Java type -parameters. Since LiveData is a Java class its value can always +parameters. Since LiveData is a Java class its value can always be null even when its type is explicitly declared as non-nullable. This can lead to runtime exceptions from -reading a null LiveData value that is assumed to be +reading a null LiveData value that is assumed to be non-nullable. +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Repackaged + +This lint check appears to have been packaged in other artifacts as +well. Issue id's must be unique, so you cannot combine these libraries. +Also defined in: +* NullSafeMutableLiveData: LiveData value assignment nullability mismatch (this issue) +* [NullSafeMutableLiveData from androidx.lifecycle:lifecycle-livedata-core:2.9.0-rc01](NullSafeMutableLiveData.md.html) +* [NullSafeMutableLiveData from androidx.lifecycle:lifecycle-livedata-core-ktx:2.8.0-alpha01](NullSafeMutableLiveData-2.md.html) + + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.lifecycle:lifecycle-livedata-core:2.9.0-rc01") + +// build.gradle +implementation 'androidx.lifecycle:lifecycle-livedata-core:2.9.0-rc01' + +// build.gradle.kts with version catalogs: +implementation(libs.lifecycle.livedata.core) + +# libs.versions.toml +[versions] +lifecycle-livedata-core = "2.9.0-rc01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lifecycle-livedata-core = { + module = "androidx.lifecycle:lifecycle-livedata-core", + version.ref = "lifecycle-livedata-core" +} +``` + +2.9.0-rc01 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.lifecycle:lifecycle-livedata-core](androidx_lifecycle_lifecycle-livedata-core.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/NullableConcurrentHashMap.md.html b/docs/checks/NullableConcurrentHashMap.md.html new file mode 100644 index 00000000..75aef5f9 --- /dev/null +++ b/docs/checks/NullableConcurrentHashMap.md.html @@ -0,0 +1,180 @@ + +(#) ConcurrentHashMap should not use nullable types + +!!! ERROR: ConcurrentHashMap should not use nullable types + This is an error. + +Id +: `NullableConcurrentHashMap` +Summary +: ConcurrentHashMap should not use nullable types +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.9.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/NullableConcurrentHashMapDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/NullableConcurrentHashMapDetectorTest.kt) +Copyright Year +: 2025 + +ConcurrentHashMap does not support null keys or values. Use non-nullable +types for both keys and values when creating a ConcurrentHashMap. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test.kt:3:Error: ConcurrentHashMap should not use nullable key types +[NullableConcurrentHashMap] + val map = java.util.concurrent.ConcurrentHashMap<String?, Int>() + ------- +src/test.kt:4:Error: ConcurrentHashMap should not use nullable key types +[NullableConcurrentHashMap] + val map2: java.util.concurrent.ConcurrentHashMap<String?, Int> = java.util.concurrent.ConcurrentHashMap() + ------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +fun test() { + val map = java.util.concurrent.ConcurrentHashMap() + val map2: java.util.concurrent.ConcurrentHashMap = java.util.concurrent.ConcurrentHashMap() +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/NullableConcurrentHashMapDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `NullableConcurrentHashMapDetector.concurrentHashMapWithNullableKeyType`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("NullableConcurrentHashMap") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("NullableConcurrentHashMap") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection NullableConcurrentHashMap + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="NullableConcurrentHashMap" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'NullableConcurrentHashMap' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore NullableConcurrentHashMap ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ObjectAnimatorBinding.md.html b/docs/checks/ObjectAnimatorBinding.md.html index 9ad1f460..bd67a23c 100644 --- a/docs/checks/ObjectAnimatorBinding.md.html +++ b/docs/checks/ObjectAnimatorBinding.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 2.3.0 (March 2017) Affects : Kotlin and Java files and resource files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ObjectAnimatorDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ObjectAnimatorDetectorTest.kt) -Copyright Year -: 2016 This check cross references properties referenced by String from `ObjectAnimator` and `PropertyValuesHolder` method calls and ensures @@ -38,131 +38,38 @@ Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -src/main/java/test/pkg/AnimatorTest.java:21:Error: The setter for this +src/main/java/AnimationExample.java:9:Error: The setter for this property does not match the expected signature (public void setProp2(int arg) [ObjectAnimatorBinding] - - ObjectAnimator.ofInt(myObject, "prop2", 0, 1, 2, 5).start(); - ------- - - -src/main/java/test/pkg/AnimatorTest.java:24:Error: Could not find -property setter method setUnknown on test.pkg.AnimatorTest.MyObject -[ObjectAnimatorBinding] - - ObjectAnimator.ofInt(myObject, "unknown", 0, 1, 2, 5).start(); - --------- - - -src/main/java/test/pkg/AnimatorTest.java:27:Error: The setter for this -property (test.pkg.AnimatorTest.MyObject.setProp3) should not be static -[ObjectAnimatorBinding] - - ObjectAnimator.ofInt(myObject, "prop3", 0, 1, 2, 5).start(); - ------- - - -src/main/java/test/pkg/AnimatorTest.java:40:Error: Could not find -property setter method setAlpha2 on android.widget.Button -[ObjectAnimatorBinding] - - ObjectAnimator.ofArgb(button, "alpha2", 1, 5); // Missing - -------- - - + ObjectAnimator animator2 = ObjectAnimator.ofInt(myObject, "prop2", 0, 1, 2, 5); + ------- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: -`src/main/java/test/pkg/AnimatorTest.java`: +`src/main/java/AnimationExample.java`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers -package test.pkg; - - import android.animation.ObjectAnimator; -import android.animation.PropertyValuesHolder; -import androidx.annotation.Keep; -import android.view.View; -import android.widget.Button; -import android.animation.FloatEvaluator; -@SuppressWarnings("unused") -public class AnimatorTest { - public void testObjectAnimator(Button button) { +public class AnimationExample { + public void startAnimations() { Object myObject = new MyObject(); ObjectAnimator animator1 = ObjectAnimator.ofInt(myObject, "prop1", 0, 1, 2, 5); - animator1.setDuration(10); animator1.start(); - - // Incorrect type (float parameter) warning - ObjectAnimator.ofInt(myObject, "prop2", 0, 1, 2, 5).start(); - - // Missing method warning - ObjectAnimator.ofInt(myObject, "unknown", 0, 1, 2, 5).start(); - - // Static method warning - ObjectAnimator.ofInt(myObject, "prop3", 0, 1, 2, 5).start(); - - // OK: Already marked @Keep - ObjectAnimator.ofInt(myObject, "prop4", 0, 1, 2, 5).start(); - - // OK: multi int - ObjectAnimator.ofMultiInt(myObject, "prop4", new int[0][]).start(); - - // OK: multi int - ObjectAnimator.ofMultiFloat(myObject, "prop5", new float[0][]).start(); - - // View stuff - ObjectAnimator.ofFloat(button, "alpha", 1, 5); // TODO: Warn about better method?, e.g. button.animate().alpha(...) - ObjectAnimator.ofArgb(button, "alpha2", 1, 5); // Missing - } - - public void testPropertyHolder() { - Object myObject = new MyObject(); - - PropertyValuesHolder p1 = PropertyValuesHolder.ofInt("prop1", 50); - PropertyValuesHolder p2 = PropertyValuesHolder.ofFloat("prop2", 100f); - ObjectAnimator.ofPropertyValuesHolder(myObject, p1, p2).start(); - ObjectAnimator.ofPropertyValuesHolder(myObject, - PropertyValuesHolder.ofInt("prop1", 50), - PropertyValuesHolder.ofFloat("prop2", 100f)).start(); + ObjectAnimator animator2 = ObjectAnimator.ofInt(myObject, "prop2", 0, 1, 2, 5); + animator2.start(); } private static class MyObject { public void setProp1(int x) { + // Implementation here } private void setProp2(float x) { - } - - public static void setProp3(int x) { - } - - @Keep - public void setProp4(int[] x) { - } - - @Keep - public void setProp5(float[] x) { - } - - @Keep - public void setProp4(int x) { - } - - @Keep - public void setProp5(float x) { + // Implementation here } } - - public void testEvaluators() { - Object myObject = new MyObject(); - PropertyValuesHolder p1 = PropertyValuesHolder.ofObject("prop5", new FloatEvaluator()); - ObjectAnimator.ofPropertyValuesHolder(myObject, p1); - ObjectAnimator.ofObject(myObject, "prop5", new FloatEvaluator(), 1f, 2f); - } - } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -170,11 +77,6 @@ [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ObjectAnimatorDetectorTest.kt) for the unit tests for this check to see additional scenarios. -The above example was automatically extracted from the first unit test -found for this lint check, `ObjectAnimatorDetector.testBasic`. -To report a problem with this extracted sample, visit -https://issuetracker.google.com/issues/new?component=192708. - (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/ObsoleteLayoutParam.md.html b/docs/checks/ObsoleteLayoutParam.md.html index 806dbb4b..7e3e37ce 100644 --- a/docs/checks/ObsoleteLayoutParam.md.html +++ b/docs/checks/ObsoleteLayoutParam.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -44,53 +46,32 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/wrongparams.xml:11:Warning: Invalid layout param in a FrameLayout: layout_weight [ObsoleteLayoutParam] - android:layout_weight="1" ------------------------- - - res/layout/wrongparams.xml:23:Warning: Invalid layout param in a LinearLayout: layout_alignParentLeft [ObsoleteLayoutParam] - android:layout_alignParentLeft="true" ------------------------------------- - - res/layout/wrongparams.xml:24:Warning: Invalid layout param in a LinearLayout: layout_alignParentTop [ObsoleteLayoutParam] - android:layout_alignParentTop="true" ------------------------------------ - - res/layout/wrongparams.xml:33:Warning: Invalid layout param in a LinearLayout: layout_alignBottom [ObsoleteLayoutParam] - android:layout_alignBottom="@+id/button1" ----------------------------------------- - - res/layout/wrongparams.xml:34:Warning: Invalid layout param in a LinearLayout: layout_toRightOf [ObsoleteLayoutParam] - android:layout_toRightOf="@+id/button1" --------------------------------------- - - res/layout/wrongparams.xml:42:Warning: Invalid layout param in a LinearLayout: layout_alignLeft [ObsoleteLayoutParam] - android:layout_alignLeft="@+id/button1" --------------------------------------- - - res/layout/wrongparams.xml:43:Warning: Invalid layout param in a LinearLayout: layout_below [ObsoleteLayoutParam] - android:layout_below="@+id/button1" ----------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/ObsoleteSdkInt.md.html b/docs/checks/ObsoleteSdkInt.md.html index 694c4b84..48e8e9a2 100644 --- a/docs/checks/ObsoleteSdkInt.md.html +++ b/docs/checks/ObsoleteSdkInt.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 2.3.0 (March 2017) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ApiDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ApiDetectorTest.java) -Copyright Year -: 2012 This check flags version checks that are not necessary, because the `minSdkVersion` (or surrounding known API level) is already at least as @@ -47,18 +47,12 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/ObsoleteSdkInt.kt:4:Warning: Unnecessary; SDK_INT is always >= 23 [ObsoleteSdkInt] - if (Build.VERSION.SDK_INT >= 21) { // UNNECESSARY, always true --------------------------- - - src/ObsoleteSdkInt.kt:7:Warning: Unnecessary; SDK_INT is never < 23 [ObsoleteSdkInt] - if (Build.VERSION.SDK_INT < 21) { // UNNECESSARY, never true -------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here are the relevant source files: diff --git a/docs/checks/OldTargetApi.md.html b/docs/checks/OldTargetApi.md.html index 05e7ab7d..6b0615f9 100644 --- a/docs/checks/OldTargetApi.md.html +++ b/docs/checks/OldTargetApi.md.html @@ -18,8 +18,10 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.2.0 (November 2023) Affects -: Manifest files +: Gradle build files, TOML files and manifest files Editing : This check runs on the fly in the IDE editor See @@ -27,25 +29,23 @@ See : https://developer.android.com/reference/android/os/Build.VERSION_CODES.html Implementation -: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ManifestDetector.kt) +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GradleDetector.kt) Tests -: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ManifestDetectorTest.kt) -Copyright Year -: 2011 +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) -When your application runs on a version of Android that is more recent -than your `targetSdkVersion` specifies that it has been tested with, -various compatibility modes kick in. This ensures that your application -continues to work, but it may look out of place. For example, if the -`targetSdkVersion` is less than 14, your app may get an option button in -the UI. +When your application or sdk runs on a version of Android that is more +recent than your `targetSdkVersion` specifies that it has been tested +with, various compatibility modes kick in. This ensures that your +application continues to work, but it may look out of place. For +example, if the `targetSdkVersion` is less than 14, your app may get an +option button in the UI. To fix this issue, set the `targetSdkVersion` to the highest available value. Then test your app to make sure everything works correctly. You may want to consult the compatibility notes to see what changes apply to each version you are adding support for: https://developer.android.com/reference/android/os/Build.VERSION_CODES.html - as well as follow this guide: +as well as follow this guide: https://developer.android.com/distribute/best-practices/develop/target-sdk.html. !!! Tip @@ -55,51 +55,62 @@ Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -AndroidManifest.xml:6:Warning: Not targeting the latest versions of +build.gradle.kts:6:Warning: Not targeting the latest versions of Android; compatibility modes apply. Consider testing and updating this version. Consult the android.os.Build.VERSION_CODES javadoc for details. [OldTargetApi] + targetSdk = libs.versions.keys.tsv.get().toInt() // ERROR 15 + ------------------------------------------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="14" /> - ----------------------------- - - +Here are the relevant source files: + +`build.gradle.kts`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +android { + compileSdk = libs.versions.compile.sdk.version.get().toInt() // ERROR 12 + compileSdk = libs.versions.keys.csv.get().toInt() // ERROR 13 + defaultConfig { + minSdk = libs.versions.keys.msv.get().toInt() // ERROR 14 + targetSdk = libs.versions.keys.tsv.get().toInt() // ERROR 15 + } +} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +`../gradle/libs.versions.toml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~toml linenumbers +[versions] +compile_sdk_version = "34" # ERROR 1 +min_sdk_version = "15" # ERROR 2 +target_sdk_version = "34" # ERROR 3 -`AndroidManifest.xml`: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers -<manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="test.bytecode" - android:versionCode="1" - android:versionName="1.0" > +compileSdkVersion = "34" # ERROR 4 +minSdkVersion = "15" # ERROR 5 +targetSdkVersion = "34" # ERROR 6 - <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="14" /> +compileSdk = "34" # ERROR 7 +minSdk = "15" # ERROR 8 +targetSdk = "34" # ERROR 9 - <application - android:icon="@drawable/ic_launcher" - android:label="@string/app_name" > - <activity - android:name=".BytecodeTestsActivity" - android:label="@string/app_name" > - <intent-filter> - <action android:name="android.intent.action.MAIN" /> +# https://github.com/Kotlin/multiplatform-library-template/blob/main/gradle/libs.versions.toml +android-minSdk = "15" # ERROR 10 +android-compileSdk = "34" # ERROR 11 - <category android:name="android.intent.category.LAUNCHER" /> - </intent-filter> - </activity> - </application> +# Unusual keys, referenced via KTS +keys-csv = "34" # ERROR 12 +keys-msv = "15" # ERROR 13 +keys-tsv = "34" # ERROR 14 -</manifest> +javaCompileSdk = "17" # OK 1 +other-compileSdk = "15" # OK 2 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can also visit the -[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ManifestDetectorTest.kt) +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) for the unit tests for this check to see additional scenarios. The above example was automatically extracted from the first unit test -found for this lint check, `ManifestDetector.testOldTargetSdk`. +found for this lint check, `GradleDetector.testCompileSdkViaVersionCatalog`. To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=192708. @@ -107,21 +118,19 @@ You can suppress false positives using one of the following mechanisms: +* Using a suppression comment like this on the line above: + + ```kt + //noinspection OldTargetApi + problematicStatement() + ``` + * Adding the suppression attribute `tools:ignore="OldTargetApi"` on the problematic XML element (or one of its enclosing elements). You may also need to add the following namespace declaration on the root element in the XML file if it's not already there: `xmlns:tools="http://schemas.android.com/tools"`. - ```xml - <?xml version="1.0" encoding="UTF-8"?> - <manifest xmlns:tools="http://schemas.android.com/tools"> - ... - <application tools:ignore="OldTargetApi" .../> - ... - </manifest> - ``` - * Using a special `lint.xml` file in the source tree which turns off the check in that folder and any sub folder. A simple file might look like this: diff --git a/docs/checks/OnClick.md.html b/docs/checks/OnClick.md.html index e1fc089e..0ca1b62f 100644 --- a/docs/checks/OnClick.md.html +++ b/docs/checks/OnClick.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files and resource files Editing @@ -43,71 +45,44 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/onclick.xml:10:Error: Corresponding method handler 'public void nonexistent(android.view.View)' not found [OnClick] - android:onClick="nonexistent" ----------------------------- - - res/layout/onclick.xml:16:Error: Corresponding method handler 'public void wrong1(android.view.View)' not found [OnClick] - android:onClick="wrong1" ------------------------ - - res/layout/onclick.xml:22:Error: Corresponding method handler 'public void wrong2(android.view.View)' not found [OnClick] - android:onClick="wrong2" ------------------------ - - res/layout/onclick.xml:28:Error: Corresponding method handler 'public void wrong3(android.view.View)' not found [OnClick] - android:onClick="wrong3" ------------------------ - - res/layout/onclick.xml:58:Error: Corresponding method handler 'public void simple_typo(android.view.View)' not found (did you mean OnClickActivity#simple_tyop ?) [OnClick] - android:onClick="simple_typo" ----------------------------- - - res/layout/onclick.xml:82:Error: onClick handler method name cannot start with the character '1' [OnClick] - android:onClick="1invalidname" ------------ - - res/layout/onclick.xml:88:Error: There should be no spaces in the onClick handler name [OnClick] - android:onClick="invalid name" ------------ - - res/layout/onclick.xml:94:Error: onClick handler method name cannot contain the character '(' [OnClick] - android:onClick="invalidname()" ------------- - - res/layout/onclick.xml:100:Error: onClick handler method name cannot be a Java keyword [OnClick] - android:onClick="new" --- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `res/layout/onclick.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -216,6 +191,58 @@ </LinearLayout> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/test/pkg/OnClickActivity.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; + +import android.app.Activity; +import android.util.Log; +import android.view.View; + +/** Test data for the OnClickDetector */ +public class OnClickActivity extends Activity { + // Wrong argument type 1 + public void wrong1() { + } + + // Wrong argument type 2 + public void wrong2(int i) { + } + + // Wrong argument type 3 + public void wrong3(View view, int i) { + } + + // Return type is allowed to not be void + public int ok2(View view) { + return 0; + } + + // Wrong modifier (not public) + void wrong5(View view) { + } + + // Wrong modifier (is static) + public static void wrong6(View view) { + } + + public void ok(View view) { + } + + // Ok: Unicode escapes + public void myሴmethod(View view) { + } + + // Typo + public void simple_tyop(View view) { + } + + void wrong7(View view) { + Log.i("x", "wrong7: called"); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/OnClickDetectorTest.java) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/OpaqueUnitKey.md.html b/docs/checks/OpaqueUnitKey.md.html new file mode 100644 index 00000000..80d04f78 --- /dev/null +++ b/docs/checks/OpaqueUnitKey.md.html @@ -0,0 +1,197 @@ + +(#) Passing an expression which always returns `Unit` as a key argument + +!!! WARNING: Passing an expression which always returns `Unit` as a key argument + This is a warning. + +Id +: `OpaqueUnitKey` +Summary +: Passing an expression which always returns `Unit` as a key argument +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: Jetpack Compose +Identifier +: androidx.compose.runtime +Feedback +: https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.runtime:runtime-android](androidx_compose_runtime_runtime-android.md.html) +Since +: 1.5.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/runtime/runtime-lint/src/main/java/androidx/compose/runtime/lint/OpaqueUnitKeyDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/runtime/runtime-lint/src/test/java/androidx/compose/runtime/lint/OpaqueUnitKeyDetectorTest.kt) +Copyright Year +: 2023 + +Certain Compose functions including `remember`, `LaunchedEffect`, and +`DisposableEffect` declare (and sometimes require) one or more key +parameters. When a key parameter changes, it is a signal that the +previous invocation is now invalid. In certain cases, it may be required +to pass `Unit` as a key to one of these functions, indicating that the +invocation never becomes invalid. Using `Unit` as a key should be done +infrequently, and should always be done explicitly by passing the `Unit` +literal. This inspection checks for invocations where `Unit` is being +passed as a key argument in any form other than the `Unit` literal. This +is usually done by mistake, and can harm readability. If a Unit +expression is being passed as a key, it is always equivalent to move the +expression before the function invocation and pass the `Unit` literal +instead. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test/test.kt:10:Warning: Implicitly passing Unit as argument to key1 +[OpaqueUnitKey] + val x = remember(unitProperty) { listOf(1, 2, 3) } + ------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test + +import androidx.compose.runtime.* + +val unitProperty = Unit + +@Composable +fun Test() { + val x = remember(unitProperty) { listOf(1, 2, 3) } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/runtime/runtime-lint/src/test/java/androidx/compose/runtime/lint/OpaqueUnitKeyDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `OpaqueUnitKeyDetector.remember_withUnitPropertyRead_reportsError`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=612128. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.runtime:runtime-android:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.runtime:runtime-android:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.runtime.android) + +# libs.versions.toml +[versions] +runtime-android = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +runtime-android = { + module = "androidx.compose.runtime:runtime-android", + version.ref = "runtime-android" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.runtime:runtime-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.runtime:runtime-android](androidx_compose_runtime_runtime-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("OpaqueUnitKey") + fun method() { + remember(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("OpaqueUnitKey") + void method() { + remember(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection OpaqueUnitKey + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="OpaqueUnitKey" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'OpaqueUnitKey' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore OpaqueUnitKey ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/OpenForTesting.md.html b/docs/checks/OpenForTesting.md.html index 1f0825ed..c75c48fa 100644 --- a/docs/checks/OpenForTesting.md.html +++ b/docs/checks/OpenForTesting.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.3.0 (September 2022) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/OpenForTestingDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/OpenForTestingDetectorTest.kt) -Copyright Year -: 2022 Classes or methods annotated with `@OpenForTesting` are only allowed to be subclassed or overridden from unit tests. @@ -38,25 +38,16 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/Builder1.kt:10:Error: Builder1 should only be subclassed from tests [OpenForTesting] - class MyBuilder1 : Builder1() { // ERROR 1 -------- - - src/test/pkg/Builder1.kt:22:Error: Builder2.someMethod should only be overridden from tests [OpenForTesting] - override fun someMethod(arg: Int) { } // ERROR 2 ---------- - - src/test/pkg/MyBuilder3.java:2:Error: Builder1 should only be subclassed from tests [OpenForTesting] - class MyBuilder3 extends Builder1 { // ERROR 3 -------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here are the relevant source files: diff --git a/docs/checks/Orientation.md.html b/docs/checks/Orientation.md.html index 51a1220a..b96749ce 100644 --- a/docs/checks/Orientation.md.html +++ b/docs/checks/Orientation.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -39,7 +41,7 @@ It also checks for empty LinearLayouts without an `orientation` attribute that also defines an `id` attribute. This catches the scenarios where children will be added to the `LinearLayout` -dynamically. +dynamically. !!! Tip This lint check has an associated quickfix available in the IDE. @@ -52,11 +54,8 @@ orientation specified, and the default is horizontal, yet this layout has multiple children where at least one has layout_width="match_parent" [Orientation] - <LinearLayout ------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/OutdatedLibrary.md.html b/docs/checks/OutdatedLibrary.md.html index ce46a31a..ae70c374 100644 --- a/docs/checks/OutdatedLibrary.md.html +++ b/docs/checks/OutdatedLibrary.md.html @@ -18,18 +18,18 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.2.0 (September 2018) Affects -: Gradle build files +: Gradle build files and TOML files Editing : This check runs on the fly in the IDE editor See -: https://play.google.com/sdks +: https://developer.android.com/distribute/sdk-index Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GradleDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) -Copyright Year -: 2014 Your app is using an outdated version of a library. This may cause violations of Google Play policies (see @@ -46,28 +46,37 @@ Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -build.gradle:5:Warning: log4j:log4j version 1.2.15 has been marked as +build.gradle:5:Warning: log4j:log4j version 1.2.15 has been reported as outdated by its author [OutdatedLibrary] - compile 'log4j:log4j:1.2.15' // Outdated NON_BLOCKING -------------------- - - -build.gradle:8:Error: log4j:log4j version 1.2.12 has been marked as -outdated by its author and will block publishing of your app to Play -Console [OutdatedLibrary] - +build.gradle:8:Error: [Prevents app release in Google Play Console] +log4j:log4j version 1.2.12 has been reported as outdated by its author +and will block publishing of your app to Play Console. +The library author recommends using versions: + - 1.2.17 + - 1.2.18 or higher +These versions have not been reviewed by Google Play. They could contain +vulnerabilities or policy violations. Carefully evaluate any third-party +SDKs before integrating them into your app. [OutdatedLibrary] compile 'log4j:log4j:1.2.12' // OUTDATED BLOCKING -------------------- - - build.gradle:13:Warning: com.example.ads.third.party:example version -7.2.0 has been marked as outdated by its author [OutdatedLibrary] - - compile 'com.example.ads.third.party:example:7.2.0' // Outdated & Non compliant & Critical +7.2.0 has been reported as outdated by its author [OutdatedLibrary] + compile 'com.example.ads.third.party:example:7.2.0' // Outdated + Critical + Policy (multiple issues), no severity ------------------------------------------- - - +build.gradle:27:Warning: com.example.issues:issues-on-latest version +1.8.0 has been reported as outdated by its author. +The library author recommends using versions: + - 1.9.0 or higher [OutdatedLibrary] + compile 'com.example.issues:issues-on-latest:1.8.0' // Outdated blocking + ------------------------------------------- +build.gradle:28:Warning: com.example.issues:latest-is-preview version +1.0.0 has been reported as outdated by its author. +The library author recommends using versions: + - 1.1.0 or higher [OutdatedLibrary] + compile 'com.example.issues:latest-is-preview:1.0.0' // Outdated non-blocking + -------------------------------------------- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -86,7 +95,23 @@ compile 'com.example.ads.third.party:example:8.0.0' // OK compile 'com.example.ads.third.party:example:7.2.2' // OK compile 'com.example.ads.third.party:example:7.2.1' // OK - compile 'com.example.ads.third.party:example:7.2.0' // Outdated & Non compliant & Critical + compile 'com.example.ads.third.party:example:7.2.0' // Outdated + Critical + Policy (multiple issues), no severity + compile 'com.example.ads.third.party:example:7.1.0' // Policy (Ads), non-blocking + compile 'com.example.ads.third.party:example:7.1.1' // Policy (Device and Network Abuse), blocking + compile 'com.example.ads.third.party:example:7.1.2' // Policy (Deceptive Behavior), no severity + compile 'com.example.ads.third.party:example:7.1.3' // Policy (User Data), non-blocking + compile 'com.example.ads.third.party:example:7.1.4' // Policy (Permissions), blocking + compile 'com.example.ads.third.party:example:7.1.5' // Policy (Mobile Unwanted Software), no-severity + compile 'com.example.ads.third.party:example:7.1.6' // Policy (Malware), non-blocking + compile 'com.example.ads.third.party:example:7.1.7' // Policy (multiple types), non-blocking + compile 'com.example.ads.third.party:example:7.1.8' // Policy (multiple types), blocking + compile 'com.example.ads.third.party:example:7.1.9' // Policy (multiple types), no severity + compile 'com.example.ads.third.party:example:7.1.10' // Vulnerability (UNSAFE_HOSTNAME_VERIFIER, non-blocking) + compile 'com.example.ads.third.party:example:7.1.11' // Vulnerability multiple (UNSAFE_SSL_ERROR_HANDLER, ZIP_PATH_TRAVERSAL, UNSAFE_WEBVIEW_OAUTH, blocking) + compile 'com.example.ads.third.party:example:7.1.12' // Vulnerability multiple (non-blocking) + compile 'com.example.issues:issues-on-latest:1.8.0' // Outdated blocking + compile 'com.example.issues:latest-is-preview:1.0.0' // Outdated non-blocking + compile 'com.example.issues:deprecated:2.0.0' // Deprecated compile 'log4j:log4j:latest.release' // OK compile 'log4j:log4j' // OK diff --git a/docs/checks/Overdraw.md.html b/docs/checks/Overdraw.md.html index d0de354f..1796d645 100644 --- a/docs/checks/Overdraw.md.html +++ b/docs/checks/Overdraw.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files, manifest files and resource files Editing @@ -57,14 +59,71 @@ res/layout/sixth.xml:4:Warning: Possible overdraw: Root element paints background @drawable/custombg with a theme that also paints a background (inferred theme is @style/MyTheme) [Overdraw] - android:background="@drawable/custombg" --------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Here are the relevant source files: +`AndroidManifest.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="test.pkg" + android:versionCode="1" + android:versionName="1.0" > + + <uses-sdk android:minSdkVersion="10" /> + + <application + android:icon="@drawable/ic_launcher" + android:label="@string/app_name" + android:theme="@style/MyTheme" > + <activity + android:name=".OverdrawActivity" + android:label="@string/app_name" + android:theme="@style/MyTheme.First" > + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + <activity + android:name=".SecondActivity" + android:label="@string/app_name" > + </activity> + <activity + android:name=".ThirdActivity" + android:label="@string/app_name" > + </activity> + <activity + android:name="test.pkg.FourthActivity" + android:label="@string/app_name" + android:theme="@style/MyTheme.Fourth" > + </activity> + </application> + +</manifest> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/drawable/custombg.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<bitmap + xmlns:android="http://schemas.android.com/apk/res/android" + android:src="@drawable/ic_launcher" + android:tileMode="clamp" /> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +`res/drawable/custombg2.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:drawable="@drawable/ic_launcher" /> +</selector> + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `res/layout/sixth.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -83,6 +142,200 @@ </LinearLayout> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/layout/fifth.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:background="@drawable/custombg2" + android:orientation="vertical" > + + <TextView + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:text="@string/hello" /> + +</LinearLayout> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/layout/fourth.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:background="@drawable/ic_launcher" + android:orientation="vertical" > + + <TextView + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:text="@string/hello" /> + +</LinearLayout> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/layout/main.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:background="@drawable/ic_launcher" + android:orientation="vertical" > + + <TextView + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:text="@string/hello" /> + +</LinearLayout> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/layout/second.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:background="@drawable/ic_launcher" + android:orientation="vertical" > + + <TextView + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:text="@string/hello" /> + +</LinearLayout> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/layout/third.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:background="@drawable/ic_launcher" + android:orientation="vertical" > + + <TextView + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:text="@string/hello" /> + +</LinearLayout> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/values/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<resources> + + <string name="hello">Hello World, OverdrawActivity!</string> + <string name="app_name">Overdraw</string> + +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`res/values/styles.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<resources> + + <style name="MyTheme" parent="@android:style/Theme.Light"> + <item name="android:windowBackground">@drawable/ic_launcher</item> + </style> + + <style name="MyTheme.First"> + <item name="android:textColor">#ff00ff00</item> + </style> + + <style name="MyTheme.Second"> + <item name="android:windowIsTranslucent">true</item> + </style> + + <style name="MyTheme.Third"> + <item name="android:textColor">#ff000000</item> + </style> + + <style name="MyTheme.Fourth"> + <item name="android:windowBackground">@null</item> + <item name="android:textColor">#ff000000</item> + </style> + +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/FourthActivity.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; + +import android.app.Activity; +import android.os.Bundle; + +public class FourthActivity extends Activity { + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.fourth); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/OverdrawActivity.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; + +import android.app.Activity; +import android.os.Bundle; + +public class OverdrawActivity extends Activity { + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.main); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/SecondActivity.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; + +import android.app.Activity; +import android.os.Bundle; + +public class SecondActivity extends Activity { + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.second); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/ThirdActivity.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; + +import android.app.Activity; +import android.os.Bundle; + +public class ThirdActivity extends Activity { + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setTheme(R.style.MyTheme_Third); + setContentView(R.layout.third); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/OverdrawDetectorTest.java) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/Override.md.html b/docs/checks/Override.md.html index a1c7895b..55e3dc09 100644 --- a/docs/checks/Override.md.html +++ b/docs/checks/Override.md.html @@ -1,214 +1,8 @@ -(#) Method conflicts with new inherited method +(#) Override -!!! ERROR: Method conflicts with new inherited method - This is an error. - -Id -: `Override` -Summary -: Method conflicts with new inherited method -Severity -: Error -Category -: Correctness -Platform -: Android -Vendor -: Android Open Source Project -Feedback -: https://issuetracker.google.com/issues/new?component=192708 -Affects -: Kotlin and Java files -Editing -: This check runs on the fly in the IDE editor -Implementation -: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ApiDetector.kt) -Tests -: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ApiDetectorTest.java) -Copyright Year -: 2012 - -Suppose you are building against Android API 8, and you've subclassed -Activity. In your subclass you add a new method called `isDestroyed`(). -At some later point, a method of the same name and signature is added to -Android. Your method will now override the Android method, and possibly -break its contract. Your method is not calling `super.isDestroyed()`, -since your compilation target doesn't know about the method. - -The above scenario is what this lint detector looks for. The above -example is real, since `isDestroyed()` was added in API 17, but it will -be true for **any** method you have added to a subclass of an Android -class where your build target is lower than the version the method was -introduced in. - -To fix this, either rename your method, or if you are really trying to -augment the builtin method if available, switch to a higher build target -where you can deliberately add `@Override` on your overriding method, -and call `super` if appropriate etc. - -!!! Tip - This lint check has an associated quickfix available in the IDE. - -(##) Example - -Here is an example of lint warnings produced by this check: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -src/test/pkg/ApiCallTest11.java:13:Error: This method is not overriding -anything with the current build target, but will in API level 11 -(current target is 3): test.pkg.ApiCallTest11#getActionBar [Override] - - public ActionBar getActionBar() { - ------------ - - -src/test/pkg/ApiCallTest11.java:17:Error: This method is not overriding -anything with the current build target, but will in API level 17 -(current target is 3): test.pkg.ApiCallTest11#isDestroyed [Override] - - public boolean isDestroyed() { - ----------- - - -src/test/pkg/ApiCallTest11.java:39:Error: This method is not overriding -anything with the current build target, but will in API level 11 -(current target is 3): -test.pkg.ApiCallTest11.MyLinear#setDividerDrawable [Override] - - public void setDividerDrawable(Drawable dividerDrawable) { - ------------------ - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Here is the source file referenced above: - -`src/test/pkg/ApiCallTest11.java`: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers -package test.pkg; - -import android.annotation.SuppressLint; -import android.app.ActionBar; -import android.app.Activity; -import android.content.Context; -import android.graphics.drawable.Drawable; -import android.widget.LinearLayout; - -public class ApiCallTest11 extends Activity { - MyActivity mActionBarHost; - - public ActionBar getActionBar() { - return mActionBarHost.getActionBar(); - } - - public boolean isDestroyed() { - return true; - } - - @SuppressLint("Override") - public void finishAffinity() { - } - - private class MyLinear extends LinearLayout { - private Drawable mDividerDrawable; - - public MyLinear(Context context) { - super(context); - } - - /** - * Javadoc here - * - * - * - * - */ - public void setDividerDrawable(Drawable dividerDrawable) { - mDividerDrawable = dividerDrawable; - } - } - - private class MyActivity { - public ActionBar getActionBar() { - return null; - } - } -} - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -You can also visit the -[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ApiDetectorTest.java) -for the unit tests for this check to see additional scenarios. - -The above example was automatically extracted from the first unit test -found for this lint check, `ApiDetector.testOverride`. -To report a problem with this extracted sample, visit -https://issuetracker.google.com/issues/new?component=192708. - -(##) Suppressing - -You can suppress false positives using one of the following mechanisms: - -* Using a suppression annotation like this on the enclosing - element: - - ```kt - // Kotlin - @Suppress("Override") - fun method() { - problematicStatement() - } - ``` - - or - - ```java - // Java - @SuppressWarnings("Override") - void method() { - problematicStatement(); - } - ``` - -* Using a suppression comment like this on the line above: - - ```kt - //noinspection Override - problematicStatement() - ``` - -* Using a special `lint.xml` file in the source tree which turns off - the check in that folder and any sub folder. A simple file might look - like this: - ```xml - <?xml version="1.0" encoding="UTF-8"?> - <lint> - <issue id="Override" severity="ignore" /> - </lint> - ``` - Instead of `ignore` you can also change the severity here, for - example from `error` to `warning`. You can find additional - documentation on how to filter issues by path, regular expression and - so on - [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). - -* In Gradle projects, using the DSL syntax to configure lint. For - example, you can use something like - ```gradle - lintOptions { - disable 'Override' - } - ``` - In Android projects this should be nested inside an `android { }` - block. - -* For manual invocations of `lint`, using the `--ignore` flag: - ``` - $ lint --ignore Override ...` - ``` - -* Last, but not least, using baselines, as discussed - [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). +The issue for this id has been deleted or marked obsolete and can now be +ignored. +(Additional metadata not available.) \ No newline at end of file diff --git a/docs/checks/OverrideAbstract.md.html b/docs/checks/OverrideAbstract.md.html index ee2f3498..1426cdcc 100644 --- a/docs/checks/OverrideAbstract.md.html +++ b/docs/checks/OverrideAbstract.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 0.2.0 (October 2014) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/OverrideConcreteDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/OverrideConcreteDetectorTest.java) -Copyright Year -: 2014 To improve the usability of some APIs, some methods that used to be `abstract` have been made concrete by adding default implementations. @@ -45,40 +45,28 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/OverrideConcreteTest.java:23:Error: Must override android.service.notification.NotificationListenerService.onNotificationPosted(android.service.notification.StatusBarNotification): - Method was abstract until 21, and your minSdkVersion is 18 +Method was abstract until 21, and your minSdkVersion is 18 [OverrideAbstract] - private static class MyNotificationListenerService2 extends NotificationListenerService { ------------------------------ - - src/test/pkg/OverrideConcreteTest.java:30:Error: Must override android.service.notification.NotificationListenerService.onNotificationRemoved(android.service.notification.StatusBarNotification): - Method was abstract until 21, and your minSdkVersion is 18 +Method was abstract until 21, and your minSdkVersion is 18 [OverrideAbstract] - private static class MyNotificationListenerService3 extends NotificationListenerService { ------------------------------ - - src/test/pkg/OverrideConcreteTest.java:37:Error: Must override android.service.notification.NotificationListenerService.onNotificationPosted(android.service.notification.StatusBarNotification): - Method was abstract until 21, and your minSdkVersion is 18 +Method was abstract until 21, and your minSdkVersion is 18 [OverrideAbstract] - private static class MyNotificationListenerService4 extends NotificationListenerService { ------------------------------ - - src/test/pkg/OverrideConcreteTest.java:57:Error: Must override android.service.notification.NotificationListenerService.onNotificationRemoved(android.service.notification.StatusBarNotification): - Method was abstract until 21, and your minSdkVersion is 18 +Method was abstract until 21, and your minSdkVersion is 18 [OverrideAbstract] - private static class MyNotificationListenerService7 extends MyNotificationListenerService3 { ------------------------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/PackageManagerGetSignatures.md.html b/docs/checks/PackageManagerGetSignatures.md.html index 16a21e72..2fb0e9a1 100644 --- a/docs/checks/PackageManagerGetSignatures.md.html +++ b/docs/checks/PackageManagerGetSignatures.md.html @@ -1,147 +1,8 @@ -(#) Potential Multiple Certificate Exploit +(#) PackageManagerGetSignatures -!!! WARNING: Potential Multiple Certificate Exploit - This is a warning. - -Id -: `PackageManagerGetSignatures` -Summary -: Potential Multiple Certificate Exploit -Severity -: Warning -Category -: Security -Platform -: Android -Vendor -: Android Open Source Project -Feedback -: https://issuetracker.google.com/issues/new?component=192708 -Affects -: Kotlin and Java files -Editing -: This check runs on the fly in the IDE editor -See -: https://bluebox.com/technical/android-fake-id-vulnerability/ -Implementation -: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GetSignaturesDetector.java) -Tests -: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GetSignaturesDetectorTest.java) -Copyright Year -: 2014 - -Improper validation of app signatures could lead to issues where a -malicious app submits itself to the Play Store with both its real -certificate and a fake certificate and gains access to functionality or -information it shouldn't have due to another application only checking -for the fake certificate and ignoring the rest. Please make sure to -validate all signatures returned by this method. - -(##) Example - -Here is an example of lint warnings produced by this check: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -src/test/pkg/GetSignaturesSingleFlagTest.java:9:Warning: Reading app -signatures from getPackageInfo: The app signatures could be exploited if -not validated properly; see issue explanation for details -[PackageManagerGetSignatures] - - .getPackageInfo("some.pkg", PackageManager.GET_SIGNATURES); - ----------------------------- - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Here is the source file referenced above: - -`src/test/pkg/GetSignaturesSingleFlagTest.java`: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers -package test.pkg; - -import android.app.Activity; -import android.content.pm.PackageManager; - -public class GetSignaturesSingleFlagTest extends Activity { - public void failLintCheck() throws Exception { - getPackageManager() - .getPackageInfo("some.pkg", PackageManager.GET_SIGNATURES); - } -} -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -You can also visit the -[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GetSignaturesDetectorTest.java) -for the unit tests for this check to see additional scenarios. - -The above example was automatically extracted from the first unit test -found for this lint check, `GetSignaturesDetector.testLintWarningOnSingleGetSignaturesFlag`. -To report a problem with this extracted sample, visit -https://issuetracker.google.com/issues/new?component=192708. - -(##) Suppressing - -You can suppress false positives using one of the following mechanisms: - -* Using a suppression annotation like this on the enclosing - element: - - ```kt - // Kotlin - @Suppress("PackageManagerGetSignatures") - fun method() { - getPackageInfo(...) - } - ``` - - or - - ```java - // Java - @SuppressWarnings("PackageManagerGetSignatures") - void method() { - getPackageInfo(...); - } - ``` - -* Using a suppression comment like this on the line above: - - ```kt - //noinspection PackageManagerGetSignatures - problematicStatement() - ``` - -* Using a special `lint.xml` file in the source tree which turns off - the check in that folder and any sub folder. A simple file might look - like this: - ```xml - <?xml version="1.0" encoding="UTF-8"?> - <lint> - <issue id="PackageManagerGetSignatures" severity="ignore" /> - </lint> - ``` - Instead of `ignore` you can also change the severity here, for - example from `error` to `warning`. You can find additional - documentation on how to filter issues by path, regular expression and - so on - [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). - -* In Gradle projects, using the DSL syntax to configure lint. For - example, you can use something like - ```gradle - lintOptions { - disable 'PackageManagerGetSignatures' - } - ``` - In Android projects this should be nested inside an `android { }` - block. - -* For manual invocations of `lint`, using the `--ignore` flag: - ``` - $ lint --ignore PackageManagerGetSignatures ...` - ``` - -* Last, but not least, using baselines, as discussed - [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). +The issue for this id has been deleted or marked obsolete and can now be +ignored. +(Additional metadata not available.) \ No newline at end of file diff --git a/docs/checks/PackagedPrivateKey.md.html b/docs/checks/PackagedPrivateKey.md.html index cdaf89c4..5acd499b 100644 --- a/docs/checks/PackagedPrivateKey.md.html +++ b/docs/checks/PackagedPrivateKey.md.html @@ -20,8 +20,12 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Editing : This check can *not* run live in the IDE editor +See +: https://goo.gle/PackagedPrivateKey Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/PrivateKeyDetector.java) Tests @@ -38,17 +42,13 @@ res/private_key.pem:Error: The res/private_key.pem file seems to be a private key file. Please make sure not to embed this in your APK file. [PackagedPrivateKey] - 1 errors, 0 warnings - - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: `res/private_key.pem`: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ linenumbers +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text linenumbers -----BEGIN RSA PRIVATE KEY----- Proc-Type: 4,ENCRYPTED DEK-Info: DES-EDE3-CBC,77F426A58B274623 diff --git a/docs/checks/ParcelClassLoader.md.html b/docs/checks/ParcelClassLoader.md.html index 9b36ab5d..b34b3f15 100644 --- a/docs/checks/ParcelClassLoader.md.html +++ b/docs/checks/ParcelClassLoader.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 2.0.0 (April 2016) Affects : Kotlin and Java files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ReadParcelableDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ReadParcelableDetectorTest.java) -Copyright Year -: 2015 The documentation for `Parcel#readParcelable(ClassLoader)` (and its variations) says that you can pass in `null` to pick up the default @@ -52,83 +52,56 @@ the default class loader) will not work if you are restoring your own classes. Consider using for example getClass().getClassLoader() instead. [ParcelClassLoader] - Parcelable error1 = in.readParcelable(null); -------------------- - - src/test/pkg/ParcelableDemo.java:11:Warning: Passing null here (to use the default class loader) will not work if you are restoring your own classes. Consider using for example getClass().getClassLoader() instead. [ParcelClassLoader] - Parcelable[] error2 = in.readParcelableArray(null); ------------------------- - - src/test/pkg/ParcelableDemo.java:12:Warning: Passing null here (to use the default class loader) will not work if you are restoring your own classes. Consider using for example getClass().getClassLoader() instead. [ParcelClassLoader] - Bundle error3 = in.readBundle(null); ---------------- - - src/test/pkg/ParcelableDemo.java:13:Warning: Passing null here (to use the default class loader) will not work if you are restoring your own classes. Consider using for example getClass().getClassLoader() instead. [ParcelClassLoader] - Object[] error4 = in.readArray(null); --------------- - - src/test/pkg/ParcelableDemo.java:14:Warning: Passing null here (to use the default class loader) will not work if you are restoring your own classes. Consider using for example getClass().getClassLoader() instead. [ParcelClassLoader] - SparseArray error5 = in.readSparseArray(null); --------------------- - - src/test/pkg/ParcelableDemo.java:15:Warning: Passing null here (to use the default class loader) will not work if you are restoring your own classes. Consider using for example getClass().getClassLoader() instead. [ParcelClassLoader] - Object error6 = in.readValue(null); --------------- - - src/test/pkg/ParcelableDemo.java:16:Warning: Passing null here (to use the default class loader) will not work if you are restoring your own classes. Consider using for example getClass().getClassLoader() instead. [ParcelClassLoader] - Parcelable error7 = in.readPersistableBundle(null); --------------------------- - - src/test/pkg/ParcelableDemo.java:17:Warning: Using the default class loader will not work if you are restoring your own classes. Consider using for example readBundle(getClass().getClassLoader()) instead. [ParcelClassLoader] - Bundle error8 = in.readBundle(); ------------ - - src/test/pkg/ParcelableDemo.java:18:Warning: Using the default class loader will not work if you are restoring your own classes. Consider using for example readPersistableBundle(getClass().getClassLoader()) instead. [ParcelClassLoader] - Parcelable error9 = in.readPersistableBundle(); ----------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/ParcelCreator.md.html b/docs/checks/ParcelCreator.md.html index 6788d31b..ad38f480 100644 --- a/docs/checks/ParcelCreator.md.html +++ b/docs/checks/ParcelCreator.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files Editing @@ -45,14 +47,11 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/bytecode/MyParcelable1.java:6:Error: This class implements Parcelable but does not provide a CREATOR field [ParcelCreator] - public class MyParcelable1 implements Parcelable { ------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `src/test/bytecode/MyParcelable1.java`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers @@ -73,6 +72,87 @@ } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/test/bytecode/MyParcelable2.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.bytecode; + +import android.os.Parcel; +import android.os.Parcelable; + +public class MyParcelable2 implements Parcelable { + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + public MyParcelable2 createFromParcel(Parcel in) { + return new MyParcelable2(); + } + + public MyParcelable2[] newArray(int size) { + return new MyParcelable2[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel arg0, int arg1) { + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/bytecode/MyParcelable3.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.bytecode; + +import android.os.Parcel; +import android.os.Parcelable; + +public class MyParcelable3 implements Parcelable { + public static final int CREATOR = 0; // Wrong type + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel arg0, int arg1) { + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/bytecode/MyParcelable4.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.bytecode; + +import android.os.Parcel; +import android.os.Parcelable; + +public abstract class MyParcelable4 implements Parcelable { + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel arg0, int arg1) { + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/bytecode/MyParcelable5.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.bytecode; + +import android.os.Parcelable; + +public interface MyParcelable5 extends Parcelable { + @Override + public int describeContents(); +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ParcelDetectorTest.java) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/ParcelizeFunctionProperty.md.html b/docs/checks/ParcelizeFunctionProperty.md.html new file mode 100644 index 00000000..8346be68 --- /dev/null +++ b/docs/checks/ParcelizeFunctionProperty.md.html @@ -0,0 +1,233 @@ + +(#) Function type properties are not parcelable + +!!! ERROR: Function type properties are not parcelable + This is an error. + +Id +: `ParcelizeFunctionProperty` +Summary +: Function type properties are not parcelable +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.2.3 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/parcel/ParcelizeFunctionPropertyDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/parcel/ParcelizeFunctionPropertyDetectorTest.kt) +Copyright Year +: 2023 + +While technically (and surprisingly) supported by Parcelize, function +types should not be used in Parcelize classes. There are only limited +conditions where it will work and it's usually a sign that you're +modeling your data wrong. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test/pkg/Example1.kt:12:Error: While technically (and surprisingly) +supported by Parcelize, function types should not be used in Parcelize +classes. There are only limited conditions where it will work and it's +usually a sign that you're modeling your data wrong. +[ParcelizeFunctionProperty] + val functionType1: () -> String, + ------------ +src/test/pkg/Example1.kt:13:Error: While technically (and surprisingly) +supported by Parcelize, function types should not be used in Parcelize +classes. There are only limited conditions where it will work and it's +usually a sign that you're modeling your data wrong. +[ParcelizeFunctionProperty] + val functionType2: (String) -> String, + ------------------ +src/test/pkg/Example1.kt:14:Error: While technically (and surprisingly) +supported by Parcelize, function types should not be used in Parcelize +classes. There are only limited conditions where it will work and it's +usually a sign that you're modeling your data wrong. +[ParcelizeFunctionProperty] + val functionType3: String.() -> String, + ------------------- +src/test/pkg/Example1.kt:15:Error: While technically (and surprisingly) +supported by Parcelize, function types should not be used in Parcelize +classes. There are only limited conditions where it will work and it's +usually a sign that you're modeling your data wrong. +[ParcelizeFunctionProperty] + val functionType4: () -> Unit, + ---------- +src/test/pkg/Example1.kt:16:Error: While technically (and surprisingly) +supported by Parcelize, function types should not be used in Parcelize +classes. There are only limited conditions where it will work and it's +usually a sign that you're modeling your data wrong. +[ParcelizeFunctionProperty] + val functionType5: suspend () -> Unit, + ------------------ +src/test/pkg/Example1.kt:17:Error: While technically (and surprisingly) +supported by Parcelize, function types should not be used in Parcelize +classes. There are only limited conditions where it will work and it's +usually a sign that you're modeling your data wrong. +[ParcelizeFunctionProperty] + val aliasedFunction: FunctionType, + ------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test/pkg/Example1.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg + +import android.os.Parcelable +import kotlinx.parcelize.Parcelize +import kotlinx.parcelize.IgnoredOnParcel + +typealias FunctionType = () -> String + +@Parcelize +class Example1( + val foo: String, + val functionType1: () -> String, + val functionType2: (String) -> String, + val functionType3: String.() -> String, + val functionType4: () -> Unit, + val functionType5: suspend () -> Unit, + val aliasedFunction: FunctionType, + val functionClass: FunctionClass, + @IgnoredOnParcel + val ignoredFunction: () -> Unit = {}, // This is allowed +) : Parcelable +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/parcel/ParcelizeFunctionPropertyDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `ParcelizeFunctionPropertyDetector.simple`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ParcelizeFunctionProperty") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ParcelizeFunctionProperty") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ParcelizeFunctionProperty + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ParcelizeFunctionProperty" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ParcelizeFunctionProperty' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ParcelizeFunctionProperty ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/PendingBindings.md.html b/docs/checks/PendingBindings.md.html index 0e17f6e8..8b6eb890 100644 --- a/docs/checks/PendingBindings.md.html +++ b/docs/checks/PendingBindings.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 2.2.0 (September 2016) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/RecyclerViewDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/RecyclerViewDetectorTest.kt) -Copyright Year -: 2015 When using a `ViewDataBinding` in a `onBindViewHolder` method, you **must** call `executePendingBindings()` before the method exits; @@ -44,51 +44,36 @@ exits, otherwise, the DataBinding library will update the UI in the next animation frame causing a delayed update & potential jumps if the item resizes. [PendingBindings] - holder.dataBinder.someMethod(); // ERROR - no pending call ------------------------------ - - src/test/pkg/RecyclerViewTest2.java:40:Error: You must call holder.dataBinder.executePendingBindings() before the onBind method exits, otherwise, the DataBinding library will update the UI in the next animation frame causing a delayed update & potential jumps if the item resizes. [PendingBindings] - holder.dataBinder.someMethod(); // ERROR: After call ------------------------------ - - src/test/pkg/RecyclerViewTest2.java:48:Error: You must call holder.dataBinder.executePendingBindings() before the onBind method exits, otherwise, the DataBinding library will update the UI in the next animation frame causing a delayed update & potential jumps if the item resizes. [PendingBindings] - holder.dataBinder.someMethod(); // ERROR: can't reach pending ------------------------------ - - src/test/pkg/RecyclerViewTest2.java:116:Error: You must call holder.dataBinder.executePendingBindings() before the onBind method exits, otherwise, the DataBinding library will update the UI in the next animation frame causing a delayed update & potential jumps if the item resizes. [PendingBindings] - holder.dataBinder.someMethod(); // ERROR ------------------------------ - - src/test/pkg/RecyclerViewTest2.java:139:Error: You must call holder.dataBinder.executePendingBindings() before the onBind method exits, otherwise, the DataBinding library will update the UI in the next animation frame causing a delayed update & potential jumps if the item resizes. [PendingBindings] - holder.dataBinder.someMethod(); // ERROR: no fallthrough ------------------------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/PermissionImpliesUnsupportedChromeOsHardware.md.html b/docs/checks/PermissionImpliesUnsupportedChromeOsHardware.md.html index d65f8095..825c7658 100644 --- a/docs/checks/PermissionImpliesUnsupportedChromeOsHardware.md.html +++ b/docs/checks/PermissionImpliesUnsupportedChromeOsHardware.md.html @@ -8,8 +8,6 @@ : `PermissionImpliesUnsupportedChromeOsHardware` Summary : Permission Implies Unsupported Chrome OS Hardware -Note -: **This issue is disabled by default**; use `--enable PermissionImpliesUnsupportedChromeOsHardware` Severity : Error Category @@ -20,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 2.3.0 (March 2017) Affects : Manifest files Editing @@ -30,15 +30,13 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ChromeOsDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ChromeOsDetectorTest.java) -Copyright Year -: 2016 The `` element should not require a permission that -implies an unsupported Chrome OS hardware feature. Google Play assumes -that certain hardware related permissions indicate that the underlying -hardware features are required by default. To fix the issue, consider -declaring the corresponding uses-feature element with `required="false"` -attribute. +implies an unsupported large screen hardware feature. Google Play +assumes that certain hardware related permissions indicate that the +underlying hardware features are required by default. To fix the issue, +consider declaring the corresponding element with +`required="false"` attribute. !!! Tip This lint check has an associated quickfix available in the IDE. @@ -50,11 +48,8 @@ AndroidManifest.xml:4:Error: Permission exists without corresponding hardware tag [PermissionImpliesUnsupportedChromeOsHardware] - <uses-permission android:name="android.permission.CALL_PHONE"/> --------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/PermissionImpliesUnsupportedHardware.md.html b/docs/checks/PermissionImpliesUnsupportedHardware.md.html index ea03844e..4b0fdef1 100644 --- a/docs/checks/PermissionImpliesUnsupportedHardware.md.html +++ b/docs/checks/PermissionImpliesUnsupportedHardware.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 1.5.0 (November 2015) Affects : Manifest files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AndroidTvDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AndroidTvDetectorTest.java) -Copyright Year -: 2015 The `` element should not require a permission that implies an unsupported TV hardware feature. Google Play assumes that @@ -48,11 +48,8 @@ AndroidManifest.xml:5:Warning: Permission exists without corresponding hardware tag [PermissionImpliesUnsupportedHardware] - <uses-permission android:name="android.permission.CALL_PHONE"/> --------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/PermissionNamingConvention.md.html b/docs/checks/PermissionNamingConvention.md.html index 1ad87750..40568535 100644 --- a/docs/checks/PermissionNamingConvention.md.html +++ b/docs/checks/PermissionNamingConvention.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.4.0 (January 2023) Affects : Manifest files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/PermissionErrorDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/PermissionErrorDetectorTest.kt) -Copyright Year -: 2022 Permissions should be prefixed with an app's package name, using reverse-domain-style naming. This prefix should be followed by @@ -40,47 +40,35 @@ Following this recommendation avoids naming collisions, and helps clearly identify the owner and intention of a custom permission. +!!! Tip + This lint check has an associated quickfix available in the IDE. + (##) Example Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text AndroidManifest.xml:7:Warning: com.example.helloworld.FOO_BAR does not follow recommended naming convention [PermissionNamingConvention] - <permission android:name="com.example.helloworld.FOO_BAR" /> ------------------------------ - - AndroidManifest.xml:8:Warning: com.example.helloworld.permission.FOO-BAR does not follow recommended naming convention [PermissionNamingConvention] - <permission android:name="com.example.helloworld.permission.FOO-BAR" /> ----------------------------------------- - - AndroidManifest.xml:9:Warning: com.example.helloworld.permission.foo_bar does not follow recommended naming convention [PermissionNamingConvention] - <permission android:name="com.example.helloworld.permission.foo_bar" /> ----------------------------------------- - - AndroidManifest.xml:10:Warning: android.permission.FOO_BAR does not follow recommended naming convention [PermissionNamingConvention] - <permission android:name="android.permission.FOO_BAR" /> -------------------------- - - AndroidManifest.xml:11:Warning: FOO_BAR does not follow recommended naming convention [PermissionNamingConvention] - <permission android:name="FOO_BAR" /> ------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/PictureInPictureIssue.md.html b/docs/checks/PictureInPictureIssue.md.html new file mode 100644 index 00000000..326c0bf1 --- /dev/null +++ b/docs/checks/PictureInPictureIssue.md.html @@ -0,0 +1,140 @@ + +(#) Picture In Picture best practices not followed + +!!! WARNING: Picture In Picture best practices not followed + This is a warning. + +Id +: `PictureInPictureIssue` +Summary +: Picture In Picture best practices not followed +Severity +: Warning +Category +: Correctness +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.6.0 (August 2024) +Affects +: Kotlin and Java files +Editing +: This check can *not* run live in the IDE editor +See +: https://developer.android.com/develop/ui/views/picture-in-picture#smoother-transition +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/PictureInPictureDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/PictureInPictureDetectorTest.kt) + +Starting in Android 12, the recommended approach for enabling +picture-in-picture (PiP) has changed. If your app does not use the new +approach, your app's transition animations will be of poor quality +compared to other apps. The new approach requires calling +`setAutoEnterEnabled(true)` and `setSourceRectHint(...)`. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +AndroidManifest.xml:9:Warning: An activity in this app supports +picture-in-picture and the targetSdkVersion is 31 or above; it is +therefore strongly recommended to call both setAutoEnterEnabled(true) +and setSourceRectHint(...) [PictureInPictureIssue] + <application + ----------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`AndroidManifest.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<manifest + package="test.pkg" + xmlns:android="http://schemas.android.com/apk/res/android"> + + <uses-sdk + android:minSdkVersion="28" + android:targetSdkVersion="31" /> + + <application + android:icon="@mipmap/ic_launcher" + android:label="@string/app_name"> + + <activity + android:name=".TestActivity" + android:exported="true" + android:supportsPictureInPicture="true" + android:configChanges="screenLayout|orientation|screenSize|smallestScreenSize"> + + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + + </activity> + + </application> + +</manifest> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/TestActivity.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg + +import android.app.Activity + +class TestActivity: Activity { + fun test() { + enterPictureInPictureMode() + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/PictureInPictureDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="PictureInPictureIssue" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'PictureInPictureIssue' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore PictureInPictureIssue ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/PinSetExpiry.md.html b/docs/checks/PinSetExpiry.md.html index fc8e3e8f..79ba6c06 100644 --- a/docs/checks/PinSetExpiry.md.html +++ b/docs/checks/PinSetExpiry.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 2.3.0 (March 2017) Affects : Resource files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/NetworkSecurityConfigDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/NetworkSecurityConfigDetectorTest.java) -Copyright Year -: 2016 Ensures that the `expiration` attribute of the `` element is valid and has not already expired or is expiring soon. @@ -40,11 +40,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/xml/network_config.xml:6:Warning: pin-set is expiring soon [PinSetExpiry] - <pin-set expiration="%1$s"> ---------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/PlaySdkIndexDeprecated.md.html b/docs/checks/PlaySdkIndexDeprecated.md.html new file mode 100644 index 00000000..c5dee555 --- /dev/null +++ b/docs/checks/PlaySdkIndexDeprecated.md.html @@ -0,0 +1,147 @@ + +(#) Library is marked as deprecated in SDK Index + +!!! ERROR: Library is marked as deprecated in SDK Index + This is an error. + +Id +: `PlaySdkIndexDeprecated` +Summary +: Library is marked as deprecated in SDK Index +Severity +: Error +Category +: Security +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.9.0 (March 2025) +Affects +: Gradle build files and TOML files +Editing +: This check runs on the fly in the IDE editor +See +: https://developer.android.com/distribute/sdk-index +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GradleDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) + +This library has been deprecated, please consider updating to an +alternative SDK before publishing a new release. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +build.gradle:29:Warning: com.example.issues:deprecated has been +deprecated by its developer. Consider updating to an alternative SDK +before publishing a new release. +The developer has recommended these alternatives: + - Alternative 1 (first:alternative) + - second:alternative + [PlaySdkIndexDeprecated] + compile 'com.example.issues:deprecated:2.0.0' // Deprecated + ------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`build.gradle`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~groovy linenumbers +dependencies { + compile 'log4j:log4j:1.2.18' // OK, latest + compile 'log4j:log4j:1.2.17' // OK + compile 'log4j:log4j:1.2.16' // Critical NON_BLOCKING + compile 'log4j:log4j:1.2.15' // Outdated NON_BLOCKING + compile 'log4j:log4j:1.2.14' // Non compliant + compile 'log4j:log4j:1.2.13' // Critical BLOCKING + compile 'log4j:log4j:1.2.12' // OUTDATED BLOCKING + compile 'log4j:log4j:1.2.11' // Ok (not in Index) + compile 'com.example.ads.third.party:example:8.0.0' // OK + compile 'com.example.ads.third.party:example:7.2.2' // OK + compile 'com.example.ads.third.party:example:7.2.1' // OK + compile 'com.example.ads.third.party:example:7.2.0' // Outdated + Critical + Policy (multiple issues), no severity + compile 'com.example.ads.third.party:example:7.1.0' // Policy (Ads), non-blocking + compile 'com.example.ads.third.party:example:7.1.1' // Policy (Device and Network Abuse), blocking + compile 'com.example.ads.third.party:example:7.1.2' // Policy (Deceptive Behavior), no severity + compile 'com.example.ads.third.party:example:7.1.3' // Policy (User Data), non-blocking + compile 'com.example.ads.third.party:example:7.1.4' // Policy (Permissions), blocking + compile 'com.example.ads.third.party:example:7.1.5' // Policy (Mobile Unwanted Software), no-severity + compile 'com.example.ads.third.party:example:7.1.6' // Policy (Malware), non-blocking + compile 'com.example.ads.third.party:example:7.1.7' // Policy (multiple types), non-blocking + compile 'com.example.ads.third.party:example:7.1.8' // Policy (multiple types), blocking + compile 'com.example.ads.third.party:example:7.1.9' // Policy (multiple types), no severity + compile 'com.example.ads.third.party:example:7.1.10' // Vulnerability (UNSAFE_HOSTNAME_VERIFIER, non-blocking) + compile 'com.example.ads.third.party:example:7.1.11' // Vulnerability multiple (UNSAFE_SSL_ERROR_HANDLER, ZIP_PATH_TRAVERSAL, UNSAFE_WEBVIEW_OAUTH, blocking) + compile 'com.example.ads.third.party:example:7.1.12' // Vulnerability multiple (non-blocking) + compile 'com.example.issues:issues-on-latest:1.8.0' // Outdated blocking + compile 'com.example.issues:latest-is-preview:1.0.0' // Outdated non-blocking + compile 'com.example.issues:deprecated:2.0.0' // Deprecated + + compile 'log4j:log4j:latest.release' // OK + compile 'log4j:log4j' // OK + compile 'log4j:log4j:_' // OK + + compile 'com.another.example:example' // Ok (not in Index) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `GradleDetector.testSdkIndexLibrary`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=192708. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection PlaySdkIndexDeprecated + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="PlaySdkIndexDeprecated" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'PlaySdkIndexDeprecated' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore PlaySdkIndexDeprecated ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/PlaySdkIndexGenericIssues.md.html b/docs/checks/PlaySdkIndexGenericIssues.md.html new file mode 100644 index 00000000..e906725b --- /dev/null +++ b/docs/checks/PlaySdkIndexGenericIssues.md.html @@ -0,0 +1,81 @@ + +(#) Library has issues in SDK Index + +!!! ERROR: Library has issues in SDK Index + This is an error. + +Id +: `PlaySdkIndexGenericIssues` +Summary +: Library has issues in SDK Index +Severity +: Error +Category +: Compliance +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.2.0 (November 2023) +Affects +: Gradle build files and TOML files +Editing +: This check runs on the fly in the IDE editor +See +: https://developer.android.com/distribute/sdk-index +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GradleDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) + +This library version has issues that could block publishing in the +Google Play Store. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection PlaySdkIndexGenericIssues + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="PlaySdkIndexGenericIssues" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'PlaySdkIndexGenericIssues' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore PlaySdkIndexGenericIssues ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/PlaySdkIndexNonCompliant.md.html b/docs/checks/PlaySdkIndexNonCompliant.md.html index 9062273d..88c16d4a 100644 --- a/docs/checks/PlaySdkIndexNonCompliant.md.html +++ b/docs/checks/PlaySdkIndexNonCompliant.md.html @@ -18,22 +18,143 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.3.0 (September 2022) Affects -: Gradle build files +: Gradle build files and TOML files Editing : This check runs on the fly in the IDE editor See -: https://play.google.com/sdks +: https://developer.android.com/distribute/sdk-index Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GradleDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) -Copyright Year -: 2014 This library version has policy issues that will block publishing in the Google Play Store. +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +build.gradle:6:Warning: log4j:log4j version 1.2.14 has policy issues +that will block publishing of your app to Play Console in the future +[PlaySdkIndexNonCompliant] + compile 'log4j:log4j:1.2.14' // Non compliant + -------------------- +build.gradle:13:Warning: com.example.ads.third.party:example version +7.2.0 has User Data policy issues that will block publishing of your app +to Play Console in the future [PlaySdkIndexNonCompliant] + compile 'com.example.ads.third.party:example:7.2.0' // Outdated + Critical + Policy (multiple issues), no severity + ------------------------------------------- +build.gradle:14:Warning: com.example.ads.third.party:example version +7.1.0 has Ads policy issues that will block publishing of your app to +Play Console in the future [PlaySdkIndexNonCompliant] + compile 'com.example.ads.third.party:example:7.1.0' // Policy (Ads), non-blocking + ------------------------------------------- +build.gradle:15:Error: [Prevents app release in Google Play Console] +com.example.ads.third.party:example version 7.1.1 has Device and Network +Abuse policy issues that will block publishing of your app to Play +Console [PlaySdkIndexNonCompliant] + compile 'com.example.ads.third.party:example:7.1.1' // Policy (Device and Network Abuse), blocking + ------------------------------------------- +build.gradle:16:Warning: com.example.ads.third.party:example version +7.1.2 has Deceptive Behavior policy issues that will block publishing of +your app to Play Console in the future [PlaySdkIndexNonCompliant] + compile 'com.example.ads.third.party:example:7.1.2' // Policy (Deceptive Behavior), no severity + ------------------------------------------- +build.gradle:17:Warning: com.example.ads.third.party:example version +7.1.3 has User Data policy issues that will block publishing of your app +to Play Console in the future [PlaySdkIndexNonCompliant] + compile 'com.example.ads.third.party:example:7.1.3' // Policy (User Data), non-blocking + ------------------------------------------- +build.gradle:18:Error: [Prevents app release in Google Play Console] +com.example.ads.third.party:example version 7.1.4 has Permissions policy +issues that will block publishing of your app to Play Console +[PlaySdkIndexNonCompliant] + compile 'com.example.ads.third.party:example:7.1.4' // Policy (Permissions), blocking + ------------------------------------------- +build.gradle:19:Warning: com.example.ads.third.party:example version +7.1.5 has Mobile Unwanted Software policy issues that will block +publishing of your app to Play Console in the future +[PlaySdkIndexNonCompliant] + compile 'com.example.ads.third.party:example:7.1.5' // Policy (Mobile Unwanted Software), no-severity + ------------------------------------------- +build.gradle:20:Warning: com.example.ads.third.party:example version +7.1.6 has Malware policy issues that will block publishing of your app +to Play Console in the future [PlaySdkIndexNonCompliant] + compile 'com.example.ads.third.party:example:7.1.6' // Policy (Malware), non-blocking + ------------------------------------------- +build.gradle:21:Warning: com.example.ads.third.party:example version +7.1.7 has User Data policy issues that will block publishing of your app +to Play Console in the future [PlaySdkIndexNonCompliant] + compile 'com.example.ads.third.party:example:7.1.7' // Policy (multiple types), non-blocking + ------------------------------------------- +build.gradle:22:Error: [Prevents app release in Google Play Console] +com.example.ads.third.party:example version 7.1.8 has User Data policy +issues that will block publishing of your app to Play Console +[PlaySdkIndexNonCompliant] + compile 'com.example.ads.third.party:example:7.1.8' // Policy (multiple types), blocking + ------------------------------------------- +build.gradle:23:Warning: com.example.ads.third.party:example version +7.1.9 has Permissions policy issues that will block publishing of your +app to Play Console in the future [PlaySdkIndexNonCompliant] + compile 'com.example.ads.third.party:example:7.1.9' // Policy (multiple types), no severity + ------------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`build.gradle`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~groovy linenumbers +dependencies { + compile 'log4j:log4j:1.2.18' // OK, latest + compile 'log4j:log4j:1.2.17' // OK + compile 'log4j:log4j:1.2.16' // Critical NON_BLOCKING + compile 'log4j:log4j:1.2.15' // Outdated NON_BLOCKING + compile 'log4j:log4j:1.2.14' // Non compliant + compile 'log4j:log4j:1.2.13' // Critical BLOCKING + compile 'log4j:log4j:1.2.12' // OUTDATED BLOCKING + compile 'log4j:log4j:1.2.11' // Ok (not in Index) + compile 'com.example.ads.third.party:example:8.0.0' // OK + compile 'com.example.ads.third.party:example:7.2.2' // OK + compile 'com.example.ads.third.party:example:7.2.1' // OK + compile 'com.example.ads.third.party:example:7.2.0' // Outdated + Critical + Policy (multiple issues), no severity + compile 'com.example.ads.third.party:example:7.1.0' // Policy (Ads), non-blocking + compile 'com.example.ads.third.party:example:7.1.1' // Policy (Device and Network Abuse), blocking + compile 'com.example.ads.third.party:example:7.1.2' // Policy (Deceptive Behavior), no severity + compile 'com.example.ads.third.party:example:7.1.3' // Policy (User Data), non-blocking + compile 'com.example.ads.third.party:example:7.1.4' // Policy (Permissions), blocking + compile 'com.example.ads.third.party:example:7.1.5' // Policy (Mobile Unwanted Software), no-severity + compile 'com.example.ads.third.party:example:7.1.6' // Policy (Malware), non-blocking + compile 'com.example.ads.third.party:example:7.1.7' // Policy (multiple types), non-blocking + compile 'com.example.ads.third.party:example:7.1.8' // Policy (multiple types), blocking + compile 'com.example.ads.third.party:example:7.1.9' // Policy (multiple types), no severity + compile 'com.example.ads.third.party:example:7.1.10' // Vulnerability (UNSAFE_HOSTNAME_VERIFIER, non-blocking) + compile 'com.example.ads.third.party:example:7.1.11' // Vulnerability multiple (UNSAFE_SSL_ERROR_HANDLER, ZIP_PATH_TRAVERSAL, UNSAFE_WEBVIEW_OAUTH, blocking) + compile 'com.example.ads.third.party:example:7.1.12' // Vulnerability multiple (non-blocking) + compile 'com.example.issues:issues-on-latest:1.8.0' // Outdated blocking + compile 'com.example.issues:latest-is-preview:1.0.0' // Outdated non-blocking + compile 'com.example.issues:deprecated:2.0.0' // Deprecated + + compile 'log4j:log4j:latest.release' // OK + compile 'log4j:log4j' // OK + compile 'log4j:log4j:_' // OK + + compile 'com.another.example:example' // Ok (not in Index) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `GradleDetector.testSdkIndexLibrary`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=192708. + (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/PlaySdkIndexVulnerability.md.html b/docs/checks/PlaySdkIndexVulnerability.md.html new file mode 100644 index 00000000..0fcd5750 --- /dev/null +++ b/docs/checks/PlaySdkIndexVulnerability.md.html @@ -0,0 +1,158 @@ + +(#) Library has vulnerability issues in SDK Index + +!!! ERROR: Library has vulnerability issues in SDK Index + This is an error. + +Id +: `PlaySdkIndexVulnerability` +Summary +: Library has vulnerability issues in SDK Index +Severity +: Error +Category +: Compliance +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.8.0 (January 2025) +Affects +: Gradle build files and TOML files +Editing +: This check runs on the fly in the IDE editor +See +: https://developer.android.com/distribute/sdk-index +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GradleDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) + +This library version has vulnerability issues that could block +publishing in the Google Play Store. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +build.gradle:13:Warning: com.example.ads.third.party:example version +7.2.0 contains an unsafe implementation of the X509TrustManager +interface. [PlaySdkIndexVulnerability] + compile 'com.example.ads.third.party:example:7.2.0' // Outdated + Critical + Policy (multiple issues), no severity + ------------------------------------------- +build.gradle:24:Warning: com.example.ads.third.party:example version +7.1.10 contains an unsafe implementation of the interfaces +HostnameVerifier or X509HostnameVerifier. [PlaySdkIndexVulnerability] + compile 'com.example.ads.third.party:example:7.1.10' // Vulnerability (UNSAFE_HOSTNAME_VERIFIER, non-blocking) + -------------------------------------------- +build.gradle:25:Error: com.example.ads.third.party:example version +7.1.11 uses WebView for authentication, which is not recommended. +[PlaySdkIndexVulnerability] + compile 'com.example.ads.third.party:example:7.1.11' // Vulnerability multiple (UNSAFE_SSL_ERROR_HANDLER, ZIP_PATH_TRAVERSAL, UNSAFE_WEBVIEW_OAUTH, blocking) + -------------------------------------------- +build.gradle:26:Warning: com.example.ads.third.party:example version +7.1.12 may be vulnerable to WebView Cross-App Scripting. +[PlaySdkIndexVulnerability] + compile 'com.example.ads.third.party:example:7.1.12' // Vulnerability multiple (non-blocking) + -------------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`build.gradle`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~groovy linenumbers +dependencies { + compile 'log4j:log4j:1.2.18' // OK, latest + compile 'log4j:log4j:1.2.17' // OK + compile 'log4j:log4j:1.2.16' // Critical NON_BLOCKING + compile 'log4j:log4j:1.2.15' // Outdated NON_BLOCKING + compile 'log4j:log4j:1.2.14' // Non compliant + compile 'log4j:log4j:1.2.13' // Critical BLOCKING + compile 'log4j:log4j:1.2.12' // OUTDATED BLOCKING + compile 'log4j:log4j:1.2.11' // Ok (not in Index) + compile 'com.example.ads.third.party:example:8.0.0' // OK + compile 'com.example.ads.third.party:example:7.2.2' // OK + compile 'com.example.ads.third.party:example:7.2.1' // OK + compile 'com.example.ads.third.party:example:7.2.0' // Outdated + Critical + Policy (multiple issues), no severity + compile 'com.example.ads.third.party:example:7.1.0' // Policy (Ads), non-blocking + compile 'com.example.ads.third.party:example:7.1.1' // Policy (Device and Network Abuse), blocking + compile 'com.example.ads.third.party:example:7.1.2' // Policy (Deceptive Behavior), no severity + compile 'com.example.ads.third.party:example:7.1.3' // Policy (User Data), non-blocking + compile 'com.example.ads.third.party:example:7.1.4' // Policy (Permissions), blocking + compile 'com.example.ads.third.party:example:7.1.5' // Policy (Mobile Unwanted Software), no-severity + compile 'com.example.ads.third.party:example:7.1.6' // Policy (Malware), non-blocking + compile 'com.example.ads.third.party:example:7.1.7' // Policy (multiple types), non-blocking + compile 'com.example.ads.third.party:example:7.1.8' // Policy (multiple types), blocking + compile 'com.example.ads.third.party:example:7.1.9' // Policy (multiple types), no severity + compile 'com.example.ads.third.party:example:7.1.10' // Vulnerability (UNSAFE_HOSTNAME_VERIFIER, non-blocking) + compile 'com.example.ads.third.party:example:7.1.11' // Vulnerability multiple (UNSAFE_SSL_ERROR_HANDLER, ZIP_PATH_TRAVERSAL, UNSAFE_WEBVIEW_OAUTH, blocking) + compile 'com.example.ads.third.party:example:7.1.12' // Vulnerability multiple (non-blocking) + compile 'com.example.issues:issues-on-latest:1.8.0' // Outdated blocking + compile 'com.example.issues:latest-is-preview:1.0.0' // Outdated non-blocking + compile 'com.example.issues:deprecated:2.0.0' // Deprecated + + compile 'log4j:log4j:latest.release' // OK + compile 'log4j:log4j' // OK + compile 'log4j:log4j:_' // OK + + compile 'com.another.example:example' // Ok (not in Index) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `GradleDetector.testSdkIndexLibrary`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=192708. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection PlaySdkIndexVulnerability + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="PlaySdkIndexVulnerability" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'PlaySdkIndexVulnerability' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore PlaySdkIndexVulnerability ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/PluralsCandidate.md.html b/docs/checks/PluralsCandidate.md.html index e83468a9..b8855a0e 100644 --- a/docs/checks/PluralsCandidate.md.html +++ b/docs/checks/PluralsCandidate.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 1.1.0 (February 2015) Affects : Resource files Editing @@ -25,11 +27,9 @@ See : https://developer.android.com/guide/topics/resources/string-resource.html#Plurals Implementation -: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/StringFormatDetector.java) +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/StringFormatDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/StringFormatDetectorTest.java) -Copyright Year -: 2011 This lint check looks for potential errors in internationalization where you have translated a message which involves a quantity and it looks @@ -60,11 +60,8 @@ res/values/plurals_candidates.xml:4:Warning: Formatting %d followed by words ("times"): This should probably be a plural rather than a string [PluralsCandidate] - <string name="lockscreen_too_many_failed_attempts_dialog_message1"> ^ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/PrivacySandboxBlockedCall.md.html b/docs/checks/PrivacySandboxBlockedCall.md.html new file mode 100644 index 00000000..711a77df --- /dev/null +++ b/docs/checks/PrivacySandboxBlockedCall.md.html @@ -0,0 +1,89 @@ + +(#) Call is blocked in the Privacy Sandbox + +!!! WARNING: Call is blocked in the Privacy Sandbox + This is a warning. + +Id +: `PrivacySandboxBlockedCall` +Summary +: Call is blocked in the Privacy Sandbox +Note +: **This issue is disabled by default**; use `--enable PrivacySandboxBlockedCall` +Severity +: Warning +Category +: Correctness +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.9.0 (March 2025) +Affects +: Kotlin and Java files +Editing +: This check can *not* run live in the IDE editor +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/RestrictedEnvironmentBlockedCallDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/RestrictedEnvironmentBlockedCallDetectorTest.kt) + +Many APIs are unavailable in the Privacy Sandbox, depending on the +`targetSdk`. + +If your code is designed to run in the sandbox (and never outside the +sandbox) then you should remove the blocked calls to avoid exceptions at +runtime. + +If your code is part of a library that can be executed both inside and +outside the sandbox, surround the code with `if +(!Process.isSdkSandbox()) { ... }` (or use your own field or method +annotated with `@ChecksRestrictedEnvironment`) to avoid executing +blocked calls when in the sandbox. Or, add the +`@RestrictedForEnvironment` annotation to the containing method if the +entire method should not be called when in the sandbox. + +This check is disabled by default, and should only be enabled in modules +that may execute in the Privacy Sandbox. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="PrivacySandboxBlockedCall" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'PrivacySandboxBlockedCall' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore PrivacySandboxBlockedCall ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/PrivateApi.md.html b/docs/checks/PrivateApi.md.html index 8e65fe77..95c75dcd 100644 --- a/docs/checks/PrivateApi.md.html +++ b/docs/checks/PrivateApi.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.0.0 (October 2017) Affects : Kotlin and Java files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/PrivateApiDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/PrivateApiDetectorTest.kt) -Copyright Year -: 2017 Using reflection to access hidden/private Android APIs is not safe; it will often not work on devices from other vendors, and it may suddenly @@ -43,27 +43,18 @@ src/test/pkg/myapplication/ReflectionTest1.java:8:Warning: Accessing internal APIs via reflection is not supported and may not work on all devices or in the future [PrivateApi] - Class<?> c = Class.forName("com.android.internal.widget.LockPatternUtils"); // ERROR ------------------------------------------------------------- - - src/test/pkg/myapplication/ReflectionTest1.java:9:Warning: Accessing internal APIs via reflection is not supported and may not work on all devices or in the future [PrivateApi] - int titleContainerId = (Integer) Class.forName("com.android.internal.R{$}id").getField("title_container").get(null); -------------------------------------------- - - src/test/pkg/myapplication/ReflectionTest1.java:11:Warning: Accessing internal APIs via reflection is not supported and may not work on all devices or in the future [PrivateApi] - Class SystemProperties = cl.loadClass("android.os.SystemProperties"); ------------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/PrivateResource.md.html b/docs/checks/PrivateResource.md.html index 9bd3bdd7..82e98ab2 100644 --- a/docs/checks/PrivateResource.md.html +++ b/docs/checks/PrivateResource.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files and resource files Editing @@ -41,11 +43,8 @@ src/main/res/layout/private.xml:10:Warning: The resource @string/my_private_string is marked as private in com.android.tools:test-library:1.0.0 [PrivateResource] - android:text="@string/my_private_string" /> ------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/ProduceStateDoesNotAssignValue.md.html b/docs/checks/ProduceStateDoesNotAssignValue.md.html index 05fd5072..a4f1ddf1 100644 --- a/docs/checks/ProduceStateDoesNotAssignValue.md.html +++ b/docs/checks/ProduceStateDoesNotAssignValue.md.html @@ -20,6 +20,14 @@ : androidx.compose.runtime Feedback : https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.runtime:runtime-android](androidx_compose_runtime_runtime-android.md.html) +Since +: 1.5.0 Affects : Kotlin and Java files and test sources Editing @@ -44,35 +52,23 @@ src/androidx/compose/runtime/foo/test.kt:8:Error: produceState calls should assign value inside the producer lambda [ProduceStateDoesNotAssignValue] - produceState(true, true) { ------------ - - src/androidx/compose/runtime/foo/test.kt:12:Error: produceState calls should assign value inside the producer lambda [ProduceStateDoesNotAssignValue] - produceState(true, true) { ------------ - - src/androidx/compose/runtime/foo/test.kt:17:Error: produceState calls should assign value inside the producer lambda [ProduceStateDoesNotAssignValue] - produceState(true, true) { ------------ - - src/androidx/compose/runtime/foo/test.kt:21:Error: produceState calls should assign value inside the producer lambda [ProduceStateDoesNotAssignValue] - produceState(true, true) { ------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -118,6 +114,44 @@ To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=612128. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.runtime:runtime-android:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.runtime:runtime-android:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.runtime.android) + +# libs.versions.toml +[versions] +runtime-android = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +runtime-android = { + module = "androidx.compose.runtime:runtime-android", + version.ref = "runtime-android" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.runtime:runtime-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.runtime:runtime-android](androidx_compose_runtime_runtime-android.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/Proguard.md.html b/docs/checks/Proguard.md.html index 188c9742..700ca2b9 100644 --- a/docs/checks/Proguard.md.html +++ b/docs/checks/Proguard.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Shrinking configuration files Editing @@ -49,17 +51,14 @@ proguard.cfg:21:Error: Obsolete ProGuard file; use -keepclasseswithmembers instead of -keepclasseswithmembernames [Proguard] - -keepclasseswithmembernames class * { ^ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: `proguard.cfg`: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ linenumbers +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~proguard linenumbers -optimizationpasses 5 -dontusemixedcaseclassnames -dontskipnonpubliclibraryclasses diff --git a/docs/checks/ProguardSplit.md.html b/docs/checks/ProguardSplit.md.html index 262488c0..592bd1bc 100644 --- a/docs/checks/ProguardSplit.md.html +++ b/docs/checks/ProguardSplit.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Shrinking configuration files Editing @@ -64,18 +66,15 @@ Android configuration: Inherit these settings instead? Modify project.properties to define proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:myfile.txt - and then keep only project-specific configuration here [ProguardSplit] - +and then keep only project-specific configuration here [ProguardSplit] -keep public class * extends android.app.Activity ^ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `myfile.txt`: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ linenumbers +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text linenumbers -optimizationpasses 5 -dontusemixedcaseclassnames -dontskipnonpubliclibraryclasses @@ -114,6 +113,13 @@ } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`project.properties`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~properties linenumbers +target=android-14 +proguard.config=${sdk.dir}/foo.cfg:${user.home}/bar.pro;myfile.txt + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ProguardDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/PropertyEscape.md.html b/docs/checks/PropertyEscape.md.html index ef536790..6ab4bb34 100644 --- a/docs/checks/PropertyEscape.md.html +++ b/docs/checks/PropertyEscape.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Property files Editing @@ -44,26 +46,20 @@ local.properties:11:Error: Windows file separators (\) and drive letter separators (':') must be escaped (\\) in property files; use C\:\\my\\path\\to\\sdk [PropertyEscape] - windows.dir=C:\my\path\to\sdk -------------- - - local.properties:14:Error: Windows file separators (\) and drive letter separators (':') must be escaped (\\) in property files; use C\:\\Documents and Settings\\UserName\\Local Settings\\Application Data\\Android\\android-studio\\sdk [PropertyEscape] - ok.sdk.dir=C:\\Documents and Settings\\UserName\\Local Settings\\Application Data\\Android\\android-studio\\sdk - - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: `local.properties`: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ linenumbers +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~properties linenumbers ## This file is automatically generated by Android Studio. # Do not modify this file -- YOUR CHANGES WILL BE ERASED! # diff --git a/docs/checks/ProtectedPermissions.md.html b/docs/checks/ProtectedPermissions.md.html index 4b6f5cc4..f588f446 100644 --- a/docs/checks/ProtectedPermissions.md.html +++ b/docs/checks/ProtectedPermissions.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Manifest files Editing @@ -30,615 +32,18 @@ : 2012 Permissions with the protection level `signature`, `privileged` or -`signatureOrSystem` are only granted to system apps. If an app is a -regular non-system app, it will never be able to use these permissions. +`signatureOrSystem` are only granted to system apps (unless they also +include `appop`). If an app is a regular non-system app, it will never +be able to use these permissions. (##) Example Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -AndroidManifest.xml:15:Error: Permission is only granted to system apps +AndroidManifest.xml:13:Error: Permission is only granted to system apps [ProtectedPermissions] - - <uses-permission android:name="android.intent.category.MASTER_CLEAR.permission.C2D_MESSAGE" /> - -------------------------------------------------------------------------- - - -AndroidManifest.xml:16:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.ACCESS_CACHE_FILESYSTEM" /> - --------------------------------------------------------- - - -AndroidManifest.xml:17:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.ACCESS_CHECKIN_PROPERTIES" /> - ----------------------------------------------------------- - - -AndroidManifest.xml:18:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.ACCESS_MTP" /> - -------------------------------------------- - - -AndroidManifest.xml:19:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.ACCESS_SURFACE_FLINGER" /> - -------------------------------------------------------- - - -AndroidManifest.xml:20:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.ACCOUNT_MANAGER" /> - ------------------------------------------------- - - -AndroidManifest.xml:21:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.ALLOW_ANY_CODEC_FOR_PLAYBACK" /> - -------------------------------------------------------------- - - -AndroidManifest.xml:22:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.ASEC_ACCESS" /> - --------------------------------------------- - - -AndroidManifest.xml:23:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.ASEC_CREATE" /> - --------------------------------------------- - - -AndroidManifest.xml:24:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.ASEC_DESTROY" /> - ---------------------------------------------- - - -AndroidManifest.xml:25:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.ASEC_MOUNT_UNMOUNT" /> - ---------------------------------------------------- - - -AndroidManifest.xml:26:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.ASEC_RENAME" /> - --------------------------------------------- - - -AndroidManifest.xml:27:Error: Permission is only granted to system apps -[ProtectedPermissions] - <uses-permission android:name="android.permission.BACKUP" /> ---------------------------------------- - - -AndroidManifest.xml:28:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.BIND_APPWIDGET" /> - ------------------------------------------------ - - -AndroidManifest.xml:29:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.BIND_DEVICE_ADMIN" /> - --------------------------------------------------- - - -AndroidManifest.xml:30:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.BIND_INPUT_METHOD" /> - --------------------------------------------------- - - -AndroidManifest.xml:31:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.BIND_PACKAGE_VERIFIER" /> - ------------------------------------------------------- - - -AndroidManifest.xml:32:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.BIND_REMOTEVIEWS" /> - -------------------------------------------------- - - -AndroidManifest.xml:33:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.BIND_TEXT_SERVICE" /> - --------------------------------------------------- - - -AndroidManifest.xml:34:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.BIND_VPN_SERVICE" /> - -------------------------------------------------- - - -AndroidManifest.xml:35:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.BIND_WALLPAPER" /> - ------------------------------------------------ - - -AndroidManifest.xml:36:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.BRICK" /> - --------------------------------------- - - -AndroidManifest.xml:37:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.BROADCAST_PACKAGE_REMOVED" /> - ----------------------------------------------------------- - - -AndroidManifest.xml:38:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.BROADCAST_SMS" /> - ----------------------------------------------- - - -AndroidManifest.xml:39:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.BROADCAST_WAP_PUSH" /> - ---------------------------------------------------- - - -AndroidManifest.xml:40:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.CALL_PRIVILEGED" /> - ------------------------------------------------- - - -AndroidManifest.xml:41:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.CHANGE_BACKGROUND_DATA_SETTING" /> - ---------------------------------------------------------------- - - -AndroidManifest.xml:42:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE" /> - ---------------------------------------------------------------- - - -AndroidManifest.xml:43:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.CLEAR_APP_USER_DATA" /> - ----------------------------------------------------- - - -AndroidManifest.xml:44:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.CONFIRM_FULL_BACKUP" /> - ----------------------------------------------------- - - -AndroidManifest.xml:45:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.CONNECTIVITY_INTERNAL" /> - ------------------------------------------------------- - - -AndroidManifest.xml:46:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.CONTROL_LOCATION_UPDATES" /> - ---------------------------------------------------------- - - -AndroidManifest.xml:47:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.COPY_PROTECTED_DATA" /> - ----------------------------------------------------- - - -AndroidManifest.xml:48:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.CRYPT_KEEPER" /> - ---------------------------------------------- - - -AndroidManifest.xml:49:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.DELETE_CACHE_FILES" /> - ---------------------------------------------------- - - -AndroidManifest.xml:50:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.DELETE_PACKAGES" /> - ------------------------------------------------- - - -AndroidManifest.xml:51:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.DEVICE_POWER" /> - ---------------------------------------------- - - -AndroidManifest.xml:52:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.DIAGNOSTIC" /> - -------------------------------------------- - - -AndroidManifest.xml:53:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.DUMP" /> - -------------------------------------- - - -AndroidManifest.xml:54:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.FACTORY_TEST" /> - ---------------------------------------------- - - -AndroidManifest.xml:55:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.FORCE_BACK" /> - -------------------------------------------- - - -AndroidManifest.xml:56:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.FORCE_STOP_PACKAGES" /> - ----------------------------------------------------- - - -AndroidManifest.xml:57:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.GLOBAL_SEARCH" /> - ----------------------------------------------- - - -AndroidManifest.xml:58:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.GLOBAL_SEARCH_CONTROL" /> - ------------------------------------------------------- - - -AndroidManifest.xml:59:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.HARDWARE_TEST" /> - ----------------------------------------------- - - -AndroidManifest.xml:60:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.INJECT_EVENTS" /> - ----------------------------------------------- - - -AndroidManifest.xml:61:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.INSTALL_LOCATION_PROVIDER" /> - ----------------------------------------------------------- - - -AndroidManifest.xml:62:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.INSTALL_PACKAGES" /> - -------------------------------------------------- - - -AndroidManifest.xml:63:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.INTERNAL_SYSTEM_WINDOW" /> - -------------------------------------------------------- - - -AndroidManifest.xml:64:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.MANAGE_APP_TOKENS" /> - --------------------------------------------------- - - -AndroidManifest.xml:65:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.MANAGE_NETWORK_POLICY" /> - ------------------------------------------------------- - - -AndroidManifest.xml:66:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.MANAGE_USB" /> - -------------------------------------------- - - -AndroidManifest.xml:67:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.MASTER_CLEAR" /> - ---------------------------------------------- - - -AndroidManifest.xml:68:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.MODIFY_NETWORK_ACCOUNTING" /> - ----------------------------------------------------------- - - -AndroidManifest.xml:69:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /> - ---------------------------------------------------- - - -AndroidManifest.xml:70:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.MOVE_PACKAGE" /> - ---------------------------------------------- - - -AndroidManifest.xml:71:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.NET_ADMIN" /> - ------------------------------------------- - - -AndroidManifest.xml:72:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /> - ---------------------------------------------------- - - -AndroidManifest.xml:73:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" /> - ----------------------------------------------------- - - -AndroidManifest.xml:74:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.PACKAGE_VERIFICATION_AGENT" /> - ------------------------------------------------------------ - - -AndroidManifest.xml:75:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.PERFORM_CDMA_PROVISIONING" /> - ----------------------------------------------------------- - - -AndroidManifest.xml:76:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.READ_FRAME_BUFFER" /> - --------------------------------------------------- - - -AndroidManifest.xml:77:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.READ_INPUT_STATE" /> - -------------------------------------------------- - - -AndroidManifest.xml:78:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.READ_NETWORK_USAGE_HISTORY" /> - ------------------------------------------------------------ - - -AndroidManifest.xml:79:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE" /> - ------------------------------------------------------------- - - -AndroidManifest.xml:80:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.REBOOT" /> - ---------------------------------------- - - -AndroidManifest.xml:81:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.RECEIVE_EMERGENCY_BROADCAST" /> - ------------------------------------------------------------- - - -AndroidManifest.xml:82:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.REMOVE_TASKS" /> - ---------------------------------------------- - - -AndroidManifest.xml:83:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.RETRIEVE_WINDOW_CONTENT" /> - --------------------------------------------------------- - - -AndroidManifest.xml:84:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.SEND_SMS_NO_CONFIRMATION" /> - ---------------------------------------------------------- - - -AndroidManifest.xml:85:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.SET_ACTIVITY_WATCHER" /> - ------------------------------------------------------ - - -AndroidManifest.xml:86:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.SET_ORIENTATION" /> - ------------------------------------------------- - - -AndroidManifest.xml:87:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.SET_POINTER_SPEED" /> - --------------------------------------------------- - - -AndroidManifest.xml:88:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.SET_PREFERRED_APPLICATIONS" /> - ------------------------------------------------------------ - - -AndroidManifest.xml:89:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.SET_SCREEN_COMPATIBILITY" /> - ---------------------------------------------------------- - - -AndroidManifest.xml:90:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.SET_TIME" /> - ------------------------------------------ - - -AndroidManifest.xml:91:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.SET_WALLPAPER_COMPONENT" /> - --------------------------------------------------------- - - -AndroidManifest.xml:92:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.SHUTDOWN" /> - ------------------------------------------ - - -AndroidManifest.xml:93:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.STATUS_BAR" /> - -------------------------------------------- - - -AndroidManifest.xml:94:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.STATUS_BAR_SERVICE" /> - ---------------------------------------------------- - - -AndroidManifest.xml:95:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.STOP_APP_SWITCHES" /> - --------------------------------------------------- - - -AndroidManifest.xml:96:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.UPDATE_DEVICE_STATS" /> - ----------------------------------------------------- - - -AndroidManifest.xml:97:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.WRITE_APN_SETTINGS" /> - ---------------------------------------------------- - - -AndroidManifest.xml:98:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.WRITE_GSERVICES" /> - ------------------------------------------------- - - -AndroidManifest.xml:99:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.WRITE_MEDIA_STORAGE" /> - ----------------------------------------------------- - - -AndroidManifest.xml:100:Error: Permission is only granted to system apps -[ProtectedPermissions] - - <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" /> - ------------------------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -653,112 +58,11 @@ <uses-sdk android:minSdkVersion="14" /> - <!-- No warnings for those --> - <uses-permission android:name="android.permission.GET_ACCOUNTS" /> - <uses-permission android:name="android.permission.SEND_SMS" /> + <!-- Ok: --> <uses-permission android:name="android.permission.INTERNET" /> - <!-- Warnings for those --> - <uses-permission android:name="android.intent.category.MASTER_CLEAR.permission.C2D_MESSAGE" /> - <uses-permission android:name="android.permission.ACCESS_CACHE_FILESYSTEM" /> - <uses-permission android:name="android.permission.ACCESS_CHECKIN_PROPERTIES" /> - <uses-permission android:name="android.permission.ACCESS_MTP" /> - <uses-permission android:name="android.permission.ACCESS_SURFACE_FLINGER" /> - <uses-permission android:name="android.permission.ACCOUNT_MANAGER" /> - <uses-permission android:name="android.permission.ALLOW_ANY_CODEC_FOR_PLAYBACK" /> - <uses-permission android:name="android.permission.ASEC_ACCESS" /> - <uses-permission android:name="android.permission.ASEC_CREATE" /> - <uses-permission android:name="android.permission.ASEC_DESTROY" /> - <uses-permission android:name="android.permission.ASEC_MOUNT_UNMOUNT" /> - <uses-permission android:name="android.permission.ASEC_RENAME" /> + <!-- Error --> <uses-permission android:name="android.permission.BACKUP" /> - <uses-permission android:name="android.permission.BIND_APPWIDGET" /> - <uses-permission android:name="android.permission.BIND_DEVICE_ADMIN" /> - <uses-permission android:name="android.permission.BIND_INPUT_METHOD" /> - <uses-permission android:name="android.permission.BIND_PACKAGE_VERIFIER" /> - <uses-permission android:name="android.permission.BIND_REMOTEVIEWS" /> - <uses-permission android:name="android.permission.BIND_TEXT_SERVICE" /> - <uses-permission android:name="android.permission.BIND_VPN_SERVICE" /> - <uses-permission android:name="android.permission.BIND_WALLPAPER" /> - <uses-permission android:name="android.permission.BRICK" /> - <uses-permission android:name="android.permission.BROADCAST_PACKAGE_REMOVED" /> - <uses-permission android:name="android.permission.BROADCAST_SMS" /> - <uses-permission android:name="android.permission.BROADCAST_WAP_PUSH" /> - <uses-permission android:name="android.permission.CALL_PRIVILEGED" /> - <uses-permission android:name="android.permission.CHANGE_BACKGROUND_DATA_SETTING" /> - <uses-permission android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE" /> - <uses-permission android:name="android.permission.CLEAR_APP_USER_DATA" /> - <uses-permission android:name="android.permission.CONFIRM_FULL_BACKUP" /> - <uses-permission android:name="android.permission.CONNECTIVITY_INTERNAL" /> - <uses-permission android:name="android.permission.CONTROL_LOCATION_UPDATES" /> - <uses-permission android:name="android.permission.COPY_PROTECTED_DATA" /> - <uses-permission android:name="android.permission.CRYPT_KEEPER" /> - <uses-permission android:name="android.permission.DELETE_CACHE_FILES" /> - <uses-permission android:name="android.permission.DELETE_PACKAGES" /> - <uses-permission android:name="android.permission.DEVICE_POWER" /> - <uses-permission android:name="android.permission.DIAGNOSTIC" /> - <uses-permission android:name="android.permission.DUMP" /> - <uses-permission android:name="android.permission.FACTORY_TEST" /> - <uses-permission android:name="android.permission.FORCE_BACK" /> - <uses-permission android:name="android.permission.FORCE_STOP_PACKAGES" /> - <uses-permission android:name="android.permission.GLOBAL_SEARCH" /> - <uses-permission android:name="android.permission.GLOBAL_SEARCH_CONTROL" /> - <uses-permission android:name="android.permission.HARDWARE_TEST" /> - <uses-permission android:name="android.permission.INJECT_EVENTS" /> - <uses-permission android:name="android.permission.INSTALL_LOCATION_PROVIDER" /> - <uses-permission android:name="android.permission.INSTALL_PACKAGES" /> - <uses-permission android:name="android.permission.INTERNAL_SYSTEM_WINDOW" /> - <uses-permission android:name="android.permission.MANAGE_APP_TOKENS" /> - <uses-permission android:name="android.permission.MANAGE_NETWORK_POLICY" /> - <uses-permission android:name="android.permission.MANAGE_USB" /> - <uses-permission android:name="android.permission.MASTER_CLEAR" /> - <uses-permission android:name="android.permission.MODIFY_NETWORK_ACCOUNTING" /> - <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /> - <uses-permission android:name="android.permission.MOVE_PACKAGE" /> - <uses-permission android:name="android.permission.NET_ADMIN" /> - <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /> - <uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" /> - <uses-permission android:name="android.permission.PACKAGE_VERIFICATION_AGENT" /> - <uses-permission android:name="android.permission.PERFORM_CDMA_PROVISIONING" /> - <uses-permission android:name="android.permission.READ_FRAME_BUFFER" /> - <uses-permission android:name="android.permission.READ_INPUT_STATE" /> - <uses-permission android:name="android.permission.READ_NETWORK_USAGE_HISTORY" /> - <uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE" /> - <uses-permission android:name="android.permission.REBOOT" /> - <uses-permission android:name="android.permission.RECEIVE_EMERGENCY_BROADCAST" /> - <uses-permission android:name="android.permission.REMOVE_TASKS" /> - <uses-permission android:name="android.permission.RETRIEVE_WINDOW_CONTENT" /> - <uses-permission android:name="android.permission.SEND_SMS_NO_CONFIRMATION" /> - <uses-permission android:name="android.permission.SET_ACTIVITY_WATCHER" /> - <uses-permission android:name="android.permission.SET_ORIENTATION" /> - <uses-permission android:name="android.permission.SET_POINTER_SPEED" /> - <uses-permission android:name="android.permission.SET_PREFERRED_APPLICATIONS" /> - <uses-permission android:name="android.permission.SET_SCREEN_COMPATIBILITY" /> - <uses-permission android:name="android.permission.SET_TIME" /> - <uses-permission android:name="android.permission.SET_WALLPAPER_COMPONENT" /> - <uses-permission android:name="android.permission.SHUTDOWN" /> - <uses-permission android:name="android.permission.STATUS_BAR" /> - <uses-permission android:name="android.permission.STATUS_BAR_SERVICE" /> - <uses-permission android:name="android.permission.STOP_APP_SWITCHES" /> - <uses-permission android:name="android.permission.UPDATE_DEVICE_STATS" /> - <uses-permission android:name="android.permission.WRITE_APN_SETTINGS" /> - <uses-permission android:name="android.permission.WRITE_GSERVICES" /> - <uses-permission android:name="android.permission.WRITE_MEDIA_STORAGE" /> - <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" /> - - <application - android:icon="@drawable/ic_launcher" - android:label="@string/app_name" > - <activity - android:label="@string/app_name" - android:name=".Foo2Activity" > - <intent-filter > - <action android:name="android.intent.action.MAIN" /> - - <category android:name="android.intent.category.LAUNCHER" /> - </intent-filter> - </activity> - </application> </manifest> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -767,11 +71,6 @@ [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/SystemPermissionsDetectorTest.java) for the unit tests for this check to see additional scenarios. -The above example was automatically extracted from the first unit test -found for this lint check, `SystemPermissionsDetector.testBrokenOrder`. -To report a problem with this extracted sample, visit -https://issuetracker.google.com/issues/new?component=192708. - (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/ProtoLayoutEdgeContentLayoutResponsive.md.html b/docs/checks/ProtoLayoutEdgeContentLayoutResponsive.md.html new file mode 100644 index 00000000..20c9411a --- /dev/null +++ b/docs/checks/ProtoLayoutEdgeContentLayoutResponsive.md.html @@ -0,0 +1,158 @@ + +(#) ProtoLayout Material EdgeContentLayout should be used with responsivebehaviour to ensure the best behaviour across different screen sizes andlocales + +!!! WARNING: ProtoLayout Material EdgeContentLayout should be used with responsivebehaviour to ensure the best behaviour across different screen sizes andlocales + This is a warning. + +Id +: `ProtoLayoutEdgeContentLayoutResponsive` +Summary +: ProtoLayout Material EdgeContentLayout should be used with responsivebehaviour to ensure the best behaviour across different screen sizes andlocales +Severity +: Warning +Category +: Correctness +Platform +: Android +Vendor +: Android Open Source Project +Identifier +: androidx.wear.protolayout +Feedback +: https://issuetracker.google.com/issues/new?component=1112273 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.wear.protolayout:protolayout](androidx_wear_protolayout_protolayout.md.html) +Since +: 1.2.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/wear/protolayout/protolayout-lint/src/main/java/androidx/wear/protolayout/lint/ResponsiveLayoutDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/wear/protolayout/protolayout-lint/src/test/java/PrimaryLayoutResponsiveDetectorTest.kt) +Copyright Year +: 2024 + +It is highly recommended to use the latest +setResponsiveInsetEnabled(true) when you're +using the ProtoLayout's EdgeContentLayout. + +This is will take care of all outer margins and inner padding to ensure +that content of +labels doesn't go off the screen (especially with different locales) and +that primary +label is placed in the consistent place. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.wear.protolayout:protolayout:1.3.0-beta01") + +// build.gradle +implementation 'androidx.wear.protolayout:protolayout:1.3.0-beta01' + +// build.gradle.kts with version catalogs: +implementation(libs.protolayout) + +# libs.versions.toml +[versions] +protolayout = "1.3.0-beta01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +protolayout = { + module = "androidx.wear.protolayout:protolayout", + version.ref = "protolayout" +} +``` + +1.3.0-beta01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +Use one of the following artifacts: +* `androidx.wear.protolayout:protolayout-expression:1.3.0-beta01` +* `androidx.wear.protolayout:protolayout-material3:1.3.0-beta01` +* `androidx.wear.protolayout:protolayout-material:1.3.0-beta01` + + +[Additional details about androidx.wear.protolayout:protolayout](androidx_wear_protolayout_protolayout.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ProtoLayoutEdgeContentLayoutResponsive") + fun method() { + Builder(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ProtoLayoutEdgeContentLayoutResponsive") + void method() { + new Builder(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ProtoLayoutEdgeContentLayoutResponsive + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ProtoLayoutEdgeContentLayoutResponsive" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ProtoLayoutEdgeContentLayoutResponsive' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ProtoLayoutEdgeContentLayoutResponsive ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ProtoLayoutMinSchema.md.html b/docs/checks/ProtoLayoutMinSchema.md.html new file mode 100644 index 00000000..9aab0208 --- /dev/null +++ b/docs/checks/ProtoLayoutMinSchema.md.html @@ -0,0 +1,240 @@ + +(#) ProtoLayout feature is not guaranteed to be available on the target device API + +!!! ERROR: ProtoLayout feature is not guaranteed to be available on the target device API + This is an error. + +Id +: `ProtoLayoutMinSchema` +Summary +: ProtoLayout feature is not guaranteed to be available on the target device API +Severity +: Error +Category +: Correctness +Platform +: Android +Vendor +: Android Open Source Project +Identifier +: androidx.wear.protolayout +Feedback +: https://issuetracker.google.com/issues/new?component=1112273 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.wear.protolayout:protolayout](androidx_wear_protolayout_protolayout.md.html) +Since +: 1.1.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/wear/protolayout/protolayout-lint/src/main/java/androidx/wear/protolayout/lint/ProtoLayoutMinSchemaDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/wear/protolayout/protolayout-lint/src/test/java/ProtoLayoutMinSchemaDetectorTest.kt) +Copyright Year +: 2023 + +Using features that are not supported by an older ProtoLayout +renderer/evaluator, can lead to unexpected rendering or invalid results +(for expressions). + +Each Wear OS platform version has a guaranteed minimum ProtoLayout +schema version. +On API 33, all consumers for ProtoLayout support at least Schema version +1.2 (major=1, minor=200). +On API 34, all consumers for ProtoLayout support at least Schema version +1.3 (major=1, minor=300). + +You can use those newer features through conditional Android API checks, +or by increasing the minSdk for your project. +You can also annotate your methods with @RequiresApi or +@RequiresSchemaAnnotation if you know they require the +corresponding version. +Note that @RequiresSchemaVersion annotation on classes are mostly +ignored (except for Builder classes). + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/Bar.kt:6:Error: This API is not guaranteed to be available on +the device (requires schema 1.200). [ProtoLayoutMinSchema] + private val fieldAssignment = withAnnotation.annotatedMethod() + -------------------------------- +src/foo/Bar.kt:12:Error: This API is not guaranteed to be available on +the device (requires schema 1.200). [ProtoLayoutMinSchema] + bar() + ----- +src/foo/Bar.kt:14:Error: This API is not guaranteed to be available on +the device (requires schema 1.200). [ProtoLayoutMinSchema] + withAnnotation.annotatedMethod() + -------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`src/foo/WithAnnotation.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package foo +import androidx.wear.protolayout.expression.RequiresSchemaVersion + +@RequiresSchemaVersion(major=1, minor=200) +class WithAnnotation { + fun unAnnotatedMethod(){} + + @RequiresSchemaVersion(major=1, minor=200) + fun annotatedMethod(){} + + @RequiresSchemaVersion(major=1, minor=200) + fun unreferencedMethod(){} + + companion object { + @RequiresSchemaVersion(major=1, minor=200) + const val ANNOTATED_CONST = 10 + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/foo/Bar.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package foo +import androidx.wear.protolayout.expression.RequiresSchemaVersion + +class Bar { + private val withAnnotation = WithAnnotation() + private val fieldAssignment = withAnnotation.annotatedMethod() + + @RequiresSchemaVersion(major=1, minor=200) + fun bar() {} + + fun baz() { + bar() + withAnnotation.unAnnotatedMethod() + withAnnotation.annotatedMethod() + //TODO: b/308552481 - This should fail + val b = withAnnotation.ANNOTATED_CONST + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/wear/protolayout/protolayout-lint/src/test/java/ProtoLayoutMinSchemaDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `ProtoLayoutMinSchemaDetector.calling V1_2 API requires SDK version check`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=1112273. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.wear.protolayout:protolayout:1.3.0-beta01") + +// build.gradle +implementation 'androidx.wear.protolayout:protolayout:1.3.0-beta01' + +// build.gradle.kts with version catalogs: +implementation(libs.protolayout) + +# libs.versions.toml +[versions] +protolayout = "1.3.0-beta01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +protolayout = { + module = "androidx.wear.protolayout:protolayout", + version.ref = "protolayout" +} +``` + +1.3.0-beta01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +Use one of the following artifacts: +* `androidx.wear.protolayout:protolayout-expression:1.3.0-beta01` +* `androidx.wear.protolayout:protolayout-material3:1.3.0-beta01` +* `androidx.wear.protolayout:protolayout-material:1.3.0-beta01` + + +[Additional details about androidx.wear.protolayout:protolayout](androidx_wear_protolayout_protolayout.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ProtoLayoutMinSchema") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ProtoLayoutMinSchema") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ProtoLayoutMinSchema + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ProtoLayoutMinSchema" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ProtoLayoutMinSchema' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ProtoLayoutMinSchema ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ProtoLayoutPrimaryLayoutResponsive.md.html b/docs/checks/ProtoLayoutPrimaryLayoutResponsive.md.html new file mode 100644 index 00000000..44fc26ed --- /dev/null +++ b/docs/checks/ProtoLayoutPrimaryLayoutResponsive.md.html @@ -0,0 +1,262 @@ + +(#) ProtoLayout Material PrimaryLayout should be used with responsive behaviourto ensure the best behaviour across different screen sizes and locales + +!!! WARNING: ProtoLayout Material PrimaryLayout should be used with responsive behaviourto ensure the best behaviour across different screen sizes and locales + This is a warning. + +Id +: `ProtoLayoutPrimaryLayoutResponsive` +Summary +: ProtoLayout Material PrimaryLayout should be used with responsive behaviourto ensure the best behaviour across different screen sizes and locales +Severity +: Warning +Category +: Correctness +Platform +: Android +Vendor +: Android Open Source Project +Identifier +: androidx.wear.protolayout +Feedback +: https://issuetracker.google.com/issues/new?component=1112273 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.wear.protolayout:protolayout](androidx_wear_protolayout_protolayout.md.html) +Since +: 1.2.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/wear/protolayout/protolayout-lint/src/main/java/androidx/wear/protolayout/lint/ResponsiveLayoutDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/wear/protolayout/protolayout-lint/src/test/java/PrimaryLayoutResponsiveDetectorTest.kt) +Copyright Year +: 2024 + +It is highly recommended to use the latest +setResponsiveInsetEnabled(true) when you're +using the ProtoLayout's PrimaryLayout. + +This is will take care of all inner padding to ensure that content of +labels and bottom +chip doesn't go off the screen (especially with different locales). + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/Bar.kt:4:Warning: PrimaryLayout used, but responsiveness isn't +set: Please call +setResponsiveContentInsetEnabled(true) for the best results across +different screen sizes. [ProtoLayoutPrimaryLayoutResponsive] +val layout = PrimaryLayout.Builder(null) + --------------------- +src/foo/Bar.kt:9:Warning: PrimaryLayout used, but responsiveness isn't +set: Please call +setResponsiveContentInsetEnabled(true) for the best results across +different screen sizes. [ProtoLayoutPrimaryLayoutResponsive] + val layout = PrimaryLayout.Builder(null) + --------------------- +src/foo/Bar.kt:12:Warning: PrimaryLayout used, but responsiveness isn't +set: Please call +setResponsiveContentInsetEnabled(true) for the best results across +different screen sizes. [ProtoLayoutPrimaryLayoutResponsive] + val layoutFalse = PrimaryLayout.Builder(null) + --------------------- +src/foo/Bar.kt:17:Warning: PrimaryLayout used, but responsiveness isn't +set: Please call +setResponsiveContentInsetEnabled(true) for the best results across +different screen sizes. [ProtoLayoutPrimaryLayoutResponsive] + val l = PrimaryLayout.Builder(null) + --------------------- +src/foo/Bar.kt:24:Warning: PrimaryLayout used, but responsiveness isn't +set: Please call +setResponsiveContentInsetEnabled(true) for the best results across +different screen sizes. [ProtoLayoutPrimaryLayoutResponsive] + PrimaryLayout.Builder().setResponsiveContentInsetEnabled(enabled) + --------------------- +src/foo/Bar.kt:32:Warning: PrimaryLayout used, but responsiveness isn't +set: Please call +setResponsiveContentInsetEnabled(true) for the best results across +different screen sizes. [ProtoLayoutPrimaryLayoutResponsive] + return PrimaryLayout.Builder().build() + --------------------- +src/foo/Bar.kt:36:Warning: PrimaryLayout used, but responsiveness isn't +set: Please call +setResponsiveContentInsetEnabled(true) for the best results across +different screen sizes. [ProtoLayoutPrimaryLayoutResponsive] + PrimaryLayout.Builder() + --------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/Bar.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package foo +import androidx.wear.protolayout.material.layouts.PrimaryLayout + +val layout = PrimaryLayout.Builder(null) + .setResponsiveContentInsetEnabled(false) + .build() + +class Bar { + val layout = PrimaryLayout.Builder(null) + .build() + + val layoutFalse = PrimaryLayout.Builder(null) + .setResponsiveContentInsetEnabled(false) + .build() + + fun buildFalse() { + val l = PrimaryLayout.Builder(null) + .setResponsiveContentInsetEnabled(false) + return l.build() + } + + fun update() { + val enabled = false + PrimaryLayout.Builder().setResponsiveContentInsetEnabled(enabled) + } + + fun build() { + update().build() + } + + fun build2() { + return PrimaryLayout.Builder().build() + } + + fun doubleFalse() { + PrimaryLayout.Builder() + .setResponsiveContentInsetEnabled(true) + .setResponsiveContentInsetEnabled(false) + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/wear/protolayout/protolayout-lint/src/test/java/PrimaryLayoutResponsiveDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `ResponsiveLayoutDetector.primaryLayout without responsiveness requires and fixes setter`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=1112273. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.wear.protolayout:protolayout:1.3.0-beta01") + +// build.gradle +implementation 'androidx.wear.protolayout:protolayout:1.3.0-beta01' + +// build.gradle.kts with version catalogs: +implementation(libs.protolayout) + +# libs.versions.toml +[versions] +protolayout = "1.3.0-beta01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +protolayout = { + module = "androidx.wear.protolayout:protolayout", + version.ref = "protolayout" +} +``` + +1.3.0-beta01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +Use one of the following artifacts: +* `androidx.wear.protolayout:protolayout-expression:1.3.0-beta01` +* `androidx.wear.protolayout:protolayout-material3:1.3.0-beta01` +* `androidx.wear.protolayout:protolayout-material:1.3.0-beta01` + + +[Additional details about androidx.wear.protolayout:protolayout](androidx_wear_protolayout_protolayout.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ProtoLayoutPrimaryLayoutResponsive") + fun method() { + Builder(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ProtoLayoutPrimaryLayoutResponsive") + void method() { + new Builder(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ProtoLayoutPrimaryLayoutResponsive + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ProtoLayoutPrimaryLayoutResponsive" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ProtoLayoutPrimaryLayoutResponsive' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ProtoLayoutPrimaryLayoutResponsive ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ProviderReadPermissionOnly.md.html b/docs/checks/ProviderReadPermissionOnly.md.html new file mode 100644 index 00000000..8ee0dc24 --- /dev/null +++ b/docs/checks/ProviderReadPermissionOnly.md.html @@ -0,0 +1,206 @@ + +(#) Provider with readPermission only and implemented write APIs + +!!! WARNING: Provider with readPermission only and implemented write APIs + This is a warning. + +Id +: `ProviderReadPermissionOnly` +Summary +: Provider with readPermission only and implemented write APIs +Severity +: Warning +Category +: Security +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.1.0 (July 2023) +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ProviderPermissionDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ProviderPermissionDetectorTest.kt) + +This check looks for Content Providers that only have the +`readPermission` attribute but implement write APIs. + +If `android:readPermission` is specified and both `android:permission` +and `android:writePermission` are omitted, other apps can access any +write operations that this provider exposes with no permission check. +For a quick fix, changing the existing `android:readPermission` to +`android:permission` will protect both read and write access with the +same permission. Alternatively, declaring a separate +`android:writePermission` can protect write access with a different +permission. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +AndroidManifest.xml:5:Warning: test.pkg.JavaTestContentProvider +implements {insert} write APIs but does not protect them with a +permission. Update the tag to use android:permission or +android:writePermission [ProviderReadPermissionOnly] + <provider android:name="test.pkg.JavaTestContentProvider" android:readPermission="android.permission.READ_DATA"/> + ---------------------- +AndroidManifest.xml:6:Warning: test.pkg.KotlinTestContentProvider +implements {insert} write APIs but does not protect them with a +permission. Update the tag to use android:permission or +android:writePermission [ProviderReadPermissionOnly] + <provider android:name="test.pkg.KotlinTestContentProvider" android:readPermission="android.permission.READ_DATA"/> + ---------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`AndroidManifest.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + package="test.pkg"> + <application> + <provider android:name="test.pkg.JavaTestContentProvider" android:readPermission="android.permission.READ_DATA"/> + <provider android:name="test.pkg.KotlinTestContentProvider" android:readPermission="android.permission.READ_DATA"/> + </application> +</manifest> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/JavaTestContentProvider.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; + +import android.content.ContentProvider; +import android.net.Uri; +import android.os.Bundle; + +public class JavaTestContentProvider extends ContentProvider { + @Override + public Uri insert(Uri uri, ContentValues values) { + return insert(uri, values, null); + } + + @Override + public int delete(Uri uri, String selection, String[] selectionArgs) { + throw new UnsupportedOperationException(""); + } + + @Override + public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { + return 0; + } + + private Uri insert(Uri uri, ContentValues values, Bundle extras) { + System.out.println(uri); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/KotlinTestContentProvider.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg + +import android.content.ContentProvider +import android.net.Uri + +class KotlinTestContentProvider : ContentProvider() { + override fun insert(uri: Uri, values: ContentValues?): Uri? = insert(uri, values, null) ?: null + + override fun delete(uri: Uri, selection: String?, selectionArgs: Array?): Int { + throw UnsupportedOperationException() + } + + override fun update( + uri: Uri, + values: ContentValues?, + selection: String?, + selectionArgs: Array? + ): Int = 0 + + private fun insert(uri: Uri, values: ContentValues?, extras: Bundle?): Int? { + println(uri) + return null + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ProviderPermissionDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ProviderReadPermissionOnly") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ProviderReadPermissionOnly") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ProviderReadPermissionOnly + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ProviderReadPermissionOnly" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ProviderReadPermissionOnly' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ProviderReadPermissionOnly ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ProvidesMustNotBeAbstract.md.html b/docs/checks/ProvidesMustNotBeAbstract.md.html new file mode 100644 index 00000000..055ba725 --- /dev/null +++ b/docs/checks/ProvidesMustNotBeAbstract.md.html @@ -0,0 +1,237 @@ + +(#) @Provides functions cannot be abstract + +!!! ERROR: @Provides functions cannot be abstract + This is an error. + +Id +: `ProvidesMustNotBeAbstract` +Summary +: @Provides functions cannot be abstract +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.5.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/DaggerIssuesDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/DaggerIssuesDetectorTest.kt) +Copyright Year +: 2021 + +@Provides functions cannot be abstract. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/MyQualifier.kt:25:Error: @Provides functions cannot be abstract +[ProvidesMustNotBeAbstract] + @Provides fun Int.bind(): Number = this@bind + -------------------------------------------- +src/foo/MyQualifier.kt:26:Error: @Provides functions cannot be abstract +[ProvidesMustNotBeAbstract] + @Provides fun Long.bind(): Number = this@bind + --------------------------------------------- +src/foo/MyQualifier.kt:27:Error: @Provides functions cannot be abstract +[ProvidesMustNotBeAbstract] + @Provides fun Double.bind(): Number = this@bind + ----------------------------------------------- +src/foo/MyQualifier.kt:28:Error: @Provides functions cannot be abstract +[ProvidesMustNotBeAbstract] + @Provides fun Float.bind(): Number = this@bind + ---------------------------------------------- +src/foo/MyQualifier.kt:29:Error: @Provides functions cannot be abstract +[ProvidesMustNotBeAbstract] + @Provides fun Short.bind(): Number = this@bind + ---------------------------------------------- +src/foo/MyQualifier.kt:30:Error: @Provides functions cannot be abstract +[ProvidesMustNotBeAbstract] + @Provides fun Byte.bind(): Number = this@bind + --------------------------------------------- +src/foo/MyQualifier.kt:31:Error: @Provides functions cannot be abstract +[ProvidesMustNotBeAbstract] + @Provides fun Char.bind(): Comparable<Char> = this@bind + ------------------------------------------------------- +src/foo/MyQualifier.kt:32:Error: @Provides functions cannot be abstract +[ProvidesMustNotBeAbstract] + @Provides fun String.bind(): Comparable<String> = this@bind + ----------------------------------------------------------- +src/foo/MyQualifier.kt:33:Error: @Provides functions cannot be abstract +[ProvidesMustNotBeAbstract] + @Provides fun @receiver:MyQualifier Boolean.bind(): Comparable<Boolean> = this@bind + ----------------------------------------------------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/MyQualifier.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package foo +import javax.inject.Qualifier +import dagger.Binds +import dagger.Provides +import dagger.Module + +@Qualifier +annotation class MyQualifier + +@Module +interface MyModule { + @Binds fun Int.bind(): Number + @Binds fun Long.bind(): Number + @Binds fun Double.bind(): Number + @Binds fun Float.bind(): Number + @Binds fun Short.bind(): Number + @Binds fun Byte.bind(): Number + @Binds fun Char.bind(): Comparable + @Binds fun String.bind(): Comparable + @Binds fun @receiver:MyQualifier Boolean.bind(): Comparable +} + +@Module +interface MyModule2 { + @Provides fun Int.bind(): Number = this@bind + @Provides fun Long.bind(): Number = this@bind + @Provides fun Double.bind(): Number = this@bind + @Provides fun Float.bind(): Number = this@bind + @Provides fun Short.bind(): Number = this@bind + @Provides fun Byte.bind(): Number = this@bind + @Provides fun Char.bind(): Comparable = this@bind + @Provides fun String.bind(): Comparable = this@bind + @Provides fun @receiver:MyQualifier Boolean.bind(): Comparable = this@bind +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/DaggerIssuesDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `DaggerIssuesDetector.bindings cannot be extension functions`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ProvidesMustNotBeAbstract") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ProvidesMustNotBeAbstract") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ProvidesMustNotBeAbstract + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ProvidesMustNotBeAbstract" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ProvidesMustNotBeAbstract' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ProvidesMustNotBeAbstract ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ProxyPassword.md.html b/docs/checks/ProxyPassword.md.html index c2c65442..358b71e1 100644 --- a/docs/checks/ProxyPassword.md.html +++ b/docs/checks/ProxyPassword.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.2.0 (September 2018) Affects : Property files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/PropertyFileDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/PropertyFileDetectorTest.kt) -Copyright Year -: 2014 Storing proxy server passwords in clear text is dangerous if this file is shared via version control. If this is deliberate or this is a truly @@ -40,17 +40,14 @@ gradle.properties:1:Warning: Storing passwords in clear text is risky; make sure this file is not shared or checked in via version control [ProxyPassword] - systemProp.http.proxyPassword=something --------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: `gradle.properties`: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ linenumbers +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~properties linenumbers systemProp.http.proxyPassword=something ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/checks/PublicKeyCredential.md.html b/docs/checks/PublicKeyCredential.md.html new file mode 100644 index 00000000..8c017217 --- /dev/null +++ b/docs/checks/PublicKeyCredential.md.html @@ -0,0 +1,138 @@ + +(#) Creating public key credential + +!!! WARNING: Creating public key credential + This is a warning. + +Id +: `PublicKeyCredential` +Summary +: Creating public key credential +Severity +: Warning +Category +: Correctness +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.4.0 (April 2024) +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/PublicKeyCredentialDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/PublicKeyCredentialDetectorTest.kt) + +Credential Manager API supports creating public key credential +(Passkeys) starting Android 9 or higher. Please check for the Android +version before calling the method. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/main/kotlin/test/pkg/Test.kt:7:Warning: PublicKeyCredential is only +supported from Android 9 (API level 28) and higher +[PublicKeyCredential] + val request = CreatePublicKeyCredentialRequest() + ---------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`build.gradle`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~groovy linenumbers +dependencies { + implementation 'androidx.credentials:credentials-play-services-auth:+' +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/main/kotlin/test/pkg/Test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg + +import androidx.credentials.CreatePublicKeyCredentialRequest + +class Test { + fun test() { + val request = CreatePublicKeyCredentialRequest() + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/PublicKeyCredentialDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection PublicKeyCredential + problematicStatement() + ``` + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("PublicKeyCredential") + fun method() { + CreatePublicKeyCredentialRequest(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("PublicKeyCredential") + void method() { + new CreatePublicKeyCredentialRequest(...); + } + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="PublicKeyCredential" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'PublicKeyCredential' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore PublicKeyCredential ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/PxUsage.md.html b/docs/checks/PxUsage.md.html index 79137396..10bbdd22 100644 --- a/docs/checks/PxUsage.md.html +++ b/docs/checks/PxUsage.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -51,11 +53,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/now_playing_after.xml:41:Warning: Avoid using "px" as units; use "dp" instead [PxUsage] - android:layout_width="2px" -------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/QueryAllPackagesPermission.md.html b/docs/checks/QueryAllPackagesPermission.md.html index fb3534ed..d1fe7fd6 100644 --- a/docs/checks/QueryAllPackagesPermission.md.html +++ b/docs/checks/QueryAllPackagesPermission.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 4.1.0 (October 2020) Affects : Manifest files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/PackageVisibilityDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/PackageVisibilityDetectorTest.kt) -Copyright Year -: 2020 If you need to query or interact with other installed apps, you should be using a `` declaration in your manifest. Using the @@ -45,14 +45,11 @@ used instead of QUERY_ALL_PACKAGES; see https://g.co/dev/packagevisibility for details [QueryAllPackagesPermission] - <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/><!-- ERROR --> ---------------------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `AndroidManifest.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -65,6 +62,41 @@ </manifest> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/test/pkg/MainActivity.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg + +import android.app.Activity +import android.content.Intent +import android.os.Bundle + +class MainActivity : Activity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + val context = applicationContext + val pm = context.packageManager + + pm.getInstalledPackages(0) // ERROR + pm.getInstalledApplications(0) // ERROR + + pm.queryBroadcastReceivers(Intent(), 0) // ERROR + pm.queryContentProviders("", 0, 0) // ERROR + pm.queryIntentServices(Intent(), 0) // ERROR + pm.queryIntentActivities(Intent(), 0) // ERROR + + Intent().resolveActivity(pm) // ERROR + Intent().resolveActivityInfo(pm, 0) // ERROR + + this.getInstalledPackages() // OK + this.resolveActivity() // OK + } + + private fun getInstalledPackages() = Unit + private fun resolveActivity() = Unit +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/PackageVisibilityDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/QueryPermissionsNeeded.md.html b/docs/checks/QueryPermissionsNeeded.md.html index 59a7aacb..731a6444 100644 --- a/docs/checks/QueryPermissionsNeeded.md.html +++ b/docs/checks/QueryPermissionsNeeded.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 4.1.0 (October 2020) Affects : Kotlin and Java files and manifest files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/PackageVisibilityDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/PackageVisibilityDetectorTest.kt) -Copyright Year -: 2020 Apps that target Android 11 cannot query or interact with other installed apps by default. If you need to query or interact with other @@ -49,67 +49,43 @@ src/test/pkg/MainActivity.kt:14:Warning: As of Android 11, this method no longer returns information about all apps; see https://g.co/dev/packagevisibility for details [QueryPermissionsNeeded] - pm.getInstalledPackages(0) // ERROR -------------------- - - src/test/pkg/MainActivity.kt:15:Warning: As of Android 11, this method no longer returns information about all apps; see https://g.co/dev/packagevisibility for details [QueryPermissionsNeeded] - pm.getInstalledApplications(0) // ERROR ------------------------ - - src/test/pkg/MainActivity.kt:17:Warning: Consider adding a declaration to your manifest when calling this method; see https://g.co/dev/packagevisibility for details [QueryPermissionsNeeded] - pm.queryBroadcastReceivers(Intent(), 0) // ERROR ----------------------- - - src/test/pkg/MainActivity.kt:18:Warning: Consider adding a declaration to your manifest when calling this method; see https://g.co/dev/packagevisibility for details [QueryPermissionsNeeded] - pm.queryContentProviders("", 0, 0) // ERROR --------------------- - - src/test/pkg/MainActivity.kt:19:Warning: Consider adding a declaration to your manifest when calling this method; see https://g.co/dev/packagevisibility for details [QueryPermissionsNeeded] - pm.queryIntentServices(Intent(), 0) // ERROR ------------------- - - src/test/pkg/MainActivity.kt:20:Warning: Consider adding a declaration to your manifest when calling this method; see https://g.co/dev/packagevisibility for details [QueryPermissionsNeeded] - pm.queryIntentActivities(Intent(), 0) // ERROR --------------------- - - src/test/pkg/MainActivity.kt:22:Warning: Consider adding a declaration to your manifest when calling this method; see https://g.co/dev/packagevisibility for details [QueryPermissionsNeeded] - Intent().resolveActivity(pm) // ERROR --------------- - - src/test/pkg/MainActivity.kt:23:Warning: Consider adding a declaration to your manifest when calling this method; see https://g.co/dev/packagevisibility for details [QueryPermissionsNeeded] - Intent().resolveActivityInfo(pm, 0) // ERROR ------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/Range.md.html b/docs/checks/Range.md.html index 425eab6d..f6bdf347 100644 --- a/docs/checks/Range.md.html +++ b/docs/checks/Range.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.1.0 (March 2018) Affects : Kotlin and Java files Editing @@ -26,10 +28,8 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/RangeDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/RangeDetectorTest.kt) -Copyright Year -: 2017 -Some parameters are required to in a particular numerical range; this +Some parameters are required to be in a particular numerical range; this check makes sure that arguments passed fall within the range. For arrays, Strings and collections this refers to the size or length. @@ -38,279 +38,156 @@ Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/RangeTest.java:32:Error: Expected length 5 (was 4) [Range] - printExact("1234"); // ERROR ------ - - src/test/pkg/RangeTest.java:34:Error: Expected length 5 (was 6) [Range] - printExact("123456"); // ERROR -------- - - src/test/pkg/RangeTest.java:36:Error: Expected length ≥ 5 (was 4) [Range] - printMin("1234"); // ERROR ------ - - src/test/pkg/RangeTest.java:43:Error: Expected length ≤ 8 (was 9) [Range] - printMax("123456789"); // ERROR ----------- - - src/test/pkg/RangeTest.java:45:Error: Expected length ≥ 4 (was 3) [Range] - printRange("123"); // ERROR ----- - - src/test/pkg/RangeTest.java:49:Error: Expected length ≤ 6 (was 7) [Range] - printRange("1234567"); // ERROR --------- - - src/test/pkg/RangeTest.java:53:Error: Expected size 5 (was 4) [Range] - printExact(new int[]{1, 2, 3, 4}); // ERROR --------------------- - - src/test/pkg/RangeTest.java:55:Error: Expected size 5 (was 6) [Range] - printExact(new int[]{1, 2, 3, 4, 5, 6}); // ERROR --------------------------- - - src/test/pkg/RangeTest.java:57:Error: Expected size ≥ 5 (was 4) [Range] - printMin(new int[]{1, 2, 3, 4}); // ERROR --------------------- - - src/test/pkg/RangeTest.java:65:Error: Expected size ≤ 8 (was 9) [Range] - printMax(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9}); // ERROR ------------------------------------ - - src/test/pkg/RangeTest.java:67:Error: Expected size ≥ 4 (was 3) [Range] - printRange(new int[] {1,2,3}); // ERROR ----------------- - - src/test/pkg/RangeTest.java:71:Error: Expected size ≤ 6 (was 7) [Range] - printRange(new int[] {1,2,3,4,5,6,7}); // ERROR ------------------------- - - src/test/pkg/RangeTest.java:74:Error: Expected size to be a multiple of 3 (was 4 and should be either 3 or 6) [Range] - printMultiple(new int[] {1,2,3,4}); // ERROR ------------------- - - src/test/pkg/RangeTest.java:75:Error: Expected size to be a multiple of 3 (was 5 and should be either 3 or 6) [Range] - printMultiple(new int[] {1,2,3,4,5}); // ERROR --------------------- - - src/test/pkg/RangeTest.java:77:Error: Expected size to be a multiple of 3 (was 7 and should be either 6 or 9) [Range] - printMultiple(new int[] {1,2,3,4,5,6,7}); // ERROR ------------------------- - - src/test/pkg/RangeTest.java:80:Error: Expected size ≥ 4 (was 3) [Range] - printMinMultiple(new int[]{1, 2, 3}); // ERROR ------------------ - - src/test/pkg/RangeTest.java:84:Error: Value must be ≥ 4 (was 3) [Range] - printAtLeast(3); // ERROR - - - src/test/pkg/RangeTest.java:91:Error: Value must be ≤ 7 (was 8) [Range] - printAtMost(8); // ERROR - - - src/test/pkg/RangeTest.java:93:Error: Value must be ≥ 4 (was 3) [Range] - printBetween(3); // ERROR - - - src/test/pkg/RangeTest.java:98:Error: Value must be ≤ 7 (was 8) [Range] - printBetween(8); // ERROR - - - src/test/pkg/RangeTest.java:102:Error: Value must be ≥ 2.5 (was 2.49) [Range] - printAtLeastInclusive(2.49f); // ERROR ----- - - src/test/pkg/RangeTest.java:106:Error: Value must be > 2.5 (was 2.49) [Range] - printAtLeastExclusive(2.49f); // ERROR ----- - - src/test/pkg/RangeTest.java:107:Error: Value must be > 2.5 (was 2.5) [Range] - printAtLeastExclusive(2.5f); // ERROR ---- - - src/test/pkg/RangeTest.java:113:Error: Value must be ≤ 7.0 (was 7.1) [Range] - printAtMostInclusive(7.1f); // ERROR ---- - - src/test/pkg/RangeTest.java:117:Error: Value must be < 7.0 (was 7.0) [Range] - printAtMostExclusive(7.0f); // ERROR ---- - - src/test/pkg/RangeTest.java:118:Error: Value must be < 7.0 (was 7.1) [Range] - printAtMostExclusive(7.1f); // ERROR ---- - - src/test/pkg/RangeTest.java:120:Error: Value must be ≥ 2.5 (was 2.4) [Range] - printBetweenFromInclusiveToInclusive(2.4f); // ERROR ---- - - src/test/pkg/RangeTest.java:124:Error: Value must be ≤ 5.0 (was 5.1) [Range] - printBetweenFromInclusiveToInclusive(5.1f); // ERROR ---- - - src/test/pkg/RangeTest.java:126:Error: Value must be > 2.5 (was 2.4) [Range] - printBetweenFromExclusiveToInclusive(2.4f); // ERROR ---- - - src/test/pkg/RangeTest.java:127:Error: Value must be > 2.5 (was 2.5) [Range] - printBetweenFromExclusiveToInclusive(2.5f); // ERROR ---- - - src/test/pkg/RangeTest.java:129:Error: Value must be ≤ 5.0 (was 5.1) [Range] - printBetweenFromExclusiveToInclusive(5.1f); // ERROR ---- - - src/test/pkg/RangeTest.java:131:Error: Value must be ≥ 2.5 (was 2.4) [Range] - printBetweenFromInclusiveToExclusive(2.4f); // ERROR ---- - - src/test/pkg/RangeTest.java:135:Error: Value must be < 5.0 (was 5.0) [Range] - printBetweenFromInclusiveToExclusive(5.0f); // ERROR ---- - - src/test/pkg/RangeTest.java:137:Error: Value must be > 2.5 (was 2.4) [Range] - printBetweenFromExclusiveToExclusive(2.4f); // ERROR ---- - - src/test/pkg/RangeTest.java:138:Error: Value must be > 2.5 (was 2.5) [Range] - printBetweenFromExclusiveToExclusive(2.5f); // ERROR ---- - - src/test/pkg/RangeTest.java:141:Error: Value must be < 5.0 (was 5.0) [Range] - printBetweenFromExclusiveToExclusive(5.0f); // ERROR ---- - - src/test/pkg/RangeTest.java:145:Error: Value must be ≥ 4 (was -7) [Range] - printBetween(-7); // ERROR -- - - src/test/pkg/RangeTest.java:146:Error: Value must be > 2.5 (was -10.0) [Range] - printAtLeastExclusive(-10.0f); // ERROR ------ - - src/test/pkg/RangeTest.java:156:Error: Value must be ≥ -1 (was -2) [Range] - printIndirect(-2); // ERROR -- - - src/test/pkg/RangeTest.java:157:Error: Value must be ≤ 42 (was 43) [Range] - printIndirect(43); // ERROR -- - - src/test/pkg/RangeTest.java:158:Error: Expected length 5 (was 7) [Range] - printIndirectSize("1234567"); // ERROR --------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/RawColor.md.html b/docs/checks/RawColor.md.html new file mode 100644 index 00000000..cb697a70 --- /dev/null +++ b/docs/checks/RawColor.md.html @@ -0,0 +1,151 @@ + +(#) Flags color that are not defined as resource + +!!! WARNING: Flags color that are not defined as resource + This is a warning. + +Id +: `RawColor` +Summary +: Flags color that are not defined as resource +Severity +: Warning +Category +: Correctness +Platform +: Android +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html) +Since +: 0.6.0 +Affects +: Resource files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/main/kotlin/com/vanniktech/lintrules/android/RawColorDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/RawColorDetectorTest.kt) + +Color value should all be defined as color resources. This has the +benefit that you can easily see all of your colors in one file. One +benefit is an easier addition to Dark Theme for instance. This check +will run on layouts as well as xml drawables. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +res/layout/layout.xml:2:Warning: Should be using a color resource +instead. [RawColor] + app:someCustomColor="#fff"/> + ---- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`res/layout/layout.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<TextView xmlns:app="http://schemas.android.com/apk/res-auto" + app:someCustomColor="#fff"/> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/RawColorDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `RawColorDetector.appCustomColor`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-android:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-android:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.android) + +# libs.versions.toml +[versions] +lint-rules-android = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-android = { + module = "com.vanniktech:lint-rules-android", + version.ref = "lint-rules-android" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute `tools:ignore="RawColor"` on the + problematic XML element (or one of its enclosing elements). You may + also need to add the following namespace declaration on the root + element in the XML file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="RawColor" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'RawColor' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore RawColor ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/RawDimen.md.html b/docs/checks/RawDimen.md.html new file mode 100644 index 00000000..99043034 --- /dev/null +++ b/docs/checks/RawDimen.md.html @@ -0,0 +1,151 @@ + +(#) Flags dimensions that are not defined as resource + +!!! WARNING: Flags dimensions that are not defined as resource + This is a warning. + +Id +: `RawDimen` +Summary +: Flags dimensions that are not defined as resource +Severity +: Warning +Category +: Correctness +Platform +: Android +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html) +Since +: 0.6.0 +Affects +: Resource files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/main/kotlin/com/vanniktech/lintrules/android/RawDimenDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/RawDimenDetectorTest.kt) + +Dimensions should all be defined as dimension resources. This has the +benefit that you can easily see all of your dimensions in one file. One +benefit is that when designers change the outline across the entire app +you only have to adjust it in one place. This check will run on layouts +as well as xml drawables. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +res/layout/ids.xml:1:Warning: Should be using a dimension resource +instead. [RawDimen] +<TextView xmlns:app="http://schemas.android.com/apk/res-auto" app:someCustomAttribute="16dp"/> + ---- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`res/layout/ids.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<TextView xmlns:app="http://schemas.android.com/apk/res-auto" app:someCustomAttribute="16dp"/> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/RawDimenDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `RawDimenDetector.appCustom`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-android:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-android:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.android) + +# libs.versions.toml +[versions] +lint-rules-android = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-android = { + module = "com.vanniktech:lint-rules-android", + version.ref = "lint-rules-android" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute `tools:ignore="RawDimen"` on the + problematic XML element (or one of its enclosing elements). You may + also need to add the following namespace declaration on the root + element in the XML file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="RawDimen" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'RawDimen' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore RawDimen ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/RawDispatchersUse.md.html b/docs/checks/RawDispatchersUse.md.html new file mode 100644 index 00000000..ac16686c --- /dev/null +++ b/docs/checks/RawDispatchersUse.md.html @@ -0,0 +1,211 @@ + +(#) Use SlackDispatchers + +!!! ERROR: Use SlackDispatchers + This is an error. + +Id +: `RawDispatchersUse` +Summary +: Use SlackDispatchers +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/RawDispatchersUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/RawDispatchersUsageDetectorTest.kt) +Copyright Year +: 2021 + +Direct use of `Dispatchers.*` APIs are discouraged as they are difficult +to test. Prefer using `SlackDispatchers`. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test/pkg/test.kt:6:Error: Use SlackDispatchers. [RawDispatchersUse] + Dispatchers.IO + -------------- +src/test/pkg/test.kt:7:Error: Use SlackDispatchers. [RawDispatchersUse] + Dispatchers.Default + ------------------- +src/test/pkg/test.kt:8:Error: Use SlackDispatchers. [RawDispatchersUse] + Dispatchers.Unconfined + ---------------------- +src/test/pkg/test.kt:9:Error: Use SlackDispatchers. [RawDispatchersUse] + Dispatchers.Main + ---------------- +src/test/pkg/test.kt:11:Error: Use SlackDispatchers. +[RawDispatchersUse] + Dispatchers::IO + --------------- +src/test/pkg/test.kt:12:Error: Use SlackDispatchers. +[RawDispatchersUse] + Dispatchers::Default + -------------------- +src/test/pkg/test.kt:13:Error: Use SlackDispatchers. +[RawDispatchersUse] + Dispatchers::Unconfined + ----------------------- +src/test/pkg/test.kt:14:Error: Use SlackDispatchers. +[RawDispatchersUse] + Dispatchers::Main + ----------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test/pkg/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg + +import kotlinx.coroutines.Dispatchers + +fun example() { + Dispatchers.IO + Dispatchers.Default + Dispatchers.Unconfined + Dispatchers.Main + Dispatchers.someExtension() + Dispatchers::IO + Dispatchers::Default + Dispatchers::Unconfined + Dispatchers::Main +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/RawDispatchersUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `RawDispatchersUsageDetector.simple`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("RawDispatchersUse") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("RawDispatchersUse") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection RawDispatchersUse + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="RawDispatchersUse" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'RawDispatchersUse' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore RawDispatchersUse ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/Recycle.md.html b/docs/checks/Recycle.md.html index 922a153e..112056a2 100644 --- a/docs/checks/Recycle.md.html +++ b/docs/checks/Recycle.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files Editing @@ -39,67 +41,40 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/RecycleTest.java:56:Warning: This TypedArray should be recycled after use with #recycle() [Recycle] - final TypedArray a = getContext().obtainStyledAttributes(attrs, ---------------------- - - src/test/pkg/RecycleTest.java:63:Warning: This TypedArray should be recycled after use with #recycle() [Recycle] - final TypedArray a = getContext().obtainStyledAttributes(new int[0]); ---------------------- - - src/test/pkg/RecycleTest.java:79:Warning: This VelocityTracker should be recycled after use with #recycle() [Recycle] - VelocityTracker tracker = VelocityTracker.obtain(); ------ - - src/test/pkg/RecycleTest.java:92:Warning: This MotionEvent should be recycled after use with #recycle() [Recycle] - MotionEvent event1 = MotionEvent.obtain(null); ------ - - src/test/pkg/RecycleTest.java:93:Warning: This MotionEvent should be recycled after use with #recycle() [Recycle] - MotionEvent event2 = MotionEvent.obtainNoHistory(null); --------------- - - src/test/pkg/RecycleTest.java:98:Warning: This MotionEvent should be recycled after use with #recycle() [Recycle] - MotionEvent event2 = MotionEvent.obtainNoHistory(null); // Not recycled --------------- - - src/test/pkg/RecycleTest.java:103:Warning: This MotionEvent should be recycled after use with #recycle() [Recycle] - MotionEvent event1 = MotionEvent.obtain(null); // Not recycled ------ - - src/test/pkg/RecycleTest.java:129:Warning: This Parcel should be recycled after use with #recycle() [Recycle] - Parcel myparcel = Parcel.obtain(); ------ - - src/test/pkg/RecycleTest.java:190:Warning: This TypedArray should be recycled after use with #recycle() [Recycle] - final TypedArray a = getContext().obtainStyledAttributes(attrs, // Not recycled ---------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/RecyclerView.md.html b/docs/checks/RecyclerView.md.html index 4e74f5c5..b4e17406 100644 --- a/docs/checks/RecyclerView.md.html +++ b/docs/checks/RecyclerView.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 2.0.0 (April 2016) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/RecyclerViewDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/RecyclerViewDetectorTest.kt) -Copyright Year -: 2015 `RecyclerView` will **not** call `onBindViewHolder` again when the position of the item changes in the data set unless the item itself is @@ -48,35 +48,23 @@ src/test/pkg/RecyclerViewTest.java:69:Error: Do not treat position as fixed; only use immediately and call holder.getAdapterPosition() to look it up later [RecyclerView] - public void onBindViewHolder(ViewHolder holder, int position) { ------------ - - src/test/pkg/RecyclerViewTest.java:82:Error: Do not treat position as fixed; only use immediately and call holder.getAdapterPosition() to look it up later [RecyclerView] - public void onBindViewHolder(ViewHolder holder, final int position) { ------------------ - - src/test/pkg/RecyclerViewTest.java:102:Error: Do not treat position as fixed; only use immediately and call holder.getAdapterPosition() to look it up later [RecyclerView] - public void onBindViewHolder(ViewHolder holder, final int position) { ------------------ - - src/test/pkg/RecyclerViewTest.java:111:Error: Do not treat position as fixed; only use immediately and call holder.getAdapterPosition() to look it up later [RecyclerView] - public void onBindViewHolder(ViewHolder holder, final int position, List<Object> payloads) { ------------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/RedactedInJavaUsage.md.html b/docs/checks/RedactedInJavaUsage.md.html new file mode 100644 index 00000000..0a67e485 --- /dev/null +++ b/docs/checks/RedactedInJavaUsage.md.html @@ -0,0 +1,239 @@ + +(#) @Redacted is only supported in Kotlin classes + +!!! ERROR: @Redacted is only supported in Kotlin classes + This is an error. + +Id +: `RedactedInJavaUsage` +Summary +: @Redacted is only supported in Kotlin classes +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/RedactedUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/RedactedUsageDetectorTest.kt) +Copyright Year +: 2021 + +@Redacted is only supported in Kotlin classes! + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test/pkg/RedactedClass.java:6:Error: @Redacted is only supported in +Kotlin classes! [RedactedInJavaUsage] +@Redacted +--------- +src/test/pkg/RedactedClass.java:8:Error: @Redacted is only supported in +Kotlin classes! [RedactedInJavaUsage] + @Redacted + --------- +src/test/pkg/RedactedClass.java:13:Error: @Redacted is only supported in +Kotlin classes! [RedactedInJavaUsage] + @Redacted + --------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`src/test/pkg/RedactedClass.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg + +import slack.annotations.Redacted +import slack.annotations.AnotherRedacted +import slack.annotations.AnotherAnnotation + +@Redacted +data class RedactedClass(val value: String) + +data class RedactedProps(@Redacted val value: String) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/RedactedClass.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; + +import slack.annotations.Redacted; +import slack.annotations.AnotherAnnotation; + +@Redacted +class RedactedClass { + @Redacted + int value; + @AnotherAnnotation + int value2; + + @Redacted + public int getValue() { + return value; + } + + @AnotherAnnotation + public int getValue2() { + return value2; + } + + @AnotherAnnotation + static class AnotherInner { + + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/AnotherRedactedClass.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; + +import slack.annotations.Redacted; +import slack.annotations.AnotherRedacted; + +@AnotherRedacted +class AnotherRedactedClass { + @AnotherRedacted + int value; + + @AnotherRedacted + public int getValue() { + return value; + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/RedactedUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `RedactedUsageDetector.smokeTest`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("RedactedInJavaUsage") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("RedactedInJavaUsage") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection RedactedInJavaUsage + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="RedactedInJavaUsage" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'RedactedInJavaUsage' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore RedactedInJavaUsage ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/RedundantBinds.md.html b/docs/checks/RedundantBinds.md.html new file mode 100644 index 00000000..df86e38b --- /dev/null +++ b/docs/checks/RedundantBinds.md.html @@ -0,0 +1,191 @@ + +(#) @Binds functions should return a different type + +!!! ERROR: @Binds functions should return a different type + This is an error. + +Id +: `RedundantBinds` +Summary +: @Binds functions should return a different type +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.5.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/DaggerIssuesDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/DaggerIssuesDetectorTest.kt) +Copyright Year +: 2021 + +@Binds functions should return a different type (including annotations) +than the input type. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/MyQualifier.kt:13:Error: @Binds functions should return a +different type [RedundantBinds] + @Binds fun invalidBind(real: Long): Long + ---------------------------------------- +src/foo/MyQualifier.kt:14:Error: @Binds functions should return a +different type [RedundantBinds] + @Binds fun invalidBind(real: Long): Long + ---------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/MyQualifier.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package foo +import javax.inject.Qualifier +import dagger.Binds +import dagger.Module + +@Qualifier +annotation class MyQualifier + +@Module +interface MyModule { + @MyQualifier @Binds fun validBind(real: Boolean): Boolean + @Binds fun validBind(@MyQualifier real: Boolean): Boolean + @Binds fun invalidBind(real: Long): Long + @Binds fun invalidBind(real: Long): Long +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/DaggerIssuesDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `DaggerIssuesDetector.redundant types`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("RedundantBinds") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("RedundantBinds") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection RedundantBinds + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="RedundantBinds" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'RedundantBinds' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore RedundantBinds ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/RedundantLabel.md.html b/docs/checks/RedundantLabel.md.html index 9288caf8..7041f8b7 100644 --- a/docs/checks/RedundantLabel.md.html +++ b/docs/checks/RedundantLabel.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.1.0 (January 2022) Affects : Manifest files Editing @@ -26,24 +28,22 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ManifestDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ManifestDetectorTest.kt) -Copyright Year -: 2011 When an activity does not have a label attribute, it will use the one from the application tag. Since the application has already specified the same label, the label on this activity can be omitted. +!!! Tip + This lint check has an associated quickfix available in the IDE. + (##) Example Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text AndroidManifest.xml:7:Warning: Redundant label can be removed [RedundantLabel] - <activity android:name=".MainActivity" android:label="@string/app_name"> -------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/RedundantNamespace.md.html b/docs/checks/RedundantNamespace.md.html index 791abdab..04215a6c 100644 --- a/docs/checks/RedundantNamespace.md.html +++ b/docs/checks/RedundantNamespace.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.4.0 (April 2019) Affects : Manifest files and resource files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/NamespaceDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/NamespaceDetectorTest.kt) -Copyright Year -: 2012 In Android XML documents, only specify the namespace on the root/document element. Namespace declarations elsewhere in the document @@ -43,11 +43,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/customview2.xml:8:Warning: This namespace declaration is redundant [RedundantNamespace] - xmlns:android="http://schemas.android.com/apk/res/android" ---------------------------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -62,7 +59,6 @@ android:orientation="vertical" > <foo.bar.Baz xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:tools="http://something/else" xmlns:unrelated="http://un/related" android:id="@+id/button1" android:layout_width="wrap_content" diff --git a/docs/checks/ReferenceType.md.html b/docs/checks/ReferenceType.md.html index 7700d7e2..65d358bc 100644 --- a/docs/checks/ReferenceType.md.html +++ b/docs/checks/ReferenceType.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -43,32 +45,20 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/values/refs.xml:3:Error: Unexpected resource reference type; expected value of type @string/ [ReferenceType] - <item name="invalid1" type="string">@layout/other</item> ------------- - - res/values/refs.xml:5:Error: Unexpected resource reference type; expected value of type @drawable/ [ReferenceType] - @layout/other ------------- - - res/values/refs.xml:10:Error: Unexpected resource reference type; expected value of type @string/ [ReferenceType] - <string name="invalid4">@layout/indirect</string> ---------------- - - res/values/refs.xml:15:Error: Unexpected resource reference type; expected value of type @color/ [ReferenceType] - <item name="drawableAsColor" type="color">@drawable/my_drawable</item> --------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/Registered.md.html b/docs/checks/Registered.md.html index f0e4a61e..998c1403 100644 --- a/docs/checks/Registered.md.html +++ b/docs/checks/Registered.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files Editing @@ -40,6 +42,52 @@ If your activity is simply a parent class intended to be subclassed by other "real" activities, make it an abstract class. +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test/pkg/MyActivity2.java:5:Warning: The +test.pkg.MyActivity2 is not registered in the manifest [Registered] +public class MyActivity2 extends Activity { + ----------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`src/test/pkg/MyActivity1.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; + +import android.app.Activity; + +public class MyActivity1 extends Activity { +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/MyActivity2.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; + +import android.app.Activity; + +public class MyActivity2 extends Activity { +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/AndroidManifest.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="test.pkg"> + <application> + <activity android:name=".MyActivity1" /> + </application> +</manifest> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/RegistrationDetectorTest.java) +for the unit tests for this check to see additional scenarios. + (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/RelativeOverlap.md.html b/docs/checks/RelativeOverlap.md.html index 061cf9d0..1ad2b0bb 100644 --- a/docs/checks/RelativeOverlap.md.html +++ b/docs/checks/RelativeOverlap.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 0.2.0 (October 2014) Affects : Resource files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/RelativeOverlapDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/RelativeOverlapDetectorTest.kt) -Copyright Year -: 2014 If relative layout has text or button items aligned to left and right sides they can overlap each other due to localized text expansion unless @@ -40,11 +40,8 @@ res/layout/relative_overlap.xml:16:Warning: @id/label2 can overlap @id/label1 if @string/label1_text, @string/label2_text grow due to localized text expansion [RelativeOverlap] - <TextView -------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/RememberInComposition.md.html b/docs/checks/RememberInComposition.md.html new file mode 100644 index 00000000..c2440b42 --- /dev/null +++ b/docs/checks/RememberInComposition.md.html @@ -0,0 +1,535 @@ + +(#) Calling a @RememberInComposition annotated declaration inside composition without using `remember` + +!!! ERROR: Calling a @RememberInComposition annotated declaration inside composition without using `remember` + This is an error. + +Id +: `RememberInComposition` +Summary +: Calling a @RememberInComposition annotated declaration inside composition without using `remember` +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: Jetpack Compose +Identifier +: androidx.compose.runtime +Feedback +: https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.runtime:runtime-android](androidx_compose_runtime_runtime-android.md.html) +Since +: 1.9.0-alpha01 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/runtime/runtime-lint/src/main/java/androidx/compose/runtime/lint/RememberInCompositionDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/runtime/runtime-lint/src/test/java/androidx/compose/runtime/lint/RememberInCompositionDetectorTest.kt) +Copyright Year +: 2025 + +APIs annotated with @RememberInComposition must not be called inside +composition. This can lead to correctness issues and / or performance +issues. Instead, use `remember` to cache the value across compositions, +or hoist this call outside of composition. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/androidx/compose/runtime/foo/{.kt:8:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + test() + ---- +src/androidx/compose/runtime/foo/{.kt:9:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + val foo = Foo() + --- +src/androidx/compose/runtime/foo/{.kt:10:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + val fooValue = foo.value + ----- +src/androidx/compose/runtime/foo/{.kt:11:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + bar.calculateValue() + -------------- +src/androidx/compose/runtime/foo/{.kt:12:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + val barValue = bar.value + ----- +src/androidx/compose/runtime/foo/{.kt:14:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + barImpl.calculateValue() + -------------- +src/androidx/compose/runtime/foo/{.kt:15:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + val barImplValue = barImpl.value + ----- +src/androidx/compose/runtime/foo/{.kt:19:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + test() + ---- +src/androidx/compose/runtime/foo/{.kt:20:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + val foo = Foo() + --- +src/androidx/compose/runtime/foo/{.kt:21:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + val fooValue = foo.value + ----- +src/androidx/compose/runtime/foo/{.kt:22:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + bar.calculateValue() + -------------- +src/androidx/compose/runtime/foo/{.kt:23:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + val barValue = bar.value + ----- +src/androidx/compose/runtime/foo/{.kt:25:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + barImpl.calculateValue() + -------------- +src/androidx/compose/runtime/foo/{.kt:26:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + val barImplValue = barImpl.value + ----- +src/androidx/compose/runtime/foo/{.kt:30:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + test() + ---- +src/androidx/compose/runtime/foo/{.kt:31:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + val foo = Foo() + --- +src/androidx/compose/runtime/foo/{.kt:32:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + val fooValue = foo.value + ----- +src/androidx/compose/runtime/foo/{.kt:33:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + bar.calculateValue() + -------------- +src/androidx/compose/runtime/foo/{.kt:34:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + val barValue = bar.value + ----- +src/androidx/compose/runtime/foo/{.kt:36:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + barImpl.calculateValue() + -------------- +src/androidx/compose/runtime/foo/{.kt:37:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + val barImplValue = barImpl.value + ----- +src/androidx/compose/runtime/foo/{.kt:46:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + test() + ---- +src/androidx/compose/runtime/foo/{.kt:47:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + val foo = Foo() + --- +src/androidx/compose/runtime/foo/{.kt:48:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + val fooValue = foo.value + ----- +src/androidx/compose/runtime/foo/{.kt:49:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + bar.calculateValue() + -------------- +src/androidx/compose/runtime/foo/{.kt:50:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + val barValue = bar.value + ----- +src/androidx/compose/runtime/foo/{.kt:52:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + barImpl.calculateValue() + -------------- +src/androidx/compose/runtime/foo/{.kt:53:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + val barImplValue = barImpl.value + ----- +src/androidx/compose/runtime/foo/{.kt:56:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + test() + ---- +src/androidx/compose/runtime/foo/{.kt:57:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + val foo = Foo() + --- +src/androidx/compose/runtime/foo/{.kt:58:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + val fooValue = foo.value + ----- +src/androidx/compose/runtime/foo/{.kt:59:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + bar.calculateValue() + -------------- +src/androidx/compose/runtime/foo/{.kt:60:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + val barValue = bar.value + ----- +src/androidx/compose/runtime/foo/{.kt:62:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + barImpl.calculateValue() + -------------- +src/androidx/compose/runtime/foo/{.kt:63:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + val barImplValue = barImpl.value + ----- +src/androidx/compose/runtime/foo/{.kt:69:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + test() + ---- +src/androidx/compose/runtime/foo/{.kt:70:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + val foo = Foo() + --- +src/androidx/compose/runtime/foo/{.kt:71:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + val fooValue = foo.value + ----- +src/androidx/compose/runtime/foo/{.kt:72:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + bar.calculateValue() + -------------- +src/androidx/compose/runtime/foo/{.kt:73:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + val barValue = bar.value + ----- +src/androidx/compose/runtime/foo/{.kt:75:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + barImpl.calculateValue() + -------------- +src/androidx/compose/runtime/foo/{.kt:76:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + val barImplValue = barImpl.value + ----- +src/androidx/compose/runtime/foo/{.kt:80:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + test() + ---- +src/androidx/compose/runtime/foo/{.kt:81:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + val foo = Foo() + --- +src/androidx/compose/runtime/foo/{.kt:82:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + val fooValue = foo.value + ----- +src/androidx/compose/runtime/foo/{.kt:83:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + bar.calculateValue() + -------------- +src/androidx/compose/runtime/foo/{.kt:84:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + val barValue = bar.value + ----- +src/androidx/compose/runtime/foo/{.kt:86:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + barImpl.calculateValue() + -------------- +src/androidx/compose/runtime/foo/{.kt:87:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + val barImplValue = barImpl.value + ----- +src/androidx/compose/runtime/foo/{.kt:94:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + val foo = Foo() + --- +src/androidx/compose/runtime/foo/{.kt:95:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + val fooValue = foo.value + ----- +src/androidx/compose/runtime/foo/{.kt:96:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + val barValue = bar.value + ----- +src/androidx/compose/runtime/foo/{.kt:98:Error: Calling a +@RememberInComposition annotated declaration inside composition without +using remember [RememberInComposition] + val barImplValue = barImpl.value + ----- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/androidx/compose/runtime/foo/{.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package androidx.compose.runtime.foo + +import androidx.compose.runtime.* + +@Composable +fun Test(bar: Bar) { + test() + val foo = Foo() + val fooValue = foo.value + bar.calculateValue() + val barValue = bar.value + val barImpl = BarImpl() + barImpl.calculateValue() + val barImplValue = barImpl.value +} + +val lambda = @Composable { bar: Bar -> + test() + val foo = Foo() + val fooValue = foo.value + bar.calculateValue() + val barValue = bar.value + val barImpl = BarImpl() + barImpl.calculateValue() + val barImplValue = barImpl.value +} + +val lambda2: @Composable (bar: Bar) -> Unit = { bar -> + test() + val foo = Foo() + val fooValue = foo.value + bar.calculateValue() + val barValue = bar.value + val barImpl = BarImpl() + barImpl.calculateValue() + val barImplValue = barImpl.value +} + +@Composable +fun LambdaParameter(content: @Composable () -> Unit) {} + +@Composable +fun Test2(bar: Bar) { + LambdaParameter(content = { + test() + val foo = Foo() + val fooValue = foo.value + bar.calculateValue() + val barValue = bar.value + val barImpl = BarImpl() + barImpl.calculateValue() + val barImplValue = barImpl.value + }) + LambdaParameter { + test() + val foo = Foo() + val fooValue = foo.value + bar.calculateValue() + val barValue = bar.value + val barImpl = BarImpl() + barImpl.calculateValue() + val barImplValue = barImpl.value + } +} + +fun test3(bar: Bar) { + val localLambda1 = @Composable { + test() + val foo = Foo() + val fooValue = foo.value + bar.calculateValue() + val barValue = bar.value + val barImpl = BarImpl() + barImpl.calculateValue() + val barImplValue = barImpl.value + } + + val localLambda2: @Composable () -> Unit = { + test() + val foo = Foo() + val fooValue = foo.value + bar.calculateValue() + val barValue = bar.value + val barImpl = BarImpl() + barImpl.calculateValue() + val barImplValue = barImpl.value + } +} + +@Composable +fun Test4(bar: Bar) { + val localObject = object { + val foo = Foo() + val fooValue = foo.value + val barValue = bar.value + val barImpl = BarImpl() + val barImplValue = barImpl.value + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/runtime/runtime-lint/src/test/java/androidx/compose/runtime/lint/RememberInCompositionDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `RememberInCompositionDetector.notRemembered`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=612128. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.runtime:runtime-android:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.runtime:runtime-android:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.runtime.android) + +# libs.versions.toml +[versions] +runtime-android = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +runtime-android = { + module = "androidx.compose.runtime:runtime-android", + version.ref = "runtime-android" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.runtime:runtime-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.runtime:runtime-android](androidx_compose_runtime_runtime-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("RememberInComposition") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("RememberInComposition") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection RememberInComposition + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="RememberInComposition" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'RememberInComposition' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore RememberInComposition ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/RememberReturnType.md.html b/docs/checks/RememberReturnType.md.html index 86755060..4a18f84a 100644 --- a/docs/checks/RememberReturnType.md.html +++ b/docs/checks/RememberReturnType.md.html @@ -20,6 +20,14 @@ : androidx.compose.runtime Feedback : https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.runtime:runtime-android](androidx_compose_runtime_runtime-android.md.html) +Since +: 1.5.0 Affects : Kotlin and Java files and test sources Editing @@ -46,74 +54,84 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/androidx/compose/runtime/foo/FooState.kt:14:Error: remember calls must not return Unit [RememberReturnType] - remember { -------- - - src/androidx/compose/runtime/foo/FooState.kt:17:Error: remember calls must not return Unit [RememberReturnType] - val unit = remember { -------- - - -src/androidx/compose/runtime/foo/FooState.kt:25:Error: remember calls +src/androidx/compose/runtime/foo/FooState.kt:21:Error: remember calls must not return Unit [RememberReturnType] - - remember(number) { + remember(unitLambda) -------- - - +src/androidx/compose/runtime/foo/FooState.kt:22:Error: remember calls +must not return Unit [RememberReturnType] + val unit2 = remember(unitLambda) + -------- src/androidx/compose/runtime/foo/FooState.kt:28:Error: remember calls must not return Unit [RememberReturnType] - + remember(number) { + -------- +src/androidx/compose/runtime/foo/FooState.kt:31:Error: remember calls +must not return Unit [RememberReturnType] val unit = remember(number) { -------- - - +src/androidx/compose/runtime/foo/FooState.kt:35:Error: remember calls +must not return Unit [RememberReturnType] + remember(number, unitLambda) + -------- src/androidx/compose/runtime/foo/FooState.kt:36:Error: remember calls must not return Unit [RememberReturnType] - + val unit2 = remember(number, unitLambda) + -------- +src/androidx/compose/runtime/foo/FooState.kt:42:Error: remember calls +must not return Unit [RememberReturnType] remember(number1, number2) { -------- - - -src/androidx/compose/runtime/foo/FooState.kt:40:Error: remember calls +src/androidx/compose/runtime/foo/FooState.kt:46:Error: remember calls must not return Unit [RememberReturnType] - val unit = remember(number1, number2) { -------- - - -src/androidx/compose/runtime/foo/FooState.kt:49:Error: remember calls +src/androidx/compose/runtime/foo/FooState.kt:51:Error: remember calls +must not return Unit [RememberReturnType] + remember(number1, number2, unitLambda) + -------- +src/androidx/compose/runtime/foo/FooState.kt:52:Error: remember calls +must not return Unit [RememberReturnType] + val unit2 = remember(number1, number2, unitLambda) + -------- +src/androidx/compose/runtime/foo/FooState.kt:58:Error: remember calls must not return Unit [RememberReturnType] - remember(number1, number2, number3) { -------- - - -src/androidx/compose/runtime/foo/FooState.kt:54:Error: remember calls +src/androidx/compose/runtime/foo/FooState.kt:63:Error: remember calls must not return Unit [RememberReturnType] - val unit = remember(number1, number2, number3) { -------- - - -src/androidx/compose/runtime/foo/FooState.kt:64:Error: remember calls +src/androidx/compose/runtime/foo/FooState.kt:69:Error: remember calls +must not return Unit [RememberReturnType] + remember(number1, number2, number3, unitLambda) + -------- +src/androidx/compose/runtime/foo/FooState.kt:70:Error: remember calls +must not return Unit [RememberReturnType] + val unit2 = remember(number1, number2, number3, unitLambda) + -------- +src/androidx/compose/runtime/foo/FooState.kt:76:Error: remember calls must not return Unit [RememberReturnType] - remember(number1, number2, number3, flag) { -------- - - -src/androidx/compose/runtime/foo/FooState.kt:69:Error: remember calls +src/androidx/compose/runtime/foo/FooState.kt:81:Error: remember calls must not return Unit [RememberReturnType] - val unit = remember(number1, number2, number3, flag) { -------- - - +src/androidx/compose/runtime/foo/FooState.kt:87:Error: remember calls +must not return Unit [RememberReturnType] + remember(number1, number2, number3, flag, calculation = unitLambda) + -------- +src/androidx/compose/runtime/foo/FooState.kt:88:Error: remember calls +must not return Unit [RememberReturnType] + val unit2 = remember(number1, number2, number3, flag, calculation = unitLambda) + -------- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -138,6 +156,9 @@ val unit = remember { state.update(5) } + val unitLambda: () -> Unit = {} + remember(unitLambda) + val unit2 = remember(unitLambda) } @Composable @@ -149,6 +170,9 @@ val unit = remember(number) { state.update(number) } + val unitLambda: () -> Unit = {} + remember(number, unitLambda) + val unit2 = remember(number, unitLambda) } @Composable @@ -162,6 +186,9 @@ state.update(number1) state.update(number2) } + val unitLambda: () -> Unit = {} + remember(number1, number2, unitLambda) + val unit2 = remember(number1, number2, unitLambda) } @Composable @@ -177,6 +204,9 @@ state.update(number2) state.update(number3) } + val unitLambda: () -> Unit = {} + remember(number1, number2, number3, unitLambda) + val unit2 = remember(number1, number2, number3, unitLambda) } @Composable @@ -192,6 +222,9 @@ state.update(number2) state.update(number3) } + val unitLambda: () -> Unit = {} + remember(number1, number2, number3, flag, calculation = unitLambda) + val unit2 = remember(number1, number2, number3, flag, calculation = unitLambda) } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -204,6 +237,44 @@ To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=612128. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.runtime:runtime-android:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.runtime:runtime-android:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.runtime.android) + +# libs.versions.toml +[versions] +runtime-android = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +runtime-android = { + module = "androidx.compose.runtime:runtime-android", + version.ref = "runtime-android" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.runtime:runtime-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.runtime:runtime-android](androidx_compose_runtime_runtime-android.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/RememberSaveableSaverParameter.md.html b/docs/checks/RememberSaveableSaverParameter.md.html index 23c6563f..d9e65eb2 100644 --- a/docs/checks/RememberSaveableSaverParameter.md.html +++ b/docs/checks/RememberSaveableSaverParameter.md.html @@ -20,6 +20,14 @@ : androidx.compose.runtime.saveable Feedback : https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.runtime:runtime-saveable-android](androidx_compose_runtime_runtime-saveable-android.md.html) +Since +: 1.5.0 Affects : Kotlin and Java files and test sources Editing @@ -46,60 +54,36 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/Foo.kt:15:Error: Passing Saver instance to vararg inputs [RememberSaveableSaverParameter] - val foo = rememberSaveable(FooSaver) { Foo() } -------- - - src/test/Foo.kt:16:Error: Passing Saver instance to vararg inputs [RememberSaveableSaverParameter] - val mutableStateFoo = rememberSaveable(FooSaver) { mutableStateOf(Foo()) } -------- - - src/test/Foo.kt:17:Error: Passing Saver instance to vararg inputs [RememberSaveableSaverParameter] - val foo2 = rememberSaveable(FooSaver2()) { Foo() } ----------- - - src/test/Foo.kt:18:Error: Passing Saver instance to vararg inputs [RememberSaveableSaverParameter] - val mutableStateFoo2 = rememberSaveable(FooSaver2()) { mutableStateOf(Foo()) } ----------- - - src/test/Foo.kt:19:Error: Passing Saver instance to vararg inputs [RememberSaveableSaverParameter] - val foo3 = rememberSaveable(fooSaver3) { Foo() } --------- - - src/test/Foo.kt:20:Error: Passing Saver instance to vararg inputs [RememberSaveableSaverParameter] - val mutableStateFoo3 = rememberSaveable(fooSaver3) { mutableStateOf(Foo()) } --------- - - src/test/Foo.kt:21:Error: Passing Saver instance to vararg inputs [RememberSaveableSaverParameter] - val foo4 = rememberSaveable(fooSaver4) { Foo() } --------- - - src/test/Foo.kt:22:Error: Passing Saver instance to vararg inputs [RememberSaveableSaverParameter] - val mutableStateFoo4 = rememberSaveable(fooSaver4) { mutableStateOf(Foo()) } --------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -139,6 +123,44 @@ To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=612128. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.runtime:runtime-saveable-android:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.runtime:runtime-saveable-android:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.runtime.saveable.android) + +# libs.versions.toml +[versions] +runtime-saveable-android = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +runtime-saveable-android = { + module = "androidx.compose.runtime:runtime-saveable-android", + version.ref = "runtime-saveable-android" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.runtime:runtime-saveable-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.runtime:runtime-saveable-android](androidx_compose_runtime_runtime-saveable-android.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/RemoteViewLayout.md.html b/docs/checks/RemoteViewLayout.md.html index 982e9bb3..ac7770d7 100644 --- a/docs/checks/RemoteViewLayout.md.html +++ b/docs/checks/RemoteViewLayout.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 4.2.0 (May 2021) Affects : Kotlin and Java files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/RemoteViewDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/RemoteViewDetectorTest.kt) -Copyright Year -: 2020 In a `RemoteView`, only some layouts and views are allowed. @@ -40,14 +40,11 @@ src/test/pkg/test.kt:5:Error: @layout/test includes views not allowed in a RemoteView: CheckBox, DatePicker, RadioButton, RadioGroup, Switch, androidx.appcompat.widget.AppCompatTextView [RemoteViewLayout] - val remoteView = RemoteViews(packageName, R.layout.test) --------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `src/test/pkg/test.kt`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers @@ -59,15 +56,45 @@ } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/layout/test.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<merge> + <Button /> + <AdapterViewFlipper /> + <FrameLayout /> + <GridLayout /> + <GridView /> + <LinearLayout /> + <ListView /> + <RelativeLayout /> + <StackView /> + <ViewFlipper /> + <AnalogClock /> + <Button /> + <Chronometer /> + <ImageButton /> + <ImageView /> + <ProgressBar /> + <TextClock /> + <TextView /> + <DatePicker /> + <CheckBox /> + <Switch /> + <RadioButton /> + <RadioGroup /> + <androidx.appcompat.widget.AppCompatTextView /> +</merge> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`test.pkg`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text linenumbers +@layout/test +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/RemoteViewDetectorTest.kt) for the unit tests for this check to see additional scenarios. -The above example was automatically extracted from the first unit test -found for this lint check, `RemoteViewDetector.testBasic`. -To report a problem with this extracted sample, visit -https://issuetracker.google.com/issues/new?component=192708. - (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/RemoveWorkManagerInitializer.md.html b/docs/checks/RemoveWorkManagerInitializer.md.html index c759c54c..8a88eb28 100644 --- a/docs/checks/RemoveWorkManagerInitializer.md.html +++ b/docs/checks/RemoveWorkManagerInitializer.md.html @@ -1,7 +1,7 @@ -(#) Remove androidx.work.WorkManagerInitializer from your AndroidManifest.xml when using on-demand initialization. +(#) Remove androidx.work.WorkManagerInitializer from your AndroidManifest.xml when using on-demand initialization -!!! ERROR: Remove androidx.work.WorkManagerInitializer from your AndroidManifest.xml when using on-demand initialization. +!!! ERROR: Remove androidx.work.WorkManagerInitializer from your AndroidManifest.xml when using on-demand initialization This is an error, and is also enforced at build time when supported by the build system. For Android this means it will run during release builds. @@ -9,7 +9,7 @@ Id : `RemoveWorkManagerInitializer` Summary -: Remove androidx.work.WorkManagerInitializer from your AndroidManifest.xml when using on-demand initialization. +: Remove androidx.work.WorkManagerInitializer from your AndroidManifest.xml when using on-demand initialization Severity : Fatal Category @@ -22,6 +22,14 @@ : androidx.work Feedback : https://issuetracker.google.com/issues/new?component=409906 +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.7+ +Artifact +: [androidx.work:work-runtime](androidx_work_work-runtime.md.html) +Since +: 2.3.0 Affects : Kotlin and Java files and manifest files Editing @@ -43,44 +51,83 @@ Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -AndroidManifest.xml:8:Error: Remove androidx.work.WorkManagerInitializer +AndroidManifest.xml:4:Error: Remove androidx.work.WorkManagerInitializer from your AndroidManifest.xml when using on-demand initialization. [RemoveWorkManagerInitializer] - - <meta-data - ^ - - + <application /> + --------------- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `AndroidManifest.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.example"> - <application> - <provider - android:name="androidx.startup.InitializationProvider" - android:authorities="com.example.workmanager-init"> - <meta-data - android:name="androidx.work.WorkManagerInitializer" - android:value="@string/androidx_startup" /> - </provider> - </application> + <application /> </manifest> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`com/example/App.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package com.example + +import android.app.Application +import androidx.work.Configuration + +class App: Application(), Configuration.Provider { + override fun onCreate() { + + } + + override fun getWorkManagerConfiguration(): Configuration = TODO() +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/work/work-lint/src/test/java/androidx/work/lint/RemoveWorkManagerInitializerDetectorTest.kt) for the unit tests for this check to see additional scenarios. The above example was automatically extracted from the first unit test -found for this lint check, `RemoveWorkManagerInitializerDetector.failWhenManifestHasDefaultInitializer`. +found for this lint check, `RemoveWorkManagerInitializerDetector.failWhenUsingDefaultManifestMergeStrategy`. To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=409906. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.work:work-runtime:2.10.1") + +// build.gradle +implementation 'androidx.work:work-runtime:2.10.1' + +// build.gradle.kts with version catalogs: +implementation(libs.work.runtime) + +# libs.versions.toml +[versions] +work-runtime = "2.10.1" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +work-runtime = { + module = "androidx.work:work-runtime", + version.ref = "work-runtime" +} +``` + +2.10.1 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.work:work-runtime](androidx_work_work-runtime.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/RepeatOnLifecycleWrongUsage-2.md.html b/docs/checks/RepeatOnLifecycleWrongUsage-2.md.html new file mode 100644 index 00000000..999c151a --- /dev/null +++ b/docs/checks/RepeatOnLifecycleWrongUsage-2.md.html @@ -0,0 +1,155 @@ + +(#) Wrong usage of repeatOnLifecycle + +!!! ERROR: Wrong usage of repeatOnLifecycle + This is an error. + +Id +: `RepeatOnLifecycleWrongUsage` +Summary +: Wrong usage of repeatOnLifecycle +Severity +: Error +Category +: Correctness +Platform +: Android +Vendor +: Android Open Source Project +Identifier +: androidx.lifecycle +Feedback +: https://issuetracker.google.com/issues/new?component=413132 +Min +: Lint 7.0 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [androidx.lifecycle:lifecycle-runtime-ktx](androidx_lifecycle_lifecycle-runtime-ktx.md.html) +Since +: 2.4.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/lifecycle/lifecycle-runtime-lint/src/main/java/androidx/lifecycle/lint/RepeatOnLifecycleDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/lifecycle/lifecycle-runtime-lint/src/test/java/androidx/lifecycle/runtime/lint/RepeatOnLifecycleDetectorTest.kt) +Copyright Year +: 2021 + +The repeatOnLifecycle APIs should be used when the View is created, + that is in the `onCreate` lifecycle method for Activities, or +`onViewCreated` in case you're using Fragments. + +(##) Repackaged + +This lint check appears to have been packaged in other artifacts as +well. Issue id's must be unique, so you cannot combine these libraries. +Also defined in: +* RepeatOnLifecycleWrongUsage: Wrong usage of repeatOnLifecycle (this issue) +* [RepeatOnLifecycleWrongUsage from androidx.lifecycle:lifecycle-runtime-android:2.9.0-rc01](RepeatOnLifecycleWrongUsage.md.html) +* [RepeatOnLifecycleWrongUsage from androidx.lifecycle:lifecycle-runtime-ktx:2.8.0-alpha01](RepeatOnLifecycleWrongUsage-2.md.html) + + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.0-alpha01") + +// build.gradle +implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.8.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.lifecycle.runtime.ktx) + +# libs.versions.toml +[versions] +lifecycle-runtime-ktx = "2.8.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lifecycle-runtime-ktx = { + module = "androidx.lifecycle:lifecycle-runtime-ktx", + version.ref = "lifecycle-runtime-ktx" +} +``` + +2.8.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.lifecycle:lifecycle-runtime-ktx](androidx_lifecycle_lifecycle-runtime-ktx.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("RepeatOnLifecycleWrongUsage") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("RepeatOnLifecycleWrongUsage") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection RepeatOnLifecycleWrongUsage + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="RepeatOnLifecycleWrongUsage" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'RepeatOnLifecycleWrongUsage' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore RepeatOnLifecycleWrongUsage ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/RepeatOnLifecycleWrongUsage.md.html b/docs/checks/RepeatOnLifecycleWrongUsage.md.html index c05dc9af..11d3725f 100644 --- a/docs/checks/RepeatOnLifecycleWrongUsage.md.html +++ b/docs/checks/RepeatOnLifecycleWrongUsage.md.html @@ -1,13 +1,13 @@ -(#) Wrong usage of repeatOnLifecycle. +(#) Wrong usage of repeatOnLifecycle -!!! ERROR: Wrong usage of repeatOnLifecycle. +!!! ERROR: Wrong usage of repeatOnLifecycle This is an error. Id : `RepeatOnLifecycleWrongUsage` Summary -: Wrong usage of repeatOnLifecycle. +: Wrong usage of repeatOnLifecycle Severity : Error Category @@ -20,19 +20,73 @@ : androidx.lifecycle Feedback : https://issuetracker.google.com/issues/new?component=413132 +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.7+ +Artifact +: [androidx.lifecycle:lifecycle-runtime-android](androidx_lifecycle_lifecycle-runtime-android.md.html) +Since +: 2.4.0 Affects : Kotlin and Java files Editing : This check runs on the fly in the IDE editor Implementation -: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/lifecycle/lifecycle-runtime-ktx-lint/src/main/java/androidx/lifecycle/lint/RepeatOnLifecycleDetector.kt) +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/lifecycle/lifecycle-runtime-lint/src/main/java/androidx/lifecycle/lint/RepeatOnLifecycleDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/lifecycle/lifecycle-runtime-lint/src/test/java/androidx/lifecycle/runtime/lint/RepeatOnLifecycleDetectorTest.kt) Copyright Year : 2021 -The repeatOnLifecycle APIs should be used when the View is created, +The repeatOnLifecycle APIs should be used when the View is created, that is in the `onCreate` lifecycle method for Activities, or `onViewCreated` in case you're using Fragments. +(##) Repackaged + +This lint check appears to have been packaged in other artifacts as +well. Issue id's must be unique, so you cannot combine these libraries. +Also defined in: +* RepeatOnLifecycleWrongUsage: Wrong usage of repeatOnLifecycle (this issue) +* [RepeatOnLifecycleWrongUsage from androidx.lifecycle:lifecycle-runtime-android:2.9.0-rc01](RepeatOnLifecycleWrongUsage.md.html) +* [RepeatOnLifecycleWrongUsage from androidx.lifecycle:lifecycle-runtime-ktx:2.8.0-alpha01](RepeatOnLifecycleWrongUsage-2.md.html) + + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.lifecycle:lifecycle-runtime-android:2.9.0-rc01") + +// build.gradle +implementation 'androidx.lifecycle:lifecycle-runtime-android:2.9.0-rc01' + +// build.gradle.kts with version catalogs: +implementation(libs.lifecycle.runtime.android) + +# libs.versions.toml +[versions] +lifecycle-runtime-android = "2.9.0-rc01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lifecycle-runtime-android = { + module = "androidx.lifecycle:lifecycle-runtime-android", + version.ref = "lifecycle-runtime-android" +} +``` + +2.9.0-rc01 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.lifecycle:lifecycle-runtime-android](androidx_lifecycle_lifecycle-runtime-android.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/ReportShortcutUsage.md.html b/docs/checks/ReportShortcutUsage.md.html new file mode 100644 index 00000000..362b9996 --- /dev/null +++ b/docs/checks/ReportShortcutUsage.md.html @@ -0,0 +1,118 @@ + +(#) Report shortcut usage + +!!! Tip: Report shortcut usage + Advice from this check is just a hint; it's a "weak" warning. + +Id +: `ReportShortcutUsage` +Summary +: Report shortcut usage +Severity +: Hint +Category +: Usability +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.1.0 (July 2023) +Affects +: Kotlin and Java files +Editing +: This check can *not* run live in the IDE editor +See +: https://developer.android.com/develop/ui/views/launch/shortcuts/managing-shortcuts +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ShortcutUsageDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ShortcutUsageDetectorTest.kt) + +Reporting shortcut usage is important to improving the ranking of +shortcuts. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test/pkg/TestDocumentationExample.java:16:Hint: Calling this method +indicates use of dynamic shortcuts, but there are no calls to methods +that track shortcut usage, such as pushDynamicShortcut or +reportShortcutUsed. Calling these methods is recommended, as they track +shortcut usage and allow launchers to adjust which shortcuts appear +based on activation history. Please see +https://developer.android.com/develop/ui/views/launch/shortcuts/managing-shortcuts#track-usage +[ReportShortcutUsage] + ShortcutManagerCompat.setDynamicShortcuts(context, shortcuts); + ------------------------------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test/pkg/TestDocumentationExample.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; + +import android.app.Activity; +import android.content.Context; +import androidx.core.content.pm.ShortcutManagerCompat; +import androidx.core.content.pm.ShortcutInfoCompat; +import java.util.ArrayList; + +@SuppressWarnings("unused") +public class TestDocumentationExample extends Activity { + @Override + protected void onCreate(Bundle savedInstanceState) { + ShortcutInfoCompat shortuctInfoCompat = new ShortcutInfoCompat.Builder(context, "id").build(); + ArrayList shortcuts = new ArrayList(); + shortcuts.add(shortcutInfoCompat); + ShortcutManagerCompat.setDynamicShortcuts(context, shortcuts); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ShortcutUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ReportShortcutUsage" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ReportShortcutUsage' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ReportShortcutUsage ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/RequiredSize.md.html b/docs/checks/RequiredSize.md.html index 317a92ed..e8b29e72 100644 --- a/docs/checks/RequiredSize.md.html +++ b/docs/checks/RequiredSize.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files and resource files Editing @@ -44,25 +46,16 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/size.xml:13:Error: The required layout_height attribute is missing [RequiredSize] - <RadioButton ----------- - - res/layout/size.xml:18:Error: The required layout_width attribute is missing [RequiredSize] - <EditText -------- - - res/layout/size.xml:23:Error: The required layout_width and layout_height attributes are missing [RequiredSize] - <EditText -------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/RequiresFeature.md.html b/docs/checks/RequiresFeature.md.html index 55383dd5..b55fcde2 100644 --- a/docs/checks/RequiresFeature.md.html +++ b/docs/checks/RequiresFeature.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.2.0 (September 2018) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/RequiresFeatureDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/RequiresFeatureDetectorTest.kt) -Copyright Year -: 2018 Some APIs require optional features to be present. This check makes sure that calls to these APIs are surrounded by a check which enforces this. @@ -39,78 +39,51 @@ src/test/pkg/CheckFeatures.java:10:Warning: someMethod should only be called if the feature some.name is present; to check call test.framework.pkg.FeatureChecker#hasFeature [RequiresFeature] - api.someMethod(); // 1 - ERROR ---------------- - - src/test/pkg/CheckFeatures.java:12:Warning: someMethod should only be called if the feature some.name is present; to check call test.framework.pkg.FeatureChecker#hasFeature [RequiresFeature] - api.someMethod(); // 2 - ERROR ---------------- - - src/test/pkg/CheckFeatures.java:33:Warning: someMethod should only be called if the feature some.name is present; to check call test.framework.pkg.FeatureChecker#hasFeature [RequiresFeature] - api.someMethod(); // 6 - ERROR - wrong name ---------------- - - src/test/pkg/CheckFeatures.java:39:Warning: someMethod should only be called if the feature some.name is present; to check call test.framework.pkg.FeatureChecker#hasFeature [RequiresFeature] - api.someMethod(); // 7 - ERROR - inverted logic ---------------- - - src/test/pkg/CheckFeatures.java:52:Warning: someMethod should only be called if the feature some.name is present; to check call test.framework.pkg.FeatureChecker#hasFeature [RequiresFeature] - return FeatureChecker.hasFeature("wrong.name") && api.someMethod(); // 10 - ERROR ---------------- - - src/test/pkg/CheckFeatures.java:56:Warning: someMethod should only be called if the feature some.name is present; to check call test.framework.pkg.FeatureChecker#hasFeature [RequiresFeature] - return FeatureChecker.hasFeature("wrong.name") || api.someMethod(); // 11 - ERROR ---------------- - - src/test/pkg/CheckFeatures.java:70:Warning: someMethod should only be called if the feature some.name is present; to check call test.framework.pkg.FeatureChecker#hasFeature [RequiresFeature] - api.someMethod(); // 13 - ERROR: inverted logic in earl exit ---------------- - - src/test/pkg/CheckFeatures.java:92:Warning: someMethod should only be called if the feature some.name is present; to check call test.framework.pkg.FeatureChecker#hasFeature [RequiresFeature] - api.someMethod(); // 16 - ERROR ---------------- - - src/test/pkg/CheckFeatures.java:99:Warning: someMethod should only be called if the feature some.name is present; to check call test.framework.pkg.FeatureChecker#hasFeature [RequiresFeature] - api.someMethod(); // 17 - ERROR ---------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `src/test/pkg/CheckFeatures.java`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers @@ -218,6 +191,72 @@ } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/test/pkg/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg + +import test.framework.pkg.FeatureChecker + +fun testLambdas() { + val api = SomeApi() + api.applyIfHasFeatureX { + someMethod() // OK - checked in lambda + } + api.applyIfHasFeatureY { + someMethod() // ERROR - not checked in lambda + } +} + +inline fun T.applyIfHasFeatureX(block: T.() -> Unit): T { + if (FeatureChecker.hasFeature("some.name")) { + block() + } + return this +} + +inline fun T.applyIfHasFeatureY(block: T.() -> Unit): T { + if (FeatureChecker.hasFeature("some.other.feature")) { + block() + } + return this +} + +fun testPropertySyntax() { + val api = SomeOtherApi() + if (api.supportsFeatureX) { + SomeApi().someMethod() // OK - checked via utility method accessed via property syntax + } +} + +class SomeOtherApi { + val supportsFeatureX get() = FeatureChecker.hasFeature("some.name") +} + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/framework/pkg/FeatureChecker.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.framework.pkg; + +@SuppressWarnings({"ClassNameDiffersFromFileName", "MethodMayBeStatic"}) +public class FeatureChecker { + public static boolean hasFeature(String name) { return true; } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/SomeApi.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; + +import androidx.annotation.RequiresFeature; + +@SuppressWarnings({"ClassNameDiffersFromFileName", "MethodMayBeStatic"}) +public class SomeApi { + @RequiresFeature(name = "some.name", enforcement = "test.framework.pkg.FeatureChecker#hasFeature") + public boolean someMethod() { return true; } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/RequiresFeatureDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/RequiresWindowSdk.md.html b/docs/checks/RequiresWindowSdk.md.html new file mode 100644 index 00000000..1888cf55 --- /dev/null +++ b/docs/checks/RequiresWindowSdk.md.html @@ -0,0 +1,147 @@ + +(#) API requires a `WindowSdkExtensions.extensionVersion` check + +!!! ERROR: API requires a `WindowSdkExtensions.extensionVersion` check + This is an error. + +Id +: `RequiresWindowSdk` +Summary +: API requires a `WindowSdkExtensions.extensionVersion` check +Severity +: Error +Category +: Correctness +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.10.0 (May 2025) +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/WindowExtensionsDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/WindowExtensionsDetectorTest.kt) + +Some methods in the window library require explicit checks of the +`extensionVersion` level: +```kotlin +if (WindowSdkExtensions.getInstance().extensionVersion >= n) { + val supportedPostures = windowInfoTracker.supportedPostures + ... +``` +This lint check looks for scenarios where you're calling these methods +without checking the extension version level, or annotating the calling +method with a sufficient `@RequiresWindowSdkExtension` annotation. + +(This lint check does not tackle more advanced ways of version checks, +such as extracting the checks into utility methods or constants. Use a +direct `if` check as shown above.) + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test/pkg/test.kt:12:Error: Field requires window SDK extension level +6: `androidx.window.layout.WindowInfoTracker#getSupportedPostures` +[RequiresWindowSdk] + val supportedPostures = windowInfoTracker.supportedPostures // ERROR 1 + ----------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test/pkg/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +@file:Suppress("unused", "UnusedVariable", "ControlFlowWithEmptyBody") + +package test.pkg + +import android.content.Context +import androidx.window.RequiresWindowSdkExtension +import androidx.window.WindowSdkExtensions +import androidx.window.layout.WindowInfoTracker + +fun testPositive(context: Context) { + val windowInfoTracker = WindowInfoTracker.getOrCreate(context) + val supportedPostures = windowInfoTracker.supportedPostures // ERROR 1 + +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/WindowExtensionsDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("RequiresWindowSdk") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("RequiresWindowSdk") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection RequiresWindowSdk + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="RequiresWindowSdk" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'RequiresWindowSdk' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore RequiresWindowSdk ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ResAuto.md.html b/docs/checks/ResAuto.md.html index 35eef754..8e91a4a0 100644 --- a/docs/checks/ResAuto.md.html +++ b/docs/checks/ResAuto.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Manifest files and resource files Editing @@ -46,49 +48,34 @@ Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -res/layout/customview.xml:5:Error: In Gradle projects, always use -http://schemas.android.com/apk/res-auto for custom attributes [ResAuto] - - xmlns:foo="http://schemas.android.com/apk/res/foo" - -------------------------------------- - - +res/layout/namespace5.xml:3:Error: Suspicious namespace: Did you mean +http://schemas.android.com/apk/res-auto? [ResAuto] + xmlns:app="http://schemas.android.com/apk/auto-res/" + ---------------------------------------- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: -`res/layout/customview.xml`: +`res/layout/namespace5.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers -<?xml version="1.0" encoding="utf-8"?> -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" +<androidx.gridlayout.widget.GridLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" - xmlns:other="http://schemas.foo.bar.com/other" - xmlns:foo="http://schemas.android.com/apk/res/foo" - android:id="@+id/newlinear" + xmlns:app="http://schemas.android.com/apk/auto-res/" android:layout_width="match_parent" android:layout_height="match_parent" - android:orientation="vertical" > - - <foo.bar.Baz - android:id="@+id/button1" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="Button1" - foo:misc="Custom attribute" - tools:ignore="HardcodedText" > - </foo.bar.Baz> + app:columnCount="1" + tools:context=".MainActivity" > - <!-- Wrong namespace uri prefix: Don't warn --> - <foo.bar.Baz + <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="Button1" - other:misc="Custom attribute" - tools:ignore="HardcodedText" > - </foo.bar.Baz> + app:layout_column="0" + app:layout_gravity="center" + app:layout_row="0" + android:text="Button" /> -</LinearLayout> +</androidx.gridlayout.widget.GridLayout> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can also visit the @@ -96,7 +83,7 @@ for the unit tests for this check to see additional scenarios. The above example was automatically extracted from the first unit test -found for this lint check, `NamespaceDetector.testGradle`. +found for this lint check, `NamespaceDetector.testWrongResAutoUrl`. To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=192708. diff --git a/docs/checks/ReservedSystemPermission.md.html b/docs/checks/ReservedSystemPermission.md.html index c51c9cba..7a3f347f 100644 --- a/docs/checks/ReservedSystemPermission.md.html +++ b/docs/checks/ReservedSystemPermission.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.4.0 (January 2023) Affects : Manifest files Editing @@ -26,14 +28,15 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/PermissionErrorDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/PermissionErrorDetectorTest.kt) -Copyright Year -: 2022 This check looks for custom permission declarations whose names are -reserved values for system or Android SDK permissions. +reserved values for system or Android SDK permissions, or begin with the +reserved string `android.` Please double check the permission name you have supplied. Attempting to -redeclare a system or Android SDK permission will be ignored. +redeclare a system or Android SDK permission will be ignored. Using the +prefix `android.` is a violation of the Android Compatibility Definition +Document. (##) Example @@ -41,11 +44,12 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text AndroidManifest.xml:4:Error: android.permission.BIND_APPWIDGET is a reserved permission [ReservedSystemPermission] - <permission android:name="android.permission.BIND_APPWIDGET" /> --------------------------------- - - +AndroidManifest.xml:5:Error: android.permission.FOOBAR is using the +reserved system prefix android. [ReservedSystemPermission] + <permission android:name="android.permission.FOOBAR" /> + ------------------------- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -56,6 +60,7 @@ xmlns:tools="http://schemas.android.com/tools" package="com.example.helloworld"> <permission android:name="android.permission.BIND_APPWIDGET" /> + <permission android:name="android.permission.FOOBAR" /> <application> <service android:permission="android.permission.BIND_APPWIDGET" /> </application> diff --git a/docs/checks/ResourceAsColor.md.html b/docs/checks/ResourceAsColor.md.html index b9f88c93..9cbf570c 100644 --- a/docs/checks/ResourceAsColor.md.html +++ b/docs/checks/ResourceAsColor.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.1.0 (March 2018) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ResourceTypeDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ResourceTypeDetectorTest.kt) -Copyright Year -: 2017 Methods that take a color in the form of an integer should be passed an RGB triple, not the actual color resource id. You must call @@ -44,46 +44,31 @@ src/test/pkg/WrongColor.java:9:Error: Should pass resolved color instead of resource id here: getResources().getColor(R.color.blue) [ResourceAsColor] - paint2.setColor(R.color.blue); ------------ - - src/test/pkg/WrongColor.java:11:Error: Should pass resolved color instead of resource id here: getResources().getColor(R.color.red) [ResourceAsColor] - textView.setTextColor(R.color.red); ----------- - - src/test/pkg/WrongColor.java:12:Error: Should pass resolved color instead of resource id here: getResources().getColor(android.R.color.black) [ResourceAsColor] - textView.setTextColor(android.R.color.black); --------------------- - - src/test/pkg/WrongColor.java:13:Error: Should pass resolved color instead of resource id here: getResources().getColor(R.color.green) [ResourceAsColor] - textView.setTextColor(foo > 0 ? R.color.green : R.color.blue); ------------- - - src/test/pkg/WrongColor.java:21:Error: Should pass resolved color instead of resource id here: getResources().getColor(R.color.blue) [ResourceAsColor] - foo2(R.color.blue); ------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `src/test/pkg/WrongColor.java`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers @@ -118,6 +103,11 @@ } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`test.pkg`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text linenumbers +@color/blue +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ResourceTypeDetectorTest.kt) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/ResourceCycle.md.html b/docs/checks/ResourceCycle.md.html index fb44961d..2035a0dc 100644 --- a/docs/checks/ResourceCycle.md.html +++ b/docs/checks/ResourceCycle.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -40,11 +42,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/values/styles.xml:9:Error: Style DetailsPage_EditorialBuyButton should not extend itself [ResourceCycle] - <style name="DetailsPage_EditorialBuyButton" parent="@style/DetailsPage_EditorialBuyButton" /> ---------------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/ResourceName.md.html b/docs/checks/ResourceName.md.html index 6804bbb2..846e87bf 100644 --- a/docs/checks/ResourceName.md.html +++ b/docs/checks/ResourceName.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Binary resource files and resource files Editing @@ -36,6 +38,53 @@ don't accidentally combine resources from different libraries, since they all end up in the same shared app namespace. +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/main/res/layout/activity_main.xml:2:Error: Resource named +'activity_main' does not start with the project's resource prefix +'unit_test_prefix_'; rename to 'unit_test_prefix_activity_main' ? +[ResourceName] +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + ------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`build.gradle`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~groovy linenumbers +apply plugin: 'com.android.library' + +android { + resourcePrefix 'unit_test_prefix_' +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/main/res/layout/activity_main.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" > +</LinearLayout> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/main/res/layout/unit_test_prefix_ok.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" > +</LinearLayout> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ResourcePrefixDetectorTest.java) +for the unit tests for this check to see additional scenarios. + (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/ResourceType.md.html b/docs/checks/ResourceType.md.html index 03d6ea5e..041b4b64 100644 --- a/docs/checks/ResourceType.md.html +++ b/docs/checks/ResourceType.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.1.0 (March 2018) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ResourceTypeDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ResourceTypeDetectorTest.kt) -Copyright Year -: 2017 Ensures that resource id's passed to APIs are of the right type; for example, calling `Resources.getColor(R.string.name)` is wrong. @@ -37,11 +37,8 @@ Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test.kt:9:Error: Expected resource of type string [ResourceType] - setLabels(iconId) // bug: should have passed descId. Both are ints but of wrong type. ------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/ResourcesGetColorCall.md.html b/docs/checks/ResourcesGetColorCall.md.html new file mode 100644 index 00000000..bc6c615a --- /dev/null +++ b/docs/checks/ResourcesGetColorCall.md.html @@ -0,0 +1,174 @@ + +(#) Marks usage of deprecated getColor() on Resources + +!!! WARNING: Marks usage of deprecated getColor() on Resources + This is a warning. + +Id +: `ResourcesGetColorCall` +Summary +: Marks usage of deprecated getColor() on Resources +Severity +: Warning +Category +: Correctness: Messages +Platform +: Any +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html) +Since +: 0.6.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/main/kotlin/com/vanniktech/lintrules/android/AndroidDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/AndroidDetectorTest.kt) + +Instead of getColor(), ContextCompat or the method with the Theme +Overload should be used instead. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/Example.java:6:Warning: Calling deprecated getColor +[ResourcesGetColorCall] + resources.getColor(0); + -------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/Example.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package foo; +import android.content.res.Resources; +class Example { + public void foo() { + Resources resources = null; + resources.getColor(0); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/AndroidDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `AndroidDetector.callingGetColor`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-android:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-android:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.android) + +# libs.versions.toml +[versions] +lint-rules-android = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-android = { + module = "com.vanniktech:lint-rules-android", + version.ref = "lint-rules-android" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ResourcesGetColorCall") + fun method() { + getColor(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ResourcesGetColorCall") + void method() { + getColor(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ResourcesGetColorCall + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ResourcesGetColorCall" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ResourcesGetColorCall' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ResourcesGetColorCall ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ResourcesGetColorStateListCall.md.html b/docs/checks/ResourcesGetColorStateListCall.md.html new file mode 100644 index 00000000..a18dc522 --- /dev/null +++ b/docs/checks/ResourcesGetColorStateListCall.md.html @@ -0,0 +1,174 @@ + +(#) Marks usage of deprecated getColorStateList() on Resources + +!!! WARNING: Marks usage of deprecated getColorStateList() on Resources + This is a warning. + +Id +: `ResourcesGetColorStateListCall` +Summary +: Marks usage of deprecated getColorStateList() on Resources +Severity +: Warning +Category +: Correctness: Messages +Platform +: Any +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html) +Since +: 0.6.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/main/kotlin/com/vanniktech/lintrules/android/AndroidDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/AndroidDetectorTest.kt) + +Instead of getColorStateList(), ContextCompat or the method with the +Theme Overload should be used instead. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/Example.java:6:Warning: Calling deprecated getColorStateList +[ResourcesGetColorStateListCall] + resources.getColorStateList(0); + ----------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/Example.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package foo; +import android.content.res.Resources; +class Example { + public void foo() { + Resources resources = null; + resources.getColorStateList(0); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/AndroidDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `AndroidDetector.callingGetColorStateList`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-android:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-android:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.android) + +# libs.versions.toml +[versions] +lint-rules-android = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-android = { + module = "com.vanniktech:lint-rules-android", + version.ref = "lint-rules-android" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ResourcesGetColorStateListCall") + fun method() { + getColor(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ResourcesGetColorStateListCall") + void method() { + getColor(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ResourcesGetColorStateListCall + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ResourcesGetColorStateListCall" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ResourcesGetColorStateListCall' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ResourcesGetColorStateListCall ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ResourcesGetDrawableCall.md.html b/docs/checks/ResourcesGetDrawableCall.md.html new file mode 100644 index 00000000..9c0157cc --- /dev/null +++ b/docs/checks/ResourcesGetDrawableCall.md.html @@ -0,0 +1,174 @@ + +(#) Marks usage of deprecated getDrawable() on Resources + +!!! WARNING: Marks usage of deprecated getDrawable() on Resources + This is a warning. + +Id +: `ResourcesGetDrawableCall` +Summary +: Marks usage of deprecated getDrawable() on Resources +Severity +: Warning +Category +: Correctness: Messages +Platform +: Any +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html) +Since +: 0.6.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/main/kotlin/com/vanniktech/lintrules/android/AndroidDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/AndroidDetectorTest.kt) + +Instead of getDrawable(), ContextCompat or the method with the Theme +Overload should be used instead. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/Example.java:6:Warning: Calling deprecated getDrawable +[ResourcesGetDrawableCall] + resources.getDrawable(0); + ----------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/Example.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package foo; +import android.content.res.Resources; +class Example { + public void foo() { + Resources resources = null; + resources.getDrawable(0); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/AndroidDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `AndroidDetector.callingGetDrawable`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-android:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-android:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.android) + +# libs.versions.toml +[versions] +lint-rules-android = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-android = { + module = "com.vanniktech:lint-rules-android", + version.ref = "lint-rules-android" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ResourcesGetDrawableCall") + fun method() { + getColor(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ResourcesGetDrawableCall") + void method() { + getColor(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ResourcesGetDrawableCall + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ResourcesGetDrawableCall" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ResourcesGetDrawableCall' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ResourcesGetDrawableCall ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/RestrictCallsTo.md.html b/docs/checks/RestrictCallsTo.md.html new file mode 100644 index 00000000..0d355e4d --- /dev/null +++ b/docs/checks/RestrictCallsTo.md.html @@ -0,0 +1,246 @@ + +(#) Methods annotated with @RestrictedCallsTo should only be called from the specified scope + +!!! ERROR: Methods annotated with @RestrictedCallsTo should only be called from the specified scope + This is an error. + +Id +: `RestrictCallsTo` +Summary +: Methods annotated with @RestrictedCallsTo should only be called from the specified scope +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/RestrictCallsToDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/RestrictCallsToDetectorTest.kt) +Copyright Year +: 2021 + +This method is intended to only be called from the specified scope +despite it being public. This could be due to its use in an interface or +similar. Overrides are still ok. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/DifferentFile.kt:8:Error: Methods annotated with +@RestrictedCallsTo should only be called from the specified scope. +[RestrictCallsTo] + api.annotatedExample() + ---------------------- +src/foo/DifferentFile.kt:15:Error: Methods annotated with +@RestrictedCallsTo should only be called from the specified scope. +[RestrictCallsTo] + annotatedExample() + ------------------ +src/foo/DifferentFile.kt:26:Error: Methods annotated with +@RestrictedCallsTo should only be called from the specified scope. +[RestrictCallsTo] + MyApiImpl().annotatedExample() + ------------------------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`src/foo/MyApi.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package foo + +import slack.lint.annotations.RestrictCallsTo +import slack.lint.annotations.RestrictCallsTo.Companion.FILE + +interface MyApi { + fun example() + + @RestrictCallsTo(FILE) + fun annotatedExample() +} + +class SameFile { + fun doStuffWith(api: MyApi) { + // This is ok + api.example() + api.annotatedExample() + } +} + +class MyApiImpl : MyApi { + override fun example() { + annotatedExample() + } + + // Note this is not annotated, ensures we check up the hierarchy + override fun annotatedExample() { + println("Hello") + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/foo/DifferentFile.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package foo + +class DifferentFile { + fun doStuffWith(api: MyApi) { + // This is ok + api.example() + // This is not + api.annotatedExample() + } +} + +class MyApiImpl2 : MyApi { + override fun example() { + // Not ok + annotatedExample() + } + + // Still ok + override fun annotatedExample() { + println("Hello") + } + + fun backdoor() { + // Backdoors don't work either! This isn't annotated on the impl but we check the + // original overridden type. + MyApiImpl().annotatedExample() + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/RestrictCallsToDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `RestrictCallsToDetector.smokeTest`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("RestrictCallsTo") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("RestrictCallsTo") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection RestrictCallsTo + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="RestrictCallsTo" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'RestrictCallsTo' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore RestrictCallsTo ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/RestrictedApi.md.html b/docs/checks/RestrictedApi.md.html index 2c4ab3ed..f92c7f33 100644 --- a/docs/checks/RestrictedApi.md.html +++ b/docs/checks/RestrictedApi.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.1.0 (March 2018) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/RestrictToDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/RestrictToDetectorTest.kt) -Copyright Year -: 2017 This API has been flagged with a restriction that has not been met. @@ -46,18 +46,12 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/RestrictToSubclassTest.java:26:Error: Class1.onSomething can only be called from subclasses [RestrictedApi] - cls.onSomething(); // ERROR: Not from subclass ----------- - - src/test/pkg/RestrictToSubclassTest.java:27:Error: Class1.counter can only be accessed from subclasses [RestrictedApi] - int counter = cls.counter; // ERROR: Not from subclass ------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -100,11 +94,6 @@ [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/RestrictToDetectorTest.kt) for the unit tests for this check to see additional scenarios. -The above example was automatically extracted from the first unit test -found for this lint check, `RestrictToDetector.testRestrictToSubClass`. -To report a problem with this extracted sample, visit -https://issuetracker.google.com/issues/new?component=192708. - (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/RetrofitUsage.md.html b/docs/checks/RetrofitUsage.md.html new file mode 100644 index 00000000..f14e355f --- /dev/null +++ b/docs/checks/RetrofitUsage.md.html @@ -0,0 +1,205 @@ + +(#) This is replaced by the caller + +!!! ERROR: This is replaced by the caller + This is an error. + +Id +: `RetrofitUsage` +Summary +: This is replaced by the caller +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/retrofit/RetrofitUsageDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/retrofit/RetrofitUsageDetectorTest.kt) +Copyright Year +: 2021 + +This linter reports various common configuration issues with Retrofit. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test/Example.kt:11:Error: @FormUrlEncoded requires @PUT, @POST, or +@PATCH. [RetrofitUsage] + fun wrongMethod(): String + ----------- +src/test/Example.kt:14:Error: @FormUrlEncoded but has no @Field(Map) +parameters. [RetrofitUsage] + @FormUrlEncoded + --------------- +src/test/Example.kt:18:Error: @Field(Map) param requires +@FormUrlEncoded. [RetrofitUsage] + fun missingAnnotation(@Field("hi") input: String): String + ----------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test/Example.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test + +import retrofit2.http.Field +import retrofit2.http.FormUrlEncoded +import retrofit2.http.GET +import retrofit2.http.POST + +interface Example { + @GET("/") + @FormUrlEncoded + fun wrongMethod(): String + + @POST("/") + @FormUrlEncoded + fun missingFieldParams(): String + + @POST("/") + fun missingAnnotation(@Field("hi") input: String): String + + @FormUrlEncoded + @POST("/") + fun correct(@Field("hi") input: String): String +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/retrofit/RetrofitUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `RetrofitUsageDetector.formEncoding`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("RetrofitUsage") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("RetrofitUsage") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection RetrofitUsage + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="RetrofitUsage" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'RetrofitUsage' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore RetrofitUsage ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ReturnFromAwaitPointerEventScope.md.html b/docs/checks/ReturnFromAwaitPointerEventScope.md.html index 2ff67cc5..c3b583de 100644 --- a/docs/checks/ReturnFromAwaitPointerEventScope.md.html +++ b/docs/checks/ReturnFromAwaitPointerEventScope.md.html @@ -20,6 +20,14 @@ : androidx.compose.ui Feedback : https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.ui:ui-android](androidx_compose_ui_ui-android.md.html) +Since +: 1.5.0 Affects : Kotlin and Java files and test sources Editing @@ -37,6 +45,44 @@ guarantee that the events will persist between those calls. In this case you should keep all events inside the awaitPointerEventScope block. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.ui:ui-android:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.ui:ui-android:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.ui.android) + +# libs.versions.toml +[versions] +ui-android = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +ui-android = { + module = "androidx.compose.ui:ui-android", + version.ref = "ui-android" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.ui:ui-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.ui:ui-android](androidx_compose_ui_ui-android.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/ReturnThis.md.html b/docs/checks/ReturnThis.md.html index 2651bb6c..e20ae1ff 100644 --- a/docs/checks/ReturnThis.md.html +++ b/docs/checks/ReturnThis.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.3.0 (September 2022) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ReturnThisDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ReturnThisDetectorTest.kt) -Copyright Year -: 2022 Methods annotated with `@ReturnThis` (usually in the super method that this method is overriding) should also `return this`. @@ -38,11 +38,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/Builder.kt:18:Error: This method should return this (because it has been annotated with @ReturnThis) [ReturnThis] - return MyClass() ---------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/RiskyLibrary.md.html b/docs/checks/RiskyLibrary.md.html index 00b09596..bff39d35 100644 --- a/docs/checks/RiskyLibrary.md.html +++ b/docs/checks/RiskyLibrary.md.html @@ -18,18 +18,20 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.2.0 (September 2018) Affects -: Gradle build files +: Gradle build files and TOML files Editing : This check runs on the fly in the IDE editor See -: https://play.google.com/sdks +: https://developer.android.com/distribute/sdk-index +See +: https://goo.gle/RiskyLibrary Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GradleDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) -Copyright Year -: 2014 Your app is using a version of a library that has been identified by the library developer as a potential source of privacy and/or security @@ -50,14 +52,12 @@ Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -build.gradle:7:Error: log4j:log4j version 1.2.13 has been reported as -problematic by its author and will block publishing of your app to Play -Console [RiskyLibrary] - +build.gradle:7:Error: [Prevents app release in Google Play Console] +log4j:log4j version 1.2.13 has been reported as problematic by its +author and will block publishing of your app to Play Console +[RiskyLibrary] compile 'log4j:log4j:1.2.13' // Critical BLOCKING -------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -76,7 +76,23 @@ compile 'com.example.ads.third.party:example:8.0.0' // OK compile 'com.example.ads.third.party:example:7.2.2' // OK compile 'com.example.ads.third.party:example:7.2.1' // OK - compile 'com.example.ads.third.party:example:7.2.0' // Outdated & Non compliant & Critical + compile 'com.example.ads.third.party:example:7.2.0' // Outdated + Critical + Policy (multiple issues), no severity + compile 'com.example.ads.third.party:example:7.1.0' // Policy (Ads), non-blocking + compile 'com.example.ads.third.party:example:7.1.1' // Policy (Device and Network Abuse), blocking + compile 'com.example.ads.third.party:example:7.1.2' // Policy (Deceptive Behavior), no severity + compile 'com.example.ads.third.party:example:7.1.3' // Policy (User Data), non-blocking + compile 'com.example.ads.third.party:example:7.1.4' // Policy (Permissions), blocking + compile 'com.example.ads.third.party:example:7.1.5' // Policy (Mobile Unwanted Software), no-severity + compile 'com.example.ads.third.party:example:7.1.6' // Policy (Malware), non-blocking + compile 'com.example.ads.third.party:example:7.1.7' // Policy (multiple types), non-blocking + compile 'com.example.ads.third.party:example:7.1.8' // Policy (multiple types), blocking + compile 'com.example.ads.third.party:example:7.1.9' // Policy (multiple types), no severity + compile 'com.example.ads.third.party:example:7.1.10' // Vulnerability (UNSAFE_HOSTNAME_VERIFIER, non-blocking) + compile 'com.example.ads.third.party:example:7.1.11' // Vulnerability multiple (UNSAFE_SSL_ERROR_HANDLER, ZIP_PATH_TRAVERSAL, UNSAFE_WEBVIEW_OAUTH, blocking) + compile 'com.example.ads.third.party:example:7.1.12' // Vulnerability multiple (non-blocking) + compile 'com.example.issues:issues-on-latest:1.8.0' // Outdated blocking + compile 'com.example.issues:latest-is-preview:1.0.0' // Outdated non-blocking + compile 'com.example.issues:deprecated:2.0.0' // Deprecated compile 'log4j:log4j:latest.release' // OK compile 'log4j:log4j' // OK diff --git a/docs/checks/RtlCompat.md.html b/docs/checks/RtlCompat.md.html index a4020d01..c4ba0056 100644 --- a/docs/checks/RtlCompat.md.html +++ b/docs/checks/RtlCompat.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files, manifest files and resource files Editing @@ -44,75 +46,48 @@ res/layout/relative.xml:10:Error: To support older versions than API 17 (project specifies 5) you should also add android:layout_alignParentLeft="true" [RtlCompat] - android:layout_alignParentStart="true" ------------------------------- - - res/layout/relative.xml:13:Error: To support older versions than API 17 (project specifies 5) you should also add android:layout_marginLeft="40dip" [RtlCompat] - android:layout_marginStart="40dip" -------------------------- - - res/layout/relative.xml:24:Error: To support older versions than API 17 (project specifies 5) you should also add android:layout_marginLeft="40dip" [RtlCompat] - android:layout_marginStart="40dip" -------------------------- - - res/layout/relative.xml:26:Error: To support older versions than API 17 (project specifies 5) you should also add android:layout_toRightOf="@id/loading_progress" [RtlCompat] - android:layout_toEndOf="@id/loading_progress" ---------------------- - - res/layout/relative.xml:29:Error: To support older versions than API 17 (project specifies 5) you should also add android:paddingRight="120dip" [RtlCompat] - android:paddingEnd="120dip" ------------------ - - res/layout/relative.xml:37:Error: To support older versions than API 17 (project specifies 5) you should also add android:layout_alignParentLeft="true" [RtlCompat] - android:layout_alignParentStart="true" ------------------------------- - - res/layout/relative.xml:38:Error: To support older versions than API 17 (project specifies 5) you should also add android:layout_alignRight="@id/text" [RtlCompat] - android:layout_alignEnd="@id/text" ----------------------- - - res/layout/relative.xml:47:Error: To support older versions than API 17 (project specifies 5) you should also add android:layout_alignLeft="@id/cancel" [RtlCompat] - android:layout_alignStart="@id/cancel" ------------------------- - - res/layout/relative.xml:48:Error: To support older versions than API 17 (project specifies 5) you should also add android:layout_alignRight="@id/cancel" [RtlCompat] - android:layout_alignEnd="@id/cancel" ----------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/RtlEnabled.md.html b/docs/checks/RtlEnabled.md.html index 84162740..060fdbc7 100644 --- a/docs/checks/RtlEnabled.md.html +++ b/docs/checks/RtlEnabled.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files, manifest files and resource files Editing @@ -44,14 +46,10 @@ AndroidManifest.xml:Warning: The project references RTL attributes, but does not explicitly enable or disable RTL support with android:supportsRtl in the manifest [RtlEnabled] - 0 errors, 4 warnings - - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `AndroidManifest.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers @@ -61,6 +59,76 @@ </manifest> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/layout/rtl.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" + tools:ignore="HardcodedText" > + + <!-- Warn: Use start instead of left --> + + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="left" + android:text="Button" /> + + <!-- Warn: Use end instead of right with layout_gravity --> + + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="right" + android:text="Button" /> + + <!-- Warn: Use end instead of right with gravity --> + + <TextView + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="right" + android:text="TextView" /> + + <!-- OK: No warning --> + + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="start" + android:text="Button" /> + + <!-- OK: No warning --> + + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="end" + android:text="Button" /> + + <!-- OK: No warning --> + + <TextView + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="end" + android:text="TextView" /> + + <!-- OK: Suppressed --> + + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="right" + android:text="Button" + tools:ignore="RtlHardcoded" /> + +</LinearLayout> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/RtlDetectorTest.java) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/RtlHardcoded.md.html b/docs/checks/RtlHardcoded.md.html index 278d79d8..8338e225 100644 --- a/docs/checks/RtlHardcoded.md.html +++ b/docs/checks/RtlHardcoded.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files, manifest files and resource files Editing @@ -57,29 +59,28 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/rtl.xml:14:Warning: Use "start" instead of "left" to ensure correct behavior in right-to-left locales [RtlHardcoded] - android:layout_gravity="left" ---- - - res/layout/rtl.xml:22:Warning: Use "end" instead of "right" to ensure correct behavior in right-to-left locales [RtlHardcoded] - android:layout_gravity="right" ----- - - res/layout/rtl.xml:30:Warning: Use "end" instead of "right" to ensure correct behavior in right-to-left locales [RtlHardcoded] - android:gravity="right" ----- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Here are the relevant source files: +`src/AndroidManifest.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="test.rtl"> + <uses-sdk android:minSdkVersion="5" android:targetSdkVersion="17" /> +</manifest> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: - `res/layout/rtl.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers <?xml version="1.0" encoding="utf-8"?> diff --git a/docs/checks/RtlSymmetry.md.html b/docs/checks/RtlSymmetry.md.html index 4a6e70a4..7911c7c8 100644 --- a/docs/checks/RtlSymmetry.md.html +++ b/docs/checks/RtlSymmetry.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files, manifest files and resource files Editing @@ -40,11 +42,8 @@ res/layout/relative.xml:29:Warning: When you define paddingRight you should probably also define paddingLeft for right-to-left symmetry [RtlSymmetry] - android:paddingRight="120dip" -------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/RxJava2DefaultScheduler.md.html b/docs/checks/RxJava2DefaultScheduler.md.html new file mode 100644 index 00000000..7dd79ab3 --- /dev/null +++ b/docs/checks/RxJava2DefaultScheduler.md.html @@ -0,0 +1,177 @@ + +(#) Pass a scheduler instead of relying on the default Scheduler + +!!! WARNING: Pass a scheduler instead of relying on the default Scheduler + This is a warning. + +Id +: `RxJava2DefaultScheduler` +Summary +: Pass a scheduler instead of relying on the default Scheduler +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-rxjava2](com_vanniktech_lint-rules-rxjava2.md.html) +Since +: 0.6.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-rxjava2-lint/src/main/kotlin/com/vanniktech/lintrules/rxjava2/RxJava2DefaultSchedulerDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-rxjava2-lint/src/test/kotlin/com/vanniktech/lintrules/rxjava2/RxJava2DefaultSchedulerDetectorTest.kt) + +Calling this method will rely on a default scheduler. This is not +necessary the best default. Being explicit and taking the overload for +passing one is preferred. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/Example.java:8:Warning: interval() is using its default +scheduler [RxJava2DefaultScheduler] + Observable.interval(5, TimeUnit.SECONDS); + -------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/Example.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package foo; + +import java.util.concurrent.TimeUnit; +import io.reactivex.Observable; + +class Example { + public void foo() { + Observable.interval(5, TimeUnit.SECONDS); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-rxjava2-lint/src/test/kotlin/com/vanniktech/lintrules/rxjava2/RxJava2DefaultSchedulerDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `RxJava2DefaultSchedulerDetector.schedulerSupportComputation`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-rxjava2:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-rxjava2:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.rxjava2) + +# libs.versions.toml +[versions] +lint-rules-rxjava2 = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-rxjava2 = { + module = "com.vanniktech:lint-rules-rxjava2", + version.ref = "lint-rules-rxjava2" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-rxjava2](com_vanniktech_lint-rules-rxjava2.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("RxJava2DefaultScheduler") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("RxJava2DefaultScheduler") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection RxJava2DefaultScheduler + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="RxJava2DefaultScheduler" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'RxJava2DefaultScheduler' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore RxJava2DefaultScheduler ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/RxJava2DisposableAddAllCall.md.html b/docs/checks/RxJava2DisposableAddAllCall.md.html new file mode 100644 index 00000000..8321a859 --- /dev/null +++ b/docs/checks/RxJava2DisposableAddAllCall.md.html @@ -0,0 +1,174 @@ + +(#) Marks usage of addAll() on CompositeDisposable + +!!! WARNING: Marks usage of addAll() on CompositeDisposable + This is a warning. + +Id +: `RxJava2DisposableAddAllCall` +Summary +: Marks usage of addAll() on CompositeDisposable +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-rxjava2](com_vanniktech_lint-rules-rxjava2.md.html) +Since +: 0.6.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-rxjava2-lint/src/main/kotlin/com/vanniktech/lintrules/rxjava2/RxJava2DisposableAddAllCallDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-rxjava2-lint/src/test/kotlin/com/vanniktech/lintrules/rxjava2/RxJava2DisposableAddAllCallDetectorTest.kt) + +Instead of using addAll(), add() should be used separately for each +Disposable. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/Example.java:6:Warning: Calling addAll instead of add separately +[RxJava2DisposableAddAllCall] + cd.addAll(); + ------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/Example.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package foo; +import io.reactivex.disposables.CompositeDisposable; +class Example { + public void foo() { + CompositeDisposable cd = null; + cd.addAll(); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-rxjava2-lint/src/test/kotlin/com/vanniktech/lintrules/rxjava2/RxJava2DisposableAddAllCallDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `RxJava2DisposableAddAllCallDetector.callingCompositeDisposableAddAll`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-rxjava2:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-rxjava2:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.rxjava2) + +# libs.versions.toml +[versions] +lint-rules-rxjava2 = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-rxjava2 = { + module = "com.vanniktech:lint-rules-rxjava2", + version.ref = "lint-rules-rxjava2" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-rxjava2](com_vanniktech_lint-rules-rxjava2.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("RxJava2DisposableAddAllCall") + fun method() { + addAll(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("RxJava2DisposableAddAllCall") + void method() { + addAll(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection RxJava2DisposableAddAllCall + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="RxJava2DisposableAddAllCall" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'RxJava2DisposableAddAllCall' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore RxJava2DisposableAddAllCall ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/RxJava2DisposableDisposeCall.md.html b/docs/checks/RxJava2DisposableDisposeCall.md.html new file mode 100644 index 00000000..4c5f3d32 --- /dev/null +++ b/docs/checks/RxJava2DisposableDisposeCall.md.html @@ -0,0 +1,180 @@ + +(#) Marks usage of dispose() on CompositeDisposable + +!!! WARNING: Marks usage of dispose() on CompositeDisposable + This is a warning. + +Id +: `RxJava2DisposableDisposeCall` +Summary +: Marks usage of dispose() on CompositeDisposable +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-rxjava2](com_vanniktech_lint-rules-rxjava2.md.html) +Since +: 0.6.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-rxjava2-lint/src/main/kotlin/com/vanniktech/lintrules/rxjava2/RxJava2DisposableDisposeCallDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-rxjava2-lint/src/test/kotlin/com/vanniktech/lintrules/rxjava2/RxJava2DisposableDisposeCallDetectorTest.kt) + +Instead of using dispose(), clear() should be used. Calling clear will +result in a CompositeDisposable that can be used further to add more +Disposables. When using dispose() this is not the case. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/Example.java:8:Warning: Calling dispose instead of clear +[RxJava2DisposableDisposeCall] + cd.dispose(); + ------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/Example.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package foo; + +import io.reactivex.disposables.CompositeDisposable; + +class Example { + public void foo() { + CompositeDisposable cd = null; + cd.dispose(); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-rxjava2-lint/src/test/kotlin/com/vanniktech/lintrules/rxjava2/RxJava2DisposableDisposeCallDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `RxJava2DisposableDisposeCallDetector.callingCompositeDisposableDispose`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-rxjava2:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-rxjava2:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.rxjava2) + +# libs.versions.toml +[versions] +lint-rules-rxjava2 = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-rxjava2 = { + module = "com.vanniktech:lint-rules-rxjava2", + version.ref = "lint-rules-rxjava2" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-rxjava2](com_vanniktech_lint-rules-rxjava2.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("RxJava2DisposableDisposeCall") + fun method() { + dispose(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("RxJava2DisposableDisposeCall") + void method() { + dispose(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection RxJava2DisposableDisposeCall + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="RxJava2DisposableDisposeCall" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'RxJava2DisposableDisposeCall' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore RxJava2DisposableDisposeCall ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/RxJava2MethodMissingCheckReturnValue.md.html b/docs/checks/RxJava2MethodMissingCheckReturnValue.md.html new file mode 100644 index 00000000..46dea422 --- /dev/null +++ b/docs/checks/RxJava2MethodMissingCheckReturnValue.md.html @@ -0,0 +1,270 @@ + +(#) Method is missing the @CheckReturnValue annotation + +!!! WARNING: Method is missing the @CheckReturnValue annotation + This is a warning. + +Id +: `RxJava2MethodMissingCheckReturnValue` +Summary +: Method is missing the @CheckReturnValue annotation +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-rxjava2](com_vanniktech_lint-rules-rxjava2.md.html) +Since +: 0.6.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-rxjava2-lint/src/main/kotlin/com/vanniktech/lintrules/rxjava2/RxJava2MethodMissingCheckReturnValueDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-rxjava2-lint/src/test/kotlin/com/vanniktech/lintrules/rxjava2/RxJava2MethodMissingCheckReturnValueDetectorTest.kt) + +Methods returning RxJava Reactive Types should be annotated with the +@CheckReturnValue annotation. Static analyze tools such as Lint or +ErrorProne can detect when the return value of a method is not used. +This is usually an indication of a bug. If this is done on purpose (e.g. +fire & forget) it should be stated explicitly. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/Example.java:15:Warning: Method should have @CheckReturnValue +annotation [RxJava2MethodMissingCheckReturnValue] + private Observable<Object> observable() { + ---------- +src/foo/Example.java:19:Warning: Method should have @CheckReturnValue +annotation [RxJava2MethodMissingCheckReturnValue] + protected Flowable<Object> flowable() { + -------- +src/foo/Example.java:23:Warning: Method should have @CheckReturnValue +annotation [RxJava2MethodMissingCheckReturnValue] + protected Single<Object> single() { + ------ +src/foo/Example.java:27:Warning: Method should have @CheckReturnValue +annotation [RxJava2MethodMissingCheckReturnValue] + protected Maybe<Object> single() { + ------ +src/foo/Example.java:31:Warning: Method should have @CheckReturnValue +annotation [RxJava2MethodMissingCheckReturnValue] + public Completable completable() { + ----------- +src/foo/Example.java:35:Warning: Method should have @CheckReturnValue +annotation [RxJava2MethodMissingCheckReturnValue] + public Disposable disposable() { + ---------- +src/foo/Example.java:39:Warning: Method should have @CheckReturnValue +annotation [RxJava2MethodMissingCheckReturnValue] + public CompositeDisposable compositeDisposable() { + ------------------- +src/foo/Example.java:43:Warning: Method should have @CheckReturnValue +annotation [RxJava2MethodMissingCheckReturnValue] + public TestObserver testObserver() { + ------------ +src/foo/Example.java:47:Warning: Method should have @CheckReturnValue +annotation [RxJava2MethodMissingCheckReturnValue] + public TestSubscriber testSubscriber() { + -------------- +src/foo/Example.java:51:Warning: Method should have @CheckReturnValue +annotation [RxJava2MethodMissingCheckReturnValue] + public Scheduler scheduler() { + --------- +src/foo/Example.java:55:Warning: Method should have @CheckReturnValue +annotation [RxJava2MethodMissingCheckReturnValue] + private Observable<List<Object>> observableList() { + -------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/Example.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package foo; + +import io.reactivex.Observable; +import io.reactivex.Flowable; +import io.reactivex.Single; +import io.reactivex.Maybe; +import io.reactivex.Completable; +import io.reactivex.disposables.Disposable; +import io.reactivex.disposables.CompositeDisposable; +import io.reactivex.observers.TestObserver; +import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.Scheduler; + +class Example { + private Observable observable() { + return null; + } + + protected Flowable flowable() { + return null; + } + + protected Single single() { + return null; + } + + protected Maybe single() { + return null; + } + + public Completable completable() { + return null; + } + + public Disposable disposable() { + return null; + } + + public CompositeDisposable compositeDisposable() { + return null; + } + + public TestObserver testObserver() { + return null; + } + + public TestSubscriber testSubscriber() { + return null; + } + + public Scheduler scheduler() { + return null; + } + + private Observable> observableList() { + return null; + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-rxjava2-lint/src/test/kotlin/com/vanniktech/lintrules/rxjava2/RxJava2MethodMissingCheckReturnValueDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `RxJava2MethodMissingCheckReturnValueDetector.methodMissingCheckReturnValue`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-rxjava2:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-rxjava2:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.rxjava2) + +# libs.versions.toml +[versions] +lint-rules-rxjava2 = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-rxjava2 = { + module = "com.vanniktech:lint-rules-rxjava2", + version.ref = "lint-rules-rxjava2" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-rxjava2](com_vanniktech_lint-rules-rxjava2.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("RxJava2MethodMissingCheckReturnValue") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("RxJava2MethodMissingCheckReturnValue") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection RxJava2MethodMissingCheckReturnValue + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="RxJava2MethodMissingCheckReturnValue" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'RxJava2MethodMissingCheckReturnValue' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore RxJava2MethodMissingCheckReturnValue ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/RxJava2MissingCompositeDisposableClear.md.html b/docs/checks/RxJava2MissingCompositeDisposableClear.md.html new file mode 100644 index 00000000..4119698a --- /dev/null +++ b/docs/checks/RxJava2MissingCompositeDisposableClear.md.html @@ -0,0 +1,175 @@ + +(#) Marks CompositeDisposables that are not being cleared + +!!! ERROR: Marks CompositeDisposables that are not being cleared + This is an error. + +Id +: `RxJava2MissingCompositeDisposableClear` +Summary +: Marks CompositeDisposables that are not being cleared +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-rxjava2](com_vanniktech_lint-rules-rxjava2.md.html) +Since +: 0.6.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-rxjava2-lint/src/main/kotlin/com/vanniktech/lintrules/rxjava2/RxJava2MissingCompositeDisposableClearDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-rxjava2-lint/src/test/kotlin/com/vanniktech/lintrules/rxjava2/RxJava2MissingCompositeDisposableClearDetectorTest.kt) + +A class is using CompositeDisposable and not calling clear(). This can +leave operations running and even cause memory leaks. It's best to +always call clear() once you're done. e.g. in onDestroy() for +Activitys. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/Example.java:6:Error: clear() is not called +[RxJava2MissingCompositeDisposableClear] + CompositeDisposable cd; + ----------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/Example.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package foo; + +import io.reactivex.disposables.CompositeDisposable; + +class Example { + CompositeDisposable cd; +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-rxjava2-lint/src/test/kotlin/com/vanniktech/lintrules/rxjava2/RxJava2MissingCompositeDisposableClearDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `RxJava2MissingCompositeDisposableClearDetector.compositeDisposableMissingClear`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-rxjava2:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-rxjava2:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.rxjava2) + +# libs.versions.toml +[versions] +lint-rules-rxjava2 = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-rxjava2 = { + module = "com.vanniktech:lint-rules-rxjava2", + version.ref = "lint-rules-rxjava2" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-rxjava2](com_vanniktech_lint-rules-rxjava2.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("RxJava2MissingCompositeDisposableClear") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("RxJava2MissingCompositeDisposableClear") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection RxJava2MissingCompositeDisposableClear + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="RxJava2MissingCompositeDisposableClear" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'RxJava2MissingCompositeDisposableClear' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore RxJava2MissingCompositeDisposableClear ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/RxJava2SchedulersFactoryCall.md.html b/docs/checks/RxJava2SchedulersFactoryCall.md.html new file mode 100644 index 00000000..0dcd973c --- /dev/null +++ b/docs/checks/RxJava2SchedulersFactoryCall.md.html @@ -0,0 +1,179 @@ + +(#) Instead of calling the Schedulers factory methods directly inject the Schedulers + +!!! WARNING: Instead of calling the Schedulers factory methods directly inject the Schedulers + This is a warning. + +Id +: `RxJava2SchedulersFactoryCall` +Summary +: Instead of calling the Schedulers factory methods directly inject the Schedulers +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-rxjava2](com_vanniktech_lint-rules-rxjava2.md.html) +Since +: 0.6.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-rxjava2-lint/src/main/kotlin/com/vanniktech/lintrules/rxjava2/RxJava2SchedulersFactoryCallDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-rxjava2-lint/src/test/kotlin/com/vanniktech/lintrules/rxjava2/RxJava2SchedulersFactoryCallDetectorTest.kt) + +Injecting the Schedulers instead of accessing them via the factory +methods has the benefit that unit testing is way easier. Instead of +overriding them via the Plugin mechanism we can just pass a custom +Scheduler. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/Example.java:9:Warning: Inject this Scheduler instead of calling +it directly [RxJava2SchedulersFactoryCall] + return Schedulers.io(); + -- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/Example.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package foo; + +import io.reactivex.annotations.CheckReturnValue; +import io.reactivex.Scheduler; +import io.reactivex.schedulers.Schedulers; + +class Example { + @CheckReturnValue Scheduler provideSchedulerIo() { + return Schedulers.io(); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-rxjava2-lint/src/test/kotlin/com/vanniktech/lintrules/rxjava2/RxJava2SchedulersFactoryCallDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `RxJava2SchedulersFactoryCallDetector.ioCallInsideCheckReturnValueMethod`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-rxjava2:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-rxjava2:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.rxjava2) + +# libs.versions.toml +[versions] +lint-rules-rxjava2 = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-rxjava2 = { + module = "com.vanniktech:lint-rules-rxjava2", + version.ref = "lint-rules-rxjava2" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-rxjava2](com_vanniktech_lint-rules-rxjava2.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("RxJava2SchedulersFactoryCall") + fun method() { + io(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("RxJava2SchedulersFactoryCall") + void method() { + io(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection RxJava2SchedulersFactoryCall + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="RxJava2SchedulersFactoryCall" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'RxJava2SchedulersFactoryCall' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore RxJava2SchedulersFactoryCall ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/RxJava2SubscribeMissingOnError.md.html b/docs/checks/RxJava2SubscribeMissingOnError.md.html new file mode 100644 index 00000000..ad9c527a --- /dev/null +++ b/docs/checks/RxJava2SubscribeMissingOnError.md.html @@ -0,0 +1,177 @@ + +(#) Flags a version of the subscribe() method without an error Consumer + +!!! ERROR: Flags a version of the subscribe() method without an error Consumer + This is an error. + +Id +: `RxJava2SubscribeMissingOnError` +Summary +: Flags a version of the subscribe() method without an error Consumer +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-rxjava2](com_vanniktech_lint-rules-rxjava2.md.html) +Since +: 0.6.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-rxjava2-lint/src/main/kotlin/com/vanniktech/lintrules/rxjava2/RxJava2SubscribeMissingOnErrorDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-rxjava2-lint/src/test/kotlin/com/vanniktech/lintrules/rxjava2/RxJava2SubscribeMissingOnErrorDetectorTest.kt) + +When calling the subscribe() method an error Consumer should always be +used. Otherwise errors might be thrown and may crash the application or +get forwarded to the Plugin Error handler. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/Example.java:8:Error: Using a version of subscribe() without an +error Consumer [RxJava2SubscribeMissingOnError] + o.subscribe(); + --------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/Example.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package foo; + +import io.reactivex.Observable; + +class Example { + public void foo() { + Observable o = null; + o.subscribe(); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-rxjava2-lint/src/test/kotlin/com/vanniktech/lintrules/rxjava2/RxJava2SubscribeMissingOnErrorDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `RxJava2SubscribeMissingOnErrorDetector.callingObservableSubscribe`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-rxjava2:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-rxjava2:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.rxjava2) + +# libs.versions.toml +[versions] +lint-rules-rxjava2 = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-rxjava2 = { + module = "com.vanniktech:lint-rules-rxjava2", + version.ref = "lint-rules-rxjava2" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-rxjava2](com_vanniktech_lint-rules-rxjava2.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("RxJava2SubscribeMissingOnError") + fun method() { + subscribe(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("RxJava2SubscribeMissingOnError") + void method() { + subscribe(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection RxJava2SubscribeMissingOnError + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="RxJava2SubscribeMissingOnError" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'RxJava2SubscribeMissingOnError' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore RxJava2SubscribeMissingOnError ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/SQLiteString.md.html b/docs/checks/SQLiteString.md.html index 5647fedc..72b62df2 100644 --- a/docs/checks/SQLiteString.md.html +++ b/docs/checks/SQLiteString.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 1.3.0 (July 2015) Affects : Kotlin and Java files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/SQLiteDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/SQLiteDetectorTest.java) -Copyright Year -: 2015 In SQLite, any column can store any data type; the declared type for a column is more of a hint as to what the data should be cast to when @@ -59,23 +59,48 @@ you mean to use TEXT? (STRING is a numeric type and its value can be adjusted; for example, strings that look like integers can drop leading zeroes. See issue explanation for details.) [SQLiteString] - db.execSQL("CREATE TABLE " + name + "(" + Tables.AppKeys.SCHEMA + ");"); // ERROR ----------------------------------------------------------------------- - - src/test/pkg/SQLiteTest.java:30:Warning: Using column type STRING; did you mean to use TEXT? (STRING is a numeric type and its value can be adjusted; for example, strings that look like integers can drop leading zeroes. See issue explanation for details.) [SQLiteString] - db.execSQL(TracksColumns.CREATE_TABLE); // ERROR -------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Here are the relevant source files: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`src/test/pkg/TracksColumns.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package test.pkg; -Here is the source file referenced above: +import android.provider.BaseColumns; + +public interface TracksColumns extends BaseColumns { + + String TABLE_NAME = "tracks"; + + String NAME = "name"; + String CATEGORY = "category"; + String STARTTIME = "starttime"; + String MAXGRADE = "maxgrade"; + String MAPID = "mapid"; + String TABLEID = "tableid"; + String ICON = "icon"; + + String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " (" + + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + + NAME + " STRING, " + + CATEGORY + " STRING, " + + STARTTIME + " INTEGER, " + + MAXGRADE + " FLOAT, " + + MAPID + " STRING, " + + TABLEID + " STRING, " + + ICON + " STRING" + + ");"; +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `src/test/pkg/SQLiteTest.java`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers diff --git a/docs/checks/SSLCertificateSocketFactoryCreateSocket.md.html b/docs/checks/SSLCertificateSocketFactoryCreateSocket.md.html index ec8d4720..97eeab72 100644 --- a/docs/checks/SSLCertificateSocketFactoryCreateSocket.md.html +++ b/docs/checks/SSLCertificateSocketFactoryCreateSocket.md.html @@ -18,16 +18,18 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 1.5.0 (November 2015) Affects : Kotlin and Java files Editing : This check runs on the fly in the IDE editor +See +: https://goo.gle/SSLCertificateSocketFactoryCreateSocket Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/SslCertificateSocketFactoryDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/SslCertificateSocketFactoryDetectorTest.kt) -Copyright Year -: 2015 When `SSLCertificateSocketFactory.createSocket()` is called with an `InetAddress` as the first parameter, TLS/SSL hostname verification is @@ -47,61 +49,43 @@ can cause insecure network traffic due to trusting arbitrary hostnames in TLS/SSL certificates presented by peers [SSLCertificateSocketFactoryCreateSocket] - sf.createSocket(inet, 80); ------------------------- - - src/test/pkg/SSLCertificateSocketFactoryTest.java:22:Warning: Use of SSLCertificateSocketFactory.createSocket() with an InetAddress parameter can cause insecure network traffic due to trusting arbitrary hostnames in TLS/SSL certificates presented by peers [SSLCertificateSocketFactoryCreateSocket] - sf.createSocket(inet4, 80); -------------------------- - - src/test/pkg/SSLCertificateSocketFactoryTest.java:23:Warning: Use of SSLCertificateSocketFactory.createSocket() with an InetAddress parameter can cause insecure network traffic due to trusting arbitrary hostnames in TLS/SSL certificates presented by peers [SSLCertificateSocketFactoryCreateSocket] - sf.createSocket(inet6, 80); -------------------------- - - src/test/pkg/SSLCertificateSocketFactoryTest.java:24:Warning: Use of SSLCertificateSocketFactory.createSocket() with an InetAddress parameter can cause insecure network traffic due to trusting arbitrary hostnames in TLS/SSL certificates presented by peers [SSLCertificateSocketFactoryCreateSocket] - sf.createSocket(inet, 80, inet, 2000); ------------------------------------- - - src/test/pkg/SSLCertificateSocketFactoryTest.java:25:Warning: Use of SSLCertificateSocketFactory.createSocket() with an InetAddress parameter can cause insecure network traffic due to trusting arbitrary hostnames in TLS/SSL certificates presented by peers [SSLCertificateSocketFactoryCreateSocket] - sf.createSocket(inet4, 80, inet, 2000); -------------------------------------- - - src/test/pkg/SSLCertificateSocketFactoryTest.java:26:Warning: Use of SSLCertificateSocketFactory.createSocket() with an InetAddress parameter can cause insecure network traffic due to trusting arbitrary hostnames in TLS/SSL certificates presented by peers [SSLCertificateSocketFactoryCreateSocket] - sf.createSocket(inet6, 80, inet, 2000); -------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/SSLCertificateSocketFactoryGetInsecure.md.html b/docs/checks/SSLCertificateSocketFactoryGetInsecure.md.html index ead014b3..d7f7d6bf 100644 --- a/docs/checks/SSLCertificateSocketFactoryGetInsecure.md.html +++ b/docs/checks/SSLCertificateSocketFactoryGetInsecure.md.html @@ -18,16 +18,18 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 1.5.0 (November 2015) Affects : Kotlin and Java files Editing : This check runs on the fly in the IDE editor +See +: https://goo.gle/SSLCertificateSocketFactoryGetInsecure Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/SslCertificateSocketFactoryDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/SslCertificateSocketFactoryDetectorTest.kt) -Copyright Year -: 2015 The `SSLCertificateSocketFactory.getInsecure()` method returns an SSLSocketFactory with all TLS/SSL security checks disabled, which could @@ -44,11 +46,8 @@ SSLCertificateSocketFactory.getInsecure() can cause insecure network traffic due to trusting arbitrary TLS/SSL certificates presented by peers [SSLCertificateSocketFactoryGetInsecure] - SSLCertificateSocketFactory.getInsecure(-1,null)); ------------------------------------------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/ScheduleExactAlarm.md.html b/docs/checks/ScheduleExactAlarm.md.html new file mode 100644 index 00000000..b91a0f3a --- /dev/null +++ b/docs/checks/ScheduleExactAlarm.md.html @@ -0,0 +1,169 @@ + +(#) Scheduling Exact Alarms Without Required Permission + +!!! ERROR: Scheduling Exact Alarms Without Required Permission + This is an error. + +Id +: `ScheduleExactAlarm` +Summary +: Scheduling Exact Alarms Without Required Permission +Severity +: Error +Category +: Correctness +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.1.0 (July 2023) +Affects +: Kotlin and Java files and manifest files +Editing +: This check runs on the fly in the IDE editor +See +: https://developer.android.com/training/scheduling/alarms#exact +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AlarmDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AlarmDetectorTest.kt) + +Applications looking to schedule exact alarms should ensure that the +`SCHEDULE_EXACT_ALARM` permission is granted by calling the +`AlarmManager#canScheduleExactAlarms` API before attempting to set an +exact alarm. If the permission is not granted to your application, +please consider requesting it from the user by starting the +`ACTION_REQUEST_SCHEDULE_EXACT_ALARM` intent or gracefully falling back +to another option. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test/pkg/AlarmTest.kt:7:Error: When scheduling exact alarms, apps +should explicitly call AlarmManager#canScheduleExactAlarms or handle +`SecurityException`s [ScheduleExactAlarm] + alarmManager.setExact(AlarmManager.ELAPSED_REALTIME, 5000, null) + ---------------------------------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`src/AndroidManifest.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<manifest xmlns:android="http://schemas.android.com/apk/res/android"> + <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" /> + <uses-sdk android:targetSdkVersion="33" /> +</manifest> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/test/pkg/AlarmTest.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg; + +import android.app.AlarmManager; +@SuppressWarnings("ClassNameDiffersFromFileName") +class AlarmTest { + fun test(alarmManager: AlarmManager) { + alarmManager.setExact(AlarmManager.ELAPSED_REALTIME, 5000, null) + + try { + alarmManager.setExact(AlarmManager.ELAPSED_REALTIME, 5000, null) + } catch (e: SecurityException) {} + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AlarmDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `AlarmDetector.testScheduleExactAlarmBasic`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=192708. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute `tools:ignore="ScheduleExactAlarm"` + on the problematic XML element (or one of its enclosing elements). + You may also need to add the following namespace declaration on the + root element in the XML file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <manifest xmlns:tools="http://schemas.android.com/tools"> + ... + <uses-permission tools:ignore="ScheduleExactAlarm" .../> + ... + </manifest> + ``` + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ScheduleExactAlarm") + fun method() { + setRepeating(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ScheduleExactAlarm") + void method() { + setRepeating(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ScheduleExactAlarm + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ScheduleExactAlarm" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ScheduleExactAlarm' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ScheduleExactAlarm ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ScopedStorage.md.html b/docs/checks/ScopedStorage.md.html index b9dea4a3..bc38bcab 100644 --- a/docs/checks/ScopedStorage.md.html +++ b/docs/checks/ScopedStorage.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 4.1.0 (October 2020) Affects : Manifest files Editing @@ -28,14 +30,23 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ScopedStorageDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ScopedStorageDetectorTest.kt) -Copyright Year -: 2020 Scoped storage is enforced on Android 10+ (or Android 11+ if using `requestLegacyExternalStorage`). In particular, `WRITE_EXTERNAL_STORAGE` will no longer provide write access to all files; it will provide the equivalent of `READ_EXTERNAL_STORAGE` instead. +As of Android 13, if you need to query or interact with MediaStore or +media files on the shared storage, you should be using instead one or +more new storage permissions: +* `android.permission.READ_MEDIA_IMAGES` +* `android.permission.READ_MEDIA_VIDEO` +* `android.permission.READ_MEDIA_AUDIO` + +and then add `maxSdkVersion="33"` to the older permission. See the +developer guide for how to do this: +https://developer.android.com/about/versions/13/behavior-changes-13#granular-media-permissions + The `MANAGE_EXTERNAL_STORAGE` permission can be used to manage all files, but it is rarely necessary and most apps on Google Play are not allowed to use it. Most apps should instead migrate to use scoped @@ -47,6 +58,9 @@ https://goo.gle/policy-storage-help Allowable use cases: https://goo.gle/policy-storage-usecases. +!!! Tip + This lint check has an associated quickfix available in the IDE. + (##) Example Here is an example of lint warnings produced by this check: @@ -54,11 +68,8 @@ AndroidManifest.xml:4:Warning: WRITE_EXTERNAL_STORAGE no longer provides write access when targeting Android 10, unless you use requestLegacyExternalStorage [ScopedStorage] - <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/><!-- ERROR --> ----------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -69,6 +80,7 @@ <uses-sdk android:targetSdkVersion="29"/> <uses-permission/><!-- Test for NPEs --> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/><!-- ERROR --> + <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/><!-- OK --> </manifest> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/checks/ScrollViewCount.md.html b/docs/checks/ScrollViewCount.md.html index 0eaee2d7..04d7e5e9 100644 --- a/docs/checks/ScrollViewCount.md.html +++ b/docs/checks/ScrollViewCount.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -38,11 +40,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/has_children.xml:1:Warning: A scroll view can have only one child [ScrollViewCount] - <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" ---------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/ScrollViewSize.md.html b/docs/checks/ScrollViewSize.md.html index 0ea2fab3..74dc22c6 100644 --- a/docs/checks/ScrollViewSize.md.html +++ b/docs/checks/ScrollViewSize.md.html @@ -18,12 +18,14 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing : This check runs on the fly in the IDE editor Implementation -: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ScrollViewChildDetector.java) +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ScrollViewChildDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ScrollViewChildDetectorTest.kt) Copyright Year @@ -42,11 +44,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/wrong_dimension.xml:8:Warning: This LinearLayout should use android:layout_width="wrap_content" [ScrollViewSize] - android:layout_width="match_parent" ----------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -70,11 +69,6 @@ [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ScrollViewChildDetectorTest.kt) for the unit tests for this check to see additional scenarios. -The above example was automatically extracted from the first unit test -found for this lint check, `ScrollViewChildDetector.testScrollView`. -To report a problem with this extracted sample, visit -https://issuetracker.google.com/issues/new?component=192708. - (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/SdCardPath.md.html b/docs/checks/SdCardPath.md.html index f641cac8..5666bf10 100644 --- a/docs/checks/SdCardPath.md.html +++ b/docs/checks/SdCardPath.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files Editing @@ -45,105 +47,66 @@ src/test/pkg/SdCardTest.java:13:Warning: Do not hardcode "/sdcard/"; use Environment.getExternalStorageDirectory().getPath() instead [SdCardPath] - private static final String SDCARD_TEST_HTML = "/sdcard/test.html"; ------------------- - - src/test/pkg/SdCardTest.java:14:Warning: Do not hardcode "/sdcard/"; use Environment.getExternalStorageDirectory().getPath() instead [SdCardPath] - public static final String SDCARD_ROOT = "/sdcard"; --------- - - src/test/pkg/SdCardTest.java:15:Warning: Do not hardcode "/sdcard/"; use Environment.getExternalStorageDirectory().getPath() instead [SdCardPath] - public static final String PACKAGES_PATH = "/sdcard/o/packages/"; --------------------- - - src/test/pkg/SdCardTest.java:16:Warning: Do not hardcode "/sdcard/"; use Environment.getExternalStorageDirectory().getPath() instead [SdCardPath] - File deviceDir = new File("/sdcard/vr"); ------------ - - src/test/pkg/SdCardTest.java:20:Warning: Do not hardcode "/sdcard/"; use Environment.getExternalStorageDirectory().getPath() instead [SdCardPath] - android.os.Debug.startMethodTracing("/sdcard/launcher"); ------------------ - - src/test/pkg/SdCardTest.java:22:Warning: Do not hardcode "/sdcard/"; use Environment.getExternalStorageDirectory().getPath() instead [SdCardPath] - if (new File("/sdcard").exists()) { --------- - - src/test/pkg/SdCardTest.java:24:Warning: Do not hardcode "/sdcard/"; use Environment.getExternalStorageDirectory().getPath() instead [SdCardPath] - String FilePath = "/sdcard/" + new File("test"); ---------- - - src/test/pkg/SdCardTest.java:29:Warning: Do not hardcode "/sdcard/"; use Environment.getExternalStorageDirectory().getPath() instead [SdCardPath] - intent.setDataAndType(Uri.parse("file://sdcard/foo.json"), "application/bar-json"); ------------------------ - - src/test/pkg/SdCardTest.java:30:Warning: Do not hardcode "/sdcard/"; use Environment.getExternalStorageDirectory().getPath() instead [SdCardPath] - intent.putExtra("path-filter", "/sdcard(/.+)*"); --------------- - - src/test/pkg/SdCardTest.java:31:Warning: Do not hardcode "/sdcard/"; use Environment.getExternalStorageDirectory().getPath() instead [SdCardPath] - intent.putExtra("start-dir", "/sdcard"); --------- - - src/test/pkg/SdCardTest.java:32:Warning: Do not hardcode "/data/"; use Context.getFilesDir().getPath() instead [SdCardPath] - String mypath = "/data/data/foo"; ---------------- - - src/test/pkg/SdCardTest.java:33:Warning: Do not hardcode "/data/"; use Context.getFilesDir().getPath() instead [SdCardPath] - String base = "/data/data/foo.bar/test-profiling"; ----------------------------------- - - src/test/pkg/SdCardTest.java:34:Warning: Do not hardcode "/sdcard/"; use Environment.getExternalStorageDirectory().getPath() instead [SdCardPath] - String s = "file://sdcard/foo"; ------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/SecretInSource.md.html b/docs/checks/SecretInSource.md.html new file mode 100644 index 00000000..1f85123b --- /dev/null +++ b/docs/checks/SecretInSource.md.html @@ -0,0 +1,139 @@ + +(#) Secret in source code + +!!! WARNING: Secret in source code + This is a warning. + +Id +: `SecretInSource` +Summary +: Secret in source code +Severity +: Warning +Category +: Security +Platform +: Any +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.3.0 (February 2024) +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +See +: https://developers.google.com/maps/documentation/android-sdk/secrets-gradle-plugin +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/SecretDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/SecretDetectorTest.kt) + +Including secrets, such as API keys, in source code is a security risk. +It is generally best practice to not include API keys in source code, +and instead use something like the Secrets Gradle Plugin for Android. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/com/pkg/keydemo/test.kt:8:Warning: This argument looks like an API +key that has come from source code; API keys should not be included in +source code [SecretInSource] + val model1 = GenerativeModel("name", KEY) + --- +src/com/pkg/keydemo/test.kt:9:Warning: This argument looks like an API +key that has come from source code; API keys should not be included in +source code [SecretInSource] + val model2 = GenerativeModel("name", "AIzadGhpcyBpcyBhbm90aGVy_IHQ-akd==") + ------------------------------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/com/pkg/keydemo/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package com.pkg.keydemo + +import com.google.ai.client.generativeai.GenerativeModel + +val KEY = "AIzadGhpcyBpcyBhbm90aGVy_IHQ-akd==" + +fun foo(extra: String) { + val model1 = GenerativeModel("name", KEY) + val model2 = GenerativeModel("name", "AIzadGhpcyBpcyBhbm90aGVy_IHQ-akd==") +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/SecretDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("SecretInSource") + fun method() { + GenerativeModel(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("SecretInSource") + void method() { + new GenerativeModel(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection SecretInSource + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="SecretInSource" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'SecretInSource' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore SecretInSource ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/SecureRandom.md.html b/docs/checks/SecureRandom.md.html index d307b3fd..f5e62e82 100644 --- a/docs/checks/SecureRandom.md.html +++ b/docs/checks/SecureRandom.md.html @@ -18,11 +18,15 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files Editing : This check runs on the fly in the IDE editor See +: https://goo.gle/SecureRandom +See : https://developer.android.com/reference/java/security/SecureRandom.html Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/SecureRandomDetector.kt) @@ -42,91 +46,58 @@ src/test/pkg/SecureRandomTest.java:12:Warning: It is dangerous to seed SecureRandom with the current time because that value is more predictable to an attacker than the default seed [SecureRandom] - random1.setSeed(System.currentTimeMillis()); // Wrong ------------------------------------------- - - src/test/pkg/SecureRandomTest.java:13:Warning: It is dangerous to seed SecureRandom with the current time because that value is more predictable to an attacker than the default seed [SecureRandom] - random1.setSeed(System.nanoTime()); // Wrong ---------------------------------- - - src/test/pkg/SecureRandomTest.java:15:Warning: Do not call setSeed() on a SecureRandom with a fixed seed: it is not secure. Use getSeed(). [SecureRandom] - random1.setSeed(0); // Wrong ------------------ - - src/test/pkg/SecureRandomTest.java:16:Warning: Do not call setSeed() on a SecureRandom with a fixed seed: it is not secure. Use getSeed(). [SecureRandom] - random1.setSeed(1); // Wrong ------------------ - - src/test/pkg/SecureRandomTest.java:17:Warning: Do not call setSeed() on a SecureRandom with a fixed seed: it is not secure. Use getSeed(). [SecureRandom] - random1.setSeed((int)1023); // Wrong -------------------------- - - src/test/pkg/SecureRandomTest.java:18:Warning: Do not call setSeed() on a SecureRandom with a fixed seed: it is not secure. Use getSeed(). [SecureRandom] - random1.setSeed(1023L); // Wrong ---------------------- - - src/test/pkg/SecureRandomTest.java:19:Warning: Do not call setSeed() on a SecureRandom with a fixed seed: it is not secure. Use getSeed(). [SecureRandom] - random1.setSeed(FIXED_SEED); // Wrong --------------------------- - - src/test/pkg/SecureRandomTest.java:29:Warning: Do not call setSeed() on a SecureRandom with a fixed seed: it is not secure. Use getSeed(). [SecureRandom] - random3.setSeed(0); // Wrong: owner is java/util/Random, but applied to SecureRandom object ------------------ - - src/test/pkg/SecureRandomTest.java:41:Warning: Do not call setSeed() on a SecureRandom with a fixed seed: it is not secure. Use getSeed(). [SecureRandom] - random2.setSeed(seed); // Wrong --------------------- - - src/test/pkg/SecureRandomTest.java:47:Warning: Do not call setSeed() on a SecureRandom with a fixed seed: it is not secure. Use getSeed(). [SecureRandom] - random2.setSeed(seedBytes); // Wrong -------------------------- - - src/test/pkg/SecureRandomTest.java:55:Warning: Do not call setSeed() on a SecureRandom with a fixed seed: it is not secure. Use getSeed(). [SecureRandom] - random2.setSeed(fixedSeed); // Wrong -------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/SelectableText.md.html b/docs/checks/SelectableText.md.html index e21d71e2..69610c9a 100644 --- a/docs/checks/SelectableText.md.html +++ b/docs/checks/SelectableText.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -48,11 +50,8 @@ res/layout/edit_textview.xml:83:Warning: Consider making the text value selectable by specifying android:textIsSelectable="true" [SelectableText] - <TextView -------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/SelectedPhotoAccess.md.html b/docs/checks/SelectedPhotoAccess.md.html new file mode 100644 index 00000000..82bca523 --- /dev/null +++ b/docs/checks/SelectedPhotoAccess.md.html @@ -0,0 +1,133 @@ + +(#) Behavior change when requesting photo library access + +!!! WARNING: Behavior change when requesting photo library access + This is a warning. + +Id +: `SelectedPhotoAccess` +Summary +: Behavior change when requesting photo library access +Severity +: Warning +Category +: Correctness +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.3.0 (February 2024) +Affects +: Manifest files +Editing +: This check runs on the fly in the IDE editor +See +: https://developer.android.com/about/versions/14/changes/partial-photo-video-access +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/SelectedPhotoAccessDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/SelectedPhotoAccessDetectorTest.kt) + +Selected Photo Access is a new ability for users to share partial access +to their photo library when apps request access to their device storage +on Android 14+. + +Instead of letting the system manage the selection lifecycle, we +recommend you adapt your app to handle partial access to the photo +library. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +AndroidManifest.xml:11:Warning: Your app is currently not handling +Selected Photos Access introduced in Android 14+ [SelectedPhotoAccess] + <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" android:minSdkVersion="33" /> + ------------------------------------ +AndroidManifest.xml:13:Warning: Your app is currently not handling +Selected Photos Access introduced in Android 14+ [SelectedPhotoAccess] + <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" android:minSdkVersion="33"/> + ----------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`AndroidManifest.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers + <manifest xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + package="foo.bar" + android:versionCode="990000000" + android:versionName="9.1.0.0.0x"> + + <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="34" /> + + <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32"/> + <!-- Media permissions introduced in Android 13 (T) --> + <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" android:minSdkVersion="33" /> + <uses-permission android:name="android.permission.READ_MEDIA_AUDIO" android:minSdkVersion="33" /> + <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" android:minSdkVersion="33"/> + <uses-permission android:name="android.permission.CAMERA" /> + + <application + android:icon="@drawable/ic_launcher" + android:label="@string/app_name" + android:permission="android.permission.READ_CONTACTS"> + </application> + +</manifest> + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/SelectedPhotoAccessDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute + `tools:ignore="SelectedPhotoAccess"` on the problematic XML element + (or one of its enclosing elements). You may also need to add the + following namespace declaration on the root element in the XML file + if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="SelectedPhotoAccess" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'SelectedPhotoAccess' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore SelectedPhotoAccess ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/SensitiveExternalPath.md.html b/docs/checks/SensitiveExternalPath.md.html new file mode 100644 index 00000000..ce820ee0 --- /dev/null +++ b/docs/checks/SensitiveExternalPath.md.html @@ -0,0 +1,160 @@ + +(#) Application may expose sensitive info like PII by storing it in external storage + +!!! WARNING: Application may expose sensitive info like PII by storing it in external storage + This is a warning. + +Id +: `SensitiveExternalPath` +Summary +: Application may expose sensitive info like PII by storing it in external storage +Severity +: Warning +Category +: Security +Platform +: Android +Vendor +: Google - Android 3P Vulnerability Research +Contact +: https://github.com/google/android-security-lints +Feedback +: https://github.com/google/android-security-lints/issues +Min +: Lint 4.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.android.security.lint:lint](com_android_security_lint_lint.md.html) +Since +: 1.0.1 +Affects +: Resource files +Editing +: This check runs on the fly in the IDE editor +See +: https://goo.gle/SensitiveExternalPath +Implementation +: [Source Code](https://github.com/google/android-security-lints/tree/main/checks/src/main/java/com/example/lint/checks/MisconfiguredFileProviderDetector.kt) +Tests +: [Source Code](https://github.com/google/android-security-lints/tree/main/checks/src/test/java/com/example/lint/checks/MisconfiguredFileProviderDetectorTest.kt) +Copyright Year +: 2023 + +Sensitive information like PII should not be stored outside of the +application container or system credential storage facilities. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +res/xml/file_paths.xml:5:Warning: Sensitive info like PII should not be +stored or shared via [SensitiveExternalPath] + <external-path name="external_path" path="sdcard/"/> + ---------------------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`res/xml/file_paths.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> + <paths xmlns:android="http://schemas.android.com/apk/res/android"> + <files-path name="my_images" path="images/"/> + <files-path name="my_docs" path="docs/"/> + <external-path name="external_path" path="sdcard/"/> + </paths> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/google/android-security-lints/tree/main/checks/src/test/java/com/example/lint/checks/MisconfiguredFileProviderDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `MisconfiguredFileProviderDetector.testWhenExternalPathUsedInConfig_showsWarningAndQuickFix`. +To report a problem with this extracted sample, visit +https://github.com/google/android-security-lints/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.android.security.lint:lint:1.0.3") + +// build.gradle +lintChecks 'com.android.security.lint:lint:1.0.3' + +// build.gradle.kts with version catalogs: +lintChecks(libs.com.android.security.lint.lint) + +# libs.versions.toml +[versions] +com-android-security-lint-lint = "1.0.3" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +com-android-security-lint-lint = { + module = "com.android.security.lint:lint", + version.ref = "com-android-security-lint-lint" +} +``` + +1.0.3 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.android.security.lint:lint](com_android_security_lint_lint.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute + `tools:ignore="SensitiveExternalPath"` on the problematic XML + element (or one of its enclosing elements). You may also need to add + the following namespace declaration on the root element in the XML + file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="SensitiveExternalPath" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'SensitiveExternalPath' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore SensitiveExternalPath ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/SerializableUsage.md.html b/docs/checks/SerializableUsage.md.html new file mode 100644 index 00000000..80336bfc --- /dev/null +++ b/docs/checks/SerializableUsage.md.html @@ -0,0 +1,180 @@ + +(#) Don't use Serializable + +!!! ERROR: Don't use Serializable + This is an error. + +Id +: `SerializableUsage` +Summary +: Don't use Serializable +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/SerializableDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/SerializableDetectorTest.kt) +Copyright Year +: 2021 + +Don't use Serializable. It's brittle, requires reflection, does not work +well with Kotlin, and prevents us from using Core Library Desugaring. +Either implement Parcelable too or use another safer serialization +mechanism. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/ImplementsExplicitly.kt:6:Error: Don't use Serializable. +[SerializableUsage] +class ImplementsExplicitly : RuntimeException, Serializable + -------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/ImplementsExplicitly.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack + +import java.io.Serializable +import kotlin.RuntimeException + +class ImplementsExplicitly : RuntimeException, Serializable +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/SerializableDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `SerializableDetector.kotlin_explicitPlatformType_isNotIgnored`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("SerializableUsage") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("SerializableUsage") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection SerializableUsage + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="SerializableUsage" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'SerializableUsage' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore SerializableUsage ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ServiceCast.md.html b/docs/checks/ServiceCast.md.html index f2a3209a..5ae15114 100644 --- a/docs/checks/ServiceCast.md.html +++ b/docs/checks/ServiceCast.md.html @@ -18,14 +18,16 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files Editing : This check runs on the fly in the IDE editor Implementation -: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ServiceCastDetector.java) +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ServiceCastDetector.kt) Tests -: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ServiceCastDetectorTest.java) +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ServiceCastDetectorTest.kt) Copyright Year : 2013 @@ -40,27 +42,18 @@ src/test/pkg/SystemServiceTest.java:13:Error: Suspicious cast to DisplayManager for a DEVICE_POLICY_SERVICE: expected DevicePolicyManager [ServiceCast] - DisplayManager displayServiceWrong = (DisplayManager) getSystemService( ^ - - src/test/pkg/SystemServiceTest.java:16:Error: Suspicious cast to WallpaperService for a WALLPAPER_SERVICE: expected WallpaperManager [ServiceCast] - WallpaperService wallPaperWrong = (WallpaperService) getSystemService(WALLPAPER_SERVICE); ------------------------------------------------------ - - src/test/pkg/SystemServiceTest.java:22:Error: Suspicious cast to DisplayManager for a DEVICE_POLICY_SERVICE: expected DevicePolicyManager [ServiceCast] - DisplayManager displayServiceWrong = (DisplayManager) context ^ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -101,7 +94,7 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can also visit the -[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ServiceCastDetectorTest.java) +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ServiceCastDetectorTest.kt) for the unit tests for this check to see additional scenarios. The above example was automatically extracted from the first unit test diff --git a/docs/checks/SetAndClearCommunicationDevice.md.html b/docs/checks/SetAndClearCommunicationDevice.md.html new file mode 100644 index 00000000..9b648863 --- /dev/null +++ b/docs/checks/SetAndClearCommunicationDevice.md.html @@ -0,0 +1,107 @@ + +(#) Clearing communication device + +!!! WARNING: Clearing communication device + This is a warning. + +Id +: `SetAndClearCommunicationDevice` +Summary +: Clearing communication device +Severity +: Warning +Category +: Correctness +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.0.0 (April 2023) +Affects +: Kotlin and Java files +Editing +: This check can *not* run live in the IDE editor +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/CommunicationDeviceDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/CommunicationDeviceDetectorTest.kt) + +After selecting the audio device for communication use cases using +`setCommunicationDevice(AudioDeviceInfo device)`, the selection is +active as long as the requesting application process lives, until +`clearCommunicationDevice()` is called or until the device is +disconnected. It is therefore important to clear the request when a call +ends or the requesting activity or service is stopped or destroyed. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test/pkg/Test.kt:9:Warning: Must call clearCommunicationDevice() +after setCommunicationDevice() [SetAndClearCommunicationDevice] + manager.setCommunicationDevice(AudioDeviceInfo()) + ------------------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test/pkg/Test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test.pkg + +import android.media.AudioDeviceInfo +import android.media.AudioManager + +class Test { + fun test() { + val manager = AudioManager() + manager.setCommunicationDevice(AudioDeviceInfo()) + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/CommunicationDeviceDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="SetAndClearCommunicationDevice" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'SetAndClearCommunicationDevice' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore SetAndClearCommunicationDevice ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/SetJavaScriptEnabled.md.html b/docs/checks/SetJavaScriptEnabled.md.html index db6ceb4e..a5b8c22a 100644 --- a/docs/checks/SetJavaScriptEnabled.md.html +++ b/docs/checks/SetJavaScriptEnabled.md.html @@ -18,11 +18,15 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files Editing : This check runs on the fly in the IDE editor See +: https://goo.gle/SetJavaScriptEnabled +See : https://developer.android.com/training/articles/security-tips Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/SetJavaScriptEnabledDetector.java) @@ -41,11 +45,8 @@ src/test/pkg/SetJavaScriptEnabled.java:14:Warning: Using setJavaScriptEnabled can introduce XSS vulnerabilities into your application, review carefully [SetJavaScriptEnabled] - webView.getSettings().setJavaScriptEnabled(true); // bad ------------------------------------------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/SetTextI18n.md.html b/docs/checks/SetTextI18n.md.html index c983bb51..0468819e 100644 --- a/docs/checks/SetTextI18n.md.html +++ b/docs/checks/SetTextI18n.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 1.5.0 (November 2015) Affects : Kotlin and Java files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/SetTextDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/SetTextDetectorTest.kt) -Copyright Year -: 2014 When calling `TextView#setText` @@ -49,33 +49,21 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/CustomScreen.java:13:Warning: String literal in setText can not be translated. Use Android resources instead. [SetTextI18n] - view.setText("Hardcoded"); ----------- - - src/test/pkg/CustomScreen.java:17:Warning: Number formatting does not take into account locale settings. Consider using String.format instead. [SetTextI18n] - view.setText(Integer.toString(50) + "%"); -------------------- - - src/test/pkg/CustomScreen.java:18:Warning: String literal in setText can not be translated. Use Android resources instead. [SetTextI18n] - view.setText(Double.toString(12.5) + " miles"); -------- - - src/test/pkg/CustomScreen.java:21:Warning: String literal in setText can not be translated. Use Android resources instead. [SetTextI18n] - btn.setText("User " + getUserName()); ------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -104,6 +92,7 @@ Button btn = new Button(context); btn.setText("User " + getUserName()); btn.setText(String.format("%s of %s users", Integer.toString(5), Integer.toString(10))); + view.setText(""); } private static String getUserName() { diff --git a/docs/checks/SetWorldReadable.md.html b/docs/checks/SetWorldReadable.md.html index 1365a82b..f43e16cc 100644 --- a/docs/checks/SetWorldReadable.md.html +++ b/docs/checks/SetWorldReadable.md.html @@ -18,16 +18,18 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 1.5.0 (November 2015) Affects : Kotlin and Java files Editing : This check runs on the fly in the IDE editor +See +: https://goo.gle/SetWorldReadable Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/SecurityDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/SecurityDetectorTest.java) -Copyright Year -: 2011 Setting files world-readable is very dangerous, and likely to cause security holes in applications. It is strongly discouraged; instead, @@ -41,11 +43,8 @@ src/test/pkg/WorldWriteableFile.java:41:Warning: Setting file permissions to world-readable can be risky, review carefully [SetWorldReadable] - mFile.setReadable(true, false); ------------------------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/SetWorldWritable.md.html b/docs/checks/SetWorldWritable.md.html index 2fb8e3e9..90688bef 100644 --- a/docs/checks/SetWorldWritable.md.html +++ b/docs/checks/SetWorldWritable.md.html @@ -18,16 +18,18 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 1.5.0 (November 2015) Affects : Kotlin and Java files Editing : This check runs on the fly in the IDE editor +See +: https://goo.gle/SetWorldWritable Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/SecurityDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/SecurityDetectorTest.java) -Copyright Year -: 2011 Setting files world-writable is very dangerous, and likely to cause security holes in applications. It is strongly discouraged; instead, @@ -41,11 +43,8 @@ src/test/pkg/WorldWriteableFile.java:48:Warning: Setting file permissions to world-writable can be risky, review carefully [SetWorldWritable] - mFile.setWritable(true, false); ------------------------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/ShiftFlags.md.html b/docs/checks/ShiftFlags.md.html index d97b65e2..d9413d82 100644 --- a/docs/checks/ShiftFlags.md.html +++ b/docs/checks/ShiftFlags.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 1.5.0 (November 2015) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AnnotationDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AnnotationDetectorTest.kt) -Copyright Year -: 2012 When defining multiple constants for use in flags, the recommended style is to use the form `1 << 2`, `1 << 3`, `1 << 4` and so on to ensure that @@ -42,32 +42,20 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/IntDefTest.java:13:Warning: Consider declaring this constant using 1 << 44 instead [ShiftFlags] - public static final long FLAG5 = 0x100000000000L; --------------- - - src/test/pkg/IntDefTest.java:14:Warning: Consider declaring this constant using 1 << 49 instead [ShiftFlags] - public static final long FLAG6 = 0x0002000000000000L; ------------------- - - src/test/pkg/IntDefTest.java:15:Warning: Consider declaring this constant using 1 << 3 instead [ShiftFlags] - public static final long FLAG7 = 8L; -- - - src/test/pkg/IntDefTest.java:20:Warning: Consider declaring this constant using 1 << 4 instead [ShiftFlags] - public static final int FLAG12 = 0x10; ---- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/ShortAlarm.md.html b/docs/checks/ShortAlarm.md.html index a8bfe56f..52a8467c 100644 --- a/docs/checks/ShortAlarm.md.html +++ b/docs/checks/ShortAlarm.md.html @@ -18,16 +18,16 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 1.3.0 (July 2015) Affects -: Kotlin and Java files +: Kotlin and Java files and manifest files Editing : This check runs on the fly in the IDE editor Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AlarmDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AlarmDetectorTest.kt) -Copyright Year -: 2015 Frequent alarms are bad for battery life. As of API 22, the `AlarmManager` will override near-future and high-frequency alarm @@ -43,25 +43,16 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/AlarmTest.java:9:Warning: Value will be forced up to 60000 as of Android 5.1; don't rely on this to be exact [ShortAlarm] - alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 50, 10, null); // ERROR -- - - src/test/pkg/AlarmTest.java:11:Warning: Value will be forced up to 60000 as of Android 5.1; don't rely on this to be exact [ShortAlarm] - OtherClass.MY_INTERVAL, null); // ERROR ---------------------- - - src/test/pkg/AlarmTest.java:16:Warning: Value will be forced up to 60000 as of Android 5.1; don't rely on this to be exact [ShortAlarm] - alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 5000, interval2, null); // ERROR --------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -133,6 +124,21 @@ problematicStatement() ``` +* Adding the suppression attribute `tools:ignore="ShortAlarm"` on the + problematic XML element (or one of its enclosing elements). You may + also need to add the following namespace declaration on the root + element in the XML file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <manifest xmlns:tools="http://schemas.android.com/tools"> + ... + <uses-permission tools:ignore="ShortAlarm" .../> + ... + </manifest> + ``` + * Using a special `lint.xml` file in the source tree which turns off the check in that folder and any sub folder. A simple file might look like this: diff --git a/docs/checks/ShouldUseStaticImport.md.html b/docs/checks/ShouldUseStaticImport.md.html new file mode 100644 index 00000000..66e40b1b --- /dev/null +++ b/docs/checks/ShouldUseStaticImport.md.html @@ -0,0 +1,173 @@ + +(#) Flags declarations that should be statically imported + +!!! WARNING: Flags declarations that should be statically imported + This is a warning. + +Id +: `ShouldUseStaticImport` +Summary +: Flags declarations that should be statically imported +Severity +: Warning +Category +: Correctness +Platform +: Any +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html) +Since +: 0.6.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/main/kotlin/com/vanniktech/lintrules/android/ShouldUseStaticImportDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/ShouldUseStaticImportDetectorTest.kt) + +Certain declarations like TimeUnit.SECONDS should be statically imported +to increase the readability. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/Example.java:5:Warning: Should statically import SECONDS +[ShouldUseStaticImport] + TimeUnit.SECONDS.toDays(1); + ------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/foo/Example.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package foo; +import java.util.concurrent.TimeUnit; +class Example { + public void foo() { + TimeUnit.SECONDS.toDays(1); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/ShouldUseStaticImportDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `ShouldUseStaticImportDetector.timeUnitSeconds`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-android:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-android:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.android) + +# libs.versions.toml +[versions] +lint-rules-android = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-android = { + module = "com.vanniktech:lint-rules-android", + version.ref = "lint-rules-android" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("ShouldUseStaticImport") + fun method() { + asList(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("ShouldUseStaticImport") + void method() { + asList(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection ShouldUseStaticImport + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="ShouldUseStaticImport" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'ShouldUseStaticImport' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore ShouldUseStaticImport ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/ShowToast.md.html b/docs/checks/ShowToast.md.html index 2cd6951c..acc6a469 100644 --- a/docs/checks/ShowToast.md.html +++ b/docs/checks/ShowToast.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files Editing @@ -42,32 +44,20 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/ToastTest.java:32:Warning: Toast created but not shown: did you forget to call show()? [ShowToast] - Toast.makeText(context, "foo", Toast.LENGTH_LONG); -------------- - - src/test/pkg/ToastTest.java:33:Warning: Toast created but not shown: did you forget to call show()? [ShowToast] - Toast toast = Toast.makeText(context, R.string.app_name, 5000); -------------- - - src/test/pkg/ToastTest.java:39:Warning: Toast created but not shown: did you forget to call show()? [ShowToast] - Toast.makeText(context, "foo", Toast.LENGTH_LONG); -------------- - - src/test/pkg/ToastTest.java:54:Warning: Toast created but not shown: did you forget to call show()? [ShowToast] - Toast toast2 = Toast.makeText(context, "foo", Toast.LENGTH_LONG); // not shown -------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/SignatureOrSystemPermissions.md.html b/docs/checks/SignatureOrSystemPermissions.md.html index ed9e9c31..aaf5931c 100644 --- a/docs/checks/SignatureOrSystemPermissions.md.html +++ b/docs/checks/SignatureOrSystemPermissions.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Manifest files Editing @@ -44,11 +46,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text AndroidManifest.xml:13:Warning: protectionLevel should probably not be set to signatureOrSystem [SignatureOrSystemPermissions] - android:protectionLevel="signatureOrSystem"/> ------------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/SimilarGradleDependency.md.html b/docs/checks/SimilarGradleDependency.md.html new file mode 100644 index 00000000..c37d22f9 --- /dev/null +++ b/docs/checks/SimilarGradleDependency.md.html @@ -0,0 +1,121 @@ + +(#) Multiple Versions Gradle Dependency + +!!! Tip: Multiple Versions Gradle Dependency + Advice from this check is just a hint; it's a "weak" warning. + +Id +: `SimilarGradleDependency` +Summary +: Multiple Versions Gradle Dependency +Severity +: Hint +Category +: Correctness +Platform +: Any +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.5.0 (June 2024) +Affects +: Gradle build files and TOML files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GradleDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) + +This detector looks for usages of libraries when name and group are the +same but versions are different. Using multiple versions in big project +is fine, and there are cases where you deliberately want to stick with +such approach. However, you may simply not be aware that this situation +happens, and that is what this lint check helps find. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +../gradle/libs.versions.toml:6:Hint: There are multiple dependencies +joda-time:joda-time but with different version +[SimilarGradleDependency] +joda_library = { module = "joda-time:joda-time", version.ref = "jodaVersion"} + ------------------------------------------------------------- +../gradle/libs.versions.toml:7:Hint: There are multiple dependencies +joda-time:joda-time but with different version +[SimilarGradleDependency] +joda_library2 = { module = "joda-time:joda-time", version = "2.0"} + ------------------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`../gradle/libs.versions.toml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~toml linenumbers +[versions] +jodaVersion = "2.1" +dagger="1.2.0" + +[libraries] +joda_library = { module = "joda-time:joda-time", version.ref = "jodaVersion"} +joda_library2 = { module = "joda-time:joda-time", version = "2.0"} +dagger-lib = { group = "com.squareup.dagger", name ="dagger", version.ref = "dagger" } +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `GradleDetector.testVersionCatalogWithSimilarLibraryDependencies`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=192708. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection SimilarGradleDependency + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="SimilarGradleDependency" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'SimilarGradleDependency' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore SimilarGradleDependency ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/SimpleDateFormat.md.html b/docs/checks/SimpleDateFormat.md.html index 7fc1adad..354da10f 100644 --- a/docs/checks/SimpleDateFormat.md.html +++ b/docs/checks/SimpleDateFormat.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 1.1.0 (February 2015) Affects : Kotlin and Java files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/DateFormatDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/DateFormatDetectorTest.kt) -Copyright Year -: 2014 Almost all callers should use `getDateInstance()`, `getDateTimeInstance()`, or `getTimeInstance()` to get a ready-made @@ -52,29 +52,20 @@ getDateInstance(), getDateTimeInstance(), or getTimeInstance(), or use new SimpleDateFormat(String template, Locale locale) with for example Locale.US for ASCII dates. [SimpleDateFormat] - new SimpleDateFormat(); // WRONG ---------------------- - - src/test/pkg/LocaleTest.java:33:Warning: To get local formatting use getDateInstance(), getDateTimeInstance(), or getTimeInstance(), or use new SimpleDateFormat(String template, Locale locale) with for example Locale.US for ASCII dates. [SimpleDateFormat] - new SimpleDateFormat("yyyy-MM-dd"); // WRONG ---------------------------------- - - src/test/pkg/LocaleTest.java:34:Warning: To get local formatting use getDateInstance(), getDateTimeInstance(), or getTimeInstance(), or use new SimpleDateFormat(String template, Locale locale) with for example Locale.US for ASCII dates. [SimpleDateFormat] - new SimpleDateFormat("yyyy-MM-dd", DateFormatSymbols.getInstance()); // WRONG ------------------------------------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/Slices.md.html b/docs/checks/Slices.md.html index d61e2548..dde80fc0 100644 --- a/docs/checks/Slices.md.html +++ b/docs/checks/Slices.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.2.0 (September 2018) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/SliceDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/SliceDetectorTest.kt) -Copyright Year -: 2018 This check analyzes usages of the Slices API and offers suggestions based on best practices. @@ -38,18 +38,12 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/SliceTest.java:33:Warning: A slice should have at least one row added to it [Slices] - Slice slice = new ListBuilder(context, uri, ttl).build(); ---------------------------------- - - src/test/pkg/SliceTest.java:39:Warning: A slice should have at least one row added to it [Slices] - ListBuilder lb2 = new ListBuilder(context, uri, ttl); // missing on this one ---------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/SlotReused.md.html b/docs/checks/SlotReused.md.html new file mode 100644 index 00000000..68785581 --- /dev/null +++ b/docs/checks/SlotReused.md.html @@ -0,0 +1,215 @@ + +(#) Slots should be invoked in at most one place + +!!! ERROR: Slots should be invoked in at most one place + This is an error. + +Id +: `SlotReused` +Summary +: Slots should be invoked in at most one place +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: com.slack.lint.compose:compose-lints +Feedback +: https://github.com/slackhq/compose-lints/issues +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html) +Since +: 1.4.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/main/java/slack/lint/compose/SlotReusedDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/SlotReusedDetectorTest.kt) +Copyright Year +: 2024 + +Slots should be invoked in at most once place to meet lifecycle +expectations. Slots should not be invoked in multiple places in source +code, where the invoking location changes based on some condition. This +will preserve the slot's internal state when the invoking location +changes. See +https://slackhq.github.io/compose-lints/rules/#do-not-invoke-slots-in-more-than-once-place +for more information. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test.kt:7:Error: Slots should be invoked in at most once place to +meet lifecycle expectations. Slots should not be invoked in multiple +places in source code, where the invoking location changes based on some +condition. This will preserve the slot's internal state when the +invoking location changes. See +https://slackhq.github.io/compose-lints/rules/#do-not-invoke-slots-in-more-than-once-place +for more information. [SlotReused] + slot: @Composable () -> Unit, + ---------------------------- +src/test.kt:18:Error: Slots should be invoked in at most once place to +meet lifecycle expectations. Slots should not be invoked in multiple +places in source code, where the invoking location changes based on some +condition. This will preserve the slot's internal state when the +invoking location changes. See +https://slackhq.github.io/compose-lints/rules/#do-not-invoke-slots-in-more-than-once-place +for more information. [SlotReused] + slot: @Composable () -> Unit, + ---------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier + +@Composable +fun Something( + modifier: Modifier = Modifier, + slot: @Composable () -> Unit, +) { + Row(modifier) { + slot() + slot() + } +} + +@Composable +fun SomethingElse( + modifier: Modifier = Modifier, + slot: @Composable () -> Unit, +) { + Column(modifier) { + slot() + Box { + slot() + } + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/SlotReusedDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `SlotReusedDetector.errors when the slot parameter of a Composable is used more than once at the same time`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/compose-lints/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint.compose:compose-lint-checks:1.4.2") + +// build.gradle +lintChecks 'com.slack.lint.compose:compose-lint-checks:1.4.2' + +// build.gradle.kts with version catalogs: +lintChecks(libs.compose.lint.checks) + +# libs.versions.toml +[versions] +compose-lint-checks = "1.4.2" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +compose-lint-checks = { + module = "com.slack.lint.compose:compose-lint-checks", + version.ref = "compose-lint-checks" +} +``` + +1.4.2 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("SlotReused") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("SlotReused") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection SlotReused + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="SlotReused" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'SlotReused' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore SlotReused ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/SmallSp.md.html b/docs/checks/SmallSp.md.html index 9c983f96..be2b01e3 100644 --- a/docs/checks/SmallSp.md.html +++ b/docs/checks/SmallSp.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -37,18 +39,12 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/textsize.xml:33:Warning: Avoid using sizes smaller than 11sp: 10sp [SmallSp] - android:textSize="10sp" /> ----------------------- - - res/layout/textsize.xml:37:Warning: Avoid using sizes smaller than 11sp: 6.5sp [SmallSp] - android:layout_height="6.5sp" /> ----------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/SoonBlockedPrivateApi.md.html b/docs/checks/SoonBlockedPrivateApi.md.html index ffcf86de..c4d957e4 100644 --- a/docs/checks/SoonBlockedPrivateApi.md.html +++ b/docs/checks/SoonBlockedPrivateApi.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.5.0 (August 2019) Affects : Kotlin and Java files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/PrivateApiDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/PrivateApiDetectorTest.kt) -Copyright Year -: 2017 Usage of restricted non-SDK interface will throw an exception at runtime. Accessing non-SDK methods or fields through reflection has a @@ -43,11 +43,8 @@ src/test/pkg/TestReflection.java:16:Error: Reflective access to OTASP_NEEDED will throw an exception when targeting API 28 and above [SoonBlockedPrivateApi] - Field maybeField = TelephonyManager.class.getDeclaredField("OTASP_NEEDED"); // ERROR 2 ------------------------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/SourceLockedOrientationActivity.md.html b/docs/checks/SourceLockedOrientationActivity.md.html index 478a6687..b86822fd 100644 --- a/docs/checks/SourceLockedOrientationActivity.md.html +++ b/docs/checks/SourceLockedOrientationActivity.md.html @@ -18,21 +18,24 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.6.0 (February 2020) Affects : Kotlin and Java files Editing : This check runs on the fly in the IDE editor +See +: https://developer.android.com/guide/topics/large-screens/large-screen-cookbook#restricted_app_orientation Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ChromeOsSourceDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ChromeOsSourceDetectorTest.kt) -Copyright Year -: 2018 The `Activity` should not be locked to a portrait orientation so that users can take advantage of the multi-window environments and larger -landscape-first screens that Android runs on such as Chrome OS. To fix -the issue, consider calling `setRequestedOrientation` with the +landscape-first screens that Android runs on such as ChromeOS, tablets, +and foldables. To fix the issue, consider calling +`setRequestedOrientation` with the `ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR` or `ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED` options or removing the call all together. @@ -48,11 +51,8 @@ orientation of your activities, so that you can support a good user experience for any device or orientation [SourceLockedOrientationActivity] - setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); ----------------------------------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/SpUsage.md.html b/docs/checks/SpUsage.md.html index 0f80ccb4..265f40c0 100644 --- a/docs/checks/SpUsage.md.html +++ b/docs/checks/SpUsage.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -52,18 +54,12 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/textsize.xml:11:Warning: Should use "sp" instead of "dp" for text sizes [SpUsage] - android:textSize="14dp" /> ----------------------- - - res/layout/textsize.xml:16:Warning: Should use "sp" instead of "dp" for text sizes [SpUsage] - android:textSize="14dip" /> ------------------------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/SpanMarkPointMissingMask.md.html b/docs/checks/SpanMarkPointMissingMask.md.html new file mode 100644 index 00000000..4f3207e6 --- /dev/null +++ b/docs/checks/SpanMarkPointMissingMask.md.html @@ -0,0 +1,186 @@ + +(#) Check that Span flags use the bitwise mask SPAN_POINT_MARK_MASK when being compared to + +!!! ERROR: Check that Span flags use the bitwise mask SPAN_POINT_MARK_MASK when being compared to + This is an error. + +Id +: `SpanMarkPointMissingMask` +Summary +: Check that Span flags use the bitwise mask SPAN_POINT_MARK_MASK when being compared to +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/text/SpanMarkPointMissingMaskDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/text/SpanMarkPointMissingMaskDetectorTest.kt) +Copyright Year +: 2021 + +Spans flags can have priority or other bits set. Ensure that Span flags +are checked using `currentFlag and Spanned.SPAN_POINT_MARK_MASK == +desiredFlag` rather than just `currentFlag == desiredFlag` + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/slack/text/MyClass.kt:7:Error: Do not check against directly. +Instead mask flag with Spanned.SPAN_POINT_MARK_MASK to only check +MARK_POINT flags. [SpanMarkPointMissingMask] + return spanned.getSpanFlags(Object()) == || Spanned.x() + ------------------------------------------------------------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/slack/text/MyClass.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package slack.text + +import android.text.Spanned + +class MyClass { + fun doCheckIncorrectly(spanned: Spanned): Boolean { + return spanned.getSpanFlags(Object()) == || Spanned.x() + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/text/SpanMarkPointMissingMaskDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `SpanMarkPointMissingMaskDetector.testViolatingExpressionLeft`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("SpanMarkPointMissingMask") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("SpanMarkPointMissingMask") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection SpanMarkPointMissingMask + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="SpanMarkPointMissingMask" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'SpanMarkPointMissingMask' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore SpanMarkPointMissingMask ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/SpecifyForegroundServiceType.md.html b/docs/checks/SpecifyForegroundServiceType.md.html index 14783c54..747fe52a 100644 --- a/docs/checks/SpecifyForegroundServiceType.md.html +++ b/docs/checks/SpecifyForegroundServiceType.md.html @@ -22,6 +22,14 @@ : androidx.work Feedback : https://issuetracker.google.com/issues/new?component=409906 +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.7+ +Artifact +: [androidx.work:work-runtime](androidx_work_work-runtime.md.html) +Since +: 2.3.1 Affects : Kotlin and Java files and manifest files Editing @@ -37,6 +45,76 @@ entry for `SystemForegroundService` to include the foreground service type in the `AndroidManifest.xml` file. +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +com/example/App.kt:9:Error: Missing dataSync foregroundServiceType in +the AndroidManifest.xml [SpecifyForegroundServiceType] + val info = ForegroundInfo(0, notification, 1) + ---------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`com/example/App.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package com.example + +import android.app.Notification +import androidx.work.ForegroundInfo + +class App { + fun onCreate() { + val notification = Notification() + val info = ForegroundInfo(0, notification, 1) + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/work/work-lint/src/test/java/androidx/work/lint/SpecifyForegroundServiceTypeIssueDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `SpecifyForegroundServiceTypeIssueDetector.failWhenServiceTypeIsNotSpecified`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=409906. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.work:work-runtime:2.10.1") + +// build.gradle +implementation 'androidx.work:work-runtime:2.10.1' + +// build.gradle.kts with version catalogs: +implementation(libs.work.runtime) + +# libs.versions.toml +[versions] +work-runtime = "2.10.1" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +work-runtime = { + module = "androidx.work:work-runtime", + version.ref = "work-runtime" +} +``` + +2.10.1 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.work:work-runtime](androidx_work_work-runtime.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/SpecifyJobSchedulerIdRange.md.html b/docs/checks/SpecifyJobSchedulerIdRange.md.html index 9e640edb..b9ce78d0 100644 --- a/docs/checks/SpecifyJobSchedulerIdRange.md.html +++ b/docs/checks/SpecifyJobSchedulerIdRange.md.html @@ -20,6 +20,14 @@ : androidx.work Feedback : https://issuetracker.google.com/issues/new?component=409906 +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.7+ +Artifact +: [androidx.work:work-runtime](androidx_work_work-runtime.md.html) +Since +: 2.3.4 Affects : Kotlin and Java files Editing @@ -33,11 +41,75 @@ When using `JobScheduler` APIs directly, `WorkManager` requires that developers specify a range of `JobScheduler` ids that are safe for -`WorkManager` to use so the `id`s do not collide. +`WorkManager` to use so the `id`s do not collide. For more information look at `androidx.work.Configuration.Builder.setJobSchedulerJobIdRange(int, int)`. +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +com/example/TestJobService.kt:5:Warning: Specify a valid range of job +id's for WorkManager to use. [SpecifyJobSchedulerIdRange] +class TestJobService: JobService() + -------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`com/example/TestJobService.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package com.example + +import android.app.job.JobService + +class TestJobService: JobService() +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/work/work-lint/src/test/java/androidx/work/lint/SpecifyJobSchedulerIdRangeIssueDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `SpecifyJobSchedulerIdRangeIssueDetector.failWhenUsingCustomJobServiceAndIdsAreNotSpecified`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=409906. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.work:work-runtime:2.10.1") + +// build.gradle +implementation 'androidx.work:work-runtime:2.10.1' + +// build.gradle.kts with version catalogs: +implementation(libs.work.runtime) + +# libs.versions.toml +[versions] +work-runtime = "2.10.1" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +work-runtime = { + module = "androidx.work:work-runtime", + version.ref = "work-runtime" +} +``` + +2.10.1 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.work:work-runtime](androidx_work_work-runtime.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/SquareAndRoundTilePreviews.md.html b/docs/checks/SquareAndRoundTilePreviews.md.html index 1d93669f..5e96d3ff 100644 --- a/docs/checks/SquareAndRoundTilePreviews.md.html +++ b/docs/checks/SquareAndRoundTilePreviews.md.html @@ -18,16 +18,18 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.4.0 (January 2023) Affects : Binary resource files and manifest files Editing : This check can *not* run live in the IDE editor +See +: https://developer.android.com/design/ui/wear/guides/surfaces/tiles#tile-previews Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/TileProviderDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/TileProviderDetectorTest.kt) -Copyright Year -: 2021 Tile projects should specify preview resources for different screen shapes. The preview resource is specified in the manifest under tile @@ -38,13 +40,10 @@ Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -AndroidManifest.xml:7:Warning: Tiles need preview assets +AndroidManifest.xml:8:Warning: Tiles need preview assets [SquareAndRoundTilePreviews] - <service ^ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -53,6 +52,7 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="test.pkg"> + <uses-feature android:name="android.hardware.type.watch" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > diff --git a/docs/checks/StartActivityAndCollapseDeprecated.md.html b/docs/checks/StartActivityAndCollapseDeprecated.md.html new file mode 100644 index 00000000..ea6666e4 --- /dev/null +++ b/docs/checks/StartActivityAndCollapseDeprecated.md.html @@ -0,0 +1,134 @@ + +(#) TileService.startActivityAndCollapse(Intent) is deprecated + +!!! ERROR: TileService.startActivityAndCollapse(Intent) is deprecated + This is an error. + +Id +: `StartActivityAndCollapseDeprecated` +Summary +: TileService.startActivityAndCollapse(Intent) is deprecated +Severity +: Error +Category +: Correctness +Platform +: Android +Vendor +: Android Open Source Project +Feedback +: https://issuetracker.google.com/issues/new?component=192708 +Since +: 8.2.0 (November 2023) +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/TileServiceActivityDetector.kt) +Tests +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/TileServiceActivityDetectorTest.kt) + +`TileService#startActivityAndCollapse(Intent)` has been deprecated, and +will throw an `UnsupportedOperationException` if used in apps targeting +Android versions UpsideDownCake and higher. Convert the Intent to a +PendingIntent. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test.kt:6:Error: TileService#startActivityAndCollapse(Intent) is +deprecated. Use TileService#startActivityAndCollapse(PendingIntent) +instead. [StartActivityAndCollapseDeprecated] + tileService.startActivityAndCollapse(intent) // ERROR + ------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +import android.app.PendingIntent +import android.content.Intent +import android.service.quicksettings.TileService + +fun callAMethod(tileService: TileService, intent: Intent) { + tileService.startActivityAndCollapse(intent) // ERROR +} + +fun callAMethod(tileService: TileService, intent: PendingIntent) { + tileService.startActivityAndCollapse(intent) // OK +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/TileServiceActivityDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("StartActivityAndCollapseDeprecated") + fun method() { + startActivityAndCollapse(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("StartActivityAndCollapseDeprecated") + void method() { + startActivityAndCollapse(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection StartActivityAndCollapseDeprecated + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="StartActivityAndCollapseDeprecated" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'StartActivityAndCollapseDeprecated' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore StartActivityAndCollapseDeprecated ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/StateFlowValueCalledInComposition.md.html b/docs/checks/StateFlowValueCalledInComposition.md.html index cd9db7bd..fcd50ecc 100644 --- a/docs/checks/StateFlowValueCalledInComposition.md.html +++ b/docs/checks/StateFlowValueCalledInComposition.md.html @@ -20,6 +20,14 @@ : androidx.compose.runtime Feedback : https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.runtime:runtime-android](androidx_compose_runtime_runtime-android.md.html) +Since +: 1.5.0 Affects : Kotlin and Java files and test sources Editing @@ -43,107 +51,68 @@ src/androidx/compose/runtime/foo/TestFlow.kt:20:Error: StateFlow.value should not be called within composition [StateFlowValueCalledInComposition] - testFlow.value ----- - - src/androidx/compose/runtime/foo/TestFlow.kt:24:Error: StateFlow.value should not be called within composition [StateFlowValueCalledInComposition] - stateFlow.value ----- - - src/androidx/compose/runtime/foo/TestFlow.kt:25:Error: StateFlow.value should not be called within composition [StateFlowValueCalledInComposition] - testFlow.value ----- - - src/androidx/compose/runtime/foo/TestFlow.kt:29:Error: StateFlow.value should not be called within composition [StateFlowValueCalledInComposition] - stateFlow.value ----- - - src/androidx/compose/runtime/foo/TestFlow.kt:30:Error: StateFlow.value should not be called within composition [StateFlowValueCalledInComposition] - testFlow.value ----- - - src/androidx/compose/runtime/foo/TestFlow.kt:39:Error: StateFlow.value should not be called within composition [StateFlowValueCalledInComposition] - stateFlow.value ----- - - src/androidx/compose/runtime/foo/TestFlow.kt:40:Error: StateFlow.value should not be called within composition [StateFlowValueCalledInComposition] - testFlow.value ----- - - src/androidx/compose/runtime/foo/TestFlow.kt:43:Error: StateFlow.value should not be called within composition [StateFlowValueCalledInComposition] - stateFlow.value ----- - - src/androidx/compose/runtime/foo/TestFlow.kt:44:Error: StateFlow.value should not be called within composition [StateFlowValueCalledInComposition] - testFlow.value ----- - - src/androidx/compose/runtime/foo/TestFlow.kt:50:Error: StateFlow.value should not be called within composition [StateFlowValueCalledInComposition] - stateFlow.value ----- - - src/androidx/compose/runtime/foo/TestFlow.kt:51:Error: StateFlow.value should not be called within composition [StateFlowValueCalledInComposition] - testFlow.value ----- - - src/androidx/compose/runtime/foo/TestFlow.kt:55:Error: StateFlow.value should not be called within composition [StateFlowValueCalledInComposition] - stateFlow.value ----- - - src/androidx/compose/runtime/foo/TestFlow.kt:56:Error: StateFlow.value should not be called within composition [StateFlowValueCalledInComposition] - testFlow.value ----- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -218,6 +187,44 @@ To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=612128. +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.runtime:runtime-android:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.runtime:runtime-android:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.runtime.android) + +# libs.versions.toml +[versions] +runtime-android = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +runtime-android = { + module = "androidx.compose.runtime:runtime-android", + version.ref = "runtime-android" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.runtime:runtime-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.runtime:runtime-android](androidx_compose_runtime_runtime-android.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/StateListReachable.md.html b/docs/checks/StateListReachable.md.html index 20a282ca..b351e2ab 100644 --- a/docs/checks/StateListReachable.md.html +++ b/docs/checks/StateListReachable.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -40,11 +42,8 @@ res/drawable/states.xml:3:Warning: This item is unreachable because a previous item (item #1) is a more general match than this one [StateListReachable] - <item android:state_pressed="true" ^ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/StaticFieldLeak.md.html b/docs/checks/StaticFieldLeak.md.html index 7f9d0692..cce4d54e 100644 --- a/docs/checks/StaticFieldLeak.md.html +++ b/docs/checks/StaticFieldLeak.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 2.2.0 (September 2016) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/LeakDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/LeakDetectorTest.kt) -Copyright Year -: 2016 A static field will leak contexts. @@ -49,41 +49,26 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/LeakTest.java:18:Warning: Do not place Android context classes in static fields; this is a memory leak [StaticFieldLeak] - private static Activity sField7; // LEAK! ------ - - src/test/pkg/LeakTest.java:19:Warning: Do not place Android context classes in static fields; this is a memory leak [StaticFieldLeak] - private static Fragment sField8; // LEAK! ------ - - src/test/pkg/LeakTest.java:20:Warning: Do not place Android context classes in static fields; this is a memory leak [StaticFieldLeak] - private static Button sField9; // LEAK! ------ - - src/test/pkg/LeakTest.java:21:Warning: Do not place Android context classes in static fields (static reference to MyObject which has field mActivity pointing to Activity); this is a memory leak [StaticFieldLeak] - private static MyObject sField10; ------ - - src/test/pkg/LeakTest.java:30:Warning: Do not place Android context classes in static fields; this is a memory leak [StaticFieldLeak] - private static Activity sAppContext1; // LEAK ------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/StopShip.md.html b/docs/checks/StopShip.md.html index 879ce981..3d1a0a1c 100644 --- a/docs/checks/StopShip.md.html +++ b/docs/checks/StopShip.md.html @@ -22,6 +22,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Gradle build files, Kotlin and Java files, manifest files, property files and resource files Editing @@ -53,18 +55,12 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/Hidden.java:11:Error: STOPSHIP comment found; points to code which must be fixed prior to release [StopShip] - // STOPSHIP -------- - - src/test/pkg/Hidden.java:12:Error: STOPSHIP comment found; points to code which must be fixed prior to release [StopShip] - /* We must STOPSHIP! */ -------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/StrandhoggVulnerable.md.html b/docs/checks/StrandhoggVulnerable.md.html new file mode 100644 index 00000000..ef8ef8b8 --- /dev/null +++ b/docs/checks/StrandhoggVulnerable.md.html @@ -0,0 +1,170 @@ + +(#) Application vulnerable to Strandhogg attacks + +!!! WARNING: Application vulnerable to Strandhogg attacks + This is a warning. + +Id +: `StrandhoggVulnerable` +Summary +: Application vulnerable to Strandhogg attacks +Severity +: Warning +Category +: Security +Platform +: Android +Vendor +: Google - Android 3P Vulnerability Research +Contact +: https://github.com/google/android-security-lints +Feedback +: https://github.com/google/android-security-lints/issues +Min +: Lint 4.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.android.security.lint:lint](com_android_security_lint_lint.md.html) +Since +: 1.0.1 +Affects +: Manifest files +Editing +: This check runs on the fly in the IDE editor +See +: https://goo.gle/StrandhoggVulnerable +Implementation +: [Source Code](https://github.com/google/android-security-lints/tree/main/checks/src/main/java/com/example/lint/checks/StrandhoggDetector.kt) +Tests +: [Source Code](https://github.com/google/android-security-lints/tree/main/checks/src/test/java/com/example/lint/checks/StrandhoggDetectorTest.kt) +Copyright Year +: 2023 + +Apps targeting SDK versions earlier than 28 are susceptible to +Strandhogg / Task Affinity attacks. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +AndroidManifest.xml:2:Warning: Update your application's target SDK +version to 28 and above to protect it from Strandhogg attacks +[StrandhoggVulnerable] +<uses-sdk android:targetSdkVersion='27'/> + -- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`AndroidManifest.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<manifest xmlns:android='http://schemas.android.com/apk/res/android' package='test.pkg'> +<uses-sdk android:targetSdkVersion='27'/> +<application android:debuggable='false'> + <activity android:name='com.example.MainActivity'></activity> +</application> +</manifest> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/google/android-security-lints/tree/main/checks/src/test/java/com/example/lint/checks/StrandhoggDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `StrandhoggDetector.testWhenTargetSdkBelowStrandhoggPatch_showsWarning`. +To report a problem with this extracted sample, visit +https://github.com/google/android-security-lints/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.android.security.lint:lint:1.0.3") + +// build.gradle +lintChecks 'com.android.security.lint:lint:1.0.3' + +// build.gradle.kts with version catalogs: +lintChecks(libs.com.android.security.lint.lint) + +# libs.versions.toml +[versions] +com-android-security-lint-lint = "1.0.3" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +com-android-security-lint-lint = { + module = "com.android.security.lint:lint", + version.ref = "com-android-security-lint-lint" +} +``` + +1.0.3 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.android.security.lint:lint](com_android_security_lint_lint.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute + `tools:ignore="StrandhoggVulnerable"` on the problematic XML element + (or one of its enclosing elements). You may also need to add the + following namespace declaration on the root element in the XML file + if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <manifest xmlns:tools="http://schemas.android.com/tools"> + ... + <uses-sdk tools:ignore="StrandhoggVulnerable" .../> + ... + </manifest> + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="StrandhoggVulnerable" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'StrandhoggVulnerable' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore StrandhoggVulnerable ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/StringEscaping.md.html b/docs/checks/StringEscaping.md.html index ea8bf73f..5467bf1c 100644 --- a/docs/checks/StringEscaping.md.html +++ b/docs/checks/StringEscaping.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.3.0 (September 2022) Affects : Resource files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/StringEscapeDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/StringEscapeDetectorTest.kt) -Copyright Year -: 2022 Apostrophes (') must always be escaped (with a \\\\), unless they appear in a string which is itself escaped in double quotes (\"). @@ -41,39 +41,24 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/values/strings.xml:3:Error: Apostrophe not preceded by \ [StringEscaping] - <string name="some_string">'ERROR'</string> ^ - - res/values/strings.xml:5:Error: Apostrophe not preceded by \ [StringEscaping] - <string name="some_string3">What's New</string> ^ - - res/values/strings.xml:12:Error: Bad character in \u unicode escape sequence [StringEscaping] - <string name="some_string10">Unicode\u12.</string> ^ - - res/values/strings.xml:19:Error: Apostrophe not preceded by \ [StringEscaping] - <item>It's incorrect</item> ^ - - res/values/strings.xml:23:Error: Apostrophe not preceded by \ [StringEscaping] - <item quantity="few">%d piose'nki.</item> ^ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -105,6 +90,7 @@ <item quantity="few">%d piose'nki.</item> <item quantity="other">%d piosenek.</item> </plurals> +<string name="foo">Letzte Freischaltung:\\ </string> <!-- b/387281249 --> </resources> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/checks/StringFormatCount.md.html b/docs/checks/StringFormatCount.md.html index fa85099f..cbac397e 100644 --- a/docs/checks/StringFormatCount.md.html +++ b/docs/checks/StringFormatCount.md.html @@ -18,12 +18,14 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing : This check can *not* run live in the IDE editor Implementation -: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/StringFormatDetector.java) +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/StringFormatDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/StringFormatDetectorTest.java) Copyright Year @@ -44,11 +46,8 @@ res/values-es/formatstrings.xml:2:Warning: Inconsistent number of arguments in formatting string hello; found both 3 here and 2 in values/formatstrings.xml [StringFormatCount] - <string name="hello">%3$d: %1$s, %2$s?</string> ----------------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here are the relevant source files: diff --git a/docs/checks/StringFormatInTimber.md.html b/docs/checks/StringFormatInTimber.md.html new file mode 100644 index 00000000..b0ae61f2 --- /dev/null +++ b/docs/checks/StringFormatInTimber.md.html @@ -0,0 +1,189 @@ + +(#) Logging call with Timber contains String#format() + +!!! WARNING: Logging call with Timber contains String#format() + This is a warning. + +Id +: `StringFormatInTimber` +Summary +: Logging call with Timber contains String#format() +Severity +: Warning +Category +: Correctness: Messages +Platform +: Any +Vendor +: JakeWharton/timber +Identifier +: com.jakewharton.timber:timber:{version} +Feedback +: https://github.com/JakeWharton/timber/issues +Min +: Lint 4.0 +Compiled +: Lint 7.0 +Artifact +: [com.jakewharton.timber:timber](com_jakewharton_timber_timber.md.html) +Since +: 4.6.0 +Affects +: Kotlin and Java files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/JakeWharton/timber/tree/trunk/timber-lint/src/main/java/timber/lint/WrongTimberUsageDetector.kt) +Tests +: [Source Code](https://github.com/JakeWharton/timber/tree/trunk/timber-lint/src/test/java/timber/lint/WrongTimberUsageDetectorTest.kt) + +Since Timber handles String.format automatically, you may not use +String#format(). + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/foo/Example.java:5:Warning: Using 'String#format' inside of 'Timber' +[StringFormatInTimber] + Timber.d(String.format("%s", "arg1")); + --------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`src/foo/Example.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package foo; +import timber.log.Timber; +public class Example { + public void log() { + Timber.d(String.format("%s", "arg1")); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/foo/Example.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package foo +import timber.log.Timber +class Example { + fun log() { + Timber.d(String.format("%s", "arg1")) + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/JakeWharton/timber/tree/trunk/timber-lint/src/test/java/timber/lint/WrongTimberUsageDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `WrongTimberUsageDetector.innerStringFormat`. +To report a problem with this extracted sample, visit +https://github.com/JakeWharton/timber/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +implementation("com.jakewharton.timber:timber:5.0.1") + +// build.gradle +implementation 'com.jakewharton.timber:timber:5.0.1' + +// build.gradle.kts with version catalogs: +implementation(libs.timber) + +# libs.versions.toml +[versions] +timber = "5.0.1" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +timber = { + module = "com.jakewharton.timber:timber", + version.ref = "timber" +} +``` + +5.0.1 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.jakewharton.timber:timber](com_jakewharton_timber_timber.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("StringFormatInTimber") + fun method() { + tag(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("StringFormatInTimber") + void method() { + tag(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection StringFormatInTimber + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="StringFormatInTimber" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'StringFormatInTimber' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore StringFormatInTimber ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/StringFormatInvalid.md.html b/docs/checks/StringFormatInvalid.md.html index 7975bd2a..39e2585f 100644 --- a/docs/checks/StringFormatInvalid.md.html +++ b/docs/checks/StringFormatInvalid.md.html @@ -18,12 +18,14 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing : This check can *not* run live in the IDE editor Implementation -: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/StringFormatDetector.java) +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/StringFormatDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/StringFormatDetectorTest.java) Copyright Year @@ -55,11 +57,8 @@ src/StringFormatInvalid.java:3:Error: Format string 'no_args' is not a valid format string so it should not be passed to String.format [StringFormatInvalid] - context.getString(R.string.no_args, "first"); // ERROR -------------------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here are the relevant source files: diff --git a/docs/checks/StringFormatMatches.md.html b/docs/checks/StringFormatMatches.md.html index 96f62be0..023a3168 100644 --- a/docs/checks/StringFormatMatches.md.html +++ b/docs/checks/StringFormatMatches.md.html @@ -18,12 +18,14 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files and resource files Editing : This check runs on the fly in the IDE editor Implementation -: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/StringFormatDetector.java) +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/StringFormatDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/StringFormatDetectorTest.java) Copyright Year @@ -44,11 +46,8 @@ argument '#1' in score: conversion is 'd', received boolean (argument #2 in method call) (Did you mean formatting character b?) [StringFormatMatches] - String output4 = String.format(score, true); // wrong ---- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here are the relevant source files: diff --git a/docs/checks/StringFormatTrivial.md.html b/docs/checks/StringFormatTrivial.md.html index 3b7f461e..e646e5e3 100644 --- a/docs/checks/StringFormatTrivial.md.html +++ b/docs/checks/StringFormatTrivial.md.html @@ -20,16 +20,16 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.3.0 (September 2022) Affects : Kotlin and Java files and resource files Editing : This check runs on the fly in the IDE editor Implementation -: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/StringFormatDetector.java) +: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/StringFormatDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/StringFormatDetectorTest.java) -Copyright Year -: 2011 Every call to `String.format` creates a new `Formatter` instance, which will decrease the performance of your app. `String.format` should only @@ -44,30 +44,21 @@ src/test/pkg/Trivial.java:10:Warning: This formatting string is trivial. Rather than using String.format to create your String, it will be more performant to concatenate your arguments with +. [StringFormatTrivial] - String output1a = String.format("%s", "Hello world"); ---- - - src/test/pkg/Trivial.java:11:Warning: This formatting string is trivial. Rather than using String.format to create your String, it will be more performant to concatenate your arguments with +. [StringFormatTrivial] - String output2a = String.format("%s %c", "Hello world", '!'); ------- - - src/test/pkg/Trivial.java:12:Warning: This formatting string is trivial. Rather than using String.format to create your String, it will be more performant to concatenate your arguments with +. [StringFormatTrivial] - String output3a = String.format("%s %c %b", "Hello world", '!', true); ---------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here is the source file referenced above: +Here are the relevant source files: `src/test/pkg/Trivial.java`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers @@ -98,6 +89,17 @@ } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`res/values/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<resources> + <string name="trivial1">%s</string> + <string name="trivial2">%s %c</string> + <string name="trivial3">%s %c %b</string> +</resources> + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/StringFormatDetectorTest.java) for the unit tests for this check to see additional scenarios. diff --git a/docs/checks/StringNotCapitalized.md.html b/docs/checks/StringNotCapitalized.md.html new file mode 100644 index 00000000..6c1a26c2 --- /dev/null +++ b/docs/checks/StringNotCapitalized.md.html @@ -0,0 +1,159 @@ + +(#) Marks strings which are not capitalized + +!!! WARNING: Marks strings which are not capitalized + This is a warning. + +Id +: `StringNotCapitalized` +Summary +: Marks strings which are not capitalized +Severity +: Warning +Category +: Correctness +Platform +: Android +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html) +Since +: 0.24.0 +Affects +: Resource files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/main/kotlin/com/vanniktech/lintrules/android/StringNotCapitalizedDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/StringNotCapitalizedDetectorTest.kt) + +Every string should be capitalized. If not, it is flagged. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +res/values/strings.xml:2:Warning: String is not capitalized +[StringNotCapitalized] + <string name="my_string">my string</string> + ^ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`res/values/strings.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<resources> + <string name="my_string">my string</string> +</resources> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/StringNotCapitalizedDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `StringNotCapitalizedDetector.lowercase`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-android:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-android:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.android) + +# libs.versions.toml +[versions] +lint-rules-android = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-android = { + module = "com.vanniktech:lint-rules-android", + version.ref = "lint-rules-android" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute + `tools:ignore="StringNotCapitalized"` on the problematic XML element + (or one of its enclosing elements). You may also need to add the + following namespace declaration on the root element in the XML file + if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <resources xmlns:tools="http://schemas.android.com/tools"> + ... + <string tools:ignore="StringNotCapitalized" .../> + ... + </resources> + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="StringNotCapitalized" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'StringNotCapitalized' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore StringNotCapitalized ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/StringShouldBeInt.md.html b/docs/checks/StringShouldBeInt.md.html index 1a46dae5..59649f08 100644 --- a/docs/checks/StringShouldBeInt.md.html +++ b/docs/checks/StringShouldBeInt.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Gradle build files Editing @@ -47,32 +49,20 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text build.gradle:4:Error: Use an integer rather than a string here (replace '19' with just 19) [StringShouldBeInt] - compileSdkVersion '19' ---------------------- - - build.gradle:7:Error: Use an integer rather than a string here (replace '8' with just 8) [StringShouldBeInt] - minSdkVersion '8' ----------------- - - build.gradle:8:Error: Use an integer rather than a string here (replace "16" with just 16) [StringShouldBeInt] - targetSdkVersion "16" --------------------- - - build.gradle:10:Error: Use an integer rather than a string here (replace '19' with just 19) [StringShouldBeInt] - compileSdk '19' --------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/SubscribeOnMain.md.html b/docs/checks/SubscribeOnMain.md.html new file mode 100644 index 00000000..a21db40c --- /dev/null +++ b/docs/checks/SubscribeOnMain.md.html @@ -0,0 +1,205 @@ + +(#) subscribeOn called with the main thread scheduler + +!!! ERROR: subscribeOn called with the main thread scheduler + This is an error. + +Id +: `SubscribeOnMain` +Summary +: subscribeOn called with the main thread scheduler +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.1.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/rx/RxSubscribeOnMainDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/rx/RxSubscribeOnMainDetectorTest.kt) +Copyright Year +: 2021 + +Calling `subscribeOn(AndroidSchedulers.mainThread())` will cause the +code ran at subscription time to be executed on the main thread - that +is, code above this line. +Typically this is not actually desired, and instead you want to use +observeOn(AndroidSchedulers.mainThread()) which will cause the code +below this line to be run on the main thread (eg the code inside your +subscribe() block). + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/com/slack/lint/Foo.java:8:Error: This will make the code for the +initial subscription (above this line) run on the main thread. You +probably want observeOn(AndroidSchedulers.mainThread()). +[SubscribeOnMain] + obs.subscribeOn(AndroidSchedulers.mainThread()); + ------------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here are the relevant source files: + +`src/io/reactivex/rxjava3/android/schedulers/AndroidSchedulers.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package io.reactivex.rxjava3.android.schedulers; + +import io.reactivex.rxjava3.core.Scheduler; + +public final class AndroidSchedulers { + public static Scheduler mainThread() { + return null; + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`src/com/slack/lint/Foo.java`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers +package com.slack.lint; + +import io.reactivex.rxjava3.core.Observable; +import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers; + +public class Foo { + public void bar(Observable obs) { + obs.subscribeOn(AndroidSchedulers.mainThread()); + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/rx/RxSubscribeOnMainDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `RxSubscribeOnMainDetector.subscribeOnMain_fullyQualified_fails_java`. +To report a problem with this extracted sample, visit +https://github.com/slackhq/slack-lints. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("SubscribeOnMain") + fun method() { + subscribeOn(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("SubscribeOnMain") + void method() { + subscribeOn(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection SubscribeOnMain + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="SubscribeOnMain" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'SubscribeOnMain' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore SubscribeOnMain ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/SuperfluousMarginDeclaration.md.html b/docs/checks/SuperfluousMarginDeclaration.md.html new file mode 100644 index 00000000..3b605730 --- /dev/null +++ b/docs/checks/SuperfluousMarginDeclaration.md.html @@ -0,0 +1,154 @@ + +(#) Flags margin declarations that can be simplified + +!!! WARNING: Flags margin declarations that can be simplified + This is a warning. + +Id +: `SuperfluousMarginDeclaration` +Summary +: Flags margin declarations that can be simplified +Severity +: Warning +Category +: Correctness +Platform +: Android +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html) +Since +: 0.6.0 +Affects +: Resource files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/main/kotlin/com/vanniktech/lintrules/android/SuperfluousMarginDeclarationDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/SuperfluousMarginDeclarationDetectorTest.kt) + +Instead of using start-, end-, bottom- and top margins, layout_margin +can be used. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +res/layout/ids.xml:1:Warning: Should be using layout_margin instead. +[SuperfluousMarginDeclaration] +<TextView +^ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`res/layout/ids.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<TextView + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_marginTop="16dp" + android:layout_marginBottom="16dp" + android:layout_marginStart="16dp" + android:layout_marginEnd="16dp"/> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/SuperfluousMarginDeclarationDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `SuperfluousMarginDeclarationDetector.androidMarginSame`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-android:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-android:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.android) + +# libs.versions.toml +[versions] +lint-rules-android = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-android = { + module = "com.vanniktech:lint-rules-android", + version.ref = "lint-rules-android" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute + `tools:ignore="SuperfluousMarginDeclaration"` on the problematic XML + element (or one of its enclosing elements). You may also need to add + the following namespace declaration on the root element in the XML + file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="SuperfluousMarginDeclaration" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'SuperfluousMarginDeclaration' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore SuperfluousMarginDeclaration ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/SuperfluousNameSpace.md.html b/docs/checks/SuperfluousNameSpace.md.html new file mode 100644 index 00000000..f3815012 --- /dev/null +++ b/docs/checks/SuperfluousNameSpace.md.html @@ -0,0 +1,152 @@ + +(#) Flags namespaces that are already declared + +!!! WARNING: Flags namespaces that are already declared + This is a warning. + +Id +: `SuperfluousNameSpace` +Summary +: Flags namespaces that are already declared +Severity +: Warning +Category +: Correctness +Platform +: Android +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html) +Since +: 0.6.0 +Affects +: Resource files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/main/kotlin/com/vanniktech/lintrules/android/SuperfluousNameSpaceDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/SuperfluousNameSpaceDetectorTest.kt) + +Re-declaring a namespace is unnecessary and hence can be just removed. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +res/layout/activity_home.xml:3:Warning: This name space is already +declared and hence not needed [SuperfluousNameSpace] + xmlns:android="http://schemas.android.com/apk/res/android" + ---------------------------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`res/layout/activity_home.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"> + <TextView + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="wrap_content"/> +</LinearLayout> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/SuperfluousNameSpaceDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `SuperfluousNameSpaceDetector.androidNamespaceOnChild`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-android:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-android:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.android) + +# libs.versions.toml +[versions] +lint-rules-android = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-android = { + module = "com.vanniktech:lint-rules-android", + version.ref = "lint-rules-android" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute + `tools:ignore="SuperfluousNameSpace"` on the problematic XML element + (or one of its enclosing elements). You may also need to add the + following namespace declaration on the root element in the XML file + if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="SuperfluousNameSpace" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'SuperfluousNameSpace' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore SuperfluousNameSpace ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/SuperfluousPaddingDeclaration.md.html b/docs/checks/SuperfluousPaddingDeclaration.md.html new file mode 100644 index 00000000..4ca9171d --- /dev/null +++ b/docs/checks/SuperfluousPaddingDeclaration.md.html @@ -0,0 +1,154 @@ + +(#) Flags padding declarations that can be simplified + +!!! WARNING: Flags padding declarations that can be simplified + This is a warning. + +Id +: `SuperfluousPaddingDeclaration` +Summary +: Flags padding declarations that can be simplified +Severity +: Warning +Category +: Correctness +Platform +: Android +Vendor +: vanniktech/lint-rules/ +Feedback +: https://github.com/vanniktech/lint-rules/issues +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html) +Since +: 0.6.0 +Affects +: Resource files +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/main/kotlin/com/vanniktech/lintrules/android/SuperfluousPaddingDeclarationDetector.kt) +Tests +: [Source Code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/SuperfluousPaddingDeclarationDetectorTest.kt) + +Instead of using start-, end-, bottom- and top paddings, padding can be +used. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +res/layout/ids.xml:1:Warning: Should be using padding instead. +[SuperfluousPaddingDeclaration] +<TextView +^ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`res/layout/ids.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<TextView + xmlns:android="http://schemas.android.com/apk/res/android" + android:paddingTop="16dp" + android:paddingBottom="16dp" + android:paddingStart="16dp" + android:paddingEnd="16dp"/> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/vanniktech/lint-rules/tree/master/lint-rules-android-lint/src/test/kotlin/com/vanniktech/lintrules/android/SuperfluousPaddingDeclarationDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `SuperfluousPaddingDeclarationDetector.androidPaddingSame`. +To report a problem with this extracted sample, visit +https://github.com/vanniktech/lint-rules/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.vanniktech:lint-rules-android:0.25.0") + +// build.gradle +lintChecks 'com.vanniktech:lint-rules-android:0.25.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.lint.rules.android) + +# libs.versions.toml +[versions] +lint-rules-android = "0.25.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lint-rules-android = { + module = "com.vanniktech:lint-rules-android", + version.ref = "lint-rules-android" +} +``` + +0.25.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.vanniktech:lint-rules-android](com_vanniktech_lint-rules-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute + `tools:ignore="SuperfluousPaddingDeclaration"` on the problematic + XML element (or one of its enclosing elements). You may also need to + add the following namespace declaration on the root element in the + XML file if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="SuperfluousPaddingDeclaration" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'SuperfluousPaddingDeclaration' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore SuperfluousPaddingDeclaration ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/SupportAnnotationUsage.md.html b/docs/checks/SupportAnnotationUsage.md.html index a9edbff7..44d5d0e4 100644 --- a/docs/checks/SupportAnnotationUsage.md.html +++ b/docs/checks/SupportAnnotationUsage.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 2.2.0 (September 2016) Affects : Kotlin and Java files Editing @@ -26,14 +28,15 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AnnotationDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AnnotationDetectorTest.kt) -Copyright Year -: 2012 This lint check makes sure that the support annotations (such as `@IntDef` and `@ColorInt`) are used correctly. For example, it's an error to specify an `@IntRange` where the `from` value is higher than the `to` value. +!!! Tip + This lint check has an associated quickfix available in the IDE. + (##) Example Here is an example of lint warnings produced by this check: @@ -42,19 +45,13 @@ @java.lang.annotation.Target here; these targets will be ignored from Kotlin and the annotation will not be allowed on any element types from Java [SupportAnnotationUsage] - @java.lang.annotation.Target(ElementType.PARAMETER) // ERROR 1 ------ - - src/test/pkg/Annotation1.kt:19:Error: Do not use @java.lang.annotation.Target here; it will cause the annotation to not be allowed on any element types from Java [SupportAnnotationUsage] - @java.lang.annotation.Target(ElementType.PARAMETER) // ERROR 2 ------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/Suspicious0dp.md.html b/docs/checks/Suspicious0dp.md.html index bd49c157..919e8905 100644 --- a/docs/checks/Suspicious0dp.md.html +++ b/docs/checks/Suspicious0dp.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -43,39 +45,24 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/wrong0dp.xml:19:Error: Suspicious size: this will make the view invisible, should be used with layout_weight [Suspicious0dp] - android:layout_width="0dp" -------------------------- - - res/layout/wrong0dp.xml:25:Error: Suspicious size: this will make the view invisible, should be used with layout_weight [Suspicious0dp] - android:layout_height="0dp" --------------------------- - - res/layout/wrong0dp.xml:34:Error: Suspicious size: this will make the view invisible, probably intended for layout_height [Suspicious0dp] - android:layout_width="0dp" -------------------------- - - res/layout/wrong0dp.xml:67:Error: Suspicious size: this will make the view invisible, probably intended for layout_width [Suspicious0dp] - android:layout_height="0dp" --------------------------- - - res/layout/wrong0dp.xml:90:Error: Suspicious size: this will make the view invisible, probably intended for layout_width [Suspicious0dp] - android:layout_height="0dp" --------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/SuspiciousCompositionLocalModifierRead.md.html b/docs/checks/SuspiciousCompositionLocalModifierRead.md.html new file mode 100644 index 00000000..9f655ac6 --- /dev/null +++ b/docs/checks/SuspiciousCompositionLocalModifierRead.md.html @@ -0,0 +1,215 @@ + +(#) CompositionLocals should not be read in Modifier.onAttach() or Modifier.onDetach() + +!!! ERROR: CompositionLocals should not be read in Modifier.onAttach() or Modifier.onDetach() + This is an error. + +Id +: `SuspiciousCompositionLocalModifierRead` +Summary +: CompositionLocals should not be read in Modifier.onAttach() or Modifier.onDetach() +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: Jetpack Compose +Identifier +: androidx.compose.ui +Feedback +: https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.ui:ui-android](androidx_compose_ui_ui-android.md.html) +Since +: 1.5.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/ui/ui-lint/src/main/java/androidx/compose/ui/lint/SuspiciousCompositionLocalModifierReadDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/ui/ui-lint/src/test/java/androidx/compose/ui/lint/SuspiciousCompositionLocalModifierReadDetectorTest.kt) +Copyright Year +: 2023 + +Jetpack Compose is unable to send updated values of a CompositionLocal +when it's read in a Modifier.Node's initializer and onAttach() or +onDetach() callbacks. Modifier.Node's callbacks are not aware of +snapshot reads, and their lifecycle callbacks are not invoked on every +recomposition. If you read a CompositionLocal in onAttach() or +onDetach(), you will only get the CompositionLocal's value once at the +moment of the read, which may lead to unexpected behaviors. We recommend +instead reading CompositionLocals at time-of-use in callbacks that apply +your Modifier's behavior, like measure() for LayoutModifierNode, draw() +for DrawModifierNode, and so on. To observe the value of the +CompositionLocal manually, extend from the ObserverNode interface and +place the read inside an observeReads {} block within the +onObservedReadsChanged() callback. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test/NodeUnderTest.kt:16:Error: Reading localInt in onAttach will +only access the CompositionLocal's value when the modifier is attached. +To be notified of the latest value of the CompositionLocal, read the +value in one of the modifier's other callbacks. +[SuspiciousCompositionLocalModifierRead] + val readValue = currentValueOf(localInt) + ------------------------ +src/test/NodeUnderTest.kt:20:Error: Reading staticLocalInt in onDetach +will only access the CompositionLocal's value when the modifier is +detached. To be notified of the latest value of the CompositionLocal, +read the value in one of the modifier's other callbacks. +[SuspiciousCompositionLocalModifierRead] + val readValue = currentValueOf(staticLocalInt) + ------------------------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test/NodeUnderTest.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test + +import androidx.compose.ui.Modifier +import androidx.compose.ui.node.CompositionLocalConsumerModifierNode +import androidx.compose.ui.node.currentValueOf +import androidx.compose.runtime.CompositionLocal +import androidx.compose.runtime.compositionLocalOf +import androidx.compose.runtime.staticCompositionLocalOf + +val staticLocalInt = staticCompositionLocalOf { 0 } +val localInt = compositionLocalOf { 0 } + +class NodeUnderTest : Modifier.Node(), CompositionLocalConsumerModifierNode { + override fun onAttach() { + val readValue = currentValueOf(localInt) + } + + override fun onDetach() { + val readValue = currentValueOf(staticLocalInt) + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/ui/ui-lint/src/test/java/androidx/compose/ui/lint/SuspiciousCompositionLocalModifierReadDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `SuspiciousCompositionLocalModifierReadDetector.testCompositionLocalReadInModifierAttachAndDetach`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=612128. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.ui:ui-android:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.ui:ui-android:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.ui.android) + +# libs.versions.toml +[versions] +ui-android = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +ui-android = { + module = "androidx.compose.ui:ui-android", + version.ref = "ui-android" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.ui:ui-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.ui:ui-android](androidx_compose_ui_ui-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("SuspiciousCompositionLocalModifierRead") + fun method() { + currentValueOf(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("SuspiciousCompositionLocalModifierRead") + void method() { + currentValueOf(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection SuspiciousCompositionLocalModifierRead + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="SuspiciousCompositionLocalModifierRead" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'SuspiciousCompositionLocalModifierRead' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore SuspiciousCompositionLocalModifierRead ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/SuspiciousImport.md.html b/docs/checks/SuspiciousImport.md.html index 77bb219e..c847be91 100644 --- a/docs/checks/SuspiciousImport.md.html +++ b/docs/checks/SuspiciousImport.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Kotlin and Java files Editing @@ -43,11 +45,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/BadImport.java:5:Warning: Don't include android.R here; use a fully qualified name for each usage instead [SuspiciousImport] - import android.R; ----------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/SuspiciousIndentation.md.html b/docs/checks/SuspiciousIndentation.md.html index c54c98d5..9f015ff0 100644 --- a/docs/checks/SuspiciousIndentation.md.html +++ b/docs/checks/SuspiciousIndentation.md.html @@ -6,8 +6,6 @@ Id : `SuspiciousIndentation` -Alias -: SuspiciousIndentAfterControlStatement Summary : Suspicious indentation Severity @@ -20,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.3.0 (September 2022) Affects : Kotlin and Java files Editing @@ -28,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/IndentationDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/IndentationDetectorTest.kt) -Copyright Year -: 2021 This check looks for cases where the indentation suggests a grouping that isn't actually there in the code. A common example of this would be @@ -67,107 +65,19 @@ Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -src/Java.java:4:Error: Suspicious indentation: This is conditionally -executed; expected it to be indented [SuspiciousIndentation] - - System.out.println("test"); // WARN 1 - -------------------------- - - -src/Java.java:7:Error: Suspicious indentation: This is indented but is -not nested under the previous expression (if (context == null)...) -[SuspiciousIndentation] - - System.out.println("test"); // WARN 2 - -------------------------- - - src/Kotlin.kt:8:Error: Suspicious indentation: This is indented but is not nested under the previous expression (if (this[i] == '\n')...) [SuspiciousIndentation] - - line++ // WARN 3 + line++ // WARN1 ------ - - src/Kotlin.kt:15:Error: Suspicious indentation: This is indented but is not continuing the previous expression (var s = "The price i...) [SuspiciousIndentation] - - price.toString() + // WARN 4 + price.toString() + // WARN 2 ---------------------------- - - -src/Kotlin.kt:23:Error: Suspicious indentation: This is indented but is -not continuing the previous expression (s += "The price...) -[SuspiciousIndentation] - - price.toString() + // WARN 5 - ---------------------------- - - -src/Kotlin.kt:32:Error: Suspicious indentation: This is indented but is -not continuing the previous expression (s = "The price was...) -[SuspiciousIndentation] - - price.toString() + // WARN 6 - ---------------------------- - - -src/Kotlin.kt:42:Error: Suspicious indentation: This is indented but is -not nested under the previous expression (for (i in 0 until 10...) -[SuspiciousIndentation] - - y++ // WARN 7 - --- - - -src/Kotlin.kt:48:Error: Suspicious indentation: This is indented but is -not nested under the previous expression (while (x > 0) ...) -[SuspiciousIndentation] - - y++ // WARN 8 - --- - - -src/Kotlin.kt:55:Error: Suspicious indentation: This is conditionally -executed; expected it to be indented [SuspiciousIndentation] - - println("hello") // WARN 9 - ---------------- - - -src/Kotlin.kt:62:Error: Suspicious indentation: This is conditionally -executed; expected it to be indented [SuspiciousIndentation] - - println("hello") // WARN 10 - ---------------- - - -src/Kotlin.kt:73:Error: Suspicious indentation: This is indented but is -not nested under the previous expression (if (this[i] != '\n')...) -[SuspiciousIndentation] - - line++ // WARN 11 - ------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here are the relevant source files: - -`src/Java.java`: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers -class Java { - public void test(Object context) { - if (context == null) - System.out.println("test"); // WARN 1 - if (context == null) - System.out.println("test"); // OK - System.out.println("test"); // WARN 2 - } -} -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Here is the source file referenced above: `src/Kotlin.kt`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers @@ -178,75 +88,16 @@ column++ if (this[i] == '\n') column = 0 - line++ // WARN 3 + line++ // WARN1 } return Pair(line, column) } -fun getFooter1(price: Int) { - var s = "The price is: " // missing + - price.toString() + // WARN 4 +fun getPriceString(price: Int) { + var s = "The price is: " + price.toString() + // WARN 2 "." } - -fun getFooter2(price: Int) { - var s = "" - if (price > 100) { - s += "The price " // missing + - price.toString() + // WARN 5 - " is high." - } -} - -fun getFooter3(price: Int) { - var s = "" - if (price < 1000) { - s = "The price was " // missing + - price.toString() + // WARN 6 - "." - } -} - -fun loops1() { - var x = 0 - var y = 0 - for (i in 0 until 100) - x++ - y++ // WARN 7 -} - -fun loops2() { - while (x > 0) - x-- - y++ // WARN 8 -} - -fun expectedIndent1(x: Int) { - if (x > 10) - println("hello") // OK - if (x < 10) - println("hello") // WARN 9 -} - -fun expectedIndent2(x: Int) { - if (x < 10) - println("hello") - else - println("hello") // WARN 10 -} - -fun String.getLineAndColumn2(offset: Int): Pair { - var line = 1 - var column = 1 - for (i in 0 until offset) { - column++ - if (this[i] != '\n') { - } else - column = 0 - line++ // WARN 11 - } - return Pair(line, column) -} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can also visit the diff --git a/docs/checks/SuspiciousModifierThen.md.html b/docs/checks/SuspiciousModifierThen.md.html new file mode 100644 index 00000000..16d52a61 --- /dev/null +++ b/docs/checks/SuspiciousModifierThen.md.html @@ -0,0 +1,205 @@ + +(#) Using Modifier.then with a Modifier factory function with an implicit receiver + +!!! ERROR: Using Modifier.then with a Modifier factory function with an implicit receiver + This is an error. + +Id +: `SuspiciousModifierThen` +Summary +: Using Modifier.then with a Modifier factory function with an implicit receiver +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: Jetpack Compose +Identifier +: androidx.compose.ui +Feedback +: https://issuetracker.google.com/issues/new?component=612128 +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.ui:ui-android](androidx_compose_ui_ui-android.md.html) +Since +: 1.7.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/ui/ui-lint/src/main/java/androidx/compose/ui/lint/SuspiciousModifierThenDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/ui/ui-lint/src/test/java/androidx/compose/ui/lint/SuspiciousModifierThenDetectorTest.kt) +Copyright Year +: 2024 + +Calling a Modifier factory function with an implicit receiver inside +Modifier.then will result in the receiver (`this`) being added twice to +the chain. For example, fun Modifier.myModifier() = +this.then(otherModifier()) - the implementation of factory functions +such as Modifier.otherModifier() will internally call this.then(...) to +chain the provided modifier with their implementation. When you expand +this.then(otherModifier()), it becomes: +this.then(this.then(OtherModifierImplementation)) - so you can see that +`this` is included twice in the chain, which results in modifiers such +as padding being applied twice, for example. Instead, you should either +remove the then() and directly chain the factory function on the +receiver, this.otherModifier(), or add the empty Modifier as the +receiver for the factory, such as this.then(Modifier.otherModifier()) + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/test/TestModifier.kt:10:Error: Using Modifier.then with a Modifier +factory function with an implicit receiver [SuspiciousModifierThen] + fun Modifier.test2() = this.then(test()) + ---- +src/test/TestModifier.kt:12:Error: Using Modifier.then with a Modifier +factory function with an implicit receiver [SuspiciousModifierThen] + fun Modifier.test3() = this.then(with(1) { test() }) + ---- +src/test/TestModifier.kt:14:Error: Using Modifier.then with a Modifier +factory function with an implicit receiver [SuspiciousModifierThen] + fun Modifier.test4() = this.then(if (true) test() else TestModifier) + ---- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/test/TestModifier.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package test + +import androidx.compose.ui.Modifier + +object TestModifier : Modifier.Element + +fun Modifier.test(): Modifier = this.then(TestModifier) + +fun Modifier.test2() = this.then(test()) + +fun Modifier.test3() = this.then(with(1) { test() }) + +fun Modifier.test4() = this.then(if (true) test() else TestModifier) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/ui/ui-lint/src/test/java/androidx/compose/ui/lint/SuspiciousModifierThenDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `SuspiciousModifierThenDetector.errors`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=612128. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.ui:ui-android:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.ui:ui-android:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.ui.android) + +# libs.versions.toml +[versions] +ui-android = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +ui-android = { + module = "androidx.compose.ui:ui-android", + version.ref = "ui-android" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.ui:ui-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.ui:ui-android](androidx_compose_ui_ui-android.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("SuspiciousModifierThen") + fun method() { + then(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("SuspiciousModifierThen") + void method() { + then(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection SuspiciousModifierThen + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="SuspiciousModifierThen" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'SuspiciousModifierThen' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore SuspiciousModifierThen ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/SwitchIntDef.md.html b/docs/checks/SwitchIntDef.md.html index e824b901..936a0ece 100644 --- a/docs/checks/SwitchIntDef.md.html +++ b/docs/checks/SwitchIntDef.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 2.0.0 (April 2016) Affects : Kotlin and Java files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AnnotationDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AnnotationDetectorTest.kt) -Copyright Year -: 2012 This check warns if a `switch` statement does not explicitly include all the values declared by the typedef `@IntDef` declaration. @@ -41,61 +41,33 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/X.java:40:Warning: Don't use a constant here; expected one of: LENGTH_INDEFINITE, LENGTH_LONG, LENGTH_SHORT [SwitchIntDef] - case 5: - - - src/test/pkg/X.java:47:Warning: Switch statement on an int with known associated constant missing case LENGTH_LONG [SwitchIntDef] - switch (duration) { ------ - - src/test/pkg/X.java:56:Warning: Switch statement on an int with known associated constant missing case LENGTH_INDEFINITE, LENGTH_LONG, LENGTH_SHORT [SwitchIntDef] - switch (duration) { ------ - - src/test/pkg/X.java:66:Warning: Switch statement on an int with known associated constant missing case LENGTH_SHORT [SwitchIntDef] - switch (duration) { ------ - - src/test/pkg/X.java:75:Warning: Switch statement on an int with known associated constant missing case LENGTH_SHORT [SwitchIntDef] - switch ((int)getDuration()) { ------ - - src/test/pkg/X.java:85:Warning: Switch statement on an int with known associated constant missing case LENGTH_SHORT [SwitchIntDef] - switch (true ? getDuration() : 0) { ------ - - src/test/pkg/X.java:95:Warning: Switch statement on an int with known associated constant missing case X.LENGTH_SHORT [SwitchIntDef] - switch (X.getDuration()) { ------ - - -src/test/pkg/X.java:104:Warning: Switch statement on an int with known -associated constant missing case LENGTH_INDEFINITE [SwitchIntDef] - - switch (duration) { - ------ - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -205,7 +177,7 @@ } public static void testMissingWithDefault(@Duration int duration) { - switch (duration) { + switch (duration) { // OK case LENGTH_SHORT: case LENGTH_LONG: default: @@ -215,7 +187,7 @@ @SuppressLint("SwitchIntDef") public static void testSuppressAnnotation(@Duration int duration) { - switch (duration) { + switch (duration) { // OK case LENGTH_SHORT: case LENGTH_INDEFINITE: break; @@ -224,7 +196,7 @@ public static void testSuppressComment(@Duration int duration) { //noinspection AndroidLintSwitchIntDef - switch (duration) { + switch (duration) { // OK case LENGTH_SHORT: case LENGTH_INDEFINITE: break; diff --git a/docs/checks/SyntheticAccessor.md.html b/docs/checks/SyntheticAccessor.md.html index f0218c42..94975430 100644 --- a/docs/checks/SyntheticAccessor.md.html +++ b/docs/checks/SyntheticAccessor.md.html @@ -6,10 +6,6 @@ Id : `SyntheticAccessor` -Alias -: SyntheticAccessorCall -Alias -: PrivateMemberAccessBetweenOuterAndInnerClass Summary : Synthetic Accessor Note @@ -24,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.2.0 (September 2018) Affects : Kotlin and Java files Editing @@ -32,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/SyntheticAccessorDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/SyntheticAccessorDetectorTest.kt) -Copyright Year -: 2018 A private inner class which is accessed from the outer class will force the compiler to insert a synthetic accessor; this means that you are @@ -52,62 +48,38 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/AccessTest.java:33:Warning: Access to private constructor of class AccessTest requires synthetic accessor [SyntheticAccessor] - new AccessTest(); // ERROR ---------------- - - src/test/pkg/AccessTest.java:36:Warning: Access to private field field1 of class AccessTest requires synthetic accessor [SyntheticAccessor] - int f1 = field1; // ERROR ------ - - src/test/pkg/AccessTest.java:40:Warning: Access to private field field5 of class AccessTest requires synthetic accessor [SyntheticAccessor] - Inner[] f5 = field5; // ERROR ------ - - src/test/pkg/AccessTest.java:42:Warning: Access to private method method1 of class AccessTest requires synthetic accessor [SyntheticAccessor] - method1(); // ERROR ------- - - src/test/pkg/AccessTest.java:66:Warning: Access to private constructor of class AccessTest requires synthetic accessor [SyntheticAccessor] - new AccessTest(); // ERROR ---------------- - - src/test/pkg/AccessTest.java:69:Warning: Access to private field field1 of class AccessTest requires synthetic accessor [SyntheticAccessor] - int f1 = field1; // ERROR ------ - - src/test/pkg/AccessTest.java:73:Warning: Access to private field field5 of class AccessTest requires synthetic accessor [SyntheticAccessor] - Inner[] f5 = field5; // ERROR ------ - - src/test/pkg/AccessTest.java:75:Warning: Access to private method method1 of class AccessTest requires synthetic accessor [SyntheticAccessor] - method1(); // ERROR ------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/SystemPermissionTypo.md.html b/docs/checks/SystemPermissionTypo.md.html index 903b7f63..fc3b6de6 100644 --- a/docs/checks/SystemPermissionTypo.md.html +++ b/docs/checks/SystemPermissionTypo.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 7.4.0 (January 2023) Affects : Manifest files Editing @@ -26,8 +28,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/PermissionErrorDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/PermissionErrorDetectorTest.kt) -Copyright Year -: 2022 This check looks for required permissions that *look* like well-known system permissions or permissions from the Android SDK, but aren't, and @@ -35,59 +35,41 @@ Please double check the permission value you have supplied. +!!! Tip + This lint check has an associated quickfix available in the IDE. + (##) Example Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text AndroidManifest.xml:5:Warning: Did you mean android.permission.BIND_NFC_SERVICE? [SystemPermissionTypo] - <uses-permission android:name="android.permission.BIND_NCF_SERVICE" /> ----------------------------------- - - AndroidManifest.xml:6:Warning: Did you mean android.permission.BIND_NFC_SERVICE? [SystemPermissionTypo] - <application android:name="App" android:permission="android.permission.BIND_NCF_SERVICE"> ----------------------------------- - - AndroidManifest.xml:9:Warning: Did you mean android.permission.BIND_NFC_SERVICE? [SystemPermissionTypo] - <activity android:permission="android.permission.BIND_NCF_SERVICE" /> ----------------------------------- - - AndroidManifest.xml:10:Warning: Did you mean android.permission.BIND_NFC_SERVICE? [SystemPermissionTypo] - <activity-alias android:permission="android.permission.BIND_NCF_SERVICE" /> ----------------------------------- - - AndroidManifest.xml:11:Warning: Did you mean android.permission.BIND_NFC_SERVICE? [SystemPermissionTypo] - <receiver android:permission="android.permission.BIND_NCF_SERVICE" /> ----------------------------------- - - AndroidManifest.xml:12:Warning: Did you mean android.permission.BIND_NFC_SERVICE? [SystemPermissionTypo] - <service android:permission="android.permission.BIND_NCF_SERVICE" /> ----------------------------------- - - AndroidManifest.xml:13:Warning: Did you mean android.permission.BIND_NFC_SERVICE? [SystemPermissionTypo] - <provider android:permission="android.permission.BIND_NCF_SERVICE" /> ----------------------------------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/TapjackingVulnerable.md.html b/docs/checks/TapjackingVulnerable.md.html new file mode 100644 index 00000000..c6b64b5c --- /dev/null +++ b/docs/checks/TapjackingVulnerable.md.html @@ -0,0 +1,170 @@ + +(#) Application's UI is vulnerable to tapjacking attacks + +!!! WARNING: Application's UI is vulnerable to tapjacking attacks + This is a warning. + +Id +: `TapjackingVulnerable` +Summary +: Application's UI is vulnerable to tapjacking attacks +Severity +: Warning +Category +: Security +Platform +: Android +Vendor +: Google - Android 3P Vulnerability Research +Contact +: https://github.com/google/android-security-lints +Feedback +: https://github.com/google/android-security-lints/issues +Min +: Lint 4.1 +Compiled +: Lint 8.0 and 8.1 +Artifact +: [com.android.security.lint:lint](com_android_security_lint_lint.md.html) +Since +: 1.0.1 +Affects +: Resource files +Editing +: This check runs on the fly in the IDE editor +See +: https://goo.gle/TapjackingVulnerable +Implementation +: [Source Code](https://github.com/google/android-security-lints/tree/main/checks/src/main/java/com/example/lint/checks/TapjackingDetector.kt) +Tests +: [Source Code](https://github.com/google/android-security-lints/tree/main/checks/src/test/java/com/example/lint/checks/TapjackingDetectorTest.kt) +Copyright Year +: 2023 + +Apps with sensitive UI elements should add the +`filterTouchesWithObscured` attribute to protect it from tapjacking / +overlay attacks. + +!!! Tip + This lint check has an associated quickfix available in the IDE. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +res/xml/switch.xml:3:Warning: Add the android:filterTouchesWhenObscured +attribute to protect this UI element from tapjacking / overlay attacks +[TapjackingVulnerable] + <Switch android:id='enable_setting'> + ------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`res/xml/switch.xml`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"> + <Switch android:id='enable_setting'> + </Switch> +</LinearLayout> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/google/android-security-lints/tree/main/checks/src/test/java/com/example/lint/checks/TapjackingDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `TapjackingDetector.testWhenNamedEnableUiElement_showsWarning`. +To report a problem with this extracted sample, visit +https://github.com/google/android-security-lints/issues. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.android.security.lint:lint:1.0.3") + +// build.gradle +lintChecks 'com.android.security.lint:lint:1.0.3' + +// build.gradle.kts with version catalogs: +lintChecks(libs.com.android.security.lint.lint) + +# libs.versions.toml +[versions] +com-android-security-lint-lint = "1.0.3" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +com-android-security-lint-lint = { + module = "com.android.security.lint:lint", + version.ref = "com-android-security-lint-lint" +} +``` + +1.0.3 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.android.security.lint:lint](com_android_security_lint_lint.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Adding the suppression attribute + `tools:ignore="TapjackingVulnerable"` on the problematic XML element + (or one of its enclosing elements). You may also need to add the + following namespace declaration on the root element in the XML file + if it's not already there: + `xmlns:tools="http://schemas.android.com/tools"`. + + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <resources xmlns:tools="http://schemas.android.com/tools"> + ... + <ToggleButton tools:ignore="TapjackingVulnerable" .../> + ... + </resources> + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="TapjackingVulnerable" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'TapjackingVulnerable' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore TapjackingVulnerable ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/TestAppLink.md.html b/docs/checks/TestAppLink.md.html index 8d412a7d..75a63b61 100644 --- a/docs/checks/TestAppLink.md.html +++ b/docs/checks/TestAppLink.md.html @@ -20,6 +20,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: 3.0.0 (October 2017) Affects : Manifest files Editing @@ -28,8 +30,6 @@ : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AppLinksValidDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AppLinksValidDetectorTest.kt) -Copyright Year -: 2017 Using one or more `tools:validation testUrl="some url"/>` elements in your manifest allows the link attributes in your intent filter to be @@ -39,14 +39,11 @@ Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text -AndroidManifest.xml:12:Error: Validation nodes should be in the tools: +AndroidManifest.xml:15:Error: Validation nodes should be in the tools: namespace to ensure they are removed from the manifest at build time [TestAppLink] - <validation /> ---------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: @@ -58,8 +55,11 @@ package="test.pkg" > <application> - <activity> + <activity android:name=".MainActivity"> <intent-filter android:autoVerify="true"> + <action android:name="android.intent.action.VIEW" /> + <category android:name="android.intent.category.DEFAULT" /> + <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="http" android:host="example.com" android:pathPrefix="/gizmos" /> diff --git a/docs/checks/TestLifecycleOwnerInCoroutine.md.html b/docs/checks/TestLifecycleOwnerInCoroutine.md.html new file mode 100644 index 00000000..6e80a873 --- /dev/null +++ b/docs/checks/TestLifecycleOwnerInCoroutine.md.html @@ -0,0 +1,194 @@ + +(#) Use the suspending function setCurrentState(), rather than directly accessing the currentState property + +!!! ERROR: Use the suspending function setCurrentState(), rather than directly accessing the currentState property + This is an error. + +Id +: `TestLifecycleOwnerInCoroutine` +Summary +: Use the suspending function setCurrentState(), rather than directly accessing the currentState property +Severity +: Error +Category +: Correctness +Platform +: Android +Vendor +: Android Open Source Project +Identifier +: androidx.lifecycle +Feedback +: https://issuetracker.google.com/issues/new?component=413132 +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.7+ +Artifact +: [androidx.lifecycle:lifecycle-runtime-testing](androidx_lifecycle_lifecycle-runtime-testing.md.html) +Since +: 2.7.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/lifecycle/lifecycle-runtime-testing-lint/src/main/java/androidx/lifecycle/testing/lint/TestLifecycleOwnerInCoroutineDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/lifecycle/lifecycle-runtime-testing-lint/src/test/java/androidx/lifecycle/runtime/testing/lint/TestLifecycleOwnerInCoroutineDetectorTest.kt) +Copyright Year +: 2021 + +When using TestLifecycleOwner, one of the main use cases is to change + the currentState property. Under the hood, we do this using +runBlocking to keep it thread-safe. However, when using +TestLifecycleOwner from the context of a coroutine (like +runTest), this will cause the setter to hang, since coroutines + should remain asynchronous. + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/example/foo/test.kt:8:Error: Incorrect use of currentState property +inside of Coroutine, please use the suspending setCurrentState() +function. [TestLifecycleOwnerInCoroutine] + fun testSetCurrentStateInRunTest() = runTest { + ------- +src/example/foo/test.kt:13:Error: Incorrect use of currentState property +inside of Coroutine, please use the suspending setCurrentState() +function. [TestLifecycleOwnerInCoroutine] + fun testSetCurrentStateInRunTestWithTimeOut() = runTest(timeout = 5000) { + ------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/example/foo/test.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +package example.foo + +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.testing.TestLifecycleOwner +import kotlinx.coroutines.test.runTest + +fun testSetCurrentStateInRunTest() = runTest { + val owner = TestLifecycleOwner() + owner.currentState = Lifecycle.State.RESUMED +} + +fun testSetCurrentStateInRunTestWithTimeOut() = runTest(timeout = 5000) { + val owner = TestLifecycleOwner() + owner.currentState = Lifecycle.State.RESUMED +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/lifecycle/lifecycle-runtime-testing-lint/src/test/java/androidx/lifecycle/runtime/testing/lint/TestLifecycleOwnerInCoroutineDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `TestLifecycleOwnerInCoroutineDetector.errors`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=413132. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.lifecycle:lifecycle-runtime-testing:2.9.0-rc01") + +// build.gradle +implementation 'androidx.lifecycle:lifecycle-runtime-testing:2.9.0-rc01' + +// build.gradle.kts with version catalogs: +implementation(libs.lifecycle.runtime.testing) + +# libs.versions.toml +[versions] +lifecycle-runtime-testing = "2.9.0-rc01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +lifecycle-runtime-testing = { + module = "androidx.lifecycle:lifecycle-runtime-testing", + version.ref = "lifecycle-runtime-testing" +} +``` + +2.9.0-rc01 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about androidx.lifecycle:lifecycle-runtime-testing](androidx_lifecycle_lifecycle-runtime-testing.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("TestLifecycleOwnerInCoroutine") + fun method() { + runTest(...) + } + ``` + + or + + ```java + // Java + @SuppressWarnings("TestLifecycleOwnerInCoroutine") + void method() { + runTest(...); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection TestLifecycleOwnerInCoroutine + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="TestLifecycleOwnerInCoroutine" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'TestLifecycleOwnerInCoroutine' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore TestLifecycleOwnerInCoroutine ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/TestManifestGradleConfiguration.md.html b/docs/checks/TestManifestGradleConfiguration.md.html index b8ee2604..50fa5185 100644 --- a/docs/checks/TestManifestGradleConfiguration.md.html +++ b/docs/checks/TestManifestGradleConfiguration.md.html @@ -1,13 +1,13 @@ -(#) The ui-test-manifest library should be included using the debugImplementation configuration. +(#) The ui-test-manifest library should be included using the debugImplementation configuration -!!! WARNING: The ui-test-manifest library should be included using the debugImplementation configuration. +!!! WARNING: The ui-test-manifest library should be included using the debugImplementation configuration This is a warning. Id : `TestManifestGradleConfiguration` Summary -: The ui-test-manifest library should be included using the debugImplementation configuration. +: The ui-test-manifest library should be included using the debugImplementation configuration Severity : Warning Category @@ -20,6 +20,14 @@ : androidx.compose.ui.test.manifest Feedback : https://issuetracker.google.com/issues/new?component=741505 +Min +: Lint 8.0 and 8.1 +Compiled +: Lint 8.7+ +Artifact +: [androidx.compose.ui:ui-test-manifest](androidx_compose_ui_ui-test-manifest.md.html) +Since +: 1.2.0 Affects : Gradle build files Editing @@ -28,6 +36,8 @@ : https://developer.android.com/jetpack/compose/testing#setup Implementation : [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/ui/ui-test-manifest-lint/src/main/java/androidx/compose/ui/test/manifest/lint/GradleDebugConfigurationDetector.kt) +Tests +: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/ui/ui-test-manifest-lint/src/test/java/androix/compose/ui/test/manifest/lint/GradleDebugConfigurationDetectorTest.kt) Copyright Year : 2022 @@ -36,6 +46,102 @@ only needs to be present in testing configurations therefore use this dependency with the debugImplementation configuration. +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +build.gradle:2:Warning: Please use debugImplementation. +[TestManifestGradleConfiguration] + implementation("androidx.compose.ui:ui-test-manifest:1.2.0-beta02") + ------------------------------------------------------------------- +build.gradle:3:Warning: Please use debugImplementation. +[TestManifestGradleConfiguration] + api("androidx.compose.ui:ui-test-manifest:1.2.0-beta02") + -------------------------------------------------------- +build.gradle:4:Warning: Please use debugImplementation. +[TestManifestGradleConfiguration] + compileOnly("androidx.compose.ui:ui-test-manifest:1.2.0-beta02") + ---------------------------------------------------------------- +build.gradle:5:Warning: Please use debugImplementation. +[TestManifestGradleConfiguration] + runtimeOnly("androidx.compose.ui:ui-test-manifest:1.2.0-beta02") + ---------------------------------------------------------------- +build.gradle:6:Warning: Please use debugImplementation. +[TestManifestGradleConfiguration] + annotationProcessor("androidx.compose.ui:ui-test-manifest:1.2.0-beta02") + ------------------------------------------------------------------------ +build.gradle:7:Warning: Please use debugImplementation. +[TestManifestGradleConfiguration] + lintChecks("androidx.compose.ui:ui-test-manifest:1.2.0-beta02") + --------------------------------------------------------------- +build.gradle:8:Warning: Please use debugImplementation. +[TestManifestGradleConfiguration] + lintPublish("androidx.compose.ui:ui-test-manifest:1.2.0-beta02") + ---------------------------------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`build.gradle`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~groovy linenumbers +dependencies { + implementation("androidx.compose.ui:ui-test-manifest:1.2.0-beta02") + api("androidx.compose.ui:ui-test-manifest:1.2.0-beta02") + compileOnly("androidx.compose.ui:ui-test-manifest:1.2.0-beta02") + runtimeOnly("androidx.compose.ui:ui-test-manifest:1.2.0-beta02") + annotationProcessor("androidx.compose.ui:ui-test-manifest:1.2.0-beta02") + lintChecks("androidx.compose.ui:ui-test-manifest:1.2.0-beta02") + lintPublish("androidx.compose.ui:ui-test-manifest:1.2.0-beta02") +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/compose/ui/ui-test-manifest-lint/src/test/java/androix/compose/ui/test/manifest/lint/GradleDebugConfigurationDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +The above example was automatically extracted from the first unit test +found for this lint check, `GradleDebugConfigurationDetector.kotlin_manifestDependencyInBlockedConfigs_shouldRaiseIssue`. +To report a problem with this extracted sample, visit +https://issuetracker.google.com/issues/new?component=741505. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. + +``` +// build.gradle.kts +implementation("androidx.compose.ui:ui-test-manifest:1.9.0-alpha01") + +// build.gradle +implementation 'androidx.compose.ui:ui-test-manifest:1.9.0-alpha01' + +// build.gradle.kts with version catalogs: +implementation(libs.ui.test.manifest) + +# libs.versions.toml +[versions] +ui-test-manifest = "1.9.0-alpha01" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +ui-test-manifest = { + module = "androidx.compose.ui:ui-test-manifest", + version.ref = "ui-test-manifest" +} +``` + +1.9.0-alpha01 is the version this documentation was generated from; +there may be newer versions available. + +NOTE: These lint checks are **also** made available separate from the main library. +You can also use `androidx.compose.ui:ui-test-manifest-lint:1.9.0-alpha01`. + + +[Additional details about androidx.compose.ui:ui-test-manifest](androidx_compose_ui_ui-test-manifest.md.html). (##) Suppressing You can suppress false positives using one of the following mechanisms: diff --git a/docs/checks/TestParameterSiteTarget.md.html b/docs/checks/TestParameterSiteTarget.md.html new file mode 100644 index 00000000..78612d1d --- /dev/null +++ b/docs/checks/TestParameterSiteTarget.md.html @@ -0,0 +1,172 @@ + +(#) `TestParameter` annotation has the wrong site target + +!!! ERROR: `TestParameter` annotation has the wrong site target + This is an error. + +Id +: `TestParameterSiteTarget` +Summary +: `TestParameter` annotation has the wrong site target +Severity +: Error +Category +: Correctness +Platform +: Any +Vendor +: slack +Identifier +: slack-lint +Contact +: https://github.com/slackhq/slack-lints +Feedback +: https://github.com/slackhq/slack-lints +Min +: Lint 8.7+ +Compiled +: Lint 8.7+ +Artifact +: [com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html) +Since +: 0.9.0 +Affects +: Kotlin and Java files and test sources +Editing +: This check runs on the fly in the IDE editor +Implementation +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/main/java/slack/lint/TestParameterSiteTargetDetector.kt) +Tests +: [Source Code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/TestParameterSiteTargetDetectorTest.kt) +Copyright Year +: 2025 + +`TestParameter` annotations on parameter properties must have `param:` +site targets.For example:```kotlinclass MyTest( @param:TestParameter +val myParam: String)```For more information, see: +https://github.com/google/TestParameterInjector/issues/49 + +(##) Example + +Here is an example of lint warnings produced by this check: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text +src/MyTest.kt:3:Error: TestParameter annotation has the wrong site +target [TestParameterSiteTarget] + @com.google.testing.junit.testparameterinjector.TestParameter val myParam: String + ------------------------------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Here is the source file referenced above: + +`src/MyTest.kt`: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers +class MyTest( + @com.google.testing.junit.testparameterinjector.TestParameter val myParam: String +) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also visit the +[source code](https://github.com/slackhq/slack-lints/tree/main/slack-lint-checks/src/test/java/slack/lint/TestParameterSiteTargetDetectorTest.kt) +for the unit tests for this check to see additional scenarios. + +(##) Including + +!!! + This is not a built-in check. To include it, add the below dependency + to your project. This lint check is included in the lint documentation, + but the Android team may or may not agree with its recommendations. + +``` +// build.gradle.kts +lintChecks("com.slack.lint:slack-lint-checks:0.9.0") + +// build.gradle +lintChecks 'com.slack.lint:slack-lint-checks:0.9.0' + +// build.gradle.kts with version catalogs: +lintChecks(libs.slack.lint.checks) + +# libs.versions.toml +[versions] +slack-lint-checks = "0.9.0" +[libraries] +# For clarity and text wrapping purposes the following declaration is +# shown split up across lines, but in TOML it needs to be on a single +# line (see https://github.com/toml-lang/toml/issues/516) so adjust +# when pasting into libs.versions.toml: +slack-lint-checks = { + module = "com.slack.lint:slack-lint-checks", + version.ref = "slack-lint-checks" +} +``` + +0.9.0 is the version this documentation was generated from; +there may be newer versions available. + +[Additional details about com.slack.lint:slack-lint-checks](com_slack_lint_slack-lint-checks.md.html). +(##) Suppressing + +You can suppress false positives using one of the following mechanisms: + +* Using a suppression annotation like this on the enclosing + element: + + ```kt + // Kotlin + @Suppress("TestParameterSiteTarget") + fun method() { + problematicStatement() + } + ``` + + or + + ```java + // Java + @SuppressWarnings("TestParameterSiteTarget") + void method() { + problematicStatement(); + } + ``` + +* Using a suppression comment like this on the line above: + + ```kt + //noinspection TestParameterSiteTarget + problematicStatement() + ``` + +* Using a special `lint.xml` file in the source tree which turns off + the check in that folder and any sub folder. A simple file might look + like this: + ```xml + <?xml version="1.0" encoding="UTF-8"?> + <lint> + <issue id="TestParameterSiteTarget" severity="ignore" /> + </lint> + ``` + Instead of `ignore` you can also change the severity here, for + example from `error` to `warning`. You can find additional + documentation on how to filter issues by path, regular expression and + so on + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). + +* In Gradle projects, using the DSL syntax to configure lint. For + example, you can use something like + ```gradle + lintOptions { + disable 'TestParameterSiteTarget' + } + ``` + In Android projects this should be nested inside an `android { }` + block. + +* For manual invocations of `lint`, using the `--ignore` flag: + ``` + $ lint --ignore TestParameterSiteTarget ...` + ``` + +* Last, but not least, using baselines, as discussed + [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html). + + \ No newline at end of file diff --git a/docs/checks/TextFields.md.html b/docs/checks/TextFields.md.html index 64ba6d30..4cedca59 100644 --- a/docs/checks/TextFields.md.html +++ b/docs/checks/TextFields.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -32,7 +34,7 @@ Providing an `inputType` attribute on a text field improves usability because depending on the data to be input, optimized keyboards can be shown to the user (such as just digits and parentheses for a phone -number). +number). The lint detector also looks at the `id` of the view, and if the id offers a hint of the purpose of the field (for example, the `id` @@ -51,18 +53,12 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/note_edit.xml:43:Warning: This text field does not specify an inputType [TextFields] - <EditText -------- - - res/layout/note_edit.xml:50:Warning: This text field does not specify an inputType [TextFields] - <EditText -------- - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: diff --git a/docs/checks/TextViewEdits.md.html b/docs/checks/TextViewEdits.md.html index a9f50278..8a8eb68a 100644 --- a/docs/checks/TextViewEdits.md.html +++ b/docs/checks/TextViewEdits.md.html @@ -18,6 +18,8 @@ : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 +Since +: Initial Affects : Resource files Editing @@ -47,171 +49,108 @@ res/layout/edit_textview.xml:13:Warning: Attribute android:autoText should not be used with : Change element type to ? [TextViewEdits] - android:autoText="true" ----------------------- - - res/layout/edit_textview.xml:14:Warning: Attribute android:bufferType should not be used with : Change element type to ? [TextViewEdits] - android:bufferType="editable" ----------------------------- - - res/layout/edit_textview.xml:15:Warning: Attribute android:capitalize should not be used with : Change element type to ? [TextViewEdits] - android:capitalize="words" -------------------------- - - res/layout/edit_textview.xml:16:Warning: Attribute android:cursorVisible should not be used with : Change element type to ? [TextViewEdits] - android:cursorVisible="true" ---------------------------- - - res/layout/edit_textview.xml:17:Warning: Attribute android:digits should not be used with : Change element type to ? [TextViewEdits] - android:digits="" ----------------- - - res/layout/edit_textview.xml:18:Warning: Attribute android:editable should not be used with : Change element type to ? [TextViewEdits] - android:editable="true" ----------------------- - - res/layout/edit_textview.xml:19:Warning: Attribute android:editorExtras should not be used with : Change element type to ? [TextViewEdits] - android:editorExtras="@+id/foobar" ---------------------------------- - - res/layout/edit_textview.xml:22:Warning: Attribute android:imeActionId should not be used with : Change element type to ? [TextViewEdits] - android:imeActionId="@+id/foo" ------------------------------ - - res/layout/edit_textview.xml:23:Warning: Attribute android:imeActionLabel should not be used with : Change element type to ? [TextViewEdits] - android:imeActionLabel="" ------------------------- - - res/layout/edit_textview.xml:24:Warning: Attribute android:imeOptions should not be used with : Change element type to ? [TextViewEdits] - android:imeOptions="" --------------------- - - res/layout/edit_textview.xml:25:Warning: Attribute android:inputMethod should not be used with : Change element type to ? [TextViewEdits] - android:inputMethod="" ---------------------- - - res/layout/edit_textview.xml:26:Warning: Attribute android:inputType should not be used with : Change element type to ? [TextViewEdits] - android:inputType="text" ------------------------ - - res/layout/edit_textview.xml:27:Warning: Attribute android:numeric should not be used with : Change element type to ? [TextViewEdits] - android:numeric="" ------------------ - - res/layout/edit_textview.xml:28:Warning: Attribute android:password should not be used with : Change element type to ? [TextViewEdits] - android:password="true" ----------------------- - - res/layout/edit_textview.xml:29:Warning: Attribute android:phoneNumber should not be used with : Change element type to ? [TextViewEdits] - android:phoneNumber="true" -------------------------- - - res/layout/edit_textview.xml:30:Warning: Attribute android:privateImeOptions should not be used with : Change element type to ? [TextViewEdits] - android:privateImeOptions="" /> ---------------------------- - - res/layout/edit_textview.xml:38:Warning: Attribute android:cursorVisible should not be used with