# WARNING!
#
# When making changes to auto-formatters used in pre-commit hooks, you are
# likely to cause merge conflicts with main and/or other pull requests.
# Fixing them might revert other people's work. Expect pain!
# To avoid accidental reversions and keep it easy to review, please make sure
# that changes here are in a pull request by themselves, that it consists of
# two commits:
#
# 1. The changes to this file
# 2. Changes made by running `python3 -m pre_commit run --all-files`.
#
# Then each time your pull request is blocked by a merge conflict, do the
# following steps:
#
#    git reset HEAD^1 && git checkout -f    # discard the change commit
#    git rebase main                        # re-apply other people's changes
#    python3 -m pre_commit run --all-files  # re-run the rules
#    git add .                              # add the newly changed files
#    git commit -m 'apply pre-commit'       # commit it
#    git push -f                            # force push back to your branch
#
# Keep in mind you may have to do this a few times, as changes here may impact
# other pull requests. Try to keep it up-to-date so they can go in when it'll
# cause least disruption.
#
# /WARNING!

exclude: build|stubs|^bot/templates/$|openassistant/templates|docs/docs/api/openapi.json|scripts/postprocessing/regex_pii_detector.py

default_language_version:
  python: python3

ci:
  autofix_prs: true
  autoupdate_commit_msg: "[pre-commit.ci] pre-commit suggestions"
  autoupdate_schedule: quarterly
  skip: ["next-lint-website"] # list of hook ids to skip only in pre-commit.ci

repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.4.0
    hooks:
      - id: trailing-whitespace
      - id: check-ast
      - id: check-yaml
        # Always check YAML but skip a few YAML files that are auto-generated
        # and which break the standard YAML check.  The alternative would be to
        # skip any unsafe errors (and thus break YAML compatibility) or use
        # some other checker that may not work in general.
        exclude: ^copilot/.*/addons/.*$
      - id: check-json
      - id: check-case-conflict
      - id: detect-private-key
      - id: fix-encoding-pragma
        args: [--remove]
      - id: forbid-submodules
      - id: mixed-line-ending
      - id: requirements-txt-fixer
      - id: check-executables-have-shebangs
      - id: check-shebang-scripts-are-executable
      - id: check-byte-order-marker
      - id: check-symlinks
      - id: check-merge-conflict
      - id: check-added-large-files
        args: [--maxkb=1024]
      - id: end-of-file-fixer

  - repo: https://github.com/psf/black
    rev: 23.3.0
    hooks:
      - id: black-jupyter

  - repo: https://github.com/pycqa/isort
    rev: 5.12.0
    hooks:
      - id: isort
        args: ["--profile", "black", "--filter-files"]

  - repo: https://github.com/charliermarsh/ruff-pre-commit
    rev: v0.0.263
    hooks:
      - id: ruff
        args: ["--fix"]

  - repo: https://github.com/pre-commit/mirrors-prettier
    rev: v2.7.1
    hooks:
      - id: prettier
        args:
          [
            --prose-wrap=always,
            --write,
            --ignore-path=./website/.prettierignore,
          ]

  - repo: local
    hooks:
      - id: next-lint-website
        name: Lint website
        files: ^website/
        exclude: ^website/node_modules/
        types_or: [javascript, jsx, ts, tsx]
        language: node
        pass_filenames: false
        entry: website/next-lint.js
