diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..cd20d5dcf --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +root = true + +[*] +charset = utf-8 +trim_trailing_whitespace = true + +[*.{kt,kts}] +max_line_length = 9000 +ij_kotlin_allow_trailing_comma=true +ij_kotlin_allow_trailing_comma_on_call_site=true +ktlint_function_naming_ignore_when_annotated_with=Composable, Test + +[*.gradle] +indent_size = 4 \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e7ef182e0..399586771 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,7 +28,7 @@ jobs: ${{ runner.os }}-gradle- - name: Linter (gradle) - run: ./gradlew ktlintCheck + run: ./gradlew spotlessCheck - name: Test (gradle) run: ./gradlew test --no-daemon diff --git a/.gitignore b/.gitignore index 3805e0bf1..4c295cc9b 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ /.idea/androidTestResultsUserPreferences.xml /.idea/deploymentTargetDropDown.xml /.idea/appInsightsSettings.xml +/.idea/ktlint-plugin.xml .DS_Store /build /captures diff --git a/README.md b/README.md index d5831fe25..429514296 100644 --- a/README.md +++ b/README.md @@ -150,8 +150,8 @@ Build the app: ## Linting ```bash -./gradlew ktlintCheck -./gradlew ktlintFormat +./gradlew spotlessCheck +./gradlew spotlessApply ``` ## Installing on device diff --git a/app/build.gradle b/app/build.gradle index 861b44aec..daad43afb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,7 +1,6 @@ plugins { id 'com.android.application' id 'org.jetbrains.kotlin.android' - id 'org.jlleitschuh.gradle.ktlint' version "11.6.1" id 'com.google.gms.google-services' } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/ConnectivityType.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/ConnectivityType.kt deleted file mode 100644 index a41ebf3fc..000000000 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/ConnectivityType.kt +++ /dev/null @@ -1 +0,0 @@ -package com.vitorpamplona.amethyst.ui.note diff --git a/build.gradle b/build.gradle index 76b2c4b2e..f2fad81f3 100644 --- a/build.gradle +++ b/build.gradle @@ -26,16 +26,9 @@ plugins { id 'org.jetbrains.kotlin.jvm' version '1.9.10' apply false id 'org.jetbrains.kotlin.plugin.serialization' version '1.9.10' apply false id 'androidx.benchmark' version '1.1.1' apply false + id 'com.diffplug.spotless' version '6.22.0' apply false } -tasks.register('installGitHook', Copy) { - from new File(rootProject.rootDir, 'git-hooks/pre-commit') - from new File(rootProject.rootDir, 'git-hooks/pre-push') - into { new File(rootProject.rootDir, '.git/hooks') } - fileMode 0777 -} -tasks.getByPath(':app:preBuild').dependsOn installGitHook - subprojects { tasks.withType(KotlinCompile).configureEach { kotlinOptions { @@ -55,4 +48,35 @@ subprojects { } } } -} \ No newline at end of file + + apply plugin: 'com.diffplug.spotless' + spotless { + kotlin { + target '**/*.kt' + targetExclude("$buildDir/**/*.kt") + + ktlint("1.1.0") + ktfmt().googleStyle() + licenseHeaderFile rootProject.file('spotless/copyright.txt'), "package|import|class|object|sealed|open|interface|abstract " + } + + groovyGradle { + target '*.gradle' + } + + afterEvaluate { + tasks.named("preBuild") { + dependsOn("spotlessApply") + } + } + } +} + + +tasks.register('installGitHook', Copy) { + from new File(rootProject.rootDir, 'git-hooks/pre-commit') + from new File(rootProject.rootDir, 'git-hooks/pre-push') + into { new File(rootProject.rootDir, '.git/hooks') } + fileMode 0777 +} +tasks.getByPath(':app:preBuild').dependsOn installGitHook \ No newline at end of file diff --git a/git-hooks/pre-commit b/git-hooks/pre-commit index dd6636028..e02ca661a 100755 --- a/git-hooks/pre-commit +++ b/git-hooks/pre-commit @@ -12,7 +12,7 @@ echo "$JAVA_HOME" echo "$(java -version)" echo "Running test... " -./gradlew ktlintCheck +./gradlew spotlessCheck status=$? @@ -22,7 +22,7 @@ if [ "$status" = 0 ] ; then else echo "*********************************************************" echo 1>&2 "Static analysis found violations it could not fix." - printf "Run ${GREEN}./gradlew ktlintFormat${NO_COLOR} to fix formatting related issues...\n" + printf "Run ${GREEN}./gradlew spotlessApply${NO_COLOR} to fix formatting related issues...\n" echo "*********************************************************" exit 1 fi diff --git a/spotless/copyright.kt b/spotless/copyright.kt new file mode 100644 index 000000000..b1d2fa456 --- /dev/null +++ b/spotless/copyright.kt @@ -0,0 +1,7 @@ +Copyright (c) 2023 Vitor Pamplona + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file