Fix bug where acronyms rule would incorrectly always capitalize potentially matching acronyms one letter before end of identifier (#2226)

This commit is contained in:
Cal Stephens
2025-09-23 20:19:36 -07:00
parent d3cfc9df66
commit 3aeb711d77
2 changed files with 17 additions and 1 deletions
+1 -1
View File
@@ -27,7 +27,7 @@ public extension FormatRule {
for replaceCandidateRange in token.string.ranges(of: find) {
let acronymShouldBeCapitalized: Bool
if replaceCandidateRange.upperBound < token.string.indices.last! {
if replaceCandidateRange.upperBound <= token.string.indices.last! {
let indexAfterMatch = replaceCandidateRange.upperBound
let characterAfterMatch = token.string[indexAfterMatch]
+16
View File
@@ -90,4 +90,20 @@ class AcronymsTests: XCTestCase {
let options = FormatOptions(preserveAcronyms: ["externallyProvidedUrl", "toUrl"])
testFormatting(for: input, output, rule: .acronyms, options: options)
}
func testAcronymMatchesPartOfOtherWordAtEndOfIdentifier() {
let input = """
struct MasKit {}
struct Mask {}
struct MaskView {}
"""
let output = """
struct MASKit {}
struct Mask {}
struct MaskView {}
"""
testFormatting(for: input, output, rule: .acronyms, options: FormatOptions(acronyms: ["MAS"]))
}
}