1
0
Fork 0

Remove underscore prefix from generated filenames

This commit is contained in:
Brendan Szymanski 2026-07-17 23:26:34 -04:00
parent 321b42f9af
commit 4dd74b0f65
2 changed files with 8 additions and 10 deletions

View file

@ -64,7 +64,7 @@ public func renderModule(_ plan: ModulePlan) -> [String: String] {
}
// Always emit the per-module pointer-cast helpers.
files["_Support.swift"] = renderSupport(moduleName: plan.module)
files["Support.swift"] = renderSupport(moduleName: plan.module)
for filename in files.keys {
precondition(isValidGeneratedFileName(filename),
@ -73,19 +73,17 @@ public func renderModule(_ plan: ModulePlan) -> [String: String] {
return files
}
/// Whether a generated filename follows the project convention: a PascalCase
/// base name (`Align.swift`, `IOChannel.swift`) with an optional `_` prefix
/// reserved for infrastructure files (`_Support.swift`). Underscores inside
/// the name and uppercase runs longer than three letters (the signature of
/// unconverted C spellings like `BOOLEANBOXED`) are rejected.
/// Tests whether a generated filename follows the PascalCase convention starts
/// with an uppercase ASCII letter, contains only ASCII letters/digits, and has
/// no run of more than 3 consecutive uppercase letters (catches unconverted C
/// spellings like `cclosureMarshalBOOLEANFLAGS.swift` while allowing legitimate
/// 23-letter acronym runs like `IOChannel.swift`, `FileIOStream.swift`).
///
/// - Parameter filename: A relative filename ending in `.swift`.
/// - Returns: `true` when the name is conventional.
public func isValidGeneratedFileName(_ filename: String) -> Bool {
guard filename.hasSuffix(".swift") else { return false }
var base = Substring(filename.dropLast(".swift".count))
if base.hasPrefix("_") { base = base.dropFirst() }
let base = filename.dropLast(".swift".count)
guard let first = base.first, first.isUppercase else { return false }
guard base.allSatisfy({ ($0.isLetter && $0.isASCII) || $0.isNumber }) else { return false }
var run = 0

View file

@ -41,7 +41,7 @@ struct NamingTests {
#expect(isValidGeneratedFileName("Align.swift"))
#expect(isValidGeneratedFileName("IOChannel.swift")) // 3-cap acronym run
#expect(isValidGeneratedFileName("FileIOStream.swift"))
#expect(isValidGeneratedFileName("_Support.swift")) // infra prefix
#expect(!isValidGeneratedFileName("_Support.swift")) // underscore prefix
#expect(isValidGeneratedFileName("ParamSpecInt64.swift")) // digits
#expect(!isValidGeneratedFileName("boxedFree.swift")) // lowerCamelCase