Skip to content

Commit

Permalink
support searching from the current directory
Browse files Browse the repository at this point in the history
Thinking it might be sufficient to ignore hidden files, as we want to stay out of .build directories
  • Loading branch information
nicorichard committed Jun 23, 2024
1 parent 436188d commit 2a99281
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions Sources/XCStringsLint/XCStringsLint+Lint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ extension XCStringsLint {
commandName: "lint"
)

// TODO: Add support for automatic discovery of .xcstrings files if no path is provided
@Argument(help: "Path(s) to .xcstrings String Catalogs")
private var paths: [String]
private var paths: [String] = []

@Option(name: .customLong("config"))
private var configPath: String?
Expand All @@ -20,6 +19,10 @@ extension XCStringsLint {
private var reporter: ReporterFactory = .xcode

mutating func run() throws {
if paths.isEmpty {
paths = try findXCStringsFiles(atPath: FileManager.default.currentDirectoryPath)
}

for path in paths {
try run(path: path)
}
Expand All @@ -42,6 +45,26 @@ extension XCStringsLint {
// MARK: - Config Resolving

extension XCStringsLint.Lint {

private func findXCStringsFiles(atPath path: String) throws -> [String] {
let enumerator = FileManager.default
.enumerator(
at: URL(fileURLWithPath: path),
includingPropertiesForKeys: [],
options: [.skipsHiddenFiles]
)

var files: [String] = []
while let file = enumerator?.nextObject() as? URL {
let relativePath = file.relativePath
if relativePath.hasSuffix(".xcstrings") {
files.append(relativePath)
}
}

return files
}

private func findConfig(atPath path: String) throws -> String? {
try FileManager.default
.contentsOfDirectory(atPath: path)
Expand Down

0 comments on commit 2a99281

Please sign in to comment.