Add trailing white space check

This commit is contained in:
Ben Edgington
2023-03-10 09:14:40 +00:00
parent 790b22299a
commit 6c56a6b334
2 changed files with 29 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ const glob = require('glob')
// - Checks that HTML tags are properly balanced
// - Spellcheck
// - Repeated words check
// - Trailing whitespace check
// - Lints the source markdown (see lintSourceMarkdown in this file)
// - Splits the source markdown into individual pages
// - Lints the split markdown (see lintSplitMarkdown in this file)
@@ -15,6 +16,7 @@ const doInternalLinks = true
const doHtmlCheck = true
const doSpellCheck = true
const doRepeatCheck = true
const doWhitespaceCheck = true
const doSourceLint = true
const doSplitLint = true
@@ -22,6 +24,7 @@ const linkChecker = 'bin/build/links.pl'
const htmlChecker = 'bin/build/html.pl'
const spellChecker = 'bin/build/spellcheck.sh'
const repeatChecker = 'bin/build/repeatcheck.sh'
const whitespaceChecker = 'bin/build/whitespacecheck.sh'
const mdSplitter = 'bin/build/update.sh'
const sourceMarkdown = 'src/book.md'
@@ -105,6 +108,22 @@ module.exports.runChecks = (reporter) => {
reporter.warn('Skipping repeat check')
}
if (doWhitespaceCheck) {
reporter.info('Performing trailing whitespace check...')
try {
const out = execSync(`${whitespaceChecker} ${sourceMarkdown}`, {encoding: 'utf8', stdio: 'pipe'})
if (out !== '') {
reporter.warn('Found trailing whitespace:')
printLines(out, reporter.warn)
}
} catch (err) {
reporter.warn('Unable to perform whitespace check:')
printLines(err.toString(), reporter.warn)
}
} else {
reporter.warn('Skipping whitespace check')
}
if (doSourceLint) {
reporter.info('Linting source markdown...')
try {

10
bin/build/whitespacecheck.sh Executable file
View File

@@ -0,0 +1,10 @@
#!/bin/bash
# Check the book source, supplied as $1, for trailing whitespace
grep -n '\s$' $1 | awk 'BEGIN {FS=":"} {print "Line " $1}'
# The following allows us to handle the return from grep ("1" is not an error!)
r=("${PIPESTATUS[@]}")
(( ${r[0]} )) && (( ${r[0]} != 1 )) && exit ${r[0]}
exit ${r[1]}