Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Undesired behavior with --format #2374

Closed
2 tasks done
ornithocoder opened this issue Sep 1, 2018 · 0 comments
Closed
2 tasks done

Undesired behavior with --format #2374

ornithocoder opened this issue Sep 1, 2018 · 0 comments

Comments

@ornithocoder
Copy link
Contributor

ornithocoder commented Sep 1, 2018

New Issue Checklist

Bug Report

As closure_end_indentation's description states, a closure end should have the same indentation as the line that started it, but this behavior conflicts with Xcode's indentation (^i) and SwiftLint's --format.

Below, a sample .swiftlint.yml file with the rule enabled, a swift file - file.swift - with one of the examples from swiftlint rules closure_end_indentation and the output, showing that the code is correct (closure ending with correct indentation, as imposed by the rule).

$ cat .swiftlint.yml
opt_in_rules:
  - closure_end_indentation

$ cat file.swift
SignalProducer(values: [1, 2, 3])
    .startWithNext { number in
        print(number)
    }

$ swiftlint lint
Loading configuration from '.swiftlint.yml'
Linting Swift files at paths 
Linting 'file.swift' (1/1)
Done linting! Found 0 violations, 0 serious in 1 file.

However, when the command swiftlint autocorrect --format runs, it autocorrects the file and reformats it, reverting the autocorrection applied by the rule.

$ swiftlint autocorrect --format
Loading configuration from '.swiftlint.yml'
Correcting Swift files at paths 
Correcting 'file.swift' (1/1)
Done correcting 1 file!

$ cat file.swift
SignalProducer(values: [1, 2, 3])
    .startWithNext { number in
        print(number)
}

As result, autocorrect has to run twice - first to format and then to correct the files -, adding a undesired delay to the build phase:

$ swiftlint autocorrect --format
$ swiftlint autocorrect

Ideally swiftlint autocorrect --format should first format and then autocorrect the files.

Environment

  • SwiftLint version (run swiftlint version to be sure)? master
  • Installation method used (Homebrew, CocoaPods, building from source, etc)? swift build
  • Paste your configuration file:
opt_in_rules:
  - closure_end_indentation
  • Are you using nested configurations? no.
  • Which Xcode version are you using (check xcode-select -p)? 9.4.1
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant