Skip to content

Commit 766c89e

Browse files
authored
Add hint on auto formatting (#13886)
* Add hint on auto formatting * Fix spelling of Checkstyle * Revert JBang - is in the settings xml * Add heading to enable deep linking
1 parent 99411e7 commit 766c89e

File tree

2 files changed

+40
-18
lines changed

2 files changed

+40
-18
lines changed
122 KB
Loading

docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/intellij-13-code-style.md

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Click on "Restart" to finally restart.
3737

3838
Wait for IntelliJ coming up again.
3939

40+
## Put JabRef's code style configuration in place
41+
4042
Go to **File > Settings... > Editor > Code Style**
4143

4244
Click on the settings wheel (next to the scheme chooser),
@@ -65,13 +67,13 @@ Click there "OK", too.
6567

6668
Click on "Apply" to store the preferences.
6769

68-
## Put JabRef's checkstyle configuration in place
70+
## Put JabRef's Checkstyle configuration in place
6971

70-
Now, put the checkstyle configuration file is in place:
72+
Now, put the Checkstyle configuration file is in place:
7173

7274
Go to **File > Settings... > Tools > Checkstyle > Configuration File**
7375

74-
Trigger the import dialog of a CheckStyle style by clicking the \[+] button:
76+
Trigger the import dialog of a Checkstyle style by clicking the \[+] button:
7577

7678
{% figure caption:"Trigger the rule import dialog" %}
7779
![Trigger the rule import dialog](13-07-checkstyle-start-import.png)
@@ -90,30 +92,20 @@ Then:
9092

9193
Click on "Finish"
9294

93-
Activate the CheckStyle configuration file by ticking it in the list
95+
Activate the Checkstyle configuration file by ticking it in the list
9496

95-
{% figure caption:"JabRef's checkstyle config is activated" %}
96-
![JabRef's checkstyle config is activated](13-09-checkstyle-jabref-active.png)
97+
{% figure caption:"JabRef's Checkstyle config is activated" %}
98+
![JabRef's Checkstyle config is activated](13-09-checkstyle-jabref-active.png)
9799
{% endfigure %}
98100

99-
Ensure that the [latest CheckStyle version](https://checkstyle.org/releasenotes.html) is selected (10.21.0 or higher).
101+
Ensure that the [latest Checkstyle version](https://checkstyle.org/releasenotes.html) is selected (10.21.0 or higher).
100102
Also, set the "Scan Scope" to "Only Java sources (including tests)".
101103

102104
{% figure caption:"Checkstyle is the highest version - and tests are also scanned" %}
103105
![Checkstyle is the highest version - and tests are also scanned](13-10-checkstyle-final-settings.png)
104106
{% endfigure %}
105107

106-
Save settings by clicking "Apply" and then "OK"
107-
108-
## Run checkstyle
109-
110-
In the lower part of IntelliJ's window, click on "Checkstyle".
111-
In "Rules", change to "JabRef".
112-
Then, you can run a check on all modified files.
113-
114-
{% figure caption:"JabRef's style is active - and we are ready to run a check on all modified files" %}
115-
![JabRef's style is active - and we are ready to run a check on all modified files](13-11-checkstyle-window.png)
116-
{% endfigure %}
108+
Save settings by clicking "Apply".
117109

118110
## Have auto format working properly in JavaDoc
119111

@@ -127,6 +119,26 @@ At "Other", disable "Wrap at right margin"
127119
!["Wrap at right margin" disabled](13-12-editor-javadoc-do-not-wrap.png)
128120
{% endfigure %}
129121

122+
## Enable auto formatting of your code
123+
124+
IntelliJ can automatically reformat your code on save.
125+
Please make use of this functionality.
126+
127+
Go to **File > Settings... > Tools > Actions on Save**.
128+
129+
1. Check "Reformat on code"
130+
2. Click on "All file types" (on the right)
131+
3. Uncheck "All file types"
132+
4. Check "Java"
133+
5. Check "Optimize imports"
134+
6. Click on "All file types" (on the right)
135+
7. Uncheck "All file types" to disable it
136+
8. Check "Java"
137+
138+
{% figure caption:"Enable autoformatting on save" %}
139+
![Enable autoformatting on save](13-12.5-auto-formatting.png)
140+
{% endfigure %}
141+
130142
## Enable proper import cleanup
131143

132144
To enable "magic" creation and auto cleanup of imports, go to **File > Settings... > Editor > General > Auto Import**.
@@ -151,6 +163,16 @@ At section "Java", disable "One-line methods".
151163

152164
Press "OK".
153165

166+
## Run checkstyle
167+
168+
In the lower part of IntelliJ's window, click on "Checkstyle".
169+
In "Rules", change to "JabRef".
170+
Then, you can run a check on all modified files.
171+
172+
{% figure caption:"JabRef's style is active - and we are ready to run a check on all modified files" %}
173+
![JabRef's style is active - and we are ready to run a check on all modified files](13-11-checkstyle-window.png)
174+
{% endfigure %}
175+
154176
## Final comments
155177

156178
{: .highlight }

0 commit comments

Comments
 (0)