common_fs
¶
-
cpp_linter.common_fs.CACHE_PATH =
PosixPath('.cpp-linter_cache')
¶ A path to generated cache artifacts. (only used when verbosity is in debug mode)
-
class cpp_linter.common_fs.FileObj(name: str, additions: list[int] | None =
None
, diff_chunks: list[list[int]] | None =None
)[source]¶ A class to represent a single file being analyzed.
- Parameters:¶
- name: str¶
The file name. This should use Unix style path delimiters (
/
), even on Windows.- additions: list[int] | None =
None
¶ A
list
of line numbers that have added changes in the diff. This value is used to populate thelines_added
property.- diff_chunks: list[list[int]] | None =
None
¶ The ranges that define the beginning and ending line numbers for all hunks in the diff.
- additions : List[int]¶
A list of line numbers that contain added changes. This will be empty if not focusing on lines changed only.
- diff_chunks : List[List[int]]¶
A list of line numbers that define the beginning and ending of hunks in the diff. This will be empty if not focusing on lines changed only.
- lines_added : List[List[int]]¶
A list of line numbers that define the beginning and ending of ranges that have added changes. This will be empty if not focusing on lines changed only.
-
range_of_changed_lines(lines_changed_only: int, get_ranges: bool =
False
) list[int] | list[list[int]] [source]¶ Assemble a list of lines changed.
- Parameters:¶
- lines_changed_only: int¶
A flag to indicate the focus of certain lines.
0
: focuses on all lines in a file(s).1
: focuses on any lines shown in the event’s diff (may include unchanged lines).2
: focuses strictly on lines in the diff that contain additions.
- get_ranges: bool =
False
¶ A flag to return a list of sequences representing
range
parameters. Defaults toFalse
since this is only required when constructing clang-tidy or clang-format CLI arguments.
- Returns:¶
A list of line numbers for which to give attention. If
get_ranges
is asserted, then the returned list will be a list of ranges. Iflines_changed_only
is0
, then an empty list is returned.
- serialize() dict[str, Any] [source]¶
For easy debugging, use this method to serialize the
FileObj
into a json compatibledict
.
- is_hunk_contained(hunk: DiffHunk) tuple[int, int] | None [source]¶
Does a given
hunk
start and end within a single diff hunk?This also includes some compensations for hunk headers that are oddly formed.
Tip
This is mostly useful to create comments that can be posted within a git changes’ diff. Ideally, designed for PR reviews based on patches generated by clang tools’ output.
- is_range_contained(start: int, end: int) tuple[int, int] | None [source]¶
Does the given
start
andend
line numbers fit within a single diff hunk?This is a helper function to
is_hunk_contained()
.Tip
This is mostly useful to create comments that can be posted within a git changes’ diff. Ideally, designed for PR reviews based on patches generated by clang tools’ output.
- cpp_linter.common_fs.has_line_changes(lines_changed_only: int, diff_chunks: list[list[int]], additions: list[int]) bool [source]¶
Does this file actually apply to condition specified by
lines_changed_only
?- Parameters:¶
- lines_changed_only: int¶
A value that means:
0 = We don’t care. Analyze the whole file.
1 = Only analyze lines in the diff chunks, which may include unchanged lines but not lines with subtractions.
2 = Only analyze lines with additions.
- diff_chunks: list[list[int]]¶
The ranges of lines in the diff for a single file.
- additions: list[int]¶
The lines with additions in the diff for a single file.