Beispiel #1
0
def format_violation(violation, max_line_length=90):
    """Format a violation."""
    if isinstance(violation, SQLBaseError):
        code, line, pos, desc = violation.get_info_tuple()
        if line is not None:
            line_elem = "{0:4d}".format(line)
        else:
            line_elem = "   -"
        if pos is not None:
            pos_elem = "{0:4d}".format(pos)
        else:
            pos_elem = "   -"
    else:
        raise ValueError("Unexpected violation format: {0}".format(violation))

    if violation.ignore:
        desc = "IGNORE: " + desc

    split_desc = split_string_on_spaces(desc, line_length=max_line_length - 25)

    out_buff = ""
    for idx, line in enumerate(split_desc):
        if idx == 0:
            out_buff += colorize(
                "L:{0} | P:{1} | {2} | ".format(line_elem, pos_elem,
                                                code.rjust(4)),
                # Grey out the violation if we're ignoring it.
                "lightgrey" if violation.ignore else "blue",
            )
        else:
            out_buff += (
                "\n" + (" " * 23) +
                colorize("| ", "lightgrey" if violation.ignore else "blue"))
        out_buff += line
    return out_buff
Beispiel #2
0
def format_violation(violation, max_line_length=90):
    """Format a violation."""
    if isinstance(violation, SQLBaseError):
        desc = violation.desc()
        if violation.line_no is not None:
            line_elem = f"{violation.line_no:4d}"
        else:
            line_elem = "   -"  # pragma: no cover
        if violation.line_pos is not None:
            pos_elem = f"{violation.line_pos:4d}"
        else:
            pos_elem = "   -"  # pragma: no cover
    else:  # pragma: no cover
        raise ValueError(f"Unexpected violation format: {violation}")

    if violation.ignore:
        desc = "IGNORE: " + desc  # pragma: no cover

    split_desc = split_string_on_spaces(desc, line_length=max_line_length - 25)

    out_buff = ""
    for idx, line in enumerate(split_desc):
        if idx == 0:
            out_buff += colorize(
                "L:{} | P:{} | {} | ".format(line_elem, pos_elem,
                                             violation.rule_code().rjust(4)),
                # Grey out the violation if we're ignoring it.
                "lightgrey" if violation.ignore else "blue",
            )
        else:
            out_buff += (
                "\n" + (" " * 23) +
                colorize("| ", "lightgrey" if violation.ignore else "blue"))
        out_buff += line
    return out_buff
Beispiel #3
0
def format_filename(filename, success=False, success_text="PASS"):
    """Format filenames."""
    if isinstance(success, str):
        status_string = success
    else:
        status_string = colorize(success_text if success else "FAIL",
                                 "green" if success else "red")
    return "== [" + colorize(f"{filename}", "lightgrey") + "] " + status_string
Beispiel #4
0
def format_dialect_warning():
    """Output a warning for parsing errors found on the ansi dialect."""
    return colorize(
        ("WARNING: Parsing errors found and dialect is set to "
         "'ansi'. Have you configured your dialect?"),
        "lightgrey",
    )
Beispiel #5
0
def format_config_vals(config_vals):
    """Format an iterable of config values from a config object."""
    text_buffer = StringIO()
    for i, k, v in config_vals:
        val = "" if v is None else str(v)
        text_buffer.write(("    " * i) + colorize(
            pad_line(str(k) + ":", 20, "left"), color=Color.lightgrey) +
                          pad_line(val, 20, "left") + "\n")
    return text_buffer.getvalue()
Beispiel #6
0
def format_filename(filename: str,
                    success: Union[str, bool] = False,
                    success_text: str = "PASS") -> str:
    """Format filenames."""
    if isinstance(success, str):
        status_string = success
    else:
        status_string = colorize(
            success_text if success else "FAIL",
            Color.green if success else Color.red,
        )
    return f"== [{colorize(filename, Color.lightgrey)}] {status_string}"
Beispiel #7
0
def test__cli__helpers__colorize():
    """Test ANSI colouring."""
    assert colorize("foo", "red") == u"\u001b[31mfoo\u001b[0m"
Beispiel #8
0
 def _format_path(path):
     """Format paths."""
     return "=== [ path: {0} ] ===\n".format(colorize(path, "lightgrey"))
Beispiel #9
0
 def dispatch_compilation_header(self, templater, message):
     """Dispatch the header displayed before linting."""
     self._dispatch("=== [" + colorize(templater, "lightgrey") + "] " +
                    message)
Beispiel #10
0
def test__cli__helpers__colorize():
    assert colorize('foo', 'red') == u"\u001b[31mfoo\u001b[0m"
Beispiel #11
0
def test__cli__helpers__colorize():
    """Test ANSI colouring."""
    assert colorize('foo', 'red') == u"\u001b[31mfoo\u001b[0m"