Skip to content

Adding KtLint #77

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# .editorconfig
root = true

[*.{kt,kts}]
end_of_line = lf
ij_kotlin_packages_to_use_import_on_demand = true
ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = true
ij_kotlin_imports_layout = *
ij_kotlin_indent_before_arrow_on_new_line = false
ij_kotlin_line_break_after_multiline_when_entry = true
indent_size = 4
indent_style = space
insert_final_newline = true
ktlint_argument_list_wrapping_ignore_when_parameter_count_greater_or_equal_than = 8
ktlint_chain_method_rule_force_multiline_when_chain_operator_count_greater_or_equal_than = 4
ktlint_code_style = android_studio
ktlint_enum_entry_name_casing = upper_or_camel_cases
ktlint_function_naming_ignore_when_annotated_with = Composable
ktlint_function_signature_body_expression_wrapping = default
ktlint_ignore_back_ticked_identifier = false
max_line_length = 140
parameter-list-wrapping = true
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ jobs:
- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1
- name: Cache gradle
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Cache konan
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ~/.konan
key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Build
run: ./gradlew build --no-daemon --stacktrace
run: ./gradlew ktlintCheck build --no-daemon --stacktrace

env:
GRADLE_OPTS: -Dkotlin.incremental=false -Dorg.gradle.jvmargs="-Xmx4g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:MaxMetaspaceSize=512m"
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ jobs:
uses: gradle/wrapper-validation-action@v1

- name: Cache gradle
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }}
restore-keys: |
${{ runner.os }}-gradle-

- name: Cache konan
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ~/.konan
key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ jobs:
- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1
- name: Cache gradle
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }}
restore-keys: |
${{ runner.os }}-gradle-

- name: Cache konan
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ~/.konan
key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }}
Expand Down
5 changes: 4 additions & 1 deletion bugsnag-ios-link/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ java {
}
}

@Suppress("ktlint:standard:property-naming")
val GROUP: String by project

@Suppress("ktlint:standard:property-naming")
val VERSION_NAME: String by project

group = GROUP
Expand All @@ -63,4 +66,4 @@ mavenPublishing {
project.properties["RELEASE_SIGNING_ENABLED"]?.toString()?.equals("false", ignoreCase = true) != true
if (releaseSigningEnabled) signAllPublications()
pomFromGradleProperties()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ internal val Project.kotlinExtension: KotlinMultiplatformExtension get() = exten
@Suppress("unused")
class BugsnagLinkPlugin : Plugin<Project> {
override fun apply(project: Project): Unit = project.withKotlinMultiplatformPlugin {
val linkerArgs = "-U _OBJC_CLASS_\$_BugsnagHandledState " +
val linkerArgs =
"-U _OBJC_CLASS_\$_BugsnagHandledState " +
"-U _OBJC_CLASS_\$_Bugsnag " +
"-U _OBJC_CLASS_\$_BugsnagStackframe " +
"-U _OBJC_CLASS_\$_FIRStackFrame " +
Expand Down
14 changes: 11 additions & 3 deletions bugsnag/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ plugins {
id("com.vanniktech.maven.publish")
}

@Suppress("ktlint:standard:property-naming")
val GROUP: String by project

@Suppress("ktlint:standard:property-naming")
val VERSION_NAME: String by project

group = GROUP
Expand Down Expand Up @@ -88,15 +91,20 @@ kotlin {

android {
namespace = "co.touchlab.crashkios.bugsnag"
compileSdk = libs.versions.compileSdk.get().toInt()
compileSdk =
libs.versions.compileSdk
.get()
.toInt()
defaultConfig {
minSdk = libs.versions.minSdk.get().toInt()
minSdk =
libs.versions.minSdk
.get()
.toInt()
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

}

tasks.withType<KotlinCompile> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ actual class BugsnagCallsActual : BugsnagCalls {
override fun setCustomValue(section: String, key: String, value: Any) {
Bugsnag.addMetadata(section, key, value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import kotlinx.cinterop.ExperimentalForeignApi

@OptIn(ExperimentalForeignApi::class)
actual class BugsnagCallsActual : BugsnagCalls {

override fun logMessage(message: String) {
Bugsnag.leaveBreadcrumbWithMessage(message)
}
Expand Down Expand Up @@ -45,4 +44,4 @@ actual class BugsnagCallsActual : BugsnagCalls {
true
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.rickclephas.kmp.nsexceptionkt.core.wrapUnhandledExceptionHook
import kotlinx.cinterop.ExperimentalForeignApi
import platform.Foundation.NSException

public fun startBugsnag(config: BugsnagConfiguration){
public fun startBugsnag(config: BugsnagConfiguration) {
configureBugsnag(config)
Bugsnag.startWithConfiguration(config)
setBugsnagUnhandledExceptionHook()
Expand Down Expand Up @@ -53,6 +53,7 @@ public fun setBugsnagUnhandledExceptionHook(): Unit = wrapUnhandledExceptionHook
/**
* Feature flag used to mark the Kotlin termination crash.
*/
@Suppress("ktlint:standard:property-naming")
private const val kotlinCrashedFeatureFlag = "crashkios.kotlin_crashed"

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package co.touchlab.crashkios.bugsnag

interface BugsnagCalls {
fun logMessage(message: String)

fun sendHandledException(throwable: Throwable)

fun sendFatalException(throwable: Throwable)

fun setCustomValue(section: String, key: String, value: Any)
}

expect class BugsnagCallsActual() : BugsnagCalls
expect class BugsnagCallsActual() : BugsnagCalls
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,20 @@ object BugsnagKotlin {
* Call in startup code in an actual app. Tests should generally skip this. In Kotlin/Native, not calling this
* for tests avoids linker issues.
*/
fun enableBugsnag(){
fun enableBugsnag() {
BugsnagKotlin.implementation = BugsnagCallsActual()
}

internal object EmptyCalls : BugsnagCalls {
override fun logMessage(message: String) {

}

override fun sendHandledException(throwable: Throwable) {

}

override fun sendFatalException(throwable: Throwable) {

}

override fun setCustomValue(section: String, key: String, value: Any) {

}
}
}
20 changes: 20 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,31 @@ plugins {
alias(libs.plugins.android.library) apply false
alias(libs.plugins.touchlab.docusaurus.template)
alias(libs.plugins.gradle.publish) apply false
id("org.jlleitschuh.gradle.ktlint") version "12.2.0" apply false
}

allprojects {
repositories {
mavenCentral()
google()
}
}

subprojects {
apply(plugin = "org.jlleitschuh.gradle.ktlint")

configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
version.set("1.4.0")
enableExperimentalRules.set(true)
verbose.set(true)
filter {
exclude { it.file.path.contains("build/") }
}
}

afterEvaluate {
tasks.named("check") {
dependsOn(tasks.getByName("ktlintCheck"))
}
}
}
13 changes: 11 additions & 2 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ plugins {
kotlin("multiplatform")
}

@Suppress("ktlint:standard:property-naming")
val GROUP: String by project

@Suppress("ktlint:standard:property-naming")
val VERSION_NAME: String by project

group = GROUP
Expand Down Expand Up @@ -60,9 +63,15 @@ kotlin {

android {
namespace = "co.touchlab.crashkios.core"
compileSdk = libs.versions.compileSdk.get().toInt()
compileSdk =
libs.versions.compileSdk
.get()
.toInt()
defaultConfig {
minSdk = libs.versions.minSdk.get().toInt()
minSdk =
libs.versions.minSdk
.get()
.toInt()
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import kotlin.reflect.KProperty

actual class ThreadSafeVar<T> actual constructor(@Volatile private var target: T) {
actual operator fun getValue(thisRef: Any?, property: KProperty<*>): T = target

actual operator fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
target = value
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package co.touchlab.crashkios.core

import kotlin.experimental.ExperimentalNativeApi
import kotlin.concurrent.AtomicReference
import kotlin.experimental.ExperimentalNativeApi
import kotlin.native.concurrent.freeze
import kotlin.reflect.KProperty

@OptIn(FreezingIsDeprecated::class, ExperimentalNativeApi::class)
actual class ThreadSafeVar<T> actual constructor(target: T) {
private val atom = AtomicReference(target)

actual operator fun getValue(thisRef: Any?, property: KProperty<*>): T = atom.value

actual operator fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
if (Platform.memoryModel == MemoryModel.STRICT) {
value.freeze()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package co.touchlab.crashkios.core

import kotlin.reflect.KProperty

expect class ThreadSafeVar<T>(target:T) {
expect class ThreadSafeVar<T>(target: T) {
operator fun getValue(thisRef: Any?, property: KProperty<*>): T

operator fun setValue(thisRef: Any?, property: KProperty<*>, value: T)
}
5 changes: 4 additions & 1 deletion crashlytics-ios-link/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ java {
}
}

@Suppress("ktlint:standard:property-naming")
val GROUP: String by project

@Suppress("ktlint:standard:property-naming")
val VERSION_NAME: String by project

group = GROUP
Expand All @@ -62,4 +65,4 @@ mavenPublishing {
project.properties["RELEASE_SIGNING_ENABLED"]?.toString()?.equals("false", ignoreCase = true) != true
if (releaseSigningEnabled) signAllPublications()
pomFromGradleProperties()
}
}
17 changes: 13 additions & 4 deletions crashlytics/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ plugins {
id("com.vanniktech.maven.publish")
}

@Suppress("ktlint:standard:property-naming")
val GROUP: String by project

@Suppress("ktlint:standard:property-naming")
val VERSION_NAME: String by project

group = GROUP
Expand Down Expand Up @@ -49,7 +52,7 @@ kotlin {
tvosArm64()
tvosSimulatorArm64()
tvosX64()

sourceSets {
commonMain {
dependencies {
Expand Down Expand Up @@ -80,15 +83,21 @@ kotlin {
compilerOpts("-DNS_FORMAT_ARGUMENT(A)=", "-D_Nullable_result=_Nullable")
// extraOpts("-mode", "sourcecode")
}
}
}
}
}

android {
namespace = "co.touchlab.crashkios.crashlytics"
compileSdk = libs.versions.compileSdk.get().toInt()
compileSdk =
libs.versions.compileSdk
.get()
.toInt()
defaultConfig {
minSdk = libs.versions.minSdk.get().toInt()
minSdk =
libs.versions.minSdk
.get()
.toInt()
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
Expand Down
Loading