summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Fiddaman <omnios@citrus-it.co.uk>2019-02-11 11:08:45 +0000
committerAndy Fiddaman <omnios@citrus-it.co.uk>2019-03-01 10:08:39 +0000
commit18ce2efc2fad1ecfa25d6faac23d49fb479d2f00 (patch)
treed9191bb0e5a142a48eb24d6fb9c7e8e42ed862d3
parentd8fc057eca26611d58b48e7ed8fe8735d50c8cb5 (diff)
downloadillumos-joyent-18ce2efc2fad1ecfa25d6faac23d49fb479d2f00.tar.gz
10386 pbchk should catch capitalised "illumos"
10387 pbchk should check commit message spelling Reviewed by: Toomas Soome <tsoome@me.com> Reviewed by: Gergő Mihály Doma <domag02@gmail.com> Approved by: Dan McDonald <danmcd@joyent.com>
-rw-r--r--usr/src/tools/onbld/Checks/Comments.py20
-rw-r--r--usr/src/tools/onbld/Checks/SpellCheck.py43
2 files changed, 47 insertions, 16 deletions
diff --git a/usr/src/tools/onbld/Checks/Comments.py b/usr/src/tools/onbld/Checks/Comments.py
index 4b4706618b..8285be2daa 100644
--- a/usr/src/tools/onbld/Checks/Comments.py
+++ b/usr/src/tools/onbld/Checks/Comments.py
@@ -26,17 +26,19 @@
#
# Copyright 2007, 2010 Richard Lowe
-# Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
+# Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
#
# Check delta comments:
# - Have the correct form.
# - Have a synopsis matching that of the bug
# - Appear only once.
+# - Do not contain common spelling errors.
#
import re, sys
from onbld.Checks.DbLookups import BugDB
+from onbld.Checks.SpellCheck import spellcheck_line
bugre = re.compile(r'^(\d{2,7}) (.*)$')
@@ -71,12 +73,16 @@ def comchk(comments, check_db=True, output=sys.stderr):
'mutant': [],
'dup': [],
'nomatch': [],
- 'nonexistent': [] }
+ 'nonexistent': [],
+ 'spelling': [] }
bugs = {}
ret = 0
blanks = False
+ lineno = 0
for com in comments:
+ lineno += 1
+
# Our input must be newline-free, comments are line-wise.
if com.find('\n') != -1:
raise ValueError("newline in comment '%s'" % com)
@@ -89,6 +95,10 @@ def comchk(comments, check_db=True, output=sys.stderr):
blanks = True
continue
+ for err in spellcheck_line(com):
+ errors['spelling'].append(
+ 'comment line {} - {}'.format(lineno, err))
+
match = bugre.search(com)
if match:
if match.group(1) not in bugs:
@@ -179,4 +189,10 @@ def comchk(comments, check_db=True, output=sys.stderr):
output.write(" should be: '%s'\n" % err[1])
output.write(" is: '%s'\n" % err[2])
+ if errors['spelling']:
+ ret = 1
+ output.write("Spellcheck:\n")
+ for err in errors['spelling']:
+ output.write('{}\n'.format(err))
+
return ret
diff --git a/usr/src/tools/onbld/Checks/SpellCheck.py b/usr/src/tools/onbld/Checks/SpellCheck.py
index 0d07017846..c858947fe6 100644
--- a/usr/src/tools/onbld/Checks/SpellCheck.py
+++ b/usr/src/tools/onbld/Checks/SpellCheck.py
@@ -26,8 +26,9 @@
import re, sys
-spellMsg = '%s: Line %d contains "%s", a common misspelling of "%s"\n'
-altMsg = '%s: Line %d contains "%s"; please use "%s" instead for consistency with other documentation\n'
+spellMsg = 'contains "{}", a common misspelling of "{}"'
+altMsg = 'contains "{}"; please use "{}" instead for consistency with other documentation'
+caseMsg = 'contains "{}"; please use "{}" instead'
misspellings = {
'absense': 'absence',
@@ -253,8 +254,13 @@ alternates = {
'writeable': 'writable'
}
+case = {
+ 'Illumos': 'illumos'
+}
+
misspellingREs = []
alternateREs = []
+caseREs = []
for misspelling, correct in misspellings.items():
regex = re.compile(r'\b%s\b' % (misspelling), re.IGNORECASE)
@@ -266,12 +272,23 @@ for alternate, correct in alternates.items():
entry = (regex, alternate, correct)
alternateREs.append(entry)
-def check(errmsg, output, filename, line, lineno, entry):
- if entry[0].search(line):
- output.write(errmsg % (filename, lineno, entry[1], entry[2]))
- return 1
- else:
- return 0
+for alternate, correct in case.items():
+ regex = re.compile(r'\b%s\b' % (alternate))
+ entry = (regex, alternate, correct)
+ caseREs.append(entry)
+
+def spellcheck_line(line):
+ errs = []
+ for entry in misspellingREs:
+ if entry[0].search(line):
+ errs.append(spellMsg.format(entry[1], entry[2]))
+ for entry in alternateREs:
+ if entry[0].search(line):
+ errs.append(altMsg.format(entry[1], entry[2]))
+ for entry in caseREs:
+ if entry[0].search(line):
+ errs.append(caseMsg.format(entry[1], entry[2]))
+ return errs
def spellcheck(fh, filename=None, output=sys.stderr, **opts):
lineno = 1
@@ -283,12 +300,10 @@ def spellcheck(fh, filename=None, output=sys.stderr, **opts):
fh.seek(0)
for line in fh:
line = line.decode(errors='replace')
- for entry in misspellingREs:
- ret |= check(spellMsg, output, filename, line,
- lineno, entry)
- for entry in alternateREs:
- ret |= check(altMsg, output, filename, line,
- lineno, entry)
+ for err in spellcheck_line(line):
+ output.write('{}: Line {} {}\n'.format(
+ filename, lineno, err))
+ ret = 1
lineno += 1
return ret