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

@cazoo/eslint-plugin-eslint

v2.0.0

Published

ESLint rules for Cazoo org

Downloads

19

Readme

Cazoo ESLint

What's this?

It's an NPM package providing an opinionated ESLint configuration to use at Cazoo. It exposes two ESLint presets:

  • plugin:@cazoo/eslint/react for React based applications
  • plugin:@cazoo/eslint/node for Node.js applications

Why do we want this?

We have quite coherent dev stack at Cazoo (React/TypeScript/Node/Jest), and most projects are set up with ESLint and Prettier. This package aims at avoiding all the duplication between teams.

This does not aim at being the true and only way. Teams are more than welcome to extend this in their project and enable/disable rules. PRs are also welcome if there are some useful rules/plugins that we could add to benefit everyone.

What does it setup?

When using React ⚛️:

It also tells ESLint that jest exists in .test.ts(x) and .spec.ts(x) files.

How do I use it?

Migrating an existing app

If you already are using ESLint on your project first remove all ESLint plugins dependencies as well as prettier:

npm remove eslint @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint-config-prettier eslint-plugin-jsx-a11y eslint-plugin-prettier eslint-plugin-react eslint-plugin-simple-import-sort prettier

Then follow the instructions for a new app bellow.

On a new app

First install @cazoo/eslint-plugin-eslint and eslint as dev dependencies:

npm i -D @cazoo/eslint-plugin-eslint eslint@8

Then add an .eslintrc.json config file to the root of your project containing only:

For a React ⚛️ app use:

{
  "extends": [
    "plugin:@cazoo/eslint/react"
  ]
}

For a Node.js app (like an API) use:

{
  "extends": [
    "plugin:@cazoo/eslint/node"
  ]
}

Finally, add a lint rule to your package.json:

{
  "scripts": {
    "lint": "eslint --fix 'src/**/*.{ts,tsx}'"
  }
}

To lint and fix your project you can now run:

npm run lint

Running ESLint on save

In WebStorm

Go to Preferences > Languages and Framework > JavaScript > Code Quality Tools > ESLint:

  • Check Automatic ESLint configuration
  • Check Run eslint --fix on save

You're done 🎉! Webstorm will now reformat your file with prettier and sort your imports on save, as well as showing you ESLint errors and warnings.

⚠️ If you want to avoid doing this for every new project you can set that setting in: File > New Project settings > Preferences for New Projects

⚠️ If Webstorm complains about not finding ESLint it usually means that you have multiple ESLint (monorepo). Check Manual ESLint configuration in the settings instead. Then click in ESLint package, click on the arrow and select the path to one of your ESLint package (whichever you want).

In VSCode

First, install the VSCode ESLint extension.

Once installed, on Mac you'll need to click on ❌ ESLint at the bottom right of your window to allow the extension access.

Then, go to Settings > Workspace, and search for Code Actions On Save in the search bar on top.

Then click on: Edit in settings.json, and enter:

{
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  }
}

You're good to go 🎉! VSCode will now reformat your file with prettier and sort your imports on save, as well as showing you ESLint errors and warnings.

Pre commit hooks

If you wish to enforce running ESLint before commits you can use Husky 🐶.

First install husky and lint-staged as dev dependencies:

npm i -D husky@4 lint-staged

⚠️ Husky 5 licence doesn't allow use in non open-source project. Please use Husky 4.x in private projects!

Then add their configuration in your package.json:

{
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "*.{ts,tsx}": [
      "eslint --fix"
    ]
  }
}

This will only run ESLint on the files that are about to be committed, so it should be quite fast ⚡️!