Skip to content

Commit f5d01d9

Browse files
committed
Avoid redundant suggestions
1 parent 83a3a69 commit f5d01d9

3 files changed

Lines changed: 13 additions & 6 deletions

File tree

‎README.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ From the command line::
5252
$ echo 'This are bad.' > example.txt
5353

5454
$ language-check example.txt
55-
example.txt:1:1: THIS_NNS[3]: Did you mean 'these'?; suggestions: These
55+
example.txt:1:1: THIS_NNS[3]: Did you mean 'these'?
5656

5757

5858
Installation

‎language_check/main.py‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,20 @@ def main():
123123
rule_id += '[{}]'.format(match.subId)
124124

125125
replacement_text = ', '.join(match.replacements).strip()
126-
print('{}:{}:{}: {}: {}{}'.format(
126+
127+
message = match.msg
128+
129+
# Messages that end with punctuation already include the
130+
# suggestion.
131+
if replacement_text and not message.endswith(('.', '?')):
132+
message += '; suggestions: ' + replacement_text
133+
134+
print('{}:{}:{}: {}: {}'.format(
127135
filename,
128136
match.fromy + 1,
129137
match.fromx + 1,
130138
rule_id,
131-
match.msg,
132-
('; suggestions: ' + replacement_text)
133-
if replacement_text else ''))
139+
message))
134140
status = 2
135141

136142
return status

‎test.bash‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ echo 'This is okay.' | language-check -
88
echo 'This is okay.' | python -m language_check -
99
! echo 'This is noot okay.' | python -m language_check -
1010

11-
! echo 'This is a "dumb" quote.' | python -m language_check -
11+
echo 'These are “smart” quotes.' | python -m language_check -
12+
! echo 'These are "dumb" quotes.' | python -m language_check -

0 commit comments

Comments
 (0)