Skip to content

Commit

Permalink
Merge branch 'main' into nc/composite-build
Browse files Browse the repository at this point in the history
  • Loading branch information
chao2zhang committed Apr 24, 2022
2 parents 17d9c94 + 17a62ec commit 881a353
Show file tree
Hide file tree
Showing 174 changed files with 8,708 additions and 16,834 deletions.
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
@@ -1,7 +1,7 @@
# Contributing to detekt

- Read [this article](https://chris.beams.io/posts/git-commit/) before writing commit messages.
- Use `gradle buildAll -x dokkaJekyll` to build the source but exclude documentation JAR generation to save time.
- Use `gradle buildAll -x dokkaHtml` to build the source but exclude documentation JAR generation to save time.
- Make sure that `gradle detekt` does not report any errors.
- This repository follows the [Kotlin coding conventions](https://kotlinlang.org/docs/reference/coding-conventions.html),
which are enforced by ktlint when running `gradle detekt`.
Expand Down
4 changes: 2 additions & 2 deletions .github/labeler.yml
Expand Up @@ -14,14 +14,14 @@ cli:
- "detekt-cli/src/**/*"

core:
- "detekt-core/src/**/*"
- "detekt-core/src/**/*.kt"

dependencies:
- "gradle/libs.versions.toml"

documentation:
- "**/*.md"
- "docs/**/*"
- "website/**/*"

formatting:
- "detekt-formatting/src/**/*"
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/codecoverage.yaml
Expand Up @@ -8,6 +8,9 @@ on:
branches:
- '**'

permissions:
contents: read

jobs:
publish-code-coverage:
if: ${{ !contains(github.event.head_commit.message, 'coverage skip') }}
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/deploy-snapshot.yaml
Expand Up @@ -5,6 +5,9 @@ on:
branches:
- main

permissions:
contents: read

jobs:
gradle:
runs-on: ubuntu-latest
Expand Down
105 changes: 0 additions & 105 deletions .github/workflows/deploy-website.yaml

This file was deleted.

6 changes: 6 additions & 0 deletions .github/workflows/detekt-with-type-resolution.yaml
Expand Up @@ -11,8 +11,14 @@ on:
env:
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}

permissions:
contents: read

jobs:
plain:
permissions:
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
runs-on: ubuntu-latest
if: ${{ !contains(github.event.head_commit.message, 'ci skip') }}
steps:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/fossascan.yaml
Expand Up @@ -5,6 +5,9 @@ on:
branches:
- main

permissions:
contents: read

jobs:
fossa-scan:
if: ${{ github.repository == 'detekt/detekt' }}
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/gradle-wrapper-validation.yml
Expand Up @@ -7,6 +7,9 @@ on:
branches:
- '**'

permissions:
contents: read

jobs:
validation:
name: Validation
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/pre-merge.yaml
Expand Up @@ -11,6 +11,9 @@ on:
env:
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}

permissions:
contents: read

jobs:
gradle:
if: ${{ !contains(github.event.head_commit.message, 'ci skip') }}
Expand Down
53 changes: 53 additions & 0 deletions .github/workflows/website.yaml
@@ -0,0 +1,53 @@
name: Build and Deploy Website

on:
push:
branches:
- main
pull_request:
branches:
- '**'

permissions:
contents: write # for JamesIves/github-pages-deploy-action to push changes in repo

jobs:
build-detekt-docs:
if: github.repository == 'detekt/detekt'
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Setup Java
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'temurin'

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: '16'
cache: 'yarn'
cache-dependency-path: 'website/yarn.lock'

- name: Build Detekt Documentation
uses: gradle/gradle-build-action@v2
with:
arguments: :detekt-generator:generateDocumentation

- name: Install Yarn Dependencies
working-directory: website/
run: yarn install

- name: Build the Detekt Website
working-directory: website/
run: yarn build

- name: Deploy Github Pages (only on main)
uses: JamesIves/github-pages-deploy-action@v4
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
with:
branch: gh-pages
folder: website/build/
9 changes: 3 additions & 6 deletions .gitignore
Expand Up @@ -158,14 +158,11 @@ target/
/detekt-cli/src/test/kotlin/io/gitlab/arturbosch/detekt/cli/Test.kt
*.iml
*/out
/docs/_site
/docs/.bundle

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

# Avoid committing generated documentation to the repo
/docs/pages/documentation
/docs/pages/kdoc
/docs/pages/gettingstarted/cli-options.md
/docs/vendor/
/website/docs/rules
/website/static/kdoc
/website/docs/gettingstarted/cli-options.md
6 changes: 3 additions & 3 deletions build-logic/src/main/kotlin/releasing.gradle.kts
Expand Up @@ -65,8 +65,8 @@ tasks {
register("incrementMajor") { doLast { updateVersion { it.nextMajor() } } }

register<UpdateVersionInFileTask>("applyDocVersion") {
fileToUpdate.set(file("${rootProject.rootDir}/docs/_config.yml"))
linePartToFind.set("detekt_version:")
lineTransformation.set("detekt_version: ${Versions.DETEKT}")
fileToUpdate.set(file("${rootProject.rootDir}/website/docusaurus.config.js"))
linePartToFind.set(" detektVersion:")
lineTransformation.set(" detektVersion: '${Versions.DETEKT}'")
}
}
2 changes: 1 addition & 1 deletion config/detekt/detekt.yml
Expand Up @@ -243,7 +243,7 @@ style:
UntilInsteadOfRangeTo:
active: true
UnusedImports:
active: true
active: false # formatting already have this rule enabled
UnusedPrivateMember:
active: true
allowedNames: '(_|ignored|expected)'
Expand Down
6 changes: 2 additions & 4 deletions detekt-api/build.gradle.kts
Expand Up @@ -16,8 +16,6 @@ dependencies {
testImplementation(libs.assertj)

testFixturesApi(libs.kotlin.stdlibJdk8)

dokkaJekyllPlugin(libs.dokka.jekyll)
}

val javaComponent = components["java"] as AdhocComponentWithVariants
Expand All @@ -30,10 +28,10 @@ listOf(configurations.testFixturesApiElements, configurations.testFixturesRuntim
}

tasks.withType<DokkaTask>().configureEach {
outputDirectory.set(rootDir.resolve("docs/pages/kdoc"))
outputDirectory.set(rootDir.resolve("website/static/kdoc"))
}

tasks.dokkaJekyll {
tasks.dokkaHtml {
notCompatibleWithConfigurationCache("https://github.com/Kotlin/dokka/issues/1217")
}

Expand Down
1 change: 1 addition & 0 deletions detekt-core/src/main/resources/default-detekt-config.yml
Expand Up @@ -675,6 +675,7 @@ style:
active: true
VarCouldBeVal:
active: true
ignoreLateinitVar: false
WildcardImport:
active: true
excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**']
Expand Down
6 changes: 3 additions & 3 deletions detekt-generator/build.gradle.kts
Expand Up @@ -18,9 +18,9 @@ dependencies {
testImplementation(libs.reflections)
}

val documentationDir = "${rootProject.rootDir}/docs/pages/documentation"
val documentationDir = "${rootProject.rootDir}/website/docs/rules"
val configDir = "${rootProject.rootDir}/detekt-core/src/main/resources"
val cliOptionsFile = "${rootProject.rootDir}/docs/pages/gettingstarted/cli-options.md"
val cliOptionsFile = "${rootProject.rootDir}/website/docs/gettingstarted/cli-options.md"
val defaultConfigFile = "$configDir/default-detekt-config.yml"
val deprecationFile = "$configDir/deprecation.properties"

Expand All @@ -31,7 +31,7 @@ val ruleModules = rootProject.subprojects
.map { "${rootProject.rootDir}/$it/src/main/kotlin" }

val generateDocumentation by tasks.registering(JavaExec::class) {
dependsOn(tasks.assemble, ":detekt-api:dokkaJekyll")
dependsOn(tasks.assemble, ":detekt-api:dokkaHtml")
description = "Generates detekt documentation and the default config.yml based on Rule KDoc"
group = "documentation"

Expand Down
Expand Up @@ -20,7 +20,7 @@ class DetektPrinter(private val arguments: GeneratorArgs) {
fun print(pages: List<RuleSetPage>) {
pages.forEach {
markdownWriter.write(arguments.documentationPath, it.ruleSet.name) {
jekyllHeader(it.ruleSet.name) + "\n" + RuleSetPagePrinter.print(it)
markdownHeader(it.ruleSet.name) + "\n" + RuleSetPagePrinter.print(it)
}
}
yamlWriter.write(arguments.configPath, "default-detekt-config") {
Expand All @@ -38,13 +38,13 @@ class DetektPrinter(private val arguments: GeneratorArgs) {
}
}

private fun jekyllHeader(ruleSet: String): String {
private fun markdownHeader(ruleSet: String): String {
check(ruleSet.length > 1) { "Rule set name must be not empty or less than two symbols." }
return """
|---
|title: ${ruleSet[0].toUpperCase()}${ruleSet.substring(1)} Rule Set
|sidebar: home_sidebar
|keywords: rules, $ruleSet
|keywords: [rules, $ruleSet]
|permalink: $ruleSet.html
|toc: true
|folder: documentation
Expand Down
Expand Up @@ -17,7 +17,7 @@ internal object RulePrinter : DocumentationPrinter<Rule> {
h3 { item.name }

if (item.description.isNotEmpty()) {
paragraph { item.description }
paragraph { escapeHtml(item.description) }
} else {
paragraph { "TODO: Specify description" }
}
Expand Down Expand Up @@ -62,4 +62,8 @@ internal object RulePrinter : DocumentationPrinter<Rule> {
paragraph { codeBlock { rule.compliantCodeExample } }
}
}

internal fun escapeHtml(input: String) = input
.replace("<", "&lt;")
.replace(">", "&gt;")
}
Expand Up @@ -43,6 +43,14 @@ internal class RulePrinterTest {
val actual = RulePrinter.print(rule)
assertThat(actual).contains(description)
}

@Test
fun `with html tags`() {
val description = "The return type is Array<String>"
val rule = ruleTemplate.copy(description = description)
val actual = RulePrinter.print(rule)
assertThat(actual).contains("The return type is Array&lt;String&gt;")
}
}

@Nested
Expand Down

0 comments on commit 881a353

Please sign in to comment.