clang_tools.clang_tidy

Parse output from clang-tidy’s stdout

class cpp_linter.clang_tools.clang_tidy.TidyNotification(notification_line: tuple[str, int | str, int | str, str, str, str], database: list[dict[str, str]] | None, repo_root: str)[source]

Create a object that decodes info from the clang-tidy output’s initial line that details a specific notification.

Parameters:
notification_line: tuple[str, int | str, int | str, str, str, str]

The first line in the notification parsed into a tuple of str that represent the different components of the notification’s details.

database: list[dict[str, str]] | None

The compilation database deserialized from JSON, only if --database argument points to a valid path containing a compile_commands.json file.

repo_root: str

The path that clang-tidy ran in. The notification’s file name is made relative to it.

diagnostic

The columns of the line that triggered the notification.

rationale

The rationale of the notification.

severity

The priority level of notification (warning/error).

line

The line number of the source file.

cols

The columns of the line that triggered the notification.

filename

The source filename concerning the notification.

fixit_lines : list[str]

A list of lines for the code-block in the notification.

applied_fixes : set[int]

A list of line numbers where a suggested fix was applied.

Creates a markdown link to the diagnostic documentation.

class cpp_linter.clang_tools.clang_tidy.TidyAdvice(notes: list[TidyNotification])[source]
diagnostics_in_range(start: int, end: int) → str[source]

Get a markdown formatted list of fixed diagnostics found between a start and end range of lines.

get_suggestion_help(start: int, end: int) → 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.

get_suggestions_from_patch(file_obj: FileObj, summary_only: bool, review_comments: ReviewComments, repo_root: str)[source]

Create a list of suggestions from the tool’s patched output.

Results are stored in the review_comments parameter (passed by reference). The file’s name is relative to repo_root.

cpp_linter.clang_tools.clang_tidy.tally_tidy_advice(files: list[FileObj]) → int[source]

Returns the sum of clang-format errors

cpp_linter.clang_tools.clang_tidy.run_clang_tidy(command: str, file_obj: FileObj, checks: str, lines_changed_only: int, database: str, extra_args: list[str], db_json: list[dict[str, str]] | None, tidy_review: bool, style: str, repo_root: str) → TidyAdvice[source]

Run clang-tidy on a certain file.

Parameters:
command: str

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

file_obj: FileObj

Information about the FileObj.

checks: str

The str of comma-separated regulate expressions that describe the desired clang-tidy checks to be enabled/configured.

lines_changed_only: int

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

database: str

The path to the compilation database.

extra_args: list[str]

A list of extra arguments used by clang-tidy as compiler arguments.

Note

If the list is only 1 item long and there is a space in the first item, then the list is reformed from splitting the first item by whitespace characters.

cpp-linter --extra-arg="-std=c++14 -Wall"

is equivalent to

cpp-linter --extra-arg=-std=c++14 --extra-arg=-Wall

db_json: list[dict[str, str]] | None

The compilation database deserialized from JSON, only if database parameter points to a valid path containing a compile_commands.json file.

tidy_review: bool

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

style: str

The clang-format style that clang-tidy uses to format its fixes.

repo_root: str

The path that the file’s name is relative to. clang-tidy runs in this directory.

cpp_linter.clang_tools.clang_tidy.parse_tidy_output(tidy_out: str, database: list[dict[str, str]] | None, repo_root: str) → TidyAdvice[source]

Parse clang-tidy stdout.

Parameters:
tidy_out: str

The stdout from clang-tidy.

database: list[dict[str, str]] | None

The compilation database deserialized from JSON, only if --database argument points to a valid path containing a compile_commands.json file.

repo_root: str

The path that clang-tidy ran in.