Search code examples
pythonpre-commitpre-commit.compython-black

How can I enforce black's `--preview` option when invoking black with pre-commit?


I just found out that black's default behavior for long logfile messages does not enforce a maximum line length. I have verified that I can enforce max line length if I invoke black manually (v 23.1.0, in a Python 3.9.9 venv). Now I'd like to make sure that enforcement happens with every commit, using pre-commit, but I don't know how to do this.

Is it possible? If so, how?


Solution

  • this isn't specific to black -- any tool can add arguments in pre-commit by utilizing args

    taking black's base config:

    -   repo: https://github.com/psf/black
        rev: ...  # use your revision here
        hooks:
        -   id: black
            args: [--preview]
    

    disclaimer: I wrote pre-commit, I've contributed to black