Skip to content

Commit b5293f0

Browse files
committed
ESLint workflow and add pre-commit hooks
1 parent fed14c5 commit b5293f0

File tree

4 files changed

+14406
-14178
lines changed

4 files changed

+14406
-14178
lines changed

.github/workflows/linter.yml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
name: ESLint
1+
name: ESLint & Prettier
22

33
on:
44
pull_request:
55
branches: [master]
66

77
jobs:
88
lint:
9-
name: Lint updated JavaScript files with ESLint
9+
name: Lint and format-check changed JS files
1010

1111
runs-on: ubuntu-latest
1212

@@ -26,23 +26,24 @@ jobs:
2626
- name: Get changed JavaScript files
2727
id: get_files
2828
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
29+
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
3330
34-
- name: Install dependencies
35-
run: npm ci
31+
if [ -s changed-js-files.txt ]; then
32+
echo "has_files=true" >> "$GITHUB_OUTPUT"
33+
else
34+
echo "has_files=false" >> "$GITHUB_OUTPUT"
35+
fi
3636
3737
- name: Run ESLint on changed files
38-
if: env.files != ''
38+
if: steps.get_files.outputs.has_files == 'true'
3939
run: |
4040
echo "Linting the following files:"
41-
echo "$files"
42-
echo "$files" | xargs npx eslint
41+
cat changed-js-files.txt
42+
xargs -r npx eslint < changed-js-files.txt
4343
- name: Run Prettier check on changed files
44-
if: env.files != ''
44+
if: steps.get_files.outputs.has_files == 'true'
4545
run: |
4646
echo "Checking formatting for the following files:"
47-
echo "$files"
48-
echo "$files" | xargs npx prettier --check
47+
cat changed-js-files.txt
48+
xargs -r npx prettier --check < changed-js-files.txt
49+

.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)