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

Command line flag --code-style=android_studio has no effect in v0.49.0 #1982

Closed
ghaiszaher opened this issue Apr 27, 2023 · 0 comments · Fixed by #1990
Closed

Command line flag --code-style=android_studio has no effect in v0.49.0 #1982

ghaiszaher opened this issue Apr 27, 2023 · 0 comments · Fixed by #1990
Milestone

Comments

@ghaiszaher
Copy link

Expected Behavior

ktlint --code-style=android_studio should behave exactly like the deprecated flag ktlint --android, this is also stated in the warning message printed after running ktlint --android:

Option '--android' / '-a' is deprecated and replaced with option '--code-style=android_studio'. Setting '.editorconfig' property > 'ktlint_code_style=android_studio' might be a better idea for a project that is always to formatted with this code style.

ktlint_code_style=android_studio in .editorconfig works properly, but --code-style=android_studio in command-line has no effect.

Observed Behavior

After running the command ktlint --code-style=android_studio --log-level=debug {filepath} on a file, the following output is observed:

[...]
[pool-1-thread-1] DEBUG com.pinterest.ktlint.rule.engine.internal.EditorConfigLoader - Effective editorconfig properties for file '{filepath}':
	ktlint_experimental: disabled
	indent_size: 4
	max_line_length: 150
	ktlint_standard_import-ordering: disabled
	tab_width: 4
[...]
{filename}:7:29: Missing trailing comma before "}" (standard:trailing-comma-on-declaration-site)
[main] DEBUG com.pinterest.ktlint.cli.internal.KtlintCommandLine - Finished processing in 381ms / 1 file(s) scanned / 1 error(s) found
[main] DEBUG com.pinterest.ktlint.cli.internal.KtlintCommandLine - Exit ktlint with exit code: 1
Summary error count (descending) by rule:
  standard:trailing-comma-on-declaration-site: 1

However, running ktlint --android --log-level=debug {filepath} will show:

[...]
[pool-1-thread-1] DEBUG com.pinterest.ktlint.rule.engine.internal.EditorConfigLoader - Effective editorconfig properties for file '{filepath}':
	ktlint_experimental: disabled
	indent_size: 4
	max_line_length: 150
	ktlint_standard_import-ordering: disabled
	tab_width: 4
	ktlint_code_style: android
[...]
[main] DEBUG com.pinterest.ktlint.cli.internal.KtlintCommandLine - Finished processing in 388ms / 1 file(s) scanned / 0 error(s) found
[main] DEBUG com.pinterest.ktlint.cli.internal.KtlintCommandLine - Exit ktlint with exit code: 0

Note that ktlint_code_style: android is not mentioned in first command and the reported errors are different.

Steps to Reproduce

  1. Create a new file MyEnum.kt with following content:
enum class MyEnum {
    SomeEnumValue
}
  1. Run ktlint --android -> no issues reported
Full logs for `ktlint --log-level=debug --android`

13:39:41.798 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintCommandLine - Add editor config override to set code style to 'android'
13:39:41.805 [main] ERROR com.pinterest.ktlint.cli.internal.KtlintCommandLine - Option '--android' / '-a' is deprecated and replaced with option '--code-style=android_studio'. Setting '.editorconfig' property 'ktlint_code_style=android_studio' might be a better idea for a project that is always to formatted with this code style.
13:39:41.814 [main] INFO com.pinterest.ktlint.cli.internal.KtlintCommandLine - Enable default patterns [**/*.kt, **/*.kts]
13:39:41.817 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintServiceLoader - Discovered RuleSetProviderV3 with id 'standard' in ktlint JAR
13:39:41.909 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintServiceLoader - Discovered ReporterProviderV2 with id 'baseline' in ktlint JAR
13:39:41.909 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintServiceLoader - Discovered ReporterProviderV2 with id 'plain' in ktlint JAR
13:39:41.909 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintServiceLoader - Discovered ReporterProviderV2 with id 'checkstyle' in ktlint JAR
13:39:41.909 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintServiceLoader - Discovered ReporterProviderV2 with id 'json' in ktlint JAR
13:39:41.909 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintServiceLoader - Discovered ReporterProviderV2 with id 'format' in ktlint JAR
13:39:41.909 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintServiceLoader - Discovered ReporterProviderV2 with id 'html' in ktlint JAR
13:39:41.909 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintServiceLoader - Discovered ReporterProviderV2 with id 'plain-summary' in ktlint JAR
13:39:41.909 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintServiceLoader - Discovered ReporterProviderV2 with id 'sarif' in ktlint JAR
13:39:41.910 [main] DEBUG com.pinterest.ktlint.cli.internal.ReporterAggregator - Initializing "plain" reporter with {plain=true, color=false, color_name=DARK_GRAY, format=false}
13:39:41.917 [main] DEBUG com.pinterest.ktlint.cli.internal.FileUtils - Start walkFileTree for rootDir: '/Users/ghaiszaher/tmp/ktlint'
   include:
[      - sun.nio.fs.UnixFileSystem$3@5e4bd84a,       - sun.nio.fs.UnixFileSystem$3@648c94da,       - sun.nio.fs.UnixFileSystem$3@2a62b5bc,       - sun.nio.fs.UnixFileSystem$3@53de625d]
   exclude:
[]
13:39:41.919 [main] DEBUG com.pinterest.ktlint.cli.internal.FileUtils - Discovered 1 files to be processed in 2 ms
13:39:41.923 [pool-1-thread-1] DEBUG com.pinterest.ktlint.rule.engine.api.KtLintRuleEngine - Starting with linting file 'MyEnum.kt'
13:39:42.151 [pool-1-thread-1] DEBUG com.pinterest.ktlint.rule.engine.internal.EditorConfigLoader - Effective editorconfig properties for file '/Users/ghaiszaher/tmp/ktlint/MyEnum.kt':
	ktlint_code_style: android
13:39:42.156 [pool-1-thread-1] DEBUG com.pinterest.ktlint.rule.engine.internal.rulefilter.RunAfterRuleFilter - Rule with id 'standard:annotation' should run after the rule with id 'standard:enum-wrapping'. However, the latter rule is not loaded and is allowed to be ignored. For best results, it is advised load the rule.
13:39:42.156 [pool-1-thread-1] DEBUG com.pinterest.ktlint.rule.engine.internal.rulefilter.RunAfterRuleFilter - Rule with id 'standard:indent' should run after the rule with id 'standard:function-signature'. However, the latter rule is not loaded and is allowed to be ignored. For best results, it is advised load the rule.
13:39:42.156 [pool-1-thread-1] DEBUG com.pinterest.ktlint.rule.engine.internal.rulefilter.RunAfterRuleFilter - Rule with id 'standard:indent' should run after the rule with id 'standard:function-signature'. However, the latter rule is not loaded and is allowed to be ignored. For best results, it is advised load the rule.
13:39:42.157 [pool-1-thread-1] DEBUG com.pinterest.ktlint.rule.engine.internal.rulefilter.RunAfterRuleFilter - Rule with id 'standard:indent' should run after the rule with id 'standard:function-signature'. However, the latter rule is not loaded and is allowed to be ignored. For best results, it is advised load the rule.
13:39:42.165 [pool-1-thread-1] DEBUG com.pinterest.ktlint.rule.engine.internal.RuleProviderSorter - Rules will be executed in order below:
           - standard:annotation-spacing, 
           - standard:chain-wrapping, 
           - standard:class-naming, 
           - standard:colon-spacing, 
           - standard:comma-spacing, 
           - standard:comment-spacing, 
           - standard:comment-wrapping, 
           - standard:curly-spacing, 
           - standard:dot-spacing, 
           - standard:double-colon-spacing, 
           - standard:enum-entry-name-case, 
           - standard:filename, 
           - standard:final-newline, 
           - standard:fun-keyword-spacing, 
           - standard:function-return-type-spacing, 
           - standard:function-start-of-body-spacing, 
           - standard:function-type-reference-spacing, 
           - standard:import-ordering, 
           - standard:kdoc-wrapping, 
           - standard:keyword-spacing, 
           - standard:modifier-list-spacing, 
           - standard:modifier-order, 
           - standard:multiline-if-else, 
           - standard:no-blank-line-before-rbrace, 
           - standard:no-blank-lines-in-chained-method-calls, 
           - standard:no-consecutive-blank-lines, 
           - standard:no-empty-class-body, 
           - standard:no-empty-first-line-in-method-block, 
           - standard:no-line-break-after-else, 
           - standard:no-line-break-before-assignment, 
           - standard:no-multi-spaces, 
           - standard:no-semi, 
           - standard:no-trailing-spaces, 
           - standard:no-unit-return, 
           - standard:no-unused-imports, 
           - standard:no-wildcard-imports, 
           - standard:nullable-type-spacing, 
           - standard:op-spacing, 
           - standard:package-name, 
           - standard:parameter-list-wrapping, 
           - standard:parameter-wrapping, 
           - standard:paren-spacing, 
           - standard:property-wrapping, 
           - standard:range-spacing, 
           - standard:spacing-around-angle-brackets, 
           - standard:spacing-between-declarations-with-annotations, 
           - standard:spacing-between-declarations-with-comments, 
           - standard:spacing-between-function-name-and-opening-parenthesis, 
           - standard:string-template, 
           - standard:unary-op-spacing, 
           - standard:annotation, 
           - standard:wrapping, 
           - standard:argument-list-wrapping, 
           - standard:trailing-comma-on-call-site, 
           - standard:trailing-comma-on-declaration-site, 
           - standard:indent, 
           - standard:block-comment-initial-star-alignment, 
           - standard:max-line-length
13:39:42.177 [pool-1-thread-1] DEBUG com.pinterest.ktlint.rule.engine.api.KtLintRuleEngine - Finished with linting file 'MyEnum.kt'
13:39:42.179 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintCommandLine - Finished processing in 365ms / 1 file(s) scanned / 0 error(s) found
13:39:42.179 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintCommandLine - Exit ktlint with exit code: 0

  1. Run ktlint --code-style=android_studio -> one issue reported:
[main] INFO com.pinterest.ktlint.cli.internal.KtlintCommandLine - Enable default patterns [**/*.kt, **/*.kts]
MyEnum.kt:2:18: Missing trailing comma before "}" (standard:trailing-comma-on-declaration-site)

Summary error count (descending) by rule:
  standard:trailing-comma-on-declaration-site: 1
Full logs for `ktlint --log-level=debug --code-style=android_studio`

13:39:37.010 [main] INFO com.pinterest.ktlint.cli.internal.KtlintCommandLine - Enable default patterns [**/*.kt, **/*.kts]
13:39:37.017 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintServiceLoader - Discovered RuleSetProviderV3 with id 'standard' in ktlint JAR
13:39:37.112 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintServiceLoader - Discovered ReporterProviderV2 with id 'baseline' in ktlint JAR
13:39:37.112 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintServiceLoader - Discovered ReporterProviderV2 with id 'plain' in ktlint JAR
13:39:37.112 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintServiceLoader - Discovered ReporterProviderV2 with id 'checkstyle' in ktlint JAR
13:39:37.112 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintServiceLoader - Discovered ReporterProviderV2 with id 'json' in ktlint JAR
13:39:37.112 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintServiceLoader - Discovered ReporterProviderV2 with id 'format' in ktlint JAR
13:39:37.112 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintServiceLoader - Discovered ReporterProviderV2 with id 'html' in ktlint JAR
13:39:37.112 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintServiceLoader - Discovered ReporterProviderV2 with id 'plain-summary' in ktlint JAR
13:39:37.112 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintServiceLoader - Discovered ReporterProviderV2 with id 'sarif' in ktlint JAR
13:39:37.113 [main] DEBUG com.pinterest.ktlint.cli.internal.ReporterAggregator - Initializing "plain" reporter with {plain=true, color=false, color_name=DARK_GRAY, format=false}
13:39:37.120 [main] DEBUG com.pinterest.ktlint.cli.internal.FileUtils - Start walkFileTree for rootDir: '/Users/ghaiszaher/tmp/ktlint'
   include:
[      - sun.nio.fs.UnixFileSystem$3@3d1848cc,       - sun.nio.fs.UnixFileSystem$3@7dda48d9,       - sun.nio.fs.UnixFileSystem$3@6e4566f1,       - sun.nio.fs.UnixFileSystem$3@4b6e2263]
   exclude:
[]
13:39:37.122 [main] DEBUG com.pinterest.ktlint.cli.internal.FileUtils - Discovered 1 files to be processed in 1 ms
13:39:37.126 [pool-1-thread-1] DEBUG com.pinterest.ktlint.rule.engine.api.KtLintRuleEngine - Starting with linting file 'MyEnum.kt'
13:39:37.355 [pool-1-thread-1] DEBUG com.pinterest.ktlint.rule.engine.internal.EditorConfigLoader - Effective editorconfig properties for file '/Users/ghaiszaher/tmp/ktlint/MyEnum.kt':
	
13:39:37.359 [pool-1-thread-1] DEBUG com.pinterest.ktlint.rule.engine.internal.rulefilter.RunAfterRuleFilter - Rule with id 'standard:annotation' should run after the rule with id 'standard:enum-wrapping'. However, the latter rule is not loaded and is allowed to be ignored. For best results, it is advised load the rule.
13:39:37.359 [pool-1-thread-1] DEBUG com.pinterest.ktlint.rule.engine.internal.rulefilter.RunAfterRuleFilter - Rule with id 'standard:indent' should run after the rule with id 'standard:function-signature'. However, the latter rule is not loaded and is allowed to be ignored. For best results, it is advised load the rule.
13:39:37.359 [pool-1-thread-1] DEBUG com.pinterest.ktlint.rule.engine.internal.rulefilter.RunAfterRuleFilter - Rule with id 'standard:indent' should run after the rule with id 'standard:function-signature'. However, the latter rule is not loaded and is allowed to be ignored. For best results, it is advised load the rule.
13:39:37.359 [pool-1-thread-1] DEBUG com.pinterest.ktlint.rule.engine.internal.rulefilter.RunAfterRuleFilter - Rule with id 'standard:indent' should run after the rule with id 'standard:function-signature'. However, the latter rule is not loaded and is allowed to be ignored. For best results, it is advised load the rule.
13:39:37.368 [pool-1-thread-1] DEBUG com.pinterest.ktlint.rule.engine.internal.RuleProviderSorter - Rules will be executed in order below:
           - standard:annotation-spacing, 
           - standard:chain-wrapping, 
           - standard:class-naming, 
           - standard:colon-spacing, 
           - standard:comma-spacing, 
           - standard:comment-spacing, 
           - standard:comment-wrapping, 
           - standard:curly-spacing, 
           - standard:dot-spacing, 
           - standard:double-colon-spacing, 
           - standard:enum-entry-name-case, 
           - standard:filename, 
           - standard:final-newline, 
           - standard:fun-keyword-spacing, 
           - standard:function-return-type-spacing, 
           - standard:function-start-of-body-spacing, 
           - standard:function-type-reference-spacing, 
           - standard:import-ordering, 
           - standard:kdoc-wrapping, 
           - standard:keyword-spacing, 
           - standard:modifier-list-spacing, 
           - standard:modifier-order, 
           - standard:multiline-if-else, 
           - standard:no-blank-line-before-rbrace, 
           - standard:no-blank-lines-in-chained-method-calls, 
           - standard:no-consecutive-blank-lines, 
           - standard:no-empty-class-body, 
           - standard:no-empty-first-line-in-method-block, 
           - standard:no-line-break-after-else, 
           - standard:no-line-break-before-assignment, 
           - standard:no-multi-spaces, 
           - standard:no-semi, 
           - standard:no-trailing-spaces, 
           - standard:no-unit-return, 
           - standard:no-unused-imports, 
           - standard:no-wildcard-imports, 
           - standard:nullable-type-spacing, 
           - standard:op-spacing, 
           - standard:package-name, 
           - standard:parameter-list-wrapping, 
           - standard:parameter-wrapping, 
           - standard:paren-spacing, 
           - standard:property-wrapping, 
           - standard:range-spacing, 
           - standard:spacing-around-angle-brackets, 
           - standard:spacing-between-declarations-with-annotations, 
           - standard:spacing-between-declarations-with-comments, 
           - standard:spacing-between-function-name-and-opening-parenthesis, 
           - standard:string-template, 
           - standard:unary-op-spacing, 
           - standard:annotation, 
           - standard:wrapping, 
           - standard:argument-list-wrapping, 
           - standard:trailing-comma-on-call-site, 
           - standard:trailing-comma-on-declaration-site, 
           - standard:indent, 
           - standard:block-comment-initial-star-alignment, 
           - standard:max-line-length
13:39:37.381 [pool-1-thread-1] DEBUG com.pinterest.ktlint.rule.engine.api.KtLintRuleEngine - Finished with linting file 'MyEnum.kt'
MyEnum.kt:2:18: Missing trailing comma before "}" (standard:trailing-comma-on-declaration-site)

Summary error count (descending) by rule:
  standard:trailing-comma-on-declaration-site: 1
13:39:37.383 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintCommandLine - Finished processing in 370ms / 1 file(s) scanned / 1 error(s) found
13:39:37.383 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintCommandLine - Exit ktlint with exit code: 1

Your Environment

  • Version of ktlint used: 0.49.0
  • No .editorconfig
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): Not applicable
  • Version of Gradle used (if applicable): Not applicable
  • Operating System and version: macOS 13.3.1 (22E261)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants