Roberto Leinardi
03/19/2023, 5:45 PMRoberto Leinardi
03/19/2023, 5:47 PMpublic enum class TransformCategory(
public val nativeValue: GskTransformCategory,
) {
UNKNOWN(GSK_TRANSFORM_CATEGORY_UNKNOWN),
ANY(GSK_TRANSFORM_CATEGORY_ANY),
`3D`(GSK_TRANSFORM_CATEGORY_3D),
`2D`(GSK_TRANSFORM_CATEGORY_2D),
`2D_AFFINE`(GSK_TRANSFORM_CATEGORY_2D_AFFINE),
`2D_TRANSLATE`(GSK_TRANSFORM_CATEGORY_2D_TRANSLATE),
IDENTITY(GSK_TRANSFORM_CATEGORY_IDENTITY),
;
}
The backticks are there because this code is generating some bindings for a C library. The generation is automated via GObject introspection so we can't easily avoid backticks.Paul Dingemans
03/19/2023, 8:07 PM@Suppress("ktlint:enum-entry-name-case")
public enum class TransformCategory(
public val nativeValue: GskTransformCategory,
) {
UNKNOWN(GSK_TRANSFORM_CATEGORY_UNKNOWN),
ANY(GSK_TRANSFORM_CATEGORY_ANY),
`3D`(GSK_TRANSFORM_CATEGORY_3D),
`2D`(GSK_TRANSFORM_CATEGORY_2D),
`2D_AFFINE`(GSK_TRANSFORM_CATEGORY_2D_AFFINE),
`2D_TRANSLATE`(GSK_TRANSFORM_CATEGORY_2D_TRANSLATE),
IDENTITY(GSK_TRANSFORM_CATEGORY_IDENTITY),
;
}
Roberto Leinardi
03/19/2023, 8:26 PMktlint_standard_enum-entry-name-case = disabled
Paul Dingemans
03/19/2023, 8:44 PMephemient
03/19/2023, 9:17 PMRoberto Leinardi
03/19/2023, 9:35 PMephemient
03/19/2023, 9:40 PMephemient
03/19/2023, 9:42 PMval ruleProviders = buildSet {
ServiceLoader.load(RuleSetProviderV2::class.java).flatMapTo(this) { it.getRuleProviders() }
}
val ktLintRuleEngine = KtLintRuleEngine(ruleProviders = ruleProviders)
for (file in files) {
file.writeText(ktLintRuleEngine.format(file.toPath()))
}
Roberto Leinardi
03/19/2023, 9:47 PMRoberto Leinardi
03/19/2023, 9:47 PMPaul Dingemans
03/20/2023, 4:33 PMktlintRuleEngine
to format the generated code, then you can disable the rule via the editorConfigOverride parameter instead of disabling the rule in the .editorconfig
of the project. The advantage would be that the rule is kept enabled for non-generated code.Roberto Leinardi
03/20/2023, 5:27 PMktlintRuleEngine
. Is there some documentation that I can look at? The best would be a link to some open source project that is already doing it.Paul Dingemans
03/20/2023, 5:38 PM0.48.2
branch. This is refactored in the upcoming release, but that won’t be difficult to change.Roberto Leinardi
03/20/2023, 5:45 PMRoberto Leinardi
03/20/2023, 7:04 PMKtLintRuleEngine
?
I've tried with these but still can't find it:
ktlint = { module = "com.pinterest:ktlint", version.ref = "ktlint" }
ktlint-core = { module = "com.pinterest:ktlint-core", version.ref = "ktlint" }
ktlint-api-consumer = { module = "com.pinterest:ktlint-api-consumer", version.ref = "ktlint" }
ktlint-ruleset-standard = { module = "com.pinterest:ktlint-ruleset-standard", version.ref = "ktlint" }
Paul Dingemans
03/20/2023, 7:05 PMRoberto Leinardi
03/20/2023, 7:07 PM0.48.2
Roberto Leinardi
03/20/2023, 7:13 PMcom.pinterest.ktlint:ktlint-core
vs com.pinterest:ktlint
Paul Dingemans
03/20/2023, 7:14 PMephemient
03/20/2023, 7:17 PMephemient
03/20/2023, 7:19 PMPaul Dingemans
03/20/2023, 7:19 PMPaul Dingemans
03/20/2023, 7:20 PM<!-- keeping original (pre 0.2.0) qualifier (com.github.shyiko:ktlint) so that no one would notice a thing -->
<groupId>com.github.shyiko</groupId>
<artifactId>ktlint</artifactId>
in https://central.sonatype.com/artifact/com.github.shyiko/ktlint/0.31.0Roberto Leinardi
03/20/2023, 7:35 PM20:32:51.072 [main] DEBUG com.pinterest.ktlint.core.internal.RuleExecutionContext - Editor config properties for file '/home/leinardi/Workspace/gitlab/gtk-kn/bindings/core/gio/src/nativeMain/kotlin/bindings/gio/ThemedIcon.kt': {charset=charset = utf-8, indent_style=indent_style = space, insert_final_newline=insert_final_newline = true, max_line_length=max_line_length = 120, trim_trailing_whitespace=trim_trailing_whitespace = true, ij_continuation_indent_size=ij_continuation_indent_size = 4, ij_formatter_off_tag=ij_formatter_off_tag = @formatter:off, ij_formatter_on_tag=ij_formatter_on_tag = @formatter:on, ij_formatter_tags_enabled=ij_formatter_tags_enabled = true, ij_smart_tabs=ij_smart_tabs = false, ij_visual_guides=ij_visual_guides = 80, 100, 120, ij_wrap_on_typing=ij_wrap_on_typing = false, indent_size=indent_size = 4, tab_width=tab_width = 4, ktlint_standard_enum-entry-name-case=ktlint_standard_enum-entry-name-case = disabled, ij_kotlin_align_in_columns_case_branch=ij_kotlin_align_in_columns_case_branch = false, ij_kotlin_align_multiline_binary_operation=ij_kotlin_align_multiline_binary_operation = false, ij_kotlin_align_multiline_extends_list=ij_kotlin_align_multiline_extends_list = false, ij_kotlin_align_multiline_method_parentheses=ij_kotlin_align_multiline_method_parentheses = false, ij_kotlin_align_multiline_parameters=ij_kotlin_align_multiline_parameters = false, ij_kotlin_align_multiline_parameters_in_calls=ij_kotlin_align_multiline_parameters_in_calls = false, ij_kotlin_allow_trailing_comma=ij_kotlin_allow_trailing_comma = true,
[...]
Paul Dingemans
03/20/2023, 7:40 PM/**
* Set the [defaultLoggerModifier]. Note that it can only be set once. It should be set before the first invocation to
* [initKtLintKLogger].
*/
public fun KLogger.setDefaultLoggerModifier(loggerModifier: (KLogger) -> Unit): KLogger {
and
/**
* Initializes the logger with the [defaultLoggerModifier].
*/
public fun KLogger.initKtLintKLogger(): KLogger {
Paul Dingemans
03/20/2023, 7:56 PMRoberto Leinardi
03/20/2023, 8:03 PMkotlin-logger
and I'm using log4j2
instead of logback
...Roberto Leinardi
03/20/2023, 8:04 PMKotlinLogging
.logger {}
.setDefaultLoggerModifier { logger ->
(logger.underlyingLogger as Logger).level = Level.OFF
}
Roberto Leinardi
03/20/2023, 8:05 PMRoberto Leinardi
03/20/2023, 8:06 PMPaul Dingemans
03/20/2023, 8:08 PMPaul Dingemans
03/20/2023, 8:08 PMRoberto Leinardi
03/20/2023, 8:08 PMimport io.github.oshai.KLogger
import io.github.oshai.KotlinLogging
import org.apache.logging.log4j.Level
import org.apache.logging.log4j.core.appender.ConsoleAppender
import org.apache.logging.log4j.core.config.Configurator
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory
val logger: KLogger by lazy { KotlinLogging.logger("gir") }
private const val LOG4J_PATTERN = "%highlight{%-5level: [%c] %msg%n%throwable}" +
"{FATAL=bright_red, ERROR=bright_red, WARN=bright_yellow, INFO=bright_green, DEBUG=bright_white, TRACE=white}"
fun configureLog4j(level: io.github.oshai.Level) {
val builder = ConfigurationBuilderFactory.newConfigurationBuilder()
val console = builder
.newAppender("Stdout", "CONSOLE")
.addAttribute("target", ConsoleAppender.Target.SYSTEM_OUT)
console.add(builder.newLayout("PatternLayout").addAttribute("pattern", LOG4J_PATTERN))
builder.add(console)
builder.add(builder.newRootLogger(convertToLog4jLevel(level)).add(builder.newAppenderRef("Stdout")))
Configurator.initialize(builder.build())
}
private fun convertToLog4jLevel(level: io.github.oshai.Level) = when (level) {
io.github.oshai.Level.TRACE -> Level.TRACE
io.github.oshai.Level.DEBUG -> Level.DEBUG
<http://io.github.oshai.Level.INFO|io.github.oshai.Level.INFO> -> <http://Level.INFO|Level.INFO>
io.github.oshai.Level.WARN -> Level.WARN
io.github.oshai.Level.ERROR -> Level.ERROR
}
ephemient
03/20/2023, 8:14 PMephemient
03/20/2023, 8:16 PM<logger name="com.pinterest.ktlint" level="NONE" />
or something like thatRoberto Leinardi
03/20/2023, 8:27 PMephemient
03/20/2023, 8:30 PMRoberto Leinardi
03/20/2023, 8:31 PMresources/logback.xml
and it works in the way that I don't see logs from ktlint. But the dependency clash still prevent my logs to work:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.jetbrains.kotlin.com.intellij.util.ReflectionUtil (file:/home/leinardi/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-compiler-embeddable/1.8.0/eb9118d4bcceaa2a94b2ae2a33a4ddba7c9a947f/kotlin-compiler-embeddable-1.8.0.jar) to field java.lang.Throwable.backtrace
WARNING: Please consider reporting this to the maintainers of org.jetbrains.kotlin.com.intellij.util.ReflectionUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Any plan to migrate to kotlin-logger
v4?Paul Dingemans
03/21/2023, 8:32 AMRoberto Leinardi
03/21/2023, 10:40 AMcom.pinterest:ktlint
and instead I import only ktlint-core
and the ktlint-ruleset-*
I do not have any issues with the logs: ktlint doesn't log anything and log4j2 still works for me!
Do you think there are some side effects in doing this (not importing com.pinterest:ktlint
but only core and rulesets)?Paul Dingemans
03/21/2023, 10:42 AMPaul Dingemans
03/21/2023, 10:43 AMRoberto Leinardi
03/21/2023, 10:44 AMPaul Dingemans
03/21/2023, 10:47 AMRoberto Leinardi
03/21/2023, 11:20 AM