Skip to content

Commit

Permalink
update regex matching according to linting rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Clemens-E committed Feb 18, 2024
1 parent 72010e5 commit e466cea
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { LanguageToolPluginSettings } from './SettingsTab';
export const logs: string[] = [];

let lastStatus: 'ok' | 'request-failed' | 'request-not-ok' | 'json-parse-error' = 'ok';
const listRegex = /^\s*(-|\d+\.) $/m;

export async function getDetectionResult(
text: string,
Expand All @@ -19,11 +20,11 @@ export async function getDetectionResult(
if (/^`[^`]+`$/.test(text)) {
return text;
}
const linebreaks = '\n'.repeat(text.match(/\n/g)?.length ?? 0);
const linebreaks = '\n'.repeat((text.match(/\n/g) || [])?.length ?? 0);

// Support lists (annotation ends with marker)
if (text.match(/^\s*(-|\d+\.) $/m)) {
return linebreaks + '• '; // this is the character, the online editor uses
if (listRegex.exec(text)) {
return `${linebreaks}• `; // this is the character, the online editor uses
}

return linebreaks;
Expand Down Expand Up @@ -107,7 +108,10 @@ export async function getDetectionResult(
} catch (e) {
const status = 'request-failed';
if (lastStatus !== status || !settings.shouldAutoCheck) {
new Notice(`Request to LanguageTool server failed. Please check your connection and LanguageTool server URL`, 3000);
new Notice(
`Request to LanguageTool server failed. Please check your connection and LanguageTool server URL`,
3000,
);
lastStatus = status;
}
return Promise.reject(e);
Expand Down

0 comments on commit e466cea

Please sign in to comment.