diff options
author | Tor Norbye <tnorbye@google.com> | 2022-01-12 13:22:25 +0000 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2022-01-21 01:13:33 +0000 |
commit | ff8d544a96e2b3b90004011f6ef28daec153aeb0 (patch) | |
tree | 9d9aaa1bf096b8e49ce9dac8f530ccdfd95c7085 /lint/src | |
parent | 45129e7706f0f04cc733eca5013ad3197eceeecb (diff) | |
download | idea-ff8d544a96e2b3b90004011f6ef28daec153aeb0.tar.gz |
Add @ReturnThis, @OpenForTesting, @EmptySuper and @DeprecatedSinceApi
Register new lint checks as inspections.
Test: Automatically generated inspections registration code; lint checks
are tested in lint
Fixes: 140249763
Fixes: 141539024
Fixes: 37116481
Change-Id: I0113569420c5c8f83c1de3e75cb0894d31427a80
Diffstat (limited to 'lint/src')
6 files changed, 83 insertions, 3 deletions
diff --git a/lint/src/META-INF/lint-plugin.xml b/lint/src/META-INF/lint-plugin.xml index 26a82248f62..773d3e11ace 100644 --- a/lint/src/META-INF/lint-plugin.xml +++ b/lint/src/META-INF/lint-plugin.xml @@ -43,6 +43,7 @@ <globalInspection hasStaticDescription="true" shortName="AndroidLintDefaultLocale" displayName="Implied default locale in case conversion" bundle="messages.LintBundle" enabledByDefault="true" level="WARNING" implementationClass="com.android.tools.idea.lint.common.AndroidLintDefaultLocaleInspection"/> <globalInspection hasStaticDescription="true" shortName="AndroidLintDiscouragedApi" displayName="Using discouraged APIs" bundle="messages.LintBundle" enabledByDefault="true" level="WARNING" implementationClass="com.android.tools.idea.lint.common.AndroidLintDiscouragedApiInspection"/> <globalInspection hasStaticDescription="true" shortName="AndroidLintEasterEgg" displayName="Code contains easter egg" bundle="messages.LintBundle" enabledByDefault="false" level="WARNING" implementationClass="com.android.tools.idea.lint.common.AndroidLintEasterEggInspection"/> + <globalInspection hasStaticDescription="true" shortName="AndroidLintEmptySuperCall" displayName="Calling an empty super method" bundle="messages.LintBundle" enabledByDefault="true" level="WARNING" implementationClass="com.android.tools.idea.lint.common.AndroidLintEmptySuperCallInspection"/> <globalInspection hasStaticDescription="true" shortName="AndroidLintExpensiveAssertion" displayName="Expensive Assertions" bundle="messages.LintBundle" enabledByDefault="false" level="WARNING" implementationClass="com.android.tools.idea.lint.common.AndroidLintExpensiveAssertionInspection"/> <globalInspection hasStaticDescription="true" shortName="AndroidLintFileEndsWithExt" displayName="File endsWith on file extensions" bundle="messages.LintBundle" enabledByDefault="true" level="WARNING" implementationClass="com.android.tools.idea.lint.common.AndroidLintFileEndsWithExtInspection"/> <globalInspection hasStaticDescription="true" shortName="AndroidLintGradleDependency" displayName="Obsolete Gradle Dependency" bundle="messages.LintBundle" enabledByDefault="true" level="WARNING" implementationClass="com.android.tools.idea.lint.common.AndroidLintGradleDependencyInspection"/> @@ -63,10 +64,12 @@ <globalInspection hasStaticDescription="true" shortName="AndroidLintNoHardKeywords" displayName="No Hard Kotlin Keywords" bundle="messages.LintBundle" enabledByDefault="false" level="WARNING" implementationClass="com.android.tools.idea.lint.common.AndroidLintNoHardKeywordsInspection"/> <globalInspection hasStaticDescription="true" shortName="AndroidLintNotConstructor" displayName="Not a Constructor" bundle="messages.LintBundle" enabledByDefault="true" level="WARNING" implementationClass="com.android.tools.idea.lint.common.AndroidLintNotConstructorInspection"/> <globalInspection hasStaticDescription="true" shortName="AndroidLintNotInterpolated" displayName="Incorrect Interpolation" bundle="messages.LintBundle" enabledByDefault="true" level="ERROR" implementationClass="com.android.tools.idea.lint.common.AndroidLintNotInterpolatedInspection"/> + <globalInspection hasStaticDescription="true" shortName="AndroidLintOpenForTesting" displayName="Extending API only allowed from tests" bundle="messages.LintBundle" enabledByDefault="true" level="ERROR" implementationClass="com.android.tools.idea.lint.common.AndroidLintOpenForTestingInspection"/> <globalInspection hasStaticDescription="true" shortName="AndroidLintPropertyEscape" displayName="Incorrect property escapes" bundle="messages.LintBundle" enabledByDefault="true" level="ERROR" implementationClass="com.android.tools.idea.lint.common.AndroidLintPropertyEscapeInspection"/> <globalInspection hasStaticDescription="true" shortName="AndroidLintProxyPassword" displayName="Proxy Password in Cleartext" bundle="messages.LintBundle" enabledByDefault="true" level="WARNING" implementationClass="com.android.tools.idea.lint.common.AndroidLintProxyPasswordInspection"/> <globalInspection hasStaticDescription="true" shortName="AndroidLintRange" displayName="Outside Range" bundle="messages.LintBundle" enabledByDefault="true" level="ERROR" implementationClass="com.android.tools.idea.lint.common.AndroidLintRangeInspection"/> <globalInspection hasStaticDescription="true" shortName="AndroidLintRestrictedApi" displayName="Restricted API" bundle="messages.LintBundle" enabledByDefault="true" level="ERROR" implementationClass="com.android.tools.idea.lint.common.AndroidLintRestrictedApiInspection"/> + <globalInspection hasStaticDescription="true" shortName="AndroidLintReturnThis" displayName="Method must return this" bundle="messages.LintBundle" enabledByDefault="true" level="ERROR" implementationClass="com.android.tools.idea.lint.common.AndroidLintReturnThisInspection"/> <globalInspection hasStaticDescription="true" shortName="AndroidLintSecureRandom" displayName="Using a fixed seed with SecureRandom" bundle="messages.LintBundle" enabledByDefault="true" level="WARNING" implementationClass="com.android.tools.idea.lint.common.AndroidLintSecureRandomInspection"/> <globalInspection hasStaticDescription="true" shortName="AndroidLintShiftFlags" displayName="Dangerous Flag Constant Declaration" bundle="messages.LintBundle" enabledByDefault="true" level="WARNING" implementationClass="com.android.tools.idea.lint.common.AndroidLintShiftFlagsInspection"/> <globalInspection hasStaticDescription="true" shortName="AndroidLintSimpleDateFormat" displayName="Implied locale in date format" bundle="messages.LintBundle" enabledByDefault="true" level="WARNING" implementationClass="com.android.tools.idea.lint.common.AndroidLintSimpleDateFormatInspection"/> diff --git a/lint/src/com/android/tools/idea/lint/common/AndroidLintEmptySuperCallInspection.kt b/lint/src/com/android/tools/idea/lint/common/AndroidLintEmptySuperCallInspection.kt new file mode 100644 index 00000000000..f630ed47f22 --- /dev/null +++ b/lint/src/com/android/tools/idea/lint/common/AndroidLintEmptySuperCallInspection.kt @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2022 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.android.tools.idea.lint.common + +import com.android.tools.idea.lint.common.LintBundle.Companion.message +import com.android.tools.lint.checks.EmptySuperDetector + +class AndroidLintEmptySuperCallInspection : AndroidLintInspectionBase( + message("android.lint.inspections.empty.super.call"), EmptySuperDetector.ISSUE +)
\ No newline at end of file diff --git a/lint/src/com/android/tools/idea/lint/common/AndroidLintOpenForTestingInspection.kt b/lint/src/com/android/tools/idea/lint/common/AndroidLintOpenForTestingInspection.kt new file mode 100644 index 00000000000..fa6aaa71e7f --- /dev/null +++ b/lint/src/com/android/tools/idea/lint/common/AndroidLintOpenForTestingInspection.kt @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2022 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.android.tools.idea.lint.common + +import com.android.tools.idea.lint.common.LintBundle.Companion.message +import com.android.tools.lint.checks.OpenForTestingDetector + +class AndroidLintOpenForTestingInspection : AndroidLintInspectionBase( + message("android.lint.inspections.open.for.testing"), OpenForTestingDetector.ISSUE +)
\ No newline at end of file diff --git a/lint/src/com/android/tools/idea/lint/common/AndroidLintReturnThisInspection.kt b/lint/src/com/android/tools/idea/lint/common/AndroidLintReturnThisInspection.kt new file mode 100644 index 00000000000..2aba3a21ebf --- /dev/null +++ b/lint/src/com/android/tools/idea/lint/common/AndroidLintReturnThisInspection.kt @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2022 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.android.tools.idea.lint.common + +import com.android.tools.idea.lint.common.LintBundle.Companion.message +import com.android.tools.lint.checks.ReturnThisDetector + +class AndroidLintReturnThisInspection : AndroidLintInspectionBase( + message("android.lint.inspections.return.this"), ReturnThisDetector.ISSUE +)
\ No newline at end of file diff --git a/lint/src/com/android/tools/idea/lint/common/LintExternalAnnotator.kt b/lint/src/com/android/tools/idea/lint/common/LintExternalAnnotator.kt index 44429fbdd3c..4748d518b50 100644 --- a/lint/src/com/android/tools/idea/lint/common/LintExternalAnnotator.kt +++ b/lint/src/com/android/tools/idea/lint/common/LintExternalAnnotator.kt @@ -18,8 +18,10 @@ package com.android.tools.idea.lint.common import com.android.SdkConstants.ANDROID_MANIFEST_XML import com.android.SdkConstants.DOT_KTS import com.android.SdkConstants.DOT_XML +import com.android.SdkConstants.FN_ANDROID_PROGUARD_FILE import com.android.SdkConstants.FN_PROJECT_PROGUARD_FILE import com.android.SdkConstants.OLD_PROGUARD_FILE +import com.android.tools.lint.checks.DeprecatedSinceApiDetector import com.android.tools.lint.checks.DeprecationDetector import com.android.tools.lint.checks.GradleDetector import com.android.tools.lint.checks.WrongIdDetector @@ -167,7 +169,7 @@ class LintExternalAnnotator : ExternalAnnotator<LintEditorResult, LintEditorResu if (name.endsWith(DOT_KTS)) { scope = EnumSet.of(Scope.GRADLE_FILE, Scope.JAVA_FILE) } - } else if (name == OLD_PROGUARD_FILE || name == FN_PROJECT_PROGUARD_FILE) { + } else if (name == OLD_PROGUARD_FILE || name == FN_PROJECT_PROGUARD_FILE || name == FN_ANDROID_PROGUARD_FILE) { scope = EnumSet.of(Scope.PROGUARD_FILE) } else if (GradleFileType.isGradleFile(mainFile)) { scope = Scope.GRADLE_SCOPE @@ -232,7 +234,10 @@ class LintExternalAnnotator : ExternalAnnotator<LintEditorResult, LintEditorResu } val severity = displayLevel.severity val type: ProblemHighlightType = - if (issue === DeprecationDetector.ISSUE || issue === GradleDetector.DEPRECATED || issue === GradleDetector.DEPRECATED_CONFIGURATION) { + if (issue === DeprecationDetector.ISSUE || + issue === GradleDetector.DEPRECATED || + issue === GradleDetector.DEPRECATED_CONFIGURATION || + issue === DeprecatedSinceApiDetector.ISSUE) { ProblemHighlightType.LIKE_DEPRECATED } else if (issue === WrongIdDetector.UNKNOWN_ID || issue === WrongIdDetector.UNKNOWN_ID_LAYOUT) { ProblemHighlightType.ERROR // like unknown symbol diff --git a/lint/src/com/android/tools/idea/lint/common/LintIdeSupport.kt b/lint/src/com/android/tools/idea/lint/common/LintIdeSupport.kt index 3143dd4b749..1c5c83e3409 100644 --- a/lint/src/com/android/tools/idea/lint/common/LintIdeSupport.kt +++ b/lint/src/com/android/tools/idea/lint/common/LintIdeSupport.kt @@ -15,6 +15,9 @@ */ package com.android.tools.idea.lint.common +import com.android.SdkConstants.FN_ANDROID_PROGUARD_FILE +import com.android.SdkConstants.FN_PROJECT_PROGUARD_FILE +import com.android.SdkConstants.OLD_PROGUARD_FILE import com.android.ide.common.repository.GradleCoordinate import com.android.ide.common.repository.GradleVersion import com.android.tools.lint.client.api.IssueRegistry @@ -88,7 +91,7 @@ abstract class LintIdeSupport { } else if (fileType === FileTypes.PLAIN_TEXT) { val name = file.name - return name == "proguard-project.txt" || name == "proguard-android.txt" || name == "proguard.cfg" + return name == FN_PROJECT_PROGUARD_FILE || name == FN_ANDROID_PROGUARD_FILE || name == OLD_PROGUARD_FILE } else if (file.isGradleFile()) { return true |