Skip to content

Commit 48248fd

Browse files
authored
Merge pull request #36 from jcfr/improve-display-output
Improve display output
2 parents 3740a17 + 13ba99a commit 48248fd

1 file changed

Lines changed: 20 additions & 16 deletions

File tree

codespell.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ def spell_check_comment(
9090
"""Check comment and return list of identified issues if any."""
9191

9292
if output_lvl > 1:
93-
print(f"Comment: {c}")
94-
print(type(c))
93+
print(f"Line {c.line_number()}: {c}")
9594

9695
mistakes = []
9796
spell_checker.set_text(c.text())
@@ -106,6 +105,8 @@ def spell_check_comment(
106105
if error.word.startswith(pre):
107106
# check if the word is only the prefix
108107
if len(pre) == len(error.word):
108+
if output_lvl > 1:
109+
print(f"Prefix '{pre}' matches word")
109110
break
110111

111112
# remove the prefix
@@ -330,9 +331,12 @@ def parse_args():
330331
return args
331332

332333

333-
def add_dict(enchant_dict, filename):
334+
def add_dict(enchant_dict, filename, verbose=False):
334335
"""Update ``enchant_dict`` spell checking dictionary with the words listed
335336
in ``filename`` (one word per line)."""
337+
if verbose:
338+
print(f"Additional dictionary: {filename}")
339+
336340
with open(filename) as f:
337341
lines = f.read().splitlines()
338342

@@ -347,30 +351,30 @@ def main():
347351

348352
sitk_dict = Dict("en_US")
349353

354+
# Set the amount of debugging messages to print.
355+
output_lvl = 1
356+
if args.brief:
357+
output_lvl = 0
358+
else:
359+
if args.verbose:
360+
output_lvl = 2
361+
if args.miss:
362+
output_lvl = -1
363+
350364
# Load the dictionary files
351365
#
352366
initial_dct = Path(__file__).parent / "additional_dictionary.txt"
353367
if not initial_dct.exists():
354368
initial_dct = None
355369
else:
356-
add_dict(sitk_dict, str(initial_dct))
370+
add_dict(sitk_dict, str(initial_dct), any([args.brief, output_lvl >= 0]))
357371

358372
if args.dict is not None:
359373
for d in args.dict:
360-
add_dict(sitk_dict, d)
374+
add_dict(sitk_dict, d, any([args.brief, output_lvl >= 0]))
361375

362376
spell_checker = SpellChecker(sitk_dict, filters=[EmailFilter, URLFilter])
363377

364-
# Set the amount of debugging messages to print.
365-
output_lvl = 1
366-
if args.brief:
367-
output_lvl = 0
368-
else:
369-
if args.verbose:
370-
output_lvl = 2
371-
if args.miss:
372-
output_lvl = -1
373-
374378
file_list = []
375379
if len(args.filenames):
376380
file_list = args.filenames
@@ -386,7 +390,7 @@ def main():
386390
else:
387391
suffixes = args.suffix
388392

389-
if output_lvl > 1:
393+
if any([args.brief, output_lvl >= 0]):
390394
print(f"Prefixes: {prefixes}")
391395
print(f"Suffixes: {suffixes}")
392396

0 commit comments

Comments
 (0)