forked from pinterest/ktlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EditorConfigDefaults.kt
36 lines (32 loc) · 1.45 KB
/
EditorConfigDefaults.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package com.pinterest.ktlint.core.api
import com.pinterest.ktlint.core.internal.EditorConfigDefaultsLoader
import java.nio.file.Path
import org.ec4j.core.model.EditorConfig
/**
* Wrapper around the [EditorConfig]. Only to be used only for the default value of properties.
*/
public data class EditorConfigDefaults(public val value: EditorConfig) {
public companion object {
private val editorConfigDefaultsLoader = EditorConfigDefaultsLoader()
/**
* Loads properties from [path]. [path] may either locate a file (also allows specifying a file with a name other
* than ".editorconfig") or a directory in which a file with name ".editorconfig" is expected to exist. Properties
* from all globs are returned.
*
* If [path] is not valid then the [emptyEditorConfigDefaults] is returned.
*
* The property "root" which denotes whether the parent directory is to be checked for the existence of a fallback
* ".editorconfig" is ignored entirely.
*/
public fun load(path: Path?): EditorConfigDefaults =
if (path == null) {
emptyEditorConfigDefaults
} else {
editorConfigDefaultsLoader.load(path)
}
/**
* Empty representation of [EditorConfigDefaults].
*/
public val emptyEditorConfigDefaults: EditorConfigDefaults = EditorConfigDefaults(EditorConfig.builder().build())
}
}