Skip to content

Commit

Permalink
Merge branch 'main' into subgroup-catch-all
Browse files Browse the repository at this point in the history
  • Loading branch information
tisonkun committed Jan 13, 2023
2 parents 6688e3f + 66b8dd2 commit c59cadd
Show file tree
Hide file tree
Showing 108 changed files with 3,439 additions and 289 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# NEXUS_USER
# NEXUS_PASS
# GPG_PASSPHRASE
# GPG_KEY (base64)
# GPG_KEY64 (base64)
# gpg --export-secret-keys --armor KEY_ID | openssl base64 | pbcopy
# GRADLE_PORTAL_KEY
# GRADLE_PORTAL_SECRET
Expand All @@ -29,11 +29,9 @@ jobs:
env:
gh_token: ${{ secrets.GH_TOKEN }}
ORG_GRADLE_PROJECT_nexus_user: ${{ secrets.NEXUS_USER }}
ORG_GRADLE_PROJECT_nexus_pass: ${{ secrets.NEXUS_PASS }}
ORG_GRADLE_PROJECT_nexus_pass64: ${{ secrets.NEXUS_PASS64 }}
ORG_GRADLE_PROJECT_gpg_passphrase: ${{ secrets.GPG_PASSPHRASE }}
ORG_GRADLE_PROJECT_gpg_key64: ${{ secrets.GPG_KEY }}

gradle_key
ORG_GRADLE_PROJECT_gpg_key64: ${{ secrets.GPG_KEY64 }}
steps:
- uses: actions/checkout@v3
- name: jdk 11
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,6 @@ nbdist/
nbactions.xml
nb-configuration.xml
.nb-gradle/

# MacOS jenv
.java-version
6 changes: 5 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
* Add option `editorConfigFile` for `ktLint` [#142](https://github.com/diffplug/spotless/issues/142)
* **POTENTIALLY BREAKING** `ktlint` step now modifies license headers. Make sure to put `licenseHeader` *after* `ktlint`.
* Added `skipLinesMatching` option to `licenseHeader` to support formats where license header cannot be immediately added to the top of the file (e.g. xml, sh). ([#1441](https://github.com/diffplug/spotless/pull/1441)).
* Add YAML support through Jackson ([#1478](https://github.com/diffplug/spotless/pull/1478))
* Added support for npm-based [ESLint](https://eslint.org/)-formatter for javascript and typescript ([#1453](https://github.com/diffplug/spotless/pull/1453))
* Better suggested messages when user's default is set by JVM limitation. ([#995](https://github.com/diffplug/spotless/pull/995))
### Fixed
* Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444))
* Fix subgroups leading catch all matcher.

### Changes
* Bump default version for `prettier` from `2.0.5` to `2.8.1` ([#1453](https://github.com/diffplug/spotless/pull/1453))
* Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409))
* We also removed the no-longer-required dependency `org.codehaus.groovy:groovy-xml`
* Breaking changes to Spotless' internal testing infrastructure `testlib` ([#1443](https://github.com/diffplug/spotless/pull/1443))
Expand All @@ -30,6 +33,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
* Switch our publishing infrastructure from CircleCI to GitHub Actions ([#1462](https://github.com/diffplug/spotless/pull/1462)).
* Help wanted for moving our tests too ([#1472](https://github.com/diffplug/spotless/issues/1472))


## [2.31.1] - 2023-01-02
### Fixed
* Improve memory usage when using git ratchet ([#1426](https://github.com/diffplug/spotless/pull/1426))
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ lib('kotlin.KtfmtStep') +'{{yes}} | {{yes}}
lib('kotlin.DiktatStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
lib('markdown.FreshMarkStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |',
lib('markdown.FlexmarkStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |',
lib('npm.EslintFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
lib('npm.PrettierFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
lib('npm.TsFmtFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
lib('pom.SortPomStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |',
lib('python.BlackStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |',
lib('scala.ScalaFmtStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
lib('sql.DBeaverSQLFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
extra('wtp.EclipseWtpFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
lib('yaml.YamlJacksonStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |',
'| [(Your FormatterStep here)](CONTRIBUTING.md#how-to-add-a-new-formatterstep) | {{no}} | {{no}} | {{no}} | {{no}} |',
].join('\n');
-->
Expand Down Expand Up @@ -113,13 +115,15 @@ extra('wtp.EclipseWtpFormatterStep') +'{{yes}} | {{yes}}
| [`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: |
| [`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: |
| [`pom.SortPomStep`](lib/src/main/java/com/diffplug/spotless/pom/SortPomStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: |
| [`python.BlackStep`](lib/src/main/java/com/diffplug/spotless/python/BlackStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: |
| [`scala.ScalaFmtStep`](lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java) | :+1: | :+1: | :+1: | :white_large_square: |
| [`sql.DBeaverSQLFormatterStep`](lib/src/main/java/com/diffplug/spotless/sql/DBeaverSQLFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: |
| [`wtp.EclipseWtpFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
| [`yaml.YamlJacksonStep`](lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: |
| [(Your FormatterStep here)](CONTRIBUTING.md#how-to-add-a-new-formatterstep) | :white_large_square: | :white_large_square: | :white_large_square: | :white_large_square: |
<!---freshmark /matrix -->

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ VER_SLF4J=[1.6,2.0[
# Used in multiple places
VER_DURIAN=1.2.0
VER_JGIT=5.13.1.202206130422-r
VER_JUNIT=5.9.1
VER_JUNIT=5.9.2
VER_ASSERTJ=3.24.1
VER_MOCKITO=4.11.0

Expand Down
18 changes: 16 additions & 2 deletions gradle/java-publish.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
import java.nio.charset.StandardCharsets

def decode64(String varName) {
String envValue = System.env[varName]
if (envValue == null) {
return ""
} else {
return new String(envValue.decodeBase64(), "UTF-8")
}
}

if (project.parent == null) {
group = 'com.diffplug.spotless'
def pass = System.env['ORG_GRADLE_PROJECT_nexus_pass64']
if (pass != null) {
pass = pass.decodeBase64()
}
// it's the root project
apply plugin: 'io.github.gradle-nexus.publish-plugin'
nexusPublishing {
Expand All @@ -9,7 +23,7 @@ if (project.parent == null) {
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
username = System.env['ORG_GRADLE_PROJECT_nexus_user']
password = System.env['ORG_GRADLE_PROJECT_nexus_pass']
password = decode64('ORG_GRADLE_PROJECT_nexus_pass64')
}
}
}
Expand Down Expand Up @@ -158,7 +172,7 @@ model {

if (!version.endsWith('-SNAPSHOT')) {
signing {
String gpg_key = new String(System.env['ORG_GRADLE_PROJECT_gpg_key64'].decodeBase64())
String gpg_key = decode64('ORG_GRADLE_PROJECT_gpg_key64')
useInMemoryPgpKeys(gpg_key, System.env['ORG_GRADLE_PROJECT_gpg_passphrase'])
sign(publishing.publications)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2022 DiffPlug
* Copyright 2020-2023 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
6 changes: 5 additions & 1 deletion lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def NEEDS_GLUE = [
'ktlint',
'flexmark',
'diktat',
'scalafmt'
'scalafmt',
'jackson'
]
for (glue in NEEDS_GLUE) {
sourceSets.register(glue) {
Expand Down Expand Up @@ -55,6 +56,9 @@ dependencies {

palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' // this version needs to stay compilable against Java 8 for CI Job testNpm

// used jackson-based formatters
jacksonCompileOnly 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.14.1'

String VER_KTFMT = '0.42'
ktfmtCompileOnly "com.facebook:ktfmt:$VER_KTFMT"
String VER_KTLINT_GOOGLE_JAVA_FORMAT = '1.7' // for JDK 8 compatibility
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Copyright 2021-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.spotless.glue.yaml;

import java.io.IOException;
import java.util.List;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

import com.diffplug.spotless.FormatterFunc;

public class YamlJacksonFormatterFunc implements FormatterFunc {
private List<String> enabledFeatures;
private List<String> disabledFeatures;

public YamlJacksonFormatterFunc(List<String> enabledFeatures, List<String> disabledFeatures) {
this.enabledFeatures = enabledFeatures;
this.disabledFeatures = disabledFeatures;
}

@Override
public String apply(String input) throws Exception {
ObjectMapper objectMapper = makeObjectMapper();

return format(objectMapper, input);
}

protected ObjectMapper makeObjectMapper() {
YAMLFactory yamlFactory = new YAMLFactory();
ObjectMapper objectMapper = new ObjectMapper(yamlFactory);

// Configure the ObjectMapper
// https://github.com/FasterXML/jackson-databind#commonly-used-features
for (String rawFeature : enabledFeatures) {
// https://stackoverflow.com/questions/3735927/java-instantiating-an-enum-using-reflection
SerializationFeature feature = SerializationFeature.valueOf(rawFeature);

objectMapper.enable(feature);
}

for (String rawFeature : disabledFeatures) {
// https://stackoverflow.com/questions/3735927/java-instantiating-an-enum-using-reflection
SerializationFeature feature = SerializationFeature.valueOf(rawFeature);

objectMapper.disable(feature);
}
return objectMapper;
}

protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException {
// We may consider adding manually an initial '---' prefix to help management of multiple documents
// if (!input.trim().startsWith("---")) {
// input = "---" + "\n" + input;
// }

try {
// https://stackoverflow.com/questions/25222327/deserialize-pojos-from-multiple-yaml-documents-in-a-single-file-in-jackson
// https://github.com/FasterXML/jackson-dataformats-text/issues/66#issuecomment-375328648
// 2023-01: For now, we get 'Cannot deserialize value of type `com.fasterxml.jackson.databind.node.ObjectNode` from Array value'
// JsonParser yamlParser = objectMapper.getFactory().createParser(input);
// List<ObjectNode> docs = objectMapper.readValues(yamlParser, ObjectNode.class).readAll();
// return objectMapper.writeValueAsString(docs);

// 2023-01: This returns JSON instead of YAML
// This will transit with a JsonNode
// A JsonNode may keep the comments from the input node
// JsonNode jsonNode = objectMapper.readTree(input);
//Not 'toPrettyString' as one could require no INDENT_OUTPUT
// return jsonNode.toPrettyString();
ObjectNode objectNode = objectMapper.readValue(input, ObjectNode.class);
return objectMapper.writeValueAsString(objectNode);
} catch (JsonProcessingException e) {
throw new AssertionError("Unable to format YAML. input='" + input + "'", e);
}
}

// Spotbugs
private static class ObjectNodeTypeReference extends TypeReference<ObjectNode> {}
}
7 changes: 4 additions & 3 deletions lib/src/main/java/com/diffplug/spotless/Jvm.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2022 DiffPlug
* Copyright 2016-2023 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -198,8 +198,9 @@ private String buildUpgradeFormatterMessage(V fmtVersion) {
StringBuilder builder = new StringBuilder();
V recommendedFmtVersionOrNull = getRecommendedFormatterVersion();
if (null != recommendedFmtVersionOrNull && (fmtVersionComparator.compare(fmtVersion, recommendedFmtVersionOrNull) < 0)) {
builder.append(String.format("You are not using latest version on JVM %d+.%n", getRequiredJvmVersion(recommendedFmtVersionOrNull)));
builder.append(String.format("Try to upgrade to %s %s, which may have fixed this problem.", fmtName, getRecommendedFormatterVersion()));
builder.append(String.format("%s %s is currently being used, but outdated.%n", fmtName, fmtVersion));
builder.append(String.format("%s %s is the recommended version, which may have fixed this problem.%n", fmtName, recommendedFmtVersionOrNull));
builder.append(String.format("%s %s requires JVM %d+.", fmtName, recommendedFmtVersionOrNull, getRequiredJvmVersion(recommendedFmtVersionOrNull)));
} else {
V higherFormatterVersionOrNull = fmt2jvmVersion.higherKey(fmtVersion);
if (null != higherFormatterVersionOrNull) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2016-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.spotless.npm;

abstract class BaseNpmRestService {

protected final SimpleRestClient restClient;

BaseNpmRestService(String baseUrl) {
this.restClient = SimpleRestClient.forBaseUrl(baseUrl);
}

public String shutdown() {
return restClient.post("/shutdown");
}

}
72 changes: 72 additions & 0 deletions lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright 2016-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.spotless.npm;

import java.io.File;
import java.io.IOException;
import java.io.Serializable;

import javax.annotation.Nullable;

import com.diffplug.spotless.FileSignature;
import com.diffplug.spotless.ThrowingEx;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

public class EslintConfig implements Serializable {

private static final long serialVersionUID = -6196834313082791248L;

@SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED")
@Nullable
private final transient File eslintConfigPath;

@SuppressWarnings("unused")
private final FileSignature eslintConfigPathSignature;

private final String eslintConfigJs;

public EslintConfig(@Nullable File eslintConfigPath, @Nullable String eslintConfigJs) {
try {
this.eslintConfigPath = eslintConfigPath;
this.eslintConfigPathSignature = eslintConfigPath != null ? FileSignature.signAsList(this.eslintConfigPath) : FileSignature.signAsList();
this.eslintConfigJs = eslintConfigJs;
} catch (IOException e) {
throw ThrowingEx.asRuntime(e);
}
}

public EslintConfig withEslintConfigPath(@Nullable File eslintConfigPath) {
return new EslintConfig(eslintConfigPath, this.eslintConfigJs);
}

@Nullable
public File getEslintConfigPath() {
return eslintConfigPath;
}

@Nullable
public String getEslintConfigJs() {
return eslintConfigJs;
}

public EslintConfig verify() {
if (eslintConfigPath == null && eslintConfigJs == null) {
throw new IllegalArgumentException("ESLint must be configured using either a configFile or a configJs - but both are null.");
}
return this;
}
}
Loading

0 comments on commit c59cadd

Please sign in to comment.