From 53cc988ec66f6114c337876b0ff25eeaad213bda Mon Sep 17 00:00:00 2001 From: Ryan McCarl Date: Tue, 25 May 2021 20:38:44 +0100 Subject: [PATCH] Added Garner checks --- proselint/.proselintrc | 2 ++ proselint/checks/garner/__init__.py | 1 + proselint/checks/garner/jargon.py | 45 ++++++++++++++++++++++++ proselint/checks/garner/substitutions.py | 43 ++++++++++++++++++++++ tests/test_garner_jargon.py | 24 +++++++++++++ tests/test_garner_substitutions.py | 25 +++++++++++++ 6 files changed, 140 insertions(+) create mode 100644 proselint/checks/garner/__init__.py create mode 100644 proselint/checks/garner/jargon.py create mode 100644 proselint/checks/garner/substitutions.py create mode 100644 tests/test_garner_jargon.py create mode 100644 tests/test_garner_substitutions.py diff --git a/proselint/.proselintrc b/proselint/.proselintrc index 5a8759245..909d392f5 100644 --- a/proselint/.proselintrc +++ b/proselint/.proselintrc @@ -14,6 +14,8 @@ "cursing.nword" : true, "dates_times.am_pm" : true, "dates_times.dates" : true, + "garner.jargon" : true, + "garner.substitutions" : true, "hedging.misc" : true, "hyperbole.misc" : true, "jargon.misc" : true, diff --git a/proselint/checks/garner/__init__.py b/proselint/checks/garner/__init__.py new file mode 100644 index 000000000..1ee9231ec --- /dev/null +++ b/proselint/checks/garner/__init__.py @@ -0,0 +1 @@ +"""Brian Garner recommendations from various sources.""" diff --git a/proselint/checks/garner/jargon.py b/proselint/checks/garner/jargon.py new file mode 100644 index 000000000..8aeaf4cf7 --- /dev/null +++ b/proselint/checks/garner/jargon.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +"""Brian Garner recommendations from various sources. + +Resources: +Garner, Modern American Usage +Garner, Modern Legal Usage +Garner, Lawprose Blog +http://www.lawprose.org/lawprose-blog/ +https://abajournal.com/magazine/article/ax_these_terms_from_your_legal_writing/ + +--- +layout: post +source: Various Brian Garner sources +source_url: http://www.lawprose.org/lawprose-blog/ +title: Brian Garner - Jargon +date: 2018-11-19 11:35:00 +categories: writing +--- + +""" +from proselint.tools import memoize, existence_check + + +@memoize +def check(text): + """Check the text.""" + err = "garner.jargon" + msg = u"""'{}' may be jargon, legalese, or a redundancy.""" + + jargon = [ + "acknowledge same", + "aid and abet", + "aid and comfort" + "conclusory", + "deem", + "each and every", + "for same", + "one and only", + "provided that", + "such", + "to same", + "witnesseth", + ] + + return existence_check(text, jargon, err, msg, join=True) diff --git a/proselint/checks/garner/substitutions.py b/proselint/checks/garner/substitutions.py new file mode 100644 index 000000000..1bc752572 --- /dev/null +++ b/proselint/checks/garner/substitutions.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +"""Brian Garner recommended substitutions from various sources. + +Resources: +Garner, Modern American Usage +Garner, Modern Legal Usage +Garner, Lawprose Blog +http://www.lawprose.org/lawprose-blog/ +https://abajournal.com/magazine/article/ax_these_terms_from_your_legal_writing/ + +--- +layout: post +source: Various Brian Garner sources +source_url: http://www.lawprose.org/lawprose-blog/ +title: Brian Garner - Preferred Forms +date: 2018-11-19 13:35:00 +categories: writing +--- + +""" + +from proselint.tools import memoize, preferred_forms_check + + +@memoize +def check(text): + """Suggest the preferred forms.""" + err = "garner.substitutions" + msg = "Consider {}." + + # https://abajournal.com/magazine/article/ax_these_terms_from_your_legal_writing + preferences = [ + ["'or'", [r"and(/| )or"]], + ["'are'", ["deem"]], + ["'if', 'except' or 'also'", ["(provided that|given that)"]], + ["'let it be known' or 'understand'", [ + r"know all (women|men|persons) by these presents"]], + ["'in this [agreement, section, etc]", ["herein"]], + ["'must,' 'should,' 'is,' 'will,' or 'may'", ["shall"]], + ["'required by''", ["pursuant to"]], + ] + + return preferred_forms_check(text, preferences, err, msg) diff --git a/tests/test_garner_jargon.py b/tests/test_garner_jargon.py new file mode 100644 index 000000000..241866bb0 --- /dev/null +++ b/tests/test_garner_jargon.py @@ -0,0 +1,24 @@ +"""Tests for garner.jargon check.""" +from __future__ import absolute_import + +from proselint.checks.garner import jargon as chk + +from .check import Check + + +class TestCheck(Check): + """The test class for garner.jargon.""" + + __test__ = True + + @property + def this_check(self): + """Boilerplate.""" + return chk + + @property + def test_smoke(self): + """Basic smoke test for garner.jargon.""" + assert self.passes("""This sentence contains no jargon.""") + assert not self.passes("""Whereas this conclusory sentence contains + jargon.""") diff --git a/tests/test_garner_substitutions.py b/tests/test_garner_substitutions.py new file mode 100644 index 000000000..1448344f7 --- /dev/null +++ b/tests/test_garner_substitutions.py @@ -0,0 +1,25 @@ +"""Tests for garner.jargon check.""" +from __future__ import absolute_import + +from proselint.checks.garner import substitutions as chk + +from .check import Check + + +class TestCheck(Check): + """The test class for garner.substitutions""" + + __test__ = True + + @property + def this_check(self): + """Boilerplate.""" + return chk + + @property + def test_smoke(self): + """Basic smoke test for garner.substitutions.""" + assert self.passes("""This sentence should pass.""") + assert not self.passes("""Herein we agree on the agreement at issue in + the above-captioned case, provided, however, that all parties have no + objections to same.""")