Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Auto-format with Prettier (format and push changes) #1057

Copy link
Copy link

Description

@Alex-is-Gonzalez
Issue body actions

Description

What it does: Runs Prettier to reformat code and automatically commits the formatting changes back to the branch (useful for keeping style consistent).

name: Format with Prettier

on:
  workflow_dispatch:
  pull_request:
    types: [opened, synchronize]

jobs:
  prettier:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout (full)
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Use Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '18'

      - name: Install dependencies
        run: |
          npm ci || npm install
          npm install --no-save prettier

      - name: Run Prettier (format)
        run: npx prettier --write "**/*.{js,jsx,ts,tsx,json,md}"

      - name: Commit formatted changes
        uses: EndBug/add-and-commit@v9
        with:
          message: "chore: format code with Prettier"
          add: "."

Step-by-step

  1. Add the file .github/workflows/format-prettier.yml.

  2. Ensure your repo has a package.json (or npm ci will fallback to npm install).

  3. Commit & push. Run the workflow manually from the Actions tab or open a PR.

  4. If formatting changed files, the action commits them back to the branch. Inspect the PR to see the formatting commit.

Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

Morty Proxy This is a proxified and sanitized view of the page, visit original site.