From 5f0da0b2ac9b38c728f1fc73bc21fbe0ce53106e Mon Sep 17 00:00:00 2001 From: Ryan Liang Date: Thu, 11 Jan 2024 13:54:22 -0800 Subject: [PATCH 1/6] Add eslint workflow Signed-off-by: Ryan Liang --- .github/workflows/lint.yml | 80 +++++++++++++++++++++++++++++++ gantt-chart/.cypress/.eslintrc.js | 17 +++++++ gantt-chart/.eslintignore | 7 +++ gantt-chart/.eslintrc.js | 59 +++++++++++++++++++++++ gantt-chart/.eslintrc.yaml | 9 ---- gantt-chart/package.json | 4 +- 6 files changed, 165 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/lint.yml create mode 100644 gantt-chart/.cypress/.eslintrc.js create mode 100644 gantt-chart/.eslintignore create mode 100644 gantt-chart/.eslintrc.js delete mode 100644 gantt-chart/.eslintrc.yaml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..e838ef8 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,80 @@ +name: Lint + +on: [pull_request] + +env: + PLUGIN_NAME: dashboards-visualizations + OPENSEARCH_DASHBOARDS_VERSION: "main" + +jobs: + build: + name: Lint + runs-on: ubuntu-latest + + steps: + - name: Checkout Plugin + uses: actions/checkout@v2 + + - name: Checkout OpenSearch Dashboards + uses: actions/checkout@v2 + with: + repository: opensearch-project/Opensearch-Dashboards + ref: ${{ env.OPENSEARCH_DASHBOARDS_VERSION }} + path: OpenSearch-Dashboards + + - name: Install Gantt Chart to Opensearch Dashboards Plugins Dir + run: | + mv gantt-chart ./OpenSearch-Dashboards/plugins + + - name: Get node and yarn versions + working-directory: ${{ env.WORKING_DIR }} + id: versions_step + run: | + echo "::set-output name=node_version::$(cat ./OpenSearch-Dashboards/.nvmrc | cut -d"." -f1)" + echo "::set-output name=yarn_version::$(node -p "(require('./OpenSearch-Dashboards/package.json').engines.yarn).match(/[.0-9]+/)[0]")" + + - name: Setup node + uses: actions/setup-node@v1 + with: + node-version: ${{ steps.versions_step.outputs.node_version }} + registry-url: "https://registry.npmjs.org" + + - name: Install correct yarn version for OpenSearch Dashboards + run: | + npm uninstall -g yarn + echo "Installing yarn ${{ steps.versions_step.outputs.yarn_version }}" + 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 + + - name: Get list of changed files using GitHub Action + uses: lots0logs/gh-action-get-changed-files@2.2.2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Check Changes of Files + run: | + echo "FILES_MODIFIED=$(cat ${HOME}/files_modified.json)" + echo "FILES_ADDED=$(cat ${HOME}/files_added.json)" + echo "FILES_RENAMED=$(cat ${HOME}/files_renamed.json)" + echo "FILES_DELETED=$(cat ${HOME}/files_deleted.json)" + + - name: Lint Changed Files + run: | + jq -r '.[]' ${HOME}/files_modified.json ${HOME}/files_added.json | sort | uniq > /tmp/changed_files.txt + CHANGED_FILES=$(cat /tmp/changed_files.txt) + echo "These are the changed files: $CHANGED_FILES" + if [[ -n "$CHANGED_FILES" ]]; then + echo "Linting changed files..." + while IFS= read -r file; do + if [[ $file == *.js || $file == *.ts || $file == *.tsx ]]; then + echo "linting file $file" + yarn lint "$file" + fi + done < /tmp/changed_files.txt + else + echo "No matched files to lint." + fi + working-directory: OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }} diff --git a/gantt-chart/.cypress/.eslintrc.js b/gantt-chart/.cypress/.eslintrc.js new file mode 100644 index 0000000..26edd9b --- /dev/null +++ b/gantt-chart/.cypress/.eslintrc.js @@ -0,0 +1,17 @@ +module.exports = { + root: true, + extends: ['plugin:cypress/recommended'], + env: { + 'cypress/globals': true, + }, + plugins: ['cypress'], + rules: { + // Add cypress specific rules here + 'cypress/no-assigning-return-values': 'error', + 'cypress/no-unnecessary-waiting': 'error', + 'cypress/assertion-before-screenshot': 'warn', + 'cypress/no-force': 'warn', + 'cypress/no-async-tests': 'error', + }, + }; + \ No newline at end of file diff --git a/gantt-chart/.eslintignore b/gantt-chart/.eslintignore new file mode 100644 index 0000000..c5e1946 --- /dev/null +++ b/gantt-chart/.eslintignore @@ -0,0 +1,7 @@ +node_modules +/data +/build +/target +/.eslintrc.js +/cypress.config.js +!.cypress/ diff --git a/gantt-chart/.eslintrc.js b/gantt-chart/.eslintrc.js new file mode 100644 index 0000000..12f093d --- /dev/null +++ b/gantt-chart/.eslintrc.js @@ -0,0 +1,59 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +const LICENSE_HEADER = `/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */`; + +module.exports = { + root: true, + extends: [ + '@elastic/eslint-config-kibana', + 'plugin:@elastic/eui/recommended', + 'plugin:react-hooks/recommended', + 'plugin:jest/recommended', + 'plugin:prettier/recommended', + ], + + rules: { + '@typescript-eslint/no-unused-vars': [ + 'error', + { + argsIgnorePattern: '^_', + varsIgnorePattern: '^_', + caughtErrorsIgnorePattern: '^_', + }, + ], + '@osd/eslint/no-restricted-paths': [ + 'error', + { + basePath: __dirname, + zones: [ + { + target: ['(public|server)/**/*'], + from: ['../../packages/**/*','packages/**/*'], + }, + ], + }, + ], + }, + overrides: [ + { + files: ['**/*.{js,ts,tsx}'], + rules: { + '@typescript-eslint/no-explicit-any': 'warn', + 'no-console': 0, + '@osd/eslint/require-license-header': [ + 'error', + { + licenses: [LICENSE_HEADER], + }, + ], + }, + }, + ], + "ignorePatterns": ["**/*.d.ts"] +}; diff --git a/gantt-chart/.eslintrc.yaml b/gantt-chart/.eslintrc.yaml deleted file mode 100644 index 593afaa..0000000 --- a/gantt-chart/.eslintrc.yaml +++ /dev/null @@ -1,9 +0,0 @@ ---- -extends: '@elastic/kibana' - -settings: - import/resolver: - '@osd/eslint-import-resolver-kibana': - rootPackageName: 'gantt-chart' - pluginPaths: - - . diff --git a/gantt-chart/package.json b/gantt-chart/package.json index 6391dac..88e7f00 100644 --- a/gantt-chart/package.json +++ b/gantt-chart/package.json @@ -5,8 +5,8 @@ "scripts": { "osd": "node ../../scripts/osd", "opensearch": "node ../../scripts/opensearch", - "lint": "eslint .", - "lint:style": "node ../../scripts/stylelint", + "lint:es": "node ../../scripts/eslint", + "lint": "yarn lint:es", "build": "yarn plugin-helpers build", "plugin-helpers": "node ../../scripts/plugin_helpers", "test": "../../node_modules/.bin/jest --config ./test/jest.config.js", From 3877830ca61779e17b261ba98c187c8a66aee9df Mon Sep 17 00:00:00 2001 From: Ryan Liang Date: Thu, 11 Jan 2024 14:00:41 -0800 Subject: [PATCH 2/6] Correct the plugin name Signed-off-by: Ryan Liang --- .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 e838ef8..7caaa7a 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -46,7 +46,7 @@ jobs: npm i -g yarn@${{ steps.versions_step.outputs.yarn_version }} - name: Bootstrap the plugin - working-directory: OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }} + working-directory: OpenSearch-Dashboards/plugins/gantt-chart run: yarn osd bootstrap - name: Get list of changed files using GitHub Action From b023da7c89840102f8d297cee521312d55cdacd7 Mon Sep 17 00:00:00 2001 From: Ryan Liang Date: Thu, 11 Jan 2024 14:18:34 -0800 Subject: [PATCH 3/6] Correct the plugin name2 Signed-off-by: Ryan Liang --- .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 7caaa7a..42ddda4 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -77,4 +77,4 @@ jobs: else echo "No matched files to lint." fi - working-directory: OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }} + working-directory: OpenSearch-Dashboards/plugins/gantt-chart From 8dc2b5d73b2ca6e2794316021199847a5ce38be3 Mon Sep 17 00:00:00 2001 From: Ryan Liang Date: Thu, 11 Jan 2024 14:37:46 -0800 Subject: [PATCH 4/6] change the linting running dir Signed-off-by: Ryan Liang --- .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 42ddda4..3d08f5c 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -71,7 +71,7 @@ jobs: while IFS= read -r file; do if [[ $file == *.js || $file == *.ts || $file == *.tsx ]]; then echo "linting file $file" - yarn lint "$file" + yarn lint "../$file" fi done < /tmp/changed_files.txt else From 788515af08c6d5aeaae08b8f62a80332cb561a22 Mon Sep 17 00:00:00 2001 From: Ryan Liang Date: Fri, 12 Jan 2024 10:19:13 -0800 Subject: [PATCH 5/6] Fix some comments Signed-off-by: Ryan Liang --- .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 3d08f5c..5f5995a 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -69,7 +69,7 @@ jobs: if [[ -n "$CHANGED_FILES" ]]; then echo "Linting changed files..." while IFS= read -r file; do - if [[ $file == *.js || $file == *.ts || $file == *.tsx ]]; then + if [[ $file =~ ^gantt-chart/.+\.(js|ts|tsx)$ ]]; then echo "linting file $file" yarn lint "../$file" fi From 3ea46785588c1059d06ea999640cd5891a13ac06 Mon Sep 17 00:00:00 2001 From: Ryan Liang Date: Fri, 12 Jan 2024 10:22:00 -0800 Subject: [PATCH 6/6] Add stylelint back Signed-off-by: Ryan Liang --- gantt-chart/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/gantt-chart/package.json b/gantt-chart/package.json index 88e7f00..61b6286 100644 --- a/gantt-chart/package.json +++ b/gantt-chart/package.json @@ -5,6 +5,7 @@ "scripts": { "osd": "node ../../scripts/osd", "opensearch": "node ../../scripts/opensearch", + "lint:style": "node ../../scripts/stylelint", "lint:es": "node ../../scripts/eslint", "lint": "yarn lint:es", "build": "yarn plugin-helpers build",