From 7f8da89e8622a95f823e55a95c65d17aedd50242 Mon Sep 17 00:00:00 2001
From: Anthony Correa
Date: Fri, 19 Jan 2024 12:47:54 -0600
Subject: [PATCH] Implement spell-check (and spell check existing)
commit c81148c7d6ab9f0d01499945f87e8a632b46c37c
Author: Anthony Correa
Date: Fri Jan 19 12:44:22 2024 -0600
ignore git-spell-check temp files
commit 66fe77de453aa758b1122f821e1d3e99557516eb
Author: Anthony Correa
Date: Fri Jan 19 12:43:05 2024 -0600
add checking for header in pws
commit e7659d2442382c71e683596f77b32cc3f3a46bb2
Author: Anthony Correa
Date: Fri Jan 19 12:29:40 2024 -0600
spell-check files
commit 44081a0c148cf30627191a5ff5acaed704785b04
Author: Anthony Correa
Date: Fri Jan 19 12:27:41 2024 -0600
implement spell-check
---
.gitignore | 10 +-
.spell-check/.aspell.en.prepl | 1 +
.spell-check/.aspell.en.pws | 20 ++++
.spell-check/git-spell-check | 189 ++++++++++++++++++++++++++++++++++
.spell-check/spell-check | 10 ++
README.md | 20 +++-
src/cmba-bylaws.md | 4 +-
7 files changed, 248 insertions(+), 6 deletions(-)
create mode 100644 .spell-check/.aspell.en.prepl
create mode 100644 .spell-check/.aspell.en.pws
create mode 100755 .spell-check/git-spell-check
create mode 100755 .spell-check/spell-check
diff --git a/.gitignore b/.gitignore
index cd86870..946330a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,4 +7,12 @@
/dataSources/
/dataSources.local.xml
-.idea/
\ No newline at end of file
+.idea/
+*.bbprojectd
+
+# Backups created by aspell
+*.md.bak*
+
+# Tempfiles created by git-spell-check
+docs-dictionary-*
+temp_file-*
\ No newline at end of file
diff --git a/.spell-check/.aspell.en.prepl b/.spell-check/.aspell.en.prepl
new file mode 100644
index 0000000..4c3ecb8
--- /dev/null
+++ b/.spell-check/.aspell.en.prepl
@@ -0,0 +1 @@
+personal_repl-1.1 en 0
diff --git a/.spell-check/.aspell.en.pws b/.spell-check/.aspell.en.pws
new file mode 100644
index 0000000..f197bab
--- /dev/null
+++ b/.spell-check/.aspell.en.pws
@@ -0,0 +1,20 @@
+personal_ws-1.1 en 19
+BBCOR
+MLB
+RO
+Rawlings
+chicagoland
+cmba
+ePUB
+epub
+gitdriver
+github
+html
+jgm
+lua
+md
+pandoc
+repo
+rostered
+src
+timeframe
diff --git a/.spell-check/git-spell-check b/.spell-check/git-spell-check
new file mode 100755
index 0000000..2ee3f32
--- /dev/null
+++ b/.spell-check/git-spell-check
@@ -0,0 +1,189 @@
+#!/bin/bash
+# mprpic/git-spell-check
+# https://github.com/mprpic/git-spell-check/
+set -e
+
+#adding this for use on a Mac
+if command -v gsed &> /dev/null
+then
+ sed=gsed
+else
+ sed=sed
+fi
+
+# Instructions:
+#
+# This script is a Git pre-commit hook that spell checks any content you are about to commit.
+#
+# Place this script into the ".git/hooks/" directory in your repository. It must be called "pre-commit" and be
+# executable. A Git hook only works in a single repository. You need to copy this hook into every repository you wish to
+# use it in manually. Optionally, you can set up a symlink in the ".git/hooks/" directory pointing to the script.
+#
+# Each time you try to commit something, this script is run and spell checks the content you are committing.
+#
+# Should you want to bypass the pre-commit hook (though not recommended), you can commit with "git commit --no-verify".
+
+
+# The following is a text file that represents your custom dictionary; edit as necessary. Add words to it that you wish
+# to ignore for the spell check.
+dict=~/.git-spell-check
+if [ ! -f $dict ]; then
+ touch ~/.git-spell-check
+ dict=~/.git-spell-check
+ printf "%s\n" "Custom dictionary not found. Created ~/.git-spell-check..."
+fi
+
+
+# The following is a temporary dictionary (a binary file) created from the dict text file. It is deleted after the
+# script finishes.
+temp_dict=$(mktemp docs-dictionary-XXXXXX)
+
+# Language of your doc. When using a non-English language, make sure you have the appropriate aspell libraries
+# installed: "yum search aspell". For example, to spell check in Slovak, you must have the aspell-sk package installed.
+lang=en
+
+# Define an extension for any additional dictionaries (containing words that are ignored during the spell check) that
+# are kept locally in your repository. These dictionaries will be loaded on top of the existing global dictionary (by
+# default ~/.git-spell-check).
+extension=pws
+
+# Clean up if script is interrupted or terminated.
+trap "cleanup" SIGINT SIGTERM
+
+# Prepares the dictionary from scratch in case new words were added since last time.
+function prepare_dictionary() {
+
+ local_dict=$(find . -name *.$extension -exec ls {} \;)
+ if [ -z "$local_dict" ]; then
+ sort -u $temp_dict -o $temp_dict
+ aspell --lang="$lang" create master "$temp_dict" < "$dict"
+ else
+ temp_file=$(mktemp temp_file-XXXXXX)
+ for file in $local_dict; do
+ cat $file >> $temp_file
+ done
+ cat $dict >> $temp_file
+ ## Remove header line
+ $sed -i '/personal_ws-/d' "${temp_file}"
+ sort -u $temp_file -o $temp_file
+ aspell --lang="$lang" create master "$temp_dict" < "$temp_file"
+ /bin/rm -f "$temp_file"
+ fi
+
+}
+
+# Removes the temporary dictionary.
+function cleanup() {
+
+ /bin/rm -f "$temp_dict"
+
+}
+
+# Spell checks content you're about to commit. Writes out words that are misspelled or exits with 0 (i.e. continues with
+# commit).
+function spell_check() {
+
+ words=$(git diff --cached | grep -e "^+[^+]" | aspell --mode=sgml list --add-sgml-skip={ulink,code,literal,firstname,parameter,option,package,replaceable,programlisting,userinput,screen,filename,command,computeroutput,abbrev,accel,orgname,surname,foreignphrase,acronym,hardware,keycap,systemitem,application} --lang="$lang" --extra-dicts="$temp_dict" | sort -u)
+ if [ ! "$words" ]; then
+ printf "%s\n" "No typos found. Proceeding with commit..."
+ cleanup; exit 0
+ fi
+ printf "%s\n" "Spell check failed on the following words:
+-------------------------------------------------"
+ echo $words
+ for word in $words; do
+ grep --color=always --exclude-dir={.git,tmp} -HIrone "\<$word\>" $(git diff --cached --name-only --diff-filter=ACMRTUXB) | awk -F ":" '{print "File: " $1 "\ton line: " $2 "\tTypo: " $3}'
+ printf "%s\n" "-------------------"
+ done
+
+}
+
+# Adds all, some, or none of the misspelled words to the custom dictionary.
+function add_words_to_dict() {
+
+ printf "%s\n" "
+Add any of the misspelled words into your custom dictionary?
+ * a[ll] (add all words into dict, continue with commit)
+ * s[ome] (add some words into dict, fix others, no commit)
+ * i[gnore] (add some words into dict, ignore rest, continue with commit)
+ * n[one] (no commit)
+"
+
+ while true; do
+ exec < /dev/tty # Simply reading user input does not work because Git hooks have stdin detached.
+ read answer
+ shopt -s nocasematch
+ case "$answer" in
+ a|all)
+ add_all
+ cleanup; exit 0
+ ;;
+ s|some)
+ add_some
+ printf "%s\n" "Please fix remaining typos, use \"git add\" to add fixed files, and commit."
+ cleanup; exit 1
+ ;;
+ i|ignore)
+ add_some
+ cleanup; exit 0
+ ;;
+ n|none)
+ add_none
+ cleanup; exit 1
+ ;;
+ *)
+ printf "%s\n" "Incorrect answer. Try again."
+ continue
+ esac
+ shopt -u nocasematch
+ done
+
+}
+
+# Adds all words to the custom dictionary and continues with the commit.
+function add_all() {
+
+ for word in $words; do
+ echo $word >> "$dict"
+ done
+
+}
+
+# Adds some (selected by user) of the words to the dictionary and exits with 1.
+function add_some() {
+
+ for word in $words; do
+ printf "%s\n" "Do you want to add the following word to your custom dictionary: $word (y[es] or n[o])"
+ while true; do
+ exec < /dev/tty
+ read answer
+ shopt -s nocasematch
+ case "$answer" in
+ y|yes)
+ echo $word >> "$dict"
+ printf "%s\n" "\"$word\" added to your custom dictionary."
+ break ;;
+ n|no)
+ break ;;
+ *)
+ printf "%s\n" "Incorrect answer. Try again."
+ continue
+ esac
+ shopt -u nocasematch
+ done
+ done
+
+}
+
+# Adds none of the words and exits with 1.
+function add_none() {
+
+ printf "%s\n" "No words were added to your custom dictionary."
+ printf "%s\n" "Please fix remaining typos, use \"git add\" to add fixed files, and commit."
+
+}
+
+
+prepare_dictionary
+spell_check
+add_words_to_dict
\ No newline at end of file
diff --git a/.spell-check/spell-check b/.spell-check/spell-check
new file mode 100755
index 0000000..ba705bc
--- /dev/null
+++ b/.spell-check/spell-check
@@ -0,0 +1,10 @@
+#!/bin/bash
+set -e
+
+extension_files_to_check=md
+
+function spell_check(){
+ find . -type f -name "*.${extension_files_to_check}" -exec aspell check {} --mode=markdown --home-dir=./.spell-check \;
+}
+
+spell_check
\ No newline at end of file
diff --git a/README.md b/README.md
index c95f118..e8420f5 100644
--- a/README.md
+++ b/README.md
@@ -43,7 +43,7 @@ were `{format}` is one of the below:
## Markdown formatting
-- `#` or `h1` is used for either "Consitution" or "Bylaws". They are not numbered, necessitating an `{.unnumbered}` class.
+- `#` or `h1` is used for either "Constitution" or "Bylaws". They are not numbered, necessitating an `{.unnumbered}` class.
- Note: to get the numbering to match existing convention, a [Lua filter](https://github.com/jgm/pandoc/issues/5071#issuecomment-856918980) was required, see [jgm/pandoc#5701](https://github.com/jgm/pandoc/issues/5071)
- `##` or `h2` is used for sections
- `###` or `h3` is used for subsections
@@ -54,10 +54,24 @@ Metadata is stored in the `metadata.yml` file.
## Project history
-The constitution and bylaws were modernized in 2021, using Google Docs. This project brings that effort into Git and Github. Previous commits show a generated plaintext history of the changes prior to this project (thanks to [gitdriver](https://github.com/larsks/gitdriver)), with the first being the version from 2016.
+The constitution and bylaws were modernized in 2021, using Google Docs. This project brings that effort into Git and Github. Previous commits show a generated plain-text history of the changes prior to this project (thanks to [gitdriver](https://github.com/larsks/gitdriver)), with the first being the version from 2016.
+
+## Spell-checking
+Spell-checking is performed on the pre-commit via [.spell-check/git-spell-check](.spell-check/git-spell-check) (courtesy of [mprpic/git-spell-check](https://github.com/mprpic/git-spell-check))
+
+You can manually run spell-checking of all markdown files by running the script (requires [aspell](http://aspell.net)):
+
+```console
+./.spell-check/spell-check
+```
+
+Should you want to bypass the pre-commit hook (though not recommended), you can commit with
+```console
+git commit --no-verify".
+```
## To-Do
-- [ ] Spell Checking
+- [X] Spell Checking
- [ ] Remove dependence on make, verify Windows support
## About the CMBA
diff --git a/src/cmba-bylaws.md b/src/cmba-bylaws.md
index f157afe..dbd3121 100644
--- a/src/cmba-bylaws.md
+++ b/src/cmba-bylaws.md
@@ -267,10 +267,10 @@ The CMBA shall not incorporate the following rules of Major League Baseball:
- Rule 4.03(c)(4) specifying limitations on when a position player can pitch.
- Rule 5.02(c) specifying limitations on infielder placement.
-- Rule 7.01(b) incorporating the parameters of the Extra Innings Rule, which includes starting each half-inning following the last regu lation inning with a runner on second base.
+- Rule 7.01(b) incorporating the parameters of the Extra Innings Rule, which includes starting each half-inning following the last regulation inning with a runner on second base.
- Rule 5.10(m)(1) limiting the number of mound visits.
- Rule 5.10(g) requiring that pitchers must face at least three batters.
-- Rules 5.07(c) specifying time limits on pitchers and batters. Limitations on pitcher disengagments (i.e. pick-offs) shall also not be incorporated.
+- Rules 5.07(c) specifying time limits on pitchers and batters. Limitations on pitcher disengagements (i.e. pick-offs) shall also not be incorporated.
### Regulation Games