From df70fa962e11ac4f74bc2a6725963ddb80100d29 Mon Sep 17 00:00:00 2001 From: Umair Khan Date: Fri, 8 Sep 2017 12:35:11 +0500 Subject: [PATCH] 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; --- tools/linter_lib/custom_check.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/linter_lib/custom_check.py b/tools/linter_lib/custom_check.py index 7195cf004d..ae811ab518 100644 --- a/tools/linter_lib/custom_check.py +++ b/tools/linter_lib/custom_check.py @@ -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'},