Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: 코드 포메팅 도구 CheckStyle을 Spotless로 변경한다 #25

Merged
merged 10 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id 'java'
id 'org.springframework.boot' version '3.1.5'
id 'io.spring.dependency-management' version '1.1.3'
id 'checkstyle'
id 'com.diffplug.spotless' version '6.11.0'
}

group = 'com.depromeet'
Expand Down Expand Up @@ -42,16 +42,22 @@ tasks.named('test') {
useJUnitPlatform()
}

tasks.withType(Checkstyle) {
reports {
xml.required = true
html.required = true
jar.enabled = false

spotless {
java {
target("**/*.java")
importOrder()
removeUnusedImports() // 사용하지 않는 import 제거
trimTrailingWhitespace() // 공백 제거
endWithNewline() // 끝부분 NewLine 처리
googleJavaFormat().aosp() // google java format
}
}

checkstyle {
configFile = file("config/checkstyle/naver-checkstyle-rules.xml")
configProperties = ['suppressionFile': file("config/checkstyle/naver-checkstyle-suppressions.xml")]
// pre-commit spotless check script
tasks.register('updateGitHooks', Copy) {
from './scripts/pre-commit'
into './.git/hooks'
}

jar.enabled = false
compileJava.dependsOn updateGitHooks
439 changes: 0 additions & 439 deletions config/checkstyle/naver-checkstyle-rules.xml

This file was deleted.

7 changes: 0 additions & 7 deletions config/checkstyle/naver-checkstyle-suppressions.xml

This file was deleted.

10 changes: 10 additions & 0 deletions scripts/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
echo "Running spotless check"
./gradlew spotlessCheck
if [ \$? -eq 0 ]
then
echo "Spotless check succeed"
else
echo "Spotless check failed" >&2
exit 1
fi
15 changes: 7 additions & 8 deletions src/main/java/com/depromeet/ExampleController.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package com.depromeet;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "health-check", description = "상태 체크")
@RestController
public class ExampleController {

@Operation(summary = "게시글 생성", description = "API health check")
@GetMapping("/health-check")
public String hello() {
return "hello";
}
@Operation(summary = "게시글 생성", description = "API health check")
@GetMapping("/health-check")
public String hello() {
return "hello";
}
}
6 changes: 3 additions & 3 deletions src/main/java/com/depromeet/TenminuteApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

@SpringBootApplication
public class TenminuteApplication {
public static void main(String[] args) {
SpringApplication.run(TenminuteApplication.class, args);
}
public static void main(String[] args) {
SpringApplication.run(TenminuteApplication.class, args);
}
}
91 changes: 42 additions & 49 deletions src/main/java/com/depromeet/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
package com.depromeet.config;

import java.util.List;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.fasterxml.jackson.databind.ObjectMapper;

import io.swagger.v3.core.jackson.ModelResolver;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
Expand All @@ -18,50 +11,50 @@
import io.swagger.v3.oas.models.security.SecurityScheme.Type;
import io.swagger.v3.oas.models.servers.Server;
import jakarta.servlet.ServletContext;
import java.util.List;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SwaggerConfig {

@Value("${swagger.version}")
private String version;

@Bean
public OpenAPI openAPI(ServletContext servletContext) {
Server server = new Server().url(servletContext.getContextPath());
return new OpenAPI()
.servers(List.of(server))
.components(authSetting())
.info(swaggerInfo());
}

private Components authSetting() {
return new Components()
.addSecuritySchemes(
"bearer auth",
new SecurityScheme()
.type(Type.HTTP)
.scheme("bearer")
.bearerFormat("JWT")
.in(In.HEADER)
.name("Authorization Token"));
}

private Info swaggerInfo() {
License license = new License();
license.setUrl("https://github.com/depromeet/10mm-server");
license.setName("10MM Server Repository");

return new Info()
.version("v" + version)
.title("\"10MM 서버 API문서\"")
.description("10MM 서버 API 문서입니다.")
.license(license);
}

@Bean
public ModelResolver modelResolver(ObjectMapper objectMapper) {
// 객체 직렬화
return new ModelResolver(objectMapper);
}

@Value("${swagger.version}")
private String version;

@Bean
public OpenAPI openAPI(ServletContext servletContext) {
Server server = new Server().url(servletContext.getContextPath());
return new OpenAPI().servers(List.of(server)).components(authSetting()).info(swaggerInfo());
}

private Components authSetting() {
return new Components()
.addSecuritySchemes(
"bearer auth",
new SecurityScheme()
.type(Type.HTTP)
.scheme("bearer")
.bearerFormat("JWT")
.in(In.HEADER)
.name("Authorization Token"));
}

private Info swaggerInfo() {
License license = new License();
license.setUrl("https://github.com/depromeet/10mm-server");
license.setName("10MM Server Repository");

return new Info()
.version("v" + version)
.title("\"10MM 서버 API문서\"")
.description("10MM 서버 API 문서입니다.")
.license(license);
}

@Bean
public ModelResolver modelResolver(ObjectMapper objectMapper) {
// 객체 직렬화
return new ModelResolver(objectMapper);
}
}
13 changes: 4 additions & 9 deletions src/main/java/com/depromeet/global/error/ErrorResponse.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
package com.depromeet.global.error;

import java.time.LocalDateTime;

import org.springframework.http.HttpStatus;

public record ErrorResponse(
int status,
String message,
LocalDateTime timestamp
) {
public record ErrorResponse(int status, String message, LocalDateTime timestamp) {

public static ErrorResponse of(HttpStatus status, String message) {
return new ErrorResponse(status.value(), message, LocalDateTime.now());
}
public static ErrorResponse of(HttpStatus status, String message) {
return new ErrorResponse(status.value(), message, LocalDateTime.now());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
@AllArgsConstructor
public class CustomException extends RuntimeException {

private final ErrorCode errorCode;
private final ErrorCode errorCode;
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package com.depromeet.global.error.exception;

import org.springframework.http.HttpStatus;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.http.HttpStatus;

@Getter
@AllArgsConstructor
public enum ErrorCode {
SAMPLE_ERROR(HttpStatus.BAD_REQUEST, "Sample Error Message"),
;

SAMPLE_ERROR(HttpStatus.BAD_REQUEST, "Sample Error Message"),
;

private final HttpStatus status;
private final String message;
private final HttpStatus status;
private final String message;
}
5 changes: 2 additions & 3 deletions src/test/java/com/depromeet/TenminuteApplicationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

@SpringBootTest
class TenminuteApplicationTests {
@Test
void contextLoads() {
}
@Test
void contextLoads() {}
}
Loading