From 5c2f358c1d49e8b7f80229a15cc6c2bb29a49358 Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 15 Dec 2023 17:11:13 +0000 Subject: [PATCH] add linting CI Signed-off-by: Eric --- .eslintignore | 7 +++++ .eslintrc.js | 31 +++++++++++++++++++ .github/workflows/lint.yml | 62 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 .eslintignore create mode 100644 .github/workflows/lint.yml diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000000..126c839647 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,7 @@ +node_modules +/data +/build +/target +/.eslintrc.js +/cypress.config.js +!.cypress/ \ No newline at end of file diff --git a/.eslintrc.js b/.eslintrc.js index 35fde0175d..6ba689e332 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -14,7 +14,37 @@ module.exports = { '@elastic/eslint-config-kibana', 'plugin:@elastic/eui/recommended', 'plugin:react-hooks/recommended', + "eslint:recommended", + "plugin:cypress/recommended", + "plugin:import/recommended", + "prettier" ], + env: { + 'cypress/globals': true, + }, + plugins: [ + 'cypress', + ], + rules: { + '@osd/eslint/no-restricted-paths': [ + 'error', + { + basePath: __dirname, + zones: [ + { + target: ['(public|server)/**/*'], + from: ['../../packages/**/*','packages/**/*'], + }, + ], + }, + ], + // 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', + }, overrides: [ { files: ['**/*.{js,ts,tsx}'], @@ -29,4 +59,5 @@ module.exports = { }, }, ], + "ignorePatterns": ["**/*.d.ts"] }; diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000000..270de891de --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,62 @@ +name: Lint + +on: [push, pull_request] + +jobs: + build: + name: Lint + runs-on: ubuntu-latest + + permissions: + contents: read + packages: read + statuses: write + + steps: + - name: Checkout OpenSearch Dashboards + uses: actions/checkout@v2 + with: + repository: opensearch-project/Opensearch-Dashboards + ref: ${{ env.OPENSEARCH_DASHBOARDS_VERSION }} + path: OpenSearch-Dashboards + + - name: Checkout dashboards observability + uses: actions/checkout@v2 + with: + path: OpenSearch-Dashboards/plugins/dashboards-observability + + - 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 + run: | + cd OpenSearch-Dashboards/plugins/dashboards-observability + yarn osd bootstrap + + - name: lint code base + run: | + cd OpenSearch-Dashboards/plugins/dashboards-observability + git fetch origin main + CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRTUXB origin/main | grep -E "\.(js|ts|tsx)$") + if [ -n "$CHANGED_FILES" ]; then + echo "Linting changed files..." + yarn lint $CHANGED_FILES + else + echo "No JavaScript/TypeScript files changed." + fi \ No newline at end of file