Skip to content

Commit d9b5b78

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent ccd41e0 commit d9b5b78

File tree

2 files changed

+44
-27
lines changed

2 files changed

+44
-27
lines changed

pylint/checkers/misc.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,24 @@ class EncodingChecker(BaseTokenChecker, BaseRawFileChecker):
9696
"type": "yn",
9797
"metavar": "<y or n>",
9898
"default": False,
99-
"help": "Whether or not to search for fixme's in docstrings."
100-
}
101-
)
99+
"help": "Whether or not to search for fixme's in docstrings.",
100+
},
101+
),
102102
)
103103

104104
def open(self) -> None:
105105
super().open()
106106

107107
notes = "|".join(re.escape(note) for note in self.linter.config.notes)
108108
if self.linter.config.notes_rgx:
109-
comment_regex = rf"#\s*({notes}|{self.linter.config.notes_rgx})(?=(:|\s|\Z))"
109+
comment_regex = (
110+
rf"#\s*({notes}|{self.linter.config.notes_rgx})(?=(:|\s|\Z))"
111+
)
110112
self._comment_fixme_pattern = re.compile(comment_regex, re.I)
111113
if self.linter.config.check_fixme_in_docstring:
112-
docstring_regex = rf"\"\"\"\s*({notes}|{self.linter.config.notes_rgx})(?=(:|\s|\Z))"
114+
docstring_regex = (
115+
rf"\"\"\"\s*({notes}|{self.linter.config.notes_rgx})(?=(:|\s|\Z))"
116+
)
113117
self._docstring_fixme_pattern = re.compile(docstring_regex, re.I)
114118
else:
115119
comment_regex = rf"#\s*({notes})(?=(:|\s|\Z))"
@@ -149,19 +153,28 @@ def process_tokens(self, tokens: list[tokenize.TokenInfo]) -> None:
149153
return
150154
for token_info in tokens:
151155
if token_info.type == tokenize.COMMENT:
152-
comment_text = token_info.string[1:].lstrip() # trim '#' and white-spaces
156+
comment_text = token_info.string[
157+
1:
158+
].lstrip() # trim '#' and white-spaces
153159
if self._comment_fixme_pattern.search("#" + comment_text.lower()):
154160
self.add_message(
155161
"fixme",
156162
col_offset=token_info.start[1] + 1,
157163
args=comment_text,
158164
line=token_info.start[0],
159165
)
160-
elif self.linter.config.check_fixme_in_docstring and self._is_docstring_comment(token_info):
166+
elif (
167+
self.linter.config.check_fixme_in_docstring
168+
and self._is_docstring_comment(token_info)
169+
):
161170
docstring_lines = token_info.string.split("\n")
162171
for line_no, line in enumerate(docstring_lines):
163-
comment_text = line.removeprefix('"""').lstrip().removesuffix('"""') # trim '""""' and whitespace
164-
if self._docstring_fixme_pattern.search('"""' + comment_text.lower()):
172+
comment_text = (
173+
line.removeprefix('"""').lstrip().removesuffix('"""')
174+
) # trim '""""' and whitespace
175+
if self._docstring_fixme_pattern.search(
176+
'"""' + comment_text.lower()
177+
):
165178
self.add_message(
166179
"fixme",
167180
col_offset=token_info.start[1] + 1,
@@ -170,7 +183,10 @@ def process_tokens(self, tokens: list[tokenize.TokenInfo]) -> None:
170183
)
171184

172185
def _is_docstring_comment(self, token_info: tokenize.TokenInfo) -> bool:
173-
return token_info.type == tokenize.STRING and token_info.line.lstrip().startswith('"""')
186+
return (
187+
token_info.type == tokenize.STRING
188+
and token_info.line.lstrip().startswith('"""')
189+
)
174190

175191

176192
def register(linter: PyLinter) -> None:

tests/checkers/unittest_misc.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ def test_docstring_with_message(self) -> None:
124124
"""
125125
with self.assertAddsMessages(
126126
MessageTest(msg_id="fixme", line=2, args="FIXME message", col_offset=9)
127-
128127
):
129128
self.checker.process_tokens(_tokenize_str(code))
130129

@@ -150,7 +149,7 @@ def test_docstring_with_nl_message_multi(self) -> None:
150149
"""
151150
with self.assertAddsMessages(
152151
MessageTest(msg_id="fixme", line=3, args="FIXME this", col_offset=9),
153-
MessageTest(msg_id="fixme", line=4, args="TODO: that", col_offset=9)
152+
MessageTest(msg_id="fixme", line=4, args="TODO: that", col_offset=9),
154153
):
155154
self.checker.process_tokens(_tokenize_str(code))
156155

@@ -166,7 +165,7 @@ def test_docstring_with_comment(self) -> None:
166165
with self.assertAddsMessages(
167166
MessageTest(msg_id="fixme", line=2, args="XXX message1", col_offset=9),
168167
MessageTest(msg_id="fixme", line=4, args="FIXME message2", col_offset=9),
169-
MessageTest(msg_id="fixme", line=5, args="TODO message3", col_offset=9)
168+
MessageTest(msg_id="fixme", line=5, args="TODO message3", col_offset=9),
170169
):
171170
self.checker.process_tokens(_tokenize_str(code))
172171

@@ -206,29 +205,27 @@ def test_docstring_todo_mult(self) -> None:
206205
\"\"\"
207206
"""
208207
with self.assertAddsMessages(
209-
MessageTest(msg_id="fixme", line=3, args="FIXME this TODO that", col_offset=9),
208+
MessageTest(
209+
msg_id="fixme", line=3, args="FIXME this TODO that", col_offset=9
210+
),
210211
):
211212
self.checker.process_tokens(_tokenize_str(code))
212-
213-
@set_config(
214-
check_fixme_in_docstring=True,
215-
notes=["CODETAG"]
216-
)
213+
214+
@set_config(check_fixme_in_docstring=True, notes=["CODETAG"])
217215
def test_docstring_custom_note(self) -> None:
218216
code = """
219217
\"\"\"
220218
CODETAG implement this
221219
\"\"\"
222220
"""
223221
with self.assertAddsMessages(
224-
MessageTest(msg_id="fixme", line=3, args="CODETAG implement this", col_offset=9),
222+
MessageTest(
223+
msg_id="fixme", line=3, args="CODETAG implement this", col_offset=9
224+
),
225225
):
226226
self.checker.process_tokens(_tokenize_str(code))
227-
228-
@set_config(
229-
check_fixme_in_docstring=True,
230-
notes_rgx="FIX.*"
231-
)
227+
228+
@set_config(check_fixme_in_docstring=True, notes_rgx="FIX.*")
232229
def test_docstring_custom_rgx(self) -> None:
233230
code = """
234231
\"\"\"
@@ -237,7 +234,11 @@ def test_docstring_custom_rgx(self) -> None:
237234
\"\"\"
238235
"""
239236
with self.assertAddsMessages(
240-
MessageTest(msg_id="fixme", line=3, args="FIXME implement this", col_offset=9),
241-
MessageTest(msg_id="fixme", line=4, args="FIXTHIS also implement this", col_offset=9),
237+
MessageTest(
238+
msg_id="fixme", line=3, args="FIXME implement this", col_offset=9
239+
),
240+
MessageTest(
241+
msg_id="fixme", line=4, args="FIXTHIS also implement this", col_offset=9
242+
),
242243
):
243244
self.checker.process_tokens(_tokenize_str(code))

0 commit comments

Comments
 (0)