Hacker News new | past | comments | ask | show | jobs | submit login

We recently started using a lot of auto-formatters across our Python/iOS/Android code, as the team has grown (there are 17 people touching code at the company now).

I like auto-formatting, because it makes PRs less stressful to commit, and makes review comments more focused on stuff that actually matters. How exactly the code gets formatted is not something I care much about, just that it happens consistently, and I don't have to think about it.

We use pre-commit with Black and other formatters, such that it formats the code, warns you stuff changed, prevents the commit, and makes you recommit with the formatting patch included.

Because pre-commit can be tough to google sometimes, depending on your search history, here's the direct link: https://pre-commit.com/

I assumed the poster meant the git concept of pre-commit hooks, which is just a shell script - https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks

Your parent is correct. Here's our pre-commit config too FWIW:

  more .pre-commit-config.yaml
      - repo: https://github.com/pre-commit/pre-commit-hooks
        rev: v2.1.0
          - id: end-of-file-fixer
          - id: check-json
          - id: check-yaml
  - repo: https://github.com/asottile/reorder_python_imports
    rev: v1.3.4
      - id: reorder-python-imports
        args: [--application-directories=gaia]
        language_version: python3
  - repo: https://github.com/ambv/black
    rev: stable
      - id: black
        language_version: python3
  - repo: local
      - id: eslint
        name: eslint
        entry: ./frontend/node_modules/.bin/eslint --fix
        language: node
        language_version: system
        files: \.(js|jsx|ts|tsx)$
  - repo: https://github.com/prettier/prettier
    rev: "1.15.3"
      - id: prettier
        files: \.(yml|yaml|md|json)$
        language_version: system

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact