8 ms·
Lefthook: Knock your team’s code back into shape
- vemv 7y agoGenerally I'm of the opinion that git hooks are not the right place to place linters or formatters. For a JVM language, it means that you'll spin up a JVM for each step (and you can well have 15 formatters + linters in your stack). So, the formatter better lives in a dev-only part of your codebase, so it's always loaded, interacting with your codebase using _runtime insights_ otherwise impossible to gather, and it's easily hackable. I've authored this kind of solution in the past. It works great, and a proper CI pipeline (i.e. including linters) kills the other half of the problem.
- xfalcox 7y agoWe are using it at Discourse (thanks to a PR from Lefthook team) and I love it. The fact that it is zero setup for every new contributor is a killer feature IMO.
- cheesysam 7y agoThe English in this sales page is terrible. There's even a misspelling of the product name in the opening paragraph.
- marmaduke 7y agoThe substance of this comment is terrible. There's even a misunderstanding of the point of the original article.
- kevsim 7y agoI’m also terribly sick of projects that describe themselves as “lightning fast”
- amiga-workbench 7y agoIn the age of Electron it's worth mentioning.
- bryanrasmussen 7y agoI'm envisioning a cut scene from idiocracy - Lightning, it's got Electron!
- yaroslavm 7y agoHow is an open source intro post a "sales page"?
- ticmasta 7y agoWell, if they're trying to get you to switch or to adopt something new, they're trying to sell. There's more to trading than just money for product/service; could be attention, effort, endorsement, opinion and other signalling factors, etc.
- yaroslavm 7y agoBy your definition, technically, any piece of content on the Web should be considered a sales page—including your comment, where you'se selling your opinion or attention. If that's the case, does it really make sense to label something a "sales page" in a negative way? Is there any other way to present a new FOSS project besides telling about the upsides? Trashtalk it from the start, maybe? I don't really get it.
- fhbdukfrh 7y agoYep, that's kind of the point of upvotes or karma: You present your content and try to get people to buy it. Not sure where you get the negative sales page aspect though. I made no judgement on the presentation technique or quality, just that open source or not, they are still selling something.
- stronglikedan 7y agoThey are trying to sell you on using their product, regardless of price (or lack thereof).
- eclipxe 7y agoI thought it was just me - that was super hard to read.
- mLuby 7y agoIt's 95% there, but English is hard… We can be helpful about it so the authors can fix it. ¶1: Meet Lefthook, the fastest polyglot Git hooks manager out there. It ensures not a single line of unruly code makes it into production. See how easy it is to install Leftook, which was recently adopted by Discourse, Logux, and Openstax. Lefthook works with the most common front-end and back-end environments so all the developers on your team can rely on a single, flexible tool. And it also has emojis ¶2: The days when a single piece of software that millions rely on was created by a single developer in an ivory tower are long gone. Even Git, universally believed to be the brainchild of Linus Torvalds alone, was created with the help of contributors and is now being maintained by a team of dozens. ¶3: No matter if you work on an open-source project with the whole world as your oyster, or your code blooms in a walled garden of proprietary software—you still work as a team. And even with a well-organized system of pull requests and code reviews, maintaining the code quality across the large codebase with dozens of contributors is not an easy task. ¶4: Hooks—ways to fire off custom scripts when certain important actions (commit, push, etc.) occur—are baked right into Git, so if you are comfortable with Bash and the internals of the world's most popular version control system, you don’t need any external tools: just edit ./.git/hooks/pre-commit and put in some well-formed script that will, for instance, lint your files before you commit. ¶5: However, when you work on a project you are most interested in writing the project’s code, not the code that checks it. In the world of modern web development, tooling is everything, and a myriad of tools exist for a single reason: reducing overhead and complexity. Git hooks are no exception: in JavaScript community, the weapon of choice is Husky with Webpack, Babel, and create-react-app relying on this Node-based tool; the Rails-centric backend world however is mostly ruled by Overcommit that comes as a Ruby gem. ¶6: Both tools are excellent in their regard, but in a mixed team of front-end and back-end developers, as Evil Martians are, you will often end up having two separate setups for Ruby and JavaScript with front-enders and back-enders linting their commits each in their way. ¶7: With Lefthook, you don’t need to think twice—it’s a single Go binary that has wrappers both for JavaScript and for Ruby. It can also be used as a standalone tool for any other environment. ¶8: Using Go makes Lefthook lightning-fast and provides support for concurrently executed scripts out of the box. The fact that the executable is a single machine-code binary also removes the need for handling external dependencies. (Husky + lint-staged add roughly 1500 dependencies to your node_modules.) It also removes the headache of reinstalling dependencies after each update of your development environment. (Try running a globally-installed Ruby gem with another version of Ruby!) ¶9: With Lefthook added in either package.json or Gemfile and a lefthook.yml configured in the project’s root (see examples below), the tool will be installed and used against your code automatically on the next git pull, yarn install/bundle install or git add/git commit. All with zero overhead for new contributors. ¶10: An extensive README describes all the possible usage scenarios for Lefthook. Its straightforward configuration syntax does not hide actual commands being run by Lefthook, making sure there's no funny business going on. ¶11: Discourse—an incredibly popular open-source platform for forum-style discussions—has recently transitioned from Overcommit to Lefthook and never looked back. With almost 700 contributors authoring 34K commits and counting, running linters on all new contributions is a priority. With Overcommit though, team members constantly had to remind newcomers to install required tools. ¶12: Now that @arkweid/lefthook is a dev dependency in the project’s package.json, no setup is necessary for new contributors. §1: Lefthook halves the time that pre-commit scripts take on localhost. ¶13: The PR that changed the Git hook manager simply required changing .overcommit.yml to lefthook.yml. If you compare them, you will see that Lefthook’s configuration is much more explicit while the Overcommit’s relies mostly on the magic of plugins. ¶14: Besides changing the way the output looks, Lefthook offers a nice summary of everything it does. Lefthook halves the time that pre-commit scripts take on localhost, and increases the CI run speed by 20% (on CI environments with better support for parallel execution, the gain can be considerably more).
- marmaduke 7y ago> Husky + lint-staged add roughly fifteen hundred dependencies to your node_modules What on earth? I used to work on a backend and sometimes had to test the front-end. The webpack dev server required 2 gb of ram to boot. Sure we all have the latest MBP amiright, but if you have a backend stack to up as well, the OOM killer is right around the corner..
- jchw 7y ago2GB would be nice... I got a bulky laptop with 16 GB to be able to run the “full stack” at a previous employer. I had to upgrade it to 24 GB.
- dajohnson89 7y agoi wont buy a dev machine with less than 32gb.
- StavrosK 7y agoIf my stack takes more than three gigabytes to run, I consider it broken and file a bug to trim down the dependencies.
- deleted 7y ago[deleted]
- nullandvoid 7y agoWould be nice to have a tl;Dr for us folks on mobile - I enjoy this kind of stuff very much but for some reason it felt like a drag getting to the point Would be great to have seen some code examples of before/ after straight away perhaps Product seems neat I will look into giving it a go on my side projects
- majkinetor 7y agoI think this could be best described as TL;DR generation. I guess article could be more to the point but again, there is freedom of speech and stuff, we don't have all to comfort to the same paradigm so it hardly deserves a rant.
- progapandist 7y agoThank you for the feedback! I miss those beautiful days when people could read 6 paragraphs of text before getting bored, but I see your point! There's a link to GitHub readme in paragraph one, for those who want to get straight to the code.
- desc 7y agoI was introduced to an important rule re. giving presentations when I was still at school: 1. Tell them what you're going to tell them. 2. Then tell them. 3. Then tell them what you told them. Open with a clear introduction, no more than a few sentences, which covers everything at a high level and sets the scene. Then go through points in a logical order in as much detail as necessary. Finally, summarise as necessary to tie together all the points and link them back to the introduction. If someone has to read six paragraphs just to work out what the hell you're selling then you're doing it wrong. But that will be your cost, not theirs.
- nullandvoid 7y agoBeing snarky to someone who is giving cc and stating how they want to give your product a try is a sure fire way to not make me want to give it a try
- 7y ago
- anentropic 7y agosimilar: https://pre-commit.com/ https://pre-commit.com/
- falsedan 7y agohttps://github.com/Arkweid/lefthook/wiki/Comparison-with-other-solutions#pre-commit https://github.com/Arkweid/lefthook/wiki/Comparison-with-oth...
- anentropic 7y agoI agree that the docs for pre-commit are hard to follow and badly organised. The other points I'm not so sure. I don't find it slow, or find the config verbose. Nor did it break output from commands in my experience (though I did have an issue where colorised output got disabled in a tool because it couldn't detect if terminal colors were supported)
- frankish 7y agoI don't consider this a comparison given the content is one-sided and doesn't present the cases where the alternatives are better. This is a much newer project and I find it hard to believe that it is going to be as mature.
- falsedan 7y agoNot really worried about how 'mature' the thing that runs the scripts before I commit is, either it works or it makes a mess of my working tree. I do care about how opinionated and collaborative the dev behinde the tool is.
- josteink 7y agoRuby and JS only. That’s fairly low coverage. This hook here will provide much better cover for your team: https://github.com/kvz/ochtra https://github.com/kvz/ochtra Edit: Misunderstood the writing on the page, which in fairness is not very clear on what it covers and how.
- yaroslavm 7y agoSure you've read the post? It's a Go tool with install shortcuts for Ruby and JS. It works with everything.
- ohnoesjmr 7y agoYour page is so long and so bad that I left it with the same assumption. Why can't you just have a paragraph explaining what it is, why it's useful and what it supports. If I don't use any of the existing hook witchcraft, why do I have to go over paragraphs and paragraphs of comparisons of things I am not familiar with?
- deleted 7y ago[deleted]
- davidjnelson 7y agoLove these kinds of tools. What is different between husky / git-staged and this? It’s faster and smaller? Quite happy with husky and running tslint/tests with husky on precommit currently. Curious what the biggest benefits are from left hook and if it’s a pain to switch to if they are amazing benefits. The biggest annoyance with current setup is on prem ci with Jenkins and GitHub Enterprise and complex docker bash scripts embedded in Jenkins. It’s a pain to get lint/test results to show up in the GitHub pull request ui. Doesn’t seem like this tool would help make that use case faster to set up.
- webmonkeyuk 7y agoSerious question: why would I want to use this instead of tests as part of the CI process? Or would the use case be to use both but just get faster feedback from Lefthook?
- iadramelk 7y agoYou should use both. Basically it's bad idea to push broken code to remote, but running tests and linters on all files is too time consuming. So you set up lefthook to run your tests and liters only on changed files (which is fast and prevents 90% of problems), but then your code is pushed you still run CI checks on all code to make sure that that some dependency in unchanged files is not broken.
- majkinetor 7y ago> Basically it's bad idea to push broken code to remote This argument is void if CI is set to allow complete testing on branches along with parallel pipelines. So I want to do something, I branch, code, and push. Server does all the funky stuff without me having to install or understand anything which is huge time saver. With parallel pipelines you do not even block others with this behavior. Things not on trunk can be broken, that is exactly one of the points we have branches.
- huntedsnark 7y agoThis seems so backwards to me. Why not do it as part of your CI process where you're not foisting unnecessary tooling on your developers local machines? The lag involved in spinning up and running the commit hooks is noticeable and disruptive especially if you commit often and rebase locally.
- gregkerzhner 7y agoWe have two projects. In one, we have no hooks and just have CI fail if the tests fail or you forgot to lint. The other one has a commit hook to lint and a unit test hook on push. The one without hooks is so much better in my opinion. Sure, once in a while you forget to run the linter and the CI fails, but its worth it if the alternative is to have every git commit you ever make take 5 seconds and every git push take 30 seconds (our test suite is slow).
- andreineculau 7y agothe article talks about pre-commit hook, but nobody stops you from running these checks as pre-push hook. and nobody says you need to run the all the checks that you'd normally run on CI, but just enough checks to get past the silly errors. for small repos, running linters and such on pre-push is great because you definitely don't have unlimited CI agents, so a lag of 10 seconds for a "git push" might mean you actually gain 30 minutes and not wait for an agent to be available and you also save your team some good minutes with a silly CI job failing with "missing whitespace". PS: if you want to skip the pre-push hook once in a while, just run "git push --no-verify"
- webmonkeyuk 7y agoHaving to wait 30 mins for a build to run sounds like the real issue here. How would you push out an an emergency release in a timely way for example?
- majkinetor 7y agoThat may also depend on how many commits wait in the line. If team is large or monorepo, you need to wait for all pushes to pass in order for your own push to be tested which might take a long time even if single test is fairly fast.