Skip to content

Commit 6d71e4d

Browse files
committed
docs: add documentation for IntelliJ codestyle
1 parent 3277660 commit 6d71e4d

File tree

4 files changed

+64
-8
lines changed

4 files changed

+64
-8
lines changed

INTELLIJ_IDEA_SCREENSHOTS.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Extracting Code Style from IntelliJ IDEA
2+
3+
## 1. Exporting Code Style Settings to a file
4+
To export code style settings from IntelliJ IDEA to a file, go to
5+
`Settings | Editor | Code Style` and click on the gear icon next to the scheme name.
6+
7+
![Exporting code style settings](_images/intellij_export_codestyle.png)
8+
9+
## 2. Using IntelliJ's active code style directly
10+
If you have your code style settings checked into version control (in your `.idea` directory),
11+
you can use the active code style directly in Spotless without exporting it to a file.
12+
The file can be found at `.idea/codeStyles/Project.xml`.
13+
14+
## Upstream documentation
15+
More details can be found in the [IntelliJ IDEA documentation](https://www.jetbrains.com/help/idea/command-line-formatter.html#options)
16+
for the command line formatter, which is what Spotless uses under the hood.

_images/intellij_export_codestyle.png

131 KB
Loading

plugin-gradle/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,16 +1593,15 @@ and a plethora of [plugins](https://plugins.jetbrains.com/).
15931593

15941594
Spotless provides access to IntelliJ IDEA's command line formatter.
15951595
1596-
15971596
```gradle
15981597
spotless {
15991598
format 'myFormatter', {
16001599
// you have to set the target manually
16011600
target 'src/main/**/*.java','jbang/*.java'
16021601
16031602
idea()
1604-
.codeStyleSettingsPath('/path/to/config') // if you have custom formatting rules, see below for how to get them
1605-
.withDefaults(true) // Use the default code style settings when the code style is not defined for a file type (default: true)
1603+
.codeStyleSettingsPath('/path/to/config') // if you have custom formatting rules, see below for how to extract/reference them
1604+
.withDefaults(false) // Disable using default code style settings when no custom code style is defined for a file type (default: true)
16061605
16071606
// if idea is not on your path, you must specify the path to the executable
16081607
idea().binaryPath('/path/to/idea')
@@ -1611,7 +1610,7 @@ spotless {
16111610
```
16121611
16131612
### How to generate code style settings files
1614-
TODO
1613+
See [here](../INTELLIJ_IDEA_SCREENSHOTS.md) for an explanation on how to extract or reference existing code style files.
16151614
16161615
### Limitations
16171616
- Currently, only IntelliJ IDEA is supported - none of the other jetbrains IDE. Consider opening a PR if you want to change this.

plugin-maven/README.md

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ user@machine repo % mvn spotless:check
3838
- [**Quickstart**](#quickstart)
3939
- [Requirements](#requirements)
4040
- [Binding to maven phase](#binding-to-maven-phase)
41-
- **Languages**
42-
- [Java](#java) ([google-java-format](#google-java-format), [eclipse jdt](#eclipse-jdt), [prettier](#prettier), [palantir-java-format](#palantir-java-format), [formatAnnotations](#formatAnnotations), [cleanthat](#cleanthat))
41+
- **Languages** // TODO add idea
42+
- [Java](#java) ([google-java-format](#google-java-format), [eclipse jdt](#eclipse-jdt), [prettier](#prettier), [palantir-java-format](#palantir-java-format), [formatAnnotations](#formatAnnotations), [cleanthat](#cleanthat),[IntelliiJ IDEA](#intellij-idea))
4343
- [Groovy](#groovy) ([eclipse groovy](#eclipse-groovy))
4444
- [Kotlin](#kotlin) ([ktfmt](#ktfmt), [ktlint](#ktlint), [diktat](#diktat), [prettier](#prettier))
4545
- [Scala](#scala) ([scalafmt](#scalafmt))
4646
- [C/C++](#cc) ([eclipse cdt](#eclipse-cdt), [clang-format](#clang-format))
4747
- [Python](#python) ([black](#black))
4848
- [Antlr4](#antlr4) ([antlr4formatter](#antlr4formatter))
49-
- [Sql](#sql) ([dbeaver](#dbeaver))
49+
- [Sql](#sql) ([dbeaver](#dbeaver), [prettier](#prettier), [IntelliJ IDEA](#intellij-idea))
5050
- [Maven Pom](#maven-pom) ([sortPom](#sortpom))
5151
- [Markdown](#markdown) ([flexmark](#flexmark))
5252
- [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [ESLint](#eslint-typescript), [Biome](#biome))
@@ -61,6 +61,7 @@ user@machine repo % mvn spotless:check
6161
- [Prettier](#prettier) ([plugins](#prettier-plugins), [npm detection](#npm-detection), [`.npmrc` detection](#npmrc-detection), [caching `npm install` results](#caching-results-of-npm-install))
6262
- [eclipse web tools platform](#eclipse-web-tools-platform)
6363
- [Biome](#biome) ([binary detection](#biome-binary), [config file](#biome-configuration-file), [input language](#biome-input-language))
64+
- [IntelliJ IDEA](#intellij-idea)
6465
- **Language independent**
6566
- [Generic steps](#generic-steps)
6667
- [License header](#license-header) ([slurp year from git](#retroactively-slurp-years-from-git-history))
@@ -194,6 +195,7 @@ any other maven phase (i.e. compile) then it can be configured as below;
194195
<googleJavaFormat /> <!-- has its own section below -->
195196
<eclipse /> <!-- has its own section below -->
196197
<prettier /> <!-- has its own section below -->
198+
<idea /> <!-- has its own section below -->
197199

198200
<importOrder /> <!-- standard import order -->
199201
<importOrder> <!-- or a custom ordering -->
@@ -665,6 +667,7 @@ Additionally, `editorConfigOverride` options will override what's supplied in `.
665667

666668
<dbeaver /> <!-- has its own section below -->
667669
<prettier /> <!-- has its own section below -->
670+
<idea /> <!-- has its own section below -->
668671
</sql>
669672
</configuration>
670673
```
@@ -1666,9 +1669,47 @@ The following languages are currently recognized:
16661669
* `ts?` -- TypeScript, with or without JSX, depending on the file extension
16671670
* `json` -- JSON
16681671

1672+
## IntelliJ IDEA
1673+
1674+
[homepage](https://www.jetbrains.com/idea/). [changelog](https://www.jetbrains.com/idea/whatsnew/).
1675+
1676+
`IntelliJ IDEA` is a powerful IDE for java, kotlin and many more languages. There are [specific variants](https://www.jetbrains.com/products/) for almost any modern language
1677+
and a plethora of [plugins](https://plugins.jetbrains.com/).
1678+
1679+
Spotless provides access to IntelliJ IDEA's command line formatter.
1680+
1681+
```xml
1682+
<configuration>
1683+
<formats>
1684+
<format>
1685+
<includes>
1686+
<include>src/main/**/*.java</include>
1687+
<include>jbang/*.java</include>
1688+
</includes>
1689+
1690+
<idea>
1691+
<!-- if you have custom formatting rules, see below for how to extract/reference them -->
1692+
<codeStyleSettingsPath>/path/to/config</codeStyleSettingsPath>
1693+
<!-- disable using default code style settings when no custom code style is defined for a file type (default: true) -->
1694+
<withDefaults>false</withDefaults>
1695+
<!-- if idea is not on your path, you must specify the path to the executable -->
1696+
<binaryPath>/path/to/idea</binaryPath>
1697+
</idea>
1698+
</format>
1699+
</formats>
1700+
</configuration>
1701+
```
1702+
1703+
### How to generate code style settings files
1704+
See [here](../INTELLIJ_IDEA_SCREENSHOTS.md) for an explanation on how to extract or reference existing code style files.
1705+
1706+
### Limitations
1707+
- Currently, only IntelliJ IDEA is supported - none of the other jetbrains IDE. Consider opening a PR if you want to change this.
1708+
- Launching IntelliJ IDEA from the command line is pretty expensive and as of now, we do this for each file. If you want to change this, consider opening a PR.
1709+
16691710
## Generic steps
16701711

1671-
[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:
1712+
[Prettier](#prettier), [eclipse wtp](#eclipse-web-tools-platform), [IntelliJ IDEA](#intellij-idea) 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:
16721713

16731714
```xml
16741715
<trimTrailingWhitespace /> <!-- trim trailing whitespaces -->

0 commit comments

Comments
 (0)