#!/bin/sh
# Reads a draft and names every banned word and every sentence that
# describes how it is being said rather than what was found.
#
# check_words.sh draft.txt
#
# Two kinds of fault are looked for.
#
# The first is a fixed list: words Chris has asked never to appear.
#
# The second is a shape, which is where the failures keep happening. Every
# banned lead-in occupies the same slot: a clause whose subject is the
# writer and whose verb is about speaking, placed in front of a fact.
# "Let me be plain", "I will say so", "I should note" are all that shape.
# The cure is not a longer list but a rule about sentence openers, since
# that is where they live: no sentence may open with a clause about how it
# is being said. Write the fact with the thing as its subject instead.
#
# Exits non-zero when anything is found, so it can gate a send.
draft=${1:-}
if [ -z "$draft" ] || [ ! -f "$draft" ]; then
echo "check: name a file holding the draft"
exit 2
fi
found=0
words='harness|ctor|rails|sidecar|fixture|nit|goldens|slug|seamless|proof|proven|honestly|genuinely|plainly|frankly|candidly'
if grep -n -i -E "\\b($words)\\b" "$draft"; then
echo "check: the words above are asked never to appear"
found=1
fi
# A clause about how the writing is being done, wherever it sits in a
# sentence. Each pattern is a subject that is the writer with a verb about
# speaking or seeming.
shapes='let me|let us|let'"'"'s|i will say|i will be|i should say|i should note|i want to be|i have to say|to be (honest|fair|clear|blunt|direct)|in (all )?fairness|for what it'"'"'s worth|the (honest|plain|simple) (truth|answer|finding)|my (honest|candid) (read|view)|no dressing|dress it up|straight with you|be straight|being straight'
if grep -n -i -E "($shapes)" "$draft"; then
echo "check: the clauses above say how you are speaking, not what you"
echo "found; cut the clause and let the fact carry itself"
found=1
fi
if [ "$found" -eq 0 ]; then
echo "check: nothing found"
fi
exit $found