-
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 #22 from Senior-Capstone-2024/lowerCaseEnumsParam
This fixes LowercaseEnums so that it gets stored in the map before co…
- Loading branch information
Showing
3 changed files
with
63 additions
and
46 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
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"]} |
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 |
---|---|---|
@@ -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; | ||
} |