Esempio n. 1
0
def check(conf, token, prev, next, nextnext, context):
    if isinstance(token, yaml.ValueToken):
        problem = spaces_before(token,
                                prev,
                                next,
                                max=conf['max-spaces-before'],
                                max_desc='too many spaces before colon')
        if problem is not None:
            yield problem

        problem = spaces_after(token,
                               prev,
                               next,
                               max=conf['max-spaces-after'],
                               max_desc='too many spaces after colon')
        if problem is not None:
            yield problem

    if isinstance(token, yaml.KeyToken) and is_explicit_key(token):
        problem = spaces_after(token,
                               prev,
                               next,
                               max=conf['max-spaces-after'],
                               max_desc='too many spaces after question mark')
        if problem is not None:
            yield problem
Esempio n. 2
0
def check(conf, token, prev, next, nextnext, context):
    if (isinstance(token, yaml.FlowMappingStartToken) and
            isinstance(next, yaml.FlowMappingEndToken)):
        problem = spaces_after(token, prev, next,
                               min=(conf['min-spaces-inside-empty']
                                    if conf['min-spaces-inside-empty'] != -1
                                    else conf['min-spaces-inside']),
                               max=(conf['max-spaces-inside-empty']
                                    if conf['max-spaces-inside-empty'] != -1
                                    else conf['max-spaces-inside']),
                               min_desc='too few spaces inside empty braces',
                               max_desc='too many spaces inside empty braces')
        if problem is not None:
            yield problem

    elif isinstance(token, yaml.FlowMappingStartToken):
        problem = spaces_after(token, prev, next,
                               min=conf['min-spaces-inside'],
                               max=conf['max-spaces-inside'],
                               min_desc='too few spaces inside braces',
                               max_desc='too many spaces inside braces')
        if problem is not None:
            yield problem

    elif (isinstance(token, yaml.FlowMappingEndToken) and
            (prev is None or
             not isinstance(prev, yaml.FlowMappingStartToken))):
        problem = spaces_before(token, prev, next,
                                min=conf['min-spaces-inside'],
                                max=conf['max-spaces-inside'],
                                min_desc='too few spaces inside braces',
                                max_desc='too many spaces inside braces')
        if problem is not None:
            yield problem
Esempio n. 3
0
def check(conf, token, prev, next, nextnext, context):
    if (conf['forbid'] is True
            and isinstance(token, yaml.FlowSequenceStartToken)):
        yield LintProblem(token.start_mark.line + 1, token.end_mark.column + 1,
                          'forbidden flow sequence')

    elif (conf['forbid'] == 'non-empty'
          and isinstance(token, yaml.FlowSequenceStartToken)
          and not isinstance(next, yaml.FlowSequenceEndToken)):
        yield LintProblem(token.start_mark.line + 1, token.end_mark.column + 1,
                          'forbidden flow sequence')

    elif (isinstance(token, yaml.FlowSequenceStartToken)
          and isinstance(next, yaml.FlowSequenceEndToken)):
        problem = spaces_after(token,
                               prev,
                               next,
                               min=(conf['min-spaces-inside-empty']
                                    if conf['min-spaces-inside-empty'] != -1
                                    else conf['min-spaces-inside']),
                               max=(conf['max-spaces-inside-empty']
                                    if conf['max-spaces-inside-empty'] != -1
                                    else conf['max-spaces-inside']),
                               min_desc='too few spaces inside empty brackets',
                               max_desc=('too many spaces inside empty '
                                         'brackets'))
        if problem is not None:
            yield problem

    elif isinstance(token, yaml.FlowSequenceStartToken):
        problem = spaces_after(token,
                               prev,
                               next,
                               min=conf['min-spaces-inside'],
                               max=conf['max-spaces-inside'],
                               min_desc='too few spaces inside brackets',
                               max_desc='too many spaces inside brackets')
        if problem is not None:
            yield problem

    elif (isinstance(token, yaml.FlowSequenceEndToken) and
          (prev is None or not isinstance(prev, yaml.FlowSequenceStartToken))):
        problem = spaces_before(token,
                                prev,
                                next,
                                min=conf['min-spaces-inside'],
                                max=conf['max-spaces-inside'],
                                min_desc='too few spaces inside brackets',
                                max_desc='too many spaces inside brackets')
        if problem is not None:
            yield problem
Esempio n. 4
0
def check(conf, token, prev, next, nextnext, context):
    if isinstance(token, yaml.BlockEntryToken):
        problem = spaces_after(token, prev, next,
                               max=conf['max-spaces-after'],
                               max_desc='too many spaces after hyphen')
        if problem is not None:
            yield problem
Esempio n. 5
0
def check(conf, token, prev, next, nextnext, context):
    if isinstance(token, yaml.FlowEntryToken):
        if (prev is not None and conf['max-spaces-before'] != -1
                and prev.end_mark.line < token.start_mark.line):
            yield LintProblem(token.start_mark.line + 1,
                              max(1, token.start_mark.column),
                              'too many spaces before comma')
        else:
            problem = spaces_before(token,
                                    prev,
                                    next,
                                    max=conf['max-spaces-before'],
                                    max_desc='too many spaces before comma')
            if problem is not None:
                yield problem

        problem = spaces_after(token,
                               prev,
                               next,
                               min=conf['min-spaces-after'],
                               max=conf['max-spaces-after'],
                               min_desc='too few spaces after comma',
                               max_desc='too many spaces after comma')
        if problem is not None:
            yield problem
Esempio n. 6
0
def check(conf, token, prev, next, nextnext, context):
    if isinstance(token, yaml.ValueToken):
        problem = spaces_before(token, prev, next,
                                max=conf['max-spaces-before'],
                                max_desc='too many spaces before colon')
        if problem is not None:
            yield problem

        problem = spaces_after(token, prev, next,
                               max=conf['max-spaces-after'],
                               max_desc='too many spaces after colon')
        if problem is not None:
            yield problem

    if isinstance(token, yaml.KeyToken) and is_explicit_key(token):
        problem = spaces_after(token, prev, next,
                               max=conf['max-spaces-after'],
                               max_desc='too many spaces after question mark')
        if problem is not None:
            yield problem
Esempio n. 7
0
def check(conf, token, prev, next, nextnext, context):
    if isinstance(token, yaml.FlowSequenceStartToken):
        problem = spaces_after(token, prev, next,
                               min=conf['min-spaces-inside'],
                               max=conf['max-spaces-inside'],
                               min_desc='too few spaces inside brackets',
                               max_desc='too many spaces inside brackets')
        if problem is not None:
            yield problem

    elif (isinstance(token, yaml.FlowSequenceEndToken) and
            (prev is None or
             not isinstance(prev, yaml.FlowSequenceStartToken))):
        problem = spaces_before(token, prev, next,
                                min=conf['min-spaces-inside'],
                                max=conf['max-spaces-inside'],
                                min_desc='too few spaces inside brackets',
                                max_desc='too many spaces inside brackets')
        if problem is not None:
            yield problem
Esempio n. 8
0
def check(conf, token, prev, next, nextnext, context):
    if isinstance(token, yaml.FlowEntryToken):
        if (prev is not None and conf['max-spaces-before'] != -1 and
                prev.end_mark.line < token.start_mark.line):
            yield LintProblem(token.start_mark.line + 1,
                              max(1, token.start_mark.column),
                              'too many spaces before comma')
        else:
            problem = spaces_before(token, prev, next,
                                    max=conf['max-spaces-before'],
                                    max_desc='too many spaces before comma')
            if problem is not None:
                yield problem

        problem = spaces_after(token, prev, next,
                               min=conf['min-spaces-after'],
                               max=conf['max-spaces-after'],
                               min_desc='too few spaces after comma',
                               max_desc='too many spaces after comma')
        if problem is not None:
            yield problem
Esempio n. 9
0
def check(conf, token, prev, next, nextnext, context):
    if isinstance(token, yaml.FlowSequenceStartToken):
        problem = spaces_after(token,
                               prev,
                               next,
                               min=conf['min-spaces-inside'],
                               max=conf['max-spaces-inside'],
                               min_desc='too few spaces inside brackets',
                               max_desc='too many spaces inside brackets')
        if problem is not None:
            yield problem

    elif (isinstance(token, yaml.FlowSequenceEndToken) and
          (prev is None or not isinstance(prev, yaml.FlowSequenceStartToken))):
        problem = spaces_before(token,
                                prev,
                                next,
                                min=conf['min-spaces-inside'],
                                max=conf['max-spaces-inside'],
                                min_desc='too few spaces inside brackets',
                                max_desc='too many spaces inside brackets')
        if problem is not None:
            yield problem