Skip to content

Commit 775776e

Browse files
committed
ENH: Initialize default list of suffixes
1 parent 8eed350 commit 775776e

1 file changed

Lines changed: 22 additions & 19 deletions

File tree

codespell.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@
1515
from comment_parser import comment_parser
1616

1717

18+
SUFFIX2MIME = {
19+
'.h': 'text/x-c++',
20+
'.cxx': 'text/x-c++',
21+
'.c': 'text/x-c++',
22+
'.hxx': 'text/x-c++',
23+
'.py': 'text/x-python',
24+
'.ruby': 'text/x-ruby',
25+
'.java': 'text/x-java-source',
26+
'.txt': 'text/plain',
27+
'.rst': 'text/plain',
28+
'.md': 'text/plain',
29+
}
30+
31+
1832
def splitCamelCase(word):
1933
"""Split a camel case string into individual words."""
2034

@@ -37,24 +51,8 @@ def splitCamelCase(word):
3751

3852
def getMimeType(filepath):
3953
"""Map `filepath`` extension to file type."""
40-
41-
suffix2mime = { '.h': 'text/x-c++',
42-
'.cxx': 'text/x-c++',
43-
'.c': 'text/x-c++',
44-
'.hxx': 'text/x-c++',
45-
'.py': 'text/x-python',
46-
'.ruby': 'text/x-ruby',
47-
'.java': 'text/x-java-source',
48-
'.txt': 'text/plain',
49-
'.rst': 'text/plain',
50-
'.md': 'text/plain',
51-
}
5254
name, ext = os.path.splitext(filepath)
53-
54-
if ext in suffix2mime:
55-
return suffix2mime[ext]
56-
else:
57-
return 'text/plain'
55+
return SUFFIX2MIME.get(ext, 'text/plain')
5856

5957

6058
def load_text_file(filename):
@@ -298,9 +296,14 @@ def main():
298296

299297
bad_words = []
300298

299+
if not args.suffix:
300+
suffixes = list(SUFFIX2MIME.keys())
301+
else:
302+
suffixes = args.suffix
303+
301304
if output_lvl>1:
302305
print("Prefixes:", prefixes)
303-
print("Suffixes:", args.suffix)
306+
print("Suffixes:", suffixes)
304307

305308
#
306309
# Spell check the files
@@ -315,7 +318,7 @@ def main():
315318

316319
# f is a directory, so search for files inside
317320
dir_entries = []
318-
for s in args.suffix:
321+
for s in suffixes:
319322
dir_entries = dir_entries + glob.glob(f + '/**/*' + s, recursive=True)
320323

321324
if output_lvl>0:

0 commit comments

Comments
 (0)