Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Rome as a formatter #1663

Merged
merged 36 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5fd904e
POC: Basic support for rome
blutorange Apr 2, 2023
f62050c
Default download directory for Rome binary to the local repository
blutorange Apr 6, 2023
7705a14
Add Rome support to unreleased changes
blutorange Apr 6, 2023
c3ffe2d
Allow a command on the path to be specified as the name of the Rome
blutorange Apr 6, 2023
0d1e9fc
Add optional configuration for the config path with the config file
blutorange Apr 6, 2023
6fb765d
Merge remote-tracking branch 'origin/main' into js-ts-rome
blutorange Apr 6, 2023
c8e5430
Limit visibility of Rome internal logic classes, JavaDoc
blutorange Apr 7, 2023
cdb0ec6
Fix changes.md + Architecture visibility
blutorange Apr 8, 2023
a158493
Support formatting JSON files with Rome
blutorange Apr 8, 2023
7461c04
Add rome to feature matrix
blutorange Apr 8, 2023
17b05d7
Add rome() step to generic format for Gradle plugin
blutorange Apr 8, 2023
7481a9b
Add license header
blutorange Apr 8, 2023
afd0edb
Run spotlessApply
blutorange Apr 8, 2023
0afd327
Add rome format step to json/javascript/typescript languages
blutorange Apr 8, 2023
8c71500
Add docs for Maven plugin
blutorange Apr 8, 2023
8fa9cda
Add docs for Gradle plugin
blutorange Apr 8, 2023
2330874
Readme: Mention Rome in TOC for JS/TS
blutorange Apr 8, 2023
850b287
Fix readme for Gradle plugin with custom binary
blutorange Apr 8, 2023
7afe75b
Minor refactor, remove useless extra builder class
blutorange Apr 8, 2023
57d36b4
Fix default download dir path for Gradle plugin
blutorange Apr 8, 2023
c483ed3
Add tests for RomeStep
blutorange Apr 8, 2023
97198cb
Add tests for Maven plugin
blutorange Apr 8, 2023
77d302e
Add tests for Gradle plugin
blutorange Apr 8, 2023
971824d
Fix spotbugs issues
blutorange Apr 13, 2023
98910ef
Merge remote-tracking branch 'origin/main' into js-ts-rome
blutorange Apr 13, 2023
071df53
Run spotlessApply again
blutorange Apr 13, 2023
20729b8
Fix conversion of file URL to Path, improve exception handling
blutorange Apr 22, 2023
bc3261b
use sha-256 for downloaded rome binary checksum
blutorange Apr 22, 2023
b516c65
Remove whitespace on empty line
awa-xima May 16, 2023
8dd9b34
Merge branch 'main' into js-ts-rome
nedtwigg May 16, 2023
39d61bc
SHA256 -> SHA-256
awa-xima May 16, 2023
6c8bff1
Update changelogs.
nedtwigg May 17, 2023
ed4e5c2
Move RomeStepConfig into its own file since it's so big.
nedtwigg May 17, 2023
09d8498
Fix root path issue in the Rome formatter.
nedtwigg May 17, 2023
d8913c4
Another changelog fix.
nedtwigg May 17, 2023
a56e7e6
Use Path.of(URI) instead of manual string wrangling.
nedtwigg May 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ This document is intended for Spotless developers.
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).

## [Unreleased]
### Changes
* Bump default sortpom version to latest `3.0.0` -> `3.2.1`. ([#1675](https://github.com/diffplug/spotless/pull/1675))

### Added
* `Jvm.Support` now accepts `-SNAPSHOT` versions, treated as the non`-SNAPSHOT`. ([#1583](https://github.com/diffplug/spotless/issues/1583))
* Support Rome as a formatter for JavaScript and TypeScript code. Adds a new `rome` step to `javascript` and `typescript` formatter configurations. ([#1663](https://github.com/diffplug/spotless/pull/1663))
### Fixed
* When P2 download fails, indicate the responsible formatter. ([#1698](https://github.com/diffplug/spotless/issues/1698))
### Changes
* Bump default sortpom version to latest `3.0.0` -> `3.2.1`. ([#1675](https://github.com/diffplug/spotless/pull/1675))

## [2.38.0] - 2023-04-06
### Added
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ lib('npm.PrettierFormatterStep') +'{{yes}} | {{yes}}
lib('npm.TsFmtFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
lib('pom.SortPomStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |',
lib('python.BlackStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |',
lib('rome.RomeStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
lib('scala.ScalaFmtStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
lib('sql.DBeaverSQLFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
extra('wtp.EclipseWtpFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
Expand Down Expand Up @@ -148,6 +149,7 @@ lib('yaml.JacksonYamlStep') +'{{yes}} | {{yes}}
| [`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: |
| [`rome.RomeStep`](lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java) | :+1: | :+1: | :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: |
Expand Down
69 changes: 69 additions & 0 deletions lib/src/main/java/com/diffplug/spotless/rome/Architecture.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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.rome;

/**
* Enumeration of possible computer architectures.
*/
enum Architecture {
/** The arm64 architecture */
ARM64,
/** Either x64 or x64_32 architecture */
X64;

/**
* Attempts to guess the architecture of the environment running the JVM.
*
* @return The best guess for the architecture.
*/
public static Architecture guess() {
var arch = System.getProperty("os.arch");
var version = System.getProperty("os.version");

if (arch == null || arch.isBlank()) {
throw new IllegalStateException("No OS information is available, specify the Rome executable manually");
}

var msg = "Unsupported architecture " + arch + "/" + version
+ ", specify the path to the Rome executable manually";

if (arch.equals("ppc64le")) {
throw new IllegalStateException(msg);
}
if (arch.equals("aarch64")) {
throw new IllegalStateException(msg);
}
if (arch.equals("s390x")) {
throw new IllegalStateException(msg);
}
if (arch.equals("ppc64")) {
throw new IllegalStateException(msg);
}
if (arch.equals("ppc")) {
throw new IllegalStateException(msg);
}
if (arch.equals("arm")) {
if (version.contains("v7")) {
throw new IllegalStateException(msg);
}
return ARM64;
}
if (arch.contains("64")) {
return X64;
}
throw new IllegalStateException(msg);
}
}
56 changes: 56 additions & 0 deletions lib/src/main/java/com/diffplug/spotless/rome/OS.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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.rome;

import java.util.Locale;

/**
* Enumeration of possible computer operation systems.
*/
enum OS {
/** Any derivate of a Linux operation system. */
LINUX,
/** The Macintosh operating system/ */
MAC_OS,
/** The Microsoft Windows operating system. */
WINDOWS,;

/**
* Attempts to guess the OS of the environment running the JVM.
*
* @return The best guess for the architecture.
* @throws IllegalStateException When the OS is either unsupported or no
* information about the OS could be retrieved.
*/
public static OS guess() {
var osName = System.getProperty("os.name");
if (osName == null || osName.isBlank()) {
throw new IllegalStateException("No OS information is available, specify the Rome executable manually");
}
var osNameUpper = osName.toUpperCase(Locale.ROOT);
if (osNameUpper.contains("SUNOS") || osName.contains("AIX")) {
throw new IllegalStateException(
"Unsupported OS " + osName + ", specify the path to the Rome executable manually");
}
if (osNameUpper.contains("WINDOWS")) {
return OS.WINDOWS;
} else if (osNameUpper.contains("MAC")) {
return OS.MAC_OS;
} else {
return OS.LINUX;
}
}
}
91 changes: 91 additions & 0 deletions lib/src/main/java/com/diffplug/spotless/rome/Platform.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* 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.rome;

/**
* Represents a platform where code is run, consisting of an operating system
* and an architecture.
*/
class Platform {
/**
* Attempts to guess the platform of the hosting environment running the JVM
* machine.
*
* @return The best guess for the current OS and architecture.
* @throws IllegalStateException When no OS information is available, or when
* the OS or architecture is unsupported.
*/
public static Platform guess() {
var os = OS.guess();
var architecture = Architecture.guess();
return new Platform(os, architecture);
}

private final Architecture architecture;

private final OS os;

/**
* Creates a new Platform descriptor for the given OS and architecture.
*
* @param os Operating system of the platform.
* @param architecture Architecture of the platform.
*/
public Platform(OS os, Architecture architecture) {
this.os = os;
this.architecture = architecture;
}

/**
* @return The architecture of this platform.
*/
public Architecture getArchitecture() {
return architecture;
}

/**
* @return The operating system of this platform.
*/
public OS getOs() {
return os;
}

/**
* @return Whether the operating system is Linux.
*/
public boolean isLinux() {
return os == OS.LINUX;
}

/**
* @return Whether the operating system is Mac.
*/
public boolean isMac() {
return os == OS.MAC_OS;
}

/**
* @return Whether the operating system is Windows.
*/
public boolean isWindows() {
return os == OS.WINDOWS;
}

@Override
public String toString() {
return String.format("Platform[os=%s,architecture=%s]", os, architecture);
}
}
Loading