diff --git a/output/data.json b/output/data.json index 7c899fe..ec9168a 100644 --- a/output/data.json +++ b/output/data.json @@ -1 +1 @@ -{"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"]} \ No newline at end of file +{"3":["Improper Capitalized Primitive Type"],"4":["Improper Capitalized Primitive Type"],"7":["Lowercase ENUM found!"],"18":["Improper Capitalized Primitive Type","Improper Capitalized Primitive Type"],"19":["Improper Capitalized Primitive Type","Improper Capitalized Primitive Type"],"20":["Improper Capitalized Primitive Type"],"35":["Improper Capitalized Primitive Type"],"179":["enum fruit"]} \ No newline at end of file diff --git a/src/extension.ts b/src/extension.ts index 514f0e6..7f6f97b 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -13,7 +13,7 @@ import { findLowercaseEnums } from './findLowercaseEnums'; import { findConstantCap} from './findConstantCap'; const myMap: Map = new Map(); -const filePath = 'C:\\Users\\Will\\Desktop\\cw\\gradeFast-1.0\\output\\data.json'; +const filePath = 'C:\\Users\\Will\\Desktop\\cww\\gradeFast-1.0\\output\\data.json'; export function activate(context: vscode.ExtensionContext) { @@ -26,7 +26,6 @@ export function activate(context: vscode.ExtensionContext) { findCapitalizedMethodName(myMap); } ); - const disposable1 = vscode.commands.registerCommand('extension.findLowercaseClassOrInterface', () => { findLowercaseClassOrInterface(myMap); } ); @@ -37,7 +36,9 @@ export function activate(context: vscode.ExtensionContext) { const disposable4 = vscode.commands.registerCommand('extension.findDuplicateCode', findDuplicateCode); - const disposable5 = vscode.commands.registerCommand('extension.findLowercaseEnums', findLowercaseEnums); + const disposable5 = vscode.commands.registerCommand('extension.findLowercaseEnums', () => { + findLowercaseEnums(myMap); + } ); const disposable0 = vscode.commands.registerCommand('extension.findAllErrors', findAllErrors); diff --git a/src/findLowercaseEnums.ts b/src/findLowercaseEnums.ts index 85c870d..e25cb66 100644 --- a/src/findLowercaseEnums.ts +++ b/src/findLowercaseEnums.ts @@ -1,44 +1,60 @@ 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.'); - } -} \ No newline at end of file +export function findLowercaseEnums(myMap: Map): Map { + // 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 enum + + // Store the index where the error is found + myMap.set(firstLetterIndex, [variableName]); + + // Update the map with the error message + const lineNumber = document.positionAt(firstLetterIndex).line+1; + const errorMessage = "Lowercase ENUM found!"; + if (!myMap.has(lineNumber)) { + myMap.set(lineNumber, [errorMessage]); + } else { + const currentErrors = myMap.get(lineNumber) || []; + currentErrors.push(errorMessage); + myMap.set(lineNumber, currentErrors); + } + + // Print out "Lowercase ENUM found!" + console.log("Lowercase ENUM found!"); + + const firstLetterRange = new vscode.Range(document.positionAt(firstLetterIndex), document.positionAt(firstLetterIndex + 1)); + + // Highlight the first letter after the enum 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.'); + } + return myMap; +}