@@ -365,6 +365,14 @@ def parse_args():
365365 args = parser .parse_args ()
366366 return args
367367
368+ def word_check (word ):
369+ """ Check if a word is acceptable for the dictionary. We allow string that
370+ is acceptable as a python idenfier, plus also we allow apostrophes."""
371+ if word .isidentifier ():
372+ return True
373+ # word without apostrophe
374+ word2 = word .replace ("'" , "" )
375+ return word2 .isidentifier ()
368376
369377def add_dict (enchant_dict , filename , verbose = False ):
370378 """Update ``enchant_dict`` spell checking dictionary with the words listed
@@ -377,6 +385,8 @@ def add_dict(enchant_dict, filename, verbose=False):
377385
378386 # You better not have more than 1 word in a line
379387 for wrd in lines :
388+ if not word_check (wrd ):
389+ print ("Warning: adding word with non-alphanumeric characters to dictionary:" , wrd )
380390 if not enchant_dict .check (wrd ):
381391 enchant_dict .add (wrd )
382392
@@ -482,22 +492,23 @@ def main():
482492 # Done spell checking. Print out all the words not found in our dictionary.
483493 #
484494 if not args .miss :
485- print ("\n Bad words\n " )
495+ print ("\n Bad words" )
486496
487497 previous_word = ""
498+ print ("" )
488499
489500 for misspelled_word , found_file , line_num in bad_words :
490- if misspelled_word != previous_word :
501+ if misspelled_word != previous_word and args . first :
491502 print (f"\n { misspelled_word } :" )
492503
493504 if (misspelled_word == previous_word ) and args .first :
494505 sys .stderr .write ("." )
495506 continue
496507
497508 if args .vim :
498- print (f" vim +{ line_num } { found_file } " , file = sys .stderr )
509+ print (f"vim +{ line_num } { found_file } " , file = sys .stderr )
499510 else :
500- print (f" { found_file } , { line_num } " , file = sys .stderr )
511+ print (f"file: { found_file :30 } line: { line_num :3d } word: { misspelled_word } " , file = sys .stderr )
501512
502513 previous_word = misspelled_word
503514
0 commit comments