How to use the yamllint.parser.Line function in yamllint

To help you get started, we’ve selected a few yamllint examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github adrienverge / yamllint / tests / test_parser.py View on Github external
def test_token_or_comment_or_line_generator(self):
        e = list(token_or_comment_or_line_generator('---\n'
                                                    'k: v  # k=v\n'))
        self.assertEqual(len(e), 13)
        self.assertIsInstance(e[0], Token)
        self.assertIsInstance(e[0].curr, yaml.StreamStartToken)
        self.assertIsInstance(e[1], Token)
        self.assertIsInstance(e[1].curr, yaml.DocumentStartToken)
        self.assertIsInstance(e[2], Line)
        self.assertIsInstance(e[3].curr, yaml.BlockMappingStartToken)
        self.assertIsInstance(e[4].curr, yaml.KeyToken)
        self.assertIsInstance(e[6].curr, yaml.ValueToken)
        self.assertIsInstance(e[8], Comment)
        self.assertIsInstance(e[9], Line)
        self.assertIsInstance(e[12], Line)
github adrienverge / yamllint / tests / test_parser.py View on Github external
def test_token_or_comment_or_line_generator(self):
        e = list(token_or_comment_or_line_generator('---\n'
                                                    'k: v  # k=v\n'))
        self.assertEqual(len(e), 13)
        self.assertIsInstance(e[0], Token)
        self.assertIsInstance(e[0].curr, yaml.StreamStartToken)
        self.assertIsInstance(e[1], Token)
        self.assertIsInstance(e[1].curr, yaml.DocumentStartToken)
        self.assertIsInstance(e[2], Line)
        self.assertIsInstance(e[3].curr, yaml.BlockMappingStartToken)
        self.assertIsInstance(e[4].curr, yaml.KeyToken)
        self.assertIsInstance(e[6].curr, yaml.ValueToken)
        self.assertIsInstance(e[8], Comment)
        self.assertIsInstance(e[9], Line)
        self.assertIsInstance(e[12], Line)
github adrienverge / yamllint / yamllint / parser.py View on Github external
def line_generator(buffer):
    line_no = 1
    cur = 0
    next = buffer.find('\n')
    while next != -1:
        if next > 0 and buffer[next - 1] == '\r':
            yield Line(line_no, buffer, start=cur, end=next - 1)
        else:
            yield Line(line_no, buffer, start=cur, end=next)
        cur = next + 1
        next = buffer.find('\n', cur)
        line_no += 1

    yield Line(line_no, buffer, start=cur, end=len(buffer))
github adrienverge / yamllint / yamllint / linter.py View on Github external
problem.level = rule_conf['level']
                    cache.append(problem)
        elif isinstance(elem, parser.Comment):
            for rule in comment_rules:
                rule_conf = conf.rules[rule.ID]
                for problem in rule.check(rule_conf, elem):
                    problem.rule = rule.ID
                    problem.level = rule_conf['level']
                    cache.append(problem)

            disabled.process_comment(elem)
            if elem.is_inline():
                disabled_for_line.process_comment(elem)
            else:
                disabled_for_next_line.process_comment(elem)
        elif isinstance(elem, parser.Line):
            for rule in line_rules:
                rule_conf = conf.rules[rule.ID]
                for problem in rule.check(rule_conf, elem):
                    problem.rule = rule.ID
                    problem.level = rule_conf['level']
                    cache.append(problem)

            # This is the last token/comment/line of this line, let's flush the
            # problems found (but filter them according to the directives)
            for problem in cache:
                if not (disabled_for_line.is_disabled_by_directive(problem) or
                        disabled.is_disabled_by_directive(problem)):
                    yield problem

            disabled_for_line = disabled_for_next_line
            disabled_for_next_line = DisableLineDirective()
github adrienverge / yamllint / yamllint / parser.py View on Github external
def line_generator(buffer):
    line_no = 1
    cur = 0
    next = buffer.find('\n')
    while next != -1:
        if next > 0 and buffer[next - 1] == '\r':
            yield Line(line_no, buffer, start=cur, end=next - 1)
        else:
            yield Line(line_no, buffer, start=cur, end=next)
        cur = next + 1
        next = buffer.find('\n', cur)
        line_no += 1

    yield Line(line_no, buffer, start=cur, end=len(buffer))
github nzoschke / gofaas / vendor / pip / yamllint / linter.py View on Github external
problem.level = rule_conf['level']
                    cache.append(problem)
        elif isinstance(elem, parser.Comment):
            for rule in comment_rules:
                rule_conf = conf.rules[rule.ID]
                for problem in rule.check(rule_conf, elem):
                    problem.rule = rule.ID
                    problem.level = rule_conf['level']
                    cache.append(problem)

            disabled.process_comment(elem)
            if elem.is_inline():
                disabled_for_line.process_comment(elem)
            else:
                disabled_for_next_line.process_comment(elem)
        elif isinstance(elem, parser.Line):
            for rule in line_rules:
                rule_conf = conf.rules[rule.ID]
                for problem in rule.check(rule_conf, elem):
                    problem.rule = rule.ID
                    problem.level = rule_conf['level']
                    cache.append(problem)

            # This is the last token/comment/line of this line, let's flush the
            # problems found (but filter them according to the directives)
            for problem in cache:
                if not (disabled_for_line.is_disabled_by_directive(problem) or
                        disabled.is_disabled_by_directive(problem)):
                    yield problem

            disabled_for_line = disabled_for_next_line
            disabled_for_next_line = DisableLineDirective()