Skip to content

Commit 4c1a2cc

Browse files
authored
chore: Include spotless formatter (#1234)
Uses https://github.com/palantir/palantir-java-format for Java which seems to be pretty close to the 'Vaadin conventions' by default Includes prettier for TypeScript but commented out to avoid requiring node from everybody
1 parent 1191ca5 commit 4c1a2cc

File tree

7 files changed

+46
-16
lines changed

7 files changed

+46
-16
lines changed

Diff for: .prettierrc.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"singleQuote": true,
3+
"printWidth": 120,
4+
"bracketSameLine": true
5+
}
6+

Diff for: README.md

+8
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ Vaadin web applications are full-stack and include both client-side and server-s
7676
|     `Application.java` | Server entrypoint |
7777
|     `AppShell.java` | application-shell configuration |
7878

79+
## Code Formatting
80+
81+
The project includes the Spotless code formatter.
82+
83+
To use it in IntelliJ, install the [https://plugins.jetbrains.com/plugin/22455-spotless-applier](IntelliJ plugin)
84+
To use it in VS Code, install the [https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-spotless-gradle ](VS Code extension)
85+
To use it from the command line, run `mvn spotless:apply`
86+
7987
## Useful links
8088

8189
- Read the documentation at [vaadin.com/docs](https://vaadin.com/docs).

Diff for: pom.xml

+26-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,32 @@
9797
<groupId>org.springframework.boot</groupId>
9898
<artifactId>spring-boot-maven-plugin</artifactId>
9999
</plugin>
100-
100+
<plugin>
101+
<groupId>com.diffplug.spotless</groupId>
102+
<artifactId>spotless-maven-plugin</artifactId>
103+
<version>2.43.0</version>
104+
<configuration>
105+
<java>
106+
<palantirJavaFormat>
107+
<version>2.50.0</version>
108+
</palantirJavaFormat>
109+
</java>
110+
<!-- Uncomment to format TypeScript files
111+
<typescript>
112+
<includes>
113+
<include>src/main/frontend/**/*.ts</include>
114+
</includes>
115+
<excludes>
116+
<exclude>src/main/frontend/generated/**</exclude>
117+
</excludes>
118+
<prettier>
119+
<prettierVersion>3.3.3</prettierVersion>
120+
<configFile>.prettierrc.json</configFile>
121+
</prettier>
122+
</typescript>
123+
-->
124+
</configuration>
125+
</plugin>
101126
<plugin>
102127
<groupId>com.vaadin</groupId>
103128
<artifactId>vaadin-maven-plugin</artifactId>

Diff for: src/main/java/org/vaadin/example/Application.java

-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.vaadin.flow.component.page.AppShellConfigurator;
44
import com.vaadin.flow.server.PWA;
55
import com.vaadin.flow.theme.Theme;
6-
76
import org.springframework.boot.SpringApplication;
87
import org.springframework.boot.autoconfigure.SpringBootApplication;
98

@@ -22,5 +21,4 @@ public class Application implements AppShellConfigurator {
2221
public static void main(String[] args) {
2322
SpringApplication.run(Application.class, args);
2423
}
25-
2624
}

Diff for: src/main/java/org/vaadin/example/GreetService.java

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.vaadin.example;
22

33
import java.io.Serializable;
4-
54
import org.springframework.stereotype.Service;
65

76
@Service
@@ -14,5 +13,4 @@ public String greet(String name) {
1413
return "Hello " + name;
1514
}
1615
}
17-
1816
}

Diff for: src/main/java/org/vaadin/example/MainView.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
package org.vaadin.example;
22

3-
import org.springframework.beans.factory.annotation.Autowired;
4-
53
import com.vaadin.flow.component.Key;
64
import com.vaadin.flow.component.button.Button;
75
import com.vaadin.flow.component.button.ButtonVariant;
86
import com.vaadin.flow.component.html.Paragraph;
9-
import com.vaadin.flow.component.notification.Notification;
107
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
118
import com.vaadin.flow.component.textfield.TextField;
129
import com.vaadin.flow.router.Route;
10+
import org.springframework.beans.factory.annotation.Autowired;
1311

1412
/**
1513
* A sample Vaadin view class.
@@ -32,8 +30,7 @@ public class MainView extends VerticalLayout {
3230
* Build the initial UI state for the user accessing the application.
3331
*
3432
* @param service
35-
* The message service. Automatically injected Spring managed
36-
* bean.
33+
* The message service. Automatically injected Spring managed bean.
3734
*/
3835
public MainView(@Autowired GreetService service) {
3936

@@ -60,5 +57,4 @@ public MainView(@Autowired GreetService service) {
6057

6158
add(textField, button);
6259
}
63-
6460
}

Diff for: src/test/java/org/vaadin/example/MainViewIT.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package org.vaadin.example;
22

3-
import org.junit.jupiter.api.Assertions;
4-
import org.junit.jupiter.api.BeforeEach;
5-
import org.openqa.selenium.Keys;
6-
73
import com.vaadin.flow.component.button.testbench.ButtonElement;
84
import com.vaadin.flow.component.html.testbench.ParagraphElement;
95
import com.vaadin.flow.component.textfield.testbench.TextFieldElement;
106
import com.vaadin.testbench.BrowserTest;
117
import com.vaadin.testbench.BrowserTestBase;
8+
import org.junit.jupiter.api.Assertions;
9+
import org.junit.jupiter.api.BeforeEach;
10+
import org.openqa.selenium.Keys;
1211

1312
public class MainViewIT extends BrowserTestBase {
1413

@@ -27,7 +26,7 @@ private static String getDeploymentHostname() {
2726

2827
@BeforeEach
2928
public void open() {
30-
getDriver().get("http://"+getDeploymentHostname()+":8080/");
29+
getDriver().get("http://" + getDeploymentHostname() + ":8080/");
3130
}
3231

3332
@BrowserTest

0 commit comments

Comments
 (0)