Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linter CI #1301

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
/data
/build
/target
/.eslintrc.js
/cypress.config.js
!.cypress/
31 changes: 31 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check warning on line 1 in .eslintrc.js

View workflow job for this annotation

GitHub Actions / Lint

File ignored by default.
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -14,7 +14,37 @@
'@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': [
mengweieric marked this conversation as resolved.
Show resolved Hide resolved
'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}'],
Expand All @@ -29,4 +59,5 @@
},
},
],
"ignorePatterns": ["**/*.d.ts"]
};
61 changes: 61 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Lint

on: [push, pull_request]

env:
PLUGIN_NAME: dashboards-observability
OPENSEARCH_DASHBOARDS_VERSION: 'main'

jobs:
build:
name: Lint
runs-on: ubuntu-latest

steps:
- name: Checkout OpenSearch Dashboards
uses: actions/checkout@v2
with:
repository: opensearch-project/Opensearch-Dashboards
ref: ${{ env.OPENSEARCH_DASHBOARDS_VERSION }}
mengweieric marked this conversation as resolved.
Show resolved Hide resolved
path: OpenSearch-Dashboards

- name: Checkout dashboards observability
uses: actions/checkout@v2
with:
path: OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}

- 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: lint code base
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)$")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why --diff-filter? seems unnecessary

Copy link
Collaborator Author

@mengweieric mengweieric Dec 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for not including files that are deleted, and also with this it explicitly shows what are included and what are not. I actually tried before to run CI without these flags but it was getting errors, and it runs successfully after adding it back. without flags: https://github.com/mengweieric/dashboards-observability/actions/runs/7254224280/job/19762669894. Do you have any other suggestions that it can be written differently without those flags but do the work?

Copy link
Member

@joshuali925 joshuali925 Dec 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you just want to exclude deleted, it should be --diff-filter=d?

also you are right it'll cause issues with deleted files

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The --diff-filter we specify here are actually specifying what we select from git diff if I'm not mistaken: https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---diff-filterACDMRTUXB82308203, therefore here without 'D' we skipped deleted files but select all others.

if [ -n "$CHANGED_FILES" ]; then
echo "Linting changed files..."
yarn lint $CHANGED_FILES
mengweieric marked this conversation as resolved.
Show resolved Hide resolved
else
echo "No JavaScript/TypeScript files changed."
fi
Loading