-
Notifications
You must be signed in to change notification settings - Fork 99
Adding KTLint to the project to provide a uniform coding style #579
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
Conversation
All project modules whose build.gradle defines the ktlint plugin dependency are included when linting. The current implementation applies the ktlint plugin to all modules in the project from the root build.gradle. It is thus easy to disable linting (for development) by commenting out 1 line of code. Gradle tasks such as ktlintFormat, ktlintCheck are added. The standard set of rules (pinterest.github.io/ktlint/0.49.1/rules/standard/) are run with every lint. Signed-off-by: dritan-x <dritan.xhabija@gmail.com>
@@ -12,6 +24,11 @@ plugins { | |||
alias libs.plugins.org.jetbrains.kotlin.jvm apply false | |||
} | |||
|
|||
allprojects { | |||
// add ktlint to all modules | |||
// apply plugin: libs.plugins.ktlint.get().pluginId |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
disable ktlint by not applying it to any of the project's modules and thus prevent the creation of ktlint gradle tasks (that are all run during the building of the code).
When we're ready to proceed with finalizing the integration of ktlint, we will uncomment this 1 line and provide all the linting changes that come with it @davidz25
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. I was about to ask how this would work since the tests were failing b/c of linting problems..
@@ -126,6 +127,8 @@ | |||
|
|||
accompanist-permissions = { group = "com.google.accompanist", name = "accompanist-permissions", version.ref = "accompanist-permissions"} | |||
|
|||
ktlint-gradle = { module = "org.jlleitschuh.gradle:ktlint-gradle", version.ref = "ktlint" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a library definition instead of a plugin definiton. The library definition is used in root build.gradle
to give the root project the ktlint dependency.
While in the allprojects
snippet we apply the plugin definition of ktlint
@@ -151,3 +154,4 @@ | |||
parcelable = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" } | |||
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } | |||
org-jetbrains-kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "org-jetbrains-kotlin-jvm" } | |||
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plugin definiton of ktlint
@@ -12,6 +24,11 @@ plugins { | |||
alias libs.plugins.org.jetbrains.kotlin.jvm apply false | |||
} | |||
|
|||
allprojects { | |||
// add ktlint to all modules | |||
// apply plugin: libs.plugins.ktlint.get().pluginId |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. I was about to ask how this would work since the tests were failing b/c of linting problems..
#!/bin/bash | ||
|
||
echo "Running KTLint" | ||
./gradlew ktlintFormat |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this fail as long as apply plugin: libs.plugins.ktlint.get().pluginId
is commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct but this file has not been symbolically linked to the .git/hooks/
folder by running the other script .scripts/install-precommit-git-hook
- engineers would have to run this script manually once to add the ktlint hook to their git
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we probably want that hook installed automatically once we turn this on.
#!/bin/bash | ||
|
||
echo "Running KTLint" | ||
./gradlew ktlintFormat |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we probably want that hook installed automatically once we turn this on.
All project modules whose build.gradle defines the ktlint plugin dependency are included when linting. The current implementation applies the ktlint plugin to all modules in the project from the root build.gradle. It is thus easy to disable linting (for development) by commenting out 1 line of code.
Linting has been disabled because ktlint gradle tasks are created once a module is applied the ktlint plugin.
Gradle tasks such as ktlintFormat, ktlintCheck are added.
The standard set of rules (pinterest.github.io/ktlint/0.49.1/rules/standard/) are run with every lint.
See Android Code Linting.
This PR contains only build.gradle changes and no linting/auto-corrected changes. A future PR will bring those changes in.
This PR provides the scripts (in .scripts/) that adds a git pre-commit hook to run ktlint -- however this final integration will occur once all linting errors have been resolved (otherwise no one would be able to commit anything)
All unit tests pass. The wallet, reader, verifier apps run OK.