[clang] [analyzer][NFC] Simplify Analysis/csv2json.py (PR #161665)

Balazs Benics via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 2 06:28:23 PDT 2025


https://github.com/steakhal created https://github.com/llvm/llvm-project/pull/161665

None

>From 88e6a29ee76faee3626649b64a82141ee335a10e Mon Sep 17 00:00:00 2001
From: Balazs Benics <benicsbalazs at gmail.com>
Date: Thu, 2 Oct 2025 15:24:23 +0200
Subject: [PATCH] [analyzer][NFC] Simplify Analysis/csv2json.py

---
 clang/test/Analysis/csv2json.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/test/Analysis/csv2json.py b/clang/test/Analysis/csv2json.py
index 3c20d689243e7..d7fb3491f82fa 100644
--- a/clang/test/Analysis/csv2json.py
+++ b/clang/test/Analysis/csv2json.py
@@ -44,7 +44,7 @@ def csv_to_json_dict(csv_filepath):
     """
     try:
         with open(csv_filepath, "r", encoding="utf-8") as csvfile:
-            reader = csv.reader(csvfile)
+            reader = csv.reader(csvfile, skipinitialspace=True)
 
             # Read the header row (column names)
             try:
@@ -58,19 +58,19 @@ def csv_to_json_dict(csv_filepath):
                 json.dumps({}, indent=2)
                 return
 
-            other_column_names = [name.strip() for name in header[1:]]
+            header_length = len(header)
 
             data_dict = {}
 
             for row in reader:
-                if len(row) != len(header):
+                if len(row) != header_length:
                     raise csv.Error("Inconsistent CSV file")
                     exit(1)
 
                 key = row[0]
                 value_map = {}
 
-                for i, col_name in enumerate(other_column_names):
+                for i, col_name in enumerate(header[1:]):
                     # +1 to skip the first column
                     value_map[col_name] = row[i + 1].strip()
 



More information about the cfe-commits mailing list