Skip to content

Commit

Permalink
Extract EditorConfigProperty class and definitions to separate files …
Browse files Browse the repository at this point in the history
…in subpackage "editorconfig"
  • Loading branch information
paul-dingemans committed Dec 10, 2022
1 parent 2590ed8 commit 481ad64
Show file tree
Hide file tree
Showing 49 changed files with 597 additions and 544 deletions.
24 changes: 10 additions & 14 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ The KtLint CLI has not been changed. Although you can still use parameter `--exp

If you are not an API consumer or Rule Set provider then you can skip this section.

#### Class relocations

Classes below have been relocated:

* Class `com.pinterest.ktlint.core.api.UsesEditorConfigProperties.EditorConfigProperty` has been replaced with `com.pinterest.ktlint.core.api.editorconfig.EditorConfigProperty`.
* Class `com.pinterest.ktlint.core.KtLintParseException` has been replaced with `com.pinterest.ktlint.core.api.KtLintParseException`.
* Class `com.pinterest.ktlint.core.RuleExecutionException` has been replaced with `com.pinterest.ktlint.core.api.KtLintRuleException`.
* Class `com.pinterest.ktlint.reporter.format.internal.Color` has been moved to `com.pinterest.ktlint.reporter.format.Color`.
* Class `com.pinterest.ktlint.reporter.plain.internal.Color` has been moved to `com.pinterest.ktlint.reporter.plain.Color`.

#### Invoking `lint` and `format`

This is the last release that supports the `ExperimentalParams` to invoke the `lint` and `format` functions of KtLint. The `ExperimentalParams` contains a mix of configuration settings which are not dependent on the file/code which is to be processed. Other parameters in that class describe the code/file to be processed but can be configured inconsistently (for example a file with name "foo.kt" could be marked as a Kotlin Script file).
Expand Down Expand Up @@ -70,20 +80,6 @@ if (node.isRoot()) {
}
```

#### ParseException

Class `com.pinterest.ktlint.core.KtLintParseException` has been replaced with `com.pinterest.ktlint.core.api.KtLintParseException`.

#### RuleExecutionException

Class `com.pinterest.ktlint.core.RuleExecutionException` has been replaced with `com.pinterest.ktlint.core.api.KtLintRuleException`.

#### Color

Class `com.pinterest.ktlint.reporter.format.internal.Color` has been moved to `com.pinterest.ktlint.reporter.format.Color`.

Class `com.pinterest.ktlint.reporter.plain.internal.Color` has been moved to `com.pinterest.ktlint.reporter.plain.Color`.

### Added
* Wrap blocks in case the max line length is exceeded or in case the block contains a new line `wrapping` ([#1643](https://github.com/pinterest/ktlint/issue/1643))
* patterns can be read in from `stdin` with the `--patterns-from-stdin` command line options/flags ([#1606](https://github.com/pinterest/ktlint/pull/1606))
Expand Down
12 changes: 6 additions & 6 deletions ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/KtLint.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ package com.pinterest.ktlint.core
import com.pinterest.ktlint.core.KtLint.ExperimentalParams
import com.pinterest.ktlint.core.KtLint.format
import com.pinterest.ktlint.core.KtLint.lint
import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties
import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.CODE_STYLE_PROPERTY
import com.pinterest.ktlint.core.api.EditorConfigDefaults
import com.pinterest.ktlint.core.api.EditorConfigDefaults.Companion.EMPTY_EDITOR_CONFIG_DEFAULTS
import com.pinterest.ktlint.core.api.EditorConfigOverride
import com.pinterest.ktlint.core.api.EditorConfigOverride.Companion.EMPTY_EDITOR_CONFIG_OVERRIDE
import com.pinterest.ktlint.core.api.KtLintRuleException
import com.pinterest.ktlint.core.api.UsesEditorConfigProperties
import com.pinterest.ktlint.core.api.editorconfig.CodeStyleValue
import com.pinterest.ktlint.core.api.editorconfig.DEFAULT_EDITOR_CONFIG_PROPERTIES
import com.pinterest.ktlint.core.internal.EditorConfigFinder
import com.pinterest.ktlint.core.internal.EditorConfigGenerator
import com.pinterest.ktlint.core.internal.EditorConfigLoader
Expand Down Expand Up @@ -120,7 +120,7 @@ public object KtLint {
.filterIsInstance<UsesEditorConfigProperties>()
.map { it.editorConfigProperties }
.flatten()
.plus(DefaultEditorConfigProperties.editorConfigProperties)
.plus(DEFAULT_EDITOR_CONFIG_PROPERTIES)
.map { it.name }
.distinct()
.toSet()
Expand Down Expand Up @@ -580,10 +580,10 @@ public class KtLintRuleEngine(
public fun generateKotlinEditorConfigSection(filePath: Path): String {
val codeStyle =
editorConfigOverride
.properties[CODE_STYLE_PROPERTY]
.properties[com.pinterest.ktlint.core.api.editorconfig.CODE_STYLE_PROPERTY]
?.parsed
?.safeAs<DefaultEditorConfigProperties.CodeStyleValue>()
?: CODE_STYLE_PROPERTY.defaultValue
?.safeAs<CodeStyleValue>()
?: com.pinterest.ktlint.core.api.editorconfig.CODE_STYLE_PROPERTY.defaultValue
val rules =
ruleProviders
.map { RuleRunner(it) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.pinterest.ktlint.core.api

import com.pinterest.ktlint.core.api.UsesEditorConfigProperties.EditorConfigProperty
import com.pinterest.ktlint.core.api.editorconfig.EditorConfigProperty
import org.ec4j.core.model.PropertyType.PropertyValue

/**
Expand Down
Loading

0 comments on commit 481ad64

Please sign in to comment.