Skip to content

Commit b6e692e

Browse files
committed
report_converter: use relative file paths for testing ruff
1 parent 97d0131 commit b6e692e

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

tools/report-converter/codechecker_report_converter/analyzers/ruff/analyzer_result.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,14 @@ def get_reports(self, file_path: str) -> List[Report]:
5050
for bug in bugs:
5151
fp = bug.get('filename')
5252
if not os.path.exists(fp):
53-
LOG.warning("Source file does not exists: %s", fp)
54-
continue
53+
# Ruff uses absolute file names per default.
54+
# However, for the tests, we also try relative filenames!
55+
relative_fp = os.path.join(os.path.dirname(file_path), bug.get('filename'))
56+
if os.path.exists(relative_fp):
57+
fp = relative_fp
58+
else:
59+
LOG.warning("Source file does not exists: %s", fp)
60+
continue
5561

5662
reports.append(Report(
5763
get_or_create_file(os.path.abspath(fp), file_cache),
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# copied from pylint, could
22
all:
3-
ruff check --exit-zero --output-format=json --output-file=./simple.json files/simple.py
3+
ruff check --exit-zero --output-format=json files/simple.py | sed "s#$(PWD)/##" > simple.json

tools/report-converter/tests/unit/analyzers/ruff_output_test_files/simple.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"column": 12,
77
"row": 3
88
},
9-
"filename": "/localdata1/zoel_ml/codechecker/tools/report-converter/tests/unit/analyzers/ruff_output_test_files/files/simple.py",
9+
"filename": "files/simple.py",
1010
"fix": {
1111
"applicability": "safe",
1212
"edits": [

0 commit comments

Comments
 (0)