-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add applicable
.editorconfig
s as tasks input
- Loading branch information
1 parent
710a949
commit 255a8f3
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/EditorConfigUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.jmailen.gradle.kotlinter.tasks | ||
|
||
import org.gradle.api.file.ProjectLayout | ||
import java.io.File | ||
|
||
internal fun ProjectLayout.findApplicableEditorConfigFiles(): Sequence<File> { | ||
val projectEditorConfig = projectDirectory.file(".editorconfig").asFile | ||
|
||
return generateSequence(seed = projectEditorConfig) { editorconfig -> | ||
if (editorconfig.isRootEditorConfig) { | ||
null | ||
} else { | ||
editorconfig.parentFile?.parentFile?.resolve(".editorconfig") | ||
} | ||
} | ||
} | ||
|
||
private val File.isRootEditorConfig: Boolean | ||
get() { | ||
if (!isFile || !canRead()) return false | ||
|
||
return useLines { lines -> | ||
lines.any { line -> line.matches(editorConfigRootRegex) } | ||
} | ||
} | ||
|
||
/** | ||
* According to https://editorconfig.org/ root-most EditorConfig file contains line with `root=true` | ||
*/ | ||
private val editorConfigRootRegex = "^root\\s?=\\s?true".toRegex() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters