Skip to content

Commit

Permalink
Merge pull request #14 from Senior-Capstone-2024/findLowercaseEnums
Browse files Browse the repository at this point in the history
Finds improperly named enums
  • Loading branch information
willeand authored May 2, 2024
2 parents d248806 + 86fc600 commit 91529d2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@
{
"command": "extension.findConstantCap",
"title": "findConstantCap"
},
{
"command": "extension.findLowercaseEnums",
"title": "findLowercaseEnums"
}
],
"menus": {
Expand Down
1 change: 1 addition & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { findCapitalizedMethodName } from './findCapitalizedMethodName';
import { singleStatementPerLineChecker } from './singleStatementPerLineChecker';
import { findAllErrors } from './findAllErrors';
import { findConstantCap} from './findConstantCap';
import { findLowercaseEnums } from './findLowercaseEnums';

export function activate(context: vscode.ExtensionContext) {
console.log('Congratulations, your extension "Java convention commands" is now active!');
Expand Down
44 changes: 44 additions & 0 deletions src/findLowercaseEnums.ts
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.');
}
}

0 comments on commit 91529d2

Please sign in to comment.