cvxpy icon indicating copy to clipboard operation
cvxpy copied to clipboard

Include ruff format in `pre-commit`

Open andresliszt opened this issue 1 year ago • 2 comments

I noticed that ruff formatting is not being done on commits. The pre-commit.yaml file is

repos:
  - repo: https://github.com/astral-sh/ruff-pre-commit
    # Ruff version.
    rev: 'v0.1.11'
    hooks:
      - id: ruff
        args: [--fix, --exit-non-zero-on-fix]

According to ruff official docs they do not support (yet: A unified command for both linting and formatting is planned) formatting and linting in a single command. Running ruff format in the source code shows several files that must be formatted.

It makes it a bit difficult to create a PR if the code formatting is out of sync with the master

andresliszt avatar Oct 24 '24 14:10 andresliszt

I am not too familiar with Ruff format, does it make changes on all the files or only those that have changes in the pre-commit? Also, feel free to open a PR for this, we would probably be happy to add this feature.

Transurgeon avatar Oct 24 '24 20:10 Transurgeon

I am not too familiar with Ruff format, does it make changes on all the files or only those that have changes in the pre-commit? Also, feel free to open a PR for this, we would probably be happy to add this feature.

Happy to help with. The steps are:

  1. Add the format rule in the pre-commit
  2. The very first commit with this rule will format all the files that ruff finds that need formatting according to the rules defined in the pyproject.toml. I ran it locally and there are several python files.
  3. New commits will make formatting mandatory, done automatically by pre-commit

andresliszt avatar Oct 24 '24 20:10 andresliszt