ktlint
- lint : 코드를 분석하여, 프로그램 오류, 버그, 스타일 오류, 구조적 문제점을 확인하는 도구
- 코딩 컨벤션에 따라 코드를 작성했는지 확인해주는 도구
- ktlint : kotlin 개발 환경에서 사용되는 lint 로, 공식 코틀린 코딩 컨벤션과 안드로이드 코틀린 스타일 가이드에 따라 만들어짐 ( pinterest 사에서 만듦 )
- Android lint : 폴더 선택 > 마우스 오른쪽 버튼 > Analyaze > Inspect
코딩 컨벤션
1) lint
프로젝트 app 우클릭 > Analyze > Inspect Code
2) ktlint
Features - Ktlint
Welcome to Ktlint Kotlin linter in spirit of feross/standard (JavaScript) and gofmt (Go). Features No configuration required ktlint aims to capture the Kotlin coding conventions and Android Kotlin Style Guide. In some aspects ktlint is a bit more strict*.
pinterest.github.io
Installation > Integrations
안드로이드 스튜디오: 앱 수준의 그래들파일 ( Module: app )
ktlint 에서 build.gradle 참고
build.gradle.kts ( Module: app ) 에 아래 코드 추가
- configurations 는 dependenceis 위에 추가
// kotlin-gradle-plugin must be applied for configuration below to work
// (see <https://kotlinlang.org/docs/reference/using-gradle.html>)
repositories {
mavenCentral()
}
configurations {
ktlint
}
dependencies {
ktlint("com.pinterest:ktlint:0.47.1") {
attributes {
attribute(Bundling.BUNDLING_ATTRIBUTE, getObjects().named(Bundling, Bundling.EXTERNAL))
}
}
// additional 3rd party ruleset(s) can be specified here
// just add them to the classpath (e.g. ktlint 'groupId:artifactId:version') and
// ktlint will pick them up
}
task ktlint(type: JavaExec, group: "verification") {
description = "Check Kotlin code style."
classpath = configurations.ktlint
mainClass.set("com.pinterest.ktlint.Main")
args "src/**/*.kt"
// see <https://pinterest.github.io/ktlint/install/cli/#command-line-usage> for more information
}
check.dependsOn ktlint
task ktlintFormat(type: JavaExec, group: "formatting") {
description = "Fix Kotlin code style deviations."
classpath = configurations.ktlint
mainClass.set("com.pinterest.ktlint.Main")
args "-F", "src/**/*.kt"
// see <https://pinterest.github.io/ktlint/install/cli/#command-line-usage> for more information
}
위와 같이 변경을 하면
아래와 같이 task 옆에 play button 이 생긴다. 실행.
task 옆에 play button 이 나오지 않아서
240827 (화) 오후 4시부터 240828 (수) 오전 8시까지 헤맸는데
알고보니 안드로이드 스튜디오 버전이 맞지 않아서 그런 것이었다.
처음에 다운로드 받았던 안드로이드 스튜디오 버전은, Koala 2024.1.1
그러나 수업에 사용된 안드로이드 스튜디오 버전은, Dolphin 2021.3.1 Patch 1 이었다.
그래서 수업에 사용되는 버전 dmg 를 다운 받아 다운그래이드 하였다.
아래 인도 언니의 도움을 받아서
다운그래이드 및 여러 버전 동시 사용할 수 있엇다.
https://www.youtube.com/watch?v=t3fhvFhG4eY
'안드로이드 앱(Kotlin|Java) > [2025~] 안드로이드 앱' 카테고리의 다른 글
Part1_Ch01_01 오리엔테이션 (0) | 2025.02.03 |
---|---|
Part0_Ch04_04 detekt 적용해보기 (0) | 2025.02.03 |
Part0_Ch04_02 Android Studio 살펴보기 (0) | 2025.02.03 |
Part0_Ch03_05 뷰 그려지는 순서 (0) | 2025.02.03 |
Part0_Ch03_04 Activity 생명주기 (2) (0) | 2025.02.03 |