From 7d5ab523ba5cf41f3db86aeb029474c77a0bbba8 Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 20 Dec 2023 22:27:30 +0000 Subject: [PATCH 1/5] no matching corner case Signed-off-by: Eric --- .github/workflows/lint.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index d66abe5366..a194e81b42 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -52,10 +52,11 @@ jobs: working-directory: OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }} run: | git fetch origin main - CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRTUXB origin/main | grep -E "\.(js|ts|tsx)$") + CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRTUXB origin/main | grep -E "\.(js|ts|tsx)$" || true) if [ -n "$CHANGED_FILES" ]; then echo "Linting changed files..." yarn lint $CHANGED_FILES else - echo "No JavaScript/TypeScript files changed." + echo "No matching files changed." + exit 0 fi \ No newline at end of file From 14e4ee086fef1cf9edffbae21bcf164c23db6ec9 Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 20 Dec 2023 23:30:47 +0000 Subject: [PATCH 2/5] adjust some linting rules Signed-off-by: Eric --- .eslintrc.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 6ba689e332..527f17bba7 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -14,10 +14,9 @@ module.exports = { '@elastic/eslint-config-kibana', 'plugin:@elastic/eui/recommended', 'plugin:react-hooks/recommended', - "eslint:recommended", "plugin:cypress/recommended", - "plugin:import/recommended", - "prettier" + 'plugin:jest/recommended', + 'plugin:prettier/recommended', ], env: { 'cypress/globals': true, @@ -26,6 +25,14 @@ module.exports = { 'cypress', ], rules: { + '@typescript-eslint/no-unused-vars': [ + 'error', + { + argsIgnorePattern: '^_', + varsIgnorePattern: '^_', + caughtErrorsIgnorePattern: '^_', + }, + ], '@osd/eslint/no-restricted-paths': [ 'error', { @@ -49,6 +56,7 @@ module.exports = { { files: ['**/*.{js,ts,tsx}'], rules: { + '@typescript-eslint/no-explicit-any': 'warn', 'no-console': 0, '@osd/eslint/require-license-header': [ 'error', From febe215236536da599e0e6222de06ecb7327daaa Mon Sep 17 00:00:00 2001 From: Eric Date: Thu, 21 Dec 2023 00:18:49 +0000 Subject: [PATCH 3/5] using bash array Signed-off-by: Eric --- .github/workflows/lint.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index a194e81b42..0666e1896e 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,6 +1,6 @@ name: Lint -on: [push, pull_request] +on: [pull_request] env: PLUGIN_NAME: dashboards-observability @@ -52,11 +52,10 @@ jobs: working-directory: OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }} run: | git fetch origin main - CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRTUXB origin/main | grep -E "\.(js|ts|tsx)$" || true) + CHANGED_FILES=($(git diff --name-only --diff-filter=d origin/main | grep -E "\.(js|ts|tsx)$")) || true if [ -n "$CHANGED_FILES" ]; then echo "Linting changed files..." - yarn lint $CHANGED_FILES + yarn lint "${CHANGED_FILES[@]}" else echo "No matching files changed." - exit 0 fi \ No newline at end of file From 0bdf0dd96f286a387031cd9fa5448505d9275e07 Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 22 Dec 2023 00:31:40 +0000 Subject: [PATCH 4/5] improve linter Signed-off-by: Eric --- .github/workflows/lint.yml | 39 ++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 0666e1896e..81d46ef198 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,10 +1,10 @@ name: Lint -on: [pull_request] +on: [pull_request] env: PLUGIN_NAME: dashboards-observability - OPENSEARCH_DASHBOARDS_VERSION: 'main' + OPENSEARCH_DASHBOARDS_VERSION: "main" jobs: build: @@ -22,7 +22,8 @@ jobs: - name: Checkout dashboards observability uses: actions/checkout@v2 with: - path: OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }} + path: OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }} + fetch-depth: 0 - name: Get node and yarn versions working-directory: ${{ env.WORKING_DIR }} @@ -35,7 +36,7 @@ jobs: uses: actions/setup-node@v1 with: node-version: ${{ steps.versions_step.outputs.node_version }} - registry-url: 'https://registry.npmjs.org' + registry-url: "https://registry.npmjs.org" - name: Install correct yarn version for OpenSearch Dashboards run: | @@ -44,18 +45,28 @@ jobs: npm i -g yarn@${{ steps.versions_step.outputs.yarn_version }} - name: Bootstrap the plugin - working-directory: OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }} - run: - yarn osd bootstrap + working-directory: OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }} + run: yarn osd bootstrap - - name: lint code base + - name: Get list of changed files + id: files + run: | + BASE_SHA="${{ github.event.pull_request.base.sha }}" + HEAD_SHA="${{ github.event.pull_request.head.sha }}" + git fetch origin $BASE_SHA + git diff --name-only $BASE_SHA...$HEAD_SHA > changed_files.txt + CHANGED_FILES=$(cat changed_files.txt | grep -E '\.(js|ts|tsx)$' || true) + echo "::set-output name=changed::${CHANGED_FILES}" working-directory: OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }} + + - name: Lint Changed Files run: | - git fetch origin main - CHANGED_FILES=($(git diff --name-only --diff-filter=d origin/main | grep -E "\.(js|ts|tsx)$")) || true - if [ -n "$CHANGED_FILES" ]; then + CHANGED_FILES="${{ steps.files.outputs.changed }}" + if [[ -n "$CHANGED_FILES" && "$CHANGED_FILES" != "" ]]; then echo "Linting changed files..." - yarn lint "${CHANGED_FILES[@]}" + IFS=$'\n' read -r -a FILES_TO_LINT <<< "$CHANGED_FILES" + yarn lint "${FILES_TO_LINT[@]}" else - echo "No matching files changed." - fi \ No newline at end of file + echo "No matched files to lint." + fi + working-directory: OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }} From 5dcf215fea9d6c500dde0d93e8e4bc681f13454c Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 22 Dec 2023 00:33:33 +0000 Subject: [PATCH 5/5] remove redundant check Signed-off-by: Eric --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 81d46ef198..f26802c597 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -62,7 +62,7 @@ jobs: - name: Lint Changed Files run: | CHANGED_FILES="${{ steps.files.outputs.changed }}" - if [[ -n "$CHANGED_FILES" && "$CHANGED_FILES" != "" ]]; then + if [[ -n "$CHANGED_FILES" ]]; then echo "Linting changed files..." IFS=$'\n' read -r -a FILES_TO_LINT <<< "$CHANGED_FILES" yarn lint "${FILES_TO_LINT[@]}"