Skip to content

Commit

Permalink
This fixes LowercaseEnums so that it gets stored in the map before co…
Browse files Browse the repository at this point in the history
…nverting to PDF
willeand committed May 30, 2024
1 parent 8b1b483 commit f1b49f2
Showing 3 changed files with 63 additions and 46 deletions.
2 changes: 1 addition & 1 deletion output/data.json
Original file line number Diff line number Diff line change
@@ -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"]}
{"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"]}
7 changes: 4 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ import { findLowercaseEnums } from './findLowercaseEnums';
import { findConstantCap} from './findConstantCap';

const myMap: Map<number, string[]> = 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);

100 changes: 58 additions & 42 deletions src/findLowercaseEnums.ts
Original file line number Diff line number Diff line change
@@ -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.');
}
}
export function findLowercaseEnums(myMap: Map<number, string[]>): Map<number, string[]> {
// 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;
}

0 comments on commit f1b49f2

Please sign in to comment.