MCPcopy Index your code
hub / github.com/getsentry/sentry / SentryVisitor

Class SentryVisitor

tools/flake8_plugin.py:141–353  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

139
140
141class SentryVisitor(ast.NodeVisitor):
142 def __init__(self, filename: str, s015_year: int, s015_msg: str) -> None:
143 self.errors: list[tuple[int, int, str]] = []
144 self.filename = filename
145 self._s015_year = s015_year
146 self._s015_msg = s015_msg
147
148 self._except_vars: list[str | None] = []
149 self._function_depth = 0
150
151 def visit_ImportFrom(self, node: ast.ImportFrom) -> None:
152 if node.module and not node.level:
153 if node.module.split(".")[0] in S003_modules:
154 self.errors.append((node.lineno, node.col_offset, S003_msg))
155 elif node.module == "sentry.models":
156 self.errors.append((node.lineno, node.col_offset, S005_msg))
157 elif (
158 ("tests/" in self.filename or "testutils/" in self.filename)
159 and node.module == "django.utils.encoding"
160 and any(x.name in {"force_bytes", "force_str"} for x in node.names)
161 ):
162 self.errors.append((node.lineno, node.col_offset, S006_msg))
163 elif (
164 "tests/" in self.filename or "testutils/" in self.filename
165 ) and node.module == "dateutil.parser":
166 self.errors.append((node.lineno, node.col_offset, S008_msg))
167 elif (
168 "tests/" not in self.filename
169 and "fixtures/" not in self.filename
170 and "sentry/testutils/" not in self.filename
171 and "sentry.testutils" in node.module
172 ):
173 self.errors.append((node.lineno, node.col_offset, S007_msg))
174 elif node.module == "rest_framework.permissions" and any(
175 x.name == "IsAuthenticated" for x in node.names
176 ):
177 self.errors.append((node.lineno, node.col_offset, S012_msg))
178 elif node.module == "sentry.db.models.fields.array":
179 self.errors.append((node.lineno, node.col_offset, S013_msg))
180 elif node.module == "concurrent.futures" and any(
181 x.name == "ThreadPoolExecutor" for x in node.names
182 ):
183 self.errors.append((node.lineno, node.col_offset, S016_msg))
184 elif node.module == S018_module and any(
185 x.name == "PyMemcacheCache" for x in node.names
186 ):
187 self.errors.append((node.lineno, node.col_offset, S018_msg))
188
189 if (
190 _is_platform_path(self.filename)
191 and node.module
192 and not node.level
193 and _is_non_platform_import(node.module)
194 ):
195 self.errors.append((node.lineno, node.col_offset, S017_msg))
196
197 self.generic_visit(node)
198

Callers 1

runMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected