Skip to content

Commit d9baac4

Browse files
committed
fix: address SonarQube code quality issues
1 parent 02c7495 commit d9baac4

17 files changed

Lines changed: 39 additions & 41 deletions

File tree

.github/workflows/cd.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# .github/workflows/cd.yml
22
name: treemapper CD
33

4-
permissions:
5-
contents: write
4+
permissions: {}
65

76
'on':
87
workflow_dispatch:
@@ -316,6 +315,8 @@ jobs:
316315
(needs.publish-to-pypi.result == 'success' ||
317316
needs.publish-to-pypi.result == 'skipped')
318317
runs-on: ubuntu-latest
318+
permissions:
319+
contents: write
319320
steps:
320321
- name: Download git bundle
321322
uses: actions/download-artifact@v7

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ name: treemapper CI
33

44
permissions:
55
contents: read
6-
security-events: write # For CodeQL
76

87
'on':
98
pull_request:

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ dev = [
159159
"twine>=4.0,<7.0",
160160
"pyinstaller>=5.0,<7.0",
161161
# Security fixes
162-
"urllib3>=2.6.0",
162+
"urllib3>=2.6.3",
163+
"filelock>=3.20.3",
163164
]
164165

165166
[tool.setuptools.dynamic]

src/treemapper/cli.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,19 @@ def _resolve_root_dir(directory: str) -> Path:
5757

5858

5959
def _resolve_output_file(output_file_arg: str | None, output_format: str) -> tuple[Path | None, bool]:
60-
force_stdout = output_file_arg == "-"
61-
if output_file_arg is None or output_file_arg == "-":
62-
return None, force_stdout
60+
if output_file_arg is None:
61+
return None, False
62+
if output_file_arg == "-":
63+
return None, True
6364

6465
if output_file_arg == "":
6566
ext = "yaml" if output_format == "yaml" else output_format
66-
return Path(f"tree.{ext}").resolve(), force_stdout
67+
return Path(f"tree.{ext}").resolve(), False
6768

6869
output_file = Path(output_file_arg).resolve()
6970
if output_file.is_dir():
7071
_exit_error(f"'{output_file_arg}' is a directory, not a file.")
71-
return output_file, force_stdout
72+
return output_file, False
7273

7374

7475
def _resolve_ignore_file(ignore_file_arg: str | None) -> Path | None:

src/treemapper/diffctx/edges/config/build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
_CMAKE_SET_RE = re.compile(r"set\s*\(\s*([A-Z_][A-Z0-9_]*)", re.IGNORECASE)
2626

2727
_SCRIPT_CALL_RE = re.compile(r"(?:bash|sh|python|python3|\.\/scripts\/|\.\/bin\/)([a-zA-Z0-9_.-]+)")
28-
_SOURCE_FILE_RE = re.compile(r"\b([a-zA-Z_][a-zA-Z0-9_]*\.(?:c|cpp|cc|cxx|h|hpp|hxx|py|sh|go|rs|java))\b")
28+
_SOURCE_FILE_RE = re.compile(r"\b([a-zA-Z_]\w*\.(?:c|cpp|cc|cxx|h|hpp|hxx|py|sh|go|rs|java))\b")
2929

3030

3131
def _is_makefile(path: Path) -> bool:

src/treemapper/diffctx/edges/config/cicd.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,11 @@
77
from ..base import EdgeBuilder, EdgeDict, FragmentIndex, discover_files_by_refs
88

99
_GHA_RUN_RE = re.compile(r"^\s*-?\s*run:\s*[|>]?\s*(.+?)(?:\n\s{4,}|\n[^\s]|$)", re.MULTILINE | re.DOTALL)
10-
_GHA_USES_RE = re.compile(r"^\s*uses:\s*([^\s@]+)", re.MULTILINE)
11-
_GHA_WITH_RE = re.compile(r"^\s*with:\s*\n((?:\s+\w+:.+\n)+)", re.MULTILINE)
1210

1311
_GITLAB_SCRIPT_RE = re.compile(r"^\s*(?:script|before_script|after_script):\s*\n((?:\s+-\s*.+\n)+)", re.MULTILINE)
1412
_GITLAB_INCLUDE_RE = re.compile(r"^\s*-?\s*(?:local|project|remote|template):\s*['\"]?([^'\"#\n]+)", re.MULTILINE)
15-
_GITLAB_EXTENDS_RE = re.compile(r"^\s*extends:\s*['\"]?([^'\"#\n]+)", re.MULTILINE)
1613

17-
_JENKINS_STAGE_RE = re.compile(r"stage\s*\(\s*['\"]([^'\"]+)['\"]", re.MULTILINE)
18-
_JENKINS_SH_RE = re.compile(r"sh\s*(?:\(['\"]|['\"])(.+?)(?:['\"](?:\))?)", re.MULTILINE | re.DOTALL)
14+
_JENKINS_SH_RE = re.compile(r"sh\s*(?:\(['\"]|['\"])(.+?)(?:['\"])\)?", re.MULTILINE | re.DOTALL)
1915
_JENKINS_SCRIPT_RE = re.compile(r"script\s*\{([^}]+)\}", re.MULTILINE | re.DOTALL)
2016

2117
_SCRIPT_CALL_RE = re.compile(r"(?:bash|sh|python|python3|node|npm|yarn|pnpm|make|go|cargo|dotnet|mvn|gradle)\s+([^\s;&|]+)")

src/treemapper/diffctx/edges/semantic/c_family.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
_NAMESPACE_RE = re.compile(r"^\s*namespace\s+(\w+)", re.MULTILINE)
3131

3232
_FUNC_CALL_RE = re.compile(r"\b(\w+)\s*\(")
33-
_TYPE_REF_RE = re.compile(r"\b([A-Z][A-Za-z0-9_]*)\b")
33+
_TYPE_REF_RE = re.compile(r"\b([A-Z]\w*)\b")
3434

3535
_METHOD_IMPL_RE = re.compile(r"^\s*(?:[\w:]+\s+)?(\w+)::(\w+)\s*\(", re.MULTILINE)
3636

src/treemapper/diffctx/edges/semantic/dotnet.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@
2020
_CS_INHERIT_RE = re.compile(r"(?:class|interface|struct|record)\s+\w+\s*(?:<[^>]+>)?\s*:\s*([A-Z]\w*(?:\s*,\s*[A-Z]\w*)*)")
2121
_CS_GENERIC_RE = re.compile(r"<([A-Z]\w*(?:\s*,\s*[A-Z]\w*)*)>")
2222
_CS_METHOD_RE = re.compile(
23-
r"^\s*(?:public|private|protected|internal)?\s*(?:static|virtual|override|abstract|async)?\s*(?:[A-Z]\w*(?:<[^>]+>)?)\s+([A-Z][a-zA-Z0-9_]*)\s*\(",
23+
r"^\s*(?:public|private|protected|internal)?\s*(?:static|virtual|override|abstract|async)?\s*(?:[A-Z]\w*(?:<[^>]+>)?)\s+([A-Z]\w*)\s*\(",
2424
re.MULTILINE,
2525
)
2626

2727
_FS_OPEN_RE = re.compile(r"^\s*open\s+([A-Z][a-zA-Z0-9_.]*)", re.MULTILINE)
2828
_FS_MODULE_RE = re.compile(r"^\s*module\s+(?:rec\s+)?([A-Z][a-zA-Z0-9_.]*)", re.MULTILINE)
2929
_FS_NAMESPACE_RE = re.compile(r"^\s*namespace\s+(?:rec\s+)?([A-Z][a-zA-Z0-9_.]*)", re.MULTILINE)
3030
_FS_TYPE_RE = re.compile(r"^\s*type\s+(?:private\s+)?([A-Z]\w*)", re.MULTILINE)
31-
_FS_LET_RE = re.compile(r"^\s*let\s+(?:rec\s+)?(?:private\s+)?([a-z][a-zA-Z0-9_]*)", re.MULTILINE)
31+
_FS_LET_RE = re.compile(r"^\s*let\s+(?:rec\s+)?(?:private\s+)?([a-z]\w*)", re.MULTILINE)
3232

33-
_TYPE_REF_RE = re.compile(r"(?<![a-z_])([A-Z][a-zA-Z0-9_]*)\b")
34-
_ATTRIBUTE_RE = re.compile(r"\[([A-Z][a-zA-Z0-9_]*)\]")
33+
_TYPE_REF_RE = re.compile(r"(?<![a-z_])([A-Z]\w*)\b")
34+
_ATTRIBUTE_RE = re.compile(r"\[([A-Z]\w*)\]")
3535

3636

3737
def _is_dotnet_file(path: Path) -> bool:

src/treemapper/diffctx/edges/semantic/go.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
_GO_CONST_VAR_RE = re.compile(r"^(?:const|var)\s+(\w+)\s+", re.MULTILINE)
1717

1818
_GO_FUNC_CALL_RE = re.compile(r"\b([A-Z]\w+)\s*\(")
19-
_GO_TYPE_REF_RE = re.compile(r"\*?([A-Z][a-zA-Z0-9]*)\b")
19+
_GO_TYPE_REF_RE = re.compile(r"\*?([A-Z]\w*)\b")
2020
_GO_PKG_CALL_RE = re.compile(r"\b(\w+)\.([A-Z]\w*)")
2121

2222

src/treemapper/diffctx/edges/semantic/jvm.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626
re.MULTILINE,
2727
)
2828
_KOTLIN_FUN_RE = re.compile(
29-
r"^\s*(?:public|private|internal|protected)?\s*(?:suspend\s+)?fun\s+(?:<[^>]+>\s+)?([a-z][a-zA-Z0-9_]*)", re.MULTILINE
29+
r"^\s*(?:public|private|internal|protected)?\s*(?:suspend\s+)?fun\s+(?:<[^>]+>\s+)?([a-z]\w*)", re.MULTILINE
3030
)
3131

3232
_SCALA_IMPORT_RE = re.compile(r"^\s*import\s+([a-z][a-z0-9_]*(?:\.[a-z][a-z0-9_]*)*(?:\.[A-Z_]\w*)?)", re.MULTILINE)
3333
_SCALA_CLASS_RE = re.compile(r"^\s*(?:abstract\s+)?(?:sealed\s+)?(?:case\s+)?(?:class|trait|object)\s+([A-Z]\w*)", re.MULTILINE)
34-
_SCALA_DEF_RE = re.compile(r"^\s*(?:private|protected)?\s*def\s+([a-z][a-zA-Z0-9_]*)", re.MULTILINE)
34+
_SCALA_DEF_RE = re.compile(r"^\s*(?:private|protected)?\s*def\s+([a-z]\w*)", re.MULTILINE)
3535

36-
_TYPE_REF_RE = re.compile(r"(?<![a-z_])([A-Z][a-zA-Z0-9_]*)\b")
37-
_ANNOTATION_RE = re.compile(r"@([A-Z][a-zA-Z0-9_]*)")
36+
_TYPE_REF_RE = re.compile(r"(?<![a-z_])([A-Z]\w*)\b")
37+
_ANNOTATION_RE = re.compile(r"@([A-Z]\w*)")
3838

3939

4040
def _is_jvm_file(path: Path) -> bool:

0 commit comments

Comments
 (0)