Skip to content

Commit a8e7c63

Browse files
committed
Add NOLINT_START/NOLINT_END to lint.py
1 parent f46cee8 commit a8e7c63

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

scripts/lint.py

+25-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"""
44
Runs custom linting on our code.
55
6-
Adding "NOLINT" to any line makes the linter ignore that line.
6+
Adding "NOLINT" to any line makes the linter ignore that line. Adding a pair of "NOLINT_START" and "NOLINT_END" makes
7+
the linter ignore these lines, as well as all lines in between.
78
"""
89

910
from __future__ import annotations
@@ -973,7 +974,19 @@ def _update_content(self) -> None:
973974
self.content = "".join(self.lines)
974975

975976
# gather lines with a `NOLINT` marker
976-
self.no_lints = {i for i, line in enumerate(self.lines) if "NOLINT" in line}
977+
self.no_lints = set()
978+
is_in_no_lint_block = False
979+
for i, line in enumerate(self.lines):
980+
if "NOLINT" in line:
981+
self.no_lints.add(i)
982+
983+
if "NOLINT_START" in line:
984+
is_in_no_lint_block = True
985+
986+
if is_in_no_lint_block:
987+
self.no_lints.add(i)
988+
if "NOLINT_END" in line:
989+
is_in_no_lint_block = False
977990

978991
def rewrite(self, new_lines: list[str]) -> None:
979992
"""Rewrite the contents of the file."""
@@ -1020,8 +1033,18 @@ def lint_file(filepath: str, args: Any) -> int:
10201033

10211034
is_in_docstring = False
10221035

1036+
is_in_no_lint_block = False
1037+
10231038
prev_line = None
10241039
for line_nr, line in enumerate(source.lines):
1040+
if "NOLINT_START" in line:
1041+
is_in_no_lint_block = True
1042+
1043+
if is_in_no_lint_block:
1044+
if "NOLINT_END" in line:
1045+
is_in_no_lint_block = False
1046+
continue
1047+
10251048
if line == "" or line[-1] != "\n":
10261049
error = "Missing newline at end of file"
10271050
else:

0 commit comments

Comments
 (0)