ruff icon indicating copy to clipboard operation
ruff copied to clipboard

Add markdownlint, prettier, and dev ruff to pre-commit

Open JonathanPlasse opened this issue 3 years ago • 13 comments

Hi, I propose adding markdownlint and Prettier to pre-commit. I already added markdownlint but I did not add Prettier because dev-generate-all is incompatible with it. We would have to run Prettier inside dev-generate-all. To do this we either require the developer to have node installed on their machine or use nodeenv which only requires Python to create a Node virtual environment where we would run Prettier.

Prettier would be really useful to format ruff.schema.json as it is required by schemastore.org.

Also maybe we should consider using for the ruff hook cargo run with repo: local instead of ruff-pre-commit which sometimes fails because the version for the latest release is not out yet.

JonathanPlasse avatar Jan 28 '23 17:01 JonathanPlasse

Cargo format is part of our GitHub actions pipeline. If markdownlint is added, any reason to not enforce it there?

sbrugman avatar Jan 29 '23 11:01 sbrugman

We could use pre-commit.ci that would run on pull-request to do this.

JonathanPlasse avatar Jan 29 '23 15:01 JonathanPlasse

We could use pre-commit.ci that would run on pull-request to do this.

Certainly an option. There is also a markdownlint github action: https://github.com/actionshub/markdownlint (that does not require to install a github application)

sbrugman avatar Jan 29 '23 16:01 sbrugman

I already added markdownlint but I did not add Prettier because dev-generate-all is incompatible with it.

Can you expand on this? How is it incompatible?

charliermarsh avatar Jan 29 '23 18:01 charliermarsh

Dev generate all will generate the different file which will be then formated by prettier. Pre-commit will always fail at the one of the hook as the output of prettier is different from dev generate all. For it to be compatible it would need that dev generate all generate the different files already well formated.

JonathanPlasse avatar Jan 29 '23 18:01 JonathanPlasse

To do this we either require the developer to have node installed on their machine or use nodeenv which only requires Python to create a Node virtual environment where we would run Prettier.

I'd really rather not add Node as a dev dependency.

Prettier would be really useful to format ruff.schema.json as it is required by schemastore.org.

I think the better approach would be to implement https://github.com/SchemaStore/schemastore/issues/2731 then our schema file would no longer have to be part of the schemastore repository.

not-my-profile avatar Jan 30 '23 04:01 not-my-profile

Yeah I'd like to avoid adding Node as a dependency. I'm happy to just do this manually from time to time, even though it's not a great practice.

charliermarsh avatar Jan 30 '23 04:01 charliermarsh

I added prettier in pre-commit. I had to:

  • Ignore formatting for the table (c.f. prettier/prettier-vscode#762)
  • Use - as bullet as prettier does not support * bullet (c.f. prettier/prettier#4440). prettier option philosophy is to have few option so that we do not debate on which style to chose.

    By far the biggest reason for adopting Prettier is to stop all the ongoing debates over styles. Yet the more options Prettier has, the further from the above goal it gets. The debates over styles just turn into debates over which Prettier options to use.

JonathanPlasse avatar Jan 30 '23 11:01 JonathanPlasse

I added prettier in pre-commit.

Does this require that the user have Node installed? Or how does it work?

(I don't feel strongly about those individual style decisions, like * vs. -. Even if I have preferences, it's not a blocker for me.)

charliermarsh avatar Jan 30 '23 12:01 charliermarsh

I added prettier in pre-commit.

Does this require that the user have Node installed? Or how does it work?

No, it does not require Node. If pre-commit is installed it will run the prettier hook with nodeenv but the developer only need to have pre-commit installed and nothing else. For the CI, I would suggest using pre-commit.ci to run pre-commit. To avoid checking twice fmt, clippy, and dev-generate-all, we can edit .pre-commit-config.yaml to skip them when in CI. Like this validate-pyproject, prettier, markdownlint-fix, and ruff hooks would run on the pull request. Which is not the case currently. Using pre-commit.ci only needs .pre-commit-config.yaml and avoids maintaining a separate GitHub Action.

JonathanPlasse avatar Jan 30 '23 12:01 JonathanPlasse

Candidly, while I definitely appreciate the motivation, I'm probably not going to enable pre-commit CI right now, since I don't use pre-commit personally!

charliermarsh avatar Jan 30 '23 12:01 charliermarsh

@JonathanPlasse - I'd like to pull in some of these changes, but exclude Prettier for now. Would you like me to do it in a separate PR, or push to this branch?

charliermarsh avatar Feb 02 '23 01:02 charliermarsh

Hi, sorry for the late response. I rebase and remove prettier.

JonathanPlasse avatar Feb 02 '23 17:02 JonathanPlasse