Skip to content

Commit 50c1a0d

Browse files
committed
fix: fix empty string verify (#7)
1 parent e06cee1 commit 50c1a0d

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

server/src/lib/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// 匹配单引号/双引号内的字符串文本
33
// 单个字符 . 的匹配默认是贪婪的,所以当有多个带引号的句子在一行时,匹配结果就会是从第一个引号开始到最后一个引号结束,所以要用 [^'\n]+ 和 [^"\n]+ 去匹配
44
// 例如 const message = `${'添加'}hellllllo${'添加'}` 会匹配为 添加'}hellllllo${'添加
5-
export const StringRegx = /'([^'\n]+)'|"([^"\n]+)"/gu
5+
export const StringRegx = /'([^'\n]*)'|"([^"\n]*)"/gu
66

77
// 标识特殊字符串前缀,表示含有特殊字符需要 react-intl-linter 识别 'react-intl=你好,{name: 约翰}' 或 '$=你好,{name: 约翰}'
88
export const SpecialStringRegx = /^(?:react-intl|\$)=([^\n]+)/u

server/src/lib/validator.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export const validateMessage = (textDocument: TextDocument): Diagnostic[] =>
3333
// 单双引号之间的文本内容
3434
const string = match[1] || match[2]
3535

36+
if (!string) continue
37+
3638
// 以 react-intl= 或 $= 开头的特殊字符串匹配
3739
const specialStringMatch = SpecialStringRegx.exec(string)
3840
const invalidParams = specialStringMatch ? !!inValidParamsRegx.exec(specialStringMatch[1].trim()) : false

test_files/TypescriptReact.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
'添加'
1818

19+
// https://github.com/Styx11/react-intl-linter/issues/7
20+
const validMessage = true ? '' : '你好'; const followMessage = true ? '你好' : ''
21+
1922
const message = `${"添加"}hellllllo${"添加"}`
2023

2124
const testMsg = `${'添加'}hellllllo${'一个文本'}hellllllo{"这是另一个文本"}`

0 commit comments

Comments
 (0)