Skip to content

Commit

Permalink
Merge pull request #8 from Senior-Capstone-2024/singleStatementPerLin…
Browse files Browse the repository at this point in the history
…eChecker

Creates a new java convention for finding multiple statements per line
  • Loading branch information
aravindrsripada authored Apr 11, 2024
2 parents b68ebc6 + 48d7176 commit e028902
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
{
"command": "extension.findCapitalizedMethodName",
"title": "findCapitalizedMethodName"
},
{
"command": "extension.singleStatementPerLineChecker",
"title": "singleStatementPerLineChecker"
}
],
"menus": {
Expand Down
2 changes: 2 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import { NoteComment, NoteCommentController } from './noteComment';
import { findCapitalizedPrimitiveTypes } from './findCapitalizedPrimitiveTypes';
import { findLowercaseClassOrInterface } from './findLowercaseClassOrInterface';
import { findCapitalizedMethodName } from './findCapitalizedMethodName';
import { singleStatementPerLineChecker } from './singleStatementPerLineChecker';

export function activate(context: vscode.ExtensionContext) {
console.log('Congratulations, your extension "Java convention commands" is now active!');

const disposable = vscode.commands.registerCommand('extension.findCapitalizedPrimitiveTypes', findCapitalizedPrimitiveTypes);
const disposable1 = vscode.commands.registerCommand('extension.findLowercaseClassOrInterface', findLowercaseClassOrInterface);
const disposable2 = vscode.commands.registerCommand('extension.findCapitalizedMethodName', findCapitalizedMethodName);
const disposable3 = vscode.commands.registerCommand('extension.singleStatementPerLineChecker', singleStatementPerLineChecker);

const commentController = vscode.comments.createCommentController('comment-sample', 'Comment API Sample');
context.subscriptions.push(commentController);
Expand Down
32 changes: 32 additions & 0 deletions src/singleStatementPerLineChecker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as vscode from 'vscode';

export function singleStatementPerLineChecker(): number[] {
const problematicLines: number[] = []; // Array to store line numbers with multiple semicolons

// Get the currently active text editor
const editor = vscode.window.activeTextEditor;

// If there is an active text editor
if (editor) {
const document = editor.document;
const text = document.getText();

// Split the text into an array of lines
const lines = text.split('\n');

lines.forEach((lineText, lineNumber) => {

const isForLoop = /^\s*for\s*\([^;]*;[^;]*;[^;]*\)\s*{/i.test(lineText);

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
}
}});
}
vscode.window.showInformationMessage(`Problematic lines: ${problematicLines.join(', ')}`);
return problematicLines;

}

0 comments on commit e028902

Please sign in to comment.