default_language_version:
  # force all unspecified python hooks to run python3
  python: default

repos:
  # Run manually in CI skipping the branch checks
  - repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.14.10
    hooks:
      - id: ruff
        name: "Ruff check"
        args:
          - --fix
      - id: ruff-format
        name: "Ruff format"
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v6.0.0
    hooks:
      - id: check-executables-have-shebangs
        name: "Check scripts"
        stages: [manual]
      - id: no-commit-to-branch
        name: "Check branch"
        args:
          - --branch=main
  - repo: https://github.com/asottile/pyupgrade
    rev: v3.21.2
    hooks:
      - id: pyupgrade
        name: "Check Py upgrade"
        args: [--py311-plus]
  - repo: https://github.com/codespell-project/codespell
    rev: v2.4.1
    hooks:
      - id: codespell
        name: "Check Code Spelling"
        args:
          - --ignore-words-list=aiport,astroid,checkin,currenty,hass,iif,incomfort,lookin,nam,NotIn
          - --skip="./.*,*.csv,*.json,*.ambr"
          - --quiet-level=2
        exclude_types: [csv, json]
        exclude: ^userdata/|^fixtures/
  - repo: https://github.com/PyCQA/bandit
    rev: 1.9.2
    hooks:
      - id: bandit
        name: "Bandit checking"
        args:
          - --quiet
          - --format=custom
          - --configfile=tests/bandit.yaml
        files: ^(plugwise|tests)/.+\.py$
  - repo: https://github.com/adrienverge/yamllint.git
    rev: v1.37.1
    hooks:
      - id: yamllint
        name: "YAML linting"
  - repo: https://github.com/shellcheck-py/shellcheck-py
    rev: v0.10.0.1
    hooks:
      - id: shellcheck
        name: "Shell checking"
        args:
          - --external-sources
  - repo: https://github.com/cdce8p/python-typing-update
    rev: v0.8.1
    hooks:
      # Run `python-typing-update` hook manually from time to time
      # to update python typing syntax.
      # Will require manual work, before submitting changes!
      - id: python-typing-update
        name: "Python typing"
        stages: [manual]
        args:
          - --py39-plus
          - --force
          - --keep-updates
        files: ^(plugwise|tests)/.+\.py$
  - repo: local
    hooks:
      # Run mypy through our wrapper script in order to get the possible
      # pyenv and/or virtualenv activated; it may not have been e.g. if
      # committing from a GUI tool that was not launched from an activated
      # shell.
      - id: setup
        name: "Setup"
        entry: /usr/bin/env bash -c 'test -d ./venv || scripts/setup.sh'
        language: script
      - id: setup_test
        name: "Setup (extended for testing"
        entry: /usr/bin/env bash -c 'test -f ./tmp/biome || scripts/setup_test.sh pre-commit'
        language: script
      - id: userdata
        name: "Validating userdata"
        entry: scripts/pre-commit.sh
        language: script
        types: [python]
        pass_filenames: false
      - id: mypy
        name: "Running MyPy"
        entry: scripts/run-in-env.sh mypy
        language: script
        types: [python]
        require_serial: true
        files: ^plugwise/$
      - id: pylint
        name: "PyLinting"
        entry: scripts/run-in-env.sh pylint -j 0
        language: script
        types: [python]
        files: ^plugwise/.+\.py$
      - id: testing
        name: "Performing Tests"
        # yamllint disable-line rule:line-length
        entry: /usr/bin/env bash -c 'exec env GITHUB_ACTIONS="1" NO_FIXTURES="1" scripts/tests_and_coverage.sh test_and_coverage'
        language: script
        pass_filenames: false
      - id: biome
        name: "Biome (prettier)"
        entry: ./tmp/biome check fixtures/ plugwise/ tests/ --files-ignore-unknown=true --no-errors-on-unmatched --json-formatter-indent-width=2 --json-formatter-indent-style=space
        language: script
  - repo: https://github.com/igorshubovych/markdownlint-cli
    rev: v0.47.0
    hooks:
      - id: markdownlint
