martinthomson / i-d-template

A template for IETF internet draft git repositories
Other
213 stars 182 forks source link

Add spell checkers as optional #238

Open martinthomson opened 4 years ago

martinthomson commented 4 years ago

@larseggert shared this neat hack:

diff --git a/main.mk b/main.mk
index d49ec88..c50c2a4 100644
--- a/main.mk
+++ b/main.mk
@@ -77,7 +77,18 @@ endif
      cat $< $(MD_PRE) | $(mmark) -xml2 -page $(MD_POST) $@; \
    else \
      ! echo "Unable to detect '%%%' or '---' in markdown file" 1>&2; \
-   fi && [ -e $@ ]
+   fi && [ -e $@ ]; \
+   codespell $<; \
+   sed -e "s/MAY/may/g" -e "s/MUST NOT/must not/g" -e "s/MUST/must/g" \
+       -e "s/NOT RECOMMENDED/not recommended/g" \
+       -e "s/OPTIONAL/optional/g" -e "s/RECOMMENDED/recommended/g" \
+       -e "s/REQUIRED/required/g" -e "s/SHALL NOT/shall not/g" \
+       -e "s/SHALL/shall/g" -e "s/SHOULD NOT/should not/g" \
+       -e "s/SHOULD/should/g" $@ | \
+   languagetool --disable WORD_CONTAINS_UNDERSCORE \
+       --disablecategories PUNCTUATION,TYPOGRAPHY --xmlfilter - || exit 0
+
+# --language en-US 

 ifdef REFCACHEDIR
 %.xml: .refcache

I think that the right place to put something like that is under a new target, as this is likely to produce a ton of chaff. People can then make spell checking mandatory by adding to their Makefile as follows:

lint:: spellcheck

This is a general pattern I'm considering for lints. I want to pull in the column-length checks that we use in QUIC in a similar way. I'm certain that most people won't want those, but they are generally useful as a discretionary feature.

martinthomson commented 3 years ago

Took a look at this and while codespell is fairly simple, languagetool installation requirements are... epic. This means standing up services or something like that.