Skip to content

Commit

Permalink
fix: sonar complaints fix (#688)
Browse files Browse the repository at this point in the history
* fix: sonar complaints fix

* fix: changeset

* fix: regex complexity

* fix: bug fix
  • Loading branch information
vadson71 authored Jan 10, 2024
1 parent dd4d31b commit 1e011e6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
8 changes: 8 additions & 0 deletions .changeset/lovely-dragons-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"vscode-ui5-language-assistant": patch
"@ui5-language-assistant/language-server": patch
"@ui5-language-assistant/binding-parser": patch
"@ui5-language-assistant/vscode-ui5-language-assistant-bas-ext": patch
---

Fixed SonarCloud complaints
17 changes: 15 additions & 2 deletions packages/binding-parser/src/lexer/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,23 @@ const whiteSpace = createToken({
// group: Lexer.SKIPPED,
line_breaks: true,
});

const specChars = "#!\"'$%&()*+-./;<=>?@\\^_`~|";
const charsToEscape = "$()*+./?^|\\";

const tokens: string[] = specChars.split("").map((token) => {
if (charsToEscape.includes(token)) {
token = "\\" + token;
}
return token;
});

const regExLookup = ["&gt;", "&#47;", "&#x2F;", ...tokens].join("|");
const pattern = new RegExp(`(?:${regExLookup})+`);

const specialChars = createToken({
name: SPECIAL_CHARS,
pattern:
/(?:#|&gt;|&#47;|&#x2F;|!|"|\$|%|&|'|\(|\)|\*|\+|-|\.|\/|;|<|=|>|\?|@|\\|\^|_|`|~|\||)+/,
pattern,
});

const leftCurly = createToken({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ describe("binding parser", () => {
continue;
}
if (only.includes(t)) {
it.only(`${t}`, async () => {
const cb = async () => {
await testParser(t);
});
};
it.only(`${t}`, cb); // NOSONAR
continue;
}
it(`${t}`, async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/language-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ connection.onInitialize(
}
);

connection.onInitialized(async () => {
connection.onInitialized(async (): Promise<void> => {
getLogger().info("`onInitialized` event");
if (hasConfigurationCapability) {
// Register for all configuration changes
Expand Down Expand Up @@ -266,7 +266,7 @@ const validateOpenDocuments = async (changes: FileEvent[]): Promise<void> => {
}
};

connection.onDidChangeWatchedFiles(async (changeEvent) => {
connection.onDidChangeWatchedFiles(async (changeEvent): Promise<void> => {
getLogger().debug("`onDidChangeWatchedFiles` event", {
changeEvent,
});
Expand Down
4 changes: 2 additions & 2 deletions packages/vscode-ui5-language-assistant/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ export async function activate(context: ExtensionContext): Promise<void> {
client.start().then(() => {
client.onNotification(
"UI5LanguageAssistant/ui5Model",
async (model: UI5Model) => await updateCurrentModel(model)
async (model: UI5Model): Promise<void> => await updateCurrentModel(model)
);
client.onNotification(
"UI5LanguageAssistant/context-error",
async (error: Error) => await handleContextError(error)
(error: Error) => handleContextError(error)
);
});
window.onDidChangeActiveTextEditor(async () => {
Expand Down

0 comments on commit 1e011e6

Please sign in to comment.