Skip to content

Commit

Permalink
add flexmark gradle support (#1801)
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg authored Sep 28, 2023
2 parents fed839a + 9ac3edc commit d518fd3
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 12 deletions.
6 changes: 3 additions & 3 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (

## [Unreleased]
### Added
* Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)).

* Add support for biome. The Rome project [was renamed to Biome](https://biomejs.dev/blog/annoucing-biome/).
The configuration is still the same, but you should switch to the new `biome` tag / function and adjust
the version accordingly. ([#1804](https://github.com/diffplug/spotless/issues/1804)).

### Fixed
* Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802))
### Changes
* Bump default `flexmark` version to latest `0.64.0` -> `0.64.8`. ([#1801](https://github.com/diffplug/spotless/pull/1801))
* Bump default `ktlint` version to latest `0.50.0` -> `1.0.0`. ([#1808](https://github.com/diffplug/spotless/pull/1808))

## [2.41.0] - 2023-08-29
### Added
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ lib('kotlin.KtLintStep') +'{{yes}} | {{yes}}
lib('kotlin.KtfmtStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
lib('kotlin.DiktatStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
lib('markdown.FreshMarkStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |',
lib('markdown.FlexmarkStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |',
lib('markdown.FlexmarkStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
lib('npm.EslintFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
lib('npm.PrettierFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
lib('npm.TsFmtFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
Expand Down Expand Up @@ -146,7 +146,7 @@ lib('yaml.JacksonYamlStep') +'{{yes}} | {{yes}}
| [`kotlin.KtfmtStep`](lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
| [`kotlin.DiktatStep`](lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
| [`markdown.FreshMarkStep`](lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: |
| [`markdown.FlexmarkStep`](lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: |
| [`markdown.FlexmarkStep`](lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
| [`npm.EslintFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
| [`npm.PrettierFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
| [`npm.TsFmtFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class FlexmarkStep {
// prevent direct instantiation
private FlexmarkStep() {}

private static final String DEFAULT_VERSION = "0.64.0";
private static final String DEFAULT_VERSION = "0.64.8";
private static final String NAME = "flexmark-java";
private static final String MAVEN_COORDINATE = "com.vladsch.flexmark:flexmark-all:";

Expand Down
6 changes: 3 additions & 3 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (

## [Unreleased]
### Added
* Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)).

* Support `flexmark` in gradle. Previously only Maven was supported. ([#1801](https://github.com/diffplug/spotless/pull/1801))
* Add support for biome. The Rome project [was renamed to Biome](https://biomejs.dev/blog/annoucing-biome/).
The configuration is still the same, but you should switch to the new `biome(...)` function and adjust
the version accordingly. ([#1804](https://github.com/diffplug/spotless/issues/1804)).

### Fixed
* Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802))
### Changes
* Bump default `ktlint` version to latest `0.50.0` -> `1.0.0`. ([#1808](https://github.com/diffplug/spotless/pull/1808))

## [6.21.0] - 2023-08-29
### Added
Expand Down
20 changes: 20 additions & 0 deletions plugin-gradle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Spotless supports all of Gradle's built-in performance features (incremental bui
- [Protobuf](#protobuf) ([buf](#buf), [clang-format](#clang-format))
- [Python](#python) ([black](#black))
- [FreshMark](#freshmark) aka markdown
- [Flexmark](#flexmark) aka markdown
- [Antlr4](#antlr4) ([antlr4formatter](#antlr4formatter))
- [SQL](#sql) ([dbeaver](#dbeaver), [prettier](#prettier))
- [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [ESLint](#eslint-typescript), [Biome](#biome))
Expand Down Expand Up @@ -577,6 +578,25 @@ spotless {
}
```
## Flexmark
`com.diffplug.gradle.spotless.FlexmarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FlexmarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java)
[homepage](https://github.com/vsch/flexmark-java). Flexmark is a flexible Commonmark/Markdown parser that can be used to format Markdown files. It supports different [flavors of Markdown](https://github.com/vsch/flexmark-java#markdown-processor-emulation) and [many formatting options](https://github.com/vsch/flexmark-java/wiki/Markdown-Formatter#options).
Currently, none of the available options can be configured yet. It uses only the default options together with `COMMONMARK` as `FORMATTER_EMULATION_PROFILE`.
To apply flexmark to all of the `.md` files in your project, use this snippet:
```gradle
spotless {
flexmark {
target '**/*.md' // you have to set the target manually
flexmark() // or flexmark('0.64.8') // version is optional
}
}
```
## Antlr4
`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright 2023 DiffPlug
*
* 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.diffplug.gradle.spotless;

import java.util.Objects;

import javax.inject.Inject;

import com.diffplug.spotless.FormatterStep;
import com.diffplug.spotless.markdown.FlexmarkStep;

public class FlexmarkExtension extends FormatExtension {
static final String NAME = "flexmark";

@Inject
public FlexmarkExtension(SpotlessExtension spotless) {
super(spotless);
}

public FlexmarkFormatterConfig flexmark() {
return flexmark(FlexmarkStep.defaultVersion());
}

public FlexmarkFormatterConfig flexmark(String version) {
return new FlexmarkFormatterConfig(version);
}

@Override
protected void setupTask(SpotlessTask task) {
// defaults to all markdown files
if (target == null) {
throw noDefaultTargetException();
}
super.setupTask(task);
}

public class FlexmarkFormatterConfig {

private final String version;

FlexmarkFormatterConfig(String version) {
this.version = Objects.requireNonNull(version);
addStep(createStep());
}

private FormatterStep createStep() {
return FlexmarkStep.create(this.version, provisioner());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ public void freshmark(Action<FreshMarkExtension> closure) {
format(FreshMarkExtension.NAME, FreshMarkExtension.class, closure);
}

/** Configures the special flexmark-specific extension. */
public void flexmark(Action<FlexmarkExtension> closure) {
requireNonNull(closure);
format(FlexmarkExtension.NAME, FlexmarkExtension.class, closure);
}

/** Configures the special groovy-specific extension. */
public void groovy(Action<GroovyExtension> closure) {
format(GroovyExtension.NAME, GroovyExtension.class, closure);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2023 DiffPlug
*
* 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.diffplug.gradle.spotless;

import java.io.IOException;

import org.junit.jupiter.api.Test;

class FlexmarkExtensionTest extends GradleIntegrationHarness {
@Test
void integration() throws IOException {
setFile("build.gradle").toLines(
"plugins {",
" id 'java'",
" id 'com.diffplug.spotless'",
"}",
"repositories { mavenCentral() }",
"spotless {",
" flexmark {",
" target '*.md'",
" flexmark()",
" }",
"}");
setFile("markdown_test.md").toResource("markdown/flexmark/FlexmarkUnformatted.md");
gradleRunner().withArguments("spotlessApply").build();
assertFile("markdown_test.md").sameAsResource("markdown/flexmark/FlexmarkFormatted.md");
}
}
6 changes: 3 additions & 3 deletions plugin-maven/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (

## [Unreleased]
### Added
* Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)).

* Add support for biome. The Rome project [was renamed to Biome](https://biomejs.dev/blog/annoucing-biome/).
The configuration is still the same, but you should switch to the new `<biome>` tag and adjust
the version accordingly. ([#1804](https://github.com/diffplug/spotless/issues/1804)).

### Fixed
* Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802))
### Changes
* Bump default `flexmark` version to latest `0.64.0` -> `0.64.8`. ([#1801](https://github.com/diffplug/spotless/pull/1801))
* Bump default `ktlint` version to latest `0.50.0` -> `1.0.0`. ([#1808](https://github.com/diffplug/spotless/pull/1808))

## [2.39.0] - 2023-08-29
### Added
Expand Down

0 comments on commit d518fd3

Please sign in to comment.