realm / SwiftLint

A tool to enforce Swift style and conventions.
https://realm.github.io/SwiftLint
MIT License
18.55k stars 2.21k forks source link

Undo history cleared when using SwiftLint autocorrect in the build phase script #3512

Closed marcoboerner closed 3 years ago

marcoboerner commented 3 years ago

Description of the bug

When using SwiftLint autocorrect and a file is corrected after building the app, the undo history of the corrected file is gone.

Environment

# By default, SwiftLint uses a set of sensible default rules you can adjust:
disabled_rules: # rule identifiers turned on by default to exclude from running
  - line_length
  - todo
excluded: # paths to ignore during linting. Takes precedence over `included`.
  - Carthage
  - Pods
  - bak.swift # Exclude files with a wildcard
# naming rules can set warnings/errors for min_length and max_length
# additionally they can set excluded names
type_name:
  min_length: 1 # only warning
  max_length: # warning and error
    warning: 50
    error: 60
  excluded: iPhone # excluded via string
  allowed_symbols: ["_"] # these are allowed in type names
identifier_name:
  min_length: 1

Create a SwiftUI project with only this code:

import SwiftUI

struct ContentView: View {
    var body: some View {
        Text("Hello, world!")
            .padding()
        //Comment violation
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Setup the following as a build script:

if which swiftlint >/dev/null; then
  swiftlint autocorrect && swiftlint
else
  echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi

To reproduce the error, simply change a few things. Then run the app and the undo history will be gone.

marcelofabri commented 3 years ago

This is just how Xcode works, unfortunately there's nothing we can do here.