     }
 
     public func correct(file: File) -> [Correction] {
-        let violatingIndexes = file.structure.dictionary.substructure.flatMap { sub -> Int? in
+        let violatingIndexes = file.structure.dictionary.substructure.flatMap { sub -> CommaRuleViolation? in
             guard let kind = SwiftExpressionKind(rawValue: sub.kind ?? "") else { return nil }
-            return violationIndexAndReason(in: file, kind: kind, dictionary: sub)?.0
+            return violationIndexAndReason(in: file, kind: kind, dictionary: sub)
         }
 
-        let adjustedIndexes = violatingIndexes.reduce([Int]()) { adjustedIndexes, element in
-            return adjustedIndexes + [element - adjustedIndexes.count]
+        let adjustedIndexes = violatingIndexes.reduce([CommaRuleViolation]()) { adjustedIndexes, element in
+            let correction: Int
+            switch element.reason {
+            case .missingTrailingCommaReason:
+                correction = adjustedIndexes.count
+            case .extraTrailingCommaReason:
+                correction = -adjustedIndexes.count
+            }
+
+            return adjustedIndexes + [(element.index + correction, element.reason)]
         }
 
         var correctedContents = file.contents
 
         adjustedIndexes.forEach {
-            let stringIndex = correctedContents.index(correctedContents.startIndex, offsetBy: $0)
-            correctedContents.remove(at: stringIndex)
+            let stringIndex = correctedContents.index(correctedContents.startIndex, offsetBy: $0.index)
+            switch $0.reason {
+            case .missingTrailingCommaReason:
+                correctedContents.insert(",", at: stringIndex)
+            case .extraTrailingCommaReason:
+                correctedContents.remove(at: stringIndex)
+            }
         }
 
         file.write(correctedContents)
 
         return adjustedIndexes.map {
             Correction(ruleDescription: type(of: self).description,
-                       location: Location(file: file, characterOffset: $0))
+                       location: Location(file: file, characterOffset: $0.index))
         }
     }
 }

                return nil
            }

            return (lastPosition, missingTrailingCommaReason)
        }

        // trailing comma is present, which is a violation if mandatoryComma is false

        }

        let violationOffset = lastPosition + commaIndex
        return (violationOffset, .extraTrailingCommaReason)
    }

    private func violations(file: File, byteOffset: Int, reason: String) -> [StyleViolation] {
