GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Check if ktlint_code_style is set in .editorconfig before overriding it by OlivierGenez · Pull Request #2143 · diffplug/spotless Conversation
|
|
I see it! Could you add a test case for this? Or just update spotless/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java Lines 130 to 147 in 5f840aa
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Thanks for the quick reply! The PR already has this test: https://github.com/diffplug/spotless/pull/2143/files#diff-7bbe43d03149d8aad5b95564d57dc5bf59cba4ce539a44e01bbe51215dcdae71R131-R147. Is it sufficient, or is there a specific/additional scenario I am missing that you're after? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Ooooops, will take a look later. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if (!editorConfigOverrideMap.containsKey("ktlint_code_style")) { | ||
| boolean isCodeStyleDefinedInEditorConfig = editorConfig.getValue().getSections().stream() | ||
| .anyMatch(section -> section.getProperties().containsKey("ktlint_code_style")); | ||
| if (!isCodeStyleDefinedInEditorConfig && !editorConfigOverrideMap.containsKey("ktlint_code_style")) { |
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The key point is here, I missed checking EditorConfig file properties in #1808.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| "spotless {", | ||
| " kotlin {", | ||
| " ktlint().editorConfigOverride([", | ||
| " ktlint_test_key: true,", |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Nice, can you add a test case like 87537c0 for maven as well?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Done!
While adding the test I realised that plugin-maven never defaulted EditorConfig's path to .editorconfig, so I fixed that too.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
The default path was never set, which means that .editorconfig was never picked up if not explicitly set.
This verifies that the previous fix which checks if ktlint_code_style is already defined in .editorconfig before overriding it works as expected in plugin-maven.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| if (editorConfigPath == null) { | ||
| File defaultEditorConfig = new File(".editorconfig"); | ||
| if (defaultEditorConfig.exists()) { | ||
| editorConfigPath = defaultEditorConfig.getPath(); | ||
| } | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Will load EMPTY_EDITOR_CONFIG_DEFAULTS before
Lines 96 to 101 in cf6c76f
| EditorConfigDefaults editorConfig; | |
| if (editorConfigPath == null || !Files.exists(editorConfigPath)) { | |
| editorConfig = EditorConfigDefaults.Companion.getEMPTY_EDITOR_CONFIG_DEFAULTS(); | |
| } else { | |
| editorConfig = EditorConfigDefaults.Companion.load(editorConfigPath, RuleProviderKt.propertyTypes(allRuleProviders)); | |
| } |
But this should parse the root .editorconfig, I forget the exact position, let me check.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
You are right! KtLintRuleEngine will load the .editorconfig.
However I believe we still need to load it ourselves as well in order to check if it sets ktlint_code_style in KtLintCompat1Dot0Dot0Adapter. Otherwise we will run into the original issue: ktlint_code_style will be overridden to its default value (intellij_idea) when the editorConfigOverride map is non-empty but does not define it. This is also what plugin-gradle does:
spotless/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java
Lines 159 to 160 in add4c1e
| File defaultEditorConfig = getProject().getRootProject().file(".editorconfig"); | |
| FileSignature editorConfigPath = defaultEditorConfig.exists() ? FileSignature.signAsList(defaultEditorConfig) : null; |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Co-authored-by: Zongle Wang <[email protected]>
| if (editorConfigPath == null) { | ||
| File defaultEditorConfig = new File(".editorconfig"); | ||
| if (defaultEditorConfig.exists()) { | ||
| editorConfigPath = defaultEditorConfig.getPath(); | ||
| } | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| if (editorConfigPath == null) { | |
| File defaultEditorConfig = new File(".editorconfig"); | |
| if (defaultEditorConfig.exists()) { | |
| editorConfigPath = defaultEditorConfig.getPath(); | |
| } | |
| } | |
| if (editorConfigPath == null && defaultEditorConfig.exists()) { | |
| editorConfigPath = defaultEditorConfig.getPath(); | |
| } |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
And add
private static final File defaultEditorConfig = new File(".editorconfig");
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Done.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Quick shot!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
ktlint - ktlint_code_style gets unconditionally overridden to its default value when not defined in editorConfigOverride
There was an error while loading. Please reload this page.