name: Linters
permissions: read-all

on:
  pull_request:
    branches:
    - main
  workflow_dispatch:

jobs:
  jshint:
    name: Javascript Linter
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v5
    - name: Install linters
      run: |
        sudo npm install -g jshint@2.13.6 eslint@8.57.0
    - name: Run jshint
      run: jshint internal/ui/static/js/*.js
    - name: Run ESLint
      run: eslint internal/ui/static/js/*.js

  golangci:
    name: Golang Linters
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: actions/setup-go@v5
        with:
          go-version: "1.24.x"
      - uses: golangci/golangci-lint-action@v8
        with:
          args: >
            --timeout 10m
            --disable errcheck
            --enable sqlclosecheck,misspell,whitespace,gocritic
      - name: Run gofmt linter
        run: gofmt -d -e .

  commitlint:
    if: github.event_name == 'pull_request'
    name: Commit Linter
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
        with:
          fetch-depth: 0
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.13'
      - name: Validate PR commits
        run: python3 .github/workflows/scripts/commit-checker.py --base ${{ github.event.pull_request.base.sha }} --head ${{ github.event.pull_request.head.sha }}
