Skip to content

Commit

Permalink
Disable the standard:filename rule whenever Ktlint CLI is run with …
Browse files Browse the repository at this point in the history
…option `--stdin (#1745)

Closes #1742
  • Loading branch information
paul-dingemans committed Dec 24, 2022
1 parent 557c640 commit 15655db
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -11,6 +11,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
### Fixed

* An enumeration class having a primary constructor and in which the list of enum entries is followed by a semicolon then do not remove the semicolon in case it is followed by code element `no-semi` ([#1733](https://github.com/pinterest/ktlint/issues/1733))
* Disable the `standard:filename` rule whenever Ktlint CLI is run with option `--stdin` ([#1742](https://github.com/pinterest/ktlint/issues/1742))

### Changed

Expand Down
Expand Up @@ -261,6 +261,8 @@ internal class KtlintCommandLine {
plus(*disabledRulesEditorConfigOverrides())
}.applyIf(android) {
plus(CODE_STYLE_PROPERTY to CodeStyleValue.android)
}.applyIf(stdin) {
plus(createRuleExecutionEditorConfigProperty("standard:filename") to RuleExecution.disabled)
}

private fun disabledRulesEditorConfigOverrides() =
Expand Down
16 changes: 16 additions & 0 deletions ktlint/src/test/kotlin/com/pinterest/ktlint/SimpleCLITest.kt
Expand Up @@ -2,6 +2,7 @@ package com.pinterest.ktlint

import java.io.ByteArrayInputStream
import java.nio.file.Path
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.SoftAssertions
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.io.TempDir
Expand Down Expand Up @@ -168,4 +169,19 @@ class SimpleCLITest {
}.assertAll()
}
}

@Test
fun `Issue 1742 - Disable the filename rule when --stdin is used`(
@TempDir
tempDir: Path,
) {
CommandLineTestRunner(tempDir)
.run(
testProjectName = "too-many-empty-lines",
arguments = listOf("--stdin"),
stdin = ByteArrayInputStream("fun foo() = 42".toByteArray()),
) {
assertThat(normalOutput).containsLineMatching(Regex(".*ktlint_standard_filename: disabled.*"))
}
}
}

0 comments on commit 15655db

Please sign in to comment.