name: Code linting

on:
  push:
    branches: [ main ]
    paths:
      - '.github/workflows/lint.yml'
      - 'src/scripts/**'
      - 'src/*.ts'
      - 'src/styles/**'
      - 'test/**'
      - 'test-e2e/**'
      - 'package-lock.json'
      - '.browserslistrc'
      - '.eslintrc.json'
      - '.editorconfig'
      - '.prettierrc.json'
      - '.stylelintrc.json'
  pull_request:
    paths:
      - '.github/workflows/lint.yml'
      - 'src/scripts/**'
      - 'src/*.ts'
      - 'src/styles/**'
      - 'test/**'
      - 'test-e2e/**'
      - 'package-lock.json'
      - '.browserslistrc'
      - '.eslintrc.json'
      - '.editorconfig'
      - '.prettierrc.json'
      - '.stylelintrc.json'

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 1

      - uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: 'npm'

      - name: Install dependencies
        run: npm ci --no-audit
        env:
          HUSKY_SKIP_INSTALL: true

      - name: run eslint
        run: npm run lint:js

      ## Can't use same eslint config for TypeScript and JavaScript
      ## TypeScript rules cause rule definition not found errors
      ## Can be re-enabled if this is resolved: https://github.com/eslint/eslint/issues/14851
      # - name: Lint JS bundle
      #   run: |
      #     npm run js:build
      #     npx eslint --no-ignore ./public/assets/scripts/*.js

      - name: run stylelint
        run: npm run lint:scss