-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathflake8_scrapy.py
58 lines (44 loc) · 1.52 KB
/
flake8_scrapy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import ast
from finders.domains import (
UnreachableDomainIssueFinder, UrlInAllowedDomainsIssueFinder,
)
from finders.oldstyle import OldSelectorIssueFinder, UrlJoinIssueFinder
__version__ = '0.0.2'
class ScrapyStyleIssueFinder(ast.NodeVisitor):
def __init__(self, *args, **kwargs):
super(ScrapyStyleIssueFinder, self).__init__(*args, **kwargs)
self.issues = []
self.finders = {
'Assign': [
UnreachableDomainIssueFinder(),
UrlInAllowedDomainsIssueFinder(),
OldSelectorIssueFinder(),
],
'Call': [
UrlJoinIssueFinder(),
]
}
def find_issues_visitor(self, visitor, node):
"""Find issues for the provided visitor
"""
for finder in self.finders[visitor]:
issues = finder.find_issues(node)
if issues:
self.issues.extend(list(issues))
self.generic_visit(node)
def visit_Assign(self, node):
self.find_issues_visitor('Assign', node)
def visit_Call(self, node):
self.find_issues_visitor('Call', node)
class ScrapyStyleChecker(object):
options = None
name = 'flake8-scrapy'
version = __version__
def __init__(self, tree, filename):
self.tree = tree
self.filename = filename
def run(self):
finder = ScrapyStyleIssueFinder()
finder.visit(self.tree)
for line, col, msg in finder.issues:
yield (line, col, msg, ScrapyStyleChecker)