Skip to content

Commit 56fde13

Browse files
committed
Simplified regex which works nice on prose
1 parent 6f48a8f commit 56fde13

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

codespell_lib/_codespell.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
uri_regex_def = (u"(\\b(?:https?|[ts]?ftp|file|git|smb)://[^\\s]+(?=$|\\s)|"
3434
u"\\b[\\w.%+-]+@[\\w.-]+\\b)")
3535
inline_ignore_regex = re.compile(
36-
r"([^\w\s]) codespell:ignore(\s(?P<words>[\w,]*))?(\s+\1|$)")
36+
r"[^\w\s]\s?codespell:ignore\b(\s+(?P<words>[\w,]*))?")
3737
encodings = ('utf-8', 'iso-8859-1')
3838
USAGE = """
3939
\t%prog [OPTIONS] [file1 file2 ... fileN]

codespell_lib/tests/test_basic.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,21 +247,23 @@ def test_ignore_word_list(tmpdir, capsys):
247247
('abandonned abondon abilty # codespell:ignore\r\n', 0),
248248
('abandonned abondon abilty # codespell:ignore # noqa: E501\n', 0),
249249
('abandonned abondon abilty # codespell:ignore # noqa: E501\n', 0),
250+
('abandonned abondon abilty # codespell:ignore# noqa: E501\n', 0),
251+
('abandonned abondon abilty # codespell:ignore, noqa: E501\n', 0),
252+
('abandonned abondon abilty #codespell:ignore\n', 0),
250253
# ignore these for safety
251-
('abandonned abondon abilty # codespell:ignore# noqa: E501\n', 3),
252-
('abandonned abondon abilty # codespell:ignore, noqa: E501\n', 3),
253-
('abandonned abondon abilty # codespell:ignore/noqa: E501\n', 3),
254254
('abandonned abondon abilty # codespell:ignorenoqa: E501\n', 3),
255-
('abandonned abondon abilty #codespell:ignore\n', 3),
256255
('abandonned abondon abilty codespell:ignore\n', 3),
257256
('abandonned abondon abilty codespell:ignore\n', 3),
258257
# showcase different comment markers
259258
("abandonned abondon abilty ' codespell:ignore\n", 0),
260259
('abandonned abondon abilty " codespell:ignore\n', 0),
261260
('abandonned abondon abilty ;; codespell:ignore\n', 0),
262261
('abandonned abondon abilty /* codespell:ignore */\n', 0),
263-
# avoid false positive
264-
('You could also use line based igore ( codespell:ignore ) to igore ', 2),
262+
# prose examples
263+
('You could also use line based igore ( codespell:ignore ) to igore ', 0),
264+
('You could also use line based igore (codespell:ignore) to igore ', 0),
265+
('You could also use line based igore (codespell:ignore igore) to igore ', 0),
266+
('You could also use line based igore (codespell:ignore igare) to igore ', 2),
265267
])
266268
def test_inline_ignores(tmpdir, capsys, content, expected_error_count):
267269
d = str(tmpdir)

0 commit comments

Comments
 (0)