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

๐Ÿš€ ํ”„๋กœ์ ํŠธ์— checkstyle(lint)๊ณผ code style(formatter) ์„ค์ • #19

Merged
merged 22 commits into from
Dec 22, 2023

Conversation

Sehee-Lee-01
Copy link
Member

@Sehee-Lee-01 Sehee-Lee-01 commented Dec 21, 2023

โœ… ์š”๊ตฌ์‚ฌํ•ญ

  • checkstyle(Java Lint) ์ ์šฉ
  • checkstyle์„ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•œ code style ์ƒ์„ฑ
  • ๊ธฐ์กด ๋ชจ๋“  ์†Œ์Šค์ฝ”๋“œ code style ๋ฐ˜์˜

๐Ÿš€ ์ฃผ์š” ๋ณ€๊ฒฝ์‚ฌํ•ญ

checkstyle(Java Lint) ์ ์šฉ

  • config/checkstyle/checkstyle.xml ์ถ”๊ฐ€: ๊ธฐ๋ณธ ์Šคํƒ€์ผ์ธ ๊ตฌ๊ธ€ google checkstyle ์ ์šฉ ํ›„ ์ปค์Šคํ…€
  • config/checkstyle/suppressions.xml ์ถ”๊ฐ€: Lint๋ฅผ ์กฐ๊ธˆ ๋” ์„ธ๋ฐ€ํ•˜๊ฒŒ ๋ฐ˜์˜ํ•˜๊ณ  ์‹ถ์ง€ ์•Š์„ ๋•Œ. ๋ถˆํ•„์š”ํ•œ Lint Warning์ด ์žˆ์„ ๋•Œ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๋Š” ํŒŒ์ผ(checkstyle.xml ํŒŒ์ผ๊ณผ ์„ธํŠธ์ž…๋‹ˆ๋‹น.)
  • config/checkstyle/configuration_1_3.dtd๊ณผ config/checkstyle/suppressions_1_2.dtd: ์›๋ž˜ ์ด ํŒŒ์ผ์€ ์›๋ณธ ๊ตฌ๊ธ€ checkstyle.xml, suppressions.xml์—์„œ http๋กœ ๋งค๋ฒˆ ๋ฐ›์•„์™€์•ผํ•˜๋Š” ๊ฒƒ ๊ฐ™๋˜๋ฐ http ํ†ต์‹  ์—†์ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ์•„์˜ˆ ๋„ฃ์–ด๋†จ์Šต๋‹ˆ๋‹ค.
  • gradle.build์— ํ”Œ๋Ÿฌ๊ทธ์ธ ์ ์šฉ ๋ฐ ์œ„ ์„ค์ • ํŒŒ์ผ๋“ค ์ธ์‹ํ•˜๋„๋ก ์„ค์ •

checkstyle์„ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•œ code style ์ƒ์„ฑ

  • ProjectCodeStyleConfiguration.xml ๊ณผ intellij code style xml(.idea/codeStyles/Project.xml) ์ถ”๊ฐ€

| ์„ธ๋ถ€ ์Šคํƒ€์ผ ์„ค์ •์€ commit log ์ฐธ๊ณ  ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค!

๐Ÿ’ก ๊ธฐํƒ€์‚ฌํ•ญ

๐Ÿšจ pull ์ดํ›„ code style ์„ค์ • ๋ฐ˜์˜์ด ์•ˆ๋œ๋‹ค๋ฉด ์•„๋ž˜ ์ด๋ฏธ์ง€์ฒ˜๋Ÿผ Project๋ฅผ ์„ค์ •ํ•ด์ค˜์•ผํ•ฉ๋‹ˆ๋‹ค!(์•„๋ž˜ ์‚ฌ์ง„ ์ฐธ๊ณ )

image

1. Code Style ์„ค์ • ๋ฐฉ๋ฒ•์— ๋Œ€ํ•œ ๊ณ ๋ฏผ์„ ํ–ˆ์Šต๋‹ˆ๋‹ค.

  • code style ์„ค์ • ๋ฐฉ๋ฒ•์—๋Š” ๋‘ ๊ฐ€์ง€๊ฐ€ ์žˆ๋Š”๋ฐ .editorconfig ํŒŒ์ผ์„ ์ด์šฉํ•˜๋Š” ๊ฒƒ๊ณผ ํ˜„์žฌ ์ ์šฉํ•œ ๊ฒƒ์ฒ˜๋Ÿผ IntelliJ IDEA code style XML ์„ค์ •์ด ์žˆ์Šต๋‹ˆ๋‹ค.
    • intellij code style xml ์„ค์ •์€ ์ธํ…”๋ฆฌ์ œ์ด ide์—๋งŒ ํ•œ์ •๋˜๊ณ  editorconfig๋Š” ํŠน์ • ide์— ๊ตฌ์• ๋ฐ›์ง€ ์•Š๋Š”๋‹ค๋Š” ํŠน์ง•์ด ์žˆ์Šต๋‹ˆ๋‹ค.
    • ๋‹ค๋งŒ editorconfig๋Š” ํ”Œ๋Ÿฌ๊ทธ์ธ ์„ค์น˜๋ฅผ ๋ณ„๋„๋กœ ํ•ด์•ผํ•˜๋Š” ๊ฒƒ์œผ๋กœ ์•Œ๊ณ  ์žˆ๊ณ , ๋ชจ๋“  ํŒ€์›์ด ์ธํ…”๋ฆฌ์ œ์ด๋ฅผ ๊ธฐ๋ณธ์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์–ด์„œ intellij code style xml๋กœ ์„ค์ •ํ•˜๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค!

2. ์ถ”ํ›„ ์ƒ๊ฐํ•  ์ผ(์ฐธ๊ณ )

  • html ํŒŒ์ผ๋กœ ๋ฆฌํฌํŠธ๋ฅผ ๋ฐ›๋Š” ์„ค์ •์ด ์žˆ๋Š”๋ฐ ํ•„์š”ํ•˜๋ฉด ๋ฐ˜์˜ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค!
  • gradle.build ํŒŒ์ผ์—์„œ checkstyle ์„ค์ •์—์„œ maxWarnings ์ฒ˜๋ฆฌ๋ฅผ ์•ˆํ•œ ์ƒํƒœ๋ผ ๊ฒฝ๊ณ ๋งŒ ๋œจ๊ณ  ๋นŒ๋“œ์—๋Š” ์˜ํ–ฅ์ด ๊ฐ€์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์ถ”ํ›„ ํ•„์š”ํ•˜๋‹ค๋ฉด ๋นŒ๋“œ์—๋„ ์˜ํ–ฅ์ด ๊ฐ€๋„๋ก ๋ฐ”๊พธ๊ฒ ์Šต๋‹ˆ๋‹ค!
  • ์ฟผ๋ฆฌ DSL ์ ์šฉ ํ›„ ์ˆ˜์ •์ด ํ•„์š”ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ๋ฉ”์„œ๋“œ ๋ผ์ธ ์ œํ•œ ํ™•์ธ๋งŒ ํ•ด๋ณด๊ธฐ => jacoco ๋ฉ”์„œ๋“œ ๋ผ์ธ ์ œํ•œ ์ฒ˜๋Ÿผ ์—ฌ๊ธฐ์—๋„ ํ™•์ธํ•˜๋Š” ๊ฒƒ์ด ์žˆ๋„ค์šฉ!

3. TMI(2023.12.22 ์ •์ •)

  • ์ž˜๋ชป๋œ ์„ค๋ช…: _checkstyle์€ java code style๋งŒ ํ™•์ธํ•˜๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค! ์•„๊นŒ ๋‹ค๊ฐ™์ด ๋ณธ fileExtensions์€ ์—ฌ๊ธฐ ์„ค๋ช…์— ๋”ฐ๋ฅด๋ฉด ํ—ˆ์šฉ๋˜๋Š” ํŒŒ์ผ ํ™•์žฅ์ž๋ช…์ด๋ผ๊ณ ๋งŒ ๋˜์–ด์žˆ๋„ค์š”..! ๋˜ ๊ณต์‹๋ฌธ์„œ์—์„œ๋„ java code ์œ„์ฃผ๋กœ๋งŒ ๋ณธ๋‹ค๋Š” ๋ง๋„ ์žˆ์–ด์š”!

It automates the process of checking Java code to spare humans of this boring (but important) task. This makes it ideal for projects that want to enforce a coding standard._

  • ์ •์ •๐Ÿšจ: xml ํŒŒ์ผ๊นŒ์ง€ ์Šคํƒ€์ผ ๋‹ค ํ™•์ธํ•ด์ค๋‹ˆ๋‹ค....

checkstye.xml์€ google ์Šคํƒ€์ผ์„ ๋”ฐ๋ฅธ๋‹ค.
๋ถˆํ•„์š”ํ•œ ๊ทœ์น™์„ ์žก์•„์ค€๋‹ค๋ฉด ๋‚˜์ค‘์— ์ถ”๊ฐ€ ์˜ˆ์ •
- ํ”Œ๋Ÿฌ๊ทธ์ธ ์ถ”๊ฐ€
- checkstyle config ํŒŒ์ผ๊ณผ ํ”„๋กœํผํ‹ฐ, ๋ฒ„์ „ ์„ค์ •
Copy link
Collaborator

@ASak1104 ASak1104 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check style ๋•Œ๋ฌธ์ธ์ง€ ์ฝ”๋“œ ์ปจ๋ฒค์…˜์ด ๋‹ค๋ฅธ ๋ถ€๋ถ„์ด ์žˆ๋„ค์š”!

src/main/java/com/backendoori/ootw/domain/BaseEntity.java Outdated Show resolved Hide resolved
build.gradle Outdated Show resolved Hide resolved
Copy link
Collaborator

@ASak1104 ASak1104 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊ณ ์ƒํ•˜์…จ์Šต๋‹ˆ๋‹ค!
๋ฆฌ๋ทฐ๋กœ ๋‚จ๊ธด ๋ถ€๋ถ„์€ ๊ฐ™์ด ๊ฒ€ํ† ํ•ด๋ณด๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”!

Comment on lines 3 to 9
import java.time.LocalDateTime;
import lombok.Getter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import lombok.Getter;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด ๋ถ€๋ถ„์€ import๋ฌธ์˜ ์˜ค๋”๊ฐ€ ๋‹ค๋ฅธ ๊ฒƒ ๊ฐ™์•„์š”!
์•„๋ž˜์™€ ๊ฐ™์ด formatting์ด ๋˜์•ผํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!

import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import java.time.LocalDateTime;
import lombok.Getter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํ™•์ธํ•ด์„œ ๋ฐฉ๊ธˆ ๊ณ ์ณค์Šต๋‹ˆ๋‹ค! ๋ฐ”๋กœ ์ปค๋ฐ‹ ์˜ฌ๋ฆฌ๊ฒ ์Šต๋‹ˆ๋‹ค!

build.gradle Outdated
Comment on lines 90 to 96
checkstyle {
toolVersion = "10.12.5"
configFile = file("${rootDir}/config/checkstyle/checkstyle.xml")
configProperties = [
"org.checkstyle.google.suppressionfilter.config" : "suppressions.xml",
"org.checkstyle.google.suppressionxpathfilter.config": "suppressions.xml"]
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด ๋ถ€๋ถ„์— ํ•„์š” ์—†๋Š” ๊ณต๋ฐฑ์ด ์กฐ๊ธˆ ์žˆ๋„ค์š”!
์•„๋ž˜์™€ ๊ฐ™์ด ์ˆ˜์ •ํ•˜๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค

Suggested change
checkstyle {
toolVersion = "10.12.5"
configFile = file("${rootDir}/config/checkstyle/checkstyle.xml")
configProperties = [
"org.checkstyle.google.suppressionfilter.config" : "suppressions.xml",
"org.checkstyle.google.suppressionxpathfilter.config": "suppressions.xml"]
}
checkstyle {
toolVersion = "10.12.5"
configFile = file("${rootDir}/config/checkstyle/checkstyle.xml")
configProperties = [
"org.checkstyle.google.suppressionfilter.config" : "suppressions.xml",
"org.checkstyle.google.suppressionxpathfilter.config": "suppressions.xml"]
}

Copy link
Member Author

@Sehee-Lee-01 Sehee-Lee-01 Dec 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์žก์•„ ์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! ๋ญ”๊ฐ€ ์ค„๋ฐ”๊ฟˆ ์ž‘์—…์„ ์ข€ ๋งŽ์ด ํ•˜๋‹ค๋ณด๋‹ˆ ์ปดํ“จํ„ฐ๊ฐ€ ์ œ๋Œ€๋กœ ์žก์งˆ ๋ชปํ•˜๋Š” ๊ฒƒ ๊ฐ™๋„ค์š”,,, ์œˆ๋„์šฐ์—์„œ๋Š” ์•„๋ž˜ ๊ณ ์นœ ๋ถ€๋ถ„์ฒ˜๋Ÿผ ๋ณด์—ฌ์„œ ์ธ์‹์„ ๋ชปํ•˜๊ณ  ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค! ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹คใ… ใ… ใ… 

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ˆ˜์ •์ด์ „์—๋Š” ํƒญ๋ฌธ์ž๊ฐ€ ์žˆ์—ˆ๋„ค์š”! ide ์ƒ์—์„œ๋Š” ์ŠคํŽ˜์ด์Šค 4๊ฐœ ํฌ๊ธฐ์™€ ๋™์ผํ•˜๊ฒŒ ๋ณด์ด๋Š”๋ฐ github์—์„œ๋Š” ํฌ๊ธฐ๊ฐ€ ๋‹ฌ๋ผ์„œ ๋‹ค๋ฅด๊ฒŒ ๋ณด์ด๋Š” ๊ฒƒ์ด์—ˆ์Šต๋‹ˆ๋‹ค! ์ŠคํŽ˜์ด์Šค 4๊ฐœ๋กœ ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค~!

๊ทธ๋ฃน ์„ค์ •์—์„œ ์ž˜๋ชป๋œ ๋ถ€๋ถ„ ์ˆ˜์ •
์ˆ˜์ • ์ด์ „์—๋Š” ํƒญ๋ฌธ์ž๊ฐ€ ์žˆ์—ˆ๋‹ค. ์ด ๋ถ€๋ถ„ ๋•Œ๋ฌธ์— github์— ์˜ฌ๋ผ๊ฐ”์„ ๋•Œ ๋‹ค๋ฅด๊ฒŒ ๋ณด์ด๋Š” ๊ฒƒ ๊ฐ™๋‹ค.
@Sehee-Lee-01 Sehee-Lee-01 merged commit 4e8c971 into backendoori:main Dec 22, 2023
Sehee-Lee-01 added a commit that referenced this pull request Jan 19, 2024
This reverts commit 4e8c971, reversing
changes made to ccb1ab6.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

โœ… checkstyle ์ ์šฉํ•˜๊ธฐ(์ž๋ฐ” Lint)
3 participants