Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix code style parameter in cli #2241

Merged
merged 4 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix ktlint cli parameter --code-style
Pass parameter correctly to KtlintRuleEngine.
Also, deprecate parameters '--code-style', '--disabled-rules' and '--experimental' as those should be specified in the '.editorconfig' properties
  • Loading branch information
paul-dingemans committed Sep 5, 2023
commit 4d2fdf648f5345ea09f5a70d4e55f80b3852bbb8
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,13 @@ internal class KtlintCommandLine {
scope = CommandLine.ScopeType.INHERIT,
names = ["--code-style"],
description = [
"Defines the code style (ktlint_official, intellij_idea or android_studio) to be used for formatting the code. It is " +
"advised to define '.editorconfig' property 'ktlint_code_style'.",
"Defines the code style (ktlint_official, intellij_idea or android_studio) to be used for formatting the code. This option " +
"is deprecated, and will be removed in Ktlint 1.1. The code style has to be defined as '.editorconfig' property " +
"'ktlint_code_style'.",
],
converter = [CodeStyleValueConverter::class],
)
@Deprecated("Marked for removal in Ktlint 1.1")
var codeStyle: CodeStyleValue? = null

@Option(
Expand All @@ -127,10 +129,12 @@ internal class KtlintCommandLine {
@Option(
names = ["--disabled_rules"],
description = [
"Comma-separated list of rules to globally disable." +
" To disable standard ktlint rule-set use --disabled_rules=standard",
"Comma-separated list of rules to globally disable. This option is deprecated, and will be removed in Ktlint 1.1. The " +
"disabled rules have to be defined as '.editorconfig' properties. See " +
"https://pinterest.github.io/ktlint/1.0.0/faq/#how-do-i-enable-or-disable-a-rule",
],
)
@Deprecated("Marked for removal in Ktlint 1.1")
var disabledRules: String = ""

@Option(
Expand Down Expand Up @@ -202,8 +206,13 @@ internal class KtlintCommandLine {

@Option(
names = ["--experimental"],
description = ["Enable experimental rules"],
description = [
"Enable experimental rules. This option is deprecated, and will be removed in Ktlint 1.1. The experimental flag has to be " +
"set as '.editorconfig' property 'ktlint_experimental'. See " +
"https://pinterest.github.io/ktlint/1.0.0/faq/#how-do-i-enable-or-disable-a-rule-set",
],
)
@Deprecated("Marked for removal in Ktlint 1.1")
var experimental: Boolean = false

@Option(
Expand Down Expand Up @@ -246,14 +255,25 @@ internal class KtlintCommandLine {
EditorConfigOverride
.EMPTY_EDITOR_CONFIG_OVERRIDE
.applyIf(experimental) {
logger.debug { "Add editor config override to allow the experimental rule set" }
logger.warn {
"Parameter `--experimental is deprecated, and will be removed in Ktlint 1.1. The experimental flag has to be " +
"set as '.editorconfig' property 'ktlint_experimental = enabled'. See " +
"https://pinterest.github.io/ktlint/1.0.0/faq/#how-do-i-enable-or-disable-a-rule-set"
}
plus(EXPERIMENTAL_RULES_EXECUTION_PROPERTY to RuleExecution.enabled)
}.applyIf(disabledRules.isNotBlank()) {
logger.debug { "Add editor config override to disable rules: '$disabledRules'" }
logger.warn {
"Parameter `--disabled-rules is deprecated, and will be removed in Ktlint 1.1. The disabled rules have to be " +
"defined as '.editorconfig' properties. See " +
"https://pinterest.github.io/ktlint/1.0.0/faq/#how-do-i-enable-or-disable-a-rule"
}
plus(*disabledRulesEditorConfigOverrides())
}.applyIf(codeStyle == CodeStyleValue.android_studio) {
logger.debug { "Add editor config override to set code style to 'android_studio'" }
plus(CODE_STYLE_PROPERTY to CodeStyleValue.android_studio)
}.applyIf(codeStyle != null) {
logger.warn {
"Parameter `--code-style=${codeStyle?.name} is deprecated. The code style should be defined as '.editorconfig' " +
"property 'ktlint_code_style'."
}
plus(CODE_STYLE_PROPERTY to codeStyle)
}.applyIf(stdin) {
logger.debug {
"Add editor config override to disable 'filename' rule which can not be used in combination with reading from " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,12 @@ class SimpleCLITest {
CommandLineTestRunner(tempDir)
.run(
"too-many-empty-lines",
listOf("--code-style=ktlint_official", "generateEditorConfig"),
listOf("--code-style=intellij_idea", "generateEditorConfig"),
) {
SoftAssertions()
.apply {
assertNormalExitCode()
assertThat(normalOutput).containsLineMatching("ktlint_code_style = ktlint_official")
assertThat(normalOutput).containsLineMatching("ktlint_code_style = intellij_idea")
}.assertAll()
}
}
Expand Down Expand Up @@ -526,7 +526,9 @@ class SimpleCLITest {
arguments = listOf("--code-style=android_studio"),
) {
assertThat(normalOutput).containsLineMatching(
Regex(".*Add editor config override to set code style to 'android_studio'.*"),
Regex(
".*WARN.*Parameter `--code-style=android_studio is deprecated. The code style should be defined as " +
"'.editorconfig' property 'ktlint_code_style'.*"),
)
}
}
Expand Down