-
Notifications
You must be signed in to change notification settings - Fork 506
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve documentation about prevent conflicts with Intellij IDEA form…
- Loading branch information
1 parent
fd083b6
commit dcec7ba
Showing
4 changed files
with
61 additions
and
87 deletions.
There are no files selected for viewing
63 changes: 27 additions & 36 deletions
63
documentation/release-latest/docs/rules/configuration-intellij-idea.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,27 @@ | ||
!!! Warning | ||
`ktlint` strives to prevent code formatting conflicts with IntelliJ IDEA / Android Studio. We recommend using either IDE formatting or `ktlint` formatting. However, if you persist on using both, then please ensure that the formatting settings are aligned as described below. This reduces the chance that code which is formatted by ktlint conflicts with formatting by the IntelliJ IDEA built-in formatter. | ||
|
||
!!! Note | ||
IntelliJ IDEA supports the [kotlin coding conventions](https://kotlinlang.org/docs/coding-conventions.html). As of version 0.47.x of ktlint, the support to overwrite some configuration files of IntelliJ IDEA has been dropped as it no longer fits the scope of the project. | ||
|
||
|
||
Steps: | ||
|
||
1. Go to your project directory | ||
2. Create or replace file `.idea/codeStyles/codeStyleConfig.xml` with content below: | ||
```xml | ||
<component name="ProjectCodeStyleConfiguration"> | ||
<state> | ||
<option name="USE_PER_PROJECT_SETTINGS" value="true" /> | ||
</state> | ||
</component> | ||
``` | ||
3. Create or replace file `.idea/codeStyles/Project.xml` with content below: | ||
```xml | ||
<component name="ProjectCodeStyleConfiguration"> | ||
<code_scheme name="Project" version="173"> | ||
<JetCodeStyleSettings> | ||
<option name="PACKAGES_TO_USE_STAR_IMPORTS"> | ||
<value /> | ||
</option> | ||
<option name="NAME_COUNT_TO_USE_STAR_IMPORT" value="2147483647" /> | ||
<option name="NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS" value="2147483647" /> | ||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" /> | ||
</JetCodeStyleSettings> | ||
<codeStyleSettings language="kotlin"> | ||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" /> | ||
</codeStyleSettings> | ||
</code_scheme> | ||
</component> | ||
``` | ||
# Intellij IDEA configuration | ||
|
||
`ktlint` strives to prevent code formatting conflicts with IntelliJ IDEA / Android Studio as much as possible. In some cases, `ktlint` deliberately deviates from IDEA formatting. | ||
|
||
## Preventing conflicts | ||
|
||
Many conflicts can be prevented by setting following `.editorconfig` settings: | ||
``` | ||
root = true | ||
[*] | ||
insert_final_newline = true | ||
[{*.kt,*.kts}] | ||
ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL | ||
# Disable wildcard imports entirely | ||
ij_kotlin_name_count_to_use_star_import = 2147483647 | ||
ij_kotlin_name_count_to_use_star_import_for_members = 2147483647 | ||
ij_kotlin_packages_to_use_import_on_demand = unset | ||
``` | ||
|
||
Conflicts between `ktlint` and IDEA formatting can also be resolved by using the [ktlint-intellij-plugin](https://plugins.jetbrains.com/plugin/15057-ktlint) (or install via Intellij IDEA plugin marketplace) in `distract free` mode. In this mode, the plugin formats your code with `ktlint` while you're editing the code. | ||
|
||
# Cleaning up old XML configuration settings | ||
|
||
Projects which have been created with (old)er versions of Intellij IDEA might still contain XML configuration regarding code styling. It is advised to remove the directory `.idea/codeStyles` whenever it still exists in your project directory. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 27 additions & 36 deletions
63
documentation/snapshot/docs/rules/configuration-intellij-idea.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,27 @@ | ||
!!! Warning | ||
`ktlint` strives to prevent code formatting conflicts with IntelliJ IDEA / Android Studio. We recommend using either IDE formatting or `ktlint` formatting. However, if you persist on using both, then please ensure that the formatting settings are aligned as described below. This reduces the chance that code which is formatted by ktlint conflicts with formatting by the IntelliJ IDEA built-in formatter. | ||
|
||
!!! Note | ||
IntelliJ IDEA supports the [kotlin coding conventions](https://kotlinlang.org/docs/coding-conventions.html). As of version 0.47.x of ktlint, the support to overwrite some configuration files of IntelliJ IDEA has been dropped as it no longer fits the scope of the project. | ||
|
||
|
||
Steps: | ||
|
||
1. Go to your project directory | ||
2. Create or replace file `.idea/codeStyles/codeStyleConfig.xml` with content below: | ||
```xml | ||
<component name="ProjectCodeStyleConfiguration"> | ||
<state> | ||
<option name="USE_PER_PROJECT_SETTINGS" value="true" /> | ||
</state> | ||
</component> | ||
``` | ||
3. Create or replace file `.idea/codeStyles/Project.xml` with content below: | ||
```xml | ||
<component name="ProjectCodeStyleConfiguration"> | ||
<code_scheme name="Project" version="173"> | ||
<JetCodeStyleSettings> | ||
<option name="PACKAGES_TO_USE_STAR_IMPORTS"> | ||
<value /> | ||
</option> | ||
<option name="NAME_COUNT_TO_USE_STAR_IMPORT" value="2147483647" /> | ||
<option name="NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS" value="2147483647" /> | ||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" /> | ||
</JetCodeStyleSettings> | ||
<codeStyleSettings language="kotlin"> | ||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" /> | ||
</codeStyleSettings> | ||
</code_scheme> | ||
</component> | ||
``` | ||
# Intellij IDEA configuration | ||
|
||
`ktlint` strives to prevent code formatting conflicts with IntelliJ IDEA / Android Studio as much as possible. In some cases, `ktlint` deliberately deviates from IDEA formatting. | ||
|
||
## Preventing conflicts | ||
|
||
Many conflicts can be prevented by setting following `.editorconfig` settings: | ||
``` | ||
root = true | ||
[*] | ||
insert_final_newline = true | ||
[{*.kt,*.kts}] | ||
ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL | ||
# Disable wildcard imports entirely | ||
ij_kotlin_name_count_to_use_star_import = 2147483647 | ||
ij_kotlin_name_count_to_use_star_import_for_members = 2147483647 | ||
ij_kotlin_packages_to_use_import_on_demand = unset | ||
``` | ||
|
||
Conflicts between `ktlint` and IDEA formatting can also be resolved by using the [ktlint-intellij-plugin](https://plugins.jetbrains.com/plugin/15057-ktlint) (or install via Intellij IDEA plugin marketplace) in `distract free` mode. In this mode, the plugin formats your code with `ktlint` while you're editing the code. | ||
|
||
# Cleaning up old XML configuration settings | ||
|
||
Projects which have been created with (old)er versions of Intellij IDEA might still contain XML configuration regarding code styling. It is advised to remove the directory `.idea/codeStyles` whenever it still exists in your project directory. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters