diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f5a9c7b..70780451 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Change Log +## [0.52.4](https://github.com/nicklockwood/SwiftFormat/releases/tag/0.52.4) (2023-09-17) + +- Fixed `docComments` rule incorrectly replacing comments inside switch cases and if/guard conditions +- Fixed `redundantLet` rule removing required `let` inside `ViewBuilder` modifiers +- Fixed `redundantLet` rule removing required `let` after `@MainActor` or `@Sendable` +- Fixed bug when using `--wrapconditions after-first` if first line of condition is a comment +- Added more context to "failed to terminate" error message to aid tracking down issues +- Updated `sortTypealiases` rule to also remove duplicate protocols in declaration +- Added some fixes to support parameter packs in Swift 5.9 + ## [0.52.3](https://github.com/nicklockwood/SwiftFormat/releases/tag/0.52.3) (2023-09-02) - Fixed incorrect hoisting of `try` inside multiline string literal interpolations diff --git a/CommandLineTool/swiftformat b/CommandLineTool/swiftformat index cdb21226..862dfd26 100755 Binary files a/CommandLineTool/swiftformat and b/CommandLineTool/swiftformat differ diff --git a/Sources/Arguments.swift b/Sources/Arguments.swift index e47fa44d..8ebdcd18 100644 --- a/Sources/Arguments.swift +++ b/Sources/Arguments.swift @@ -56,7 +56,7 @@ extension Options { } extension String { - // Find best match for the string in a list of options + /// Find best match for the string in a list of options func bestMatches(in options: [String]) -> [String] { let lowercaseQuery = lowercased() // Sort matches by Levenshtein edit distance @@ -108,8 +108,8 @@ extension String { } } -// Parse a space-delimited string into an array of command-line arguments -// Replicates the behavior implemented by the console when parsing input +/// Parse a space-delimited string into an array of command-line arguments +/// Replicates the behavior implemented by the console when parsing input func parseArguments(_ argumentString: String, ignoreComments: Bool = true) -> [String] { var arguments = [""] // Arguments always begin with script path var characters = String.UnicodeScalarView.SubSequence(argumentString.unicodeScalars) @@ -149,7 +149,7 @@ func parseArguments(_ argumentString: String, ignoreComments: Bool = true) -> [S return arguments } -// Parse a flat array of command-line arguments into a dictionary of flags and values +/// Parse a flat array of command-line arguments into a dictionary of flags and values func preprocessArguments(_ args: [String], _ names: [String]) throws -> [String: String] { var anonymousArgs = 0 var namedArgs: [String: String] = [:] @@ -205,7 +205,7 @@ func preprocessArguments(_ args: [String], _ names: [String]) throws -> [String: return namedArgs } -// Parse a comma-delimited list of items +/// Parse a comma-delimited list of items func parseCommaDelimitedList(_ string: String) -> [String] { string.components(separatedBy: ",").compactMap { let item = $0.trimmingCharacters(in: .whitespacesAndNewlines) @@ -213,7 +213,7 @@ func parseCommaDelimitedList(_ string: String) -> [String] { } } -// Parse a comma-delimited string into an array of rules +/// Parse a comma-delimited string into an array of rules let allRules = Set(FormatRules.byName.keys) func parseRules(_ rules: String) throws -> [String] { try parseCommaDelimitedList(rules).flatMap { proposedName -> [String] in @@ -238,7 +238,7 @@ func parseRules(_ rules: String) throws -> [String] { } } -// Parse single file path, disallowing globs or commas +/// Parse single file path, disallowing globs or commas func parsePath(_ path: String, for argument: String, in directory: String) throws -> URL { let expandedPath = expandPath(path, in: directory) if !FileManager.default.fileExists(atPath: expandedPath.path) { @@ -252,12 +252,12 @@ func parsePath(_ path: String, for argument: String, in directory: String) throw return expandedPath } -// Parse one or more comma-delimited file paths, expanding globs as required +/// Parse one or more comma-delimited file paths, expanding globs as required func parsePaths(_ paths: String, in directory: String) throws -> [URL] { try matchGlobs(expandGlobs(paths, in: directory), in: directory) } -// Merge two dictionaries of arguments +/// Merge two dictionaries of arguments func mergeArguments(_ args: [String: String], into config: [String: String]) throws -> [String: String] { var input = config var output = args @@ -327,7 +327,7 @@ func mergeArguments(_ args: [String: String], into config: [String: String]) thr return output } -// Parse a configuration file into a dictionary of arguments +/// Parse a configuration file into a dictionary of arguments public func parseConfigFile(_ data: Data) throws -> [String: String] { guard let input = String(data: data, encoding: .utf8) else { throw FormatError.reading("Unable to read data for configuration file") @@ -378,7 +378,7 @@ private func effectiveContent(of line: String) -> String { .trimmingCharacters(in: .whitespaces) } -// Serialize a set of options into either an arguments string or a file +/// Serialize a set of options into either an arguments string or a file func serialize(options: Options, swiftVersion: Version = .undefined, excludingDefaults: Bool = false, @@ -412,7 +412,7 @@ func serialize(options: Options, .joined(separator: separator) } -// Serialize arguments +/// Serialize arguments func serialize(arguments: [String: String], separator: String = "\n") -> String { @@ -425,7 +425,7 @@ func serialize(arguments: [String: String], }.sorted().joined(separator: separator) } -// Get command line arguments from options +/// Get command line arguments from options func argumentsFor(_ options: Options, excludingDefaults: Bool = false) -> [String: String] { var args = [String: String]() if let fileOptions = options.fileOptions { @@ -523,7 +523,7 @@ private func processOption(_ key: String, } } -// Parse rule names from arguments +/// Parse rule names from arguments public func rulesFor(_ args: [String: String], lint: Bool) throws -> Set { var rules = allRules rules = try args["rules"].map { @@ -545,7 +545,7 @@ public func rulesFor(_ args: [String: String], lint: Bool) throws -> Set return rules } -// Parse FileOptions from arguments +/// Parse FileOptions from arguments func fileOptionsFor(_ args: [String: String], in directory: String) throws -> FileOptions? { var options = FileOptions() var arguments = Set(fileArguments) @@ -584,8 +584,8 @@ func fileOptionsFor(_ args: [String: String], in directory: String) throws -> Fi return containsFileOption ? options : nil } -// Parse FormatOptions from arguments -// Returns nil if the arguments dictionary does not contain any formatting arguments +/// Parse FormatOptions from arguments +/// Returns nil if the arguments dictionary does not contain any formatting arguments public func formatOptionsFor(_ args: [String: String]) throws -> FormatOptions? { var options = FormatOptions.default var arguments = Set(formattingArguments) @@ -601,7 +601,7 @@ public func formatOptionsFor(_ args: [String: String]) throws -> FormatOptions? return containsFormatOption ? options : nil } -// Get deprecation warnings from a set of arguments +/// Get deprecation warnings from a set of arguments func warningsForArguments(_ args: [String: String], ignoreUnusedOptions: Bool = false) -> [String] { var warnings = [String]() for option in Descriptors.all { diff --git a/Sources/CommandLine.swift b/Sources/CommandLine.swift index d3c1ca0d..2c72ac0b 100644 --- a/Sources/CommandLine.swift +++ b/Sources/CommandLine.swift @@ -74,7 +74,7 @@ private func print(_ message: String, as type: CLI.OutputType = .info) { } } -// Print warnings and return true if any was an actual error +/// Print warnings and return true if any was an actual error private func printWarnings(_ errors: [Error]) -> Bool { var containsError = false for error in errors { @@ -102,7 +102,7 @@ private func printWarnings(_ errors: [Error]) -> Bool { return containsError } -// Represents the exit codes to the command line. See `man sysexits` for more information. +/// Represents the exit codes to the command line. See `man sysexits` for more information. public enum ExitCode: Int32 { case ok = 0 // EX_OK case lintFailure = 1 diff --git a/Sources/Formatter.swift b/Sources/Formatter.swift index 2bfe7d66..d714095a 100644 --- a/Sources/Formatter.swift +++ b/Sources/Formatter.swift @@ -2,7 +2,7 @@ // Formatter.swift // SwiftFormat // -// Version 0.52.3 +// Version 0.52.4 // // Created by Nick Lockwood on 12/08/2016. // Copyright 2016 Nick Lockwood @@ -47,10 +47,10 @@ public class Formatter: NSObject { private var tempOptions: FormatOptions? private var wasNextDirective = false - // Formatting range + /// Formatting range public var range: Range? - // Current rule, used for handling comment directives + /// Current rule, used for handling comment directives var currentRule: FormatRule? { didSet { disabledCount = 0 @@ -64,7 +64,7 @@ public class Formatter: NSObject { } } - // Is current rule enabled + /// Is current rule enabled var isEnabled: Bool { if ruleDisabled || disabledCount + disabledNext > 0 || range?.contains(enumerationIndex) == false @@ -77,7 +77,7 @@ public class Formatter: NSObject { /// Directives that can be used in comments, e.g. `// swiftformat:disable rule` let directives = ["disable", "enable", "options", "sort"] - // Process a comment token (which may contain directives) + /// Process a comment token (which may contain directives) func processCommentBody(_ comment: String, at index: Int) { var prefix = "swiftformat:" guard let range = comment.range(of: prefix) else { @@ -590,7 +590,7 @@ public extension Formatter { return 0 // Inserted 0 tokens } - // As above, but only if formatting is enabled + /// As above, but only if formatting is enabled @discardableResult internal func insertSpaceIfEnabled(_ space: String, at index: Int) -> Int { isEnabled ? insertSpace(space, at: index) : 0 diff --git a/Sources/FormattingHelpers.swift b/Sources/FormattingHelpers.swift index b6f2731d..2cf77d46 100644 --- a/Sources/FormattingHelpers.swift +++ b/Sources/FormattingHelpers.swift @@ -11,7 +11,7 @@ import Foundation // MARK: shared helper methods extension Formatter { - // should brace be wrapped according to `wrapMultilineStatementBraces` rule? + /// should brace be wrapped according to `wrapMultilineStatementBraces` rule? func shouldWrapMultilineStatementBrace(at index: Int) -> Bool { assert(tokens[index] == .startOfScope("{")) guard let endIndex = endOfScope(at: index), @@ -36,7 +36,7 @@ extension Formatter { return false } - // remove self if possible + /// remove self if possible func removeSelf(at i: Int, exclude: Set, include: Set? = nil) -> Bool { guard case let .identifier(selfKeyword) = tokens[i], ["self", "Self"].contains(selfKeyword) else { assertionFailure() @@ -82,7 +82,7 @@ extension Formatter { return true } - // gather declared variable names, starting at index after let/var keyword + /// gather declared variable names, starting at index after let/var keyword func processDeclaredVariables(at index: inout Int, names: inout Set, removeSelfKeyword: String?, onlyLocal: Bool, scopeAllowsImplicitSelfRebinding: Bool) @@ -270,7 +270,7 @@ extension Formatter { } } - // Shared wrap implementation + /// Shared wrap implementation func wrapCollectionsAndArguments(completePartialWrapping: Bool, wrapSingleArguments: Bool) { let maxWidth = options.maxWidth func removeLinebreakBeforeEndOfScope(at endOfScope: inout Int) { @@ -540,7 +540,7 @@ extension Formatter { var isParameters = false switch string { case "(": - /// Don't wrap color/image literals due to Xcode bug + // Don't wrap color/image literals due to Xcode bug guard let prevToken = self.token(at: i - 1), prevToken != .keyword("#colorLiteral"), prevToken != .keyword("#imageLiteral") @@ -739,10 +739,10 @@ extension Formatter { } } - /// Wraps / re-wraps a multi-line statement where each delimiter index - /// should be the first token on its line, if the statement - /// is longer than the max width or there is already a linebreak - /// adjacent to one of the delimiters + // Wraps / re-wraps a multi-line statement where each delimiter index + // should be the first token on its line, if the statement + // is longer than the max width or there is already a linebreak + // adjacent to one of the delimiters @discardableResult func wrapMultilineStatement( startIndex: Int, @@ -999,8 +999,8 @@ extension Formatter { } } - // Common implementation for the `hoistTry` and `hoistAwait` rules - // Hoists the first keyword of the specified type out of the specified scope + /// Common implementation for the `hoistTry` and `hoistAwait` rules + /// Hoists the first keyword of the specified type out of the specified scope func hoistEffectKeyword( _ keyword: String, inScopeAt scopeStart: Int, @@ -1469,7 +1469,7 @@ extension Formatter { } } -// Utility functions used by organizeDeclarations rule +/// Utility functions used by organizeDeclarations rule // TODO: find a better place to put this extension Formatter { /// Categories of declarations within an individual type @@ -1883,7 +1883,7 @@ extension Formatter { $0.isComment && $0.string.contains("swiftformat:sort") && !$0.string.contains(":sort:") }) - /// Sorts the given categoried declarations based on their derived metadata + // Sorts the given categoried declarations based on their derived metadata func sortDeclarations( _ declarations: CategorizedDeclarations, byCategory sortByCategory: Bool, @@ -1941,8 +1941,8 @@ extension Formatter { if typeDeclaration.kind == "struct", !typeDeclaration.body.contains(where: { $0.keyword == "init" }) { - /// Whether or not this declaration is an instance property that can affect - /// the parameters struct's synthesized memberwise initializer + // Whether or not this declaration is an instance property that can affect + // the parameters struct's synthesized memberwise initializer func affectsSynthesizedMemberwiseInitializer( _ declaration: Declaration, _ type: DeclarationType? @@ -2114,7 +2114,7 @@ extension Formatter { } extension Formatter { - /// A generic type parameter for a method + // A generic type parameter for a method class GenericType { /// The name of the generic parameter. For example with `` the generic parameter `name` is `T`. let name: String @@ -2153,8 +2153,8 @@ extension Formatter { self.conformances = conformances } - // The opaque parameter syntax that represents this generic type, - // if the constraints can be expressed using this syntax + /// The opaque parameter syntax that represents this generic type, + /// if the constraints can be expressed using this syntax func asOpaqueParameter(useSomeAny: Bool) -> [Token]? { // Protocols with primary associated types that can be used with // opaque parameter syntax. In the future we could make this extensible @@ -2850,14 +2850,14 @@ extension Formatter { closureLocalNames.insert("self") } - /// Whether or not the closure at the current index permits implicit self. - /// - /// SE-0269 (in Swift 5.3) allows implicit self when: - /// - the closure captures self explicitly using [self] or [unowned self] - /// - self is not a reference type - /// - /// SE-0365 (in Swift 5.8) additionally allows implicit self using - /// [weak self] captures after self has been unwrapped. + // Whether or not the closure at the current index permits implicit self. + // + // SE-0269 (in Swift 5.3) allows implicit self when: + // - the closure captures self explicitly using [self] or [unowned self] + // - self is not a reference type + // + // SE-0365 (in Swift 5.8) additionally allows implicit self using + // [weak self] captures after self has been unwrapped. func closureAllowsImplicitSelf() -> Bool { guard options.swiftVersion >= "5.3" else { return false diff --git a/Sources/OptionDescriptor.swift b/Sources/OptionDescriptor.swift index 64f47d34..a427c312 100644 --- a/Sources/OptionDescriptor.swift +++ b/Sources/OptionDescriptor.swift @@ -33,7 +33,7 @@ import Foundation class OptionDescriptor { enum ArgumentType: EnumAssociable { - // index 0 is official value, others are acceptable + /// index 0 is official value, others are acceptable case binary(true: [String], false: [String]) case `enum`([String]) case text diff --git a/Sources/Options.swift b/Sources/Options.swift index deff6e9b..ed71d2d9 100644 --- a/Sources/Options.swift +++ b/Sources/Options.swift @@ -90,7 +90,7 @@ public enum ArgumentStrippingMode: String, CaseIterable { case all = "always" } -// Wrap mode for @ attributes +/// Wrap mode for @ attributes public enum AttributeMode: String, CaseIterable { case prevLine = "prev-line" case sameLine = "same-line" @@ -434,18 +434,18 @@ public struct FormatOptions: CustomStringConvertible { public var useSomeAny: Bool public var wrapEffects: WrapEffects - // Deprecated + /// Deprecated public var indentComments: Bool - // Doesn't really belong here, but hard to put elsewhere + /// Doesn't really belong here, but hard to put elsewhere public var fragment: Bool public var ignoreConflictMarkers: Bool public var swiftVersion: Version public var fileInfo: FileInfo public var timeout: TimeInterval - // Enabled rules - this is a hack used to allow rules to vary their behavior - // based on other rules being enabled. Do not rely on it in other contexts + /// Enabled rules - this is a hack used to allow rules to vary their behavior + /// based on other rules being enabled. Do not rely on it in other contexts var enabledRules: Set = [] public static let `default` = FormatOptions() diff --git a/Sources/ParsingHelpers.swift b/Sources/ParsingHelpers.swift index f4a2be08..b52b01a7 100644 --- a/Sources/ParsingHelpers.swift +++ b/Sources/ParsingHelpers.swift @@ -590,7 +590,7 @@ extension Formatter { } } return false - case "class", "actor", "struct", "protocol", "enum", "extension", + case "class", "actor", "struct", "enum", "protocol", "extension", "func", "subscript", "catch": return false case "throws", "rethrows": @@ -1447,7 +1447,7 @@ extension Formatter { /// Whether or not this declaration defines a type (a class, enum, etc, but not an extension) var definesType: Bool { - ["class", "actor", "enum", "protocol", "struct", "typealias"].contains(keyword) + ["class", "actor", "struct", "enum", "protocol", "typealias"].contains(keyword) } /// The name of this type or variable @@ -1591,16 +1591,16 @@ extension Formatter { endOfDeclaration = linebreakSearchIndex + 1 } - /// If there was another declaration after this one in the same scope, - /// then we know this declaration ends before that one starts + // If there was another declaration after this one in the same scope, + // then we know this declaration ends before that one starts if let endOfDeclaration = endOfDeclaration { return endOfDeclaration } - /// Otherwise this is the last declaration in the scope. - /// To know where this declaration ends we just have to know where - /// the parent scope ends. - /// - We don't do this inside `parseDeclarations` itself since it handles this cases + // Otherwise this is the last declaration in the scope. + // To know where this declaration ends we just have to know where + // the parent scope ends. + // - We don't do this inside `parseDeclarations` itself since it handles this cases if fallBackToEndOfScope, declarationKeywordIndex != 0, let endOfParentScope = endOfScope(at: declarationKeywordIndex - 1), @@ -1639,7 +1639,7 @@ extension Formatter { return declarations.map { declaration in let declarationParser = Formatter(declaration.tokens) - /// Parses this declaration into a body of declarations separate from the start and end tokens + // Parses this declaration into a body of declarations separate from the start and end tokens func parseBody(in bodyRange: ClosedRange) -> (start: [Token], body: [Declaration], end: [Token]) { var startTokens = declarationParser.tokens[...bodyRange.lowerBound] var bodyTokens = declarationParser.tokens[bodyRange.lowerBound + 1 ..< bodyRange.upperBound] @@ -1719,10 +1719,10 @@ extension Formatter { /// Returns the declaration scope (global, type, or local) that the /// given token index is contained by. func declarationScope(at i: Int) -> DeclarationScope { - /// Declarations which have `DeclarationScope.type` + // Declarations which have `DeclarationScope.type` let typeDeclarations = Set(["class", "actor", "struct", "enum", "extension"]) - /// Declarations which have `DeclarationScope.local` + // Declarations which have `DeclarationScope.local` let localDeclarations = Set(["let", "var", "func", "subscript", "init", "deinit"]) let allDeclarationScopes = typeDeclarations.union(localDeclarations) @@ -1990,7 +1990,7 @@ extension Formatter { } } - // Range of tokens forming file header comment + /// Range of tokens forming file header comment var headerCommentTokenRange: Range? { guard !options.fragment else { return nil diff --git a/Sources/Rules.swift b/Sources/Rules.swift index 7fea1e6a..2d8cdba4 100644 --- a/Sources/Rules.swift +++ b/Sources/Rules.swift @@ -43,7 +43,7 @@ public final class FormatRule: Equatable, Comparable { let sharedOptions: [String] let deprecationMessage: String? - // Null rule, used for testing + /// Null rule, used for testing static let none: FormatRule = .init(help: "") { _ in } var isDeprecated: Bool { @@ -166,7 +166,7 @@ extension _FormatRules { return options.sorted() } - // Get shared-only options for a given set of rules + /// Get shared-only options for a given set of rules func sharedOptionsForRules(_ rules: [FormatRule]) -> [String] { var options = Set() var sharedOptions = Set() @@ -695,7 +695,7 @@ public struct _FormatRules { let typeEndIndex = formatter.index(of: .nonSpaceOrCommentOrLinebreak, before: equalsIndex) else { return } - /// Compares whether or not two types are equivalent + // Compares whether or not two types are equivalent func compare(typeStartingAfter j: Int, withTypeStartingAfter i: Int) -> (matches: Bool, i: Int, j: Int, wasValue: Bool) { @@ -766,7 +766,7 @@ public struct _FormatRules { } } - /// Removes a type already processed by `compare(typeStartingAfter:withTypeStartingAfter:)` + // Removes a type already processed by `compare(typeStartingAfter:withTypeStartingAfter:)` func removeType(after indexBeforeStartOfType: Int, i: Int, j: Int, wasValue: Bool) { if isInferred { formatter.removeTokens(in: colonIndex ... typeEndIndex) @@ -877,7 +877,7 @@ public struct _FormatRules { } } - // Converts types used for hosting only static members into enums to avoid instantiation. + /// Converts types used for hosting only static members into enums to avoid instantiation. public let enumNamespaces = FormatRule( help: """ Convert types used for hosting only static members into enums (an empty enum is @@ -1039,7 +1039,7 @@ public struct _FormatRules { // Consumers can choose whether or not this rule should apply to type bodies if !formatter.options.removeStartOrEndBlankLinesFromTypes, - ["class", "struct", "enum", "actor", "protocol", "extension"].contains( + ["class", "actor", "struct", "enum", "protocol", "extension"].contains( formatter.lastSignificantKeyword(at: i, excluding: ["where"])) { return @@ -1084,7 +1084,7 @@ public struct _FormatRules { // Consumers can choose whether or not this rule should apply to type bodies if !formatter.options.removeStartOrEndBlankLinesFromTypes, - ["class", "struct", "enum", "actor", "protocol", "extension"].contains( + ["class", "actor", "struct", "enum", "protocol", "extension"].contains( formatter.lastSignificantKeyword(at: startOfScopeIndex, excluding: ["where"])) { return @@ -2080,7 +2080,7 @@ public struct _FormatRules { } } - // Add @available(*, unavailable) to init?(coder aDecoder: NSCoder) + /// Add @available(*, unavailable) to init?(coder aDecoder: NSCoder) public let initCoderUnavailable = FormatRule( help: """ Add `@available(*, unavailable)` attribute to required `init(coder:)` when @@ -2122,7 +2122,7 @@ public struct _FormatRules { } } - // Implement brace-wrapping rules + /// Implement brace-wrapping rules public let braces = FormatRule( help: "Wrap braces in accordance with selected style (K&R or Allman).", options: ["allman"], @@ -3180,7 +3180,7 @@ public struct _FormatRules { return } - /// Removes return statements in the given single-statement scope + // Removes return statements in the given single-statement scope func removeReturn(atStartOfScope startOfScopeIndex: Int) { // If this scope is a single-statement if or switch statement then we have to recursively // remove the return from each branch of the if statement @@ -5617,7 +5617,7 @@ public struct _FormatRules { isGroupedWithExtendingType = declarationsBetweenTypeAndExtension.allSatisfy { // Only treat the type and its extension as grouped if there aren't any other // types or type-like declarations between them - if ["class", "actor", "enum", "protocol", "struct", "typealias"].contains($0.keyword) { + if ["class", "actor", "struct", "enum", "protocol", "typealias"].contains($0.keyword) { return false } // Extensions extending other types also break the grouping @@ -6808,8 +6808,8 @@ public struct _FormatRules { let conditionalBranches = formatter.conditionalBranches(at: startOfConditional) else { return } - /// Whether or not the conditional statement that starts at the given index - /// has branches that are exhaustive + // Whether or not the conditional statement that starts at the given index + // has branches that are exhaustive func conditionalBranchesAreExhaustive( conditionKeywordIndex: Int, branches: [Formatter.ConditionalBranch] diff --git a/Sources/SwiftFormat.swift b/Sources/SwiftFormat.swift index 0fb1d4e8..0f6ce150 100644 --- a/Sources/SwiftFormat.swift +++ b/Sources/SwiftFormat.swift @@ -32,7 +32,7 @@ import Foundation /// The current SwiftFormat version -let swiftFormatVersion = "0.52.3" +let swiftFormatVersion = "0.52.4" public let version = swiftFormatVersion /// The standard SwiftFormat config file name @@ -254,7 +254,7 @@ public func enumerateFiles(withInputURL inputURL: URL, return errors } -// Process configuration in all directories in specified path. +/// Process configuration in all directories in specified path. func gatherOptions(_ options: inout Options, for inputURL: URL, with logger: Logger?) throws { var directory = URL(fileURLWithPath: inputURL.pathComponents[0]).standardized for part in inputURL.pathComponents.dropFirst().dropLast() { @@ -266,7 +266,7 @@ func gatherOptions(_ options: inout Options, for inputURL: URL, with logger: Log } } -// Process configuration files in specified directory. +/// Process configuration files in specified directory. private var configCache = [URL: [String: String]]() private let configQueue = DispatchQueue(label: "swiftformat.config", qos: .userInteractive) private func processDirectory(_ inputURL: URL, with options: inout Options, logger: Logger?) throws { @@ -646,7 +646,7 @@ func getResourceValues(for url: URL, keys: [URLResourceKey]) throws -> URLResour // MARK: Documentation utilities -// Strip markdown code-formatting +/// Strip markdown code-formatting func stripMarkdown(_ input: String) -> String { var result = "" var startCount = 0 diff --git a/Sources/Tokenizer.swift b/Sources/Tokenizer.swift index 4635b700..e3421af1 100644 --- a/Sources/Tokenizer.swift +++ b/Sources/Tokenizer.swift @@ -2,7 +2,7 @@ // Tokenizer.swift // SwiftFormat // -// Version 0.52.3 +// Version 0.52.4 // // Created by Nick Lockwood on 11/08/2016. // Copyright 2016 Nick Lockwood @@ -35,12 +35,12 @@ import Foundation // https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/LexicalStructure.html -// Used to speed up matching +/// Used to speed up matching // Note: Any, Self, self, super, nil, true and false have been omitted deliberately, as they -// behave like identifiers. So too have context-specific keywords such as the following: -// any, associativity, async, convenience, didSet, dynamic, final, get, indirect, infix, lazy, -// left, mutating, none, nonmutating, open, optional, override, postfix, precedence, -// prefix, Protocol, required, right, set, some, any, Type, unowned, weak, willSet +/// behave like identifiers. So too have context-specific keywords such as the following: +/// any, associativity, async, convenience, didSet, dynamic, final, get, indirect, infix, lazy, +/// left, mutating, none, nonmutating, open, optional, override, postfix, precedence, +/// prefix, Protocol, required, right, set, some, any, Type, unowned, weak, willSet let swiftKeywords = Set([ "let", "return", "func", "var", "if", "public", "as", "else", "in", "import", "class", "try", "guard", "case", "for", "init", "extension", "private", "static", @@ -90,13 +90,13 @@ public enum TokenType { case number case error - // OR types + /// OR types case spaceOrComment case spaceOrLinebreak case spaceOrCommentOrLinebreak case identifierOrKeyword - // NOT types + /// NOT types case nonSpace case nonLinebreak case nonSpaceOrComment @@ -121,7 +121,7 @@ public enum OperatorType { case postfix } -// Original line number for token +/// Original line number for token public typealias OriginalLine = Int /// All token types diff --git a/SwiftFormat.podspec.json b/SwiftFormat.podspec.json index 51718a55..0b2cd4e0 100644 --- a/SwiftFormat.podspec.json +++ b/SwiftFormat.podspec.json @@ -1,6 +1,6 @@ { "name": "SwiftFormat", - "version": "0.52.3", + "version": "0.52.4", "license": { "type": "MIT", "file": "LICENSE.md" @@ -10,7 +10,7 @@ "authors": "Nick Lockwood", "source": { "git": "https://github.com/nicklockwood/SwiftFormat.git", - "tag": "0.52.3" + "tag": "0.52.4" }, "default_subspecs": "Core", "subspecs": [ diff --git a/SwiftFormat.xcodeproj/project.pbxproj b/SwiftFormat.xcodeproj/project.pbxproj index 2ba3262c..0ef96ee7 100644 --- a/SwiftFormat.xcodeproj/project.pbxproj +++ b/SwiftFormat.xcodeproj/project.pbxproj @@ -1111,7 +1111,7 @@ "@loader_path/Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.14; - MARKETING_VERSION = 0.52.3; + MARKETING_VERSION = 0.52.4; MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++"; MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu99 gnu++11"; PRODUCT_BUNDLE_IDENTIFIER = com.charcoaldesign.SwiftFormat; @@ -1144,7 +1144,7 @@ "@loader_path/Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.14; - MARKETING_VERSION = 0.52.3; + MARKETING_VERSION = 0.52.4; MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++"; MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu99 gnu++11"; PRODUCT_BUNDLE_IDENTIFIER = com.charcoaldesign.SwiftFormat; @@ -1251,7 +1251,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.14; - MARKETING_VERSION = 0.52.3; + MARKETING_VERSION = 0.52.4; PRODUCT_BUNDLE_IDENTIFIER = "com.charcoaldesign.SwiftFormat-for-Xcode"; PRODUCT_NAME = "SwiftFormat for Xcode"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -1282,7 +1282,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.14; - MARKETING_VERSION = 0.52.3; + MARKETING_VERSION = 0.52.4; PRODUCT_BUNDLE_IDENTIFIER = "com.charcoaldesign.SwiftFormat-for-Xcode"; PRODUCT_NAME = "SwiftFormat for Xcode"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -1310,7 +1310,7 @@ "@executable_path/../../../../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.14; - MARKETING_VERSION = 0.52.3; + MARKETING_VERSION = 0.52.4; PRODUCT_BUNDLE_IDENTIFIER = "com.charcoaldesign.SwiftFormat-for-Xcode.SourceEditorExtension"; PRODUCT_NAME = SwiftFormat; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -1340,7 +1340,7 @@ "@executable_path/../../../../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.14; - MARKETING_VERSION = 0.52.3; + MARKETING_VERSION = 0.52.4; PRODUCT_BUNDLE_IDENTIFIER = "com.charcoaldesign.SwiftFormat-for-Xcode.SourceEditorExtension"; PRODUCT_NAME = SwiftFormat; PROVISIONING_PROFILE_SPECIFIER = "";