forked from gforcada/flake8-pep3101
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake8_pep3101.py
30 lines (24 loc) · 856 Bytes
/
flake8_pep3101.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
# -*- coding: utf-8 -*-
import ast
import pycodestyle
class Flake8Pep3101(object):
name = 'flake8_pep3101'
version = '1.0'
message = 'S001 found module formatter'
def __init__(self, tree, filename):
self.filename = filename
self.tree = tree
def run(self):
if self.filename is 'stdin':
lines = pycodestyle.stdin_get_value().splitlines()
tree = ast.parse(lines)
elif self.tree:
tree = self.tree
else:
with open(self.filename) as f:
tree = ast.parse(f.read())
for stmt in ast.walk(tree):
if isinstance(stmt, ast.BinOp) and \
isinstance(stmt.op, ast.Mod) and \
isinstance(stmt.left, ast.Str):
yield stmt.lineno, stmt.col_offset, self.message, type(self)