Skip to content

Commit e44e5c7

Browse files
committed
Copilot nits
1 parent e835c5f commit e44e5c7

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/checks/keywords.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ export type KeywordsContext = z.infer<typeof KeywordsContext>;
4040
* @param config Configuration specifying keywords and behavior
4141
* @returns GuardrailResult indicating if tripwire was triggered
4242
*/
43-
const unicodeWordCharRegex = /[\p{L}\p{N}]/u;
44-
const isWordChar = (char: string | undefined): boolean => {
45-
if (!char) return false;
46-
if (char === '_') return true;
47-
return unicodeWordCharRegex.test(char);
48-
};
43+
const WORD_CHAR_CLASS = '[\\p{L}\\p{N}_]';
44+
const isWordChar = (() => {
45+
const wordCharRegex = new RegExp(WORD_CHAR_CLASS, 'u');
46+
return (char: string | undefined): boolean => {
47+
if (!char) return false;
48+
return wordCharRegex.test(char);
49+
};
50+
})();
4951

5052
export const keywordsCheck: CheckFn<KeywordsContext, string, KeywordsConfig> = (
5153
ctx,
@@ -86,8 +88,8 @@ export const keywordsCheck: CheckFn<KeywordsContext, string, KeywordsConfig> = (
8688
const lastChar = keywordChars[keywordChars.length - 1];
8789
const needsLeftBoundary = isWordChar(firstChar);
8890
const needsRightBoundary = isWordChar(lastChar);
89-
const leftBoundary = needsLeftBoundary ? '(?<![\\p{L}\\p{N}_])' : '';
90-
const rightBoundary = needsRightBoundary ? '(?![\\p{L}\\p{N}_])' : '';
91+
const leftBoundary = needsLeftBoundary ? `(?<!${WORD_CHAR_CLASS})` : '';
92+
const rightBoundary = needsRightBoundary ? `(?!${WORD_CHAR_CLASS})` : '';
9193
return `${leftBoundary}${escaped}${rightBoundary}`;
9294
});
9395

0 commit comments

Comments
 (0)