-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from Senior-Capstone-2024/singleStatementPerLin…
…eChecker Creates a new java convention for finding multiple statements per line
- Loading branch information
Showing
3 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |