Skip to content

Commit cf27a3c

Browse files
committed
Move suppression logic up to FileIterator
1 parent 17dc1bd commit cf27a3c

File tree

5 files changed

+11
-43
lines changed

5 files changed

+11
-43
lines changed

Documentation/Configuration.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ top-level keys and values:
1111
* `version` _(number)_: The version of the configuration file. For now, this
1212
should always be `1`.
1313

14-
* `skipAll` _(boolean)_: If this is true, all other configuration
15-
options are ignored, and formatting/linting is disabled.
16-
1714
* `lineLength` _(number)_: The maximum allowed length of a line, in
1815
characters.
1916

Sources/SwiftFormat/API/Configuration.swift

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,9 @@ internal let highestSupportedConfigurationVersion = 1
2424
/// Holds the complete set of configured values and defaults.
2525
public struct Configuration: Codable, Equatable {
2626

27-
/// Name of the configuration file to look for.
28-
/// The presence of this file in a directory will cause the formatter
29-
/// to use the configuration specified in that file.
30-
private static let configurationFileName = ".swift-format"
31-
32-
/// Name of the suppression file to look for.
33-
/// The presence of this file in a directory will cause the formatter
34-
/// to skip formatting files in that directory and its subdirectories.
35-
private static let suppressionFileName = ".swift-format-ignore"
3627

3728
private enum CodingKeys: CodingKey {
3829
case version
39-
case skipAll
4030
case maximumBlankLines
4131
case lineLength
4232
case spacesBeforeEndOfLineComments
@@ -71,9 +61,6 @@ public struct Configuration: Codable, Equatable {
7161

7262
/// MARK: Common configuration
7363

74-
/// Is all formatting disbled?
75-
public var skipAll = false
76-
7764
/// The dictionary containing the rule names that we wish to run on. A rule is not used if it is
7865
/// marked as `false`, or if it is missing from the dictionary.
7966
public var rules: [String: Bool]
@@ -284,13 +271,6 @@ public struct Configuration: Codable, Equatable {
284271

285272
/// Creates a new `Configuration` by loading it from a configuration file.
286273
public init(contentsOf url: URL) throws {
287-
if url.lastPathComponent == Self.suppressionFileName {
288-
var config = Configuration()
289-
config.skipAll = true
290-
self = config
291-
return
292-
}
293-
294274
let data = try Data(contentsOf: url)
295275
try self.init(data: data)
296276
}
@@ -324,9 +304,6 @@ public struct Configuration: Codable, Equatable {
324304
// default-initialized instance.
325305
let defaults = Configuration()
326306

327-
self.skipAll =
328-
try container.decodeIfPresent(Bool.self, forKey: .skipAll)
329-
?? false
330307
self.maximumBlankLines =
331308
try container.decodeIfPresent(Int.self, forKey: .maximumBlankLines)
332309
?? defaults.maximumBlankLines
@@ -420,7 +397,6 @@ public struct Configuration: Codable, Equatable {
420397
var container = encoder.container(keyedBy: CodingKeys.self)
421398

422399
try container.encode(version, forKey: .version)
423-
try container.encode(skipAll, forKey: .skipAll)
424400
try container.encode(maximumBlankLines, forKey: .maximumBlankLines)
425401
try container.encode(lineLength, forKey: .lineLength)
426402
try container.encode(spacesBeforeEndOfLineComments, forKey: .spacesBeforeEndOfLineComments)
@@ -465,11 +441,7 @@ public struct Configuration: Codable, Equatable {
465441
}
466442
repeat {
467443
candidateDirectory.deleteLastPathComponent()
468-
let suppressingFile = candidateDirectory.appendingPathComponent(Self.suppressionFileName)
469-
if FileManager.default.isReadableFile(atPath: suppressingFile.path) {
470-
return suppressingFile
471-
}
472-
let candidateFile = candidateDirectory.appendingPathComponent(Self.configurationFileName)
444+
let candidateFile = candidateDirectory.appendingPathComponent(".swift-format")
473445
if FileManager.default.isReadableFile(atPath: candidateFile.path) {
474446
return candidateFile
475447
}

Sources/SwiftFormat/API/SwiftFormatter.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,6 @@ public final class SwiftFormatter {
111111
// also does not touch an empty file even if the setting to add trailing newlines is enabled.)
112112
guard !source.isEmpty else { return }
113113

114-
// If skipAll is set, just emit the source as-is.
115-
guard !configuration.skipAll else {
116-
outputStream.write(source)
117-
return
118-
}
119-
120114
let sourceFile = try parseAndEmitDiagnostics(
121115
source: source,
122116
operatorTable: .standardOperators,

Sources/SwiftFormat/API/SwiftLinter.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,6 @@ public final class SwiftLinter {
9898
// newline from being diagnosed for an empty file. (This is consistent with clang-format, which
9999
// also does not touch an empty file even if the setting to add trailing newlines is enabled.)
100100
guard !source.isEmpty else { return }
101-
102-
// If skipAll is set, do nothing.
103-
guard !configuration.skipAll else {
104-
return
105-
}
106101

107102
let sourceFile = try parseAndEmitDiagnostics(
108103
source: source,

Sources/SwiftFormat/Utilities/FileIterator.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ import WinSDK
2121
@_spi(Internal)
2222
public struct FileIterator: Sequence, IteratorProtocol {
2323

24+
/// Name of the suppression file to look for.
25+
/// The presence of this file in a directory will cause the formatter
26+
/// to skip formatting files in that directory and its subdirectories.
27+
private static let suppressionFileName = ".swift-format-ignore"
28+
2429
/// List of file and directory URLs to iterate over.
2530
private let urls: [URL]
2631

@@ -92,6 +97,11 @@ public struct FileIterator: Sequence, IteratorProtocol {
9297
fallthrough
9398

9499
case .typeDirectory:
100+
let suppressionFile = next.appendingPathComponent(Self.suppressionFileName)
101+
if FileManager.default.fileExists(atPath: suppressionFile.path) {
102+
continue
103+
}
104+
95105
dirIterator = FileManager.default.enumerator(
96106
at: next,
97107
includingPropertiesForKeys: nil,

0 commit comments

Comments
 (0)