Skip to content

Commit

Permalink
🔧 Updated the configuration for Ktlint and Detekt
Browse files Browse the repository at this point in the history
  • Loading branch information
vegidio committed Sep 26, 2024
1 parent 8420ec9 commit 6b557e4
Show file tree
Hide file tree
Showing 23 changed files with 140 additions and 138 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ ij_kotlin_name_count_to_use_star_import = 999
ij_kotlin_packages_to_use_import_on_demand = unset
ij_visual_guides = none

# Ktlint
ktlint_code_style = intellij_idea
ktlint_function_naming_ignore_when_annotated_with = Composable

[*.yml]
indent_size = 2
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
alias(libs.plugins.android.app) apply false
alias(libs.plugins.android.lib) apply false
alias(libs.plugins.kotlin) apply false
alias(libs.plugins.compose.compiler) apply false
alias(libs.plugins.detekt)
alias(libs.plugins.ktlint)
}
Expand All @@ -12,10 +13,6 @@ detekt {
source.setFrom(
"$rootDir/network/src/main/kotlin",
"$rootDir/util/src/main/kotlin",
"$rootDir/view/src/main/kotlin"
"$rootDir/view/src/main/kotlin",
)
}

ktlint {
android.set(true)
}
46 changes: 22 additions & 24 deletions config/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ build:
maxIssues: 0
excludeCorrectable: false
weights:
# complexity: 2
# LongParameterList: 1
# style: 1
# comments: 1
# complexity: 2
# LongParameterList: 1
# style: 1
# comments: 1

config:
validation: true
Expand Down Expand Up @@ -34,11 +34,11 @@ processors:
console-reports:
active: true
exclude:
- 'ProjectStatisticsReport'
- 'ComplexityReport'
- 'NotificationReport'
- 'FindingsReport'
- 'FileBasedFindingsReport'
- 'ProjectStatisticsReport'
- 'ComplexityReport'
- 'NotificationReport'
- 'FindingsReport'
- 'FileBasedFindingsReport'
# - 'LiteFindingsReport'

output-reports:
Expand Down Expand Up @@ -305,7 +305,6 @@ naming:
BooleanPropertyNaming:
active: true
allowedPattern: '^(is|has|are)'
ignoreOverridden: true
ClassNaming:
active: true
classPattern: '[A-Z][a-zA-Z0-9]*'
Expand All @@ -314,7 +313,6 @@ naming:
parameterPattern: '[a-z][A-Za-z0-9]*'
privateParameterPattern: '[a-z][A-Za-z0-9]*'
excludeClassPattern: '$^'
ignoreOverridden: true
EnumNaming:
active: true
enumEntryPattern: '[A-Z][_a-zA-Z0-9]*'
Expand All @@ -324,6 +322,7 @@ naming:
FunctionMaxLength:
active: true
maximumFunctionNameLength: 30
excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/androidUnitTest/**', '**/androidInstrumentedTest/**', '**/jsTest/**', '**/iosTest/**']
FunctionMinLength:
active: true
minimumFunctionNameLength: 3
Expand All @@ -333,12 +332,10 @@ naming:
functionPattern: '[a-zA-Z][a-zA-Z0-9]*'
excludeClassPattern: '$^'
ignoreAnnotated: ['Composable']
ignoreOverridden: true
FunctionParameterNaming:
active: true
parameterPattern: '[a-z][A-Za-z0-9]*'
excludeClassPattern: '$^'
ignoreOverridden: true
InvalidPackageDeclaration:
active: true
rootPackage: ''
Expand Down Expand Up @@ -366,7 +363,7 @@ naming:
packagePattern: '[a-z]+(\.[a-z][A-Za-z0-9]*)*'
TopLevelPropertyNaming:
active: true
constantPattern: '[A-Z][A-Za-z0-9]*'
constantPattern: '[A-Z][_A-Z0-9]*'
propertyPattern: '[A-Za-z][_A-Za-z0-9]*'
privatePropertyPattern: '_?[A-Za-z][_A-Za-z0-9]*'
VariableMaxLength:
Expand All @@ -380,7 +377,6 @@ naming:
variablePattern: '[a-z][A-Za-z0-9]*'
privateVariablePattern: '(_)?[a-z][A-Za-z0-9]*'
excludeClassPattern: '$^'
ignoreOverridden: true

performance:
active: true
Expand Down Expand Up @@ -531,12 +527,10 @@ style:
includeLineWrapping: false
ForbiddenComment:
active: true
values:
- 'FIXME:'
- 'STOPSHIP:'
- 'TODO:'
comments:
- reason: 'Forbidden FIXME todo marker in comment; please fix the problem.'
value: 'FIXME:'
allowedPatterns: ''
customMessage: ''
ForbiddenImport:
active: false
imports: []
Expand Down Expand Up @@ -573,16 +567,18 @@ style:
- '2'
ignoreHashCodeFunction: true
ignorePropertyDeclaration: true
ignoreLocalVariableDeclaration: false
ignoreLocalVariableDeclaration: true
ignoreConstantDeclaration: true
ignoreCompanionObjectPropertyDeclaration: true
ignoreAnnotation: false
ignoreNamedArgument: true
ignoreEnums: false
ignoreRanges: false
ignoreExtensionFunctions: true
MandatoryBracesIfStatements:
BracesOnIfStatements:
active: false
singleLine: 'necessary'
multiLine: 'necessary'
MandatoryBracesLoops:
active: true
MaxChainedCallsOnSameLine:
Expand Down Expand Up @@ -618,8 +614,10 @@ style:
active: true
OptionalUnit:
active: true
OptionalWhenBraces:
active: false
BracesOnWhenStatements:
active: true
singleLine: 'necessary'
multiLine: 'necessary'
PreferToOverPairSyntax:
active: true
ProtectedMemberInFinalClass:
Expand Down
70 changes: 36 additions & 34 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,50 +1,52 @@
[versions]
android = "8.2.1"
apollo = "3.8.2"
compose-material3 = "1.1.2"
compose-ui = "1.5.4"
android = "8.2.2"
apollo = "3.8.5"
compose = "1.7.2"
compose-material3 = "1.3.0"
constraintlayout = "1.0.1"
core-ktx = "1.12.0"
coroutines = "1.7.3"
core-ktx = "1.13.1"
coroutines = "1.8.1"
detekt = "1.23.4"
junit = "4.13.2"
kotlin = "1.9.21"
kotlin = "2.0.20"
ktlint = "12.0.3"
lottie = "6.3.0"
material-icons = "1.5.4"
moshi = "1.14.0"
lottie = "6.5.2"
material-icons = "1.7.2"
moshi = "1.15.1"
okhttp = "4.12.0"
retrofit = "2.9.0"
test-espresso = "3.5.1"
test-ext = "1.1.5"
retrofit = "2.11.0"
test-espresso = "3.6.1"
test-ext = "1.2.1"
usb-serial = "3.5.1"

[plugins]
android-app = { id = "com.android.application", version.ref = "android" }
android-lib = { id = "com.android.library", version.ref = "android" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
kotlin = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint" }

[libraries]
apollo-runtime = { group = "com.apollographql.apollo3", name = "apollo-runtime", version.ref = "apollo" }
compose-material3 = { group = "androidx.compose.material3", name = "material3", version.ref = "compose-material3" }
compose-ui = { group = "androidx.compose.ui", name = "ui", version.ref = "compose-ui" }
compose-ui-test = { group = "androidx.compose.ui", name = "ui-test-manifest", version.ref = "compose-ui" }
compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling", version.ref = "compose-ui" }
compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview", version.ref = "compose-ui" }
constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout-compose", version.ref = "constraintlayout" }
core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "core-ktx" }
coroutines-android = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-android", version.ref = "coroutines" }
coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "coroutines" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
lottie = { group = "com.airbnb.android", name = "lottie-compose", version.ref = "lottie" }
material-icons = { group = "androidx.compose.material", name = "material-icons-extended", version.ref = "material-icons" }
moshi = { group = "com.squareup.moshi", name = "moshi-kotlin", version.ref = "moshi" }
okhttp = { group = "com.squareup.okhttp3", name = "okhttp", version.ref = "okhttp" }
okhttp-logging = { group = "com.squareup.okhttp3", name = "logging-interceptor", version.ref = "okhttp" }
retrofit = { group = "com.squareup.retrofit2", name = "retrofit", version.ref = "retrofit" }
retrofit-moshi = { group = "com.squareup.retrofit2", name = "converter-moshi", version.ref = "retrofit" }
test-espresso = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "test-espresso" }
test-ext = { group = "androidx.test.ext", name = "junit", version.ref = "test-ext" }
usb-serial = { group = "com.github.mik3y", name = "usb-serial-for-android", version.ref = "usb-serial" }
apollo-runtime = { module = "com.apollographql.apollo3:apollo-runtime", version.ref = "apollo" }
compose-material3 = { module = "androidx.compose.material3:material3", version.ref = "compose-material3" }
compose-runtime = { module = "androidx.compose.runtime:runtime", version.ref = "compose" }
compose-ui = { module = "androidx.compose.ui:ui", version.ref = "compose" }
compose-ui-test = { module = "androidx.compose.ui:ui-test-manifest", version.ref = "compose" }
compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose" }
compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "compose" }
constraintlayout = { module = "androidx.constraintlayout:constraintlayout-compose", version.ref = "constraintlayout" }
core-ktx = { module = "androidx.core:core-ktx", version.ref = "core-ktx" }
coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "coroutines" }
coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
junit = { module = "junit:junit", version.ref = "junit" }
lottie = { module = "com.airbnb.android:lottie-compose", version.ref = "lottie" }
material-icons = { module = "androidx.compose.material:material-icons-extended", version.ref = "material-icons" }
moshi = { module = "com.squareup.moshi:moshi-kotlin", version.ref = "moshi" }
okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
okhttp-logging = { module = "com.squareup.okhttp3:logging-interceptor", version.ref = "okhttp" }
retrofit = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit" }
retrofit-moshi = { module = "com.squareup.retrofit2:converter-moshi", version.ref = "retrofit" }
test-espresso = { module = "androidx.test.espresso:espresso-core", version.ref = "test-espresso" }
test-ext = { module = "androidx.test.ext:junit", version.ref = "test-ext" }
usb-serial = { module = "com.github.mik3y:usb-serial-for-android", version.ref = "usb-serial" }
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import kotlin.reflect.KClass
@OptIn(ExperimentalCoroutinesApi::class)
open class GraphqlFactory(url: String, vararg val types: KClass<*>) {
@PublishedApi internal val moshi = Moshi.Builder().build()

@PublishedApi internal val headerInterceptor = GraphqlHeaderInterceptor()

@PublishedApi internal val client = ApolloClient.Builder()
.serverUrl(url)
.addInterceptor(headerInterceptor)
Expand All @@ -27,10 +29,7 @@ open class GraphqlFactory(url: String, vararg val types: KClass<*>) {
get() = headerInterceptor.headers
set(value) = headerInterceptor.headers.putAll(value)

inline fun <reified T> sendQuery(
query: Query<*>,
headers: Map<String, String> = emptyMap()
): Flow<T> {
inline fun <reified T> sendQuery(query: Query<*>, headers: Map<String, String> = emptyMap()): Flow<T> {
val name = query.name()
headerInterceptor.requestHeaders[name] = headers

Expand All @@ -42,10 +41,7 @@ open class GraphqlFactory(url: String, vararg val types: KClass<*>) {
}
}

inline fun <reified T> sendMutation(
mutation: Mutation<*>,
headers: Map<String, String> = emptyMap()
): Flow<T> {
inline fun <reified T> sendMutation(mutation: Mutation<*>, headers: Map<String, String> = emptyMap()): Flow<T> {
val name = mutation.name()
headerInterceptor.requestHeaders[name] = headers

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal class GraphqlHeaderInterceptor : ApolloInterceptor {

override fun <D : Operation.Data> intercept(
request: ApolloRequest<D>,
chain: ApolloInterceptorChain
chain: ApolloInterceptorChain,
): Flow<ApolloResponse<D>> {
val name = request.operation.name()
val headerList = headers.map { (key, value) -> HttpHeader(key, value) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import retrofit2.http.Path
class CountriesService : RestFactory<CountriesContract>(
klass = CountriesContract::class,
baseUrl = "https://restcountries.com/v3.1/",
logHandler = LogHandler({ println(it) }, "BODY")
logHandler = LogHandler({ println(it) }, "BODY"),
) {
fun findByCode(code: String) = api.findByCode(code)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import com.squareup.moshi.JsonClass
@JsonClass(generateAdapter = true)
data class Country(
val region: String,
val population: Int
val population: Int,
)
4 changes: 2 additions & 2 deletions util/src/main/kotlin/io/vinicius/sak/util/PrivateFlow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ sealed class PrivateSharedFlow<T>(flow: SharedFlow<T>) : SharedFlow<T> by flow

private class PrivateStateFlowImpl<T>(
initial: T,
val wrapped: MutableStateFlow<T> = MutableStateFlow(initial)
val wrapped: MutableStateFlow<T> = MutableStateFlow(initial),
) : PrivateStateFlow<T>(wrapped)

private class PrivateSharedFlowImpl<T>(
replay: Int,
extraBufferCapacity: Int,
onBufferOverflow: BufferOverflow,
val wrapped: MutableSharedFlow<T> = MutableSharedFlow(replay, extraBufferCapacity, onBufferOverflow)
val wrapped: MutableSharedFlow<T> = MutableSharedFlow(replay, extraBufferCapacity, onBufferOverflow),
) : PrivateSharedFlow<T>(wrapped)

interface PrivateFlow {
Expand Down
4 changes: 2 additions & 2 deletions util/src/main/kotlin/io/vinicius/sak/util/UsbHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ class UsbHelper(
object : BroadcastReceiver() {
override fun onReceive(ctx: Context?, intent: Intent?) {
hasPermission.mutable = intent?.action == usbPermissionAction &&
intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)
intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)
}
},
IntentFilter(usbPermissionAction),
ContextCompat.RECEIVER_NOT_EXPORTED
ContextCompat.RECEIVER_NOT_EXPORTED,
)
}
}
2 changes: 2 additions & 0 deletions view/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.jetbrains.kotlin.config.JvmTarget
plugins {
alias(libs.plugins.android.lib)
alias(libs.plugins.kotlin)
alias(libs.plugins.compose.compiler)
`maven-publish`

// We must have the next plugins in all subprojects that need Ktlint
Expand Down Expand Up @@ -52,6 +53,7 @@ dependencies {
api(libs.lottie)

implementation(libs.compose.material3)
implementation(libs.compose.runtime)
implementation(libs.compose.ui)
implementation(libs.compose.ui.tooling.preview)
implementation(libs.core.ktx)
Expand Down
Loading

0 comments on commit 6b557e4

Please sign in to comment.