npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

git-prettier

v0.1.1

Published

handler to improve data handling in Next.js getServerSideProps

Downloads

2

Readme

git-prettier

Run prettier during git clean and smudge stages.

Introduction

Prettier is an AST transformation tool, and should not be part of your pre-commit hooks. The whole idea of prettier is that we should no longer care about formatting. By moving the code transformation from pre-commit to git clean and smudge filters, we allow developers to see and edit the code in their preferred style, while it exists in the repo in the preferred style of the maintainers.

In other words, the code style that you see in your editor, no longer needs to match the code style from the repo.

Setup - for maintainers

Installation is done via 3 steps. The package needs to be installed, you need to enable it for specific file extensions, and you want the githook to be installed for your contributors.

Let's get started:

First, install the package as a dev dependency.

npm i -D git-prettier

Next, enable git-prettier for specific file extensions. Add as many as you'd like, simply separate the extensions with a ,.

git-prettier init js,ts,tsx

Last, add a postinstall hook so that contributors use the same filters. In package.json:

{
  "scripts": {
    "postinstall": "git-prettier"
  }
}

Note that the postinstall hook does not require extensions to be defined. The extensions are used to create or modify your .gitattributes file. That file should be committed to your repository.

Usage - for contributors

Simply create a prettier config file according to their spec, in your home directory.

Files will be formatted using your personal config file during checkout, and using the repo config file on commit.

Gotchas

  • Eslint/Prettier integration

    The connection between eslint and prettier should be removed. By integrating prettier in eslint, we force the contributor to use a coding style that they don't necessarily prefer. Eslint reports prettier/prettier errors, that are no errors. (didn't we use prettier so that it does not matter what style the developer uses?) The transformations are always auto-fixable, and using git-prettier we're confident that it will be done before code lands. Keep eslint to catch errors and things that prettier can't handle. But leave as much formatting as possible to prettier.

  • My style is not applied

    Right after installation, it might happen that the currently checked out files are not transformed to match your personal prettier config. To correct this try switching branches, or delete the file and use a git reset to revert it.