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

@rennalabs/prettier-config

v1.0.3

Published

Renna Labs' base prettier configuration

Downloads

2

Readme

Renna Labs' Prettier Config

npm version

Pairs well with our ESLint config.

Table of Contents

Installation

  1. Make sure your project is using a Node version >= 10

  2. Install dependencies

    npm install --save-dev @rennalabs/prettier-config [email protected]
    
    # or
    
    yarn add --dev @rennalabs/prettier-config [email protected]
  3. Create a prettier.config.js file at the root of your project with the following:

    module.exports = require('@rennalabs/prettier-config');

Configurations

We export two ESLint configurations for your usage:

  1. Default
  2. Four Spaces

Default Config

In your prettier.config.js:

module.exports = require('@rennalabs/prettier-config');

Four Spaces Config

Includes everything in the default config, but replaces the tabWidth rule with 4 spaces instead of 2 spaces.

In your prettier.config.js:

module.exports = require('@rennalabs/prettier-config/four-spaces');

Editor Integration & Autoformatting

VS Code

  1. Install the Prettier extension: View → Extensions then find and install Prettier - Code formatter

  2. Reload the editor

  3. Open your settings JSON file and add the following

    // Format on save with Prettier rules
    "editor.formatOnSave": true,
    // Tell the ESLint plugin to run on save
    "editor.codeActionsOnSave": {
      "source.fixAll.eslint": true
    },
    // Turn off Prettier format on save, use ESLint to format instead
    "[javascript]": {
      "editor.formatOnSave": false
    },
    "eslint.alwaysShowStatus": true,
    // An array of language identifiers specify the files to be validated
    "eslint.options": {
      "extensions": [".html", ".js", ".jsx"]
    },

Sublime Text 3

https://packagecontrol.io/packages/JsPrettier

Atom

https://atom.io/packages/prettier-atom

Pre-commit Hooks

As another line of defense, if you want Prettier to automatically fix your errors on commit, you can use lint-staged with husky.

  1. Make sure your npm version is >= 7.0.0

    npm install -g npm@latest
  2. Make sure your repo has been initialized with git

    git init --initial-branch=main
  3. Install the npm packages

    npm install --save-dev lint-staged husky
  4. Set up the package.json stuff

    npm set-script prepare "husky install" && npm run prepare \
      && npm set-script lint-staged "lint-staged" \
      && npx husky add .husky/pre-commit "npm run lint-staged"
  5. Then in your package.json add

     "lint-staged": {
       "*.{js,css,json,md}": [
         "prettier --write",
         "git add"
       ]
     }

    If you already have lint-staged running ESLint, just add the prettier step on top of it:

    "lint-staged": {
      "*.{js,css,json,md}": [
        "prettier --write",
        "git add"
      ],
      "*.js": [
        "eslint --fix",
        "git add"
      ]
    }

Publishing to npm

Read npm's docs on How to Update a Package.

  1. Checkout and pull the main branch

  2. Run the release script to bump the version numbers (the script will create a commit and push up the release branch to GitHub for you)

    ./scripts/release

    Use semantic versioning to choose the appropriate version number.

  3. Submit and merge a PR from the release branch into main

  4. Make sure you're logged into npm from the command line using npm whoami. If you're not logged in, npm login with the credentials in 1pass

  5. npm publish

Enforced Rules

Check out all of Prettier's configuration options.

Line wrap at 100 characters.

4 spaces per indentation-level

Indent lines with spaces, not tabs.

Always print semicolons at the ends of statements.

const greeting = 'hi';

Use single quotes instead of double quotes.

const quote = 'single quotes are better';

Use trailing commas wherever possible.

const obj = {
    a: 'hi',
    b: 'hey',
};

Print spaces between brackets in object literals.

{
    foo: bar;
}

Put the > of a multi-line JSX element at the end of the last line instead of being alone on the next line (does not apply to self closing elements).

<button className="prettier-class" id="prettier-id" onClick={this.handleClick}>
    Click Here
</button>

Omit parens when possible.

x => x;