linter: Improve i18n related regexes.

There are four regexes which try to ensure that the i18n strings are
properly captured.

1) The one which disallows multiline strings.
```
i18n\.t\([^)]+[^,\{\)]$

// Disallows:
i18n.t('some '
       + 'text');
```

2) The one which disallows concatenation within argument to i18n.t():
```
i18n\.t\([\'\"].+?[\'\"]\s*\+

// Disallows:
i18n.t("some " + "text");
```

3) There are two which disallow concatenation with i18n.t():
```
i18n\.t\(.+\).*\+

// Disallows:
i18n.t('some text') +

\+.*i18n\.t\(.+\)

// Disallows:
+ i18n.t('some text')
```

The ideal case is that you try to bring the string argument to the
i18n.t() on one line. In case this is not possible, you can do the
following:

```
var1 = i18n.t("Some text to be translated");
var2 = i18n.t("Some more text to be translated");
complete = var1 + var2;
This commit is contained in:
Umair Khan 2017-09-08 12:35:11 +05:00 committed by Tim Abbott
parent 221afb1492
commit df70fa962e
1 changed files with 5 additions and 3 deletions

View File

@ -140,11 +140,13 @@ def build_custom_checkers(by_lang):
'description': 'The module blueslip has no function warning, try using blueslip.warn'},
{'pattern': '[)]{$',
'description': 'Missing space between ) and {'},
{'pattern': 'i18n\.t\([^)]+[^,\{]$',
{'pattern': 'i18n\.t\([^)]+[^,\{\)]$',
'description': 'i18n string should not be a multiline string'},
{'pattern': 'i18n\.t([^)]+?\+.+?)',
{'pattern': 'i18n\.t\([\'\"].+?[\'\"]\s*\+',
'description': 'Do not concatenate arguments within i18n.t()'},
{'pattern': 'i18n\.t\(.+\).*\+',
'description': 'Do not concatenate i18n strings'},
{'pattern': 'i18n\.t([^+]+?).+?\+',
{'pattern': '\+.*i18n\.t\(.+\)',
'description': 'Do not concatenate i18n strings'},
{'pattern': '["\']json/',
'description': 'Relative URL for JSON route not supported by i18n'},