From d26d5161cc37c2e71fb7437e02cf742a9d9c34c0 Mon Sep 17 00:00:00 2001 From: Tetsuo Kiso Date: Sun, 9 Oct 2022 21:57:20 +0900 Subject: [PATCH] Add a linter to check trailing whitespace to pre-commit and CI (#400) --- .github/workflows/ci.yml | 8 ++++++++ .pre-commit-config.yaml | 4 ++++ backend/src/impl/benchmark_configs/globalbench.json | 6 +++--- backend/src/impl/benchmark_configs/masakhaner.json | 2 +- backend/templates/README.mustache | 2 +- deployment/nginx.conf | 2 +- deployment/serve.sh | 2 +- frontend/src/components/Analysis/AnalysisDrawer/index.tsx | 2 +- frontend/src/components/Analysis/AnalysisTable/index.tsx | 6 +++--- openapi/gen_api_layer.sh | 2 +- openapi/ts_templates/configuration.mustache | 6 +++--- 11 files changed, 27 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f76212d5..66c413e0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -109,3 +109,11 @@ jobs: uses: pre-commit/action@v2.0.3 with: extra_args: yamllint --all-files + lint-trailing-whitespace: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: lint + uses: pre-commit/action@v2.0.3 + with: + extra_args: trailing-whitespace --all-files diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2a99ab3d..1c283697 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -39,3 +39,7 @@ repos: rev: v1.28.0 hooks: - id: yamllint + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.3.0 + hooks: + - id: trailing-whitespace diff --git a/backend/src/impl/benchmark_configs/globalbench.json b/backend/src/impl/benchmark_configs/globalbench.json index e34b4f49..4f6089a6 100644 --- a/backend/src/impl/benchmark_configs/globalbench.json +++ b/backend/src/impl/benchmark_configs/globalbench.json @@ -37,16 +37,16 @@ {"op": "max", "group_by": ["source_language"], "skip_group_system": false}, {"op": "weighted_sum", "weight": "source_language", "weight_map": "ling_weight", "skip_group_system": false} ] - }, + }, { "name": "Most-underserved Languages", "operations": [ {"op": "max", "group_by": ["source_language"], "skip_group_system": true}, {"op": "add_default", "column": "source_language", "default_set": "all_lang", "score": 0}, - {"op": "subtract", "num": 1}, + {"op": "subtract", "num": 1}, {"op": "multiply", "weight": "source_language", "weight_map": "pop_weight"} ] } ], "default_views": ["Linguistic-weighted Global Average", "Demographic-weighted Global Average", "Linguistic-weighted System-by-system Average", "Demographic-weighted System-by-system Average", "Languages", "Original"] -} \ No newline at end of file +} \ No newline at end of file diff --git a/backend/src/impl/benchmark_configs/masakhaner.json b/backend/src/impl/benchmark_configs/masakhaner.json index 81724ed1..330cbe25 100644 --- a/backend/src/impl/benchmark_configs/masakhaner.json +++ b/backend/src/impl/benchmark_configs/masakhaner.json @@ -9,7 +9,7 @@ "paper":{ "title":"MasakhaNER: Named Entity Recognition for African Languages", "url":"https://aclanthology.org/2021.tacl-1.66.pdf" - }, + }, "metrics": [{"name": "F1"}], "datasets": [ {"dataset_name": "masakhaner", "sub_dataset": "masakhaner-bam"}, diff --git a/backend/templates/README.mustache b/backend/templates/README.mustache index 6d59c126..9857cb8a 100644 --- a/backend/templates/README.mustache +++ b/backend/templates/README.mustache @@ -7,7 +7,7 @@ is an example of building a swagger-enabled Flask server. This example uses the [Connexion](https://github.com/zalando/connexion) library on top of Flask. -The templates are copied from the [pythonFlaskConnexion folder](https://github.com/swagger-api/swagger-codegen-generators/tree/master/src/main/resources/handlebars/pythonFlaskConnexion) +The templates are copied from the [pythonFlaskConnexion folder](https://github.com/swagger-api/swagger-codegen-generators/tree/master/src/main/resources/handlebars/pythonFlaskConnexion) under [swagger-codegen-generators](https://github.com/swagger-api/swagger-codegen-generators), commit id `0c69d21044bc4f25584ac4a736d9fd13d432c70f`. ## Requirements diff --git a/deployment/nginx.conf b/deployment/nginx.conf index bf84df47..39399c4e 100644 --- a/deployment/nginx.conf +++ b/deployment/nginx.conf @@ -11,6 +11,6 @@ server { proxy_pass http://127.0.0.1:5000; } location / { - try_files $uri /index.html; + try_files $uri /index.html; } } diff --git a/deployment/serve.sh b/deployment/serve.sh index ce80bfd3..1e96ce1e 100644 --- a/deployment/serve.sh +++ b/deployment/serve.sh @@ -1,6 +1,6 @@ #!/bin/bash # Starts nginx and gunicorn. It is meant for the explainaboard_web # container only. The script takes any number of gunicorn arguments -# passed in as a string. +# passed in as a string. nohup nginx -g "daemon off;" & gunicorn -b 0.0.0.0:5000 -t 600 "explainaboard_web.__main__:create_app()" $1 diff --git a/frontend/src/components/Analysis/AnalysisDrawer/index.tsx b/frontend/src/components/Analysis/AnalysisDrawer/index.tsx index 83c980b9..a79470a5 100644 --- a/frontend/src/components/Analysis/AnalysisDrawer/index.tsx +++ b/frontend/src/components/Analysis/AnalysisDrawer/index.tsx @@ -234,7 +234,7 @@ export function AnalysisDrawer({ systems, closeDrawer }: Props) { title={getDrawerTitle()} width="90%" bodyStyle={{ minWidth: "800px" }} - /*Mark the drawer unclosable when the page is still loading to prevent + /*Mark the drawer unclosable when the page is still loading to prevent users from exiting before the asycn function finishes. */ closable={pageState !== PageState.loading} diff --git a/frontend/src/components/Analysis/AnalysisTable/index.tsx b/frontend/src/components/Analysis/AnalysisTable/index.tsx index cb0801a4..5e379bc2 100644 --- a/frontend/src/components/Analysis/AnalysisTable/index.tsx +++ b/frontend/src/components/Analysis/AnalysisTable/index.tsx @@ -190,7 +190,7 @@ export function AnalysisTable({ systemID, task, cases, changeState }: Props) { } } finally { changeState(PageState.success); - /* + /* The table after the 1st scroll may be incomplete as the async API call is not finished. If we stop there, the bottom portion of the examples will be concealed. Therefore, we need a 2nd scroll to bring the entire table @@ -200,9 +200,9 @@ export function AnalysisTable({ systemID, task, cases, changeState }: Props) { } } refreshSystemOutputs(); - /* + /* 1st scroll to the table, which is likely still loading and - incomplete. This is needed so the scroll is immediate and + incomplete. This is needed so the scroll is immediate and users will not experience a delay due to the async API call. */ tableRef.current?.scrollIntoView(); diff --git a/openapi/gen_api_layer.sh b/openapi/gen_api_layer.sh index 95f7497e..caf005ef 100644 --- a/openapi/gen_api_layer.sh +++ b/openapi/gen_api_layer.sh @@ -28,7 +28,7 @@ fi # backend if [[ $mode == "backend" || $mode == "project" ]]; then # remove src/gen if exists and generate code - # we also create a link to src/impl in src/gen which contains our own implementation + # we also create a link to src/impl in src/gen which contains our own implementation cd $project_root && rm -rf $BACKEND_GEN_PATH && \ mkdir -p $BACKEND_GEN_PATH/explainaboard_web && \ cd $BACKEND_GEN_PATH/explainaboard_web/ && \ diff --git a/openapi/ts_templates/configuration.mustache b/openapi/ts_templates/configuration.mustache index 5614b839..6ebdd849 100644 --- a/openapi/ts_templates/configuration.mustache +++ b/openapi/ts_templates/configuration.mustache @@ -18,14 +18,14 @@ export class Configuration { apiKey?: string | ((name: string) => string); /** * parameter for basic security - * + * * @type {string} * @memberof Configuration */ username?: string; /** * parameter for basic security - * + * * @type {string} * @memberof Configuration */ @@ -39,7 +39,7 @@ export class Configuration { accessToken?: string | ((name: string, scopes?: string[]) => string); /** * override base path - * + * * @type {string} * @memberof Configuration */