SwiftLint icon indicating copy to clipboard operation
SwiftLint copied to clipboard

stdout output contains duplicate content when autocorrecting vertical whitespace

Open onelittlefish opened this issue 3 years ago • 1 comments

New Issue Checklist

Describe the bug

I'm hoping to make use of https://github.com/realm/SwiftLint/pull/4132 (stdin/stdout). Autocorrecting vertical whitespace (vertical_whitespace, vertical_whitespace_closing_braces, and vertical_whitespace_opening_braces) seems to duplicate the file content in the output.

Test.swift:
class Test {
    let x : String = "test"


}

Output:
$ cat Test.swift | swiftlint --fix --use-stdin --enable-all-rules
class Test {
    let x: String = "test"


}

class Test {
    let x : String = "test"

}

class Test {
    let x : String = "test"
}

Done correcting 1 file!

The issue does not occur if the vertical_whitespace, vertical_whitespace_closing_braces, and vertical_whitespace_opening_braces rules are excluded.

.swiftlint-fix.yml:
disabled_rules:
  - vertical_whitespace
  - vertical_whitespace_closing_braces
  - vertical_whitespace_opening_braces
Output:
$ cat Test.swift | swiftlint --fix --use-stdin --config .swiftlint-fix.yml         
class Test {
    let x: String = "test"


}

Done correcting 1 file!

Environment

  • SwiftLint version (run swiftlint version to be sure)? 0.49.1
  • Installation method used (Homebrew, CocoaPods, building from source, etc)? SwiftLint.pkg
  • Are you using nested configurations? No
  • Which Xcode version are you using (check xcodebuild -version)? 13.3.1 (13E500a)

onelittlefish avatar Sep 17 '22 02:09 onelittlefish

This behavior can be observed with all rules writing directly to the file when correcting. It's not only about the vertical_whitespace* rules. They perform the fix and immediately write the result back to the file. If the file is stdout we notice the different writes as separate outputs.

SimplyDanny avatar Sep 17 '22 19:09 SimplyDanny