コード例 #1
0
    def matchyaml(self, file: Lintable) -> List["MatchError"]:
        """Return matches found for a specific YAML text."""
        matches: List["MatchError"] = []
        filtered_matches: List["MatchError"] = []
        if file.base_kind != 'text/yaml':
            return matches

        if YamllintRule.config:
            for p in run_yamllint(file.content,
                                  YamllintRule.config,
                                  filepath=file.path):
                self.severity = 'VERY_LOW'
                if p.level == "error":
                    self.severity = 'MEDIUM'
                if p.desc.endswith("(syntax)"):
                    self.severity = 'VERY_HIGH'
                matches.append(
                    self.create_matcherror(
                        message=p.desc,
                        linenumber=p.line,
                        details="",
                        filename=str(file.path),
                        tag=p.rule,
                    ))

        if matches:
            lines = file.content.splitlines()
            for match in matches:
                # rule.linenumber starts with 1, not zero
                skip_list = get_rule_skips_from_line(lines[match.linenumber -
                                                           1])
                # print(skip_list)
                if match.rule.id not in skip_list and match.tag not in skip_list:
                    filtered_matches.append(match)
        return filtered_matches
コード例 #2
0
    def matchyaml(self, file: Lintable) -> List["MatchError"]:
        """Return matches found for a specific YAML text."""
        matches: List["MatchError"] = []
        filtered_matches = []
        if file.kind == 'role':
            return matches

        if YamllintRule.config:
            for p in run_yamllint(file.content, YamllintRule.config):
                matches.append(
                    self.create_matcherror(
                        message=p.desc,
                        linenumber=p.line,
                        details="",
                        filename=str(file.path),
                        tag=p.rule,
                    )
                )

        if matches:
            lines = file.content.splitlines()
            for match in matches:
                # rule.linenumber starts with 1, not zero
                skip_list = get_rule_skips_from_line(lines[match.linenumber - 1])
                # print(skip_list)
                if match.rule.id not in skip_list and match.tag not in skip_list:
                    filtered_matches.append(match)
        return filtered_matches