Skip to content

Commit

Permalink
Setup a Remark plugin to replace [detekt_version] with the current ve…
Browse files Browse the repository at this point in the history
…rsion on website (#5001)
  • Loading branch information
cortinico committed Jun 27, 2022
1 parent c8eb24c commit 5ff82e1
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 43 deletions.
6 changes: 3 additions & 3 deletions build-logic/src/main/kotlin/releasing.gradle.kts
Expand Up @@ -66,9 +66,9 @@ tasks {
register("incrementMajor") { doLast { updateVersion { it.nextMajor() } } }

register<UpdateVersionInFileTask>("applyDocVersion") {
fileToUpdate.set(file("${rootProject.rootDir}/website/docusaurus.config.js"))
linePartToFind.set(" detektVersion:")
lineTransformation.set(" detektVersion: '${Versions.DETEKT}'")
fileToUpdate.set(file("${rootProject.rootDir}/website/src/remark/detektVersionReplace.js"))
linePartToFind.set("const detektVersion = ")
lineTransformation.set("const detektVersion = \"${Versions.DETEKT}\";")
}
}

Expand Down
5 changes: 0 additions & 5 deletions website/docs/_detekt-version-banner.mdx

This file was deleted.

8 changes: 0 additions & 8 deletions website/docs/_detekt-version.jsx

This file was deleted.

3 changes: 0 additions & 3 deletions website/docs/gettingstarted/cli.mdx
Expand Up @@ -8,7 +8,6 @@ summary:
sidebar_position: 1
---

import DetektVersionBanner from "../_detekt-version-banner.mdx";
import CliOptions from "./_cli-options.md";

## Install the cli
Expand All @@ -31,8 +30,6 @@ detekt [options]

### Any OS:

<DetektVersionBanner />

```sh
curl -sSLO https://github.com/detekt/detekt/releases/download/v[detekt_version]/detekt-cli-[detekt_version].zip
unzip detekt-cli-[detekt_version].zip
Expand Down
4 changes: 0 additions & 4 deletions website/docs/gettingstarted/gradle.mdx
Expand Up @@ -8,8 +8,6 @@ summary:
sidebar_position: 2
---

import DetektVersionBanner from "../\_detekt-version-banner.mdx";

Detekt requires **Gradle 6.1** or higher. We, however, recommend using the version of Gradle that is [listed in this table](/docs/introduction/compatibility).

## <a name="tasks">Available plugin tasks</a>
Expand Down Expand Up @@ -64,8 +62,6 @@ Using the plugins DSL:

#### Groovy DSL

<DetektVersionBanner/>

```groovy
plugins {
id "io.gitlab.arturbosch.detekt" version "[detekt_version]"
Expand Down
4 changes: 0 additions & 4 deletions website/docs/gettingstarted/gradletask.md
Expand Up @@ -8,13 +8,9 @@ summary:
sidebar_position: 3
---

import DetektVersionBanner from "../\_detekt-version-banner.mdx";

1. Add following lines to your build.gradle file.
2. Run `gradle detekt`

<DetektVersionBanner/>

###### Groovy DSL
```groovy
repositories {
Expand Down
4 changes: 0 additions & 4 deletions website/docs/gettingstarted/mavenanttask.md
Expand Up @@ -8,13 +8,9 @@ summary:
sidebar_position: 4
---

import DetektVersionBanner from "../\_detekt-version-banner.mdx";

1. Add following lines to your pom.xml.
2. Run `mvn verify` (when using the verify phase as we are doing here)

<DetektVersionBanner/>

```xml
<build>
<plugins>
Expand Down
4 changes: 0 additions & 4 deletions website/docs/intro.mdx
Expand Up @@ -5,8 +5,6 @@ sidebar_position: 1
summary:
---

import DetektVersionBanner from "./\_detekt-version-banner.mdx";

![detekt logo](/img/logo.svg "detekt logo")
![detekt in action](/img/tutorial/detekt_in_action.png "detekt in action")

Expand All @@ -26,8 +24,6 @@ import DetektVersionBanner from "./\_detekt-version-banner.mdx";

Apply the following configuration to your Gradle project build file:

<DetektVersionBanner/>

```kotlin
plugins {
id("io.gitlab.arturbosch.detekt").version("[detekt_version]")
Expand Down
6 changes: 1 addition & 5 deletions website/docs/introduction/extensions.md
Expand Up @@ -5,8 +5,6 @@ keywords: [extensions, rulesets]
sidebar_position: 9
---

import DetektVersionBanner from "../\_detekt-version-banner.mdx";

The following page describes how to extend detekt and how to customize it to your domain-specific needs.
The associated **code samples** to this guide can be found in the package [detekt/detekt-sample-extensions](https://github.com/detekt/detekt/tree/main/detekt-sample-extensions).

Expand Down Expand Up @@ -221,11 +219,9 @@ To enable it, we add the published dependency to `detekt` via the `detektPlugins

###### Gradle (Kotlin/Groovy DSL)

<DetektVersionBanner/>

```kotlin
dependencies {
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:{{ site.detekt_version }}")
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:[detekt_version]")
}
```

Expand Down
5 changes: 2 additions & 3 deletions website/docusaurus.config.js
Expand Up @@ -3,6 +3,7 @@

const lightCodeTheme = require('prism-react-renderer/themes/github');
const darkCodeTheme = require('prism-react-renderer/themes/dracula');
const detektVersionReplace = require('./src/remark/detektVersionReplace');

/** @type {import('@docusaurus/types').Config} */
const config = {
Expand All @@ -25,6 +26,7 @@ const config = {
docs: {
sidebarPath: require.resolve('./sidebars.js'),
editUrl: 'https://github.com/detekt/detekt/edit/main/website/',
remarkPlugins: [detektVersionReplace],
},
blog: {
showReadingTime: true,
Expand Down Expand Up @@ -179,9 +181,6 @@ const config = {
},
}),

customFields: {
detektVersion: '1.21.0-RC1'
},
};

module.exports = config;
19 changes: 19 additions & 0 deletions website/src/remark/detektVersionReplace.js
@@ -0,0 +1,19 @@
const visit = require("unist-util-visit");

// Remark plugin that is replacing the [detekt_version] with the latest
// released version. Please note that this field is updated automatically
// by the `:detekt-generator:generateDocumentation` task.
const detektVersion = "1.21.0-RC1";

const plugin = (options) => {
const transformer = async (ast) => {
visit(ast, "code", (node) => {
if (node.value.includes("[detekt_version]")) {
node.value = node.value.replace("[detekt_version]", detektVersion);
}
});
};
return transformer;
};

module.exports = plugin;

0 comments on commit 5ff82e1

Please sign in to comment.