Skip to content

Commit 1aa08e2

Browse files
committed
Rename option "--skip-noqa" to "--check-noqa" and reverse behavior
This is an incompatible change: without option, the "noqa"-commented lines are now skipped by default (this is the way most linters work). With the option `--check-noqa`, the "noqa"-commented lines are checked.
1 parent 469787d commit 1aa08e2

File tree

5 files changed

+19
-16
lines changed

5 files changed

+19
-16
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Version 3.2.0 (under dev)
44

55
- Drop Python 2 support, Python 3.6 is now required.
6+
- Rename option `--skip-noqa` to `--check-noqa` and reverse behavior: without option, strings with `noqa` are now skipped by default.
67
- Add support for Chinese full-stop.
78
- Add lint with bandit in CI.
89

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Options:
4646
- `-h`, `--help`: display help message and exit
4747
- `-c`, `--no-compile`: do not check compilation of file (with `msgfmt -c`)
4848
- `-f`, `--fuzzy`: check fuzzy strings
49-
- `-n`, `--skip-noqa`: do not check "noqa"-commented lines
49+
- `-n`, `--check-noqa`: check "noqa"-commented lines (they are skipped by default)
5050
- `-l`, `--no-lines`: do not check number of lines
5151
- `-p`, `--no-punct`: do not check punctuation at end of strings
5252
- `-s id|str`, `--spelling id|str`: check spelling (`id` = source messages, `str` = translations)

msgcheck/msgcheck.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ def msgcheck_parser():
6666
help='do not check compilation of file')
6767
parser.add_argument('-f', '--fuzzy', action='store_true',
6868
help='check fuzzy strings')
69-
parser.add_argument('-n', '--skip-noqa', action='store_true',
70-
help='do not check "noqa"-commented lines')
69+
parser.add_argument('-n', '--check-noqa', action='store_true',
70+
help='check "noqa"-commented lines (they are skipped '
71+
'by default)')
7172
parser.add_argument('-l', '--no-lines', action='store_true',
7273
help='do not check number of lines')
7374
parser.add_argument('-p', '--no-punct', action='store_true',
@@ -118,8 +119,9 @@ def msgcheck_check_files(args):
118119
"""Check files."""
119120
# create checker and set boolean options
120121
po_check = PoCheck()
121-
for option in ('no_compile', 'fuzzy', 'skip_noqa', 'no_lines', 'no_punct',
122-
'no_whitespace', 'no_whitespace_eol', 'extract'):
122+
for option in ('no_compile', 'fuzzy', 'check_noqa', 'no_lines',
123+
'no_punct', 'no_whitespace', 'no_whitespace_eol',
124+
'extract'):
123125
if args.__dict__[option]:
124126
po_check.set_check(option.lstrip('no_'),
125127
not option.startswith('no_'))

msgcheck/po.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ def __init__(self):
477477
self.checks = {
478478
'compile': True,
479479
'fuzzy': False,
480-
'skip_noqa': False,
480+
'check_noqa': False,
481481
'lines': True,
482482
'punct': True,
483483
'whitespace': True,
@@ -587,9 +587,9 @@ def check_pofile(self, po_file):
587587

588588
# check all messages
589589
check_fuzzy = self.checks['fuzzy']
590-
skip_noqa = self.checks['skip_noqa']
590+
check_noqa = self.checks['check_noqa']
591591
for msg in po_file.msgs:
592-
if skip_noqa and msg.noqa:
592+
if msg.noqa and not check_noqa:
593593
continue
594594
if msg.fuzzy and not check_fuzzy:
595595
continue

tests/test_msgcheck.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def test_checks():
114114
assert not result[0][1]
115115

116116
# second file has 10 errors
117-
assert len(result[1][1]) == 10
117+
assert len(result[1][1]) == 9
118118

119119
# check first error
120120
report = result[1][1][0]
@@ -129,7 +129,7 @@ def test_checks():
129129
'2 in string, 1 in translation' in str(report))
130130

131131
# check last error
132-
report = result[1][1][9]
132+
report = result[1][1][8]
133133
assert report.message == \
134134
'different whitespace at end of a line: 1 in string, 0 in translation'
135135
assert report.idmsg == 'whitespace_eol'
@@ -144,7 +144,7 @@ def test_checks():
144144
for report in result[1][1]:
145145
errors[report.idmsg] = errors.get(report.idmsg, 0) + 1
146146
assert errors['lines'] == 2
147-
assert errors['punct'] == 2
147+
assert errors['punct'] == 1
148148
assert errors['whitespace'] == 4
149149
assert errors['whitespace_eol'] == 2
150150

@@ -159,20 +159,20 @@ def test_checks_fuzzy():
159159
assert len(result) == 1
160160

161161
# the file has 11 errors (with the fuzzy string)
162-
assert len(result[0][1]) == 11
162+
assert len(result[0][1]) == 10
163163

164164

165165
def test_checks_noqa():
166-
"""Test checks on a gettext file ignoring `noqa`-commented lines."""
166+
"""Test checks on a gettext file including `noqa`-commented lines."""
167167
po_check = PoCheck()
168-
po_check.set_check('skip_noqa', True)
168+
po_check.set_check('check_noqa', True)
169169
result = po_check.check_files([local_path('fr_errors.po')])
170170

171171
# be sure we have one file in result
172172
assert len(result) == 1
173173

174-
# the file has 9 errors (`noqa` was skipped)
175-
assert len(result[0][1]) == 9
174+
# the file has 10 errors (including `noqa`-commented lines)
175+
assert len(result[0][1]) == 10
176176

177177

178178
def test_replace_fmt_c():

0 commit comments

Comments
 (0)