Casey Brooks
08/18/2023, 5:25 PMdisabledRules
and additionalEditorconfigFile
deprecation for a while now, but I’m trying to get it fixed. However, it’s not clear to me what the replacement is supposed to be. I’m trying to configure Ktlint in an included build so I don’t have to redefine the disabled rules in each project’s default .editorconfig
Vampire
08/18/2023, 5:34 PMCasey Brooks
08/18/2023, 5:46 PMPaul Dingemans
08/19/2023, 5:17 PMeditorConfigOverride
. Consulting the changelog files would have been an other good option to discover how to migrate whenever functionality is removed.wakingrufus
08/21/2023, 3:09 PMwakingrufus
08/21/2023, 3:21 PMPaul Dingemans
08/21/2023, 3:32 PMI would like to expose editorConfigOverride via the plugin, but the API uses classes/objects defined in ktlint as well as rule sets, which are not on the buildscript classpath, so I am not sure how to approach itI am happy to investigate whether ktlint can support this case. But for that, I need more clarity about the problem so that we can think of a possible future. It would be great to start with an example project that demonstrates the problem.
wakingrufus
08/21/2023, 3:45 PMEditorConfigOverride.from
accepts EditorConfigProperty
in its API. that class comes from ktlint-rule-engine-core, but instances of that class are defined in various rule set libraries. ktlint-gradle has classpath separation between the gradle configuration (where you configure ktlint-gradle) and the task worker (which actually executes ktlint). we don'tput any ktlint dependencies on the buildscript classpath. this is how we able to provide compatibility with multiple versions of ktlintPaul Dingemans
08/21/2023, 4:24 PMEditorConfigOverride.from
enforces compile time that the EditorConfigOverride is configured with valid EditorConfigProperty
. This is very convenient from ktlint perspective. For this use case you would like to have an API like from(vararg properties: Pair<String, String>): EditorConfigOverride
.
Most likely it is possible to match the keys of this map with the properties that are used by the rules that are provided to the KtlintRuleEngine
. Properties which can not be matched with a property can be ignored silently (but with a log warning). Properties which can be matched but have an invalid value according to the EditorConfigProperty
definition will throw an exception before files are processed.
I you think this will resolve the problem, I can give it a try.wakingrufus
08/21/2023, 5:06 PMPaul Dingemans
08/21/2023, 7:18 PMPaul Dingemans
08/22/2023, 2:05 PMEditorConfigOverride
can be defined for properties that are provided via rulesets that are loaded dynamically. Do you still think that this should be provided by ktlint? I have the feeling that this more specific to ktlint-gradle
due to dynamic loading of rulesets.wakingrufus
08/22/2023, 6:26 PMwakingrufus
08/22/2023, 6:27 PMwakingrufus
08/22/2023, 6:27 PMwakingrufus
08/22/2023, 6:28 PMPaul Dingemans
08/22/2023, 6:44 PM.editorconfig
file. Ktlint contains quite some logic for this and it is kept internal for reasons. There should also be no need for an API consumer to read that .editorconfig
in order to call KtlintRuleEngine
as the rule engine will read it for you. You have two ways to influence the .editorconfig
without reading/parsing it yourself.
• `editorConfigDefaults`: This contains the default values for .editorconfig
properties which are not set explicitly in any ‘.editorconfig’ file located on the path of the file which is processed with the KtLintRuleEngine
. If a property is set in editorConfigDefaults
this takes precedence above the default values defined in definition of the EditorConfigProperty
.
• `editorConfigOverride`: Override values for .editorconfig
properties. If a property is set in editorConfigOverride
it takes precedence above the same property being set in any other way.
Please clarify what reason you would have to read/parse .editorconfig
if above does not suffice.wakingrufus
08/22/2023, 8:45 PMwakingrufus
08/22/2023, 8:46 PMwakingrufus
08/22/2023, 8:46 PMwakingrufus
08/22/2023, 8:46 PMwakingrufus
08/22/2023, 8:59 PM"ktlint_standard_no-multi-spaces", "disabled"
and using that code in the sample, but it didnt work. I got
Property with name 'ktlint_standard_no-multi-spaces' is not found in any of given rules. Available properties:
- ij_kotlin_allow_trailing_comma
- ij_kotlin_allow_trailing_comma_on_call_site
- ij_kotlin_imports_layout
- ij_kotlin_packages_to_use_import_on_demand
- indent_size
- indent_style
- insert_final_newline
- ktlint_code_style
- ktlint_function_signature_body_expression_wrapping
- ktlint_function_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than
- ktlint_ignore_back_ticked_identifier
- max_line_length
wakingrufus
08/22/2023, 9:00 PMwakingrufus
08/22/2023, 9:13 PMwakingrufus
08/22/2023, 9:16 PMusesEditorConfigProperties
but shouldnt they have "ktlint_${RuleSetId.STANDARD.value}_$id"
in that Set?Paul Dingemans
08/23/2023, 6:20 PMwakingrufus
08/23/2023, 8:24 PMPaul Dingemans
08/24/2023, 6:22 AMwakingrufus
08/24/2023, 1:20 PMPaul Dingemans
08/24/2023, 2:23 PMPaul Dingemans
08/26/2023, 5:40 PMktlint-rule-engine-core
already has some extension functions that you can use to enable/disable rules and rule sets.
EditorConfigOverride
.from(
// Property types provided by ktlint-rule-engine-core
INDENT_STYLE_PROPERTY to <http://IndentConfig.IndentStyle.SPACE|IndentConfig.IndentStyle.SPACE>,
INDENT_SIZE_PROPERTY to 4,
EXPERIMENTAL_RULES_EXECUTION_PROPERTY to RuleExecution.enabled,
// Properties defines in the ktlint-ruleset-standard can only be used statically when that dependency is provided at compile
// time.
// FUNCTION_BODY_EXPRESSION_WRAPPING_PROPERTY to always
// For properties that are defined in rules for which the dependency is provided at runtime only, the property name can be
// provided as String and the value as Any type. In case the property value is invalid, the KtlintRuleEngine logs a warning.
ruleProviders.findEditorConfigProperty("ktlint_function_signature_body_expression_wrapping") to "alwaysx",
RuleId("standard:function-signature").createRuleExecutionEditorConfigProperty() to RuleExecution.disabled,
RuleSetId("some-custom-ruleset").createRuleSetExecutionEditorConfigProperty() to RuleExecution.enabled,
// In case an unknown property would be provided, an exception is thrown by the helper method
// ruleProviders.findEditorConfigProperty("unknown_property") to "some-value",
)
Paul Dingemans
08/27/2023, 8:56 AMval editorConfigPropertyRegistry = EditorConfigPropertyRegistry(ruleProviders)
val editorConfigOverride =
EditorConfigOverride
.from(
// Property types provided by ktlint-rule-engine-core
INDENT_STYLE_PROPERTY to <http://IndentConfig.IndentStyle.SPACE|IndentConfig.IndentStyle.SPACE>,
INDENT_SIZE_PROPERTY to 4,
EXPERIMENTAL_RULES_EXECUTION_PROPERTY to RuleExecution.enabled,
// Properties defines in the ktlint-ruleset-standard can only be used statically when that dependency is provided at compile
// time.
// FUNCTION_BODY_EXPRESSION_WRAPPING_PROPERTY to always
// For properties that are defined in rules for which the dependency is provided at runtime only, the property name can be
// provided as String and the value as Any type. In case the property value is invalid, the KtlintRuleEngine logs a warning.
editorConfigPropertyRegistry.find("ktlint_function_signature_body_expression_wrapping") to "alwaysx",
editorConfigPropertyRegistry.find("ktlint_standard_function-signature") to RuleExecution.disabled,
editorConfigPropertyRegistry.find("ktlint_some-custom-ruleset") to RuleExecution.enabled,
// In case an unknown property would be provided, an exception is thrown by the helper method
// ruleProviders.findEditorConfigProperty("unknown_property") to "some-value",
)
I think that I will be able to finish it tomorrow.wakingrufus
08/28/2023, 1:18 PMPaul Dingemans
08/28/2023, 7:10 PMwakingrufus
08/28/2023, 7:42 PMPaul Dingemans
09/03/2023, 6:36 PMwakingrufus
09/05/2023, 2:42 PMPaul Dingemans
09/05/2023, 2:45 PMwakingrufus
09/14/2023, 5:00 PM> Property with name 'ktlint_standard_no-multi-spaces' is not found in any of given rules. Available properties:
- ij_kotlin_allow_trailing_comma
- ij_kotlin_allow_trailing_comma_on_call_site
- ij_kotlin_imports_layout
- ij_kotlin_packages_to_use_import_on_demand
- indent_size
- indent_style
- insert_final_newline
- ktlint_chain_method_rule_force_multiline_when_chain_operator_count_greater_or_equal_than
- ktlint_class_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than
- ktlint_code_style
- ktlint_function_signature_body_expression_wrapping
- ktlint_function_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than
- ktlint_ignore_back_ticked_identifier
- max_line_length
wakingrufus
09/14/2023, 5:00 PMwakingrufus
09/14/2023, 5:01 PMKtLintRuleEngine(
ruleProviders = ruleProviders,
editorConfigOverride = EditorConfigOverride.from(*editorConfigOverrides
.mapKeys { editorConfigPropertyRegistry.find(it.key) }
.entries
.map { it.key to it.value }
.toTypedArray())
)
wakingrufus
09/14/2023, 5:11 PMwakingrufus
09/14/2023, 5:11 PMwakingrufus
09/14/2023, 5:11 PMPaul Dingemans
09/14/2023, 5:13 PMwakingrufus
09/14/2023, 5:14 PMwakingrufus
09/14/2023, 5:15 PMwakingrufus
09/14/2023, 5:15 PMwakingrufus
09/14/2023, 10:47 PMwakingrufus
09/18/2023, 8:07 PM