Skip to content

Commit

Permalink
Merge branch 'main' into compiler-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
chao2zhang committed Nov 27, 2022
2 parents 170f46f + 6985de3 commit 84ba660
Show file tree
Hide file tree
Showing 99 changed files with 9,593 additions and 229 deletions.
3 changes: 3 additions & 0 deletions .github/labeler.yml
Expand Up @@ -43,3 +43,6 @@ rules:
- "detekt-rules-naming/src/**/*"
- "detekt-rules-performance/src/**/*"
- "detekt-rules-style/src/**/*"

suppressors:
- "detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/suppressors/**/*"
4 changes: 2 additions & 2 deletions .github/workflows/detekt-with-type-resolution.yaml
Expand Up @@ -39,7 +39,7 @@ jobs:
arguments: :detekt-cli:runWithArgsFile

- name: Upload SARIF to Github using the upload-sarif action
uses: github/codeql-action/upload-sarif@ec3cf9c605b848da5f1e41e8452719eb1ccfb9a6 # tag=v2
uses: github/codeql-action/upload-sarif@312e093a1892bd801f026f1090904ee8e460b9b6 # v2
if: success() || failure()
with:
sarif_file: build/detekt-report.sarif
Expand Down Expand Up @@ -67,7 +67,7 @@ jobs:
arguments: detektMain detektTest :detektReportMergeSarif --continue

- name: Upload SARIF to Github using the upload-sarif action
uses: github/codeql-action/upload-sarif@ec3cf9c605b848da5f1e41e8452719eb1ccfb9a6 # tag=v2
uses: github/codeql-action/upload-sarif@312e093a1892bd801f026f1090904ee8e460b9b6 # v2
if: success() || failure()
with:
sarif_file: build/reports/detekt/merge.sarif
13 changes: 13 additions & 0 deletions .github/workflows/stale.yaml
Expand Up @@ -23,3 +23,16 @@ jobs:
exempt-issue-labels: help wanted, good first issue, never gets stale, blocked
exempt-pr-labels: help wanted, good first issue, never gets stale, blocked
exempt-milestones: Future Breaking Changes in Major Versions
- uses: actions/stale@5ebf00ea0e4c1561e9b43a292ed34424fb1d4578 # tag=v6
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
days-before-stale: 30
stale-issue-message: 'This issue is waiting for authors feedback since 30 days. Please comment providing the requested feedback or this issue will be closed in 7 days.'
stale-pr-message: 'This PR is waiting for authors feedback since 30 days. Please comment providing the requested feedback or this PR will be closed in 7 days.'
close-issue-message: 'This issue was closed because its author has not followed up after 7 days.'
close-pr-message: 'This PR was closed because its author has not followed up after 7 days.'
stale-issue-label: stale
stale-pr-label: stale
any-of-labels: waiting for feedback
exempt-issue-labels: never gets stale
exempt-pr-labels: never gets stale
19 changes: 13 additions & 6 deletions README.md
Expand Up @@ -33,7 +33,7 @@ Visit [the project website](https://detekt.dev/) for installation guides, rule d
- [Changelog and migration guides](https://detekt.dev/changelog.html)
- [Available CLI options](https://detekt.dev/cli.html)
- [Rule set and rule descriptions](https://detekt.dev/complexity.html)
- [Writing custom rules and extending detekt](https://detekt.dev/extensions.html)
- [Writing custom rules and extending detekt](https://detekt.dev/docs/introduction/extensions/)
- [Suppressing issues in code](https://detekt.dev/suppressing-rules.html)
- [Suppressing issues via baseline file](https://detekt.dev/baseline.html)
- [Configuring detekt](https://detekt.dev/configurations.html)
Expand Down Expand Up @@ -110,7 +110,7 @@ Gradle 6.7.1+ is the minimum requirement. However, the recommended versions toge

| Detekt Version | Gradle | Kotlin | AGP | Java Target Level | JDK Max Version |
| -------------- | ------- | -------- | ------- | ----------------- | --------------- |
| `1.21.0` | `7.5` | `1.6.21` | `7.2.1` | `1.8` | `17` |
| `1.22.0` | `7.5.1` | `1.7.21` | `7.3.1` | `1.8` | `17` |

The list of [recommended versions for previous detekt version is listed here](https://detekt.dev/compatibility.html).

Expand All @@ -125,17 +125,24 @@ dependencies {
}
```

Likewise custom [extensions](https://detekt.dev/extensions.html) can be added to detekt.
Similarly, there are extra rule sets available for Detekt from Detekt:
```kotlin
dependencies {
detektPlugins("io.gitlab.arturbosch.detekt:detekt-rules-libraries:[version]")
detektPlugins("io.gitlab.arturbosch.detekt:detekt-rules-ruleauthors:[version]")
}
```
For more info visit the [Detekt Marketplace](https://detekt.dev/marketplace).

Likewise custom [extensions](https://detekt.dev/docs/introduction/extensions/) can be added to detekt.

### Contributing

See [CONTRIBUTING](.github/CONTRIBUTING.md)

Thanks to all the people who contributed to detekt!

<a href="https://github.com/detekt/detekt/graphs/contributors">
<img src="https://contrib.rocks/image?repo=detekt/detekt" />
</a>
[![Profile images of all the contributors](https://contrib.rocks/image?repo=detekt/detekt)](https://github.com/detekt/detekt/graphs/contributors)

### Mentions

Expand Down
2 changes: 1 addition & 1 deletion bots/package.json
Expand Up @@ -7,6 +7,6 @@
"main": "index.js",
"license": "MIT",
"devDependencies": {
"danger": "11.1.4"
"danger": "11.2.0"
}
}
8 changes: 4 additions & 4 deletions bots/yarn.lock
Expand Up @@ -295,10 +295,10 @@ core-js@^3.8.2:
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.24.1.tgz#cf7724d41724154010a6576b7b57d94c5d66e64f"
integrity sha512-0QTBSYSUZ6Gq21utGzkfITDylE8jWC9Ne1D2MrhvlsZBI1x39OdDIVbzSqtgMndIy6BlHxBXpMGqzZmnztg2rg==

danger@11.1.4:
version "11.1.4"
resolved "https://registry.yarnpkg.com/danger/-/danger-11.1.4.tgz#db33fe9fb864c9a8d6e9e7a6a69072b0704c3697"
integrity sha512-2X6pbtz7r1RyRhpZpYUWA0L+NancQcjZ0krnoYS5lZxRYfZfG51g1zEUork33zwoUcSpL0BnlTlQQqcGvXhj2A==
danger@11.2.0:
version "11.2.0"
resolved "https://registry.yarnpkg.com/danger/-/danger-11.2.0.tgz#ae1f1434ced5349d9085376497993cf8cba3b77e"
integrity sha512-UMcgmUEQnk9c9ykQhxB8O/KGNGs7Y0mkPFCmg6lvjCSo5PKVyg+7f0mwMSL2gWzBcPf4/V8TpDA6uFJHIcVn4Q==
dependencies:
"@gitbeaker/node" "^21.3.0"
"@octokit/rest" "^18.12.0"
Expand Down
2 changes: 1 addition & 1 deletion build-logic/src/main/kotlin/Versions.kt
@@ -1,6 +1,6 @@
object Versions {

const val DETEKT: String = "1.22.0-RC2"
const val DETEKT: String = "1.22.0"
const val SNAPSHOT_NAME: String = "main"
const val JVM_TARGET: String = "1.8"

Expand Down
24 changes: 0 additions & 24 deletions code-coverage-report/build.gradle.kts
Expand Up @@ -43,27 +43,3 @@ dependencies {
tasks.check {
dependsOn(tasks.named("jacocoMergedReport"))
}

// The `allCodeCoverageReportClassDirectories` configuration provided by the jacoco-report-aggregation plugin actually
// resolves JARs and not class directories as the name suggests. Because the detekt-formatting JAR bundles ktlint and
// other dependencies in its JAR, they are incorrectly displayed on the coverage report even though they're external
// dependencies.
configurations.allCodeCoverageReportClassDirectories.get().attributes {
attributes.attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category::class, Category.LIBRARY))
attributes.attribute(
LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE,
objects.named(LibraryElements::class, LibraryElements.CLASSES)
)
}

val customClassDirectories = configurations.allCodeCoverageReportClassDirectories.get().incoming.artifactView {
componentFilter {
it is ProjectComponentIdentifier
}
lenient(true)
}

tasks.named("jacocoMergedReport", JacocoReport::class).configure {
this.classDirectories.setFrom(customClassDirectories.files)
mustRunAfter(rootProject.project("detekt-generator").tasks.named("generateDocumentation"))
}
Expand Up @@ -39,7 +39,8 @@ interface Config {
*/
class InvalidConfigurationError(throwable: Throwable? = null /* nullable to not break signature */) :
RuntimeException(
"Provided configuration file is invalid: Structure must be from type Map<String,Any>!",
"Provided configuration file is invalid: Structure must be from type Map<String,Any>!" +
throwable?.let { "\n" + it.message }.orEmpty(),
throwable
)

Expand Down
1 change: 1 addition & 0 deletions detekt-core/build.gradle.kts
Expand Up @@ -23,4 +23,5 @@ dependencies {
testImplementation(libs.mockk)
testImplementation(libs.reflections)
testImplementation(libs.assertj)
testRuntimeOnly(libs.slf4j.simple)
}
Expand Up @@ -29,7 +29,7 @@ internal val DEFAULT_PROPERTY_EXCLUDES = setOf(
".*>.*>autoCorrect",
".*>severity",
".*>.*>severity",
"build>weights.*",
"build>weights",
".*>.*>ignoreAnnotated",
".*>.*>ignoreFunction",
).joinToString(",")
Expand Down
Expand Up @@ -36,16 +36,16 @@ private fun configInputStream(extensionsSpec: ExtensionsSpec): InputStream {
.use { it.copyTo(outputStream) }

ExtensionFacade(extensionsSpec.plugins).pluginLoader
.getResourcesAsStream("config/config.yml")
.getSafeResourcesAsStreams("config/config.yml")
.forEach { inputStream ->
outputStream.bufferedWriter().append('\n').flush()
outputStream.write('\n'.code)
inputStream.use { it.copyTo(outputStream) }
}

return ByteArrayInputStream(outputStream.toByteArray())
}

private fun ClassLoader.getResourcesAsStream(name: String): Sequence<InputStream> {
private fun ClassLoader.getSafeResourcesAsStreams(name: String): Sequence<InputStream> {
return getResources(name)
.asSequence()
.map { it.openSafeStream() }
Expand Down
1 change: 1 addition & 0 deletions detekt-core/src/main/resources/default-detekt-config.yml
Expand Up @@ -48,6 +48,7 @@ output-reports:
# - 'XmlOutputReport'
# - 'HtmlOutputReport'
# - 'MdOutputReport'
# - 'SarifOutputReport'

comments:
active: true
Expand Down
Expand Up @@ -10,12 +10,13 @@ import io.gitlab.arturbosch.detekt.api.internal.ruleSetConfig
/**
* This rule set provides wrappers for rules implemented by ktlint - https://ktlint.github.io/.
*
* Note: Issues reported by this rule set can only be suppressed on file level (`@file:Suppress("detekt.rule")`).
* Note: The formatting rule set is not included in the detekt-cli or gradle plugin.
* **Note: The `formatting` rule set is not included in the detekt-cli or Gradle plugin.**
*
* To enable this rule set, add `detektPlugins "io.gitlab.arturbosch.detekt:detekt-formatting:$version"`
* to your gradle dependencies or reference the `detekt-formatting`-jar with the `--plugins` option
* to your gradle `dependencies` or reference the `detekt-formatting`-jar with the `--plugins` option
* in the command line interface.
*
* Note: Issues reported by this rule set can only be suppressed on file level (`@file:Suppress("detekt.rule")`).
*/
@ActiveByDefault(since = "1.0.0")
class FormattingProvider : RuleSetProvider {
Expand Down
Expand Up @@ -15,7 +15,7 @@ import io.gitlab.arturbosch.detekt.formatting.FormattingRule
class NoWildcardImports(config: Config) : FormattingRule(config) {

override val wrapping = NoWildcardImportsRule()
override val issue = issueFor("Detects wildcast import usages")
override val issue = issueFor("Detects wildcard imports")

@Configuration("Defines allowed wildcard imports")
private val packagesToUseImportOnDemandProperty by config(ALLOWED_WILDCARD_IMPORTS)
Expand Down
Expand Up @@ -3,22 +3,32 @@ package io.gitlab.arturbosch.detekt.formatting.wrappers
import com.pinterest.ktlint.core.api.UsesEditorConfigProperties
import com.pinterest.ktlint.ruleset.standard.TrailingCommaOnCallSiteRule
import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.api.config
import io.gitlab.arturbosch.detekt.api.configWithAndroidVariants
import io.gitlab.arturbosch.detekt.api.internal.AutoCorrectable
import io.gitlab.arturbosch.detekt.api.internal.Configuration
import io.gitlab.arturbosch.detekt.formatting.FormattingRule

/**
* See [ktlint docs](https://pinterest.github.io/ktlint/rules/standard/) for documentation.
*
* The default config comes from ktlint and follows these conventions:
* - [Kotlin coding convention](https://kotlinlang.org/docs/coding-conventions.html#trailing-commas) recommends
* trailing comma encourage the use of trailing commas at the declaration site and
* leaves it at your discretion for the call site.
* - [Android Kotlin style guide](https://developer.android.com/kotlin/style-guide) does not include
* trailing comma usage yet.
*/
@AutoCorrectable(since = "1.22.0")
class TrailingCommaOnCallSite(config: Config) : FormattingRule(config) {

override val wrapping = TrailingCommaOnCallSiteRule()
override val issue = issueFor("Rule to mandate/forbid trailing commas at call sites")

@Configuration("Defines whether a trailing comma (or no trailing comma) should be enforced at call sites")
private val useTrailingCommaOnCallSite by config(false)
@Configuration("Defines whether trailing commas are required (true) or forbidden (false) at call sites")
private val useTrailingCommaOnCallSite by configWithAndroidVariants(
defaultValue = true,
defaultAndroidValue = false,
)

override fun overrideEditorConfigProperties(): Map<UsesEditorConfigProperties.EditorConfigProperty<*>, String> =
mapOf(
Expand Down
Expand Up @@ -3,22 +3,32 @@ package io.gitlab.arturbosch.detekt.formatting.wrappers
import com.pinterest.ktlint.core.api.UsesEditorConfigProperties
import com.pinterest.ktlint.ruleset.standard.TrailingCommaOnDeclarationSiteRule
import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.api.config
import io.gitlab.arturbosch.detekt.api.configWithAndroidVariants
import io.gitlab.arturbosch.detekt.api.internal.AutoCorrectable
import io.gitlab.arturbosch.detekt.api.internal.Configuration
import io.gitlab.arturbosch.detekt.formatting.FormattingRule

/**
* See [ktlint docs](https://pinterest.github.io/ktlint/rules/standard/) for documentation.
*
* The default config comes from ktlint and follows these conventions:
* - [Kotlin coding convention](https://kotlinlang.org/docs/coding-conventions.html#trailing-commas) recommends
* trailing comma encourage the use of trailing commas at the declaration site and
* leaves it at your discretion for the call site.
* - [Android Kotlin style guide](https://developer.android.com/kotlin/style-guide) does not include
* trailing comma usage yet.
*/
@AutoCorrectable(since = "1.22.0")
class TrailingCommaOnDeclarationSite(config: Config) : FormattingRule(config) {

override val wrapping = TrailingCommaOnDeclarationSiteRule()
override val issue = issueFor("Rule to mandate/forbid trailing commas at declaration sites")

@Configuration("Defines whether a trailing comma (or no trailing comma) should be enforced at declaration sites")
private val useTrailingCommaOnDeclarationSite by config(false)
@Configuration("Defines whether trailing commas are required (true) or forbidden (false) at declaration sites")
private val useTrailingCommaOnDeclarationSite by configWithAndroidVariants(
defaultValue = true,
defaultAndroidValue = false,
)

override fun overrideEditorConfigProperties(): Map<UsesEditorConfigProperties.EditorConfigProperty<*>, String> =
mapOf(
Expand Down
4 changes: 2 additions & 2 deletions detekt-formatting/src/main/resources/config/config.yml
Expand Up @@ -182,11 +182,11 @@ formatting:
TrailingCommaOnCallSite:
active: false
autoCorrect: true
useTrailingCommaOnCallSite: false
useTrailingCommaOnCallSite: true
TrailingCommaOnDeclarationSite:
active: false
autoCorrect: true
useTrailingCommaOnDeclarationSite: false
useTrailingCommaOnDeclarationSite: true
TypeArgumentListSpacing:
active: false
autoCorrect: true
Expand Down
Expand Up @@ -90,5 +90,6 @@ object ConfigPrinter : DocumentationPrinter<List<RuleSetPage>> {
# - 'XmlOutputReport'
# - 'HtmlOutputReport'
# - 'MdOutputReport'
# - 'SarifOutputReport'
""".trimIndent()
}
9 changes: 3 additions & 6 deletions detekt-gradle-plugin/build.gradle.kts
Expand Up @@ -5,7 +5,7 @@ plugins {
idea
alias(libs.plugins.pluginPublishing)
// We use this published version of the Detekt plugin to self analyse this project.
id("io.gitlab.arturbosch.detekt") version "1.21.0"
id("io.gitlab.arturbosch.detekt") version "1.22.0"
id("org.gradle.test-retry") version "1.4.1"
}

Expand Down Expand Up @@ -38,6 +38,7 @@ testing {

dependencies {
implementation(libs.assertj)
implementation(testFixtures(project(":")))
}

targets {
Expand Down Expand Up @@ -67,15 +68,11 @@ dependencies {
compileOnly(libs.kotlin.gradlePluginApi)
implementation(libs.sarif4k)

// Migrate to `implementation(testFixtures(project))` in test suite configuration when this issue is fixed:
// https://github.com/gradle/gradle/pull/19472
functionalTestImplementation(testFixtures(project))

pluginCompileOnly(libs.android.gradle)
pluginCompileOnly(libs.kotlin.gradle)

// We use this published version of the detekt-formatting to self analyse this project.
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.21.0")
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.22.0")
}

gradlePlugin {
Expand Down
Expand Up @@ -589,9 +589,8 @@ class DetektAndroidSpec {
internal fun isAndroidSdkInstalled() =
System.getenv("ANDROID_SDK_ROOT") != null || System.getenv("ANDROID_HOME") != null

internal fun manifestContent(packageName: String = "io.gitlab.arturbosch.detekt.app") = """
<manifest package="$packageName"
xmlns:android="http://schemas.android.com/apk/res/android"/>
internal fun manifestContent() = """
<manifest xmlns:android="http://schemas.android.com/apk/res/android"/>
""".trimIndent()

private val APP_PLUGIN_BLOCK = """
Expand Down Expand Up @@ -620,12 +619,14 @@ private val KOTLIN_ONLY_LIB_PLUGIN_BLOCK = """
private val ANDROID_BLOCK = """
android {
compileSdk = 30
namespace = "io.gitlab.arturbosch.detekt.app"
}
""".trimIndent()

private val ANDROID_BLOCK_WITH_FLAVOR = """
android {
compileSdk = 30
namespace = "io.gitlab.arturbosch.detekt.app"
flavorDimensions("age", "name")
productFlavors {
create("harry") {
Expand All @@ -644,6 +645,7 @@ private val ANDROID_BLOCK_WITH_FLAVOR = """
private val ANDROID_BLOCK_WITH_VIEW_BINDING = """
android {
compileSdk = 30
namespace = "io.gitlab.arturbosch.detekt.app"
defaultConfig {
applicationId = "io.gitlab.arturbosch.detekt.app"
minSdk = 24
Expand Down
Expand Up @@ -154,6 +154,7 @@ class DetektMultiplatformSpec {
}
android {
compileSdk = 30
namespace = "io.gitlab.arturbosch.detekt.app"
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
buildTypes {
release {
Expand Down

0 comments on commit 84ba660

Please sign in to comment.