Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid changing newlines #1830

Merged
merged 3 commits into from
Nov 28, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,22 @@ class DiktatProcessorFactoryImpl : DiktatProcessorFactory {
}

companion object {
private fun DiktatRuleSet.toKtLintEngine(): KtLintRuleEngine = KtLintRuleEngine(ruleProviders = toKtLint())
private fun DiktatRuleSet.toKtLintEngine(): KtLintRuleEngine = KtLintRuleEngine(
ruleProviders = toKtLint(),
editorConfigDefaults = EditorConfigDefaults(
nulls marked this conversation as resolved.
Show resolved Hide resolved
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
Loading