Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/SwiftLintCore/Extensions/String+SwiftLint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public extension String {
///
/// - returns: A new `String`.
func absolutePathStandardized() -> String {
bridge().absolutePathRepresentation().bridge().standardizingPath
URL(fileURLWithPath: bridge().standardizingPath.absolutePathRepresentation()).filepath
}

var isFile: Bool {
Expand Down
7 changes: 7 additions & 0 deletions Source/SwiftLintCore/Extensions/URL+SwiftLint.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Foundation

public extension URL {
var filepath: String {
self.withUnsafeFileSystemRepresentation { String(cString: $0!) }
}
}
21 changes: 11 additions & 10 deletions Source/SwiftLintFramework/Extensions/FileManager+SwiftLint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,20 @@ public protocol LintableFileManager {

extension FileManager: LintableFileManager {
public func filesToLint(inPath path: String, rootDirectory: String? = nil) -> [String] {
let absolutePath = path.bridge()
.absolutePathRepresentation(rootDirectory: rootDirectory ?? currentDirectoryPath).bridge()
.standardizingPath

let root =
URL(fileURLWithPath: path.absolutePathRepresentation(rootDirectory: rootDirectory ?? currentDirectoryPath))
// if path is a file, it won't be returned in `enumerator(atPath:)`
if absolutePath.bridge().isSwiftFile(), absolutePath.isFile {
return [absolutePath]
if FileManager.default.isFile(atPath: root.path), root.pathExtension == "swift" {
return [root.standardized.filepath]
}

return subpaths(atPath: absolutePath)?.parallelCompactMap { element -> String? in
guard element.bridge().isSwiftFile() else { return nil }
let absoluteElementPath = absolutePath.bridge().appendingPathComponent(element)
return absoluteElementPath.isFile ? absoluteElementPath : nil
return subpaths(atPath: root.path)?.parallelCompactMap { element -> String? in
let elementURL = URL(fileURLWithPath: element, relativeTo: root)
guard elementURL.pathExtension == "swift" else { return nil }
if FileManager.default.isFile(atPath: elementURL.path) {
return elementURL.standardized.filepath
}
return nil
} ?? []
}

Expand Down
16 changes: 8 additions & 8 deletions Source/swiftlint-dev/Rules+Template.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,40 +49,40 @@ extension SwiftLintDev.Rules {
.appendingPathComponent("SwiftLintBuiltInRules", isDirectory: true)
.appendingPathComponent("Rules", isDirectory: true)
let ruleLocation = ruleDirectory.appendingPathComponent(kind.rawValue.capitalized, isDirectory: true)
guard FileManager.default.fileExists(atPath: ruleLocation.path) else {
guard FileManager.default.fileExists(atPath: ruleLocation.filepath) else {
throw ValidationError("Command must be run from the root of the SwiftLint repository.")
}
print("Creating template(s) for new rule \"\(ruleName)\" identified by '\(ruleId)' ...")
let rulePath = ruleLocation.appendingPathComponent("\(name)Rule.swift", isDirectory: false)
guard overwrite || !FileManager.default.fileExists(atPath: rulePath.path) else {
guard overwrite || !FileManager.default.fileExists(atPath: rulePath.filepath) else {
throw ValidationError("Rule file already exists at \(rulePath.relativeToCurrentDirectory).")
}
try ruleTemplate.write(toFile: rulePath.path, atomically: true, encoding: .utf8)
try ruleTemplate.write(toFile: rulePath.filepath, atomically: true, encoding: .utf8)
print("Rule file created at \(rulePath.relativeToCurrentDirectory).")
if config {
let configPath = ruleDirectory
.appendingPathComponent("RuleConfigurations", isDirectory: true)
.appendingPathComponent("\(name)Configuration.swift", isDirectory: false)
guard overwrite || !FileManager.default.fileExists(atPath: configPath.path) else {
guard overwrite || !FileManager.default.fileExists(atPath: configPath.filepath) else {
throw ValidationError(
"Configuration file already exists at \(configPath.relativeToCurrentDirectory)."
)
}
try configTemplate.write(toFile: configPath.path, atomically: true, encoding: .utf8)
try configTemplate.write(toFile: configPath.filepath, atomically: true, encoding: .utf8)
print("Configuration file created at \(configPath.relativeToCurrentDirectory).")
}
if test {
let testDirectory = rootDirectory
.appendingPathComponent("Tests", isDirectory: true)
.appendingPathComponent("BuiltInRulesTests", isDirectory: true)
let testPath = testDirectory.appendingPathComponent("\(name)RuleTests.swift", isDirectory: false)
guard FileManager.default.fileExists(atPath: testDirectory.path) else {
guard FileManager.default.fileExists(atPath: testDirectory.filepath) else {
throw ValidationError("Command must be run from the root of the SwiftLint repository.")
}
guard overwrite || !FileManager.default.fileExists(atPath: testPath.path) else {
guard overwrite || !FileManager.default.fileExists(atPath: testPath.filepath) else {
throw ValidationError("Test file already exists at \(testPath.relativeToCurrentDirectory).")
}
try testTemplate.write(toFile: testPath.path, atomically: true, encoding: .utf8)
try testTemplate.write(toFile: testPath.filepath, atomically: true, encoding: .utf8)
print("Test file created at \(testPath.relativeToCurrentDirectory).")
}
if !skipRegistration {
Expand Down
2 changes: 1 addition & 1 deletion Tests/FileSystemAccessTests/BaselineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ private var temporaryDirectoryPath: String {
let result = URL(
fileURLWithPath: NSTemporaryDirectory(),
isDirectory: true
).path
).filepath

#if os(macOS)
return "/private" + result
Expand Down
2 changes: 1 addition & 1 deletion Tests/TestHelpers/TestHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private extension SwiftLintFile {

public extension String {
func stringByAppendingPathComponent(_ pathComponent: String) -> String {
bridge().appendingPathComponent(pathComponent)
URL(fileURLWithPath: self).appendingPathComponent(pathComponent).filepath
}
}

Expand Down