Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Correct ktlint #9

Merged
merged 2 commits into from
May 30, 2023
Merged
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
133 changes: 133 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = false
max_line_length = 100
tab_width = 4
ij_continuation_indent_size = 8
ij_formatter_off_tag = @formatter:off
ij_formatter_on_tag = @formatter:on
ij_formatter_tags_enabled = false
ij_smart_tabs = false
ij_visual_guides = none
ij_wrap_on_typing = false

[{*.kt,*.kts}]
ij_kotlin_align_in_columns_case_branch = false
ij_kotlin_align_multiline_binary_operation = false
ij_kotlin_align_multiline_extends_list = false
ij_kotlin_align_multiline_method_parentheses = false
ij_kotlin_align_multiline_parameters = true
ij_kotlin_align_multiline_parameters_in_calls = false
ij_kotlin_allow_trailing_comma = false
ij_kotlin_allow_trailing_comma_on_call_site = false
ij_kotlin_assignment_wrap = normal
ij_kotlin_blank_lines_after_class_header = 0
ij_kotlin_blank_lines_around_block_when_branches = 0
ij_kotlin_blank_lines_before_declaration_with_comment_or_annotation_on_separate_line = 1
ij_kotlin_block_comment_add_space = false
ij_kotlin_block_comment_at_first_column = true
ij_kotlin_call_parameters_new_line_after_left_paren = true
ij_kotlin_call_parameters_right_paren_on_new_line = true
ij_kotlin_call_parameters_wrap = on_every_item
ij_kotlin_catch_on_new_line = false
ij_kotlin_class_annotation_wrap = split_into_lines
ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL
ij_kotlin_continuation_indent_for_chained_calls = false
ij_kotlin_continuation_indent_for_expression_bodies = false
ij_kotlin_continuation_indent_in_argument_lists = false
ij_kotlin_continuation_indent_in_elvis = false
ij_kotlin_continuation_indent_in_if_conditions = false
ij_kotlin_continuation_indent_in_parameter_lists = false
ij_kotlin_continuation_indent_in_supertype_lists = false
ij_kotlin_else_on_new_line = false
ij_kotlin_enum_constants_wrap = off
ij_kotlin_extends_list_wrap = normal
ij_kotlin_field_annotation_wrap = split_into_lines
ij_kotlin_finally_on_new_line = false
ij_kotlin_if_rparen_on_new_line = true
ij_kotlin_import_nested_classes = false
ij_kotlin_imports_layout = *,java.**,javax.**,kotlin.**,^
ij_kotlin_insert_whitespaces_in_simple_one_line_method = true
ij_kotlin_keep_blank_lines_before_right_brace = 2
ij_kotlin_keep_blank_lines_in_code = 2
ij_kotlin_keep_blank_lines_in_declarations = 2
ij_kotlin_keep_first_column_comment = true
ij_kotlin_keep_indents_on_empty_lines = false
ij_kotlin_keep_line_breaks = true
ij_kotlin_lbrace_on_next_line = false
ij_kotlin_line_comment_add_space = false
ij_kotlin_line_comment_add_space_on_reformat = false
ij_kotlin_line_comment_at_first_column = true
ij_kotlin_method_annotation_wrap = split_into_lines
ij_kotlin_method_call_chain_wrap = normal
ij_kotlin_method_parameters_new_line_after_left_paren = true
ij_kotlin_method_parameters_right_paren_on_new_line = true
ij_kotlin_method_parameters_wrap = on_every_item
ij_kotlin_name_count_to_use_star_import = 5
ij_kotlin_name_count_to_use_star_import_for_members = 3
ij_kotlin_packages_to_use_import_on_demand = unset
ij_kotlin_parameter_annotation_wrap = off
ij_kotlin_space_after_comma = true
ij_kotlin_space_after_extend_colon = true
ij_kotlin_space_after_type_colon = true
ij_kotlin_space_before_catch_parentheses = true
ij_kotlin_space_before_comma = false
ij_kotlin_space_before_extend_colon = true
ij_kotlin_space_before_for_parentheses = true
ij_kotlin_space_before_if_parentheses = true
ij_kotlin_space_before_lambda_arrow = true
ij_kotlin_space_before_type_colon = false
ij_kotlin_space_before_when_parentheses = true
ij_kotlin_space_before_while_parentheses = true
ij_kotlin_spaces_around_additive_operators = true
ij_kotlin_spaces_around_assignment_operators = true
ij_kotlin_spaces_around_equality_operators = true
ij_kotlin_spaces_around_function_type_arrow = true
ij_kotlin_spaces_around_logical_operators = true
ij_kotlin_spaces_around_multiplicative_operators = true
ij_kotlin_spaces_around_range = false
ij_kotlin_spaces_around_relational_operators = true
ij_kotlin_spaces_around_unary_operator = false
ij_kotlin_spaces_around_when_arrow = true
ij_kotlin_use_custom_formatting_for_modifiers = true
ij_kotlin_variable_annotation_wrap = off
ij_kotlin_while_on_new_line = false
ij_kotlin_wrap_elvis_expressions = 1
ij_kotlin_wrap_expression_body_functions = 1
ij_kotlin_wrap_first_method_in_call_chain = false


# Copied from internal settings
[*.kt]
continuation_indent_size = 4
ktlint_standard_annotation = disabled # Annotations don't have to be on separate lines
ktlint_standard_annotation-spacing = disabled # It is ok with a comment between annotation and declaration
ktlint_standard_argument-list-wrapping = disabled # It is ok to have multiple args on one line
ktlint_standard_spacing-between-declarations-with-annotations = disabled # No need for empty line between these
ktlint_standard_spacing-between-declarations-with-comments = disabled # No need for empty line between these
ktlint_standard_trailing-comma-on-call-site = disabled # Trailing commas are ok
ktlint_standard_trailing-comma-on-declaration-site = disabled # Trailing commas are ok

# There is a bug in ktlint making multiline typealias indent in the wrong way:
# https://github.com/pinterest/ktlint/issues/1788 - enable this one this is fixed.
ktlint_standard_indent = disabled

ktlint_experimental_class-naming = enabled
ktlint_experimental_fun-keyword-spacing = enabled
ktlint_experimental_function-type-reference-spacing = enabled
ktlint_experimental_nullable-type-spacing = enabled
ktlint_experimental_spacing-between-function-name-and-opening-parenthesis = enabled
ktlint_experimental_unnecessary-parentheses-before-trailing-lambda = enabled

# Setting max line for Kotlin files, exactly as Detekt config (120 by default) to insure IDE and ktlint formatter
# format the code that is valid for Detekt, avoiding mismatch.
max_line_length=120

# Ignore max line for kotlin test files, the same as Detekt.
[**/{test,androidTest}/**/*.kt]
max_line_length=off
8 changes: 6 additions & 2 deletions OpenFeature/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
id("maven-publish")
id("org.jlleitschuh.gradle.ktlint")
kotlin("plugin.serialization") version "1.8.10"
}

Expand All @@ -19,7 +20,10 @@ android {
buildTypes {
getByName("release") {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
Expand Down Expand Up @@ -50,4 +54,4 @@ publishing {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ interface BaseEvaluation<T> {
val reason: String?
val errorCode: ErrorCode?
val errorMessage: String?
}
}
2 changes: 1 addition & 1 deletion OpenFeature/src/main/java/dev/openfeature/sdk/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ interface Client : Features {
val hooks: List<Hook<*>>

fun addHooks(hooks: List<Hook<*>>)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ interface EvaluationContext : Structure {
// Make sure these are implemented for correct object comparisons
override fun hashCode(): Int
override fun equals(other: Any?): Boolean
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ interface FeatureProvider {

// Called by OpenFeatureAPI whenever a new EvaluationContext is set by the application
suspend fun onContextSet(oldContext: EvaluationContext?, newContext: EvaluationContext)
fun getBooleanEvaluation(key: String, defaultValue: Boolean, context: EvaluationContext?): ProviderEvaluation<Boolean>
fun getBooleanEvaluation(
key: String,
defaultValue: Boolean,
context: EvaluationContext?
): ProviderEvaluation<Boolean>

fun getStringEvaluation(key: String, defaultValue: String, context: EvaluationContext?): ProviderEvaluation<String>
fun getIntegerEvaluation(key: String, defaultValue: Int, context: EvaluationContext?): ProviderEvaluation<Int>
fun getDoubleEvaluation(key: String, defaultValue: Double, context: EvaluationContext?): ProviderEvaluation<Double>
fun getObjectEvaluation(key: String, defaultValue: Value, context: EvaluationContext?): ProviderEvaluation<Value>
}
}
23 changes: 19 additions & 4 deletions OpenFeature/src/main/java/dev/openfeature/sdk/Features.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,36 @@ interface Features {
fun getBooleanValue(key: String, defaultValue: Boolean): Boolean
fun getBooleanValue(key: String, defaultValue: Boolean, options: FlagEvaluationOptions): Boolean
fun getBooleanDetails(key: String, defaultValue: Boolean): FlagEvaluationDetails<Boolean>
fun getBooleanDetails(key: String, defaultValue: Boolean, options: FlagEvaluationOptions): FlagEvaluationDetails<Boolean>
fun getBooleanDetails(
key: String,
defaultValue: Boolean,
options: FlagEvaluationOptions
): FlagEvaluationDetails<Boolean>

fun getStringValue(key: String, defaultValue: String): String
fun getStringValue(key: String, defaultValue: String, options: FlagEvaluationOptions): String
fun getStringDetails(key: String, defaultValue: String): FlagEvaluationDetails<String>
fun getStringDetails(key: String, defaultValue: String, options: FlagEvaluationOptions): FlagEvaluationDetails<String>
fun getStringDetails(
key: String,
defaultValue: String,
options: FlagEvaluationOptions
): FlagEvaluationDetails<String>

fun getIntegerValue(key: String, defaultValue: Int): Int
fun getIntegerValue(key: String, defaultValue: Int, options: FlagEvaluationOptions): Int
fun getIntegerDetails(key: String, defaultValue: Int): FlagEvaluationDetails<Int>
fun getIntegerDetails(key: String, defaultValue: Int, options: FlagEvaluationOptions): FlagEvaluationDetails<Int>
fun getDoubleValue(key: String, defaultValue: Double): Double
fun getDoubleValue(key: String, defaultValue: Double, options: FlagEvaluationOptions): Double
fun getDoubleDetails(key: String, defaultValue: Double): FlagEvaluationDetails<Double>
fun getDoubleDetails(key: String, defaultValue: Double, options: FlagEvaluationOptions): FlagEvaluationDetails<Double>
fun getDoubleDetails(
key: String,
defaultValue: Double,
options: FlagEvaluationOptions
): FlagEvaluationDetails<Double>

fun getObjectValue(key: String, defaultValue: Value): Value
fun getObjectValue(key: String, defaultValue: Value, options: FlagEvaluationOptions): Value
fun getObjectDetails(key: String, defaultValue: Value): FlagEvaluationDetails<Value>
fun getObjectDetails(key: String, defaultValue: Value, options: FlagEvaluationOptions): FlagEvaluationDetails<Value>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ data class FlagEvaluationDetails<T>(
companion object
}

fun <T> FlagEvaluationDetails.Companion.from(providerEval: ProviderEvaluation<T>, flagKey: String): FlagEvaluationDetails<T> {
fun <T> FlagEvaluationDetails.Companion.from(
providerEval: ProviderEvaluation<T>,
flagKey: String
): FlagEvaluationDetails<T> {
return FlagEvaluationDetails(
flagKey,
providerEval.value,
Expand All @@ -22,4 +25,4 @@ fun <T> FlagEvaluationDetails.Companion.from(providerEval: ProviderEvaluation<T>
providerEval.errorCode,
providerEval.errorMessage
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package dev.openfeature.sdk
data class FlagEvaluationOptions(
var hooks: List<Hook<*>> = listOf(),
var hookHints: Map<String, Any> = mapOf()
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ enum class FlagValueType {
INTEGER,
DOUBLE,
OBJECT;
}
}
2 changes: 1 addition & 1 deletion OpenFeature/src/main/java/dev/openfeature/sdk/Hook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ interface Hook<T> {
fun error(ctx: HookContext<T>, error: Exception, hints: Map<String, Any>) = Unit
fun finallyAfter(ctx: HookContext<T>, hints: Map<String, Any>) = Unit
fun supportsFlagValueType(flagValueType: FlagValueType): Boolean = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ data class HookContext<T>(
var ctx: EvaluationContext?,
var clientMetadata: Metadata?,
var providerMetadata: Metadata
)
)
39 changes: 33 additions & 6 deletions OpenFeature/src/main/java/dev/openfeature/sdk/HookSupport.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ package dev.openfeature.sdk

@Suppress("UNCHECKED_CAST") // TODO can we do better here?
class HookSupport {
fun <T> beforeHooks(flagValueType: FlagValueType, hookCtx: HookContext<T>, hooks: List<Hook<*>>, hints: Map<String, Any>) {
fun <T> beforeHooks(
flagValueType: FlagValueType,
hookCtx: HookContext<T>,
hooks: List<Hook<*>>,
hints: Map<String, Any>
) {
hooks
.reversed()
.filter { hook -> hook.supportsFlagValueType(flagValueType) }
Expand Down Expand Up @@ -37,7 +42,13 @@ class HookSupport {
}
}

fun <T> afterHooks(flagValueType: FlagValueType, hookCtx: HookContext<T>, details: FlagEvaluationDetails<T>, hooks: List<Hook<*>>, hints: Map<String, Any>) {
fun <T> afterHooks(
flagValueType: FlagValueType,
hookCtx: HookContext<T>,
details: FlagEvaluationDetails<T>,
hooks: List<Hook<*>>,
hints: Map<String, Any>
) {
hooks
.filter { hook -> hook.supportsFlagValueType(flagValueType) }
.forEach { hook ->
Expand Down Expand Up @@ -93,7 +104,12 @@ class HookSupport {
}
}

fun <T> afterAllHooks(flagValueType: FlagValueType, hookCtx: HookContext<T>, hooks: List<Hook<*>>, hints: Map<String, Any>) {
fun <T> afterAllHooks(
flagValueType: FlagValueType,
hookCtx: HookContext<T>,
hooks: List<Hook<*>>,
hints: Map<String, Any>
) {
hooks
.filter { hook -> hook.supportsFlagValueType(flagValueType) }
.forEach { hook ->
Expand Down Expand Up @@ -144,7 +160,13 @@ class HookSupport {
}
}

fun <T> errorHooks(flagValueType: FlagValueType, hookCtx: HookContext<T>, error: Exception, hooks: List<Hook<*>>, hints: Map<String, Any>) {
fun <T> errorHooks(
flagValueType: FlagValueType,
hookCtx: HookContext<T>,
error: Exception,
hooks: List<Hook<*>>,
hints: Map<String, Any>
) {
hooks
.filter { hook -> hook.supportsFlagValueType(flagValueType) }
.forEach { hook ->
Expand Down Expand Up @@ -199,7 +221,12 @@ class HookSupport {
return if (p1 != null && p2 != null) block(p1, p2) else null
}

private inline fun <T1 : Any, T2 : Any, T3 : Any, R : Any> safeLet(p1: T1?, p2: T2?, p3: T3?, block: (T1, T2, T3) -> R?): R? {
private inline fun <T1 : Any, T2 : Any, T3 : Any, R : Any> safeLet(
p1: T1?,
p2: T2?,
p3: T3?,
block: (T1, T2, T3) -> R?
): R? {
return if (p1 != null && p2 != null && p3 != null) block(p1, p2, p3) else null
}
}
}
2 changes: 1 addition & 1 deletion OpenFeature/src/main/java/dev/openfeature/sdk/Metadata.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package dev.openfeature.sdk

interface Metadata {
val name: String?
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ class MutableContext

return true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ class MutableStructure(private var attributes: MutableMap<String, Value> = mutab

return true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ class NoOpProvider : FeatureProvider {
}

data class NoOpMetadata(override var name: String?) : Metadata
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ object OpenFeatureAPI {
fun clearHooks() {
this.hooks = listOf()
}
}
}
Loading