Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ci-ignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
python_action
cpp_linter
mkdocs.yml
32 changes: 0 additions & 32 deletions .github/workflows/build-docs.bak

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/run-pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ jobs:
python3 -m pip install -r requirements.txt
- name: run pylint
run: |
pylint python_action/**
pylint cpp_linter/**
pylint setup.py
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ RUN apt-get update
RUN apt-get -y install python3-pip
# RUN python3 -m pip install --upgrade pip

COPY python_action/ pkg/python_action/
COPY cpp_linter/ pkg/cpp_linter/
COPY setup.py pkg/setup.py
RUN python3 -m pip install pkg/

# github action args use the CMD option
# See https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runsargs
# also https://docs.docker.com/engine/reference/builder/#cmd
ENTRYPOINT [ "python3", "-m", "python_action.run" ]
ENTRYPOINT [ "python3", "-m", "cpp_linter.run" ]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ jobs:
#### `tidy-checks`

- **Description**: Comma-separated list of globs with optional '-' prefix. Globs are processed in order of appearance in the list. Globs without '-' prefix add checks with matching names to the set, globs with the '-' prefix remove checks with matching names from the set of enabled checks. This option's value is appended to the value of the 'Checks' option in a .clang-tidy file (if any).
- It is possible to disable clang-tidy entirely by setting this option to '-\*'. This allows using only clang-format to lint your source files.
- Default: 'boost-\*,bugprone-\*,performance-\*,readability-\*,portability-\*,modernize-\*,clang-analyzer-\*,cppcoreguidelines-\*'

#### `repo-root`
Expand Down
24 changes: 10 additions & 14 deletions python_action/__init__.py → cpp_linter/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""The Base module of the `python_action` package. This holds the objects shared by
"""The Base module of the `cpp_linter` package. This holds the objects shared by
multiple modules."""
import io
import os
Expand All @@ -24,7 +24,7 @@
logger.debug("rich module not found")

# global constant variables
GITHUB_SHA = os.getenv("GITHUB_SHA", "95915a282b3efcad67b9ad3f95fba1501e43ab22")
GITHUB_SHA = os.getenv("GITHUB_SHA", "")
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN", os.getenv("GIT_REST_API", ""))
API_HEADERS = {
"Authorization": f"token {GITHUB_TOKEN}",
Expand Down Expand Up @@ -54,13 +54,13 @@ class GlobalParser:

tidy_notes = []
"""This can only be a `list` of type
[`TidyNotification`][python_action.clang_tidy.TidyNotification]"""
[`TidyNotification`][cpp_linter.clang_tidy.TidyNotification]"""
tidy_advice = []
"""This can only be a `list` of type
[`YMLFixit`][python_action.clang_tidy_yml.YMLFixit]"""
[`YMLFixit`][cpp_linter.clang_tidy_yml.YMLFixit]"""
format_advice = []
"""This can only be a `list` of type
[`XMLFixit`][python_action.clang_format_xml.XMLFixit]"""
[`XMLFixit`][cpp_linter.clang_format_xml.XMLFixit]"""


def get_line_cnt_from_cols(file_path: str, offset: int) -> tuple:
Expand All @@ -80,24 +80,20 @@ def get_line_cnt_from_cols(file_path: str, offset: int) -> tuple:
last_lf_pos = 0
cols = 1
file_path = file_path.replace("/", os.sep)
with io.open(file_path, "r", encoding="utf-8", newline="\n") as src_file:
src_file.seek(0, io.SEEK_END)
max_len = src_file.tell()
# logger.debug("Getting line count from %s at offset %d", file_path, offset)
with io.open(file_path, "rb") as src_file:
max_len = src_file.seek(0, io.SEEK_END)
src_file.seek(0, io.SEEK_SET)
while src_file.tell() != offset and src_file.tell() < max_len:
char = src_file.read(1)
if char == "\n":
if char == b"\n":
line_cnt += 1
last_lf_pos = src_file.tell() - 1 # -1 because LF is part of offset
if last_lf_pos + 1 > max_len:
src_file.newlines = "\r\n"
src_file.seek(0, io.SEEK_SET)
line_cnt = 1
cols = src_file.tell() - last_lf_pos
return (line_cnt, cols)


def log_response_msg():
"""Output the response buffer's message on failed request"""
"""Output the response buffer's message on a failed request."""
if Globals.response_buffer.status_code >= 400:
logger.error("response returned message: %s", Globals.response_buffer.text)
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class FormatReplacementLine:
Attributes:
line (int): The line number of where the suggestion starts
replacements (list): A list of
[`FormatReplacement`][python_action.clang_format_xml.FormatReplacement]
[`FormatReplacement`][cpp_linter.clang_format_xml.FormatReplacement]
object(s) representing suggestions.
"""

Expand All @@ -63,7 +63,7 @@ class XMLFixit:
filename (str): The source file that the suggestion concerns.
replaced_lines (list): A list of
[`FormatReplacementLine`][
python_action.clang_format_xml.FormatReplacementLine]
cpp_linter.clang_format_xml.FormatReplacementLine]
representing replacement(s) on a single line.
"""

Expand Down Expand Up @@ -118,7 +118,7 @@ def log_command(self, style: str) -> str:

def parse_format_replacements_xml(src_filename: str):
"""Parse XML output of replacements from clang-format. Output is saved to
[`format_advice`][python_action.__init__.GlobalParser.format_advice].
[`format_advice`][cpp_linter.__init__.GlobalParser.format_advice].

Args:
src_filename: The source file's name for which the contents of the xml
Expand All @@ -145,8 +145,8 @@ def parse_format_replacements_xml(src_filename: str):


def print_fixits():
"""Print all [`XMLFixit`][python_action.clang_format_xml.XMLFixit] objects in
[`format_advice`][python_action.__init__.GlobalParser.format_advice]."""
"""Print all [`XMLFixit`][cpp_linter.clang_format_xml.XMLFixit] objects in
[`format_advice`][cpp_linter.__init__.GlobalParser.format_advice]."""
for fixit in GlobalParser.format_advice:
print(repr(fixit))
for line_fix in fixit.replaced_lines:
Expand Down
30 changes: 14 additions & 16 deletions python_action/clang_tidy.py → cpp_linter/clang_tidy.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Parse output from clang-tidy's stdout"""
import os
import sys
import re
from . import GlobalParser
from . import GlobalParser # , logger

NOTE_HEADER = re.compile("^(.*):(\d+):(\d+):\s(\w+):(.*)\[(.*)\]$")

class TidyNotification:
"""Create a object that decodes info from the clang-tidy output's initial line that
Expand All @@ -20,27 +20,24 @@ class TidyNotification:
notification.
"""

def __init__(self, notification_line: str):
def __init__(self, notification_line: tuple):
"""
Args:
notification_line: The first line in the notification.
notification_line: The first line in the notification parsed into a tuple of
string that represent the different components of the notification's
details.
"""
sliced_line = notification_line.split(":")
if sys.platform.startswith("win32") and len(sliced_line) > 5:
# sliced_list items 0 & 1 are the path seperated at the ":".
# we need to re-assemble the path for correct list expansion (see below)
sliced_line = [sliced_line[0] + ":" + sliced_line[1]] + sliced_line[2:]
# logger.debug("Creating tidy note from line %s", notification_line)
(
self.filename,
self.line,
self.cols,
self.note_type,
self.note_info,
) = sliced_line
self.diagnostic,
) = notification_line

self.diagnostic = re.search("\[.*\]", self.note_info).group(0)
self.note_info = self.note_info.replace(self.diagnostic, "").strip()
self.diagnostic = self.diagnostic[1:-1]
self.note_info = self.note_info.strip()
self.note_type = self.note_type.strip()
self.line = int(self.line)
self.cols = int(self.cols)
Expand Down Expand Up @@ -90,8 +87,9 @@ def parse_tidy_output() -> None:
notification = None
with open("clang_tidy_report.txt", "r", encoding="utf-8") as tidy_out:
for line in tidy_out.readlines():
if re.search("^.*:\d+:\d+:\s\w+:.*\[.*\]$", line) is not None:
notification = TidyNotification(line)
match = re.match(NOTE_HEADER, line)
if match is not None:
notification = TidyNotification(match.groups())
GlobalParser.tidy_notes.append(notification)
elif notification is not None:
notification.fixit_lines.append(line)
Expand All @@ -100,7 +98,7 @@ def parse_tidy_output() -> None:
def print_fixits():
"""Print out all clang-tidy notifications from stdout (which are saved to
clang_tidy_report.txt and allocated to
[`tidy_notes`][python_action.__init__.GlobalParser.tidy_notes]."""
[`tidy_notes`][cpp_linter.__init__.GlobalParser.tidy_notes]."""
for notification in GlobalParser.tidy_notes:
print("found", len(GlobalParser.tidy_notes), "tidy_notes")
print(repr(notification))
Expand Down
10 changes: 5 additions & 5 deletions python_action/clang_tidy_yml.py → cpp_linter/clang_tidy_yml.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TidyDiagnostic:
cols (int): The columns of the `line` that triggered the diagnostic
null_len (int): The number of bytes replaced by suggestions
replacements (list): The `list` of
[`TidyReplacement`][python_action.clang_tidy_yml.TidyReplacement] objects.
[`TidyReplacement`][cpp_linter.clang_tidy_yml.TidyReplacement] objects.

"""

Expand Down Expand Up @@ -79,7 +79,7 @@ class YMLFixit:
Attributes:
filename (str): The source file's name concerning the suggestion.
diagnostics (list): The `list` of
[`TidyDiagnostic`][python_action.clang_tidy_yml.TidyDiagnostic] objects.
[`TidyDiagnostic`][cpp_linter.clang_tidy_yml.TidyDiagnostic] objects.
"""

def __init__(self, filename: str) -> None:
Expand All @@ -99,7 +99,7 @@ def __repr__(self) -> str:

def parse_tidy_suggestions_yml():
"""Read a YAML file from clang-tidy and create a list of suggestions from it.
Output is saved to [`tidy_advice`][python_action.__init__.GlobalParser.tidy_advice].
Output is saved to [`tidy_advice`][cpp_linter.__init__.GlobalParser.tidy_advice].
"""
yml = {}
with open("clang_tidy_output.yml", "r", encoding="utf-8") as yml_file:
Expand Down Expand Up @@ -129,8 +129,8 @@ def parse_tidy_suggestions_yml():


def print_fixits():
"""Print all [`YMLFixit`][python_action.clang_tidy_yml.YMLFixit] objects in
[`tidy_advice`][python_action.__init__.GlobalParser.tidy_advice]."""
"""Print all [`YMLFixit`][cpp_linter.clang_tidy_yml.YMLFixit] objects in
[`tidy_advice`][cpp_linter.__init__.GlobalParser.tidy_advice]."""
for fix in GlobalParser.tidy_advice:
for diag in fix.diagnostics:
print(repr(diag))
Expand Down
Loading