From d9d5dfc0fe25230866ea3f3b09cbca50059f7519 Mon Sep 17 00:00:00 2001 From: Johnson Chu Date: Sun, 5 Jan 2025 17:01:48 +0800 Subject: [PATCH] refactor(ignore): improve regex for command parsing --- packages/config/lib/plugins/ignore.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/config/lib/plugins/ignore.ts b/packages/config/lib/plugins/ignore.ts index e13abdc..113184b 100644 --- a/packages/config/lib/plugins/ignore.ts +++ b/packages/config/lib/plugins/ignore.ts @@ -16,9 +16,10 @@ export function create( const mode = typeof cmdOption === 'string' ? 'singleLine' : 'multiLine'; const [cmd, endCmd] = Array.isArray(cmdOption) ? cmdOption : [cmdOption, undefined]; const cmdText = cmd.replace(/\?/g, ''); - const withRuleId = '(\\b[ \\t]*|[ \\t]+)(?\\S*\\b)?'; - const reg = new RegExp(`\\s*${cmd}${withRuleId}`); - const endReg = endCmd ? new RegExp(`\\s*${endCmd}${withRuleId}`) : undefined; + const withRuleId = '[ \\t]*(?\\w\\S*)?'; + const ending = '([ \\t]+[^\\r\\n]*)?$'; + const reg = new RegExp(`\\s*${cmd}${withRuleId}${ending}`); + const endReg = endCmd ? new RegExp(`\\s*${endCmd}${withRuleId}${ending}`) : undefined; const completeReg1 = /^\s*\/\/(\s*)([\S]*)?$/; const completeReg2 = new RegExp(`//\\s*${cmd}(\\S*)?$`);