clang_tools.clang_format

Parse output from clang-format’s XML suggestions.

class cpp_linter.clang_tools.clang_format.FormatReplacement(cols: int, null_len: int, text: str)[source]

An object representing a single replacement.

Parameters:
cols: int

The columns number of where the suggestion starts on the line

null_len: int

The number of bytes removed by suggestion

text: str

The bytearray of the suggestion

cols

The columns number of where the suggestion starts on the line

null_len

The number of bytes removed by suggestion

text

The bytearray of the suggestion

class cpp_linter.clang_tools.clang_format.FormatReplacementLine(line_numb: int)[source]

An object that represents a replacement(s) for a single line.

Parameters:
line_numb: int

The line number of about the replacements

line

The line number of where the suggestion starts

replacements : List[FormatReplacement]

A list of FormatReplacement object(s) representing suggestions.

class cpp_linter.clang_tools.clang_format.FormatAdvice(filename: str)[source]

A single object to represent each suggestion.

Parameters:
filename: str

The source file’s name for which the contents of the xml file exported by clang-tidy.

filename

The source file that the suggestion concerns.

replaced_lines : List[FormatReplacementLine]

A list of FormatReplacementLine representing replacement(s) on a single line.

get_suggestion_help(start, end) str[source]

Create helpful text about what the suggestion aims to fix.

The parameters start and end are the line numbers (relative to file’s original content) encapsulating the suggestion.

get_tool_name() str[source]

A function that must be implemented by derivatives to get the clang tool’s name that generated the patched data.

cpp_linter.clang_tools.clang_format.tally_format_advice(files: list[FileObj]) int[source]

Returns the sum of clang-format errors

cpp_linter.clang_tools.clang_format.parse_format_replacements_xml(xml_out: str, file_obj: FileObj, lines_changed_only: int) FormatAdvice[source]

Parse XML output of replacements from clang-format.

Parameters:
xml_out: str

A string containing the XML output.

file_obj: FileObj

The source file’s info for which the contents of the xml that was exported by clang-format.

lines_changed_only: int

A flag that forces focus on only changes in the event’s diff info.

cpp_linter.clang_tools.clang_format.run_clang_format(command: str, file_obj: FileObj, style: str, lines_changed_only: int, format_review: bool) FormatAdvice[source]

Run clang-format on a certain file

Parameters:
command: str

The clang-format command to use (usually a resolved path).

file_obj: FileObj

Information about the FileObj.

style: str

The clang-format style rules to adhere. Set this to ‘file’ to use the relative-most .clang-format configuration file.

lines_changed_only: int

A flag that forces focus on only changes in the event’s diff info.

format_review: bool

A flag to enable/disable creating a diff suggestion for PR review comments.