Repository: Moya/Moya
File: Dangerfile.swift (Swift)

Code before:

// Don't let testing shortcuts get into master by accident
if danger.utils.exec("grep -r \"fit Demo/Tests/\"").count > 1 {
    fail("fit left in tests")
}

// Added (or removed) library files need to be added (or removed) from the
// Carthage Xcode project to avoid breaking things for our Carthage users.
let addedSwiftLibraryFiles = danger.git.createdFiles.first { $0.fileType == .swift && $0.hasPrefix("Sources") } != nil
let deletedSwiftLibraryFiles = danger.git.deletedFiles.first { $0.fileType == .swift && $0.hasPrefix("Sources") } != nil
let modifiedCarthageXcodeProject = danger.git.modifiedFiles.first { $0.contains("Moya.xcodeproj") } != nil
if (addedSwiftLibraryFiles || deletedSwiftLibraryFiles) && !modifiedCarthageXcodeProject {
    fail("Added or removed library files require the Carthage Xcode project to be updated. See the Readme")
}

let missingDocChanges = danger.git.modifiedFiles.first { $0.contains("docs") } != nil
let docChangeRaccomanded = (danger.github.pullRequest.additions ?? 0) > 15
if sourceChanges && missingDocChanges && docChangeRaccomanded && !isTrivial {
    warn("Consider adding supporting documentation to this change. Documentation can be found in the `docs` directory.")
}

// Run danger-prose to lint Chinese docs
func isCnDocsMarkdown(_ file: String) -> Bool {
    return file.fileType == .markdown && file.contains("docs_CN")
}
let addedAndModifiedCnDocsMarkdown = danger.git.createdFiles.filter(isCnDocsMarkdown) + danger.git.modifiedFiles.filter(isCnDocsMarkdown)
if #available(OSX 10.12, *),
    !addedAndModifiedCnDocsMarkdown.isEmpty {
    Proselint.performSpellCheck(files: addedAndModifiedCnDocsMarkdown, excludedRules: ["misc.scare_quotes", "typography.symbols"])
}

// Run danger-prose to lint and check spelling English docs
func isEnDocsMarkdown(_ file: String) -> Bool {
    return file.fileType == .markdown && file.contains("docs/")
}
let addedAndModifiedEnDocsMarkdown = danger.git.createdFiles.filter(isEnDocsMarkdown) + danger.git.modifiedFiles.filter(isEnDocsMarkdown)
if #available(OSX 10.12, *),
    !addedAndModifiedEnDocsMarkdown.isEmpty {
    Proselint.performSpellCheck(files: addedAndModifiedEnDocsMarkdown)

    let ignoredWords = ["Auth", "auth", "Moya", "enum", "enums", "OAuth", "Artsy's", "Heimdallr.swift", "SwiftyJSONMapper", "ObjectMapper", "Argo", "ModelMapper", "ReactiveSwift", "RxSwift", "multipart", "JSONEncoder", "Alamofire", "CocoaPods", "URLSession", "plugin", "plugins", "stubClosure", "requestClosure", "endpointClosure", "Unsplash", "ReactorKit", "Dribbble", "EVReflection", "Unbox"]
    Mdspell.performSpellCheck(files: addedAndModifiedEnDocsMarkdown, ignoredWords: ignoredWords, language: "en-us")
}

// Warning message for not updated package manifest(s)
let manifests = [
    "Moya.podspec",
    "Cartfile",
    "Cartfile.resolved",
    "Package.swift",
    "Package.resolved"

Review comment (suggestion):
```suggestion
let addedOrModifiedCnDocsMarkdown = allSourceFiles.filter { $0.fileType == .markdown && $0.contains("docs_CN/") }
```

Code after:

// Don't let testing shortcuts get into master by accident
if danger.utils.exec("grep -r \"fit Demo/Tests/\"").count > 1 {
    fail("fit left in tests")
}

// Added (or removed) library files need to be added (or removed) from the
// Xcode project to avoid breaking things for our Carthage/manual framework.
let addedSwiftLibraryFiles = danger.git.createdFiles.contains { $0.fileType == .swift && $0.hasPrefix("Sources") }
let deletedSwiftLibraryFiles = danger.git.deletedFiles.contains { $0.fileType == .swift && $0.hasPrefix("Sources") }
let modifiedCarthageXcodeProject = danger.git.modifiedFiles.contains { $0.contains("Moya.xcodeproj") }
if (addedSwiftLibraryFiles || deletedSwiftLibraryFiles) && !modifiedCarthageXcodeProject {
    fail("Added or removed library files require the Carthage Xcode project to be updated. See the Readme")
}

let missingDocChanges = danger.git.modifiedFiles.contains { $0.contains("docs") }
let docChangeRecommended = (danger.github.pullRequest.additions ?? 0) > 15
if sourceChanges && missingDocChanges && docChangeRecommended && isNotTrivial {
    warn("Consider adding supporting documentation to this change. Documentation can be found in the `docs` directory.")
}

// Run danger-prose to lint Chinese docs
let addedAndModifiedCnDocsMarkdown = allSourceFiles.filter { $0.fileType == .markdown && $0.contains("docs_CN") }
if #available(OSX 10.12, *),
    !addedAndModifiedCnDocsMarkdown.isEmpty {
    Proselint.performSpellCheck(files: addedAndModifiedCnDocsMarkdown, excludedRules: ["misc.scare_quotes", "typography.symbols"])
}

// Run danger-prose to lint and check spelling English docs
let addedAndModifiedEnDocsMarkdown = allSourceFiles.filter { $0.fileType == .markdown && $0.contains("docs/") }
if #available(OSX 10.12, *),
    !addedAndModifiedEnDocsMarkdown.isEmpty {
    Proselint.performSpellCheck(files: addedAndModifiedEnDocsMarkdown)

    let ignoredWords = ["Auth", "auth", "Moya", "enum", "enums", "OAuth", "Artsy's", "Heimdallr.swift", "SwiftyJSONMapper", "ObjectMapper", "Argo", "ModelMapper", "ReactiveSwift", "RxSwift", "multipart", "JSONEncoder", "Alamofire", "CocoaPods", "URLSession", "plugin", "plugins", "stubClosure", "requestClosure", "endpointClosure", "Unsplash", "ReactorKit", "Dribbble", "EVReflection", "Unbox"]
    Mdspell.performSpellCheck(files: addedAndModifiedEnDocsMarkdown, ignoredWords: ignoredWords, language: "en-us")
}

// Warning message for not updated package manifest(s)
let manifests = [
    "Moya.podspec",
    "Cartfile",
    "Cartfile.resolved",
    "Package.swift",
    "Package.resolved"
]
let updatedManifests = manifests.filter { manifest in danger.git.modifiedFiles.contains { $0.name == manifest } }
if !updatedManifests.isEmpty && updatedManifests.count != manifests.count {
    let notUpdatedManifests = manifests.filter { !updatedManifests.contains($0) }
    let updatedArticle = updatedManifests.count == 1 ? "The " : ""
    let updatedVerb = updatedManifests.count == 1 ? "was" : "were"