Skip to content

Commit

Permalink
chore: replace org.jlleitschuh.gradle.ktlint with org.jmailen.kotlinter
Browse files Browse the repository at this point in the history
- This change aims to align the gradle plugin with what is used in the
  Android Studio plugin, so the lint command will be synchronized
  with what is shown on the IDE
- It also fixes all the lint errors that were being ignored by the
  previous plugin
  • Loading branch information
ricardodalarme committed Jul 10, 2023
1 parent 6aab32d commit 2f65e0a
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 21 deletions.
5 changes: 3 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
root = true

[*.{kt,kts}]
#Custom configuration
ktlint_disabled_rules = no-wildcard-imports
ktlint_code_style=android_studio
insert_final_newline = true
ktlint_standard_max-line-length = disabled
ktlint_standard_no-wildcard-imports = disabled
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private val LightColorScheme = lightColorScheme(
onTertiary = Color.White,
onBackground = Color(0xFF1C1B1F),
onSurface = Color(0xFF1C1B1F),
*/
*/
)

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ val Typography = Typography(
lineHeight = 16.sp,
letterSpacing = 0.5.sp
)
*/
*/
)
13 changes: 3 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,15 @@ plugins {
id 'com.android.application' version '8.0.1' apply false
id 'com.android.library' version '8.0.1' apply false
id 'org.jetbrains.kotlin.android' version '1.8.21' apply false
id 'org.jlleitschuh.gradle.ktlint' version "11.3.2"
id 'org.jmailen.kotlinter' version '3.15.0'
}

subprojects {
apply plugin: 'org.jlleitschuh.gradle.ktlint'
apply plugin: 'org.jmailen.kotlinter'
}

ktlint {
version = "0.46.1"
debug = true
verbose = true
android = true
outputToConsole = true
outputColorName = "RED"
kotlinter {
ignoreFailures = false
enableExperimentalRules = true
}

task clean(type: Delete) {
Expand Down
8 changes: 3 additions & 5 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@ $ yarn install
This will install husky pre-commit, pre-push and msg-commit hooks.

### Install Ktlint to IDE
Make sure to open this project with Android Studio at least once before proceeding with ktlint instalation. That guarantees some hidden files/folders (like `.idea`) exist and can be configured by the following command. Navigate to the project’s directory in the terminal and execute:
```console
ktlint applyToIDEAProject
```

This will change Android Studio's code format configurations. The next time you apply an automatic code formatting on a kotlin file, it will use our new set of rules defined by ktlint.
To ensure code quality, the project utilizes [kotlinter](https://github.com/jeremymailen/kotlinter-gradle) for linting. The linting process is automatically triggered through commit and push hooks. However, you can also perform manual linting by running the commands `yarn lint` and `yarn lint-fix`.

For a seamless integration with Android Studio and to conveniently view and fix linting errors within the IDE, we highly recommend installing the [ktlint-intellij-plugin](https://plugins.jetbrains.com/plugin/15057-ktlint-unofficial-). This plugin allows you to directly display and handle linting errors from within Android Studio.

**Pro Tip:** use a hotkey to make Android Studio format your file for you. You can choose your hotkey on `File > Settings > Keymap > Main Menu > Code > Reformat Code & Reformat File`

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
},
"scripts": {
"test": "./gradlew test",
"lint": "./gradlew ktlintCheck",
"lint-fix": "./gradlew ktlintFormat",
"lint": "./gradlew lintKotlin",
"lint-fix": "./gradlew formatKotlin",
"pre-push": "run-p lint test",
"prepare": "husky install"
},
Expand Down

0 comments on commit 2f65e0a

Please sign in to comment.