diff --git a/CHANGES.md b/CHANGES.md index 887b2b062b..82b6839819 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,6 +15,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Added * `prettier` will now autodetect the parser (and formatter) to use based on the filename, unless you override this using `config` or `configFile` with the option `parser` or `filepath`. ([#620](https://github.com/diffplug/spotless/pull/620)) * `GitRatchet` now lives in `lib-extra`, and is shared across `plugin-gradle` and `plugin-maven` ([#626](https://github.com/diffplug/spotless/pull/626)). +* Added ANTLR4 support ([#326](https://github.com/diffplug/spotless/issues/326)). ### Changed * **BREAKING** `FileSignature` can no longer sign folders, only files. Signatures are now based only on filename (not path), size, and a content hash. It throws an error if a signature is attempted on a folder or on multiple files with different paths but the same filename - it never breaks silently. This change does not break any of Spotless' internal logic, so it is unlikely to affect any of Spotless' consumers either. ([#571](https://github.com/diffplug/spotless/pull/571)) * This change allows the maven plugin to cache classloaders across subprojects when loading config resources from the classpath (fixes [#559](https://github.com/diffplug/spotless/issues/559)). diff --git a/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4Defaults.java b/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4Defaults.java new file mode 100644 index 0000000000..53223c087f --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4Defaults.java @@ -0,0 +1,31 @@ +/* + * Copyright 2016-2020 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.spotless.antlr4; + +public class Antlr4Defaults { + private static final String LICENSE_HEADER_DELIMITER = "(grammar|lexer grammar|parser grammar)"; + private static final String INCLUDES = "src/*/antlr4/**/*.g4"; + + private Antlr4Defaults() {} + + public static String licenseHeaderDelimiter() { + return LICENSE_HEADER_DELIMITER; + } + + public static String includes() { + return INCLUDES; + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java b/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java new file mode 100644 index 0000000000..d71182c65d --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java @@ -0,0 +1,74 @@ +/* + * Copyright 2016-2020 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.spotless.antlr4; + +import java.io.IOException; +import java.io.Serializable; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import com.diffplug.spotless.*; + +public class Antlr4FormatterStep { + + public static final String NAME = "antlr4Formatter"; + + private Antlr4FormatterStep() {} + + private static final String MAVEN_COORDINATE = "com.khubla.antlr4formatter:antlr4-formatter:"; + private static final String DEFAULT_VERSION = "1.2.1"; + + public static FormatterStep create(Provisioner provisioner) { + return create(defaultVersion(), provisioner); + } + + public static FormatterStep create(String version, Provisioner provisioner) { + return FormatterStep.createLazy(NAME, () -> new State(version, provisioner), State::createFormat); + } + + public static String defaultVersion() { + return DEFAULT_VERSION; + } + + static final class State implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * The jar that contains the formatter. + */ + final JarState jarState; + + State(String version, Provisioner provisioner) throws IOException { + this.jarState = JarState.from(MAVEN_COORDINATE + version, provisioner); + } + + FormatterFunc createFormat() throws ClassNotFoundException, NoSuchMethodException { + ClassLoader classLoader = jarState.getClassLoader(); + + // String Antlr4Formatter::format(String input) + Class formatter = classLoader.loadClass("com.khubla.antlr4formatter.Antlr4Formatter"); + Method formatterMethod = formatter.getMethod("format", String.class); + + return input -> { + try { + return (String) formatterMethod.invoke(null, input); + } catch (InvocationTargetException e) { + throw ThrowingEx.unwrapCause(e); + } + }; + } + } +} diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 444f749909..9e5e1761f5 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -9,6 +9,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Full support for the Gradle buildcache - previously only supported local, now supports remote too. Fixes [#566](https://github.com/diffplug/spotless/issues/566) and [#280](https://github.com/diffplug/spotless/issues/280), via changes in [#621](https://github.com/diffplug/spotless/pull/621) and [#571](https://github.com/diffplug/spotless/pull/571). * `prettier` will now autodetect the parser (and formatter) to use based on the filename, unless you override this using `config()` or `configFile()` with the option `parser` or `filepath`. ([#620](https://github.com/diffplug/spotless/pull/620)) * (user-invisible) moved the deprecated lib code which was only being used in deprecated parts of `plugin-gradle` into the `.libdeprecated` package. ([#630](https://github.com/diffplug/spotless/pull/630)) +* Added ANTLR4 support ([#326](https://github.com/diffplug/spotless/issues/326)). ### Fixed * LineEndings.GIT_ATTRIBUTES is now a bit more efficient, and paves the way for remote build cache support in Gradle. ([#621](https://github.com/diffplug/spotless/pull/621)) * `ratchetFrom` now ratchets from the merge base of `HEAD` and the specified branch. This fixes the surprising behavior when a remote branch advanced ([#631](https://github.com/diffplug/spotless/pull/631) fixes [#627](https://github.com/diffplug/spotless/issues/627)). diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java new file mode 100644 index 0000000000..76076987e0 --- /dev/null +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java @@ -0,0 +1,70 @@ +/* + * Copyright 2016-2020 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 com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.antlr4.Antlr4Defaults; +import com.diffplug.spotless.antlr4.Antlr4FormatterStep; + +public class Antlr4Extension extends FormatExtension implements HasBuiltinDelimiterForLicense { + static final String NAME = "antlr4"; + + public Antlr4Extension(SpotlessExtensionBase rootExtension) { + super(rootExtension); + } + + public Antlr4FormatterConfig antlr4Formatter() { + return antlr4Formatter(Antlr4FormatterStep.defaultVersion()); + } + + public Antlr4FormatterConfig antlr4Formatter(String version) { + return new Antlr4FormatterConfig(version); + } + + public class Antlr4FormatterConfig { + + private final String version; + + Antlr4FormatterConfig(String version) { + this.version = Objects.requireNonNull(version); + addStep(createStep()); + } + + private FormatterStep createStep() { + return Antlr4FormatterStep.create(this.version, provisioner()); + } + } + + @Override + protected void setupTask(SpotlessTask task) { + if (target == null) { + target = parseTarget(Antlr4Defaults.includes()); + } + super.setupTask(task); + } + + @Override + public LicenseHeaderConfig licenseHeader(String licenseHeader) { + return licenseHeader(licenseHeader, Antlr4Defaults.licenseHeaderDelimiter()); + } + + @Override + public LicenseHeaderConfig licenseHeaderFile(Object licenseHeaderFile) { + return licenseHeaderFile(licenseHeaderFile, Antlr4Defaults.licenseHeaderDelimiter()); + } +} diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtensionBase.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtensionBase.java index 1d7ed95b8a..9847a6542e 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtensionBase.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtensionBase.java @@ -161,6 +161,11 @@ public void typescript(Action closure) { format(TypescriptExtension.NAME, TypescriptExtension.class, closure); } + /** Configures the special antlr4-specific extension for antlr4 files. */ + public void antlr4(Action closure) { + format(Antlr4Extension.NAME, Antlr4Extension.class, closure); + } + /** Configures a custom extension. */ public void format(String name, Action closure) { requireNonNull(name, "name"); diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java new file mode 100644 index 0000000000..7ace7170be --- /dev/null +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java @@ -0,0 +1,79 @@ +/* + * Copyright 2016-2020 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.Test; + +public class Antlr4ExtensionTest extends GradleIntegrationHarness { + + @Test + public void applyUsingDefaultVersion() throws IOException { + String[] buildScript = { + "buildscript {", + " repositories {", + " mavenCentral()", + " }", + "}", + "plugins {", + " id 'com.diffplug.gradle.spotless'", + "}", + "spotless {", + " antlr4 {", + " target 'src/main/antlr4/**/*.g4'", + " antlr4Formatter()", + " }", + "}"}; + + assertAppliedFormat(buildScript); + } + + @Test + public void applyUsingCustomVersion() throws IOException { + String[] buildScript = { + "buildscript {", + " repositories {", + " mavenCentral()", + " }", + "}", + "plugins {", + " id 'com.diffplug.gradle.spotless'", + "}", + "spotless {", + " antlr4 {", + " target 'src/main/antlr4/**/*.g4'", + " antlr4Formatter('1.2.1')", + " }", + "}"}; + + assertAppliedFormat(buildScript); + } + + private void assertAppliedFormat(String... buildScript) throws IOException { + String testFile = "src/main/antlr4/Hello.g4"; + + setFile("build.gradle").toLines(buildScript); + + String unformatted = "antlr4/Hello.unformatted.g4"; + String formatted = "antlr4/Hello.formatted.g4"; + setFile(testFile).toResource(unformatted); + + gradleRunner().withArguments("spotlessApply").build(); + + assertFile(testFile).sameAsResource(formatted); + } +} diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index ce9d813d0e..8603a0e0d3 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -8,6 +8,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Huge speed improvement for multi-module projects thanks to improved cross-project classloader caching ([#571](https://github.com/diffplug/spotless/pull/571), fixes [#559](https://github.com/diffplug/spotless/issues/559)). * If you specify `-DspotlessSetLicenseHeaderYearsFromGitHistory=true`, Spotless will perform an expensive search through git history to determine the oldest and newest commits for each file, and uses that to determine license header years. ([#626](https://github.com/diffplug/spotless/pull/626)) * `prettier` will now autodetect the parser (and formatter) to use based on the filename, unless you override this using `config` or `configFile` with the option `parser` or `filepath` ([#620](https://github.com/diffplug/spotless/pull/620)). +* Added ANTLR4 support ([#326](https://github.com/diffplug/spotless/issues/326)). ### Removed * **BREAKING** the long-deprecated `` and `` formats have been removed, in favor of the long-available [``](https://github.com/diffplug/spotless/tree/main/plugin-maven#eclipse-wtp) step which is available in every generic format. * This probably doesn't affect you, but if it does, you just need to change `...` into `XML...` diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java index 36e2d65ec0..98ae47c788 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java @@ -47,6 +47,7 @@ import com.diffplug.spotless.LineEnding; import com.diffplug.spotless.Provisioner; import com.diffplug.spotless.generic.LicenseHeaderStep; +import com.diffplug.spotless.maven.antlr4.Antlr4; import com.diffplug.spotless.maven.cpp.Cpp; import com.diffplug.spotless.maven.generic.Format; import com.diffplug.spotless.maven.generic.LicenseHeader; @@ -108,6 +109,9 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo { @Parameter private Typescript typescript; + @Parameter + private Antlr4 antlr4; + @Parameter(property = "spotlessFiles") private String filePatterns; @@ -194,7 +198,7 @@ private FileLocator getFileLocator() { } private List getFormatterFactories() { - return Stream.concat(formats.stream(), Stream.of(java, scala, kotlin, cpp, typescript)) + return Stream.concat(formats.stream(), Stream.of(java, scala, kotlin, cpp, typescript, antlr4)) .filter(Objects::nonNull) .collect(toList()); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4.java new file mode 100644 index 0000000000..bc24ebcf16 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4.java @@ -0,0 +1,46 @@ +/* + * Copyright 2016-2020 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.spotless.maven.antlr4; + +import java.util.Set; + +import com.diffplug.common.collect.ImmutableSet; +import com.diffplug.spotless.antlr4.Antlr4Defaults; +import com.diffplug.spotless.maven.FormatterFactory; +import com.diffplug.spotless.maven.generic.LicenseHeader; + +/** + * A {@link FormatterFactory} implementation that corresponds to {@code ...} configuration element. + *

+ * It defines a formatter for ANTLR4 source files that can execute both language agnostic (e.g. {@link LicenseHeader}) + * and anltr4-specific (e.g. {@link Antlr4Formatter}) steps. + */ +public class Antlr4 extends FormatterFactory { + @Override + public Set defaultIncludes() { + return ImmutableSet.of(Antlr4Defaults.includes()); + } + + @Override + public String licenseHeaderDelimiter() { + return Antlr4Defaults.licenseHeaderDelimiter(); + } + + public void addAntlr4Formatter(Antlr4Formatter antlr4Formatter) { + addStepFactory(antlr4Formatter); + } + +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4Formatter.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4Formatter.java new file mode 100644 index 0000000000..3a6eb61145 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4Formatter.java @@ -0,0 +1,35 @@ +/* + * Copyright 2016-2020 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.spotless.maven.antlr4; + +import org.apache.maven.plugins.annotations.Parameter; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.antlr4.Antlr4FormatterStep; +import com.diffplug.spotless.maven.FormatterStepConfig; +import com.diffplug.spotless.maven.FormatterStepFactory; + +public class Antlr4Formatter implements FormatterStepFactory { + + @Parameter + private String version; + + @Override + public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { + String version = this.version == null ? Antlr4FormatterStep.defaultVersion() : this.version; + return Antlr4FormatterStep.create(version, stepConfig.getProvisioner()); + } +} diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java index 875e483271..52211054df 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java @@ -98,6 +98,10 @@ protected void writePomWithFormatSteps(String... steps) throws IOException { writePom(formats(groupWithSteps("format", including("src/**/java/**/*.java"), steps))); } + protected void writePomWithAntlr4Steps(String... steps) throws IOException { + writePom(groupWithSteps("antlr4", steps)); + } + protected void writePomWithJavaSteps(String... steps) throws IOException { writePom(groupWithSteps("java", steps)); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java new file mode 100644 index 0000000000..4623450e38 --- /dev/null +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java @@ -0,0 +1,54 @@ +/* + * Copyright 2016-2020 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.spotless.maven.antlr4; + +import org.junit.Test; + +import com.diffplug.spotless.maven.MavenIntegrationHarness; + +public class Antlr4FormatterTest extends MavenIntegrationHarness { + + @Test + public void applyUsingCustomVersion() throws Exception { + writePomWithAntlr4Steps( + "", + " 1.2.1", + ""); + runTest(); + } + + @Test + public void applyUsingDefaultVersion() throws Exception { + writePomWithAntlr4Steps( + "", + ""); + runTest(); + } + + @Test + public void applyUsingDefaultVersionSelfclosing() throws Exception { + writePomWithAntlr4Steps( + ""); + runTest(); + } + + private void runTest() throws Exception { + String path = "src/main/antlr4/Hello.g4"; + setFile(path).toResource("antlr4/Hello.unformatted.g4"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile(path).sameAsResource("antlr4/Hello.formatted.g4"); + } +} diff --git a/testlib/src/main/resources/antlr4/Hello.formatted.g4 b/testlib/src/main/resources/antlr4/Hello.formatted.g4 new file mode 100644 index 0000000000..5f73eb0e22 --- /dev/null +++ b/testlib/src/main/resources/antlr4/Hello.formatted.g4 @@ -0,0 +1,16 @@ +// Define a grammar called Hello + +grammar Hello; + +r + : 'hello' ID + ; // match keyword hello followed by an identifier + +ID + : [a-z]+ + ; // match lower-case identifiers + +WS + : [ \t\r\n]+ -> skip + ; // skip spaces, tabs, newlines + diff --git a/testlib/src/main/resources/antlr4/Hello.unformatted.g4 b/testlib/src/main/resources/antlr4/Hello.unformatted.g4 new file mode 100644 index 0000000000..a8af619185 --- /dev/null +++ b/testlib/src/main/resources/antlr4/Hello.unformatted.g4 @@ -0,0 +1,5 @@ +// Define a grammar called Hello +grammar Hello; +r : 'hello' ID ; // match keyword hello followed by an identifier +ID : [a-z]+ ; // match lower-case identifiers +WS : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines diff --git a/testlib/src/test/java/com/diffplug/spotless/antlr4/Antlr4FormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/antlr4/Antlr4FormatterStepTest.java new file mode 100644 index 0000000000..0eb4d92cd8 --- /dev/null +++ b/testlib/src/test/java/com/diffplug/spotless/antlr4/Antlr4FormatterStepTest.java @@ -0,0 +1,32 @@ +/* + * Copyright 2016-2020 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.spotless.antlr4; + +import org.junit.Test; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.ResourceHarness; +import com.diffplug.spotless.TestProvisioner; + +public class Antlr4FormatterStepTest extends ResourceHarness { + + @Test + public void formatGrammar() throws Throwable { + FormatterStep step = Antlr4FormatterStep.create(TestProvisioner.mavenCentral()); + assertOnResources(step, "antlr4/Hello.unformatted.g4", "antlr4/Hello.formatted.g4"); + } + +}