Skip to content

Commit

Permalink
Merge pull request #20 from Senior-Capstone-2024/singleStatement2.0
Browse files Browse the repository at this point in the history
this adds the errors into a single datastructure before converting to…
  • Loading branch information
chiouc authored May 6, 2024
2 parents 2d46287 + 7ac6f90 commit 4cf1660
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion output/data.json
Original file line number Diff line number Diff line change
@@ -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"]}
{"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"]}
5 changes: 4 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
30 changes: 18 additions & 12 deletions src/singleStatementPerLineChecker.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}

0 comments on commit 4cf1660

Please sign in to comment.