Skip to content

Commit 1353723

Browse files
committed
Clarify ktlint property-matching control flow for ruleset properties
1 parent e5a3167 commit 1353723

File tree

3 files changed

+27
-21
lines changed

3 files changed

+27
-21
lines changed

lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,8 @@ private static EditorConfigOverride createEditorConfigOverride(final List<Rule>
131131
Pair<EditorConfigProperty<?>, ?>[] properties = editorConfigOverrideMap.entrySet().stream()
132132
.map(entry -> {
133133
EditorConfigProperty<?> property = supportedProperties.get(entry.getKey());
134-
if (property != null) {
135-
return new Pair<>(property, entry.getValue());
136-
} else if (entry.getKey().startsWith("ktlint_")) {
134+
135+
if (property == null && entry.getKey().startsWith("ktlint_")) {
137136
String[] parts = entry.getKey().substring(7).split("_", 2);
138137
if (parts.length == 1) {
139138
// convert ktlint_{ruleset} to {ruleset}
@@ -144,9 +143,12 @@ private static EditorConfigOverride createEditorConfigOverride(final List<Rule>
144143
String qualifiedRuleId = parts[0] + ":" + parts[1];
145144
property = RuleExecutionEditorConfigPropertyKt.createRuleExecutionEditorConfigProperty(qualifiedRuleId);
146145
}
147-
return new Pair<>(property, entry.getValue());
148-
} else {
146+
}
147+
148+
if (property == null) {
149149
return null;
150+
} else {
151+
return new Pair<>(property, entry.getValue());
150152
}
151153
})
152154
.filter(Objects::nonNull)

lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,22 +175,24 @@ private static EditorConfigOverride createEditorConfigOverride(final List<Rule>
175175
Pair<EditorConfigProperty<?>, ?>[] properties = editorConfigOverrideMap.entrySet().stream()
176176
.map(entry -> {
177177
EditorConfigProperty<?> property = supportedProperties.get(entry.getKey());
178-
if (property != null) {
179-
return new Pair<>(property, entry.getValue());
180-
} else if (entry.getKey().startsWith("ktlint_")) {
178+
179+
if (property == null && entry.getKey().startsWith("ktlint_")) {
181180
String[] parts = entry.getKey().substring(7).split("_", 2);
182181
if (parts.length == 1) {
183182
// convert ktlint_{ruleset} to {ruleset}
184-
String qualifiedRuleId = parts[0] + ":";
185-
property = createRuleSetExecution(qualifiedRuleId, RuleExecution.disabled);
183+
String id = parts[0];
184+
property = createRuleSetExecution(id, RuleExecution.enabled);
186185
} else {
187186
// convert ktlint_{ruleset}_{rulename} to {ruleset}:{rulename}
188-
String qualifiedRuleId = parts[0] + ":" + parts[1];
189-
property = createRuleExecution(qualifiedRuleId, RuleExecution.disabled);
187+
String id = parts[0] + ":" + parts[1];
188+
property = createRuleExecution(id, RuleExecution.enabled);
190189
}
191-
return new Pair<>(property, entry.getValue());
192-
} else {
190+
}
191+
192+
if (property == null) {
193193
return null;
194+
} else {
195+
return new Pair<>(property, entry.getValue());
194196
}
195197
})
196198
.filter(Objects::nonNull)

lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,22 +138,24 @@ private static EditorConfigOverride createEditorConfigOverride(final List<Rule>
138138
Pair<EditorConfigProperty<?>, ?>[] properties = editorConfigOverrideMap.entrySet().stream()
139139
.map(entry -> {
140140
EditorConfigProperty<?> property = supportedProperties.get(entry.getKey());
141-
if (property != null) {
142-
return new Pair<>(property, entry.getValue());
143-
} else if (entry.getKey().startsWith("ktlint_")) {
141+
142+
if (property == null && entry.getKey().startsWith("ktlint_")) {
144143
String[] parts = entry.getKey().substring(7).split("_", 2);
145144
if (parts.length == 1) {
146145
// convert ktlint_{ruleset} to RuleSetId
147146
RuleSetId id = new RuleSetId(parts[0]);
148-
property = RuleExecutionEditorConfigPropertyKt.createRuleSetExecutionEditorConfigProperty(id, RuleExecution.disabled);
147+
property = RuleExecutionEditorConfigPropertyKt.createRuleSetExecutionEditorConfigProperty(id, RuleExecution.enabled);
149148
} else {
150149
// convert ktlint_{ruleset}_{rulename} to RuleId
151150
RuleId id = new RuleId(parts[0] + ":" + parts[1]);
152-
property = RuleExecutionEditorConfigPropertyKt.createRuleExecutionEditorConfigProperty(id, RuleExecution.disabled);
151+
property = RuleExecutionEditorConfigPropertyKt.createRuleExecutionEditorConfigProperty(id, RuleExecution.enabled);
153152
}
154-
return new Pair<>(property, entry.getValue());
155-
} else {
153+
}
154+
155+
if (property == null) {
156156
return null;
157+
} else {
158+
return new Pair<>(property, entry.getValue());
157159
}
158160
})
159161
.filter(Objects::nonNull)

0 commit comments

Comments
 (0)