Skip to content

Commit 94ba918

Browse files
authored
Support Rome as a formatter (#1663)
2 parents dfdc3ef + a56e7e6 commit 94ba918

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+3232
-18
lines changed

CHANGES.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ This document is intended for Spotless developers.
1010
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).
1111

1212
## [Unreleased]
13-
### Changes
14-
* Bump default sortpom version to latest `3.0.0` -> `3.2.1`. ([#1675](https://github.com/diffplug/spotless/pull/1675))
15-
1613
### Added
1714
* `Jvm.Support` now accepts `-SNAPSHOT` versions, treated as the non`-SNAPSHOT`. ([#1583](https://github.com/diffplug/spotless/issues/1583))
15+
* 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))
1816
### Fixed
1917
* When P2 download fails, indicate the responsible formatter. ([#1698](https://github.com/diffplug/spotless/issues/1698))
18+
### Changes
19+
* Bump default sortpom version to latest `3.0.0` -> `3.2.1`. ([#1675](https://github.com/diffplug/spotless/pull/1675))
2020

2121
## [2.38.0] - 2023-04-06
2222
### Added

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ lib('npm.PrettierFormatterStep') +'{{yes}} | {{yes}}
9999
lib('npm.TsFmtFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
100100
lib('pom.SortPomStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |',
101101
lib('python.BlackStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |',
102+
lib('rome.RomeStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
102103
lib('scala.ScalaFmtStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
103104
lib('sql.DBeaverSQLFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
104105
extra('wtp.EclipseWtpFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
@@ -148,6 +149,7 @@ lib('yaml.JacksonYamlStep') +'{{yes}} | {{yes}}
148149
| [`npm.TsFmtFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
149150
| [`pom.SortPomStep`](lib/src/main/java/com/diffplug/spotless/pom/SortPomStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: |
150151
| [`python.BlackStep`](lib/src/main/java/com/diffplug/spotless/python/BlackStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: |
152+
| [`rome.RomeStep`](lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
151153
| [`scala.ScalaFmtStep`](lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java) | :+1: | :+1: | :+1: | :white_large_square: |
152154
| [`sql.DBeaverSQLFormatterStep`](lib/src/main/java/com/diffplug/spotless/sql/DBeaverSQLFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: |
153155
| [`wtp.EclipseWtpFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2016-2023 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.spotless.rome;
17+
18+
/**
19+
* Enumeration of possible computer architectures.
20+
*/
21+
enum Architecture {
22+
/** The arm64 architecture */
23+
ARM64,
24+
/** Either x64 or x64_32 architecture */
25+
X64;
26+
27+
/**
28+
* Attempts to guess the architecture of the environment running the JVM.
29+
*
30+
* @return The best guess for the architecture.
31+
*/
32+
public static Architecture guess() {
33+
var arch = System.getProperty("os.arch");
34+
var version = System.getProperty("os.version");
35+
36+
if (arch == null || arch.isBlank()) {
37+
throw new IllegalStateException("No OS information is available, specify the Rome executable manually");
38+
}
39+
40+
var msg = "Unsupported architecture " + arch + "/" + version
41+
+ ", specify the path to the Rome executable manually";
42+
43+
if (arch.equals("ppc64le")) {
44+
throw new IllegalStateException(msg);
45+
}
46+
if (arch.equals("aarch64")) {
47+
throw new IllegalStateException(msg);
48+
}
49+
if (arch.equals("s390x")) {
50+
throw new IllegalStateException(msg);
51+
}
52+
if (arch.equals("ppc64")) {
53+
throw new IllegalStateException(msg);
54+
}
55+
if (arch.equals("ppc")) {
56+
throw new IllegalStateException(msg);
57+
}
58+
if (arch.equals("arm")) {
59+
if (version.contains("v7")) {
60+
throw new IllegalStateException(msg);
61+
}
62+
return ARM64;
63+
}
64+
if (arch.contains("64")) {
65+
return X64;
66+
}
67+
throw new IllegalStateException(msg);
68+
}
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2016-2023 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.spotless.rome;
17+
18+
import java.util.Locale;
19+
20+
/**
21+
* Enumeration of possible computer operation systems.
22+
*/
23+
enum OS {
24+
/** Any derivate of a Linux operation system. */
25+
LINUX,
26+
/** The Macintosh operating system/ */
27+
MAC_OS,
28+
/** The Microsoft Windows operating system. */
29+
WINDOWS,;
30+
31+
/**
32+
* Attempts to guess the OS of the environment running the JVM.
33+
*
34+
* @return The best guess for the architecture.
35+
* @throws IllegalStateException When the OS is either unsupported or no
36+
* information about the OS could be retrieved.
37+
*/
38+
public static OS guess() {
39+
var osName = System.getProperty("os.name");
40+
if (osName == null || osName.isBlank()) {
41+
throw new IllegalStateException("No OS information is available, specify the Rome executable manually");
42+
}
43+
var osNameUpper = osName.toUpperCase(Locale.ROOT);
44+
if (osNameUpper.contains("SUNOS") || osName.contains("AIX")) {
45+
throw new IllegalStateException(
46+
"Unsupported OS " + osName + ", specify the path to the Rome executable manually");
47+
}
48+
if (osNameUpper.contains("WINDOWS")) {
49+
return OS.WINDOWS;
50+
} else if (osNameUpper.contains("MAC")) {
51+
return OS.MAC_OS;
52+
} else {
53+
return OS.LINUX;
54+
}
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright 2016-2023 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.spotless.rome;
17+
18+
/**
19+
* Represents a platform where code is run, consisting of an operating system
20+
* and an architecture.
21+
*/
22+
class Platform {
23+
/**
24+
* Attempts to guess the platform of the hosting environment running the JVM
25+
* machine.
26+
*
27+
* @return The best guess for the current OS and architecture.
28+
* @throws IllegalStateException When no OS information is available, or when
29+
* the OS or architecture is unsupported.
30+
*/
31+
public static Platform guess() {
32+
var os = OS.guess();
33+
var architecture = Architecture.guess();
34+
return new Platform(os, architecture);
35+
}
36+
37+
private final Architecture architecture;
38+
39+
private final OS os;
40+
41+
/**
42+
* Creates a new Platform descriptor for the given OS and architecture.
43+
*
44+
* @param os Operating system of the platform.
45+
* @param architecture Architecture of the platform.
46+
*/
47+
public Platform(OS os, Architecture architecture) {
48+
this.os = os;
49+
this.architecture = architecture;
50+
}
51+
52+
/**
53+
* @return The architecture of this platform.
54+
*/
55+
public Architecture getArchitecture() {
56+
return architecture;
57+
}
58+
59+
/**
60+
* @return The operating system of this platform.
61+
*/
62+
public OS getOs() {
63+
return os;
64+
}
65+
66+
/**
67+
* @return Whether the operating system is Linux.
68+
*/
69+
public boolean isLinux() {
70+
return os == OS.LINUX;
71+
}
72+
73+
/**
74+
* @return Whether the operating system is Mac.
75+
*/
76+
public boolean isMac() {
77+
return os == OS.MAC_OS;
78+
}
79+
80+
/**
81+
* @return Whether the operating system is Windows.
82+
*/
83+
public boolean isWindows() {
84+
return os == OS.WINDOWS;
85+
}
86+
87+
@Override
88+
public String toString() {
89+
return String.format("Platform[os=%s,architecture=%s]", os, architecture);
90+
}
91+
}

0 commit comments

Comments
 (0)