Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Code Formatter Check!! Thoughts? #1162

Open
Tatsinnit opened this issue Jan 13, 2025 · 1 comment
Open

Add Code Formatter Check!! Thoughts? #1162

Tatsinnit opened this issue Jan 13, 2025 · 1 comment
Assignees
Labels
enhancement 🚀 New feature or request or improvements on existing code. github_actions Pull requests that update GitHub Actions code triage

Comments

@Tatsinnit
Copy link
Member

Tatsinnit commented Jan 13, 2025

This idea came through suggestions and discussion under this thread. https://github.com/Azure/vscode-aks-tools/pull/1161/files#r1912891247

I think given we have many contributors this could be a nice idea, hence sharing jsut for wider community thoughts. ❤

To use a TypeScript code formatter in a GitHub Actions workflow, a popular choice is Prettier, a widely adopted code formatter for TypeScript, JavaScript, and other languages. Here's how we can set it up:

Does anyone has any specific preference?

1. Add Prettier to Your Project

First, ensure Prettier is installed in our project:

npm install --save-dev prettier

Optionally, we can create a .prettierrc file to configure formatting preferences:

{
  "semi": true,
  "singleQuote": true,
  "tabWidth": 2
}

2. Set Up Prettier Check in GitHub Actions

Create a GitHub Actions workflow to check formatting on pull requests or pushes. Add the following YAML file to .github/workflows/format-check.yml:

name: Prettier Check

on:
  pull_request:
    paths:
      - '**/*.ts'
      - '**/*.tsx'
  push:
    branches:
      - main

jobs:
  prettier-check:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

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

      - name: Install dependencies
        run: npm install

      - name: Run Prettier check
        run: npx prettier --check "**/*.{ts,tsx,json,css,md}"

3. Run the Workflow

  • On each pull request, the workflow will check if the TypeScript files adhere to Prettier's formatting rules.
  • If formatting issues are detected, the action will fail and list the files that need reformatting.

Or we could add pre commit check like Husky

Please feel free to add thoughts and Idea. Thanks.

@Tatsinnit Tatsinnit self-assigned this Jan 13, 2025
@Tatsinnit Tatsinnit added enhancement 🚀 New feature or request or improvements on existing code. triage github_actions Pull requests that update GitHub Actions code labels Jan 13, 2025
@serbrech
Copy link
Member

Optionally, we can create a .prettierrc file to configure formatting preferences

That's the approach I would take. Encode it as part of the repo.
Here is the prettierrc file from the api spec repo:

https://github.com/Azure/azure-rest-api-specs/blob/main/.prettierrc.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 🚀 New feature or request or improvements on existing code. github_actions Pull requests that update GitHub Actions code triage
Projects
None yet
Development

No branches or pull requests

2 participants