         ]
     )
 
+    // swiftlint:disable:next function_body_length
     public func validate(file: File) -> [StyleViolation] {
-        guard let mainTypeSubstructure = mainTypeSubstructure(in: file) else { return [] }
+        guard let mainTypeSubstructure = mainTypeSubstructure(in: file),
+            let mainTypeSubstuctureOffset = mainTypeSubstructure.offset else { return [] }
 
         let extensionsSubstructures = self.extensionsSubstructures(
             in: file,

        mainTypeSubstructure: [String: SourceKitRepresentable]
    ) -> [[String: SourceKitRepresentable]] {
        return file.structure.dictionary.substructure.filter { substructure in
            return substructure.bridge() != mainTypeSubstructure.bridge() &&
                substructure.kind!.contains(SwiftDeclarationKind.extension.rawValue)
        }
    }


    private func mainTypeSubstructure(in dict: [String: SourceKitRepresentable]) -> [String: SourceKitRepresentable]? {
        let priorityKinds: [SwiftDeclarationKind] = [.class, .enum, .struct]
        let priorityKindRawValues = priorityKinds.map { $0.rawValue }

        let priorityKindSubstructures = dict.substructure.filter { substructure in
            guard let kind = substructure.kind else { return false }
            return priorityKindRawValues.contains(kind)
        }

        let substructuresSortedByBodyLength = priorityKindSubstructures.sorted { lhs, rhs in
            return (lhs.bodyLength ?? 0) > (rhs.bodyLength ?? 0)
        }

        guard let mainTypeSubstructure = substructuresSortedByBodyLength.first else {
            let substructuresSortedByBodyLength = dict.substructure.sorted { lhs, rhs in
                return (lhs.bodyLength ?? 0) > (rhs.bodyLength ?? 0)
            }

            // specify substructure with longest body as main type if existent
