Skip to content

Commit 8fa9cda

Browse files
committed
Add docs for Gradle plugin
1 parent 8c71500 commit 8fa9cda

File tree

2 files changed

+176
-5
lines changed

2 files changed

+176
-5
lines changed

plugin-gradle/README.md

Lines changed: 171 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Spotless supports all of Gradle's built-in performance features (incremental bui
7575
- c, c++, c#, objective-c, protobuf, javascript, java
7676
- [eclipse web tools platform](#eclipse-web-tools-platform)
7777
- css, html, js, json, xml
78+
- [Rome](#rome) ([binary detection](#rome-binary), [config file](#rome-configuration-file), [input language](#rome-input-language))
7879
- **Language independent**
7980
- [Generic steps](#generic-steps)
8081
- [License header](#license-header) ([slurp year from git](#retroactively-slurp-years-from-git-history))
@@ -613,7 +614,8 @@ spotless {
613614
614615
tsfmt() // has its own section below
615616
prettier() // has its own section below
616-
eslint() // has its own section below
617+
eslint() // has its own section below
618+
rome() // has its own section below
617619
618620
licenseHeader '/* (C) $YEAR */', '(import|const|declare|export|var) ' // or licenseHeaderFile
619621
// note the '(import|const|...' argument - this is a regex which identifies the top
@@ -705,7 +707,8 @@ spotless {
705707
target 'src/**/*.js' // you have to set the target manually
706708
707709
prettier() // has its own section below
708-
eslint() // has its own section below
710+
eslint() // has its own section below
711+
rome() // has its own section below
709712
710713
licenseHeader '/* (C) $YEAR */', 'REGEX_TO_DEFINE_TOP_OF_FILE' // or licenseHeaderFile
711714
}
@@ -772,6 +775,7 @@ spotless {
772775
eclipseWtp('json') // see Eclipse web tools platform section
773776
gson() // has its own section below
774777
jackson() // has its own section below
778+
rome() // has its own section below
775779
}
776780
}
777781
```
@@ -1064,6 +1068,171 @@ Unlike Eclipse, Spotless WTP ignores per default external URIs in schema locatio
10641068
external entities. To allow the access of external URIs, set the property `resolveExternalURI`
10651069
to true.
10661070
1071+
## Rome
1072+
1073+
[homepage](https://rome.tools/). [changelog](https://github.com/rome/tools/blob/main/CHANGELOG.md). Rome is a formatter that for the Frontend written in Rust, which has a native binary,
1074+
does not require Node.js and as such, is pretty fast. It can currently format
1075+
JavaScript, TypeScript, JSX, and JSON, and may support
1076+
[more frontend languages](https://docs.rome.tools/internals/language_support/)
1077+
such as CSS in the future.
1078+
1079+
You can use rome in any language-specific format for supported languages, but
1080+
usually you will be creating a generic format.
1081+
1082+
```gradle
1083+
spotless {
1084+
format 'styling', {
1085+
// you have to set the target manually
1086+
target 'src/*/webapp/**/*.js'
1087+
1088+
// Download Rome from the network if not already downloaded, see below for more info
1089+
rome('12.0.0')
1090+
1091+
// (optional) Path to the directory with the rome.json conig file
1092+
rome('12.0.0').configPath("path/config/dir")
1093+
1094+
// (optional) Rome will auto detect the language based on the file extension.
1095+
// See below for possible values.
1096+
rome('12.0.0').language("js")
1097+
}
1098+
}
1099+
```
1100+
1101+
**Limitations:**
1102+
- The auto-discovery of config files (up the file tree) will not work when using
1103+
Rome within spotless.
1104+
1105+
To apply Rome to more kinds of files with a different configuration, just add
1106+
more formats:
1107+
1108+
```gradle
1109+
spotless {
1110+
format 'rome-js', {
1111+
target '**/*.js'
1112+
rome('12.0.0')
1113+
}
1114+
format 'rome-ts', {
1115+
target '**/*.ts'
1116+
rome('12.0.0')
1117+
}
1118+
format 'rome-json', {
1119+
target '**/*.json'
1120+
rome('12.0.0')
1121+
}
1122+
}
1123+
```
1124+
1125+
### Rome binary
1126+
1127+
To format with Rome, spotless needs to find the Rome binary. By default,
1128+
spotless downloads the binary for the given version from the network. This
1129+
should be fine in most cases, but may not work e.g. when there is not connection
1130+
to the internet.
1131+
1132+
To download the Rome binary from the network, just specify a version:
1133+
1134+
```gradle
1135+
spotless {
1136+
format 'rome', {
1137+
target '**/*.js','**/*.ts','**/*.json'
1138+
rome('12.0.0')
1139+
}
1140+
}
1141+
```
1142+
1143+
Spotless uses a default version when you do not specfiy a version, but this
1144+
may change at any time, so we recommend that you always set the Rome version
1145+
you want to use. Optionally, you can also specify a directory for the downloaded
1146+
Rome binaries (defaults to `~/.m2/repository/com/diffplug/spotless/spotless-data/rome`):
1147+
1148+
```gradle
1149+
spotless {
1150+
format 'rome', {
1151+
target '**/*.js','**/*.ts','**/*.json'
1152+
// Relative paths are resolved against the project's base directory
1153+
rome('12.0.0').downloadDir("${project.gradle.gradleUserHomeDir}/rome")
1154+
}
1155+
}
1156+
```
1157+
1158+
To use a fixed binary, omit the `version` and specify a `pathToExe`:
1159+
1160+
```gradle
1161+
spotless {
1162+
format 'rome', {
1163+
target '**/*.js','**/*.ts','**/*.json'
1164+
rome('12.0.0').pathToExe("${project.buildDir.absolutePath}/bin/rome")
1165+
}
1166+
}
1167+
```
1168+
1169+
Absolute paths are used as-is. Relative paths are resolved against the project's
1170+
base directory. To use a pre-installed Rome binary on the user's path, specify
1171+
just a name without any slashes / backslashes:
1172+
1173+
```gradle
1174+
spotless {
1175+
format 'rome', {
1176+
target '**/*.js','**/*.ts','**/*.json'
1177+
// Uses the "rome" command, which must be on the user's path. -->
1178+
rome('12.0.0').pathToExe('rome')
1179+
}
1180+
}
1181+
```
1182+
1183+
### Rome configuration file
1184+
1185+
Rome is a biased formatter and linter without many options, but there are a few
1186+
basic options. Rome uses a file named [rome.json](https://docs.rome.tools/configuration/)
1187+
for its configuration. When none is specified, the default configuration from
1188+
Rome is used. To use a custom configuration:
1189+
1190+
```gradle
1191+
spotless {
1192+
format 'rome', {
1193+
target '**/*.js','**/*.ts','**/*.json'
1194+
// Must point to the directory with the "rome.json" config file -->
1195+
// Relative paths are resolved against the project's base directory -->
1196+
rome('12.0.0').configPath('./config')
1197+
}
1198+
}
1199+
```
1200+
1201+
### Rome input language
1202+
1203+
By default, Rome detects the language / syntax of the files to format
1204+
automatically from the file extension. This may fail if your source code files
1205+
have unusual extensions for some reason. If you are using the generic format,
1206+
you can force a certain language like this:
1207+
1208+
```xml
1209+
<configuration>
1210+
<formats>
1211+
<format>
1212+
<includes>
1213+
<include>src/**/typescript/**/*.mjson</include>
1214+
</includes>
1215+
1216+
<rome>
1217+
<version>12.0.0</version>
1218+
<language>json</language>
1219+
</prettier>
1220+
</rome>
1221+
1222+
</formats>
1223+
</configuration>
1224+
```
1225+
1226+
The following languages are currently recognized:
1227+
1228+
* `js` -- JavaScript
1229+
* `jsx` -- JavaScript + JSX (React)
1230+
* `js?` -- JavaScript, with or without JSX, depending on the file extension
1231+
* `ts` -- TypeScript
1232+
* `tsx` -- TypeScript + JSX (React)
1233+
* `ts?` -- TypeScript, with or without JSX, depending on the file extension
1234+
* `json` -- JSON
1235+
10671236
## Generic steps
10681237

10691238
[Prettier](#prettier), [eclipse wtp](#eclipse-web-tools-platform), and [license header](#license-header) are available in every format, and they each have their own section. As mentioned in the [quickstart](#quickstart), there are a variety of simple generic steps which are also available in every format, here are examples of these:

plugin-maven/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,7 @@ usually you will be creating a generic format.
12501250
<!-- (optional) Path to the directory with the rome.json conig file -->
12511251
<configPath>${project.basedir}/path/to/config/dir</configPath>
12521252

1253-
<!-- Optional, Rome will auto detect the language based on the file extension. -->
1253+
<!-- (optional) Rome will auto detect the language based on the file extension. -->
12541254
<!-- See below for possible values. -->
12551255
<language>ts</language>
12561256
</prettier>
@@ -1264,13 +1264,15 @@ usually you will be creating a generic format.
12641264
- The auto-discovery of config files (up the file tree) will not work when using
12651265
Rome within spotless.
12661266

1267-
To apply Rome to more kinds of files, just add more formats
1267+
To apply Rome to more kinds of files with a different configuration, just add
1268+
more formats
12681269

12691270
```xml
12701271
<configuration>
12711272
<formats>
12721273
<format><includes>src/**/*.ts</includes><rome/></format>
12731274
<format><includes>src/**/*.js</includes><rome/></format>
1275+
</configuration>
12741276
```
12751277

12761278
### Rome binary
@@ -1336,7 +1338,7 @@ Rome is used. To use a custom configuration:
13361338
</rome>
13371339
```
13381340

1339-
### Rome input Language
1341+
### Rome input language
13401342

13411343
By default, Rome detects the language / syntax of the files to format
13421344
automatically from the file extension. This may fail if your source code files

0 commit comments

Comments
 (0)