Skip to content

Commit

Permalink
add java linter and formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
jorbush committed Sep 19, 2024
1 parent 26a1fd2 commit ed988b8
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 31 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/java-formatter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Java Formatter

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
spotless:
runs-on: ubuntu-latest
defaults:
run:
working-directory: postrify-backend
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up JDK
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'

- name: Run Spotless Check
run: ./mvnw spotless:check
28 changes: 28 additions & 0 deletions .github/workflows/java-linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Java Linter

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
checkstyle:
runs-on: ubuntu-latest
defaults:
run:
working-directory: postrify-backend
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up JDK
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'

- name: Run Checkstyle
run: ./mvnw checkstyle:check
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,15 @@ java -jar target/postrify-0.0.1-SNAPSHOT.jar
```bash
./mvnw test
```

#### Linter

```bash
./mvnw checkstyle:check
```

#### Format code

```bash
./mvnw spotless:apply
```
15 changes: 15 additions & 0 deletions postrify-backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.37.0</version>
<configuration>
<java>
<googleJavaFormat />
</java>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
@SpringBootApplication
public class PostrifyBackendApplication {

public static void main(String[] args) {
SpringApplication.run(PostrifyBackendApplication.class, args);
}

public static void main(String[] args) {
SpringApplication.run(PostrifyBackendApplication.class, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
@org.springframework.context.annotation.Configuration
public class SecurityConfig {

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(auth -> auth
.requestMatchers("/**").permitAll()
.anyRequest().authenticated()
);
return http.build();
}
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(
auth -> auth.requestMatchers("/**").permitAll().anyRequest().authenticated());
return http.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package com.postrify.postrifybackend.config;

import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@org.springframework.context.annotation.Configuration
public class WebConfig implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("http://localhost:4200")
.allowedOrigins("https://postrify.vercel.app")
.allowedMethods("GET", "POST", "PUT", "DELETE")
.allowedHeaders("*")
.allowCredentials(true);
}
@Override
public void addCorsMappings(CorsRegistry registry) {
registry
.addMapping("/**")
.allowedOrigins("http://localhost:4200")
.allowedOrigins("https://postrify.vercel.app")
.allowedMethods("GET", "POST", "PUT", "DELETE")
.allowedHeaders("*")
.allowCredentials(true);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
@RestController
public class HomeController {

@GetMapping("/")
public String home() {
return "Hello from Postrify Backend!";
}
@GetMapping("/")
public String home() {
return "Hello from Postrify Backend!";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
@SpringBootTest
class PostrifyBackendApplicationTests {

@Test
void contextLoads() {
}

@Test
void contextLoads() {}
}

0 comments on commit ed988b8

Please sign in to comment.