@@ -105,6 +105,42 @@ void testWithInvalidEditorConfigFile() throws IOException {
105
105
assertThat (buildOutput ).contains (invalidPath );
106
106
}
107
107
108
+ @ Test
109
+ void testReadCodeStyleFromEditorConfigFile () throws IOException {
110
+ setFile (".editorconfig" ).toResource ("kotlin/ktlint/ktlint_official/.editorconfig" );
111
+ setFile ("build.gradle" ).toLines (
112
+ "plugins {" ,
113
+ " id 'org.jetbrains.kotlin.jvm' version '1.5.31'" ,
114
+ " id 'com.diffplug.spotless'" ,
115
+ "}" ,
116
+ "repositories { mavenCentral() }" ,
117
+ "spotless {" ,
118
+ " kotlin {" ,
119
+ " ktlint()" ,
120
+ " }" ,
121
+ "}" );
122
+ checkKtlintOfficialStyle ();
123
+ }
124
+
125
+ @ Test
126
+ void testSetEditorConfigCanOverrideEditorConfigFile () throws IOException {
127
+ setFile (".editorconfig" ).toResource ("kotlin/ktlint/intellij_idea/.editorconfig" );
128
+ setFile ("build.gradle" ).toLines (
129
+ "plugins {" ,
130
+ " id 'org.jetbrains.kotlin.jvm' version '1.5.31'" ,
131
+ " id 'com.diffplug.spotless'" ,
132
+ "}" ,
133
+ "repositories { mavenCentral() }" ,
134
+ "spotless {" ,
135
+ " kotlin {" ,
136
+ " ktlint().editorConfigOverride([" ,
137
+ " ktlint_code_style: \" ktlint_official\" ," ,
138
+ " ])" ,
139
+ " }" ,
140
+ "}" );
141
+ checkKtlintOfficialStyle ();
142
+ }
143
+
108
144
@ Test
109
145
void testWithHeader () throws IOException {
110
146
setFile ("build.gradle" ).toLines (
@@ -144,4 +180,11 @@ void testWithCustomMaxWidthDefaultStyleKtfmt() throws IOException {
144
180
gradleRunner ().withArguments ("spotlessApply" ).build ();
145
181
assertFile ("src/main/kotlin/max-width.kt" ).sameAsResource ("kotlin/ktfmt/max-width.clean" );
146
182
}
183
+
184
+ private void checkKtlintOfficialStyle () throws IOException {
185
+ String path = "src/main/kotlin/Main.kt" ;
186
+ setFile (path ).toResource ("kotlin/ktlint/experimentalEditorConfigOverride.dirty" );
187
+ gradleRunner ().withArguments ("spotlessApply" ).build ();
188
+ assertFile (path ).sameAsResource ("kotlin/ktlint/experimentalEditorConfigOverride.ktlintOfficial.clean" );
189
+ }
147
190
}
0 commit comments