pre-commit / pre-commit

A framework for managing and maintaining multi-language pre-commit hooks.

Home Page:https://pre-commit.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add mirror for stylelint

ogomozov-godaddy opened this issue · comments

Eslint is standard linter for Javascript. However, there is no yet leader for CSS
So far only scss-lint has mirror in pre-commit hooks
https://github.com/pre-commit/mirrors-scss-lint
However, it's biggest issue is not able to "autofix" simple errors like other linters do and is expected by many users
This issue is not going to be fixed any time
sds/scss-lint#984

It's biggest rival is stylelint. It has more features: supports many syntax besides SCSS, more rules, more config features, has larger community and contribution team. But most important - it allows autofix
https://stylelint.io/

Please, add mirror for stylelint

It would be preferable to suggest a configuration to their repository (essentially add the .pre-commit-hooks.yaml file there) -- please pursue that first.

note that you can always add a repo: local hook which uses stylelint as an additional_dependencies: [...] until official support lands

👋 I wanted to follow up on this as we’re discussing the future of stylelint’s pre-commit hooks at stylelint/stylelint#5373.

  • It looks like the preference there would be to maintain the hook as a mirror rather than inside the main repository
  • Stylelint maintainers also don’t want to have more repositories under the stylelint organisation on GitHub

I’ve made https://github.com/thibaudcolas/mirrors-stylelint as a trial, based on mirrors-prettier, but matching the configuration of awebdeveloper/pre-commit-stylelint, as that’s what current users would be migrating from (installing it is a pain but afterwards it works pretty well as-is).

From what I understand there are two options:

  1. We move the repository I made to the pre-commit organisation, like mirrors-scss-lint, and a lot of other Node-based linters. Then stylelint updates their docs to point at this "official" mirror.
  2. We keep it under my account, and I’ll do my best to keep it maintained like other mirrors anyway. Then stylelint updates their docs to point at this unofficial-but-endorsed mirror.

@asottile what do you think?

the mirror repositories are suboptimal workarounds -- the ideal state is adding the one small metadata file to the source repository

I can see that in some respect, but from what I could piece together between prettier/prettier#8925 (comment) and looking at pre-commit’s Node environment installation steps, it seems installation speed is also a factor that makes a mirror more compelling as things stand currently.

Anyway, in the case of stylelint I have a feeling there’s already consensus that a mirror is the way to go at least for the time being (reasoning here makes sense to me). What’s up in the air is just where it should be.

installation speed doesn't really matter -- it only runs once and then is done (that user didn't have caching set up properly)

Appreciate installation speed might not matter to you as much as other considerations but personally that has to factor into what approach I’d recommend supporting, as well as the other maintenance considerations I mentioned. So I think I’ll recommend we go ahead with a mirror at thibaudcolas/pre-commit-stylelint.


I wanted to check for myself how the performance compares, so tried it with ESLint since it has both mirrors-eslint and a built-in .pre-commit-hooks.yaml:

  • The mirror installs in 7s and takes up 12MB on disk
  • The main repository installs in 1min and takes 33MB on disk

Full configuration and logs:

With the built-in .pre-commit-hooks.yaml
  - repo: https://github.com/eslint/eslint
    rev: v8.8.0
    hooks:
      - id: eslint

Time it takes to install and disk space:

$ rm -rf ~/.cache/pre-commit
$ time pre-commit run eslint
[INFO] Initializing environment for https://github.com/eslint/eslint.
[…]
eslint...............................................(no files to check)Skipped
pre-commit run eslint  24.16s user 16.26s system 67% cpu 1:00.21 total
$ du -sh ~/.cache/pre-commit
33M
And with mirrors-eslint
- repo: https://github.com/pre-commit/mirrors-eslint
    rev: v8.8.0
    hooks:
      - id: eslint

Time it takes to install and disk space:

$ rm -rf ~/.cache/pre-commit
$ time pre-commit run eslint
[INFO] Initializing environment for https://github.com/pre-commit/mirrors-eslint.
[…]
eslint...............................................(no files to check)Skipped
pre-commit run eslint  3.57s user 1.63s system 71% cpu 7.317 total
$ du -sh ~/.cache/pre-commit
12M

I don’t think performance is the sole consideration but it does seem to me it’s better for tools to be installed from npm in the form they intend to be distributed in, rather than via a git clone + local npm install.

again it's not about size or speed, it's about the user experience. mirror repositories are far worse due to them being essentially a hack via additional_dependencies which are a constant source of confusion. they also redirect support away from those that can properly handle their problems

but if you want to do the wrong thing by all means go ahead, I'm just requesting you do it the right way for the users

In case anyone researches this in the future – I wrote a quick report on how the mirror has been working over the last year and a half: thibaudcolas/pre-commit-stylelint#1. I’m planning to introduce Stylelint on a major project so had to take a look at this again.

your experience seems anecdotal fwiw. the prettier mirror issue tracker has gotten so bad I've had to lock it multiple times