Skip to content

Commit a8b4133

Browse files
authored
Merge pull request #6159 from sonalgaud12/cli-fix
Fix: ESLint workflow and add pre-commit hooks
2 parents c270201 + fe23b21 commit a8b4133

File tree

4 files changed

+14409
-14183
lines changed

4 files changed

+14409
-14183
lines changed

.github/workflows/linter.yml

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
name: ESLint
2-
1+
name: ESLint & Prettier
32
on:
43
pull_request:
54
branches: [master]
6-
75
jobs:
86
lint:
9-
name: Lint updated JavaScript files with ESLint
10-
7+
name: Lint and format-check changed JS files
118
runs-on: ubuntu-latest
12-
139
steps:
1410
- name: Checkout code
1511
uses: actions/checkout@v4
@@ -23,26 +19,29 @@ jobs:
2319
node-version: 20.x
2420
cache: "npm"
2521

22+
- name: Install dependencies
23+
run: npm ci
24+
2625
- name: Get changed JavaScript files
2726
id: get_files
2827
run: |
29-
CHANGED_FILES=$(git diff --diff-filter=ACMRT --name-only ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} -- '*.js')
30-
echo "files<<EOF" >> $GITHUB_ENV
31-
echo "$CHANGED_FILES" >> $GITHUB_ENV
32-
echo "EOF" >> $GITHUB_ENV
33-
34-
- name: Install dependencies
35-
run: npm ci
28+
git diff --diff-filter=ACMRT --name-only ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} -- '*.js' '*.mjs' ':!node_modules/**' > changed-js-files.txt
29+
if [ -s changed-js-files.txt ]; then
30+
echo "has_files=true" >> "$GITHUB_OUTPUT"
31+
else
32+
echo "has_files=false" >> "$GITHUB_OUTPUT"
33+
fi
3634
3735
- name: Run ESLint on changed files
38-
if: env.files != ''
36+
if: steps.get_files.outputs.has_files == 'true'
3937
run: |
4038
echo "Linting the following files:"
41-
echo "$files"
42-
echo "$files" | xargs npx eslint
39+
cat changed-js-files.txt
40+
xargs -r npx eslint < changed-js-files.txt
41+
4342
- name: Run Prettier check on changed files
44-
if: env.files != ''
43+
if: steps.get_files.outputs.has_files == 'true'
4544
run: |
4645
echo "Checking formatting for the following files:"
47-
echo "$files"
48-
echo "$files" | xargs npx prettier --check
46+
cat changed-js-files.txt
47+
xargs -r npx prettier --check < changed-js-files.txt

.husky/pre-commit

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env sh
2+
npx lint-staged

0 commit comments

Comments
 (0)