Skip to content

Commit 763fc50

Browse files
committed
Respect status of "--ignore-comments"
1 parent 32ef66f commit 763fc50

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

‎language_check/main.py‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +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):
61+
def get_text(filename, encoding, ignore_comments):
6262
with open(filename, encoding=encoding) as f:
6363
text = ''.join(line for line in f.readlines()
64-
if not line.lstrip().startswith('#'))
64+
if not ignore_comments or
65+
not line.lstrip().startswith('#'))
6566
return text
6667

6768

@@ -95,7 +96,8 @@ def main():
9596
print('guess_language is unavailable.', file=sys.stderr)
9697
return 1
9798
else:
98-
text = get_text(filename, encoding)
99+
text = get_text(filename, encoding,
100+
ignore_comments=args.ignore_comments)
99101
language = guess_language(text)
100102
if not args.api:
101103
print('Detected language: {}'.format(language),
@@ -107,7 +109,8 @@ def main():
107109
lang_tool.language = args.language
108110

109111
if not guess_language:
110-
text = get_text(filename, encoding)
112+
text = get_text(filename, encoding,
113+
ignore_comments=args.ignore_comments)
111114

112115
if not args.spell_check:
113116
lang_tool.disable_spellchecking()

‎test.bash‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ echo 'This is okay.' | python -m language_check -
1010

1111
echo 'These are “smart” quotes.' | python -m language_check -
1212
! echo 'These are "dumb" quotes.' | python -m language_check -
13+
14+
echo '# These are "dumb".' | python -m language_check --ignore-comments -

0 commit comments

Comments
 (0)