ktlint

  • lint : 코드를 분석하여, 프로그램 오류, 버그, 스타일 오류, 구조적 문제점을 확인하는 도구
    • 코딩 컨벤션에 따라 코드를 작성했는지 확인해주는 도구
    • ktlint : kotlin 개발 환경에서 사용되는 lint 로, 공식 코틀린 코딩 컨벤션과 안드로이드 코틀린 스타일 가이드에 따라 만들어짐 ( pinterest 사에서 만듦 )
    • Android lint : 폴더 선택 > 마우스 오른쪽 버튼 > Analyaze > Inspect

 

코딩 컨벤션

사람들마다 indent 가 다를 수 있음. 규칙들이 같아야 가독성이 높아져서 생산성이 높아진다. 혼자서 개발을 한다고 해도 시간이 지난 뒤에는 작성자 본인 역시 타인이 된다. 유지보수 편리. 새로운 사람이 적응하기에도 편리.
 
 
 
 

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 ) 에 아래 코드 추가

 

  1. 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

 

+ Recent posts