-
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 #14 from Senior-Capstone-2024/findLowercaseEnums
Finds improperly named enums
- Loading branch information
Showing
3 changed files
with
49 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,44 @@ | ||
import * as vscode from 'vscode'; | ||
|
||
export function findLowercaseEnums() { | ||
// activeTextEditor allows access to text inside opened document. | ||
vscode.window.showInformationMessage('Naming Convention Mistake!! Highlighted in RED='); | ||
const editor = vscode.window.activeTextEditor; | ||
|
||
if (editor) { | ||
const document = editor.document; | ||
const text = document.getText(); | ||
|
||
const pattern = /\b(?:enum)\s+([a-z][a-zA-Z]*)\b/g; | ||
|
||
let match; | ||
while ((match = pattern.exec(text)) !== null) { | ||
// Get the matched variable name | ||
|
||
const variableName = match[0]; // Entire matched variable name | ||
const firstLetterIndex = match.index + match[0].indexOf(match[1]); // Index of the first letter after class | ||
const firstLetterRange = new vscode.Range(document.positionAt(firstLetterIndex), document.positionAt(firstLetterIndex + 1)); | ||
|
||
// Highlight the first letter after the class name | ||
editor.setDecorations(vscode.window.createTextEditorDecorationType({ | ||
isWholeLine: false, | ||
borderWidth: '1px', | ||
borderStyle: 'solid', | ||
overviewRulerColor: 'red', | ||
overviewRulerLane: vscode.OverviewRulerLane.Right, | ||
light: { | ||
borderColor: 'darkred', | ||
backgroundColor: 'rgba(255, 0, 0, 0.1)' | ||
}, | ||
dark: { | ||
borderColor: 'lightred', | ||
backgroundColor: 'rgba(255, 0, 0, 0.4)' | ||
} | ||
}), [firstLetterRange]); | ||
|
||
} | ||
|
||
} else { | ||
vscode.window.showErrorMessage('No active text editor.'); | ||
} | ||
} |