File tree Expand file tree Collapse file tree 3 files changed +6
-1
lines changed Expand file tree Collapse file tree 3 files changed +6
-1
lines changed Original file line number Diff line number Diff line change 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: 约翰}'
88export 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[] =>
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
Original file line number Diff line number Diff line change 1616
1717'添加'
1818
19+ // https://github.com/Styx11/react-intl-linter/issues/7
20+ const validMessage = true ? '' : '你好' ; const followMessage = true ? '你好' : ''
21+
1922const message = `${ "添加" } hellllllo${ "添加" } `
2023
2124const testMsg = `${ '添加' } hellllllo${ '一个文本' } hellllllo{"这是另一个文本"}`
You can’t perform that action at this time.
0 commit comments