diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e24849869..87229fcbce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,16 @@ The KtLint CLI has not been changed. Although you can still use parameter `--exp If you are not an API consumer or Rule Set provider then you can skip this section. +#### Class relocations + +Classes below have been relocated: + +* Class `com.pinterest.ktlint.core.api.UsesEditorConfigProperties.EditorConfigProperty` has been replaced with `com.pinterest.ktlint.core.api.editorconfig.EditorConfigProperty`. +* Class `com.pinterest.ktlint.core.KtLintParseException` has been replaced with `com.pinterest.ktlint.core.api.KtLintParseException`. +* Class `com.pinterest.ktlint.core.RuleExecutionException` has been replaced with `com.pinterest.ktlint.core.api.KtLintRuleException`. +* Class `com.pinterest.ktlint.reporter.format.internal.Color` has been moved to `com.pinterest.ktlint.reporter.format.Color`. +* Class `com.pinterest.ktlint.reporter.plain.internal.Color` has been moved to `com.pinterest.ktlint.reporter.plain.Color`. + #### Invoking `lint` and `format` This is the last release that supports the `ExperimentalParams` to invoke the `lint` and `format` functions of KtLint. The `ExperimentalParams` contains a mix of configuration settings which are not dependent on the file/code which is to be processed. Other parameters in that class describe the code/file to be processed but can be configured inconsistently (for example a file with name "foo.kt" could be marked as a Kotlin Script file). @@ -70,20 +80,6 @@ if (node.isRoot()) { } ``` -#### ParseException - -Class `com.pinterest.ktlint.core.KtLintParseException` has been replaced with `com.pinterest.ktlint.core.api.KtLintParseException`. - -#### RuleExecutionException - -Class `com.pinterest.ktlint.core.RuleExecutionException` has been replaced with `com.pinterest.ktlint.core.api.KtLintRuleException`. - -#### Color - -Class `com.pinterest.ktlint.reporter.format.internal.Color` has been moved to `com.pinterest.ktlint.reporter.format.Color`. - -Class `com.pinterest.ktlint.reporter.plain.internal.Color` has been moved to `com.pinterest.ktlint.reporter.plain.Color`. - ### Added * Wrap blocks in case the max line length is exceeded or in case the block contains a new line `wrapping` ([#1643](https://github.com/pinterest/ktlint/issue/1643)) * patterns can be read in from `stdin` with the `--patterns-from-stdin` command line options/flags ([#1606](https://github.com/pinterest/ktlint/pull/1606)) diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/KtLint.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/KtLint.kt index 88a027341f..ddfe5f7e50 100644 --- a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/KtLint.kt +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/KtLint.kt @@ -5,14 +5,14 @@ package com.pinterest.ktlint.core import com.pinterest.ktlint.core.KtLint.ExperimentalParams import com.pinterest.ktlint.core.KtLint.format import com.pinterest.ktlint.core.KtLint.lint -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.CODE_STYLE_PROPERTY import com.pinterest.ktlint.core.api.EditorConfigDefaults import com.pinterest.ktlint.core.api.EditorConfigDefaults.Companion.EMPTY_EDITOR_CONFIG_DEFAULTS import com.pinterest.ktlint.core.api.EditorConfigOverride import com.pinterest.ktlint.core.api.EditorConfigOverride.Companion.EMPTY_EDITOR_CONFIG_OVERRIDE import com.pinterest.ktlint.core.api.KtLintRuleException import com.pinterest.ktlint.core.api.UsesEditorConfigProperties +import com.pinterest.ktlint.core.api.editorconfig.CodeStyleValue +import com.pinterest.ktlint.core.api.editorconfig.DEFAULT_EDITOR_CONFIG_PROPERTIES import com.pinterest.ktlint.core.internal.EditorConfigFinder import com.pinterest.ktlint.core.internal.EditorConfigGenerator import com.pinterest.ktlint.core.internal.EditorConfigLoader @@ -120,7 +120,7 @@ public object KtLint { .filterIsInstance() .map { it.editorConfigProperties } .flatten() - .plus(DefaultEditorConfigProperties.editorConfigProperties) + .plus(DEFAULT_EDITOR_CONFIG_PROPERTIES) .map { it.name } .distinct() .toSet() @@ -580,10 +580,10 @@ public class KtLintRuleEngine( public fun generateKotlinEditorConfigSection(filePath: Path): String { val codeStyle = editorConfigOverride - .properties[CODE_STYLE_PROPERTY] + .properties[com.pinterest.ktlint.core.api.editorconfig.CODE_STYLE_PROPERTY] ?.parsed - ?.safeAs() - ?: CODE_STYLE_PROPERTY.defaultValue + ?.safeAs() + ?: com.pinterest.ktlint.core.api.editorconfig.CODE_STYLE_PROPERTY.defaultValue val rules = ruleProviders .map { RuleRunner(it) } diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/EditorConfigOverride.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/EditorConfigOverride.kt index e033ff653e..7c791de9a9 100644 --- a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/EditorConfigOverride.kt +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/EditorConfigOverride.kt @@ -1,6 +1,6 @@ package com.pinterest.ktlint.core.api -import com.pinterest.ktlint.core.api.UsesEditorConfigProperties.EditorConfigProperty +import com.pinterest.ktlint.core.api.editorconfig.EditorConfigProperty import org.ec4j.core.model.PropertyType.PropertyValue /** diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/UsesEditorConfigProperties.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/UsesEditorConfigProperties.kt index ee5bf0c822..ecb4bcbfdc 100644 --- a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/UsesEditorConfigProperties.kt +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/UsesEditorConfigProperties.kt @@ -1,18 +1,18 @@ package com.pinterest.ktlint.core.api -import com.pinterest.ktlint.core.IndentConfig -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.CODE_STYLE_PROPERTY -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.CodeStyleValue -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.CodeStyleValue.android -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.CodeStyleValue.official -import com.pinterest.ktlint.core.api.UsesEditorConfigProperties.EditorConfigProperty +import com.pinterest.ktlint.core.api.editorconfig.CODE_STYLE_PROPERTY +import com.pinterest.ktlint.core.api.editorconfig.CodeStyleValue +import com.pinterest.ktlint.core.api.editorconfig.DEFAULT_EDITOR_CONFIG_PROPERTIES +import com.pinterest.ktlint.core.api.editorconfig.DISABLED_RULES_PROPERTY +import com.pinterest.ktlint.core.api.editorconfig.EditorConfigProperty +import com.pinterest.ktlint.core.api.editorconfig.INDENT_SIZE_PROPERTY +import com.pinterest.ktlint.core.api.editorconfig.INDENT_STYLE_PROPERTY +import com.pinterest.ktlint.core.api.editorconfig.INSERT_FINAL_NEWLINE_PROPERTY +import com.pinterest.ktlint.core.api.editorconfig.KTLINT_DISABLED_RULES_PROPERTY +import com.pinterest.ktlint.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY import com.pinterest.ktlint.core.initKtLintKLogger -import com.pinterest.ktlint.core.internal.ruleId -import com.pinterest.ktlint.core.internal.ruleSetId import mu.KotlinLogging -import org.ec4j.core.model.Property import org.ec4j.core.model.PropertyType -import org.ec4j.core.model.PropertyType.PropertyValueParser.EnumValueParser private val LOGGER = KotlinLogging.logger {}.initKtLintKLogger() @@ -53,7 +53,7 @@ public interface UsesEditorConfigProperties { .parse( get(CODE_STYLE_PROPERTY.name)?.sourceValue, ).parsed - ?: official + ?: CodeStyleValue.official /** * Get the value of [editorConfigProperty] from [EditorConfigProperties]. @@ -120,7 +120,7 @@ public interface UsesEditorConfigProperties { } private fun EditorConfigProperty.getDefaultValue(codeStyleValue: CodeStyleValue) = - if (codeStyleValue == android) { + if (codeStyleValue == CodeStyleValue.android) { defaultAndroidValue } else { defaultValue @@ -136,74 +136,6 @@ public interface UsesEditorConfigProperties { editorConfigProperty.propertyWriter( getEditorConfigValue(editorConfigProperty), ) - - /** - * Definition of '.editorconfig' property enriched with KtLint specific fields. - */ - public data class EditorConfigProperty( - /** - * Type of property. Could be one of default ones (see [PropertyType.STANDARD_TYPES]) or custom one. - */ - public val type: PropertyType, - - /** - * Default value for property if it does not exist in loaded properties and codestyle 'official'. - */ - public val defaultValue: T, - - /** - * Default value for property if it does not exist in loaded properties and codestyle 'android'. This property - * is to be set only when its value does not equal [defaultValue]. - */ - public val defaultAndroidValue: T = defaultValue, - - /** - * If set, it maps the actual value set for the property, to another valid value for that property. See example - * below where - * ```kotlin - * propertyMapper = { property, isAndroidCodeStyle -> - * when { - * property == null -> - * // property is not defined in ".editorconfig" file - * property.isUnset -> - * // property is defined in ".editorconfig" file with special value "unset" - * property.sourceValue == "some-string-value" -> - * // property is defined in ".editorconfig" file with a value that needs to be remapped to another - * // valid value. For example the "max_line_length" property accepts value "off" but is remapped to - * // "-1" in ktlint. - * else -> - * property.getValueAs() // or null - * } - * } - * ``` - * In case the lambda returns a null value then, the [defaultValue] or [defaultAndroidValue] will be set as - * value of the property. The - */ - public val propertyMapper: ((Property?, CodeStyleValue) -> T?)? = null, - - /** - * Custom function that represents [T] as String. Defaults to the standard `toString()` call. Override the - * default implementation in case you need a different behavior than the standard `toString()` (e.g. for - * collections joinToString() is more applicable). - */ - public val propertyWriter: (T) -> String = { it.toString() }, - - /** - * Optional message to be displayed whenever the value of the property is being retrieved. - */ - internal val deprecationWarning: String? = null, - - /** - * Optional message to be displayed whenever the value of the property is being retrieved. - */ - internal val deprecationError: String? = null, - - /** - * Name of the property. A property must be named in case multiple properties are defined for the same type. - * Defaults to the name of the type when not set. - */ - public val name: String = type.name, - ) } public class DeprecatedEditorConfigPropertyException(message: String) : RuntimeException(message) @@ -211,71 +143,22 @@ public class DeprecatedEditorConfigPropertyException(message: String) : RuntimeE /** * Defines KtLint properties which are based on default property types provided by [org.ec4j.core.model.PropertyType]. */ +@Deprecated( + "Marked for removal of public API in KtLint 0.49. Please raise an issue if you have a use case why this " + + "should be kept public.", +) public object DefaultEditorConfigProperties : UsesEditorConfigProperties { - /** - * Code style to be used while linting and formatting. Note that the [EnumValueParser] requires values to be lowercase. - */ - @Suppress("EnumEntryName") - public enum class CodeStyleValue { - android, - official, - } - - public val CODE_STYLE_PROPERTY: EditorConfigProperty = - EditorConfigProperty( - type = PropertyType.LowerCasingPropertyType( - "ktlint_code_style", - "The code style ('official' or 'android') to be applied. Defaults to 'official' when not set.", - EnumValueParser(CodeStyleValue::class.java), - CodeStyleValue.values().map { it.name }.toSet(), - ), - defaultValue = official, - defaultAndroidValue = android, - ) - @Deprecated( message = "Marked for removal in KtLint 0.49", - replaceWith = ReplaceWith("CODE_STYLE_PROPERTY"), + replaceWith = ReplaceWith( + expression = "CODE_STYLE_PROPERTY", + imports = ["com.pinterest.ktlint.core.api.editorconfig.CODE_STYLE_PROPERTY"], + ), ) @Suppress("ktlint:experimental:property-naming") public val codeStyleSetProperty: EditorConfigProperty = CODE_STYLE_PROPERTY - @Deprecated( - // Keep postponing the deprecation period until around 0.50. Some projects irregular update to newer KtLint - // version and skipping intermediate version. As of such they might have missed the deprecation warning in - // KtLint 0.47. - "Marked for removal in KtLint 0.49. Update all your all '.editorconfig' files. See " + - "https://pinterest.github.io/ktlint/faq/#why-is-editorconfig-property-disabled_rules-deprecated-and-how-do-i-resolve-this " + - "for more information", - ) - public val DISABLED_RULES_PROPERTY: EditorConfigProperty = - EditorConfigProperty( - type = PropertyType.LowerCasingPropertyType( - "disabled_rules", - "A comma separated list of rule ids which should not be run. For rules not defined in the 'standard' ruleset, the qualified rule-id should be used.", - PropertyType.PropertyValueParser.IDENTITY_VALUE_PARSER, - emptySet(), - ), - defaultValue = "", - propertyMapper = { property, _ -> - when { - property?.isUnset == true -> "" - property?.getValueAs() != null -> { - // Remove spaces (most likely they occur only around the comma) as they otherwise will be seen - // as part of the rule-id which is to be disabled. But as the space is not allowed in the id's - // of rule sets and rule ids, they are just removed all. - property.getValueAs().replace(" ", "") - } - else -> property?.getValueAs() - } - }, - // TODO: Mark this property with a deprecationError starting from KtLint 0.49 - deprecationWarning = "Update all your all '.editorconfig' files. See " + - "https://pinterest.github.io/ktlint/faq/#why-is-editorconfig-property-disabled_rules-deprecated-and-how-do-i-resolve-this " + - "for more information", - ) - /** * Marked for removal in KtLint 0.49. * @@ -291,187 +174,74 @@ public object DefaultEditorConfigProperties : UsesEditorConfigProperties { * by setting the property of that rule (set) in an '.editorconfig' in that package. */ @Deprecated( - // Keep postponing the deprecation period until around 0.50. Some projects irregular update to newer KtLint - // version and skipping intermediate version. "Marked for removal in KtLint 0.49. Update all your all '.editorconfig' files. See " + "https://pinterest.github.io/ktlint/faq/#why-is-editorconfig-property-disabled_rules-deprecated-and-how-do-i-resolve-this " + "for more information", + // ReplaceWith is not specified as the property should not be migrated to KTLINT_DISABLED_RULES_PROPERTY but to + // the RuleExecution property. ) - public val KTLINT_DISABLED_RULES_PROPERTY: EditorConfigProperty = - EditorConfigProperty( - type = PropertyType.LowerCasingPropertyType( - "ktlint_disabled_rules", - "A comma separated list of rule ids which should not be run. For rules not defined in the 'standard' ruleset, the qualified rule-id should be used.", - PropertyType.PropertyValueParser.IDENTITY_VALUE_PARSER, - emptySet(), - ), - defaultValue = "", - propertyMapper = { property, _ -> - when { - property?.isUnset == true -> "" - property?.getValueAs() != null -> { - // Remove spaces (most likely they occur only around the comma) as they otherwise will be seen - // as part of the rule-id which is to be disabled. But as the space is not allowed in the id's - // of rule sets and rule ids, they are just removed all. - property.getValueAs().replace(" ", "") - } - else -> property?.getValueAs() - } - }, - // TODO: Mark this property with a deprecationError starting from KtLint 0.49 - deprecationWarning = "Update all your all '.editorconfig' files. See " + - "https://pinterest.github.io/ktlint/faq/#why-is-editorconfig-property-disabled_rules-deprecated-and-how-do-i-resolve-this " + - "for more information", - ) - - @Suppress("EnumEntryName") - public enum class RuleExecution { - enabled, - disabled, - } - - internal val RULE_EXECUTION_PROPERTY_TYPE = - PropertyType.LowerCasingPropertyType( - "ktlint_rule_execution", - "When enabled, the rule is being executed.", - EnumValueParser(RuleExecution::class.java), - CodeStyleValue.values().map { it.name }.toSet(), - ) - - /** - * Generates the rule execution '.editorconfig' property for the rule set of the given [qualifiedRuleId]. - */ - public fun createRuleSetExecutionEditorConfigProperty(qualifiedRuleId: String): EditorConfigProperty = - EditorConfigProperty( - // Explicitly name the rule as multiple properties exists for the same type - name = ktLintRuleSetExecutionPropertyName(qualifiedRuleId), - type = RULE_EXECUTION_PROPERTY_TYPE, - defaultValue = RuleExecution.enabled, - ) - - /** - * Generates the rule execution '.editorconfig' property for the given [qualifiedRuleId]. Note that the property is - * the same as the [qualifiedRuleId] but prefixed with 'ktlint_' followed by the ruleSetId and ruleId which both are - * based on the [qualifiedRuleId]. - */ - public fun createRuleExecutionEditorConfigProperty(qualifiedRuleId: String): EditorConfigProperty = - EditorConfigProperty( - name = ktLintRuleExecutionPropertyName(qualifiedRuleId), - type = RULE_EXECUTION_PROPERTY_TYPE, - defaultValue = RuleExecution.enabled, - ) - - /** - * Constructs the name of the '.editorconfig' property that determines whether the given rule is to be executed. - */ - internal fun ktLintRuleExecutionPropertyName(qualifiedRuleId: String): String = - "ktlint_${ruleSetId(qualifiedRuleId)}_${ruleId(qualifiedRuleId)}" - - /** - * Constructs the name of the '.editorconfig' property that determines whether the rule set of the given - * [qualifiedRuleId] is to be executed. - */ - internal fun ktLintRuleSetExecutionPropertyName(qualifiedRuleId: String): String = - "ktlint_${ruleSetId(qualifiedRuleId)}" + public val disabledRulesProperty: EditorConfigProperty = + DISABLED_RULES_PROPERTY @Deprecated( message = "Marked for removal in KtLint 0.49", - replaceWith = ReplaceWith("KTLINT_DISABLED_RULES_PROPERTY"), + replaceWith = ReplaceWith( + expression = "KTLINT_DISABLED_RULES_PROPERTY", + imports = ["com.pinterest.ktlint.core.api.editorconfig.INDENT_STYLE_PROPERTY"], + ), ) @Suppress("ktlint:experimental:property-naming") public val ktlintDisabledRulesProperty: EditorConfigProperty = KTLINT_DISABLED_RULES_PROPERTY - public val INDENT_STYLE_PROPERTY: EditorConfigProperty = - EditorConfigProperty( - name = PropertyType.indent_style.name, - type = PropertyType.indent_style, - defaultValue = PropertyType.IndentStyleValue.space, - ) - @Deprecated( message = "Marked for removal in KtLint 0.49", - replaceWith = ReplaceWith("INDENT_STYLE_PROPERTY"), + replaceWith = ReplaceWith( + expression = "INDENT_STYLE_PROPERTY", + imports = ["com.pinterest.ktlint.core.api.editorconfig.INDENT_STYLE_PROPERTY"], + ), ) @Suppress("ktlint:experimental:property-naming") public val indentStyleProperty: EditorConfigProperty = INDENT_STYLE_PROPERTY - public val INDENT_SIZE_PROPERTY: EditorConfigProperty = - EditorConfigProperty( - name = PropertyType.indent_size.name, - type = PropertyType.indent_size, - defaultValue = IndentConfig.DEFAULT_INDENT_CONFIG.tabWidth, - propertyMapper = { property, _ -> - when { - property?.isUnset == true -> -1 - property?.getValueAs() == null -> - IndentConfig.DEFAULT_INDENT_CONFIG.tabWidth - else -> property.getValueAs() - } - }, - ) - @Deprecated( message = "Marked for removal in KtLint 0.49", - replaceWith = ReplaceWith("INDENT_SIZE_PROPERTY"), + replaceWith = ReplaceWith( + expression = "INDENT_SIZE_PROPERTY", + imports = ["com.pinterest.ktlint.core.api.editorconfig.INDENT_SIZE_PROPERTY"], + ), ) @Suppress("ktlint:experimental:property-naming") public val indentSizeProperty: EditorConfigProperty = INDENT_SIZE_PROPERTY - public val INSERT_FINAL_NEWLINE_PROPERTY: EditorConfigProperty = - EditorConfigProperty( - name = PropertyType.insert_final_newline.name, - type = PropertyType.insert_final_newline, - defaultValue = true, - ) - @Deprecated( message = "Marked for removal in KtLint 0.49", - replaceWith = ReplaceWith("INSERT_FINAL_NEWLINE_PROPERTY"), + replaceWith = ReplaceWith( + expression = "INSERT_FINAL_NEWLINE_PROPERTY", + imports = ["com.pinterest.ktlint.core.api.editorconfig.INSERT_FINAL_NEWLINE_PROPERTY"], + ), ) @Suppress("ktlint:experimental:property-naming") public val insertNewLineProperty: EditorConfigProperty = INSERT_FINAL_NEWLINE_PROPERTY - public val MAX_LINE_LENGTH_PROPERTY: EditorConfigProperty = - EditorConfigProperty( - name = PropertyType.max_line_length.name, - type = PropertyType.max_line_length, - defaultValue = -1, - defaultAndroidValue = 100, - propertyMapper = { property, codeStyleValue -> - when { - property == null || property.isUnset -> { - if (codeStyleValue == android) { - // https://developer.android.com/kotlin/style-guide#line_wrapping - 100 - } else { - property?.getValueAs() - } - } - property.sourceValue == "off" -> -1 - else -> PropertyType.max_line_length.parse(property.sourceValue).parsed - } - }, - ) - @Deprecated( message = "Marked for removal in KtLint 0.49", - replaceWith = ReplaceWith("MAX_LINE_LENGTH_PROPERTY"), + replaceWith = ReplaceWith( + expression = "MAX_LINE_LENGTH_PROPERTY", + imports = ["com.pinterest.ktlint.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY"], + ), ) @Suppress("ktlint:experimental:property-naming") public val maxLineLengthProperty: EditorConfigProperty = MAX_LINE_LENGTH_PROPERTY - override val editorConfigProperties: List> = listOf( - CODE_STYLE_PROPERTY, - DISABLED_RULES_PROPERTY, - KTLINT_DISABLED_RULES_PROPERTY, - INDENT_STYLE_PROPERTY, - INDENT_SIZE_PROPERTY, - INSERT_FINAL_NEWLINE_PROPERTY, - MAX_LINE_LENGTH_PROPERTY, + @Deprecated( + "Marked for removal of public API in KtLint 0.49. Please raise an issue if you have a use case why this " + + "should be kept public.", ) + override val editorConfigProperties: List> = + DEFAULT_EDITOR_CONFIG_PROPERTIES } diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/editorconfig/CodeStyleEditorConfigProperty.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/editorconfig/CodeStyleEditorConfigProperty.kt new file mode 100644 index 0000000000..5cbfcce155 --- /dev/null +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/editorconfig/CodeStyleEditorConfigProperty.kt @@ -0,0 +1,25 @@ +package com.pinterest.ktlint.core.api.editorconfig + +import org.ec4j.core.model.PropertyType +import org.ec4j.core.model.PropertyType.PropertyValueParser.EnumValueParser + +/** + * Code style to be used while linting and formatting. Note that the [EnumValueParser] requires values to be lowercase. + */ +@Suppress("EnumEntryName") +public enum class CodeStyleValue { + android, + official, +} + +public val CODE_STYLE_PROPERTY: EditorConfigProperty = + EditorConfigProperty( + type = PropertyType.LowerCasingPropertyType( + "ktlint_code_style", + "The code style ('official' or 'android') to be applied. Defaults to 'official' when not set.", + EnumValueParser(CodeStyleValue::class.java), + CodeStyleValue.values().map { it.name }.toSet(), + ), + defaultValue = CodeStyleValue.official, + defaultAndroidValue = CodeStyleValue.android, + ) diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/editorconfig/DisabledRulesEditorConfigProperty.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/editorconfig/DisabledRulesEditorConfigProperty.kt new file mode 100644 index 0000000000..6a6cf54774 --- /dev/null +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/editorconfig/DisabledRulesEditorConfigProperty.kt @@ -0,0 +1,54 @@ +package com.pinterest.ktlint.core.api.editorconfig + +import org.ec4j.core.model.PropertyType + +@Deprecated( + // Keep postponing the deprecation period until around 0.50. Some projects irregular update to newer KtLint + // version and skipping intermediate version. As of such they might have missed the deprecation warning in + // KtLint 0.47. + "Marked for removal in KtLint 0.49. Update all your all '.editorconfig' files. See " + + "https://pinterest.github.io/ktlint/faq/#why-is-editorconfig-property-disabled_rules-deprecated-and-how-do-i-resolve-this " + + "for more information", +) +public val DISABLED_RULES_PROPERTY: EditorConfigProperty = + createDisabledRulesEditorConfigProperty("disabled_rules") + +@Deprecated( + // Keep postponing the deprecation period until around 0.50. Some projects irregular update to newer KtLint + // version and skipping intermediate version. + "Marked for removal in KtLint 0.49. Update all your all '.editorconfig' files. See " + + "https://pinterest.github.io/ktlint/faq/#why-is-editorconfig-property-disabled_rules-deprecated-and-how-do-i-resolve-this " + + "for more information", +) +// This property was never exposed in an official release. However, it should be kept until property +// UsesEditorConfigProperties.ktlintDisabledRulesProperty has been removed. +internal val KTLINT_DISABLED_RULES_PROPERTY: EditorConfigProperty = + createDisabledRulesEditorConfigProperty("ktlint_disabled_rules") + +private fun createDisabledRulesEditorConfigProperty(name: String) = EditorConfigProperty( + name = name, + type = PropertyType.LowerCasingPropertyType( + "disabled_rules", + "A comma separated list of rule ids which should not be run. For rules not defined in the 'standard' ruleset, the qualified rule-id should be used.", + PropertyType.PropertyValueParser.IDENTITY_VALUE_PARSER, + emptySet(), + ), + defaultValue = "", + propertyMapper = { property, _ -> + when { + property?.isUnset == true -> "" + property?.getValueAs() != null -> { + // Remove spaces (most likely they occur only around the comma) as they otherwise will be seen + // as part of the rule-id which is to be disabled. But as the space is not allowed in the id's + // of rule sets and rule ids, they are just removed all. + property.getValueAs().replace(" ", "") + } + + else -> property?.getValueAs() + } + }, + // TODO: Mark this property with a deprecationError starting from KtLint 0.49 + deprecationWarning = "Update all your all '.editorconfig' files. See " + + "https://pinterest.github.io/ktlint/faq/#why-is-editorconfig-property-disabled_rules-deprecated-and-how-do-i-resolve-this " + + "for more information", +) diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/editorconfig/EditorConfigProperties.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/editorconfig/EditorConfigProperties.kt new file mode 100644 index 0000000000..b6c20f4910 --- /dev/null +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/editorconfig/EditorConfigProperties.kt @@ -0,0 +1,12 @@ +package com.pinterest.ktlint.core.api.editorconfig + +internal val DEFAULT_EDITOR_CONFIG_PROPERTIES: List> = + listOf( + CODE_STYLE_PROPERTY, + DISABLED_RULES_PROPERTY, + KTLINT_DISABLED_RULES_PROPERTY, + INDENT_STYLE_PROPERTY, + INDENT_SIZE_PROPERTY, + INSERT_FINAL_NEWLINE_PROPERTY, + MAX_LINE_LENGTH_PROPERTY, + ) diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/editorconfig/EditorConfigProperty.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/editorconfig/EditorConfigProperty.kt new file mode 100644 index 0000000000..9576955848 --- /dev/null +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/editorconfig/EditorConfigProperty.kt @@ -0,0 +1,72 @@ +package com.pinterest.ktlint.core.api.editorconfig + +import org.ec4j.core.model.Property +import org.ec4j.core.model.PropertyType + +/** + * Definition of '.editorconfig' property enriched with KtLint specific fields. + */ +public data class EditorConfigProperty( + /** + * Type of property. Could be one of default ones (see [PropertyType.STANDARD_TYPES]) or custom one. + */ + public val type: PropertyType, + + /** + * Default value for property if it does not exist in loaded properties and codestyle 'official'. + */ + public val defaultValue: T, + + /** + * Default value for property if it does not exist in loaded properties and codestyle 'android'. This property + * is to be set only when its value does not equal [defaultValue]. + */ + public val defaultAndroidValue: T = defaultValue, + + /** + * If set, it maps the actual value set for the property, to another valid value for that property. See example + * below where + * ```kotlin + * propertyMapper = { property, isAndroidCodeStyle -> + * when { + * property == null -> + * // property is not defined in ".editorconfig" file + * property.isUnset -> + * // property is defined in ".editorconfig" file with special value "unset" + * property.sourceValue == "some-string-value" -> + * // property is defined in ".editorconfig" file with a value that needs to be remapped to another + * // valid value. For example the "max_line_length" property accepts value "off" but is remapped to + * // "-1" in ktlint. + * else -> + * property.getValueAs() // or null + * } + * } + * ``` + * In case the lambda returns a null value then, the [defaultValue] or [defaultAndroidValue] will be set as + * value of the property. The + */ + public val propertyMapper: ((Property?, CodeStyleValue) -> T?)? = null, + + /** + * Custom function that represents [T] as String. Defaults to the standard `toString()` call. Override the + * default implementation in case you need a different behavior than the standard `toString()` (e.g. for + * collections joinToString() is more applicable). + */ + public val propertyWriter: (T) -> String = { it.toString() }, + + /** + * Optional message to be displayed whenever the value of the property is being retrieved. + */ + internal val deprecationWarning: String? = null, + + /** + * Optional message to be displayed whenever the value of the property is being retrieved. + */ + internal val deprecationError: String? = null, + + /** + * Name of the property. A property must be named in case multiple properties are defined for the same type. + * Defaults to the name of the type when not set. + */ + public val name: String = type.name, +) diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/editorconfig/IndentSizeEditorConfigProperty.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/editorconfig/IndentSizeEditorConfigProperty.kt new file mode 100644 index 0000000000..c4ff6019f5 --- /dev/null +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/editorconfig/IndentSizeEditorConfigProperty.kt @@ -0,0 +1,20 @@ +package com.pinterest.ktlint.core.api.editorconfig + +import com.pinterest.ktlint.core.IndentConfig +import org.ec4j.core.model.PropertyType + +public val INDENT_SIZE_PROPERTY: EditorConfigProperty = + EditorConfigProperty( + name = PropertyType.indent_size.name, + type = PropertyType.indent_size, + defaultValue = IndentConfig.DEFAULT_INDENT_CONFIG.tabWidth, + propertyMapper = { property, _ -> + when { + property?.isUnset == true -> -1 + property?.getValueAs() == null -> + IndentConfig.DEFAULT_INDENT_CONFIG.tabWidth + + else -> property.getValueAs() + } + }, + ) diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/editorconfig/IndentStyleEditorConfigProperty.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/editorconfig/IndentStyleEditorConfigProperty.kt new file mode 100644 index 0000000000..77bb7cc170 --- /dev/null +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/editorconfig/IndentStyleEditorConfigProperty.kt @@ -0,0 +1,10 @@ +package com.pinterest.ktlint.core.api.editorconfig + +import org.ec4j.core.model.PropertyType + +public val INDENT_STYLE_PROPERTY: EditorConfigProperty = + EditorConfigProperty( + name = PropertyType.indent_style.name, + type = PropertyType.indent_style, + defaultValue = PropertyType.IndentStyleValue.space, + ) diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/editorconfig/InsertFinalNewLineEditorConfigProperty.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/editorconfig/InsertFinalNewLineEditorConfigProperty.kt new file mode 100644 index 0000000000..f2a8b66ec6 --- /dev/null +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/editorconfig/InsertFinalNewLineEditorConfigProperty.kt @@ -0,0 +1,10 @@ +package com.pinterest.ktlint.core.api.editorconfig + +import org.ec4j.core.model.PropertyType + +public val INSERT_FINAL_NEWLINE_PROPERTY: EditorConfigProperty = + EditorConfigProperty( + name = PropertyType.insert_final_newline.name, + type = PropertyType.insert_final_newline, + defaultValue = true, + ) diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/editorconfig/MaxLineLengthEditorConfigProperty.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/editorconfig/MaxLineLengthEditorConfigProperty.kt new file mode 100644 index 0000000000..09150e3091 --- /dev/null +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/editorconfig/MaxLineLengthEditorConfigProperty.kt @@ -0,0 +1,26 @@ +package com.pinterest.ktlint.core.api.editorconfig + +import org.ec4j.core.model.PropertyType + +public val MAX_LINE_LENGTH_PROPERTY: EditorConfigProperty = + EditorConfigProperty( + name = PropertyType.max_line_length.name, + type = PropertyType.max_line_length, + defaultValue = -1, + defaultAndroidValue = 100, + propertyMapper = { property, codeStyleValue -> + when { + property == null || property.isUnset -> { + if (codeStyleValue == CodeStyleValue.android) { + // https://developer.android.com/kotlin/style-guide#line_wrapping + 100 + } else { + property?.getValueAs() + } + } + + property.sourceValue == "off" -> -1 + else -> PropertyType.max_line_length.parse(property.sourceValue).parsed + } + }, + ) diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/editorconfig/RuleExecutionEditorConfigProperty.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/editorconfig/RuleExecutionEditorConfigProperty.kt new file mode 100644 index 0000000000..eb723fef25 --- /dev/null +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/editorconfig/RuleExecutionEditorConfigProperty.kt @@ -0,0 +1,55 @@ +package com.pinterest.ktlint.core.api.editorconfig + +import com.pinterest.ktlint.core.internal.ruleId +import com.pinterest.ktlint.core.internal.ruleSetId +import org.ec4j.core.model.PropertyType + +@Suppress("EnumEntryName") +public enum class RuleExecution { + enabled, + disabled, +} + +internal val RULE_EXECUTION_PROPERTY_TYPE = + PropertyType.LowerCasingPropertyType( + "ktlint_rule_execution", + "When enabled, the rule is being executed.", + PropertyType.PropertyValueParser.EnumValueParser(RuleExecution::class.java), + CodeStyleValue.values().map { it.name }.toSet(), + ) + +/** + * Generates the rule execution '.editorconfig' property for the rule set of the given [qualifiedRuleId]. + */ +public fun createRuleSetExecutionEditorConfigProperty(qualifiedRuleId: String): EditorConfigProperty = + EditorConfigProperty( + // Explicitly name the rule as multiple properties exists for the same type + name = ktLintRuleSetExecutionPropertyName(qualifiedRuleId), + type = RULE_EXECUTION_PROPERTY_TYPE, + defaultValue = RuleExecution.enabled, + ) + +/** + * Generates the rule execution '.editorconfig' property for the given [qualifiedRuleId]. Note that the property is + * the same as the [qualifiedRuleId] but prefixed with 'ktlint_' followed by the ruleSetId and ruleId which both are + * based on the [qualifiedRuleId]. + */ +public fun createRuleExecutionEditorConfigProperty(qualifiedRuleId: String): EditorConfigProperty = + EditorConfigProperty( + name = ktLintRuleExecutionPropertyName(qualifiedRuleId), + type = RULE_EXECUTION_PROPERTY_TYPE, + defaultValue = RuleExecution.enabled, + ) + +/** + * Constructs the name of the '.editorconfig' property that determines whether the given rule is to be executed. + */ +internal fun ktLintRuleExecutionPropertyName(qualifiedRuleId: String): String = + "ktlint_${ruleSetId(qualifiedRuleId)}_${ruleId(qualifiedRuleId)}" + +/** + * Constructs the name of the '.editorconfig' property that determines whether the rule set of the given + * [qualifiedRuleId] is to be executed. + */ +internal fun ktLintRuleSetExecutionPropertyName(qualifiedRuleId: String): String = + "ktlint_${ruleSetId(qualifiedRuleId)}" diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/EditorConfigGenerator.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/EditorConfigGenerator.kt index cda68cd07e..b66fa93b58 100644 --- a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/EditorConfigGenerator.kt +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/EditorConfigGenerator.kt @@ -1,10 +1,11 @@ package com.pinterest.ktlint.core.internal import com.pinterest.ktlint.core.Rule -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.CODE_STYLE_PROPERTY +import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.writeEditorConfigProperty import com.pinterest.ktlint.core.api.EditorConfigOverride import com.pinterest.ktlint.core.api.UsesEditorConfigProperties +import com.pinterest.ktlint.core.api.editorconfig.CodeStyleValue +import com.pinterest.ktlint.core.api.editorconfig.DEFAULT_EDITOR_CONFIG_PROPERTIES import com.pinterest.ktlint.core.initKtLintKLogger import java.nio.file.Path import mu.KotlinLogging @@ -33,14 +34,14 @@ internal class EditorConfigGenerator( fun generateEditorconfig( filePath: Path, rules: Set, - codeStyle: DefaultEditorConfigProperties.CodeStyleValue, + codeStyle: CodeStyleValue, ): String { val editorConfig: Map = editorConfigLoader .load( filePath = filePath, rules = rules, - editorConfigOverride = EditorConfigOverride.from(CODE_STYLE_PROPERTY to codeStyle.name), + editorConfigOverride = EditorConfigOverride.from(com.pinterest.ktlint.core.api.editorconfig.CODE_STYLE_PROPERTY to codeStyle.name), ) val potentialEditorConfigSettings = @@ -58,7 +59,7 @@ internal class EditorConfigGenerator( private fun getConfigurationSettingsForRules( rules: Set, editorConfig: Map, - codeStyle: DefaultEditorConfigProperties.CodeStyleValue, + codeStyle: CodeStyleValue, ) = rules .mapNotNull { rule -> if (rule is UsesEditorConfigProperties && rule.editorConfigProperties.isNotEmpty()) { @@ -72,7 +73,7 @@ internal class EditorConfigGenerator( ) } LOGGER.debug { - "Rule '${rule.id}' uses property '${property.type.name}' with default value '$value'" + "Rule '${rule.id}' uses property '${property.type.name}' with value '$value'" } ConfigurationSetting( key = property.type.name, @@ -87,25 +88,23 @@ internal class EditorConfigGenerator( private fun getConfigurationSettingsForDefaultEditorConfigProperties( editorConfig: Map, - codeStyle: DefaultEditorConfigProperties.CodeStyleValue, + codeStyle: CodeStyleValue, ): List { - return DefaultEditorConfigProperties - .editorConfigProperties + return DEFAULT_EDITOR_CONFIG_PROPERTIES .filter { it.deprecationWarning == null && it.deprecationError == null } .map { editorConfigProperty -> - val value = with((DefaultEditorConfigProperties as UsesEditorConfigProperties)) { - editorConfig.writeEditorConfigProperty( - editorConfigProperty, - codeStyle, - ) - } + val value = editorConfig.writeEditorConfigProperty( + editorConfigProperty, + codeStyle, + ) + LOGGER.debug { - "Class '${DefaultEditorConfigProperties::class.simpleName}' uses property '${editorConfigProperty.name}' with default value '$value'" + "Editor config property '${editorConfigProperty.name}' has default value '$value'" } ConfigurationSetting( key = editorConfigProperty.name, value = value, - usage = "Class '${DefaultEditorConfigProperties::class.simpleName}'", + usage = "Default value", ) } } diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/EditorConfigLoader.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/EditorConfigLoader.kt index 6c11b68de0..fc4129c4b4 100644 --- a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/EditorConfigLoader.kt +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/EditorConfigLoader.kt @@ -1,13 +1,13 @@ package com.pinterest.ktlint.core.internal import com.pinterest.ktlint.core.Rule -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.core.api.EditorConfigDefaults import com.pinterest.ktlint.core.api.EditorConfigDefaults.Companion.EMPTY_EDITOR_CONFIG_DEFAULTS import com.pinterest.ktlint.core.api.EditorConfigOverride import com.pinterest.ktlint.core.api.EditorConfigOverride.Companion.EMPTY_EDITOR_CONFIG_OVERRIDE import com.pinterest.ktlint.core.api.EditorConfigProperties import com.pinterest.ktlint.core.api.UsesEditorConfigProperties +import com.pinterest.ktlint.core.api.editorconfig.EditorConfigProperty import com.pinterest.ktlint.core.initKtLintKLogger import com.pinterest.ktlint.core.internal.ThreadSafeEditorConfigCache.Companion.THREAD_SAFE_EDITOR_CONFIG_CACHE import java.nio.charset.StandardCharsets @@ -58,8 +58,8 @@ public class EditorConfigLoader( .queryProperties(normalizedFilePath.resource()) .properties .also { loaded -> - if (loaded[TAB_WIDTH_PROPERTY_NAME]?.sourceValue == loaded[INDENT_SIZE_PROPERTY.name]?.sourceValue && - editorConfigOverride.properties[INDENT_SIZE_PROPERTY] != null + if (loaded[TAB_WIDTH_PROPERTY_NAME]?.sourceValue == loaded[com.pinterest.ktlint.core.api.editorconfig.INDENT_SIZE_PROPERTY.name]?.sourceValue && + editorConfigOverride.properties[com.pinterest.ktlint.core.api.editorconfig.INDENT_SIZE_PROPERTY] != null ) { // The tab_width property can not be overridden via the editorConfigOverride. So if it has been // set to the same value as the indent_size property then keep its value in sync with that @@ -68,7 +68,7 @@ public class EditorConfigLoader( .builder() .name(TAB_WIDTH_PROPERTY_NAME) .type(PropertyType.tab_width) - .value(editorConfigOverride.properties[INDENT_SIZE_PROPERTY]?.source) + .value(editorConfigOverride.properties[com.pinterest.ktlint.core.api.editorconfig.INDENT_SIZE_PROPERTY]?.source) .build() } editorConfigOverride @@ -93,7 +93,7 @@ public class EditorConfigLoader( Resource.Resources.ofPath(this, StandardCharsets.UTF_8) private fun property( - property: UsesEditorConfigProperties.EditorConfigProperty<*>, + property: EditorConfigProperty<*>, value: PropertyType.PropertyValue<*>, ) = Property .builder() diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/VisitorProvider.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/VisitorProvider.kt index 26826f2ac8..88c73eb3b5 100644 --- a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/VisitorProvider.kt +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/VisitorProvider.kt @@ -1,16 +1,14 @@ package com.pinterest.ktlint.core.internal import com.pinterest.ktlint.core.Rule -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.DISABLED_RULES_PROPERTY -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.KTLINT_DISABLED_RULES_PROPERTY -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.RULE_EXECUTION_PROPERTY_TYPE -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.RuleExecution -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.createRuleExecutionEditorConfigProperty -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.ktLintRuleExecutionPropertyName -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.ktLintRuleSetExecutionPropertyName import com.pinterest.ktlint.core.api.EditorConfigProperties import com.pinterest.ktlint.core.api.UsesEditorConfigProperties -import com.pinterest.ktlint.core.api.UsesEditorConfigProperties.EditorConfigProperty +import com.pinterest.ktlint.core.api.editorconfig.EditorConfigProperty +import com.pinterest.ktlint.core.api.editorconfig.RULE_EXECUTION_PROPERTY_TYPE +import com.pinterest.ktlint.core.api.editorconfig.RuleExecution +import com.pinterest.ktlint.core.api.editorconfig.createRuleExecutionEditorConfigProperty +import com.pinterest.ktlint.core.api.editorconfig.ktLintRuleExecutionPropertyName +import com.pinterest.ktlint.core.api.editorconfig.ktLintRuleSetExecutionPropertyName import com.pinterest.ktlint.core.initKtLintKLogger import mu.KotlinLogging @@ -31,8 +29,8 @@ internal class VisitorProvider( recreateRuleSorter: Boolean = false, ) : UsesEditorConfigProperties { override val editorConfigProperties: List> = listOf( - KTLINT_DISABLED_RULES_PROPERTY, - DISABLED_RULES_PROPERTY, + com.pinterest.ktlint.core.api.editorconfig.KTLINT_DISABLED_RULES_PROPERTY, + com.pinterest.ktlint.core.api.editorconfig.DISABLED_RULES_PROPERTY, ).plus( ruleRunners.map { createRuleExecutionEditorConfigProperty(toQualifiedRuleId(it.ruleSetId, it.ruleId)) @@ -98,11 +96,17 @@ internal class VisitorProvider( editorConfigProperties.containsKey(ktLintRuleSetExecutionPropertyName(qualifiedRuleId)) -> editorConfigProperties.isRuleEnabled(qualifiedRuleId) - editorConfigProperties.containsKey(KTLINT_DISABLED_RULES_PROPERTY.name) -> - editorConfigProperties.isEnabled(KTLINT_DISABLED_RULES_PROPERTY, qualifiedRuleId) + editorConfigProperties.containsKey(com.pinterest.ktlint.core.api.editorconfig.KTLINT_DISABLED_RULES_PROPERTY.name) -> + editorConfigProperties.isEnabled( + com.pinterest.ktlint.core.api.editorconfig.KTLINT_DISABLED_RULES_PROPERTY, + qualifiedRuleId, + ) - editorConfigProperties.containsKey(DISABLED_RULES_PROPERTY.name) -> - editorConfigProperties.isEnabled(DISABLED_RULES_PROPERTY, qualifiedRuleId) + editorConfigProperties.containsKey(com.pinterest.ktlint.core.api.editorconfig.DISABLED_RULES_PROPERTY.name) -> + editorConfigProperties.isEnabled( + com.pinterest.ktlint.core.api.editorconfig.DISABLED_RULES_PROPERTY, + qualifiedRuleId, + ) else -> ruleSetId(qualifiedRuleId) == "standard" diff --git a/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/DisabledRulesTest.kt b/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/DisabledRulesTest.kt index 5e4e55b49f..f1f4864bc8 100644 --- a/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/DisabledRulesTest.kt +++ b/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/DisabledRulesTest.kt @@ -1,10 +1,8 @@ package com.pinterest.ktlint.core -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.DISABLED_RULES_PROPERTY -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.KTLINT_DISABLED_RULES_PROPERTY -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.RuleExecution -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.createRuleExecutionEditorConfigProperty import com.pinterest.ktlint.core.api.EditorConfigOverride +import com.pinterest.ktlint.core.api.editorconfig.RuleExecution +import com.pinterest.ktlint.core.api.editorconfig.createRuleExecutionEditorConfigProperty import com.pinterest.ktlint.core.ast.ElementType import org.assertj.core.api.Assertions.assertThat import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -52,7 +50,7 @@ class DisabledRulesTest { ruleProviders = setOf( RuleProvider { NoVarRule(ruleId) }, ), - editorConfigOverride = EditorConfigOverride.from(DISABLED_RULES_PROPERTY to disabledRuleId), + editorConfigOverride = EditorConfigOverride.from(com.pinterest.ktlint.core.api.editorconfig.DISABLED_RULES_PROPERTY to disabledRuleId), ).lint("var foo") { e -> add(e) } }, ).isEmpty() @@ -80,7 +78,7 @@ class DisabledRulesTest { ruleProviders = setOf( RuleProvider { NoVarRule(ruleId) }, ), - editorConfigOverride = EditorConfigOverride.from(KTLINT_DISABLED_RULES_PROPERTY to disabledRuleId), + editorConfigOverride = EditorConfigOverride.from(com.pinterest.ktlint.core.api.editorconfig.KTLINT_DISABLED_RULES_PROPERTY to disabledRuleId), ).lint("var foo") { e -> add(e) } }, ).isEmpty() diff --git a/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/KtLintTest.kt b/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/KtLintTest.kt index fe3787397e..89d0477b14 100644 --- a/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/KtLintTest.kt +++ b/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/KtLintTest.kt @@ -12,6 +12,7 @@ import com.pinterest.ktlint.core.RuleExecutionCall.VisitNodeType.CHILD import com.pinterest.ktlint.core.RuleExecutionCall.VisitNodeType.ROOT import com.pinterest.ktlint.core.api.EditorConfigProperties import com.pinterest.ktlint.core.api.UsesEditorConfigProperties +import com.pinterest.ktlint.core.api.editorconfig.EditorConfigProperty import com.pinterest.ktlint.core.ast.ElementType.CLASS import com.pinterest.ktlint.core.ast.ElementType.FILE import com.pinterest.ktlint.core.ast.ElementType.IDENTIFIER @@ -1095,14 +1096,14 @@ class KtLintLegacyTest { private class DummyRuleWithCustomEditorConfigProperty : Rule("dummy-rule-with-custom-editor-config-property"), UsesEditorConfigProperties { - override val editorConfigProperties: List> = + override val editorConfigProperties: List> = listOf(SOME_CUSTOM_RULE_PROPERTY) companion object { const val SOME_CUSTOM_RULE_PROPERTY_NAME = "some-custom-rule-property" - val SOME_CUSTOM_RULE_PROPERTY: UsesEditorConfigProperties.EditorConfigProperty = - UsesEditorConfigProperties.EditorConfigProperty( + val SOME_CUSTOM_RULE_PROPERTY: EditorConfigProperty = + EditorConfigProperty( name = SOME_CUSTOM_RULE_PROPERTY_NAME, type = PropertyType.LowerCasingPropertyType( SOME_CUSTOM_RULE_PROPERTY_NAME, diff --git a/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/VisitorProviderTest.kt b/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/VisitorProviderTest.kt index 16b8bf47e9..8f60356285 100644 --- a/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/VisitorProviderTest.kt +++ b/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/VisitorProviderTest.kt @@ -1,9 +1,7 @@ package com.pinterest.ktlint.core -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.DISABLED_RULES_PROPERTY -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.KTLINT_DISABLED_RULES_PROPERTY -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.RuleExecution +import com.pinterest.ktlint.core.api.editorconfig.RULE_EXECUTION_PROPERTY_TYPE +import com.pinterest.ktlint.core.api.editorconfig.RuleExecution import com.pinterest.ktlint.core.internal.RuleRunner import com.pinterest.ktlint.core.internal.VisitorProvider import org.assertj.core.api.Assertions.assertThat @@ -105,7 +103,7 @@ class VisitorProviderTest { } private fun ktlintDisabledRulesEditorConfigProperties(vararg ruleIds: String) = - with(DISABLED_RULES_PROPERTY) { + with(com.pinterest.ktlint.core.api.editorconfig.DISABLED_RULES_PROPERTY) { mapOf( name to Property.builder() @@ -209,7 +207,7 @@ class VisitorProviderTest { } private fun ktlintDisabledRulesEditorConfigProperties(vararg ruleIds: String) = - with(KTLINT_DISABLED_RULES_PROPERTY) { + with(com.pinterest.ktlint.core.api.editorconfig.KTLINT_DISABLED_RULES_PROPERTY) { mapOf( name to Property.builder() @@ -432,7 +430,7 @@ class VisitorProviderTest { .let { propertyName -> propertyName to Property.builder() .name(propertyName) - .type(DefaultEditorConfigProperties.RULE_EXECUTION_PROPERTY_TYPE) + .type(RULE_EXECUTION_PROPERTY_TYPE) .value(ruleExecution.name) .build() } diff --git a/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/internal/EditorConfigGeneratorTest.kt b/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/internal/EditorConfigGeneratorTest.kt index 1c94973b4c..0d10de5b17 100644 --- a/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/internal/EditorConfigGeneratorTest.kt +++ b/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/internal/EditorConfigGeneratorTest.kt @@ -3,11 +3,9 @@ package com.pinterest.ktlint.core.internal import com.google.common.jimfs.Configuration import com.google.common.jimfs.Jimfs import com.pinterest.ktlint.core.Rule -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.CodeStyleValue.android -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.CodeStyleValue.official -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.DISABLED_RULES_PROPERTY -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.KTLINT_DISABLED_RULES_PROPERTY import com.pinterest.ktlint.core.api.UsesEditorConfigProperties +import com.pinterest.ktlint.core.api.editorconfig.CodeStyleValue +import com.pinterest.ktlint.core.api.editorconfig.EditorConfigProperty import java.nio.file.FileSystem import java.nio.file.Files import java.nio.file.Path @@ -29,7 +27,7 @@ internal class EditorConfigGeneratorTest { val generatedEditorConfig = editorConfigGenerator.generateEditorconfig( filePath = tempFileSystem.normalizedPath(rootDir).resolve("test.kt"), rules = emptySet(), - codeStyle = official, + codeStyle = CodeStyleValue.official, ) assertThat(generatedEditorConfig.lines()).containsExactly( @@ -39,8 +37,8 @@ internal class EditorConfigGeneratorTest { "ktlint_code_style = official", "max_line_length = -1", ).doesNotContain( - "${DISABLED_RULES_PROPERTY.name} = ", - "${KTLINT_DISABLED_RULES_PROPERTY.name} = ", + "${com.pinterest.ktlint.core.api.editorconfig.DISABLED_RULES_PROPERTY.name} = ", + "${com.pinterest.ktlint.core.api.editorconfig.KTLINT_DISABLED_RULES_PROPERTY.name} = ", ) } @@ -56,7 +54,7 @@ internal class EditorConfigGeneratorTest { val generatedEditorConfig = editorConfigGenerator.generateEditorconfig( filePath = tempFileSystem.normalizedPath(rootDir).resolve("test.kt"), rules = rules, - codeStyle = official, + codeStyle = CodeStyleValue.official, ) assertThat(generatedEditorConfig.lines()).doesNotContainAnyElementsOf(listOf("root = true")) @@ -71,7 +69,7 @@ internal class EditorConfigGeneratorTest { val generatedEditorConfig = editorConfigGenerator.generateEditorconfig( filePath = tempFileSystem.normalizedPath(rootDir).resolve("test.kt"), rules = rules, - codeStyle = android, + codeStyle = CodeStyleValue.android, ) assertThat(generatedEditorConfig.lines()).contains( @@ -89,18 +87,18 @@ internal class EditorConfigGeneratorTest { filePath = tempFileSystem.normalizedPath(rootDir).resolve("test.kt"), rules = setOf( object : TestRule("test-rule-two"), UsesEditorConfigProperties { - override val editorConfigProperties: List> = listOf( + override val editorConfigProperties: List> = listOf( EDITOR_CONFIG_PROPERTY_2, EDITOR_CONFIG_PROPERTY_1, ) }, object : TestRule("test-rule-two"), UsesEditorConfigProperties { - override val editorConfigProperties: List> = listOf( + override val editorConfigProperties: List> = listOf( EDITOR_CONFIG_PROPERTY_1, ) }, ), - codeStyle = official, + codeStyle = CodeStyleValue.official, ) assertThat(generatedEditorConfig.lines()).contains( @@ -115,17 +113,17 @@ internal class EditorConfigGeneratorTest { filePath = tempFileSystem.normalizedPath(rootDir).resolve("test.kt"), rules = setOf( object : TestRule("test-rule-two"), UsesEditorConfigProperties { - override val editorConfigProperties: List> = listOf( + override val editorConfigProperties: List> = listOf( EDITOR_CONFIG_PROPERTY_3_WITH_DEFAULT_VALUE_A, ) }, object : TestRule("test-rule-two"), UsesEditorConfigProperties { - override val editorConfigProperties: List> = listOf( + override val editorConfigProperties: List> = listOf( EDITOR_CONFIG_PROPERTY_3_WITH_DEFAULT_VALUE_B, ) }, ), - codeStyle = official, + codeStyle = CodeStyleValue.official, ) assertThat(generatedEditorConfig.lines()).contains( @@ -150,7 +148,7 @@ internal class EditorConfigGeneratorTest { val generatedEditorConfig = editorConfigGenerator.generateEditorconfig( filePath = tempFileSystem.normalizedPath(rootDir).resolve("test.kt"), rules = rules, - codeStyle = official, + codeStyle = CodeStyleValue.official, ) assertThat(generatedEditorConfig.lines()).doesNotContainAnyElementsOf(listOf("root = true")) @@ -174,7 +172,7 @@ internal class EditorConfigGeneratorTest { val generatedEditorConfig = editorConfigGenerator.generateEditorconfig( filePath = tempFileSystem.normalizedPath(rootDir).resolve("test.kt"), rules = rules, - codeStyle = official, + codeStyle = CodeStyleValue.official, ) assertThat(generatedEditorConfig.lines()).doesNotContainAnyElementsOf(listOf("root = true")) @@ -200,7 +198,7 @@ internal class EditorConfigGeneratorTest { } private class TestRule1 : TestRule("test-rule-one"), UsesEditorConfigProperties { - override val editorConfigProperties: List> = listOf( + override val editorConfigProperties: List> = listOf( EDITOR_CONFIG_PROPERTY_2, EDITOR_CONFIG_PROPERTY_1, ) @@ -226,7 +224,7 @@ internal class EditorConfigGeneratorTest { const val PROPERTY_3_NAME = "property-3" const val PROPERTY_3_VALUE_A = "default-value-a" const val PROPERTY_3_VALUE_B = "default-value-b" - val EDITOR_CONFIG_PROPERTY_1 = UsesEditorConfigProperties.EditorConfigProperty( + val EDITOR_CONFIG_PROPERTY_1 = EditorConfigProperty( name = PROPERTY_1_NAME, type = PropertyType( PROPERTY_1_NAME, @@ -237,7 +235,7 @@ internal class EditorConfigGeneratorTest { defaultValue = PROPERTY_1_DEFAULT_VALUE, defaultAndroidValue = PROPERTY_1_DEFAULT_VALUE_ANDROID, ) - val EDITOR_CONFIG_PROPERTY_2 = UsesEditorConfigProperties.EditorConfigProperty( + val EDITOR_CONFIG_PROPERTY_2 = EditorConfigProperty( name = PROPERTY_2_NAME, type = PropertyType( PROPERTY_2_NAME, @@ -248,7 +246,7 @@ internal class EditorConfigGeneratorTest { defaultValue = PROPERTY_2_DEFAULT_VALUE, defaultAndroidValue = PROPERTY_2_DEFAULT_VALUE_ANDROID, ) - val EDITOR_CONFIG_PROPERTY_3_WITH_DEFAULT_VALUE_A = UsesEditorConfigProperties.EditorConfigProperty( + val EDITOR_CONFIG_PROPERTY_3_WITH_DEFAULT_VALUE_A = EditorConfigProperty( name = PROPERTY_3_NAME, type = PropertyType( PROPERTY_3_NAME, @@ -259,7 +257,7 @@ internal class EditorConfigGeneratorTest { defaultValue = PROPERTY_3_VALUE_A, ) val EDITOR_CONFIG_PROPERTY_3_WITH_DEFAULT_VALUE_B = - UsesEditorConfigProperties.EditorConfigProperty( + EditorConfigProperty( name = PROPERTY_3_NAME, type = PropertyType( PROPERTY_3_NAME, diff --git a/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/internal/EditorConfigLoaderTest.kt b/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/internal/EditorConfigLoaderTest.kt index 3099304c26..305e9d9ffe 100644 --- a/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/internal/EditorConfigLoaderTest.kt +++ b/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/internal/EditorConfigLoaderTest.kt @@ -3,11 +3,10 @@ package com.pinterest.ktlint.core.internal import com.google.common.jimfs.Configuration import com.google.common.jimfs.Jimfs import com.pinterest.ktlint.core.Rule -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.INDENT_SIZE_PROPERTY -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.INSERT_FINAL_NEWLINE_PROPERTY import com.pinterest.ktlint.core.api.EditorConfigOverride import com.pinterest.ktlint.core.api.EditorConfigProperties import com.pinterest.ktlint.core.api.UsesEditorConfigProperties +import com.pinterest.ktlint.core.api.editorconfig.EditorConfigProperty import com.pinterest.ktlint.ruleset.standard.FinalNewlineRule import java.nio.file.FileSystem import java.nio.file.Files @@ -211,7 +210,7 @@ internal class EditorConfigLoaderTest { val parsedEditorConfig = editorConfigLoader.load( filePath = null, rules = rules, - editorConfigOverride = EditorConfigOverride.from(INSERT_FINAL_NEWLINE_PROPERTY to "true"), + editorConfigOverride = EditorConfigOverride.from(com.pinterest.ktlint.core.api.editorconfig.INSERT_FINAL_NEWLINE_PROPERTY to "true"), ) assertThat(parsedEditorConfig.convertToPropertyValues()).containsExactlyInAnyOrder( @@ -224,7 +223,7 @@ internal class EditorConfigLoaderTest { val parsedEditorConfig = editorConfigLoader.load( filePath = null, rules = rules, - editorConfigOverride = EditorConfigOverride.from(INSERT_FINAL_NEWLINE_PROPERTY to "true"), + editorConfigOverride = EditorConfigOverride.from(com.pinterest.ktlint.core.api.editorconfig.INSERT_FINAL_NEWLINE_PROPERTY to "true"), ) assertThat(parsedEditorConfig.convertToPropertyValues()).containsExactlyInAnyOrder( @@ -248,7 +247,7 @@ internal class EditorConfigLoaderTest { val editorConfigProperties = editorConfigLoader.load( filePath = null, rules = rules, - editorConfigOverride = EditorConfigOverride.from(INSERT_FINAL_NEWLINE_PROPERTY to true), + editorConfigOverride = EditorConfigOverride.from(com.pinterest.ktlint.core.api.editorconfig.INSERT_FINAL_NEWLINE_PROPERTY to true), ) assertThat(editorConfigProperties.convertToPropertyValues()) @@ -295,7 +294,7 @@ internal class EditorConfigLoaderTest { .load( filePath = lintFile, rules = rules, - editorConfigOverride = EditorConfigOverride.from(INDENT_SIZE_PROPERTY to 2), + editorConfigOverride = EditorConfigOverride.from(com.pinterest.ktlint.core.api.editorconfig.INDENT_SIZE_PROPERTY to 2), ) assertThat(editorConfigProperties.convertToPropertyValues()) @@ -322,7 +321,7 @@ internal class EditorConfigLoaderTest { val editorConfigProperties = editorConfigLoader.load( filePath = null, rules = rules, - editorConfigOverride = EditorConfigOverride.from(INDENT_SIZE_PROPERTY to 2), + editorConfigOverride = EditorConfigOverride.from(com.pinterest.ktlint.core.api.editorconfig.INDENT_SIZE_PROPERTY to 2), ) assertThat(editorConfigProperties.convertToPropertyValues()).containsExactlyInAnyOrder( @@ -384,7 +383,7 @@ internal class EditorConfigLoaderTest { val editorConfigProperties = editorConfigLoader.load( lintFile, rules = rules.plus(FinalNewlineRule()), - editorConfigOverride = EditorConfigOverride.from(INSERT_FINAL_NEWLINE_PROPERTY to "true"), + editorConfigOverride = EditorConfigOverride.from(com.pinterest.ktlint.core.api.editorconfig.INSERT_FINAL_NEWLINE_PROPERTY to "true"), ) assertThat(editorConfigProperties.convertToPropertyValues()).containsExactlyInAnyOrder( @@ -413,7 +412,7 @@ internal class EditorConfigLoaderTest { val editorConfigProperties = editorConfigLoader.load( lintFile, rules = rules.plus(FinalNewlineRule()), - editorConfigOverride = EditorConfigOverride.from(INSERT_FINAL_NEWLINE_PROPERTY to "false"), + editorConfigOverride = EditorConfigOverride.from(com.pinterest.ktlint.core.api.editorconfig.INSERT_FINAL_NEWLINE_PROPERTY to "false"), ) assertThat(editorConfigProperties.convertToPropertyValues()).containsExactlyInAnyOrder( @@ -450,7 +449,7 @@ internal class EditorConfigLoaderTest { } private class TestRule : Rule("editorconfig-test"), UsesEditorConfigProperties { - override val editorConfigProperties: List> = emptyList() + override val editorConfigProperties: List> = emptyList() override fun beforeVisitChildNodes( node: ASTNode, diff --git a/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/internal/SuppressionLocatorBuilderTest.kt b/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/internal/SuppressionLocatorBuilderTest.kt index af0d2eb25a..a2699debc0 100644 --- a/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/internal/SuppressionLocatorBuilderTest.kt +++ b/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/internal/SuppressionLocatorBuilderTest.kt @@ -4,9 +4,9 @@ import com.pinterest.ktlint.core.KtLintRuleEngine import com.pinterest.ktlint.core.LintError import com.pinterest.ktlint.core.Rule import com.pinterest.ktlint.core.RuleProvider -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.RuleExecution -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.createRuleSetExecutionEditorConfigProperty import com.pinterest.ktlint.core.api.EditorConfigOverride +import com.pinterest.ktlint.core.api.editorconfig.RuleExecution +import com.pinterest.ktlint.core.api.editorconfig.createRuleSetExecutionEditorConfigProperty import com.pinterest.ktlint.core.ast.ElementType import org.assertj.core.api.Assertions.assertThat import org.jetbrains.kotlin.com.intellij.lang.ASTNode diff --git a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/CommentWrappingRule.kt b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/CommentWrappingRule.kt index 7ae4f6d3d3..244bc31dcc 100644 --- a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/CommentWrappingRule.kt +++ b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/CommentWrappingRule.kt @@ -1,8 +1,10 @@ package com.pinterest.ktlint.ruleset.experimental import com.pinterest.ktlint.core.Rule -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties import com.pinterest.ktlint.core.api.UsesEditorConfigProperties +import com.pinterest.ktlint.core.api.editorconfig.EditorConfigProperty +import com.pinterest.ktlint.core.api.editorconfig.INDENT_SIZE_PROPERTY +import com.pinterest.ktlint.core.api.editorconfig.INDENT_STYLE_PROPERTY import com.pinterest.ktlint.core.ast.ElementType.BLOCK_COMMENT import com.pinterest.ktlint.core.ast.ElementType.EOL_COMMENT import com.pinterest.ktlint.core.ast.ElementType.WHITE_SPACE @@ -22,10 +24,10 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiCommentImpl public class CommentWrappingRule : Rule("$EXPERIMENTAL_RULE_SET_ID:comment-wrapping"), UsesEditorConfigProperties { - override val editorConfigProperties: List> = + override val editorConfigProperties: List> = listOf( - DefaultEditorConfigProperties.INDENT_SIZE_PROPERTY, - DefaultEditorConfigProperties.INDENT_STYLE_PROPERTY, + INDENT_SIZE_PROPERTY, + INDENT_STYLE_PROPERTY, ) override fun beforeVisitChildNodes( diff --git a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/ContextReceiverWrappingRule.kt b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/ContextReceiverWrappingRule.kt index 830915fcd7..637b62033e 100644 --- a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/ContextReceiverWrappingRule.kt +++ b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/ContextReceiverWrappingRule.kt @@ -2,9 +2,12 @@ package com.pinterest.ktlint.ruleset.experimental import com.pinterest.ktlint.core.IndentConfig import com.pinterest.ktlint.core.Rule -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties import com.pinterest.ktlint.core.api.EditorConfigProperties import com.pinterest.ktlint.core.api.UsesEditorConfigProperties +import com.pinterest.ktlint.core.api.editorconfig.EditorConfigProperty +import com.pinterest.ktlint.core.api.editorconfig.INDENT_SIZE_PROPERTY +import com.pinterest.ktlint.core.api.editorconfig.INDENT_STYLE_PROPERTY +import com.pinterest.ktlint.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY import com.pinterest.ktlint.core.ast.ElementType.CONTEXT_RECEIVER import com.pinterest.ktlint.core.ast.ElementType.CONTEXT_RECEIVER_LIST import com.pinterest.ktlint.core.ast.ElementType.GT @@ -32,11 +35,11 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode public class ContextReceiverWrappingRule : Rule("$EXPERIMENTAL_RULE_SET_ID:context-receiver-wrapping"), UsesEditorConfigProperties { - override val editorConfigProperties: List> = + override val editorConfigProperties: List> = listOf( - DefaultEditorConfigProperties.INDENT_SIZE_PROPERTY, - DefaultEditorConfigProperties.INDENT_STYLE_PROPERTY, - DefaultEditorConfigProperties.MAX_LINE_LENGTH_PROPERTY, + INDENT_SIZE_PROPERTY, + INDENT_STYLE_PROPERTY, + MAX_LINE_LENGTH_PROPERTY, ) private lateinit var indent: String @@ -45,11 +48,11 @@ public class ContextReceiverWrappingRule : override fun beforeFirstNode(editorConfigProperties: EditorConfigProperties) { with(editorConfigProperties) { val indentConfig = IndentConfig( - indentStyle = getEditorConfigValue(DefaultEditorConfigProperties.INDENT_STYLE_PROPERTY), - tabWidth = getEditorConfigValue(DefaultEditorConfigProperties.INDENT_SIZE_PROPERTY), + indentStyle = getEditorConfigValue(INDENT_STYLE_PROPERTY), + tabWidth = getEditorConfigValue(INDENT_SIZE_PROPERTY), ) indent = indentConfig.indent - maxLineLength = getEditorConfigValue(DefaultEditorConfigProperties.MAX_LINE_LENGTH_PROPERTY) + maxLineLength = getEditorConfigValue(MAX_LINE_LENGTH_PROPERTY) } } diff --git a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/FunctionSignatureRule.kt b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/FunctionSignatureRule.kt index bf4440d1de..7bb934bf47 100644 --- a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/FunctionSignatureRule.kt +++ b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/FunctionSignatureRule.kt @@ -2,11 +2,9 @@ package com.pinterest.ktlint.ruleset.experimental import com.pinterest.ktlint.core.IndentConfig import com.pinterest.ktlint.core.Rule -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.INDENT_SIZE_PROPERTY -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.INDENT_STYLE_PROPERTY -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.MAX_LINE_LENGTH_PROPERTY import com.pinterest.ktlint.core.api.EditorConfigProperties import com.pinterest.ktlint.core.api.UsesEditorConfigProperties +import com.pinterest.ktlint.core.api.editorconfig.EditorConfigProperty import com.pinterest.ktlint.core.ast.ElementType.ANNOTATION import com.pinterest.ktlint.core.ast.ElementType.ANNOTATION_ENTRY import com.pinterest.ktlint.core.ast.ElementType.BLOCK @@ -53,11 +51,11 @@ public class FunctionSignatureRule : ), ), UsesEditorConfigProperties { - override val editorConfigProperties: List> = + override val editorConfigProperties: List> = listOf( - INDENT_SIZE_PROPERTY, - INDENT_STYLE_PROPERTY, - MAX_LINE_LENGTH_PROPERTY, + com.pinterest.ktlint.core.api.editorconfig.INDENT_SIZE_PROPERTY, + com.pinterest.ktlint.core.api.editorconfig.INDENT_STYLE_PROPERTY, + com.pinterest.ktlint.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY, FORCE_MULTILINE_WHEN_PARAMETER_COUNT_GREATER_OR_EQUAL_THAN_PROPERTY, FUNCTION_BODY_EXPRESSION_WRAPPING_PROPERTY, ) @@ -72,11 +70,11 @@ public class FunctionSignatureRule : functionSignatureWrappingMinimumParameters = getEditorConfigValue(FORCE_MULTILINE_WHEN_PARAMETER_COUNT_GREATER_OR_EQUAL_THAN_PROPERTY) functionBodyExpressionWrapping = getEditorConfigValue(FUNCTION_BODY_EXPRESSION_WRAPPING_PROPERTY) val indentConfig = IndentConfig( - indentStyle = getEditorConfigValue(INDENT_STYLE_PROPERTY), - tabWidth = getEditorConfigValue(INDENT_SIZE_PROPERTY), + indentStyle = getEditorConfigValue(com.pinterest.ktlint.core.api.editorconfig.INDENT_STYLE_PROPERTY), + tabWidth = getEditorConfigValue(com.pinterest.ktlint.core.api.editorconfig.INDENT_SIZE_PROPERTY), ) indent = indentConfig.indent - maxLineLength = getEditorConfigValue(MAX_LINE_LENGTH_PROPERTY) + maxLineLength = getEditorConfigValue(com.pinterest.ktlint.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY) } } @@ -687,8 +685,8 @@ public class FunctionSignatureRule : ?.prevCodeLeaf() public companion object { - public val FORCE_MULTILINE_WHEN_PARAMETER_COUNT_GREATER_OR_EQUAL_THAN_PROPERTY: UsesEditorConfigProperties.EditorConfigProperty = - UsesEditorConfigProperties.EditorConfigProperty( + public val FORCE_MULTILINE_WHEN_PARAMETER_COUNT_GREATER_OR_EQUAL_THAN_PROPERTY: EditorConfigProperty = + EditorConfigProperty( type = PropertyType.LowerCasingPropertyType( "ktlint_function_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than", "Force wrapping the parameters of the function signature in case it contains at least the specified " + @@ -705,11 +703,11 @@ public class FunctionSignatureRule : replaceWith = ReplaceWith("FORCE_MULTILINE_WHEN_PARAMETER_COUNT_GREATER_OR_EQUAL_THAN_PROPERTY"), ) @Suppress("ktlint:experimental:property-naming") - public val forceMultilineWhenParameterCountGreaterOrEqualThanProperty: UsesEditorConfigProperties.EditorConfigProperty = + public val forceMultilineWhenParameterCountGreaterOrEqualThanProperty: EditorConfigProperty = FORCE_MULTILINE_WHEN_PARAMETER_COUNT_GREATER_OR_EQUAL_THAN_PROPERTY - public val FUNCTION_BODY_EXPRESSION_WRAPPING_PROPERTY: UsesEditorConfigProperties.EditorConfigProperty = - UsesEditorConfigProperties.EditorConfigProperty( + public val FUNCTION_BODY_EXPRESSION_WRAPPING_PROPERTY: EditorConfigProperty = + EditorConfigProperty( type = PropertyType.LowerCasingPropertyType( "ktlint_function_signature_body_expression_wrapping", "Determines how to wrap the body of function in case it is an expression. Use 'default' " + @@ -727,7 +725,7 @@ public class FunctionSignatureRule : replaceWith = ReplaceWith("FUNCTION_BODY_EXPRESSION_WRAPPING_PROPERTY"), ) @Suppress("ktlint:experimental:property-naming") - public val functionBodyExpressionWrappingProperty: UsesEditorConfigProperties.EditorConfigProperty = + public val functionBodyExpressionWrappingProperty: EditorConfigProperty = FUNCTION_BODY_EXPRESSION_WRAPPING_PROPERTY private val INDENT_WITH_CLOSING_PARENTHESIS = Regex("\\s*\\) =") diff --git a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/KdocWrappingRule.kt b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/KdocWrappingRule.kt index 5b0d75a127..34f5e9d1ee 100644 --- a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/KdocWrappingRule.kt +++ b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/KdocWrappingRule.kt @@ -1,8 +1,10 @@ package com.pinterest.ktlint.ruleset.experimental import com.pinterest.ktlint.core.Rule -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties import com.pinterest.ktlint.core.api.UsesEditorConfigProperties +import com.pinterest.ktlint.core.api.editorconfig.EditorConfigProperty +import com.pinterest.ktlint.core.api.editorconfig.INDENT_SIZE_PROPERTY +import com.pinterest.ktlint.core.api.editorconfig.INDENT_STYLE_PROPERTY import com.pinterest.ktlint.core.ast.ElementType.KDOC import com.pinterest.ktlint.core.ast.ElementType.KDOC_END import com.pinterest.ktlint.core.ast.ElementType.KDOC_START @@ -20,10 +22,10 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode public class KdocWrappingRule : Rule("$EXPERIMENTAL_RULE_SET_ID:kdoc-wrapping"), UsesEditorConfigProperties { - override val editorConfigProperties: List> = + override val editorConfigProperties: List> = listOf( - DefaultEditorConfigProperties.INDENT_SIZE_PROPERTY, - DefaultEditorConfigProperties.INDENT_STYLE_PROPERTY, + INDENT_SIZE_PROPERTY, + INDENT_STYLE_PROPERTY, ) override fun beforeVisitChildNodes( diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ArgumentListWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ArgumentListWrappingRule.kt index 85cf1e663d..3c911a15b6 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ArgumentListWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ArgumentListWrappingRule.kt @@ -2,11 +2,9 @@ package com.pinterest.ktlint.ruleset.standard import com.pinterest.ktlint.core.IndentConfig import com.pinterest.ktlint.core.Rule -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.INDENT_SIZE_PROPERTY -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.INDENT_STYLE_PROPERTY -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.MAX_LINE_LENGTH_PROPERTY import com.pinterest.ktlint.core.api.EditorConfigProperties import com.pinterest.ktlint.core.api.UsesEditorConfigProperties +import com.pinterest.ktlint.core.api.editorconfig.EditorConfigProperty import com.pinterest.ktlint.core.ast.ElementType import com.pinterest.ktlint.core.ast.ElementType.ELSE import com.pinterest.ktlint.core.ast.ElementType.VALUE_ARGUMENT_LIST @@ -50,11 +48,11 @@ public class ArgumentListWrappingRule : ), ), UsesEditorConfigProperties { - override val editorConfigProperties: List> = + override val editorConfigProperties: List> = listOf( - INDENT_SIZE_PROPERTY, - INDENT_STYLE_PROPERTY, - MAX_LINE_LENGTH_PROPERTY, + com.pinterest.ktlint.core.api.editorconfig.INDENT_SIZE_PROPERTY, + com.pinterest.ktlint.core.api.editorconfig.INDENT_STYLE_PROPERTY, + com.pinterest.ktlint.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY, ) private var editorConfigIndent = IndentConfig.DEFAULT_INDENT_CONFIG @@ -63,10 +61,10 @@ public class ArgumentListWrappingRule : override fun beforeFirstNode(editorConfigProperties: EditorConfigProperties) { editorConfigIndent = IndentConfig( - indentStyle = editorConfigProperties.getEditorConfigValue(INDENT_STYLE_PROPERTY), - tabWidth = editorConfigProperties.getEditorConfigValue(INDENT_SIZE_PROPERTY), + indentStyle = editorConfigProperties.getEditorConfigValue(com.pinterest.ktlint.core.api.editorconfig.INDENT_STYLE_PROPERTY), + tabWidth = editorConfigProperties.getEditorConfigValue(com.pinterest.ktlint.core.api.editorconfig.INDENT_SIZE_PROPERTY), ) - maxLineLength = editorConfigProperties.getEditorConfigValue(MAX_LINE_LENGTH_PROPERTY) + maxLineLength = editorConfigProperties.getEditorConfigValue(com.pinterest.ktlint.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY) } override fun beforeVisitChildNodes( diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ChainWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ChainWrappingRule.kt index e8a94772e4..72ecc824d9 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ChainWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ChainWrappingRule.kt @@ -2,9 +2,11 @@ package com.pinterest.ktlint.ruleset.standard import com.pinterest.ktlint.core.IndentConfig import com.pinterest.ktlint.core.Rule -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties import com.pinterest.ktlint.core.api.EditorConfigProperties import com.pinterest.ktlint.core.api.UsesEditorConfigProperties +import com.pinterest.ktlint.core.api.editorconfig.EditorConfigProperty +import com.pinterest.ktlint.core.api.editorconfig.INDENT_SIZE_PROPERTY +import com.pinterest.ktlint.core.api.editorconfig.INDENT_STYLE_PROPERTY import com.pinterest.ktlint.core.ast.ElementType.ANDAND import com.pinterest.ktlint.core.ast.ElementType.COMMA import com.pinterest.ktlint.core.ast.ElementType.DIV @@ -42,10 +44,10 @@ import org.jetbrains.kotlin.psi.psiUtil.leaves public class ChainWrappingRule : Rule("chain-wrapping"), UsesEditorConfigProperties { - override val editorConfigProperties: List> = + override val editorConfigProperties: List> = listOf( - DefaultEditorConfigProperties.INDENT_SIZE_PROPERTY, - DefaultEditorConfigProperties.INDENT_STYLE_PROPERTY, + INDENT_SIZE_PROPERTY, + INDENT_STYLE_PROPERTY, ) private var indent: String? = null @@ -57,8 +59,8 @@ public class ChainWrappingRule : override fun beforeFirstNode(editorConfigProperties: EditorConfigProperties) { with(editorConfigProperties) { val indentConfig = IndentConfig( - indentStyle = getEditorConfigValue(com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.INDENT_STYLE_PROPERTY), - tabWidth = getEditorConfigValue(com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.INDENT_SIZE_PROPERTY), + indentStyle = getEditorConfigValue(INDENT_STYLE_PROPERTY), + tabWidth = getEditorConfigValue(INDENT_SIZE_PROPERTY), ) indent = indentConfig.indent } diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/FinalNewlineRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/FinalNewlineRule.kt index d488146d67..aaf9d7b838 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/FinalNewlineRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/FinalNewlineRule.kt @@ -1,9 +1,9 @@ package com.pinterest.ktlint.ruleset.standard import com.pinterest.ktlint.core.Rule -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.INSERT_FINAL_NEWLINE_PROPERTY import com.pinterest.ktlint.core.api.EditorConfigProperties import com.pinterest.ktlint.core.api.UsesEditorConfigProperties +import com.pinterest.ktlint.core.api.editorconfig.EditorConfigProperty import com.pinterest.ktlint.core.ast.isRoot import kotlin.properties.Delegates import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -14,14 +14,14 @@ public class FinalNewlineRule : Rule("final-newline"), UsesEditorConfigProperties { - override val editorConfigProperties: List> = listOf( - INSERT_FINAL_NEWLINE_PROPERTY, + override val editorConfigProperties: List> = listOf( + com.pinterest.ktlint.core.api.editorconfig.INSERT_FINAL_NEWLINE_PROPERTY, ) private var insertFinalNewline by Delegates.notNull() override fun beforeFirstNode(editorConfigProperties: EditorConfigProperties) { - insertFinalNewline = editorConfigProperties.getEditorConfigValue(INSERT_FINAL_NEWLINE_PROPERTY) + insertFinalNewline = editorConfigProperties.getEditorConfigValue(com.pinterest.ktlint.core.api.editorconfig.INSERT_FINAL_NEWLINE_PROPERTY) } override fun beforeVisitChildNodes( diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ImportOrderingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ImportOrderingRule.kt index 45fbae3881..0a77b81e5e 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ImportOrderingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ImportOrderingRule.kt @@ -3,6 +3,7 @@ package com.pinterest.ktlint.ruleset.standard import com.pinterest.ktlint.core.Rule import com.pinterest.ktlint.core.api.EditorConfigProperties import com.pinterest.ktlint.core.api.UsesEditorConfigProperties +import com.pinterest.ktlint.core.api.editorconfig.EditorConfigProperty import com.pinterest.ktlint.core.ast.ElementType import com.pinterest.ktlint.core.initKtLintKLogger import com.pinterest.ktlint.ruleset.standard.ImportOrderingRule.Companion.ASCII_PATTERN @@ -40,7 +41,7 @@ public class ImportOrderingRule : Rule("import-ordering"), UsesEditorConfigProperties { - override val editorConfigProperties: List> = listOf( + override val editorConfigProperties: List> = listOf( IJ_KOTLIN_IMPORTS_LAYOUT_PROPERTY, ) @@ -240,8 +241,8 @@ public class ImportOrderingRule : } } - public val IJ_KOTLIN_IMPORTS_LAYOUT_PROPERTY: UsesEditorConfigProperties.EditorConfigProperty> = - UsesEditorConfigProperties.EditorConfigProperty>( + public val IJ_KOTLIN_IMPORTS_LAYOUT_PROPERTY: EditorConfigProperty> = + EditorConfigProperty>( type = PropertyType( "ij_kotlin_imports_layout", "Defines imports order layout for Kotlin files", @@ -257,7 +258,7 @@ public class ImportOrderingRule : replaceWith = ReplaceWith("IJ_KOTLIN_IMPORTS_LAYOUT_PROPERTY"), ) @Suppress("ktlint:experimental:property-naming") - public val ideaImportsLayoutProperty: UsesEditorConfigProperties.EditorConfigProperty> = + public val ideaImportsLayoutProperty: EditorConfigProperty> = IJ_KOTLIN_IMPORTS_LAYOUT_PROPERTY } } diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/IndentationRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/IndentationRule.kt index eab2f0064d..673190cfe8 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/IndentationRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/IndentationRule.kt @@ -4,10 +4,9 @@ import com.pinterest.ktlint.core.IndentConfig import com.pinterest.ktlint.core.IndentConfig.IndentStyle.SPACE import com.pinterest.ktlint.core.IndentConfig.IndentStyle.TAB import com.pinterest.ktlint.core.Rule -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.INDENT_SIZE_PROPERTY -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.INDENT_STYLE_PROPERTY import com.pinterest.ktlint.core.api.EditorConfigProperties import com.pinterest.ktlint.core.api.UsesEditorConfigProperties +import com.pinterest.ktlint.core.api.editorconfig.EditorConfigProperty import com.pinterest.ktlint.core.ast.ElementType.ANNOTATED_EXPRESSION import com.pinterest.ktlint.core.ast.ElementType.ANNOTATION import com.pinterest.ktlint.core.ast.ElementType.ANNOTATION_ENTRY @@ -121,10 +120,10 @@ public class IndentationRule : ), ), UsesEditorConfigProperties { - override val editorConfigProperties: List> = + override val editorConfigProperties: List> = listOf( - INDENT_SIZE_PROPERTY, - INDENT_STYLE_PROPERTY, + com.pinterest.ktlint.core.api.editorconfig.INDENT_SIZE_PROPERTY, + com.pinterest.ktlint.core.api.editorconfig.INDENT_STYLE_PROPERTY, ) private var indentConfig = IndentConfig.DEFAULT_INDENT_CONFIG @@ -136,8 +135,8 @@ public class IndentationRule : override fun beforeFirstNode(editorConfigProperties: EditorConfigProperties) { indentConfig = IndentConfig( - indentStyle = editorConfigProperties.getEditorConfigValue(INDENT_STYLE_PROPERTY), - tabWidth = editorConfigProperties.getEditorConfigValue(INDENT_SIZE_PROPERTY), + indentStyle = editorConfigProperties.getEditorConfigValue(com.pinterest.ktlint.core.api.editorconfig.INDENT_STYLE_PROPERTY), + tabWidth = editorConfigProperties.getEditorConfigValue(com.pinterest.ktlint.core.api.editorconfig.INDENT_SIZE_PROPERTY), ) if (indentConfig.disabled) { stopTraversalOfAST() diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/MaxLineLengthRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/MaxLineLengthRule.kt index 5457ac4081..f48149a1e5 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/MaxLineLengthRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/MaxLineLengthRule.kt @@ -1,9 +1,9 @@ package com.pinterest.ktlint.ruleset.standard import com.pinterest.ktlint.core.Rule -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.MAX_LINE_LENGTH_PROPERTY import com.pinterest.ktlint.core.api.EditorConfigProperties import com.pinterest.ktlint.core.api.UsesEditorConfigProperties +import com.pinterest.ktlint.core.api.editorconfig.EditorConfigProperty import com.pinterest.ktlint.core.ast.ElementType import com.pinterest.ktlint.core.ast.isPartOf import com.pinterest.ktlint.core.ast.isRoot @@ -45,18 +45,18 @@ public class MaxLineLengthRule : ), UsesEditorConfigProperties { - override val editorConfigProperties: List> = listOf( - MAX_LINE_LENGTH_PROPERTY, + override val editorConfigProperties: List> = listOf( + com.pinterest.ktlint.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY, IGNORE_BACKTICKED_IDENTIFIER_PROPERTY, ) - private var maxLineLength: Int = MAX_LINE_LENGTH_PROPERTY.defaultValue + private var maxLineLength: Int = com.pinterest.ktlint.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY.defaultValue private var rangeTree = RangeTree() private var ignoreBackTickedIdentifier by Delegates.notNull() override fun beforeFirstNode(editorConfigProperties: EditorConfigProperties) { ignoreBackTickedIdentifier = editorConfigProperties.getEditorConfigValue(IGNORE_BACKTICKED_IDENTIFIER_PROPERTY) - maxLineLength = editorConfigProperties.getEditorConfigValue(MAX_LINE_LENGTH_PROPERTY) + maxLineLength = editorConfigProperties.getEditorConfigValue(com.pinterest.ktlint.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY) } override fun beforeVisitChildNodes( @@ -116,8 +116,8 @@ public class MaxLineLengthRule : ?.let { it.firstChildNode.text == "\"\"\"" && it.textContains('\n') } == true public companion object { - public val IGNORE_BACKTICKED_IDENTIFIER_PROPERTY: UsesEditorConfigProperties.EditorConfigProperty = - UsesEditorConfigProperties.EditorConfigProperty( + public val IGNORE_BACKTICKED_IDENTIFIER_PROPERTY: EditorConfigProperty = + EditorConfigProperty( type = PropertyType.LowerCasingPropertyType( "ktlint_ignore_back_ticked_identifier", "Defines whether the backticked identifier (``) should be ignored", @@ -132,7 +132,7 @@ public class MaxLineLengthRule : replaceWith = ReplaceWith("IGNORE_BACKTICKED_IDENTIFIER_PROPERTY"), ) @Suppress("ktlint:experimental:property-naming") - public val ignoreBackTickedIdentifierProperty: UsesEditorConfigProperties.EditorConfigProperty = + public val ignoreBackTickedIdentifierProperty: EditorConfigProperty = IGNORE_BACKTICKED_IDENTIFIER_PROPERTY } } diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/MultiLineIfElseRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/MultiLineIfElseRule.kt index f4a5c2fc0b..6408a70723 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/MultiLineIfElseRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/MultiLineIfElseRule.kt @@ -2,9 +2,11 @@ package com.pinterest.ktlint.ruleset.standard import com.pinterest.ktlint.core.IndentConfig import com.pinterest.ktlint.core.Rule -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties import com.pinterest.ktlint.core.api.EditorConfigProperties import com.pinterest.ktlint.core.api.UsesEditorConfigProperties +import com.pinterest.ktlint.core.api.editorconfig.EditorConfigProperty +import com.pinterest.ktlint.core.api.editorconfig.INDENT_SIZE_PROPERTY +import com.pinterest.ktlint.core.api.editorconfig.INDENT_STYLE_PROPERTY import com.pinterest.ktlint.core.ast.ElementType.BLOCK import com.pinterest.ktlint.core.ast.ElementType.ELSE import com.pinterest.ktlint.core.ast.ElementType.ELSE_KEYWORD @@ -31,17 +33,17 @@ import org.jetbrains.kotlin.psi.psiUtil.leaves public class MultiLineIfElseRule : Rule("multiline-if-else"), UsesEditorConfigProperties { - override val editorConfigProperties: List> = + override val editorConfigProperties: List> = listOf( - DefaultEditorConfigProperties.INDENT_SIZE_PROPERTY, - DefaultEditorConfigProperties.INDENT_STYLE_PROPERTY, + INDENT_SIZE_PROPERTY, + INDENT_STYLE_PROPERTY, ) private var indentConfig = IndentConfig.DEFAULT_INDENT_CONFIG override fun beforeFirstNode(editorConfigProperties: EditorConfigProperties) { indentConfig = IndentConfig( - indentStyle = editorConfigProperties.getEditorConfigValue(DefaultEditorConfigProperties.INDENT_STYLE_PROPERTY), - tabWidth = editorConfigProperties.getEditorConfigValue(DefaultEditorConfigProperties.INDENT_SIZE_PROPERTY), + indentStyle = editorConfigProperties.getEditorConfigValue(INDENT_STYLE_PROPERTY), + tabWidth = editorConfigProperties.getEditorConfigValue(INDENT_SIZE_PROPERTY), ) } diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoWildcardImportsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoWildcardImportsRule.kt index d459ed8950..090720a3e8 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoWildcardImportsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoWildcardImportsRule.kt @@ -3,6 +3,7 @@ package com.pinterest.ktlint.ruleset.standard import com.pinterest.ktlint.core.Rule import com.pinterest.ktlint.core.api.EditorConfigProperties import com.pinterest.ktlint.core.api.UsesEditorConfigProperties +import com.pinterest.ktlint.core.api.editorconfig.EditorConfigProperty import com.pinterest.ktlint.core.ast.ElementType.IMPORT_DIRECTIVE import com.pinterest.ktlint.ruleset.standard.internal.importordering.PatternEntry import org.ec4j.core.model.PropertyType @@ -12,7 +13,7 @@ import org.jetbrains.kotlin.psi.KtImportDirective public class NoWildcardImportsRule : Rule("no-wildcard-imports"), UsesEditorConfigProperties { - override val editorConfigProperties: List> = listOf( + override val editorConfigProperties: List> = listOf( IJ_KOTLIN_PACKAGES_TO_USE_IMPORT_ON_DEMAND, ) @@ -78,13 +79,19 @@ public class NoWildcardImportsRule : } } - public val IJ_KOTLIN_PACKAGES_TO_USE_IMPORT_ON_DEMAND: UsesEditorConfigProperties.EditorConfigProperty> = - UsesEditorConfigProperties.EditorConfigProperty( + public val IJ_KOTLIN_PACKAGES_TO_USE_IMPORT_ON_DEMAND: EditorConfigProperty> = + EditorConfigProperty( type = PropertyType( "ij_kotlin_packages_to_use_import_on_demand", "Defines allowed wildcard imports", PACKAGES_TO_USE_ON_DEMAND_IMPORT_PROPERTY_PARSER, ), + /** + * Default IntelliJ IDEA style: Use wildcard imports for packages in "java.util", "kotlin.android.synthetic" and + * it's subpackages. + * + * https://github.com/JetBrains/kotlin/blob/ffdab473e28d0d872136b910eb2e0f4beea2e19c/idea/formatter/src/org/jetbrains/kotlin/idea/core/formatter/KotlinCodeStyleSettings.java#L81-L82 + */ /** * Default IntelliJ IDEA style: Use wildcard imports for packages in "java.util", "kotlin.android.synthetic" and * it's subpackages. @@ -100,7 +107,7 @@ public class NoWildcardImportsRule : replaceWith = ReplaceWith("IJ_KOTLIN_PACKAGES_TO_USE_IMPORT_ON_DEMAND"), ) @Suppress("ktlint:experimental:property-naming") - public val packagesToUseImportOnDemandProperty: UsesEditorConfigProperties.EditorConfigProperty> = + public val packagesToUseImportOnDemandProperty: EditorConfigProperty> = IJ_KOTLIN_PACKAGES_TO_USE_IMPORT_ON_DEMAND } } diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ParameterListWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ParameterListWrappingRule.kt index bba585c748..b4de2ba277 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ParameterListWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ParameterListWrappingRule.kt @@ -2,11 +2,9 @@ package com.pinterest.ktlint.ruleset.standard import com.pinterest.ktlint.core.IndentConfig import com.pinterest.ktlint.core.Rule -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.INDENT_SIZE_PROPERTY -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.INDENT_STYLE_PROPERTY -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.MAX_LINE_LENGTH_PROPERTY import com.pinterest.ktlint.core.api.EditorConfigProperties import com.pinterest.ktlint.core.api.UsesEditorConfigProperties +import com.pinterest.ktlint.core.api.editorconfig.EditorConfigProperty import com.pinterest.ktlint.core.ast.ElementType.FUNCTION_LITERAL import com.pinterest.ktlint.core.ast.ElementType.FUNCTION_TYPE import com.pinterest.ktlint.core.ast.ElementType.LPAR @@ -34,21 +32,21 @@ import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType public class ParameterListWrappingRule : Rule("parameter-list-wrapping"), UsesEditorConfigProperties { - override val editorConfigProperties: List> = + override val editorConfigProperties: List> = listOf( - INDENT_SIZE_PROPERTY, - INDENT_STYLE_PROPERTY, - MAX_LINE_LENGTH_PROPERTY, + com.pinterest.ktlint.core.api.editorconfig.INDENT_SIZE_PROPERTY, + com.pinterest.ktlint.core.api.editorconfig.INDENT_STYLE_PROPERTY, + com.pinterest.ktlint.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY, ) private var indentConfig = IndentConfig.DEFAULT_INDENT_CONFIG private var maxLineLength = -1 override fun beforeFirstNode(editorConfigProperties: EditorConfigProperties) { - maxLineLength = editorConfigProperties.getEditorConfigValue(MAX_LINE_LENGTH_PROPERTY) + maxLineLength = editorConfigProperties.getEditorConfigValue(com.pinterest.ktlint.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY) indentConfig = IndentConfig( - indentStyle = editorConfigProperties.getEditorConfigValue(INDENT_STYLE_PROPERTY), - tabWidth = editorConfigProperties.getEditorConfigValue(INDENT_SIZE_PROPERTY), + indentStyle = editorConfigProperties.getEditorConfigValue(com.pinterest.ktlint.core.api.editorconfig.INDENT_STYLE_PROPERTY), + tabWidth = editorConfigProperties.getEditorConfigValue(com.pinterest.ktlint.core.api.editorconfig.INDENT_SIZE_PROPERTY), ) if (indentConfig.disabled) { stopTraversalOfAST() diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnCallSiteRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnCallSiteRule.kt index 9941fe8ceb..8aa841e500 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnCallSiteRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnCallSiteRule.kt @@ -3,6 +3,7 @@ package com.pinterest.ktlint.ruleset.standard import com.pinterest.ktlint.core.Rule import com.pinterest.ktlint.core.api.EditorConfigProperties import com.pinterest.ktlint.core.api.UsesEditorConfigProperties +import com.pinterest.ktlint.core.api.editorconfig.EditorConfigProperty import com.pinterest.ktlint.core.ast.ElementType import com.pinterest.ktlint.core.ast.ElementType.COLLECTION_LITERAL_EXPRESSION import com.pinterest.ktlint.core.ast.ElementType.INDICES @@ -40,7 +41,7 @@ public class TrailingCommaOnCallSiteRule : ), UsesEditorConfigProperties { - override val editorConfigProperties: List> = listOf( + override val editorConfigProperties: List> = listOf( TRAILING_COMMA_ON_CALL_SITE_PROPERTY, ) @@ -233,8 +234,8 @@ public class TrailingCommaOnCallSiteRule : public companion object { private val BOOLEAN_VALUES_SET = setOf("true", "false") - public val TRAILING_COMMA_ON_CALL_SITE_PROPERTY: UsesEditorConfigProperties.EditorConfigProperty = - UsesEditorConfigProperties.EditorConfigProperty( + public val TRAILING_COMMA_ON_CALL_SITE_PROPERTY: EditorConfigProperty = + EditorConfigProperty( type = PropertyType.LowerCasingPropertyType( "ij_kotlin_allow_trailing_comma_on_call_site", "Defines whether a trailing comma (or no trailing comma) should be enforced on the calling side," + @@ -254,7 +255,7 @@ public class TrailingCommaOnCallSiteRule : replaceWith = ReplaceWith("TRAILING_COMMA_ON_CALL_SITE_PROPERTY"), ) @Suppress("ktlint:experimental:property-naming") - public val allowTrailingCommaOnCallSiteProperty: UsesEditorConfigProperties.EditorConfigProperty = + public val allowTrailingCommaOnCallSiteProperty: EditorConfigProperty = TRAILING_COMMA_ON_CALL_SITE_PROPERTY private val TYPES_ON_CALL_SITE = TokenSet.create( diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnDeclarationSiteRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnDeclarationSiteRule.kt index 83c336ebbe..9f2ad0a2c7 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnDeclarationSiteRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnDeclarationSiteRule.kt @@ -3,6 +3,7 @@ package com.pinterest.ktlint.ruleset.standard import com.pinterest.ktlint.core.Rule import com.pinterest.ktlint.core.api.EditorConfigProperties import com.pinterest.ktlint.core.api.UsesEditorConfigProperties +import com.pinterest.ktlint.core.api.editorconfig.EditorConfigProperty import com.pinterest.ktlint.core.ast.ElementType import com.pinterest.ktlint.core.ast.ElementType.ARROW import com.pinterest.ktlint.core.ast.ElementType.CLASS @@ -63,7 +64,7 @@ public class TrailingCommaOnDeclarationSiteRule : ), UsesEditorConfigProperties { - override val editorConfigProperties: List> = listOf( + override val editorConfigProperties: List> = listOf( TRAILING_COMMA_ON_DECLARATION_SITE_PROPERTY, ) @@ -419,8 +420,8 @@ public class TrailingCommaOnDeclarationSiteRule : public companion object { private val BOOLEAN_VALUES_SET = setOf("true", "false") - public val TRAILING_COMMA_ON_DECLARATION_SITE_PROPERTY: UsesEditorConfigProperties.EditorConfigProperty = - UsesEditorConfigProperties.EditorConfigProperty( + public val TRAILING_COMMA_ON_DECLARATION_SITE_PROPERTY: EditorConfigProperty = + EditorConfigProperty( type = PropertyType.LowerCasingPropertyType( "ij_kotlin_allow_trailing_comma", "Defines whether a trailing comma (or no trailing comma) should be enforced on the defining " + @@ -440,7 +441,7 @@ public class TrailingCommaOnDeclarationSiteRule : replaceWith = ReplaceWith("TRAILING_COMMA_ON_DECLARATION_SITE_PROPERTY"), ) @Suppress("ktlint:experimental:property-naming") - public val allowTrailingCommaProperty: UsesEditorConfigProperties.EditorConfigProperty = + public val allowTrailingCommaProperty: EditorConfigProperty = TRAILING_COMMA_ON_DECLARATION_SITE_PROPERTY private val TYPES_ON_DECLARATION_SITE = TokenSet.create( diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/WrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/WrappingRule.kt index dae60dd538..d031299d39 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/WrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/WrappingRule.kt @@ -2,11 +2,9 @@ package com.pinterest.ktlint.ruleset.standard import com.pinterest.ktlint.core.IndentConfig import com.pinterest.ktlint.core.Rule -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.INDENT_SIZE_PROPERTY -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.INDENT_STYLE_PROPERTY -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.MAX_LINE_LENGTH_PROPERTY import com.pinterest.ktlint.core.api.EditorConfigProperties import com.pinterest.ktlint.core.api.UsesEditorConfigProperties +import com.pinterest.ktlint.core.api.editorconfig.EditorConfigProperty import com.pinterest.ktlint.core.ast.ElementType import com.pinterest.ktlint.core.ast.ElementType.ANNOTATION import com.pinterest.ktlint.core.ast.ElementType.ARROW @@ -81,11 +79,11 @@ private val LOGGER = KotlinLogging.logger {}.initKtLintKLogger() public class WrappingRule : Rule("wrapping"), UsesEditorConfigProperties { - override val editorConfigProperties: List> = + override val editorConfigProperties: List> = listOf( - INDENT_SIZE_PROPERTY, - INDENT_STYLE_PROPERTY, - MAX_LINE_LENGTH_PROPERTY, + com.pinterest.ktlint.core.api.editorconfig.INDENT_SIZE_PROPERTY, + com.pinterest.ktlint.core.api.editorconfig.INDENT_STYLE_PROPERTY, + com.pinterest.ktlint.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY, ) private var line = 1 @@ -95,10 +93,10 @@ public class WrappingRule : override fun beforeFirstNode(editorConfigProperties: EditorConfigProperties) { line = 1 indentConfig = IndentConfig( - indentStyle = editorConfigProperties.getEditorConfigValue(INDENT_STYLE_PROPERTY), - tabWidth = editorConfigProperties.getEditorConfigValue(INDENT_SIZE_PROPERTY), + indentStyle = editorConfigProperties.getEditorConfigValue(com.pinterest.ktlint.core.api.editorconfig.INDENT_STYLE_PROPERTY), + tabWidth = editorConfigProperties.getEditorConfigValue(com.pinterest.ktlint.core.api.editorconfig.INDENT_SIZE_PROPERTY), ) - maxLineLength = editorConfigProperties.getEditorConfigValue(MAX_LINE_LENGTH_PROPERTY) + maxLineLength = editorConfigProperties.getEditorConfigValue(com.pinterest.ktlint.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY) } override fun beforeVisitChildNodes( diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/ArgumentListWrappingRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/ArgumentListWrappingRuleTest.kt index 465d327647..af57143f4c 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/ArgumentListWrappingRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/ArgumentListWrappingRuleTest.kt @@ -1,6 +1,5 @@ package com.pinterest.ktlint.ruleset.standard -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.MAX_LINE_LENGTH_PROPERTY import com.pinterest.ktlint.test.KtLintAssertThat.Companion.EOL_CHAR import com.pinterest.ktlint.test.KtLintAssertThat.Companion.MAX_LINE_LENGTH_MARKER import com.pinterest.ktlint.test.KtLintAssertThat.Companion.assertThatRule @@ -83,7 +82,7 @@ class ArgumentListWrappingRuleTest { ) """.trimIndent() argumentListWrappingRuleAssertThat(code) - .withEditorConfigOverride(MAX_LINE_LENGTH_PROPERTY to 10) + .withEditorConfigOverride(com.pinterest.ktlint.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY to 10) .hasLintViolations( LintViolation(1, 11, "Argument should be on a separate line (unless all arguments can fit a single line)"), LintViolation(1, 14, "Argument should be on a separate line (unless all arguments can fit a single line)"), @@ -162,7 +161,7 @@ class ArgumentListWrappingRuleTest { ) """.trimIndent() argumentListWrappingRuleAssertThat(code) - .withEditorConfigOverride(MAX_LINE_LENGTH_PROPERTY to 20) + .withEditorConfigOverride(com.pinterest.ktlint.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY to 20) .hasLintViolations( LintViolation(13, 10, "Argument should be on a separate line (unless all arguments can fit a single line)"), LintViolation(13, 19, "Argument should be on a separate line (unless all arguments can fit a single line)"), @@ -298,7 +297,7 @@ class ArgumentListWrappingRuleTest { val foo = foo(1, 2, 3, 4, 5, 6, 7, 8, 9) """.trimIndent() argumentListWrappingRuleAssertThat(code) - .withEditorConfigOverride(MAX_LINE_LENGTH_PROPERTY to 20) + .withEditorConfigOverride(com.pinterest.ktlint.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY to 20) .hasNoLintViolations() } @@ -523,7 +522,7 @@ class ArgumentListWrappingRuleTest { ) """.trimIndent() argumentListWrappingRuleAssertThat(code) - .withEditorConfigOverride(MAX_LINE_LENGTH_PROPERTY to 33) + .withEditorConfigOverride(com.pinterest.ktlint.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY to 33) .hasLintViolations( LintViolation(8, 23, "Argument should be on a separate line (unless all arguments can fit a single line)"), LintViolation(8, 34, "Missing newline before \")\""), @@ -555,7 +554,7 @@ class ArgumentListWrappingRuleTest { argumentListWrappingRuleAssertThat(code) // TODO: It is not clear how the length 65 is related to the lint errors below. Starting from length 66 the // lint errors are not reported anymore. - .withEditorConfigOverride(MAX_LINE_LENGTH_PROPERTY to 65) + .withEditorConfigOverride(com.pinterest.ktlint.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY to 65) .hasLintViolations( LintViolation(4, 15, "Argument should be on a separate line (unless all arguments can fit a single line)"), LintViolation(4, 70, "Missing newline before \")\""), @@ -581,7 +580,7 @@ class ArgumentListWrappingRuleTest { argumentListWrappingRuleAssertThat(code) // TODO: With max line length of 43 or below, lint errors occur. It is not clear how that is related to // example above - .withEditorConfigOverride(MAX_LINE_LENGTH_PROPERTY to 44) + .withEditorConfigOverride(com.pinterest.ktlint.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY to 44) .hasNoLintViolations() } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/FinalNewlineRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/FinalNewlineRuleTest.kt index bb22846cca..0e24a3fd6f 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/FinalNewlineRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/FinalNewlineRuleTest.kt @@ -1,6 +1,5 @@ package com.pinterest.ktlint.ruleset.standard -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.INSERT_FINAL_NEWLINE_PROPERTY import com.pinterest.ktlint.test.KtLintAssertThat.Companion.assertThatRule import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Nested @@ -109,7 +108,8 @@ class FinalNewlineRuleTest { } private companion object { - val FINAL_NEW_LINE_REQUIRED = INSERT_FINAL_NEWLINE_PROPERTY to true - val FINAL_NEW_LINE_NOT_REQUIRED = INSERT_FINAL_NEWLINE_PROPERTY to false + val FINAL_NEW_LINE_REQUIRED = com.pinterest.ktlint.core.api.editorconfig.INSERT_FINAL_NEWLINE_PROPERTY to true + val FINAL_NEW_LINE_NOT_REQUIRED = + com.pinterest.ktlint.core.api.editorconfig.INSERT_FINAL_NEWLINE_PROPERTY to false } } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/IndentationRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/IndentationRuleTest.kt index 09220407e0..9e2044af41 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/IndentationRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/IndentationRuleTest.kt @@ -1,7 +1,5 @@ package com.pinterest.ktlint.ruleset.standard -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.INDENT_SIZE_PROPERTY -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.INDENT_STYLE_PROPERTY import com.pinterest.ktlint.test.KtLintAssertThat.Companion.assertThatRule import com.pinterest.ktlint.test.LintViolation import com.pinterest.ktlint.test.MULTILINE_STRING_QUOTE @@ -1166,7 +1164,7 @@ internal class IndentationRuleTest { } """.trimIndent() indentationRuleAssertThat(code) - .withEditorConfigOverride(INDENT_SIZE_PROPERTY to 2) + .withEditorConfigOverride(com.pinterest.ktlint.core.api.editorconfig.INDENT_SIZE_PROPERTY to 2) .hasLintViolations( LintViolation(2, 1, "Unexpected indentation (3) (should be 2)"), LintViolation(3, 1, "Unexpected indentation (4) (should be 2)"), @@ -1225,7 +1223,7 @@ internal class IndentationRuleTest { } """.trimIndent() indentationRuleAssertThat(code) - .withEditorConfigOverride(INDENT_SIZE_PROPERTY to "unset") + .withEditorConfigOverride(com.pinterest.ktlint.core.api.editorconfig.INDENT_SIZE_PROPERTY to "unset") .hasNoLintViolations() } @@ -2738,7 +2736,7 @@ internal class IndentationRuleTest { } """.trimIndent() indentationRuleAssertThat(code) - .withEditorConfigOverride(INDENT_SIZE_PROPERTY to 2) + .withEditorConfigOverride(com.pinterest.ktlint.core.api.editorconfig.INDENT_SIZE_PROPERTY to 2) .hasLintViolations( LintViolation(2, 1, "Unexpected tab character(s)"), LintViolation(3, 1, "Unexpected tab character(s)"), @@ -4761,7 +4759,8 @@ internal class IndentationRuleTest { } private companion object { - val INDENT_STYLE_TAB = INDENT_STYLE_PROPERTY to PropertyType.IndentStyleValue.tab + val INDENT_STYLE_TAB = + com.pinterest.ktlint.core.api.editorconfig.INDENT_STYLE_PROPERTY to PropertyType.IndentStyleValue.tab } } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/MaxLineLengthRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/MaxLineLengthRuleTest.kt index 37b573b5ff..04ce92bbed 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/MaxLineLengthRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/MaxLineLengthRuleTest.kt @@ -1,6 +1,5 @@ package com.pinterest.ktlint.ruleset.standard -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.MAX_LINE_LENGTH_PROPERTY import com.pinterest.ktlint.ruleset.standard.MaxLineLengthRule.Companion.IGNORE_BACKTICKED_IDENTIFIER_PROPERTY import com.pinterest.ktlint.test.KtLintAssertThat.Companion.EOL_CHAR import com.pinterest.ktlint.test.KtLintAssertThat.Companion.MAX_LINE_LENGTH_MARKER @@ -190,7 +189,7 @@ class MaxLineLengthRuleTest { fun testLintOff() { val code = "// some" + " long ".repeat(100) + "comment" // Total length of line is 7 + 600 + 7 = 614 characters maxLineLengthRuleAssertThat(code) - .withEditorConfigOverride(MAX_LINE_LENGTH_PROPERTY to "off") + .withEditorConfigOverride(com.pinterest.ktlint.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY to "off") .hasNoLintViolations() } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/ParameterListWrappingRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/ParameterListWrappingRuleTest.kt index 4e60728321..2dc6001f32 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/ParameterListWrappingRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/ParameterListWrappingRuleTest.kt @@ -1,7 +1,6 @@ package com.pinterest.ktlint.ruleset.standard import com.pinterest.ktlint.core.RuleProvider -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.MAX_LINE_LENGTH_PROPERTY import com.pinterest.ktlint.test.KtLintAssertThat.Companion.assertThatRule import com.pinterest.ktlint.test.LintViolation import org.junit.jupiter.api.Test @@ -55,7 +54,7 @@ class ParameterListWrappingRuleTest { ) """.trimIndent() parameterListWrappingRuleAssertThat(code) - .withEditorConfigOverride(MAX_LINE_LENGTH_PROPERTY to 10) + .withEditorConfigOverride(com.pinterest.ktlint.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY to 10) .hasLintViolations( LintViolation(1, 14, "Parameter should be on a separate line (unless all parameters can fit a single line)"), LintViolation(1, 30, "Parameter should be on a separate line (unless all parameters can fit a single line)"), @@ -71,7 +70,7 @@ class ParameterListWrappingRuleTest { class ClassAWithALongName() """.trimIndent() parameterListWrappingRuleAssertThat(code) - .withEditorConfigOverride(MAX_LINE_LENGTH_PROPERTY to 10) + .withEditorConfigOverride(com.pinterest.ktlint.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY to 10) .hasNoLintViolations() } @@ -165,7 +164,7 @@ class ParameterListWrappingRuleTest { } """.trimIndent() parameterListWrappingRuleAssertThat(code) - .withEditorConfigOverride(MAX_LINE_LENGTH_PROPERTY to 10) + .withEditorConfigOverride(com.pinterest.ktlint.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY to 10) .hasLintViolations( LintViolation(1, 7, "Parameter should be on a separate line (unless all parameters can fit a single line)"), LintViolation(1, 15, "Parameter should be on a separate line (unless all parameters can fit a single line)"), @@ -220,7 +219,7 @@ class ParameterListWrappingRuleTest { } """.trimIndent() parameterListWrappingRuleAssertThat(code) - .withEditorConfigOverride(MAX_LINE_LENGTH_PROPERTY to 10) + .withEditorConfigOverride(com.pinterest.ktlint.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY to 10) .hasLintViolations( LintViolation(2, 11, "Parameter should be on a separate line (unless all parameters can fit a single line)"), LintViolation(6, 19, "Parameter should be on a separate line (unless all parameters can fit a single line)"), @@ -310,7 +309,7 @@ class ParameterListWrappingRuleTest { ) {} """.trimIndent() parameterListWrappingRuleAssertThat(code) - .withEditorConfigOverride(MAX_LINE_LENGTH_PROPERTY to 10) + .withEditorConfigOverride(com.pinterest.ktlint.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY to 10) .hasLintViolations( LintViolation(1, 11, "Parameter should be on a separate line (unless all parameters can fit a single line)"), LintViolation(1, 26, "Parameter should be on a separate line (unless all parameters can fit a single line)"), @@ -476,7 +475,7 @@ class ParameterListWrappingRuleTest { )? = null """.trimIndent() parameterListWrappingRuleAssertThat(code) - .withEditorConfigOverride(MAX_LINE_LENGTH_PROPERTY to 80) + .withEditorConfigOverride(com.pinterest.ktlint.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY to 80) .hasLintViolations( LintViolation(1, 22, "Parameter of nullable type should be on a separate line (unless the type fits on a single line)"), LintViolation(1, 95, """Missing newline before ")""""), diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/WrappingRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/WrappingRuleTest.kt index db91ca7e1d..85c9f42425 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/WrappingRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/WrappingRuleTest.kt @@ -1,6 +1,6 @@ package com.pinterest.ktlint.ruleset.standard -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties +import com.pinterest.ktlint.core.api.editorconfig.INDENT_STYLE_PROPERTY import com.pinterest.ktlint.test.KtLintAssertThat.Companion.EOL_CHAR import com.pinterest.ktlint.test.KtLintAssertThat.Companion.MAX_LINE_LENGTH_MARKER import com.pinterest.ktlint.test.KtLintAssertThat.Companion.assertThatRule @@ -546,7 +546,7 @@ internal class WrappingRuleTest { } """.trimIndent() wrappingRuleAssertThat(code) - .withEditorConfigOverride(DefaultEditorConfigProperties.INDENT_STYLE_PROPERTY to tab) + .withEditorConfigOverride(INDENT_STYLE_PROPERTY to tab) .hasLintViolations( LintViolation(2, 10, "Missing newline after \"(\""), LintViolation(5, 18, "Missing newline before \")\""), @@ -1181,7 +1181,7 @@ internal class WrappingRuleTest { } """.trimIndent() wrappingRuleAssertThat(codeTabs) - .withEditorConfigOverride(DefaultEditorConfigProperties.INDENT_STYLE_PROPERTY to tab) + .withEditorConfigOverride(INDENT_STYLE_PROPERTY to tab) .hasNoLintViolations() } @@ -1207,7 +1207,7 @@ internal class WrappingRuleTest { } """.trimIndent() wrappingRuleAssertThat(code) - .withEditorConfigOverride(DefaultEditorConfigProperties.INDENT_STYLE_PROPERTY to tab) + .withEditorConfigOverride(INDENT_STYLE_PROPERTY to tab) .hasNoLintViolations() } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/importordering/ImportOrderingEditorconfigTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/importordering/ImportOrderingEditorconfigTest.kt index ee514e2e39..66916834d5 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/importordering/ImportOrderingEditorconfigTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/importordering/ImportOrderingEditorconfigTest.kt @@ -1,7 +1,7 @@ package com.pinterest.ktlint.ruleset.standard.importordering -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.CodeStyleValue.official import com.pinterest.ktlint.core.api.EditorConfigProperties +import com.pinterest.ktlint.core.api.editorconfig.CodeStyleValue import com.pinterest.ktlint.ruleset.standard.ImportOrderingRule import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -12,8 +12,9 @@ class ImportOrderingEditorconfigTest { val properties: EditorConfigProperties = emptyMap() val rule = ImportOrderingRule() with(rule) { - val raw = properties.writeEditorConfigProperty(ImportOrderingRule.IJ_KOTLIN_IMPORTS_LAYOUT_PROPERTY, official) - assertThat(raw).isEqualTo("*,java.**,javax.**,kotlin.**,^") + val actual = properties.writeEditorConfigProperty(ImportOrderingRule.IJ_KOTLIN_IMPORTS_LAYOUT_PROPERTY, CodeStyleValue.official) + + assertThat(actual).isEqualTo("*,java.**,javax.**,kotlin.**,^") } } } diff --git a/ktlint-test/src/main/kotlin/com/pinterest/ktlint/test/KtLintAssertThat.kt b/ktlint-test/src/main/kotlin/com/pinterest/ktlint/test/KtLintAssertThat.kt index bdb135d3d8..ca66234cea 100644 --- a/ktlint-test/src/main/kotlin/com/pinterest/ktlint/test/KtLintAssertThat.kt +++ b/ktlint-test/src/main/kotlin/com/pinterest/ktlint/test/KtLintAssertThat.kt @@ -3,9 +3,8 @@ package com.pinterest.ktlint.test import com.pinterest.ktlint.core.LintError import com.pinterest.ktlint.core.Rule import com.pinterest.ktlint.core.RuleProvider -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.MAX_LINE_LENGTH_PROPERTY import com.pinterest.ktlint.core.api.EditorConfigOverride -import com.pinterest.ktlint.core.api.UsesEditorConfigProperties +import com.pinterest.ktlint.core.api.editorconfig.EditorConfigProperty import com.pinterest.ktlint.test.KtLintAssertThat.Companion.EOL_CHAR import com.pinterest.ktlint.test.KtLintAssertThat.Companion.MAX_LINE_LENGTH_MARKER import org.assertj.core.api.AbstractAssert @@ -47,14 +46,14 @@ public class KtLintAssertThat( ) { private var filePath: String? = null private var kotlinScript = false - private var editorConfigProperties = emptySet, *>>() + private var editorConfigProperties = emptySet, *>>() /** * Set the [EditorConfigOverride] properties to be used by the rule. This function can be called multiple times. * Properties which have been set before, are silently overwritten with the new vale. */ public fun withEditorConfigOverride( - vararg properties: Pair, *>, + vararg properties: Pair, *>, ): KtLintAssertThat { editorConfigProperties = editorConfigProperties + properties.toSet() @@ -86,7 +85,7 @@ public class KtLintAssertThat( ?.indexOf(EOL_CHAR) ?.let { index -> editorConfigProperties = - editorConfigProperties + setOf(MAX_LINE_LENGTH_PROPERTY to (index + 1).toString()) + editorConfigProperties + setOf(com.pinterest.ktlint.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY to (index + 1).toString()) } ?: throw MissingEolMarker() return this diff --git a/ktlint-test/src/main/kotlin/com/pinterest/ktlint/test/RuleExtension.kt b/ktlint-test/src/main/kotlin/com/pinterest/ktlint/test/RuleExtension.kt index 969e2d0be1..355f6d1930 100644 --- a/ktlint-test/src/main/kotlin/com/pinterest/ktlint/test/RuleExtension.kt +++ b/ktlint-test/src/main/kotlin/com/pinterest/ktlint/test/RuleExtension.kt @@ -4,10 +4,10 @@ import com.pinterest.ktlint.core.KtLint import com.pinterest.ktlint.core.KtLintRuleEngine import com.pinterest.ktlint.core.LintError import com.pinterest.ktlint.core.RuleProvider -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.RuleExecution -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.createRuleSetExecutionEditorConfigProperty import com.pinterest.ktlint.core.api.EditorConfigOverride import com.pinterest.ktlint.core.api.EditorConfigOverride.Companion.plus +import com.pinterest.ktlint.core.api.editorconfig.RuleExecution +import com.pinterest.ktlint.core.api.editorconfig.createRuleSetExecutionEditorConfigProperty import com.pinterest.ktlint.core.initKtLintKLogger import com.pinterest.ktlint.core.setDefaultLoggerModifier import com.pinterest.ruleset.test.DumpASTRule diff --git a/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/GenerateEditorConfigSubCommand.kt b/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/GenerateEditorConfigSubCommand.kt index e052a5dd27..13c75c5959 100644 --- a/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/GenerateEditorConfigSubCommand.kt +++ b/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/GenerateEditorConfigSubCommand.kt @@ -1,9 +1,8 @@ package com.pinterest.ktlint.internal import com.pinterest.ktlint.core.KtLintRuleEngine -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.CODE_STYLE_PROPERTY import com.pinterest.ktlint.core.api.EditorConfigOverride +import com.pinterest.ktlint.core.api.editorconfig.CodeStyleValue import com.pinterest.ktlint.core.initKtLintKLogger import java.nio.file.Paths import mu.KotlinLogging @@ -39,7 +38,7 @@ internal class GenerateEditorConfigSubCommand : Runnable { ) val ktLintRuleEngine = KtLintRuleEngine( ruleProviders = ruleProviders, - editorConfigOverride = EditorConfigOverride.from(CODE_STYLE_PROPERTY to codeStyle()), + editorConfigOverride = EditorConfigOverride.from(com.pinterest.ktlint.core.api.editorconfig.CODE_STYLE_PROPERTY to codeStyle()), isInvokedFromCli = true, ) val generatedEditorConfig = ktLintRuleEngine.generateKotlinEditorConfigSection(Paths.get(".")) @@ -55,9 +54,9 @@ internal class GenerateEditorConfigSubCommand : Runnable { private fun codeStyle() = if (ktlintCommand.android) { - DefaultEditorConfigProperties.CodeStyleValue.android + CodeStyleValue.android } else { - DefaultEditorConfigProperties.CodeStyleValue.official + CodeStyleValue.official } internal companion object { diff --git a/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/KtlintCommandLine.kt b/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/KtlintCommandLine.kt index afef6ca64a..bf442730d9 100644 --- a/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/KtlintCommandLine.kt +++ b/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/KtlintCommandLine.kt @@ -8,16 +8,15 @@ import com.pinterest.ktlint.core.Reporter import com.pinterest.ktlint.core.ReporterProvider import com.pinterest.ktlint.core.api.Baseline.Status.INVALID import com.pinterest.ktlint.core.api.Baseline.Status.NOT_FOUND -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.CODE_STYLE_PROPERTY -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.CodeStyleValue -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.RuleExecution -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.createRuleExecutionEditorConfigProperty import com.pinterest.ktlint.core.api.EditorConfigDefaults import com.pinterest.ktlint.core.api.EditorConfigOverride import com.pinterest.ktlint.core.api.EditorConfigOverride.Companion.plus import com.pinterest.ktlint.core.api.KtLintParseException import com.pinterest.ktlint.core.api.KtLintRuleException import com.pinterest.ktlint.core.api.doesNotContain +import com.pinterest.ktlint.core.api.editorconfig.CodeStyleValue +import com.pinterest.ktlint.core.api.editorconfig.RuleExecution +import com.pinterest.ktlint.core.api.editorconfig.createRuleExecutionEditorConfigProperty import com.pinterest.ktlint.core.api.loadBaseline import com.pinterest.ktlint.core.api.relativeRoute import com.pinterest.ktlint.core.initKtLintKLogger @@ -257,7 +256,7 @@ internal class KtlintCommandLine { .applyIf(disabledRules.isNotBlank()) { plus(*disabledRulesEditorConfigOverrides()) }.applyIf(android) { - plus(CODE_STYLE_PROPERTY to CodeStyleValue.android) + plus(com.pinterest.ktlint.core.api.editorconfig.CODE_STYLE_PROPERTY to CodeStyleValue.android) } private fun disabledRulesEditorConfigOverrides() =