From 3f2c1bb52932841ac0b42f5a787051707e846b8d Mon Sep 17 00:00:00 2001
From: Florin Postolache <florin.postolache.of@gmail.com>
Date: Thu, 16 May 2024 00:01:14 +0300
Subject: [PATCH] Add linter errors in checker output

Signed-off-by: Florin Postolache <florin.postolache.of@gmail.com>
---
 checker/checker.py   | 22 +++++++---------------
 src/local_checker.py | 35 +++++++++++++++++------------------
 2 files changed, 24 insertions(+), 33 deletions(-)

diff --git a/checker/checker.py b/checker/checker.py
index df6d14d..ea03218 100644
--- a/checker/checker.py
+++ b/checker/checker.py
@@ -88,24 +88,16 @@ def test_bonus():
 def run_linter():
     global points
     linter_points= 5.0
+    source_list = ['task-1/paranthesinator.asm', 'task-2/subtask_1.asm', 'task-2/subtask_2.asm', 'task-3/task_3.asm', 'bonus/functional.asm']
 
     print("======================= Linter =======================\n")
 
-    checkerOutput = str(subprocess.check_output(f"cd {linterDir} && ./linter-script-file ../task-1/paranthesinator.asm", shell=useShell), encoding='utf-8')
-    if len(checkerOutput) > 0:
-        linter_points = 0.0
-    checkerOutput = str(subprocess.check_output(f"cd {linterDir} && ./linter-script-file ../task-2/subtask_1.asm", shell=useShell), encoding='utf-8')
-    if len(checkerOutput) > 0:
-        linter_points = 0.0
-    checkerOutput = str(subprocess.check_output(f"cd {linterDir} && ./linter-script-file ../task-2/subtask_2.asm", shell=useShell), encoding='utf-8')
-    if len(checkerOutput) > 0:
-        linter_points = 0.0
-    checkerOutput = str(subprocess.check_output(f"cd {linterDir} && ./linter-script-file ../task-3/task_3.asm", shell=useShell), encoding='utf-8')
-    if len(checkerOutput) > 0:
-        linter_points = 0.0
-    checkerOutput = str(subprocess.check_output(f"cd {linterDir} && ./linter-script-file ../bonus/functional.asm", shell=useShell), encoding='utf-8')
-    if len(checkerOutput) > 0:
-        linter_points = 0.0
+    for source in source_list:
+        checkerOutput = str(subprocess.check_output(f"cd {linterDir} && ./linter-script-file ../{source}", shell=useShell), encoding='utf-8')
+        if len(checkerOutput) > 0:
+            linter_points = 0.0
+            print(f'Linter errors in: {source}')
+            print(checkerOutput)
 
     print(f"LINTER SCORE: {linter_points} / 5.00\n")
     points += linter_points
diff --git a/src/local_checker.py b/src/local_checker.py
index 4b6edd8..83e28b3 100644
--- a/src/local_checker.py
+++ b/src/local_checker.py
@@ -12,8 +12,9 @@ argParser = argparse.ArgumentParser(description="Python Checker for PCLP2 Homewo
 group = argParser.add_mutually_exclusive_group()
 group.add_argument("-t", "--task", help="Run tests for a certain task.")
 group.add_argument("--all", action="store_true", help="Run all tasks.")
-group.add_argument("--zip", action="store_true", help="Make zip file for VMChecker")
-argParser.add_argument("--no_clean", action="store_false", help="Do not clean outputs after run")
+group.add_argument("--zip", action="store_true", help="Make zip file for VMChecker.")
+group.add_argument("--linter", action="store_true", help="Run only the linter.")
+argParser.add_argument("--no_clean", action="store_false", help="Do not clean outputs after run.")
 args = argParser.parse_args()
 
 if len(sys.argv) == 1:
@@ -91,24 +92,16 @@ def test_bonus():
 def run_linter():
     global points
     linter_points= 5.0
+    source_list = ['task-1/paranthesinator.asm', 'task-2/subtask_1.asm', 'task-2/subtask_2.asm', 'task-3/task_3.asm', 'bonus/functional.asm']
 
     print("======================= Linter =======================\n")
 
-    checkerOutput = str(subprocess.check_output(f"cd {linterDir} && ./linter-script-file ../task-1/paranthesinator.asm", shell=useShell), encoding='utf-8')
-    if len(checkerOutput) > 0:
-        linter_points = 0.0
-    checkerOutput = str(subprocess.check_output(f"cd {linterDir} && ./linter-script-file ../task-2/subtask_1.asm", shell=useShell), encoding='utf-8')
-    if len(checkerOutput) > 0:
-        linter_points = 0.0
-    checkerOutput = str(subprocess.check_output(f"cd {linterDir} && ./linter-script-file ../task-2/subtask_2.asm", shell=useShell), encoding='utf-8')
-    if len(checkerOutput) > 0:
-        linter_points = 0.0
-    checkerOutput = str(subprocess.check_output(f"cd {linterDir} && ./linter-script-file ../task-3/task_3.asm", shell=useShell), encoding='utf-8')
-    if len(checkerOutput) > 0:
-        linter_points = 0.0
-    checkerOutput = str(subprocess.check_output(f"cd {linterDir} && ./linter-script-file ../bonus/functional.asm", shell=useShell), encoding='utf-8')
-    if len(checkerOutput) > 0:
-        linter_points = 0.0
+    for source in source_list:
+        checkerOutput = str(subprocess.check_output(f"cd {linterDir} && ./linter-script-file ../{source}", shell=useShell), encoding='utf-8')
+        if len(checkerOutput) > 0:
+            linter_points = 0.0
+            print(f'Linter errors in: {source}')
+            print(checkerOutput)
 
     print(f"LINTER SCORE: {linter_points} / 5.00\n")
     points += linter_points
@@ -130,9 +123,15 @@ if args.zip:
     rc = subprocess.call(f"zip -r {zipName} */*.asm README", shell=useShell)
     exit(rc)
 
+points = 0
+
+if args.linter:
+    run_linter()
+    exit(0)
+
 print("\n" + header)
 
-points = 0
+
 
 #================================ TESTS ================================#
 
-- 
GitLab