From 503cfde7bece0a4d55edce1ac8d45cd88d2a8c9a Mon Sep 17 00:00:00 2001 From: Liam Corrigan Date: Wed, 4 Aug 2021 15:48:07 -0400 Subject: [PATCH] added a check for comments inside JSX --- src/extension.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/extension.ts b/src/extension.ts index 521e509..9ccee3a 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -11,6 +11,9 @@ declare function clearInterval(token: IntervalToken): void; export function activate(context: vscode.ExtensionContext) { + // lines that start with {/* or end with */} are comments in JSX + const isJSXCommentRegex = /(^\s*{\/\*)|(\*\/}$)/; + const regexRegex = /(^|\s|[()={},:?;])(\/((?:\\\/|\[[^\]]*\]|[^/])+)\/([gimuy]*))(\s|[()={},:?;]|$)/g; const phpRegexRegex = /(^|\s|[()={},:?;])['|"](\/((?:\\\/|\[[^\]]*\]|[^/])+)\/([gimuy]*))['|"](\s|[()={},:?;]|$)/g; const haxeRegexRegex = /(^|\s|[()={},:?;])(~\/((?:\\\/|\[[^\]]*\]|[^/])+)\/([gimsu]*))(\s|[.()={},:?;]|$)/g; @@ -277,6 +280,9 @@ https://github.com/chrmarti/vscode-regex let regex = getRegexRegex(document.languageId); regex.lastIndex = 0; const text = line.text.substr(0, 1000); + if (isJSXComment(text)) { + continue; + } while ((match = regex.exec(text))) { const result = createRegexMatch(document, i, match); if (result) { @@ -331,4 +337,9 @@ https://github.com/chrmarti/vscode-regex } return matches; } + + function isJSXComment(line: string) { + // TODO - something to check settings if we want to support checking for JSX comments + return isJSXCommentRegex.exec(line) !== null; + } }