mirror of
https://github.com/davidhalter/parso.git
synced 2026-01-17 08:35:20 +08:00
Move more stuff and fix tests.
This commit is contained in:
@@ -76,12 +76,12 @@ class Normalizer(use_metaclass(_NormalizerMeta)):
|
||||
@classmethod
|
||||
def register_rule(cls, **kwargs):
|
||||
"""
|
||||
Use it as a class decorator:
|
||||
Use it as a class decorator::
|
||||
|
||||
>>> normalizer = Normalizer('grammar', 'config')
|
||||
>>> @normalizer.register_rule(value='foo')
|
||||
... class MyRule(Rule):
|
||||
... error_code = 42
|
||||
normalizer = Normalizer('grammar', 'config')
|
||||
@normalizer.register_rule(value='foo')
|
||||
class MyRule(Rule):
|
||||
error_code = 42
|
||||
"""
|
||||
return cls._register_rule(**kwargs)
|
||||
|
||||
|
||||
@@ -655,13 +655,6 @@ class ErrorFinder(Normalizer):
|
||||
if not in_loop:
|
||||
message = "'continue' not properly in loop"
|
||||
self._add_syntax_error(message, leaf)
|
||||
elif leaf.value == 'break':
|
||||
in_loop = False
|
||||
for block in self.context.blocks:
|
||||
if block.type in ('for_stmt', 'while_stmt'):
|
||||
in_loop = True
|
||||
if not in_loop:
|
||||
self._add_syntax_error("'break' outside loop", leaf)
|
||||
elif leaf.value in ('yield', 'return'):
|
||||
if self.context.node.type != 'funcdef':
|
||||
self._add_syntax_error("'%s' outside function" % leaf.value, leaf.parent)
|
||||
@@ -797,7 +790,7 @@ class IndentationRule(Rule):
|
||||
|
||||
|
||||
@ErrorFinder.register_rule(value='await')
|
||||
class AwaitOutsideAsync(SyntaxRule):
|
||||
class _AwaitOutsideAsync(SyntaxRule):
|
||||
message = "'await' outside async function"
|
||||
|
||||
def is_issue(self, leaf):
|
||||
@@ -806,3 +799,15 @@ class AwaitOutsideAsync(SyntaxRule):
|
||||
def get_error_node(self, node):
|
||||
# Return the whole await statement.
|
||||
return node.parent
|
||||
|
||||
|
||||
@ErrorFinder.register_rule(value='break')
|
||||
class _BreakOutsideLoop(SyntaxRule):
|
||||
message = "'break' outside loop"
|
||||
|
||||
def is_issue(self, leaf):
|
||||
in_loop = False
|
||||
for block in self._normalizer.context.blocks:
|
||||
if block.type in ('for_stmt', 'while_stmt'):
|
||||
in_loop = True
|
||||
return not in_loop
|
||||
|
||||
@@ -712,10 +712,11 @@ class PEP8NormalizerConfig(ErrorFinderConfig):
|
||||
self.spaces_before_comment = spaces_before_comment
|
||||
|
||||
|
||||
@PEP8Normalizer.register_rule(type='endmarker')
|
||||
# TODO this is not yet ready.
|
||||
#@PEP8Normalizer.register_rule(type='endmarker')
|
||||
class BlankLineAtEnd(Rule):
|
||||
code = 392
|
||||
message = 'Blank line at end of file'
|
||||
|
||||
def check(self, leaf):
|
||||
def is_issue(self, leaf):
|
||||
return self._newline_count >= 2
|
||||
|
||||
Reference in New Issue
Block a user