From 64811610f56a769e0e1132964c6d8b3752a2414e Mon Sep 17 00:00:00 2001 From: Tomas Kikutis Date: Thu, 19 Dec 2024 19:47:36 +0100 Subject: [PATCH 1/8] it can now extract translations from filters --- grep-lint.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/grep-lint.py b/grep-lint.py index 80faa8bf6f..d98fb74c36 100644 --- a/grep-lint.py +++ b/grep-lint.py @@ -13,11 +13,6 @@ def get_command(branch=None): return arguments_list 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.', From eee8e23dd346a058f242128ba83694a15d960d06 Mon Sep 17 00:00:00 2001 From: Tomas Kikutis Date: Thu, 19 Dec 2024 19:48:04 +0100 Subject: [PATCH 2/8] avoid angularjs views --- grep-lint.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/grep-lint.py b/grep-lint.py index d98fb74c36..ddc235214f 100644 --- a/grep-lint.py +++ b/grep-lint.py @@ -33,16 +33,16 @@ 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 + }, ] any_rule_violated = False From e20bca6f01b9ade9008d9274265893807cfa0d98 Mon Sep 17 00:00:00 2001 From: Tomas Kikutis Date: Thu, 19 Dec 2024 20:10:41 +0100 Subject: [PATCH 3/8] force exact ui-framework version --- grep-lint.py | 8 ++++++++ package.json | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/grep-lint.py b/grep-lint.py index ddc235214f..aa78da6d18 100644 --- a/grep-lint.py +++ b/grep-lint.py @@ -9,6 +9,7 @@ def get_command(branch=None): arguments_list.append("--") arguments_list.append("scripts") + arguments_list.append("./package.json") return arguments_list @@ -43,6 +44,13 @@ def get_command(branch=None): '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 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" From 7cd79d35638d45cd7da45ee65d51d20b81e95509 Mon Sep 17 00:00:00 2001 From: Tomas Kikutis Date: Thu, 19 Dec 2024 20:40:01 +0100 Subject: [PATCH 4/8] test if develop branch exists in github actions --- grep-lint.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/grep-lint.py b/grep-lint.py index aa78da6d18..e785d94785 100644 --- a/grep-lint.py +++ b/grep-lint.py @@ -55,6 +55,10 @@ def get_command(branch=None): any_rule_violated = False + +print('git branch output:') +print(subprocess.check_output(["git", "branch"], stderr=subprocess.STDOUT).decode('utf-8')) + for rule in rules_to_check: rule_regex = rule['perl_regex'] rule_name = rule['name'] From 3414ea5cb28fff2807e902b5dcf7ffe7b7b097b3 Mon Sep 17 00:00:00 2001 From: Tomas Kikutis Date: Fri, 20 Dec 2024 11:58:38 +0100 Subject: [PATCH 5/8] test --- grep-lint.py | 1 + 1 file changed, 1 insertion(+) diff --git a/grep-lint.py b/grep-lint.py index e785d94785..aff54ad824 100644 --- a/grep-lint.py +++ b/grep-lint.py @@ -58,6 +58,7 @@ def get_command(branch=None): print('git branch output:') print(subprocess.check_output(["git", "branch"], stderr=subprocess.STDOUT).decode('utf-8')) +print(subprocess.check_output(["git", "remote", "-v"], stderr=subprocess.STDOUT).decode('utf-8')) for rule in rules_to_check: rule_regex = rule['perl_regex'] From ecad920668f5a187108018e74e3e5025d3573707 Mon Sep 17 00:00:00 2001 From: Tomas Kikutis Date: Fri, 20 Dec 2024 12:19:52 +0100 Subject: [PATCH 6/8] test --- grep-lint.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grep-lint.py b/grep-lint.py index aff54ad824..df781d457d 100644 --- a/grep-lint.py +++ b/grep-lint.py @@ -57,8 +57,8 @@ def get_command(branch=None): print('git branch output:') +print(subprocess.check_output(["git", "fetch", "origin"], stderr=subprocess.STDOUT).decode('utf-8')) print(subprocess.check_output(["git", "branch"], stderr=subprocess.STDOUT).decode('utf-8')) -print(subprocess.check_output(["git", "remote", "-v"], stderr=subprocess.STDOUT).decode('utf-8')) for rule in rules_to_check: rule_regex = rule['perl_regex'] From d2889fdef62ecc219e7a4e3a19595c8c55f91bef Mon Sep 17 00:00:00 2001 From: Tomas Kikutis Date: Fri, 20 Dec 2024 12:44:33 +0100 Subject: [PATCH 7/8] test --- grep-lint.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grep-lint.py b/grep-lint.py index df781d457d..ecfa9c622e 100644 --- a/grep-lint.py +++ b/grep-lint.py @@ -69,7 +69,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("origin/develop")).decode('utf-8').splitlines() ) except subprocess.CalledProcessError as e: # ignore exception if grep simply didn't find matches @@ -97,6 +97,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) From c8d1bf0a5dbac07a94eda1571afe15e14262c70b Mon Sep 17 00:00:00 2001 From: Tomas Kikutis Date: Fri, 20 Dec 2024 14:12:02 +0100 Subject: [PATCH 8/8] fetch upstream to be able to compare current commit to it --- grep-lint.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/grep-lint.py b/grep-lint.py index ecfa9c622e..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] @@ -13,6 +14,14 @@ def get_command(branch=None): 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 angularjs for views anymore. Use React components and use `reactToAngular1` if you need to use React components inside existing angular templates.', @@ -55,11 +64,6 @@ def get_command(branch=None): any_rule_violated = False - -print('git branch output:') -print(subprocess.check_output(["git", "fetch", "origin"], stderr=subprocess.STDOUT).decode('utf-8')) -print(subprocess.check_output(["git", "branch"], stderr=subprocess.STDOUT).decode('utf-8')) - for rule in rules_to_check: rule_regex = rule['perl_regex'] rule_name = rule['name'] @@ -69,7 +73,7 @@ def get_command(branch=None): try: violations_count_develop = len( - subprocess.check_output(get_command("origin/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