Skip to content

Commit d80030f

Browse files
committed
Fix ESLint setup and auto-format code
1 parent 9e672d8 commit d80030f

File tree

4 files changed

+63
-23
lines changed

4 files changed

+63
-23
lines changed

.github/workflows/link-check.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Lint Check on PR
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
jobs:
8+
lint:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout the repository
13+
uses: actions/checkout@v4
14+
15+
- name: Set up Node.js
16+
uses: actions/setup-node@v2
17+
with:
18+
node-version: '22.x'
19+
registry-url: 'https://registry.npmjs.org'
20+
21+
- name: Install dependencies
22+
run: npm install
23+
24+
- name: Run ESLint
25+
run: npm run lint

.husky/pre-commit

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
11
#!/usr/bin/env sh
2-
# Pre-commit hook to run Snyk and Talisman scans, completing both before deciding to commit
2+
# Pre-commit hook to run lint, Snyk and Talisman scans, completing all before deciding to commit
33

44
# Function to check if a command exists
55
command_exists() {
66
command -v "$1" >/dev/null 2>&1
77
}
88

9+
# Allow bypassing the hook with an environment variable
10+
if [ "$SKIP_HOOK" = "1" ]; then
11+
echo "Skipping lint, Snyk and Talisman scans (SKIP_HOOK=1)."
12+
exit 0
13+
fi
14+
15+
# Run ESLint check first
16+
echo "Running ESLint check..."
17+
npm run lint
18+
lint_exit_code=$?
19+
20+
if [ $lint_exit_code -ne 0 ]; then
21+
echo "ESLint check failed. Please fix the linting issues and try again."
22+
echo "You can run 'npm run format' to auto-fix most issues."
23+
exit 1
24+
fi
25+
26+
echo "ESLint check passed."
27+
928
# Check if Snyk is installed
1029
if ! command_exists snyk; then
1130
echo "Error: Snyk is not installed. Please install it and try again."
@@ -18,12 +37,6 @@ if ! command_exists talisman; then
1837
exit 1
1938
fi
2039

21-
# Allow bypassing the hook with an environment variable
22-
if [ "$SKIP_HOOK" = "1" ]; then
23-
echo "Skipping Snyk and Talisman scans (SKIP_HOOK=1)."
24-
exit 0
25-
fi
26-
2740
# Initialize variables to track scan results
2841
snyk_failed=false
2942
talisman_failed=false
@@ -63,7 +76,7 @@ if [ "$snyk_failed" = true ] || [ "$talisman_failed" = true ]; then
6376
exit 1
6477
fi
6578

66-
# If both scans pass, allow the commit
67-
echo "All scans passed. Proceeding with commit.cd ."
79+
# If all checks pass, allow the commit
80+
echo "All checks passed (ESLint, Snyk, Talisman). Proceeding with commit."
6881
rm -f snyk_output.log talisman_output.log
6982
exit 0

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323
"build:native-script": "webpack --config webpack/webpack.nativescript.js",
2424
"build": "npm run build:node && npm run build:web && npm run build:react-native && npm run build:native-script",
2525
"generate-docs": "node_modules/.bin/jsdoc --configure docs-config.json --verbose",
26-
"prepare": "npm run build",
27-
"husky-check": "npm run build && husky && chmod +x .husky/pre-commit",
28-
"pretest": "npm run build"
26+
"prepare": "husky",
27+
"husky-check": "npx husky && chmod +x .husky/pre-commit",
28+
"pretest": "npm run build",
29+
"lint": "eslint lib test"
2930
},
3031
"repository": {
3132
"type": "git",
@@ -72,7 +73,7 @@
7273
"@types/jest": "^30.0.0",
7374
"babel-loader": "^10.0.0",
7475
"clean-webpack-plugin": "^4.0.0",
75-
"dotenv": "^17.2.0",
76+
"dotenv": "^17.2.1",
7677
"jest": "^30.0.5",
7778
"jest-html-reporters": "^3.1.7",
7879
"jsdoc": "^4.0.4",
@@ -84,14 +85,15 @@
8485
"tap-json": "1.0.0",
8586
"ts-jest": "^29.4.0",
8687
"typescript": "^5.8.3",
87-
"webpack": "^5.100.2",
88+
"webpack": "^5.101.0",
8889
"webpack-cli": "^6.0.1",
8990
"webpack-merge": "6.0.1",
9091
"webpack-node-externals": "^3.0.0"
9192
},
9293
"dependencies": {
9394
"@contentstack/utils": "^1.4.1",
9495
"es6-promise": "^4.2.8",
96+
"husky": "^9.1.7",
9597
"localStorage": "1.0.4"
9698
}
9799
}

0 commit comments

Comments
 (0)