diff --git a/.babelrc b/.babelrc index 0a9ba4b..25f934a 100644 --- a/.babelrc +++ b/.babelrc @@ -13,12 +13,8 @@ "env": { "test": { - "presets": [ - [ - "@babel/preset-env" - ] - ], + "presets": [["@babel/preset-env"]], "plugins": [] - }, - }, + } + } } diff --git a/.github/workflows/format.yaml b/.github/workflows/format.yaml new file mode 100644 index 0000000..275d4c5 --- /dev/null +++ b/.github/workflows/format.yaml @@ -0,0 +1,66 @@ +name: Format Code with Prettier + +on: + pull_request: + branches: + - main + push: + branches: + - main + +permissions: + contents: write + +jobs: + prettier: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + repository: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name || github.repository }} + ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.ref }} + fetch-depth: 0 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '22' + + - name: Check Prettier formatting + id: prettier-check + run: | + if prettier --check .; then + echo "needs_formatting=false" >> $GITHUB_OUTPUT + echo "✅ Code is already formatted" + exit 0 + else + echo "needs_formatting=true" >> $GITHUB_OUTPUT + echo "❌ Code needs formatting" + exit 1 + fi + continue-on-error: true + + - name: Run Prettier + if: steps.prettier-check.outputs.needs_formatting == 'true' + run: npx prettier --write . + + - name: Commit and push formatted code + if: steps.prettier-check.outputs.needs_formatting == 'true' && github.event_name == 'push' + run: | + # Configure git user + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + # Stage changes + git add . + + # Only commit if there are changes + if [ -n "$(git diff --cached)" ]; then + git commit -m "chore: format code with Prettier [skip ci]" + git push + else + echo "🎉 No formatting changes to commit." + fi diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 08b4b6b..c48d325 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -12,8 +12,8 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-node@v3 with: - node-version-file: '.nvmrc' - cache: 'npm' + node-version-file: '.nvmrc' + cache: 'npm' - name: Install dependencies run: npm ci --no-audit - name: Test diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..9f97022 --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +target/ \ No newline at end of file diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..346219b --- /dev/null +++ b/.prettierrc @@ -0,0 +1,10 @@ +{ + "semi": true, + "trailingComma": "es5", + "singleQuote": true, + "printWidth": 100, + "tabWidth": 2, + "useTabs": false, + "bracketSpacing": true, + "arrowParens": "avoid" +} \ No newline at end of file