Skip to content

added a check for comments inside JSX #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}