Revision c7ac7e8ba0c7249a5e08e7d9532f8e4071373b71 authored by Firelight Flagboy on 31 October 2023, 16:25:18 UTC, committed by Firelight Flagboy on 31 October 2023, 16:25:18 UTC
1 parent aa3e1d6
Raw File
.pre-commit-config.yaml
exclude: ^misc/bench.py$

default_language_version:
  rust: 1.68.0
  node: 18.12.0

repos:
  ##############
  # Common stuff

  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.4.0 # Use the ref you want to point at
    hooks:
      - id: mixed-line-ending
        alias: eol
      - id: trailing-whitespace
      - id: end-of-file-fixer
        alias: eof

  - repo: local
    hooks:
      # - id: releaser
      #   name: releaser
      #   entry: python ./misc/releaser.py check
      #   language: python
      #   language_version: python3
      #   pass_filenames: false
      #   require_serial: true
      - id: license_headers
        name: license_headers
        alias: headers
        entry: python ./misc/license_headers.py add
        language: python
        language_version: python3
        # see: https://github.com/pre-commit/identify/blob/master/identify/extensions.py
        types_or: [ python, pyi, sql, rust, vue, ts, tsx, javascript, jsx ]

  - repo: https://github.com/adrienverge/yamllint
    rev: v1.29.0
    hooks:
      - id: yamllint

  - repo: https://github.com/streetsidesoftware/cspell-cli
    rev: v6.30.1
    hooks:
      - id: cspell
        stages:
          - manual
        args:
          - --config=./.cspell/cspell.config.yml
          - --no-progress
          - --dot
          - --no-must-find-files
          - --no-summary
          - --gitignore
        additional_dependencies:
          - "@cspell/dict-en_us"
          - "@cspell/dict-fr-fr"
          - "@cspell/dict-fr-reforme"
          - "@cspell/dict-bash"
          - "@cspell/dict-shell"
          - "@cspell/dict-win32"

  ########
  # Python

  # Long story short we cannot use pre-commit isolated venv system for mypy
  # given mypy requires to have access to the project dependencies.
  # We used to specify the list of dependencies actually needed by mypy as
  # additional dependencies to install before running the pre-commit but it
  # was incredibly error-prone and create random breakages.
  # Instead we go the pragmatic way by calling mypy trough poetry:
  # - `poetry run` will stick to the shell current virtual env
  # - if the shell is not into a virtual env, poetry will create one and install Parsec&deps
  # - lastly, mypy is started
  # So this is similar to what the developer does when running mypy from it dev shell \o/
  #
  # Now that we use poetry to run mypy, why not also use it for ruff & black !
  # This have the following benefits:
  # - It prevents going out of sync in tools version between pre-commit-config
  #   and poetry.lock
  # - It saves time on initial run because we don't have to create isolated
  #   virtualenv for those tools
  # - Pre-commit hook are really simple, so it's no big deal to inline them.
  # - Pre-commit hook need sometime tweaks (e.g. ruff hook not correctly
  #   handling .pyi), it's more readable then to have all the config here then.
  - repo: local
    hooks:
      - id: ruff
        name: ruff (using `poetry run ruff`)
        entry: poetry run ruff
        require_serial: true
        language: system
        types_or: [ python, pyi ]
        args:
          [
            --extend-exclude=parsec/core/gui/_resources_rc.py,
            --extend-exclude=parsec/core/gui/ui/*,
            --extend-exclude=oxidation/*,
            --fix,
          ]

      - id: black
        name: black (using `poetry run black`)
        entry: poetry run black
        require_serial: true
        language: system
        types_or: [ python, pyi ]
        args:
          [
            --line-length=100,
            --exclude=parsec/core/gui/_resources_rc.py,
            --exclude=parsec/core/gui/ui/,
          ]

      - id: mypy
        name: Mypy (using `poetry run mypy`)
        entry: poetry run mypy
        require_serial: true
        language: system
        types_or: [ python, pyi ]
        files: ^(parsec|tests|misc)/

  ######
  # Rust

  - repo: local
    hooks:
      - id: fmt
        name: fmt
        entry: cargo fmt
        language: system
        types: [ rust ]
        args: [ -- ]

      - id: clippy
        name: clippy
        entry: cargo clippy
        language: system
        types: [ rust ]
        pass_filenames: false
        args:
          [
            --workspace,
            --tests,
            --bins,
            --lib,
            --exclude=libparsec_bindings_android,
            --exclude=libparsec_bindings_web,
            --exclude=libparsec_bindings_electron,
            --,
            --deny=warnings,
            --deny=clippy::undocumented_unsafe_blocks,
          ]

  ####
  # Js

  - repo: local
    hooks:
      - id: eslint
        name: eslint
        entry: eslint
        language: node
        files: ^oxidation/client/
        # see: https://github.com/pre-commit/identify/blob/master/identify/extensions.py
        types_or: [ vue, ts, tsx, javascript, jsx ]
        args: [ --config=oxidation/client/.eslintrc.cjs ]
        stages:
          - manual
        # Deps should be kept updated with `oxidation/client/package-lock.json` !
        additional_dependencies:
          - "@intlify/eslint-plugin-vue-i18n@2.0.0"
          - "@typescript-eslint/eslint-plugin@5.55.0"
          - "@typescript-eslint/parser@5.55.0"
          - "@vue/eslint-config-typescript@10.0.0"
          - eslint@8.36.0
          - eslint-config-standard-with-typescript@34.0.1
          - eslint-plugin-cypress@2.12.1
          - eslint-plugin-import@2.27.5
          - eslint-plugin-n@15.6.1
          - eslint-plugin-promise@6.1.1
          - eslint-plugin-vue@8.7.1

  ######
  # JSON

  - repo: https://github.com/python-jsonschema/check-jsonschema
    rev: 0.22.0
    hooks:
      - id: check-jsonschema
        name: Validate protocol files with jsonschema
        alias: check-protocol-schema
        types_or: [ json5 ]
        files: ^oxidation/libparsec/crates/protocol/schema/
        args: [ --schemafile, json_schema/protocol.schema.json ]
        additional_dependencies: [ json5 ]

      - id: check-jsonschema
        name: Validate data files with jsonschema
        alias: check-data-schema
        types_or: [ json5 ]
        files: ^oxidation/libparsec/crates/types/schema/
        args: [ --schemafile, json_schema/data.schema.json ]
        additional_dependencies: [ json5 ]

      - id: check-metaschema
        files: ^json_schema/

      - id: check-jsonschema
        name: Validate Read the doc configuration files
        alias: check-readthedoc
        files: .readthedocs.yml
        args: [ --schemafile, https://raw.githubusercontent.com/readthedocs/readthedocs.org/main/readthedocs/rtd_tests/fixtures/spec/v2/schema.json ]

      - id: check-jsonschema
        name: Validate snapcraft config
        alias: check-snapcraft
        files: ^packaging/snap/snap/snapcraft.yaml
        args: [ --schemafile, https://raw.githubusercontent.com/snapcore/snapcraft/main/schema/snapcraft.json ]
back to top