File tree 3 files changed +6
-1
lines changed
3 files changed +6
-1
lines changed Original file line number Diff line number Diff line change 2
2
// 匹配单引号/双引号内的字符串文本
3
3
// 单个字符 . 的匹配默认是贪婪的,所以当有多个带引号的句子在一行时,匹配结果就会是从第一个引号开始到最后一个引号结束,所以要用 [^'\n]+ 和 [^"\n]+ 去匹配
4
4
// 例如 const message = `${'添加'}hellllllo${'添加'}` 会匹配为 添加'}hellllllo${'添加
5
- export const StringRegx = / ' ( [ ^ ' \n ] + ) ' | " ( [ ^ " \n ] + ) " / gu
5
+ export const StringRegx = / ' ( [ ^ ' \n ] * ) ' | " ( [ ^ " \n ] * ) " / gu
6
6
7
7
// 标识特殊字符串前缀,表示含有特殊字符需要 react-intl-linter 识别 'react-intl=你好,{name: 约翰}' 或 '$=你好,{name: 约翰}'
8
8
export const SpecialStringRegx = / ^ (?: r e a c t - i n t l | \$ ) = ( [ ^ \n ] + ) / u
Original file line number Diff line number Diff line change @@ -33,6 +33,8 @@ export const validateMessage = (textDocument: TextDocument): Diagnostic[] =>
33
33
// 单双引号之间的文本内容
34
34
const string = match [ 1 ] || match [ 2 ]
35
35
36
+ if ( ! string ) continue
37
+
36
38
// 以 react-intl= 或 $= 开头的特殊字符串匹配
37
39
const specialStringMatch = SpecialStringRegx . exec ( string )
38
40
const invalidParams = specialStringMatch ? ! ! inValidParamsRegx . exec ( specialStringMatch [ 1 ] . trim ( ) ) : false
Original file line number Diff line number Diff line change 16
16
17
17
'添加'
18
18
19
+ // https://github.com/Styx11/react-intl-linter/issues/7
20
+ const validMessage = true ? '' : '你好' ; const followMessage = true ? '你好' : ''
21
+
19
22
const message = `${ "添加" } hellllllo${ "添加" } `
20
23
21
24
const testMsg = `${ '添加' } hellllllo${ '一个文本' } hellllllo{"这是另一个文本"}`
You can’t perform that action at this time.
0 commit comments