Skip to content

add auto install and auto config to eslint on github actions #2

add auto install and auto config to eslint on github actions

add auto install and auto config to eslint on github actions #2

Workflow file for this run

name: ESLint Auto-config
on:
pull_request:
branches:
- development
- main
jobs:
eslint:
name: Install ESLint and Update ESLint Configuration
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Verify and Install ESLint
run: |
if ! command -v eslint &> /dev/null; then
echo "ESLint not found. Installing ESLint..."
npm install eslint --save-dev
fi
- name: Install dependencies
run: npm install
- name: Modify .eslintrc.json
run: |
# Read the current .eslintrc.json file
contents=$(cat .eslintrc.json)
# Replace "indent": "off" with "indent": ["error", 2]
new_contents=$(echo "$contents" | jq '.rules.indent = ["error", 2]')
# Write the modified content back to .eslintrc.json
echo "$new_contents" > .eslintrc.json
- name: Auto-fix ESLint configuration
run: npx eslint --fix .eslintrc.json --no-ignore
- name: Commit changes
run: |
git config --global user.name "karleenmsrichards"
git config --global user.email "karleenmsrichards@gmail.com"
git add .eslintrc.json
git commit -m "Auto-install and auto-update ESLint configuration"
git push origin ${{ github.head_ref }}