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

Disable the standard:filename rule whenever Ktlint CLI is run with option `--stdin #1745

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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.*"))
}
}
}