Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: flake8-abp/flake8_abp.py

Issue 29371619: Noissue - Fix E305 by adapting flake8-abp to use groups, run tests on Python 3.6 (Closed)
Patch Set: Created Jan. 12, 2017, 3:22 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | flake8-abp/setup.py » ('j') | flake8-abp/tox.ini » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # This file is part of Adblock Plus <https://adblockplus.org/>, 1 # This file is part of Adblock Plus <https://adblockplus.org/>,
2 # Copyright (C) 2006-2016 Eyeo GmbH 2 # Copyright (C) 2006-2016 Eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details. 11 # GNU General Public License for more details.
12 # 12 #
13 # You should have received a copy of the GNU General Public License 13 # You should have received a copy of the GNU General Public License
14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
15 15
16 import ast 16 import ast
17 import re 17 import re
18 import tokenize 18 import tokenize
19 import sys 19 import sys
20 import collections 20 import collections
21 21
22 try: 22 try:
23 import builtins 23 import builtins
24 except ImportError: 24 except ImportError:
25 import __builtin__ as builtins 25 import __builtin__ as builtins
26 26
27 import pkg_resources 27 import pkg_resources
28 import flake8
28 29
29 try: 30 try:
30 ascii 31 ascii
31 except NameError: 32 except NameError:
32 ascii = repr 33 ascii = repr
33 34
34 __version__ = pkg_resources.get_distribution('flake8-abp').version 35 __version__ = pkg_resources.get_distribution('flake8-abp').version
35 36
36 DISCOURAGED_APIS = { 37 DISCOURAGED_APIS = {
37 're.match': 're.search', 38 're.match': 're.search',
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 keys.append(key) 348 keys.append(key)
348 349
349 def visit_Dict(self, node): 350 def visit_Dict(self, node):
350 self._visit_hash_keys(node.keys, 'key in dict') 351 self._visit_hash_keys(node.keys, 'key in dict')
351 352
352 def visit_Set(self, node): 353 def visit_Set(self, node):
353 self._visit_hash_keys(node.elts, 'item in set') 354 self._visit_hash_keys(node.elts, 'item in set')
354 355
355 356
356 class ASTChecker(object): 357 class ASTChecker(object):
357 name = 'abp'
358 version = __version__
359
360 def __init__(self, tree, filename): 358 def __init__(self, tree, filename):
361 self.tree = tree 359 self.tree = tree
362 360
363 def run(self): 361 def run(self):
364 visitor = TreeVisitor() 362 visitor = TreeVisitor()
365 visitor.visit(self.tree) 363 visitor.visit(self.tree)
366 364
367 for node, error in visitor.errors: 365 for node, error in visitor.errors:
368 yield (node.lineno, node.col_offset, error, type(self)) 366 yield (node.lineno, node.col_offset, error, type(self))
369 367
370 368
371 def check_non_default_encoding(physical_line, line_number): 369 def check_non_default_encoding(physical_line, line_number):
372 if line_number <= 2 and re.search(r'^\s*#.*coding[:=]', physical_line): 370 if line_number <= 2 and re.search(r'^\s*#.*coding[:=]', physical_line):
373 return (0, 'A303 non-default file encoding') 371 return (0, 'A303 non-default file encoding')
374 372
375 check_non_default_encoding.name = 'abp-non-default-encoding'
Sebastian Noack 2017/01/12 15:55:03 With flake8 3.2.0, it begun to use pycodestyle 2.2
376 check_non_default_encoding.version = __version__
377
378 373
379 def check_quotes(logical_line, tokens, previous_logical, checker_state): 374 def check_quotes(logical_line, tokens, previous_logical, checker_state):
380 first_token = True 375 first_token = True
381 376
382 token_strings = [t[1] for t in tokens] 377 token_strings = [t[1] for t in tokens]
383 future_import = token_strings[:3] == ['from', '__future__', 'import'] 378 future_import = token_strings[:3] == ['from', '__future__', 'import']
384 379
385 if future_import and 'unicode_literals' in token_strings: 380 if future_import and 'unicode_literals' in token_strings:
386 checker_state['has_unicode_literals'] = True 381 checker_state['has_unicode_literals'] = True
387 382
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 if 'u' in prefixes or u_literals and 'b' not in prefixes: 415 if 'u' in prefixes or u_literals and 'b' not in prefixes:
421 prefix = 'u' 416 prefix = 'u'
422 417
423 literal = '{0}{1}{2}{1}'.format(prefix, quote, text) 418 literal = '{0}{1}{2}{1}'.format(prefix, quote, text)
424 if ascii(eval(literal)) != literal: 419 if ascii(eval(literal)) != literal:
425 yield (start, "A110 string literal doesn't match " 420 yield (start, "A110 string literal doesn't match "
426 '{}()'.format(ascii.__name__)) 421 '{}()'.format(ascii.__name__))
427 422
428 first_token = False 423 first_token = False
429 424
430 check_quotes.name = 'abp-quotes'
431 check_quotes.version = __version__
432
433 425
434 def check_redundant_parenthesis(logical_line, tokens): 426 def check_redundant_parenthesis(logical_line, tokens):
435 start_line = tokens[0][2][0] 427 start_line = tokens[0][2][0]
436 level = 0 428 level = 0
437 statement = None 429 statement = None
438 430
439 for i, (kind, token, _, end, _) in enumerate(tokens): 431 for i, (kind, token, _, end, _) in enumerate(tokens):
440 if kind == tokenize.INDENT or kind == tokenize.DEDENT: 432 if kind == tokenize.INDENT or kind == tokenize.DEDENT:
441 continue 433 continue
442 434
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 if level == 0: 466 if level == 0:
475 # outer parenthesis closed before end of expression 467 # outer parenthesis closed before end of expression
476 if tokens[i + 1][:2] != (tokenize.OP, ':'): 468 if tokens[i + 1][:2] != (tokenize.OP, ':'):
477 break 469 break
478 470
479 return [(pos, 'A111 redundant parenthesis for {} ' 471 return [(pos, 'A111 redundant parenthesis for {} '
480 'statement'.format(statement))] 472 'statement'.format(statement))]
481 473
482 return [] 474 return []
483 475
484 check_redundant_parenthesis.name = 'abp-redundant-parenthesis' 476
485 check_redundant_parenthesis.version = __version__ 477 # With flake8 3, the way the entry points are register in setup.py,
478 # they are recognized as a group, and the name and version is detected
479 # automatically. For compatibility with flake8 2, however, we need to
480 # assign the name and version to each checker individually.
481 if int(flake8.__version__.split('.')[0]) < 3:
Sebastian Noack 2017/01/12 15:55:03 We could theoretically skip this check and assign
Vasily Kuznetsov 2017/01/12 16:08:51 Acknowledged.
482 for checker in [ASTChecker, check_non_default_encoding,
483 check_quotes, check_redundant_parenthesis]:
484 checker.name = 'abp'
485 checker.version = __version__
OLDNEW
« no previous file with comments | « no previous file | flake8-abp/setup.py » ('j') | flake8-abp/tox.ini » ('J')

Powered by Google App Engine
This is Rietveld