Compare commits

...

3 Commits

Author SHA1 Message Date
JP Simard 180d941327
Release 0.43.1 2021-03-15 12:00:28 -04:00
JP Simard 384e8f12ef
Re-add --format flag to reformat Swift files using SourceKit (#3573)
Missed during the migration from Commandant to swift-argument-parser in
https://github.com/realm/SwiftLint/pull/3465.

Fixes https://github.com/realm/SwiftLint/issues/3571.
2021-03-15 11:59:04 -04:00
Stephen Williams 958a8c5299
Rename the “File Line Length” rule to just “File Length” 2021-03-15 11:59:04 -04:00
7 changed files with 28 additions and 4 deletions

View File

@ -1,4 +1,4 @@
## Master
## 0.43.1: Laundroformat
#### Breaking
@ -14,7 +14,14 @@
#### Bug Fixes
* None.
* Fix the File Length rule name.
[onato](https://github.com/onato)
[#3560](https://github.com/realm/SwiftLint/issues/3560)
* Re-add `--format` flag to reformat Swift files using SourceKit.
Only applied with `--fix`/`--autocorrect`.
[JP Simard](https://github.com/jpsim)
[#3571](https://github.com/realm/SwiftLint/issues/3571)
## 0.43.0: Clothes Line Interface

View File

@ -4,5 +4,5 @@ public struct Version {
public let value: String
/// The current SwiftLint version.
public static let current = Version(value: "0.43.0")
public static let current = Version(value: "0.43.1")
}

View File

@ -7,7 +7,7 @@ public struct FileLengthRule: ConfigurationProviderRule {
public static let description = RuleDescription(
identifier: "file_length",
name: "File Line Length",
name: "File Length",
description: "Files should not span too many lines.",
kind: .metrics,
nonTriggeringExamples: [

View File

@ -43,6 +43,7 @@ extension SwiftLint {
ignoreCache: true,
enableAllRules: false,
autocorrect: common.fix,
format: common.format,
compilerLogPath: compilerLogPath,
compileCommands: compileCommands
)

View File

@ -47,6 +47,7 @@ extension SwiftLint {
ignoreCache: noCache,
enableAllRules: enableAllRules,
autocorrect: common.fix,
format: common.format,
compilerLogPath: nil,
compileCommands: nil
)

View File

@ -20,6 +20,11 @@ struct LintOrAnalyzeArguments: ParsableArguments {
var config = [String]()
@Flag(name: [.long, .customLong("autocorrect")], help: "Correct violations whenever possible.")
var fix = false
@Flag(help: """
Should reformat the Swift files using the same mechanism used by Xcode (via SourceKit).
Only applied with `--fix`/`--autocorrect`.
""")
var format = false
@Flag(help: "Use an alternative algorithm to exclude paths for `excluded`, which may be faster in some cases.")
var useAlternativeExcluding = false
@Flag(help: "Read SCRIPT_INPUT_FILE* environment variables as files.")

View File

@ -157,6 +157,15 @@ struct LintOrAnalyzeCommand {
let storage = RuleStorage()
let configuration = Configuration(options: options)
return configuration.visitLintableFiles(options: options, cache: nil, storage: storage) { linter in
if options.format {
switch configuration.indentation {
case .tabs:
linter.format(useTabs: true, indentWidth: 4)
case .spaces(let count):
linter.format(useTabs: false, indentWidth: count)
}
}
let corrections = linter.correct(using: storage)
if !corrections.isEmpty && !options.quiet {
let correctionLogs = corrections.map({ $0.consoleDescription })
@ -191,6 +200,7 @@ struct LintOrAnalyzeOptions {
let ignoreCache: Bool
let enableAllRules: Bool
let autocorrect: Bool
let format: Bool
let compilerLogPath: String?
let compileCommands: String?