From 7ac6f905aee9e304067257c9b854fc19faee5103 Mon Sep 17 00:00:00 2001 From: willeand <eandwse@gmail.com> Date: Sun, 5 May 2024 22:59:35 -0700 Subject: [PATCH] this adds the errors into a single datastructure before converting to JSON --- output/data.json | 2 +- src/extension.ts | 5 ++++- src/singleStatementPerLineChecker.ts | 30 +++++++++++++++++----------- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/output/data.json b/output/data.json index c978688..7c899fe 100644 --- a/output/data.json +++ b/output/data.json @@ -1 +1 @@ -{"3":["Improper Capitalized Primitive Type"],"4":["Improper Capitalized Primitive Type"],"11":["Improper Capitalized Primitive Type","Improper Capitalized Primitive Type"],"12":["Improper Capitalized Primitive Type","Improper Capitalized Primitive Type"],"13":["Improper Capitalized Primitive Type"],"28":["Improper Capitalized Primitive Type"],"33":["Improper Class Or Interface"]} \ No newline at end of file +{"3":["Improper Capitalized Primitive Type"],"4":["Improper Capitalized Primitive Type"],"11":["Too many statements on this line, revise","Improper Capitalized Primitive Type","Improper Capitalized Primitive Type"],"12":["Too many statements on this line, revise","Improper Capitalized Primitive Type","Improper Capitalized Primitive Type"],"13":["Improper Capitalized Primitive Type"],"28":["Improper Capitalized Primitive Type"]} \ No newline at end of file diff --git a/src/extension.ts b/src/extension.ts index 86bd05e..2085d92 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -28,7 +28,10 @@ export function activate(context: vscode.ExtensionContext) { findLowercaseClassOrInterface(myMap); } ); - const disposable3 = vscode.commands.registerCommand('extension.singleStatementPerLineChecker', singleStatementPerLineChecker); + const disposable3 = vscode.commands.registerCommand('extension.singleStatementPerLineChecker', () => { + singleStatementPerLineChecker(myMap); + } ); + const disposable0 = vscode.commands.registerCommand('extension.findAllErrors', findAllErrors); const commentController = vscode.comments.createCommentController('comment-sample', 'Comment API Sample'); diff --git a/src/singleStatementPerLineChecker.ts b/src/singleStatementPerLineChecker.ts index 1291bd9..a2eb094 100644 --- a/src/singleStatementPerLineChecker.ts +++ b/src/singleStatementPerLineChecker.ts @@ -1,7 +1,7 @@ import * as vscode from 'vscode'; -export function singleStatementPerLineChecker(): number[] { - const problematicLines: number[] = []; // Array to store line numbers with multiple semicolons +export function singleStatementPerLineChecker(myMap: Map<number, string[]>): Map<number, string[]> { + // Get the currently active text editor const editor = vscode.window.activeTextEditor; @@ -16,17 +16,23 @@ export function singleStatementPerLineChecker(): number[] { lines.forEach((lineText, lineNumber) => { - const isForLoop = /^\s*for\s*\([^;]*;[^;]*;[^;]*\)\s*{/i.test(lineText); + const isForLoop = /^\s*for\s*\([^;]*;[^;]*;[^;]*\)\s*{/i.test(lineText); + + if (!isForLoop) { + const semicolonCount = (lineText.match(/;/g) || []).length; + if (semicolonCount > 1) { - if (!isForLoop){ - const semicolonCount = (lineText.match(/;/g) || []).length; - if (semicolonCount > 1) { - // Add the line number to the array - problematicLines.push(lineNumber + 1); // Add 1 because line numbers start from 1 + // Error handling logic + if (!myMap.has(lineNumber + 1)) { + myMap.set(lineNumber + 1, []); + } + const errorMessage = "Too many statements on this line, revise"; + const currentErrors = myMap.get(lineNumber + 1) || []; + currentErrors.push(errorMessage); + myMap.set(lineNumber + 1, currentErrors); + } } - }}); + }); } - vscode.window.showInformationMessage(`Problematic lines: ${problematicLines.join(', ')}`); - return problematicLines; - + return myMap; }