Skip to content

Commit 5252f6f

Browse files
committed
Generalize
1 parent 763fc50 commit 5252f6f

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

‎language_check/main.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ def parse_args():
4343
parser.add_argument('-s', '--spell-check-off', dest='spell_check',
4444
action='store_false',
4545
help='disable spell-checking rules')
46-
parser.add_argument('--ignore-comments', action='store_true',
47-
help='ignore lines that start with a hash')
46+
parser.add_argument('--ignore-lines',
47+
help='ignore lines that match this regular expression')
4848
return parser.parse_args()
4949

5050

@@ -58,11 +58,11 @@ def get_rules(rules: str) -> set:
5858
return {rule.upper() for rule in re.findall(r"[\w\-]+", rules)}
5959

6060

61-
def get_text(filename, encoding, ignore_comments):
61+
def get_text(filename, encoding, ignore):
6262
with open(filename, encoding=encoding) as f:
6363
text = ''.join(line for line in f.readlines()
64-
if not ignore_comments or
65-
not line.lstrip().startswith('#'))
64+
if not ignore or
65+
not re.match(ignore, line))
6666
return text
6767

6868

@@ -97,7 +97,7 @@ def main():
9797
return 1
9898
else:
9999
text = get_text(filename, encoding,
100-
ignore_comments=args.ignore_comments)
100+
ignore=args.ignore_lines)
101101
language = guess_language(text)
102102
if not args.api:
103103
print('Detected language: {}'.format(language),
@@ -110,7 +110,7 @@ def main():
110110

111111
if not guess_language:
112112
text = get_text(filename, encoding,
113-
ignore_comments=args.ignore_comments)
113+
ignore=args.ignore_lines)
114114

115115
if not args.spell_check:
116116
lang_tool.disable_spellchecking()

‎test.bash‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ echo 'This is okay.' | python -m language_check -
1111
echo 'These are “smart” quotes.' | python -m language_check -
1212
! echo 'These are "dumb" quotes.' | python -m language_check -
1313

14-
echo '# These are "dumb".' | python -m language_check --ignore-comments -
14+
echo '# These are "dumb".' | python -m language_check --ignore-lines='^#' -

0 commit comments

Comments
 (0)