From 1589620f8c3b0c9bfd29f2999e98220ef2544f90 Mon Sep 17 00:00:00 2001 From: Julian Kahnert Date: Thu, 18 Feb 2021 21:43:35 +0100 Subject: [PATCH] spellchekcer: skip code sections in markdown files --- .dockerignore | 1 + Package.resolved | 16 ++++++++-------- .../CheckProviders/SpellCheck/SpellCheck.swift | 10 ++++++++-- 3 files changed, 17 insertions(+), 10 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..24e5b0a --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.build diff --git a/Package.resolved b/Package.resolved index 2a6d480..18e24dd 100644 --- a/Package.resolved +++ b/Package.resolved @@ -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" } }, { @@ -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" } }, { @@ -51,8 +51,8 @@ "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" } }, { @@ -60,8 +60,8 @@ "repositoryURL": "https://github.com/jpsim/Yams.git", "state": { "branch": null, - "revision": "c947a306d2e80ecb2c0859047b35c73b8e1ca27f", - "version": "2.0.0" + "revision": "9003d51672e516cc59297b7e96bff1dfdedcb4ea", + "version": "4.0.4" } } ] diff --git a/Sources/chiaLib/Internal/CheckProviders/SpellCheck/SpellCheck.swift b/Sources/chiaLib/Internal/CheckProviders/SpellCheck/SpellCheck.swift index 741fa9f..9dcde4f 100644 --- a/Sources/chiaLib/Internal/CheckProviders/SpellCheck/SpellCheck.swift +++ b/Sources/chiaLib/Internal/CheckProviders/SpellCheck/SpellCheck.swift @@ -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) @@ -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)'") }