Skip to content

Commit

Permalink
Avoid changing newlines (#1830)
Browse files Browse the repository at this point in the history
- set `editorConfigDefaults` with `end_of_line` based on current system
  • Loading branch information
nulls authored Nov 28, 2023
1 parent fca7f53 commit 626bac9
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ import com.saveourtool.diktat.api.DiktatCallback
import com.saveourtool.diktat.api.DiktatRuleSet
import com.saveourtool.diktat.ktlint.KtLintRuleWrapper.Companion.toKtLint
import com.pinterest.ktlint.rule.engine.api.Code
import com.pinterest.ktlint.rule.engine.api.EditorConfigDefaults
import com.pinterest.ktlint.rule.engine.api.KtLintRuleEngine
import com.pinterest.ktlint.rule.engine.api.LintError
import org.ec4j.core.model.EditorConfig
import org.ec4j.core.model.Glob
import org.ec4j.core.model.Property
import org.ec4j.core.model.PropertyType
import java.nio.file.Path

private typealias LintCallback = (LintError) -> Unit
Expand Down Expand Up @@ -41,7 +46,23 @@ class DiktatProcessorFactoryImpl : DiktatProcessorFactory {
}

companion object {
private fun DiktatRuleSet.toKtLintEngine(): KtLintRuleEngine = KtLintRuleEngine(ruleProviders = toKtLint())
private fun DiktatRuleSet.toKtLintEngine(): KtLintRuleEngine = KtLintRuleEngine(
ruleProviders = toKtLint(),
// use platform dependent endlines in process of editing
editorConfigDefaults = EditorConfigDefaults(
EditorConfig.builder()
.openSection()
.glob(Glob("**"))
.property(
Property.builder()
.name(PropertyType.end_of_line.name)
.type(PropertyType.end_of_line)
.value(PropertyType.EndOfLineValue.ofEndOfLineString(System.lineSeparator())?.name)
)
.closeSection()
.build()
)
)

private fun Path.toKtLint(): Code = Code.fromFile(this.toFile())

Expand Down

0 comments on commit 626bac9

Please sign in to comment.