mirror of
https://github.com/apakabarfm/syllabreak-swift.git
synced 2026-02-18 06:23:16 +00:00
Fix linter issues with strict SwiftLint config
- Replace 4-element tuples with struct LoadedTestCase to fix large_tuple violation - Break long function signatures across multiple lines to fix line_length violations - Now using only identifier_name in disabled_rules, matching main project standards All tests passing, zero linter warnings. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,4 @@
|
||||
disabled_rules:
|
||||
- trailing_comma
|
||||
- line_length
|
||||
- large_tuple
|
||||
- identifier_name
|
||||
|
||||
included:
|
||||
|
||||
@@ -18,15 +18,15 @@ public final class Syllabreak: Sendable {
|
||||
guard let url = Bundle.module.url(forResource: "rules", withExtension: "json") else {
|
||||
fatalError("Syllabreak: rules.json not found in bundle. This is a build/distribution error.")
|
||||
}
|
||||
|
||||
|
||||
guard let data = try? Data(contentsOf: url) else {
|
||||
fatalError("Syllabreak: Failed to read rules.json from bundle.")
|
||||
}
|
||||
|
||||
|
||||
guard let rulesData = try? JSONDecoder().decode(RulesData.self, from: data) else {
|
||||
fatalError("Syllabreak: Failed to decode rules.json. The file format is invalid.")
|
||||
}
|
||||
|
||||
|
||||
return MetaRule(rules: rulesData.rules)
|
||||
}
|
||||
|
||||
|
||||
@@ -128,7 +128,11 @@ class WordSyllabifier {
|
||||
return clusterIndices[0]
|
||||
}
|
||||
|
||||
private func findBoundaryForTwoConsonants(_ cluster: [Token], _ clusterIndices: [Int], prevNucleusIdx: Int? = nil) -> Int {
|
||||
private func findBoundaryForTwoConsonants(
|
||||
_ cluster: [Token],
|
||||
_ clusterIndices: [Int],
|
||||
prevNucleusIdx: Int? = nil
|
||||
) -> Int {
|
||||
// Determine boundary for two-consonant cluster
|
||||
if isValidOnset(cluster[0].surface, cluster[1].surface, prevNucleusIdx: prevNucleusIdx) {
|
||||
return clusterIndices[0]
|
||||
@@ -137,11 +141,19 @@ class WordSyllabifier {
|
||||
}
|
||||
}
|
||||
|
||||
private func findBoundaryForLongCluster(_ cluster: [Token], _ clusterIndices: [Int], prevNucleusIdx: Int? = nil) -> Int {
|
||||
private func findBoundaryForLongCluster(
|
||||
_ cluster: [Token],
|
||||
_ clusterIndices: [Int],
|
||||
prevNucleusIdx: Int? = nil
|
||||
) -> Int {
|
||||
// Determine boundary for cluster with 3+ consonants
|
||||
var boundaryIdx = clusterIndices[clusterIndices.count - 1]
|
||||
|
||||
if cluster.count >= 2 && isValidOnset(cluster[cluster.count - 2].surface, cluster[cluster.count - 1].surface, prevNucleusIdx: prevNucleusIdx) {
|
||||
if cluster.count >= 2 && isValidOnset(
|
||||
cluster[cluster.count - 2].surface,
|
||||
cluster[cluster.count - 1].surface,
|
||||
prevNucleusIdx: prevNucleusIdx
|
||||
) {
|
||||
boundaryIdx = clusterIndices[clusterIndices.count - 2]
|
||||
}
|
||||
|
||||
|
||||
@@ -40,8 +40,10 @@ final class DetectLanguageTests: XCTestCase {
|
||||
if !expected.isEmpty {
|
||||
XCTAssertFalse(result.isEmpty, "Failed for '\(text)': got empty result, expected \(expected)")
|
||||
if !result.isEmpty {
|
||||
XCTAssertEqual(result[0], expected[0],
|
||||
"Failed for '\(text)': got \(result[0]) as first (from \(result)), expected \(expected[0])")
|
||||
XCTAssertEqual(
|
||||
result[0], expected[0],
|
||||
"Failed for '\(text)': got \(result[0]) as first (from \(result)), expected \(expected[0])"
|
||||
)
|
||||
}
|
||||
} else {
|
||||
XCTAssertEqual(result, [], "Failed for '\(text)': got \(result), expected empty list")
|
||||
|
||||
@@ -18,7 +18,14 @@ final class SyllabifyTests: XCTestCase {
|
||||
let tests: [TestSection]
|
||||
}
|
||||
|
||||
func loadTestCases() -> [(section: String, lang: String?, text: String, want: String)] {
|
||||
struct LoadedTestCase {
|
||||
let section: String
|
||||
let lang: String?
|
||||
let text: String
|
||||
let want: String
|
||||
}
|
||||
|
||||
func loadTestCases() -> [LoadedTestCase] {
|
||||
guard let url = Bundle.module.url(forResource: "syllabify_tests", withExtension: "json"),
|
||||
let data = try? Data(contentsOf: url),
|
||||
let testData = try? JSONDecoder().decode(TestData.self, from: data) else {
|
||||
@@ -26,10 +33,15 @@ final class SyllabifyTests: XCTestCase {
|
||||
return []
|
||||
}
|
||||
|
||||
var testCases: [(String, String?, String, String)] = []
|
||||
var testCases: [LoadedTestCase] = []
|
||||
for section in testData.tests {
|
||||
for testCase in section.cases {
|
||||
testCases.append((section.section, section.lang, testCase.text, testCase.want))
|
||||
testCases.append(LoadedTestCase(
|
||||
section: section.section,
|
||||
lang: section.lang,
|
||||
text: testCase.text,
|
||||
want: testCase.want
|
||||
))
|
||||
}
|
||||
}
|
||||
return testCases
|
||||
@@ -39,13 +51,16 @@ final class SyllabifyTests: XCTestCase {
|
||||
let syllabifier = Syllabreak(softHyphen: "-")
|
||||
let testCases = loadTestCases()
|
||||
|
||||
for (section, lang, text, want) in testCases {
|
||||
for testCase in testCases {
|
||||
let result: String
|
||||
if let lang = lang {
|
||||
result = syllabifier.syllabify(text, lang: lang)
|
||||
if let lang = testCase.lang {
|
||||
result = syllabifier.syllabify(testCase.text, lang: lang)
|
||||
} else {
|
||||
result = syllabifier.syllabify(text)
|
||||
result = syllabifier.syllabify(testCase.text)
|
||||
}
|
||||
let section = testCase.section
|
||||
let text = testCase.text
|
||||
let want = testCase.want
|
||||
XCTAssertEqual(result, want, "[\(section)] Failed for '\(text)': got '\(result)', want '\(want)'")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user