Skip to content

Commit

Permalink
Add new --ignore-words option to ignore 'good' words
Browse files Browse the repository at this point in the history
A new command line option -I / --ignore-words is implemented to specify
one or multiple files containing 'good' words which codespell will
ignore.
  • Loading branch information
thdot committed Mar 7, 2017
1 parent f1c58a7 commit 2f6f7e5
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions codespell_lib/_codespell.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
VERSION = '1.10.0.dev0'

misspellings = {}
ignore_words = set()
exclude_lines = set()
options = None
file_opener = None
Expand Down Expand Up @@ -222,6 +223,10 @@ def parse_options(args):
'equals "-" then default dictionary "%s" is used. '
'This option can be specified multiple times.' %
default_dictionary)
parser.add_option('-I', '--ignore-words',
action='append', metavar='FILE',
help='File that contains words which will be ignored '
'by codespell.')
parser.add_option('-r', '--regex',
action='store', type='string',
help='Regular expression which is used to find words. '
Expand Down Expand Up @@ -284,10 +289,17 @@ def build_exclude_hashes(filename):
exclude_lines.add(line)


def build_ignore_words(filename):
with codecs.open(filename, mode='r', buffering=1, encoding='utf-8') as f:
for line in f:
ignore_words.add(line.strip())

def build_dict(filename):
with codecs.open(filename, mode='r', buffering=1, encoding='utf-8') as f:
for line in f:
[key, data] = line.split('->')
if key in ignore_words:
continue
data = data.strip()
fix = data.rfind(',')

Expand Down Expand Up @@ -520,6 +532,15 @@ def main(*args):
parser.print_help()
return 1

ignore_words_files = options.ignore_words or []
for ignore_words_file in ignore_words_files:
if not os.path.exists(ignore_words_file):
print('ERROR: cannot find ignore-words file: %s' % ignore_words_file,
file=sys.stderr)
parser.print_help()
return 1
build_ignore_words(ignore_words_file)

dictionaries = options.dictionary or [default_dictionary]
for dictionary in dictionaries:
if dictionary is "-":
Expand Down

0 comments on commit 2f6f7e5

Please sign in to comment.