 private let missingTrailingCommaReason = "Multi-line collection literals should have trailing commas."
 private let extraTrailingCommaReason = "Collection literals should not have trailing commas."
 
-public struct TrailingCommaRule: ASTRule, ConfigurationProviderRule {
+public struct TrailingCommaRule: ASTRule, CorrectableRule, ConfigurationProviderRule {
     public var configuration = TrailingCommaConfiguration()
 
     public init() {}

        guard let commaIndex = trailingCommaIndex(contents: contentsAfterLastElement, file: file,
                                                  offset: lastPosition) else {
            guard configuration.mandatoryComma else {
                return []
            }

            return violations(file: file, byteOffset: lastPosition, reason: missingTrailingCommaReason)
        }

        // trailing comma is present, which is a violation if mandatoryComma is false
        guard !configuration.mandatoryComma else {
            return []
        }

        let violationOffset = lastPosition + commaIndex
        return violations(file: file, byteOffset: violationOffset, reason: extraTrailingCommaReason)
    }

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

            contents.bridge().NSRangeToByteRange(start: $0.location, length: $0.length)
        }?.location
    }

    public func correct(file: File) -> [Correction] {
        let violatingIndexes = file.structure.dictionary.substructure.flatMap { sub -> Int? in
            guard let kind = SwiftExpressionKind(rawValue: sub.kind ?? "") else { return nil }
            return violationIndexAndReason(in: file, kind: kind, dictionary: sub)?.0
        }

        let adjustedIndexes = violatingIndexes.reduce([Int]()) { adjustedIndexes, element in
            return adjustedIndexes + [element - adjustedIndexes.count]
        }

        var correctedContents = file.contents

        adjustedIndexes.forEach {
            let stringIndex = correctedContents.index(correctedContents.startIndex, offsetBy: $0)
            correctedContents.remove(at: stringIndex)
        }

        file.write(correctedContents)

        return adjustedIndexes.map {
            Correction(ruleDescription: type(of: self).description,
                       location: Location(file: file, characterOffset: $0))
        }
    }
}
