From c4c86fa0f104cecd2da55e0d6428c685323e8bda Mon Sep 17 00:00:00 2001 From: JWM Date: Tue, 14 Jan 2025 14:14:29 +0100 Subject: [PATCH 1/6] Accept line and column numbers of 0 --- src/mlx/warnings/code_quality.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/mlx/warnings/code_quality.py b/src/mlx/warnings/code_quality.py index b73f966..29aa3a1 100644 --- a/src/mlx/warnings/code_quality.py +++ b/src/mlx/warnings/code_quality.py @@ -77,8 +77,8 @@ def line(self, value): except (TypeError, ValueError): line_number = 1 - if line_number <= 0: - raise ValueError(f"Expected line number greater than 0; Got {line_number}") + if line_number < 0: + raise ValueError(f"Expected line number greater or equal than 0; Got {line_number}") self._line = line_number @property @@ -88,9 +88,8 @@ def column(self): @column.setter def column(self, value): - column_number = int(value) - if column_number <= 0: - raise ValueError(f"Expected column number greater than 0; Got {column_number}") + if column_number < 0: + raise ValueError(f"Expected column number greater or equal than 0; Got {column_number}") self._column = column_number def to_dict(self): From 55b14aaa949766bd4d108e9ab8ab22a5fa6ac903 Mon Sep 17 00:00:00 2001 From: JWM Date: Tue, 14 Jan 2025 14:16:23 +0100 Subject: [PATCH 2/6] Use try-exept to convert column value to integer; This way it accepts `-` or other invalid characters --- src/mlx/warnings/code_quality.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/mlx/warnings/code_quality.py b/src/mlx/warnings/code_quality.py index 29aa3a1..66d1d7d 100644 --- a/src/mlx/warnings/code_quality.py +++ b/src/mlx/warnings/code_quality.py @@ -88,6 +88,11 @@ def column(self): @column.setter def column(self, value): + try: + column_number = int(value) + except (TypeError, ValueError): + column_number = 1 + if column_number < 0: raise ValueError(f"Expected column number greater or equal than 0; Got {column_number}") self._column = column_number From ce054ac4ca455bd3d668bf8ab27100d69ee6cded Mon Sep 17 00:00:00 2001 From: JWM Date: Tue, 14 Jan 2025 14:17:51 +0100 Subject: [PATCH 3/6] Use only valid values of the row when joining them together --- src/mlx/warnings/polyspace_checker.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mlx/warnings/polyspace_checker.py b/src/mlx/warnings/polyspace_checker.py index 25024a0..c66d38a 100644 --- a/src/mlx/warnings/polyspace_checker.py +++ b/src/mlx/warnings/polyspace_checker.py @@ -230,7 +230,8 @@ def check(self, content): self.logger.info(f"Excluded defect with ID {content.get('id', None)!r} because the status is " "'Not a defect' or 'Justified'") else: - tab_sep_string = "\t".join(content.values()) + valid_content_values = [item or "" for item in content.values()] + tab_sep_string = "\t".join(valid_content_values) if not self._is_excluded(tab_sep_string): self.count = self.count + 1 verbose_log_msg = f"ID {content.get('id', None)!r}" From 7341919c31f3f52b21e1dbb8f3c56ed06d4d8be8 Mon Sep 17 00:00:00 2001 From: JWM Date: Tue, 14 Jan 2025 14:21:05 +0100 Subject: [PATCH 4/6] Modify some line and column numbers of Polyspace test tsv file; Correct code quality accordingly --- tests/test_in/polyspace.tsv | 6 +++--- tests/test_in/polyspace_code_quality.json | 8 ++++---- tests/test_in/polyspace_code_quality_exclude.json | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/test_in/polyspace.tsv b/tests/test_in/polyspace.tsv index b90473b..f6c18cb 100644 --- a/tests/test_in/polyspace.tsv +++ b/tests/test_in/polyspace.tsv @@ -41,7 +41,7 @@ ID Family Group Color New Check Information Function File Status Severity Commen 19351 Run-time Check Numerical Orange no Overflow dummy_function() dummy_file_name.c Justified Unset 66C8A9F4CA91263862 8 9 19355 Run-time Check Numerical Orange no Overflow dummy_function() dummy_file_name.c Unreviewed Unset 66C8A9F4CA91263962 9 10 19354 Run-time Check Numerical Orange no Overflow dummy_function() dummy_file_name.c Unreviewed Unset CC9153E995234C62C091 9 11 -19358 Run-time Check Numerical Orange no Overflow Origin: Path related issue dummy_function() dummy_file_name.c Unreviewed Unset CC9153E995234C62C0C1 8 3 +19358 Run-time Check Numerical Orange no Overflow Origin: Path related issue dummy_function() dummy_file_name.c Unreviewed Unset CC9153E995234C62C0C1 19360 Run-time Check Numerical Orange no Overflow dummy_function() dummy_file_name.c Unreviewed Unset 66C8B1F4CA91263262 8 4 19349 Run-time Check Numerical Orange no Overflow dummy_function() dummy_file_name.c Unreviewed Unset 66C8C1F4CA91263262 9 5 19345 Run-time Check Numerical Orange no Overflow dummy_function() dummy_file_name.c Unreviewed Unset 66C8C1F4CA91263470 9 6 @@ -84,9 +84,9 @@ ID Family Group Color New Check Information Function File Status Severity Commen 22051 Run-time Check Data flow Gray no Unreachable code dummy_function() dummy_file_name.c Unreviewed Unset 3166CCB155C9941C 16 12 22052 Run-time Check Data flow Gray no Unreachable code dummy_function() dummy_file_name.c Unreviewed Unset 3166CCB955C9941C 16 13 17503 Defect Concurrency Red no Data race Impact: High File Scope dummy_file_name.h Unreviewed Unset CD99338805A214EB94A0438AC8A9 15 5 -17504 Defect Concurrency Red no Data race Impact: High File Scope dummy_file_name.h Unreviewed Unset CD99378805A214EB94A0438AC8A9 15 6 +17504 Defect Concurrency Red no Data race Impact: High File Scope dummy_file_name.h Unreviewed Unset CD99378805A214EB94A0438AC8A9 15 17505 Defect Concurrency Red no Data race Impact: High File Scope dummy_file_name.c Unreviewed Unset 4C18398805A214EB94A0438AC4A9 16 7 -17506 Defect Concurrency Red no Data race Impact: High File Scope dummy_file_name.c Unreviewed Unset 668D2241A805FA2528D0A23360 16 8 +17506 Defect Concurrency Red no Data race Impact: High File Scope dummy_file_name.c Unreviewed Unset 668D2241A805FA2528D0A23360 16 - 17507 Defect Concurrency Red no Data race Impact: High File Scope dummy_file_name.h Unreviewed Unset 4E19328805A214EB94A0438AC8A1 17 9 17508 Defect Concurrency Red no Data race Impact: High File Scope dummy_file_name.h Unreviewed Unset 0E9B328805A214EB94A0438AC8A1 17 10 17509 Defect Concurrency Red no Data race Impact: High File Scope dummy_file_name.c Unreviewed Unset E6CD2241A805FA2528D0A2316A 16 11 diff --git a/tests/test_in/polyspace_code_quality.json b/tests/test_in/polyspace_code_quality.json index 29a8a49..96ed7e5 100644 --- a/tests/test_in/polyspace_code_quality.json +++ b/tests/test_in/polyspace_code_quality.json @@ -160,8 +160,8 @@ "path": "dummy_file_name.c", "positions": { "begin": { - "line": 8, - "column": 3 + "line": 1, + "column": 1 } } }, @@ -287,7 +287,7 @@ "positions": { "begin": { "line": 15, - "column": 6 + "column": 1 } } }, @@ -315,7 +315,7 @@ "positions": { "begin": { "line": 16, - "column": 8 + "column": 1 } } }, diff --git a/tests/test_in/polyspace_code_quality_exclude.json b/tests/test_in/polyspace_code_quality_exclude.json index 0da2640..afdeebb 100644 --- a/tests/test_in/polyspace_code_quality_exclude.json +++ b/tests/test_in/polyspace_code_quality_exclude.json @@ -49,7 +49,7 @@ "positions": { "begin": { "line": 15, - "column": 6 + "column": 1 } } }, @@ -77,7 +77,7 @@ "positions": { "begin": { "line": 16, - "column": 8 + "column": 1 } } }, From 57f63d32a60a53383a0f538e6d958c91bce67563 Mon Sep 17 00:00:00 2001 From: JWM Date: Tue, 14 Jan 2025 14:32:52 +0100 Subject: [PATCH 5/6] Line and column numbers are 1-based --- src/mlx/warnings/code_quality.py | 13 ++++++++----- tests/test_in/polyspace.tsv | 4 ++-- tests/test_in/polyspace_code_quality.json | 4 ++-- tests/test_in/polyspace_code_quality_exclude.json | 4 ++-- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/mlx/warnings/code_quality.py b/src/mlx/warnings/code_quality.py index 66d1d7d..af3a7b0 100644 --- a/src/mlx/warnings/code_quality.py +++ b/src/mlx/warnings/code_quality.py @@ -76,9 +76,10 @@ def line(self, value): line_number = int(value) except (TypeError, ValueError): line_number = 1 - - if line_number < 0: - raise ValueError(f"Expected line number greater or equal than 0; Got {line_number}") + if line_number == 0: + line_number += 1 + elif line_number < 0: + raise ValueError(f"Expected line number greater than 0; Got {line_number}") self._line = line_number @property @@ -93,8 +94,10 @@ def column(self, value): except (TypeError, ValueError): column_number = 1 - if column_number < 0: - raise ValueError(f"Expected column number greater or equal than 0; Got {column_number}") + if column_number == 0: + column_number += 1 + elif column_number < 0: + raise ValueError(f"Expected column number greater than 0; Got {column_number}") self._column = column_number def to_dict(self): diff --git a/tests/test_in/polyspace.tsv b/tests/test_in/polyspace.tsv index f6c18cb..406a71d 100644 --- a/tests/test_in/polyspace.tsv +++ b/tests/test_in/polyspace.tsv @@ -89,11 +89,11 @@ ID Family Group Color New Check Information Function File Status Severity Commen 17506 Defect Concurrency Red no Data race Impact: High File Scope dummy_file_name.c Unreviewed Unset 668D2241A805FA2528D0A23360 16 - 17507 Defect Concurrency Red no Data race Impact: High File Scope dummy_file_name.h Unreviewed Unset 4E19328805A214EB94A0438AC8A1 17 9 17508 Defect Concurrency Red no Data race Impact: High File Scope dummy_file_name.h Unreviewed Unset 0E9B328805A214EB94A0438AC8A1 17 10 -17509 Defect Concurrency Red no Data race Impact: High File Scope dummy_file_name.c Unreviewed Unset E6CD2241A805FA2528D0A2316A 16 11 +17509 Defect Concurrency Red no Data race Impact: High File Scope dummy_file_name.c Unreviewed Unset E6CD2241A805FA2528D0A2316A 0 11 17510 Defect Concurrency Red no Data race Impact: High File Scope dummy_file_name.c Unreviewed Unset 27CD2241A805FA2528D0A2316C 16 12 17511 Defect Concurrency Red no Data race Impact: High File Scope dummy_file_name.c Unreviewed Unset A60C2241A805FA2528D0A2316A 17 13 17512 Defect Concurrency Red no Data race Impact: High File Scope dummy_file_name.c Unreviewed Unset 86CC2241A805FA2528D0A2316C 17 14 -17513 Defect Concurrency Red no Data race Impact: High File Scope dummy_file_name.c Unreviewed Unset 534611A054827D921468511C 18 5 +17513 Defect Concurrency Red no Data race Impact: High File Scope dummy_file_name.c Unreviewed Unset 534611A054827D921468511C 18 0 17514 Defect Concurrency Red no Data race Impact: High File Scope dummy_file_name.c Unreviewed Unset 070C2241A805FA2528D0A2326A 18 6 17515 Defect Concurrency Red no Data race Impact: High File Scope dummy_file_name.h Unreviewed Unset CD1A378805A214EB94A0438AC8A9 17 6 17516 Defect Concurrency Red no Data race Impact: High File Scope dummy_file_name.c Unreviewed Unset 864E2241A805FA2528D0A23268 17 7 diff --git a/tests/test_in/polyspace_code_quality.json b/tests/test_in/polyspace_code_quality.json index 96ed7e5..5587bd2 100644 --- a/tests/test_in/polyspace_code_quality.json +++ b/tests/test_in/polyspace_code_quality.json @@ -356,7 +356,7 @@ "path": "dummy_file_name.c", "positions": { "begin": { - "line": 16, + "line": 1, "column": 11 } } @@ -413,7 +413,7 @@ "positions": { "begin": { "line": 18, - "column": 5 + "column": 1 } } }, diff --git a/tests/test_in/polyspace_code_quality_exclude.json b/tests/test_in/polyspace_code_quality_exclude.json index afdeebb..8940507 100644 --- a/tests/test_in/polyspace_code_quality_exclude.json +++ b/tests/test_in/polyspace_code_quality_exclude.json @@ -118,7 +118,7 @@ "path": "dummy_file_name.c", "positions": { "begin": { - "line": 16, + "line": 1, "column": 11 } } @@ -175,7 +175,7 @@ "positions": { "begin": { "line": 18, - "column": 5 + "column": 1 } } }, From 84eb6962926daae5669d58059390f81f2229aac4 Mon Sep 17 00:00:00 2001 From: Jasper Craeghs <28319872+JasperCraeghs@users.noreply.github.com> Date: Tue, 14 Jan 2025 15:33:01 +0100 Subject: [PATCH 6/6] Apply suggestions from code review --- src/mlx/warnings/code_quality.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mlx/warnings/code_quality.py b/src/mlx/warnings/code_quality.py index af3a7b0..722eab7 100644 --- a/src/mlx/warnings/code_quality.py +++ b/src/mlx/warnings/code_quality.py @@ -77,7 +77,7 @@ def line(self, value): except (TypeError, ValueError): line_number = 1 if line_number == 0: - line_number += 1 + line_number = 1 elif line_number < 0: raise ValueError(f"Expected line number greater than 0; Got {line_number}") self._line = line_number @@ -95,7 +95,7 @@ def column(self, value): column_number = 1 if column_number == 0: - column_number += 1 + column_number = 1 elif column_number < 0: raise ValueError(f"Expected column number greater than 0; Got {column_number}") self._column = column_number