예제 #1
0
    def parse(cls, raw_json: JsonObject) -> "CoreError":
        error_type = CoreErrorType(raw_json["error_type"])
        raw_rule_id = raw_json.get("rule_id")
        rule_id = RuleId(raw_rule_id) if raw_rule_id else None
        location = raw_json["location"]
        path = Path(location["path"])
        start = CoreLocation.parse(location["start"])
        end = CoreLocation.parse(location["end"])
        _extra = raw_json.get("extra", {})
        message = CoreErrorMessage(
            raw_json.get("message", "<no error message>"))
        level_str = raw_json["severity"]
        if level_str.upper() == "WARNING":
            level_str = "WARN"
        level = Level[level_str.upper()]

        details = raw_json.get("details")

        # TODO legacy support for live editor pattern parse highlighting
        spans = None
        if "yaml_path" in raw_json:
            yaml_path = tuple(raw_json["yaml_path"])
            yaml_path = yaml_path[::-1]
            spans = tuple([LegacySpan(start, end, yaml_path)])  # type: ignore

        return cls(error_type, rule_id, path, start, end, message, level,
                   spans, details)
예제 #2
0
    def parse(cls, raw_json: JsonObject) -> "CoreLocation":
        line = raw_json.get("line")
        col = raw_json.get("col")
        offset = raw_json.get("offset")

        # Please mypy
        assert isinstance(line, int)
        assert isinstance(col, int)
        assert isinstance(offset, int)

        return cls(line, col, offset)
예제 #3
0
 def parse(cls, raw_json: JsonObject) -> "CoreSkipped":
     raw_rule_id = raw_json.get("rule_id")
     rule_id = RuleId(raw_rule_id) if raw_rule_id else None
     path = Path(raw_json["path"])
     reason = SkipReason(raw_json["reason"])
     details = SkipDetails(raw_json["details"])
     return cls(rule_id, path, reason, details)
예제 #4
0
 def parse(cls, raw_json: JsonObject) -> "CoreMatch":
     rule_id = RuleId(raw_json["rule_id"])
     location = raw_json["location"]
     path_str = location["path"]
     assert isinstance(path_str, str)
     path = Path(path_str)
     start = CoreLocation.parse(location["start"])
     end = CoreLocation.parse(location["end"])
     extra = raw_json.get("extra", {})
     metavars = CoreMetavars.parse(extra.get("metavars"))
     return cls(rule_id, path, start, end, extra, metavars)
예제 #5
0
    def parse(cls, raw_json: JsonObject, rule_id: RuleId) -> "CoreTiming":
        if not raw_json:
            return cls([], [])

        target_timings = raw_json.get("targets", [])
        parsed_target_timings = []
        for obj in target_timings:
            parsed_target_timings.append(CoreTargetTiming.parse(obj, rule_id))

        parsed_rule_parse_timings = [
            CoreRuleParseTiming.parse(raw_json, rule_id)
        ]

        return cls(parsed_target_timings, parsed_rule_parse_timings)
예제 #6
0
def _show_banners(current_version: Version,
                  latest_version_object: JsonObject) -> None:  # type: ignore
    banners = latest_version_object.get("banners", [])
    for b in banners:
        try:
            show_str = b.get(
                "show_version")  # Note that b["show_version"] can be None
            show = Version(show_str) if show_str else None
            hide_str = b.get("hide_version")
            hide = Version(hide_str) if hide_str else None
        except InvalidVersion as e:
            logger.debug(f"Invalid version string: {e}")
            continue
        if (not show or current_version >= show) and (not hide or
                                                      current_version < hide):
            logger.warning("\n" + b.get("message", ""))
예제 #7
0
    def parse(cls, raw_json: JsonObject, rule_id: RuleId) -> "CoreOutput":
        parsed_errors = []
        errors = raw_json["errors"]
        for error in errors:
            parsed_errors.append(CoreError.parse(error))

        parsed_matches = []
        matches = raw_json["matches"]
        for match in matches:
            parsed_matches.append(CoreMatch.parse(match))

        parsed_skipped = []
        skipped = raw_json["skipped"]
        for skip in skipped:
            parsed_skipped.append(CoreSkipped.parse(skip))

        timings = raw_json.get("time", {})
        parsed_timings = CoreTiming.parse(
            timings, rule_id)  # For now assume only one rule run at a time

        return cls(parsed_matches, parsed_errors, parsed_skipped,
                   parsed_timings)
예제 #8
0
 def parse(cls, raw_json: JsonObject) -> "CoreMetavars":
     metavars: Dict[str, MetavarValue] = {}
     for key, value in raw_json.items():
         metavars[key] = MetavarValue.parse(value)
     return cls(metavars)