diff --git a/grep-lint.py b/grep-lint.py index 80faa8bf6f..adf18e93f8 100644 --- a/grep-lint.py +++ b/grep-lint.py @@ -1,5 +1,6 @@ import subprocess import sys +import re def get_command(branch=None): arguments_list = ["git", "grep", "-P", rule_regex] @@ -9,15 +10,19 @@ def get_command(branch=None): arguments_list.append("--") arguments_list.append("scripts") + arguments_list.append("./package.json") return arguments_list +## fetch upstream to be able to compare current commit to it +subprocess.call(["git", "remote", "add", "temp-remote", "https://github.com/superdesk/superdesk-client-core.git"], stderr=subprocess.STDOUT) +subprocess.call(["git", "fetch", "temp-remote", "--quiet"], stderr=subprocess.STDOUT) +develop_commit_with_ref = subprocess.check_output(["git", "ls-remote", "--heads", "temp-remote", "develop"]).decode('utf-8') +develop_commit = re.split('\t', develop_commit_with_ref)[0] +subprocess.call(["git", "remote", "remove", "temp-remote"], stderr=subprocess.STDOUT) +## + rules_to_check = [ - { - 'name': 'Do not use `translate` filter anymore. Translation strings can\'t be extracted when the filter is used.', - 'perl_regex': '\|\s*?translate', - 'tolerance': True - }, { 'name': 'Do not use angularjs for views anymore. Use React components and use `reactToAngular1` if you need to use React components inside existing angular templates.', @@ -38,16 +43,23 @@ def get_command(branch=None): 'perl_regex': 'templateUrl\s*?:\s*[\'|"|`].+?\.html[\'|"|`]', 'tolerance': True }, - # { - # 'name': 'Do not use angularjs for views anymore. Use React components and use `reactToAngular1` if you need to use React components inside existing angular templates.', - - # # must match: - # # template: '<' - # # must not match: - # # template: 'a', b: '<' - # 'perl_regex': 'template\s*?:\s*[\'|"|`][^\'|"|`]*<[^\'|"|`]*[\'|"|`]', - # 'tolerance': True - # }, + { + 'name': 'Do not use angularjs for views anymore. Use React components and use `reactToAngular1` if you need to use React components inside existing angular templates.', + + # must match: + # template: '<' + # must not match: + # template: 'a', b: '<' + 'perl_regex': 'template\s*?:\s*[\'|"|`][^\'|"|`]*<[^\'|"|`]*[\'|"|`]', + 'tolerance': True + }, + { + 'name': 'force exact ui-framework version', + + # errors if finds a caret or a tilde next to ui-framework version + 'perl_regex': '"superdesk-ui-framework": "(\^|~)', + 'tolerance': False + }, ] any_rule_violated = False @@ -61,7 +73,7 @@ def get_command(branch=None): try: violations_count_develop = len( - subprocess.check_output(get_command("develop")).decode('utf-8').splitlines() + subprocess.check_output(get_command(develop_commit)).decode('utf-8').splitlines() ) except subprocess.CalledProcessError as e: # ignore exception if grep simply didn't find matches @@ -89,6 +101,6 @@ def get_command(branch=None): print("Rule regex: `" + rule_regex + "`") if rule_tolerance is True: - print('Tolerance is enabled, but ' + str(violations_count) + ' violations were found in the working while there only are ' + str(violations_count_develop) + ' violations on develop. See grep-lint.py for details.') + print('Tolerance is enabled, but ' + str(violations_count) + ' violations were found on this commit while there only are ' + str(violations_count_develop) + ' violations on develop. See grep-lint.py for details.') sys.exit(1 if any_rule_violated else 0) diff --git a/package.json b/package.json index 80cb7d73cc..2d495c0fad 100644 --- a/package.json +++ b/package.json @@ -123,7 +123,7 @@ "sass-loader": "6.0.6", "shortid": "2.2.8", "style-loader": "0.20.2", - "superdesk-ui-framework": "^4.0.4", + "superdesk-ui-framework": "4.0.4", "ts-loader": "3.5.0", "typescript": "4.9.5", "uuid": "8.3.1", @@ -163,7 +163,7 @@ "test": "npm run lint && npm run unit && node tasks/verify-client-api-changes.js", "debug-unit-tests": "karma start --reporters=progress --browsers=Chrome", "unit": "karma start --single-run", - "lint": "tsc -p scripts --noEmit && eslint --quiet --parser=@typescript-eslint/parser --ext .js --ext .jsx --ext .ts --ext .tsx scripts e2e/client tasks", + "lint": "python ./grep-lint.py && tsc -p scripts --noEmit && eslint --quiet --parser=@typescript-eslint/parser --ext .js --ext .jsx --ext .ts --ext .tsx scripts e2e/client tasks", "lint-fix": "eslint --fix --parser=@typescript-eslint/parser --ext .js --ext .jsx --ext .ts --ext .tsx scripts e2e/client tasks", "server": "grunt server", "dev": "npm run server"