Skip to content

Commit

Permalink
spellchekcer: skip code sections in markdown files
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Kahnert authored and Julian Kahnert committed Feb 18, 2021
1 parent 05b3c22 commit 1589620
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.build
16 changes: 8 additions & 8 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"repositoryURL": "https://github.com/JohnSundell/Files",
"state": {
"branch": null,
"revision": "22fe84797d499ffca911ccd896b34efaf06a50b9",
"version": "4.1.1"
"revision": "d273b5b7025d386feef79ef6bad7de762e106eaf",
"version": "4.2.0"
}
},
{
Expand All @@ -33,8 +33,8 @@
"repositoryURL": "https://github.com/apple/swift-log.git",
"state": {
"branch": null,
"revision": "74d7b91ceebc85daf387ebb206003f78813f71aa",
"version": "1.2.0"
"revision": "173f567a2dfec11d74588eea82cecea555bdc0bc",
"version": "1.4.0"
}
},
{
Expand All @@ -51,17 +51,17 @@
"repositoryURL": "https://github.com/apple/swift-tools-support-core.git",
"state": {
"branch": null,
"revision": "693aba4c4c9dcc4767cc853a0dd38bf90ad8c258",
"version": "0.0.1"
"revision": "2954e55faee5bfee928e844bb09e97fcfa8d24af",
"version": "0.2.0"
}
},
{
"package": "Yams",
"repositoryURL": "https://github.com/jpsim/Yams.git",
"state": {
"branch": null,
"revision": "c947a306d2e80ecb2c0859047b35c73b8e1ca27f",
"version": "2.0.0"
"revision": "9003d51672e516cc59297b7e96bff1dfdedcb4ea",
"version": "4.0.4"
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct SpellCheck: CheckProvider {
!ignoredPaths.contains(where: { file.path.contains($0) })
}

var bar = ProgressBar(count: files.count, configuration: [ProgressString(string: "SpellChcker:"), ProgressBarLine(barLength: 50), ProgressPercent()])
var bar = ProgressBar(count: files.count, configuration: [ProgressString(string: "SpellChecker:"), ProgressBarLine(barLength: 50), ProgressPercent()])
return files.flatMap { file -> [CheckResult] in
bar.next()
return analyse(file: file, with: spellChecker)
Expand All @@ -53,7 +53,13 @@ struct SpellCheck: CheckProvider {

case "md":
guard let fileContent = try? String(contentsOf: file.url) else { return [] }
return fileContent.split(separator: "\n")
let contentWithoutCode = fileContent.components(separatedBy: "```")
.enumerated()
.reduce(into: "") { (resultString, tuple) in
guard (tuple.offset % 2) == 0 else { return }
resultString += tuple.element
}
return contentWithoutCode.split(separator: "\n")
.compactMap { spellChecker.findMisspelled(in: String($0)) }
.map { .warning(msg: "Misspelled: '\($0)' in '\(file.path)'") }

Expand Down

0 comments on commit 1589620

Please sign in to comment.