-
Android studio/InteliJ IDEA Code inspectionsAndroid 2022. 9. 8. 12:16반응형
Lint에 관련해서 확인중에 IDE 에서 Code inspections라는 항목을 보고 해당 내용을 확인 하였습니다.
InteliJ IDEA를 기반으로 하는 IDE 들은 모두 사용 할 수 있는것으로 보입니다.
해당 기능을 통해서 코드의 구조의 규칙이나 변경사항들을 Editor에서 확인 가능 하도록 할 수 있습니다.
Code Inspections을 사용하기 위해서 Inspections 창으로 이동해야 합니다.
macOS 을 기준으로 Android studio -> preference -> Editor -> Inspections 으로 이동
해당 화면에서 Editor에 표기될 경고 및 에러에 대한 표기를 조절할 수 있습니다.
[Structural Search 등록]
상단 검색창 우측의 + 버튼을 클릭해서 자신이 원하는 Structural search Inspection template을 만들수 있습니다.
Add Search Template... 은 검색 조건에 대한 Inspection template만 추가 합니다.
Add Replace Template... 은 검색된 코드를 내가 정의한 형태로 변경해주는 Inspection template 추가 합니다.
[Structural search Inspection template 작성]
Template은 기본적으로 $$사이에 변수를 입력하고 검색하고자 하는 코드의 구조를 입력합니다.
$context$.getString($int$)
$$ 사이에 들어가는 변수명은 자유롭게 작성가능 합니다.하지만 설명이 필요없는 직관적인 이름을 사용하는게 좋습니다.상단의 search template 은 검색을 하려는 구조를 입력합니다.
하단의 replace template의 경우 변경하고자하는 구조를 입력합니다.
변수는 우측의 필터를 통해서 조건을 걸 수 있습니다.
추가할 수 있는 필터 조건은 count, reference, text, type, script 가 있습니다.
자세한 작성 방법 및 조건은 아래의 공식문서를 참고 바랍니다.
https://www.jetbrains.com/help/idea/structural-search-and-replace.html
Structural search and replace | IntelliJ IDEA
www.jetbrains.com
Template 작성 완료 후에 Inspection name, Problem tool tip, Description, Suppress ID 를 입력 후 OK 버튼을 누르면 등록이 완료 됩니다.
새롭개 추가한 Template은 Inspections 의 좌측의 Sturctural search 에 등록 됩니다.
[Editor 에서 확인 및 Rpelace 하기]
Inspection 적용 이후에는 아래의 이미지 처럼 Warning 표기가 표시됩니다.
해당 코드위에 마우스를 올려놓으면 아래와 같이 tooltip이 표기되며 등록된 Problem tool tip, Description 정보가 표시 됩니다.
alt + enter 를 입력하여 replace 를 할 수 있습니다.
replace 시 등록 했던 Temple으로 변환 됩니다.
[Serverity 변경]
해당 조건을 Warning 표기가 아닌 다른 표기로 변경도 가능 합니다.
Instection 창 우측 Serverity 를 WARNING 에서 ERROR 로 변경합니다.
ERROR 로 변경시 아래의 이미지처럼 코드에 Error 로 표기 됩니다.
Serverity 는 기본적으로 Error, Warning, Weak Warning, Server Problem, Typo 로 등록 되어 있고
Edit Severities... 로 새로운 Serverity 를 추가 할 수 있습니다.
[예외처리]
해당 Inspections을 등록된 Serverity 표기가 안되도록 예외처리가 필요한 경우
@Suppress() 어노테이션에 Inspections 등록시 작성한 Suppress ID 를 추가하면
해당 부분은 예외처리되어 표기되지 않습니다.
[참고자료]
https://developer.android.com/studio/write/lint
린트 검사로 코드 개선 | Android 개발자 | Android Developers
테스트를 빌드하여 앱이 기능적 요구사항을 충족하는지 확인하는 것 외에도 린트를 통해 코드를 실행하여 코드에 구조적 문제가 없는지 확인하는 것이 중요합니다.
developer.android.com
https://developer.android.com/studio/write/annotations
주석으로 코드 검사 개선 | Android 개발자 | Android Developers
주석을 사용하여 린트와 같은 코드 검사 도구에 힌트를 줌으로써 보다 미묘한 코드 문제를 더 잘 탐지하도록 할 수 있습니다.
developer.android.com
http://tools.android.com/tips/lint-checks
Android Lint Checks - Android Studio Project Site
Android tools project information site
tools.android.com
https://plugins.jetbrains.com/docs/intellij/code-inspections.html
Code Inspections | IntelliJ Platform Plugin SDK
plugins.jetbrains.com
https://www.jetbrains.com/help/idea/creating-custom-inspections.html
Create custom inspections | IntelliJ IDEA
www.jetbrains.com
https://www.jetbrains.com/help/idea/running-inspections.html
Run inspections | IntelliJ IDEA
www.jetbrains.com
https://www.jetbrains.com/help/idea/search-templates.html
Search Templates | IntelliJ IDEA
www.jetbrains.com
https://plugins.jetbrains.com/docs/intellij/psi-elements.html?from=jetbrains.org
PSI Elements | IntelliJ Platform Plugin SDK
plugins.jetbrains.com
IntelliJ의 structural search를 이용해 xml 의 특정 attribute 이름 바꾸기
며칠동안 나를 괴롭히던 난제를 해결했다. 풀고싶던 문제는 intellij(Android Studio) 에서 특정 tag의 특정 attribute의 이름을 손쉽게 바꾸는 방법은 무엇인가! 이다. 예를 들어 안드로이드 프로젝트의
kingorihouse.tumblr.com
Android studio code inspection shell script for integration in CI pipeline
I am trying to integrate dead code analysis for my android app to improve code quality. I found out the code inspection option that android studio provides out of the box which is giving me an exte...
stackoverflow.com
https://github.com/alexjlockwood/android-lint-checks-demo
GitHub - alexjlockwood/android-lint-checks-demo: A demo project that shows how to setup and write some basic custom lint checks.
A demo project that shows how to setup and write some basic custom lint checks. - GitHub - alexjlockwood/android-lint-checks-demo: A demo project that shows how to setup and write some basic custom...
github.com
안드로이드에서 Custom Lint 활용하기
Lint란?
charlezz.medium.com
https://www.androidhuman.com/2015-10-28-android-lint-preproof-your-code
Android Lint - 프로젝트 내 문제를 미리 파악하자
#Android, #Kotlin, and #Tesla
www.androidhuman.com
[안드로이드 팁] Inspect Code: 프로젝트 내의 모든 Lint 확인하기
Lint 안드로이드 프로젝트를 작업하다 보면 IDE가 시각적으로 수정을 요청하는 코드들이 있다. 그중에는 빌드 자체가 안 되는 코드도 있고, 빌드는 되지만 수정이 권장되는 코드도 있다. 바로 조
holika.tistory.com
https://www.jetbrains.com/help/idea/2016.1/structural-search-and-replace-examples.html
IntelliJ IDEA 2016.1 Help :: Structural Search and Replace Examples
Structural Search and Replace Examples This section provides a collection of structural search and replace examples: One statement $Statement$; Increasing the number of occurrences count to a certain number, you can find sequences of statements that contai
www.jetbrains.com
반응형'Android' 카테고리의 다른 글
Jetpack Compose Internals 한국어 번역 (0) 2024.02.17 2023년 4월 정책 업데이트 Google play 정책 세미나 (0) 2023.04.26 Clean Architecture in Android (0) 2023.01.30 Modern Android App Architecture (0) 2022.12.11 Jetpack Compose Modifier.onFocusChanged에서 animateScrollTo 가 작동안되는 문제 (0) 2022.04.07 Null Coalescing Operator(with. databinding) (0) 2022.01.05 Modifier in Jetpack Compose (0) 2021.12.15 Android adb 사용 여부 앱에서 확인하는 법 (0) 2021.12.14