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 #### Breaking
@ -14,7 +14,14 @@
#### Bug Fixes #### 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 ## 0.43.0: Clothes Line Interface

View File

@ -4,5 +4,5 @@ public struct Version {
public let value: String public let value: String
/// The current SwiftLint version. /// 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( public static let description = RuleDescription(
identifier: "file_length", identifier: "file_length",
name: "File Line Length", name: "File Length",
description: "Files should not span too many lines.", description: "Files should not span too many lines.",
kind: .metrics, kind: .metrics,
nonTriggeringExamples: [ nonTriggeringExamples: [

View File

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

View File

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

View File

@ -20,6 +20,11 @@ struct LintOrAnalyzeArguments: ParsableArguments {
var config = [String]() var config = [String]()
@Flag(name: [.long, .customLong("autocorrect")], help: "Correct violations whenever possible.") @Flag(name: [.long, .customLong("autocorrect")], help: "Correct violations whenever possible.")
var fix = false 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.") @Flag(help: "Use an alternative algorithm to exclude paths for `excluded`, which may be faster in some cases.")
var useAlternativeExcluding = false var useAlternativeExcluding = false
@Flag(help: "Read SCRIPT_INPUT_FILE* environment variables as files.") @Flag(help: "Read SCRIPT_INPUT_FILE* environment variables as files.")

View File

@ -157,6 +157,15 @@ struct LintOrAnalyzeCommand {
let storage = RuleStorage() let storage = RuleStorage()
let configuration = Configuration(options: options) let configuration = Configuration(options: options)
return configuration.visitLintableFiles(options: options, cache: nil, storage: storage) { linter in 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) let corrections = linter.correct(using: storage)
if !corrections.isEmpty && !options.quiet { if !corrections.isEmpty && !options.quiet {
let correctionLogs = corrections.map({ $0.consoleDescription }) let correctionLogs = corrections.map({ $0.consoleDescription })
@ -191,6 +200,7 @@ struct LintOrAnalyzeOptions {
let ignoreCache: Bool let ignoreCache: Bool
let enableAllRules: Bool let enableAllRules: Bool
let autocorrect: Bool let autocorrect: Bool
let format: Bool
let compilerLogPath: String? let compilerLogPath: String?
let compileCommands: String? let compileCommands: String?