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

setup-eslint-config

v1.11.2

Published

Helper to create setup scripts for eslint configs

Downloads

34

Readme

setup-eslint-config

This is a little utility to help manage installation of eslint configs. This is kind of an opinionated solution to the fact that eslint needs peer dependencies not dependencies for config uses other configs and plugins. It will install the given list of packages with the same version that can be found in devDependencies or use @rushstack/eslint-patch for resolving nested dependencies.

Installation

npm install setup-eslint-config
# or
yarn add setup-eslint-config

Usage

Create a file like the following example, and then add it to bin in package.json. If you define it in bin as the same name as the package you can use npx to install or upgrade it in the projects with npx eslint-config-relekang@latest. See eslint-config-relekang as example.

const {setup} = require('setup-eslint-config')

setup({
  name: "eslint-config-relekang",
  prompts: [
    { type: 'confirm', name: 'prettier', message: 'Use prettier?' },
  ],
  fileChecks: [{name: "docker": path: "Dockerfile" }],
  skipDetectedPrompts: true,
  createEslintConfig: (config) => {
      const extending = ["relekang"]
      if (config.prettier) {
        extending.push("relekang/prettier");
      }
      return {extends: extending}
  },
  createDependencyList: (config) => {
    const dependencies = ['eslint'];
    if (config.prettier) {
      dependencies.push('eslint-config-prettier');
      dependencies.push('eslint-plugin-prettier');
      dependencies.push('prettier');
    }
    return dependencies;
  }
  createNpmCommands: ({typescript}) => {
    return {
      lint: `eslint --cache ${typescript? '--ext ts,tsx,js,jsx': ''} .`,
      "lint:errors": `eslint --cache --quiet ${typescript? '--ext ts,tsx,js,jsx': ''} .`,
      format: `eslint --cache --quiet --fix ${typescript? '--ext ts,tsx,js,jsx': ''} .`,
    };
  },
}).catch(error => {
    console.error(error.message)
    process.exit(1)
})

The prompts property is passed on to the prompts package, thus read their documentation on available options. The result of the prompts are passed to functions as config. If there is an autodetection with the same name and skipDetectedPrompts is set to true then the prompt will be skipped. See list of autodetected things below. The values of the fields defined in the prompts will be stored in the config part of the eslint config and then reused the next time. This will also happen if it is detected.

Using relative resolver patch

@rushstack/eslint-patch is a package that allows using plugins and configs as nested dependencies so we don't need to have the plugins used in the config as direct dependencies in the project. To enable this it is required to use eslint config as a js file so that we can add the import of the patch. Set useEslintRelativePathPatch: true in the config. Then you can omit createDependencyList. It is important when using this option to add plugins and configs to dependencies and not devDependencies.

Specifying version when using npx

Since npx sometimes chooses the installed version even when version is specified this library supports first argument to be the wanted version:

npx eslint-config-relekang latest
npx eslint-config-relekang 2.0.0

Autodetection

  • yarn - is there a yarn.lock file in the directory
  • babel - is there a .babelrc file in the directory
  • typescript - is typescript a dependency or is there a tsconfig.json file in the directory
  • flowtype - is there a .flowconfig file in the directory
  • vue - is vue a dependency or dev dependency
  • react - is react a dependency or dev dependency
  • prettier - is prettier a dependency or dev dependency
  • jest - is jest a dependency or dev dependency
  • mocha - is mocha a dependency or dev dependency
  • ava - is ava a dependency or dev dependency
  • cypress - is cypress a dependency or dev dependency
  • node - eslintConfig.env.node is true