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

@onewelcome/eslint-config-shared-codestyle

v10.0.0

Published

A package for an ESLint + Prettier configuration that can be shared across different projects in OneWelcome.

Downloads

1,114

Readme

npm version

@onewelcome/eslint-config-shared-codestyle

This is the reusable eslint/prettier/husky config to use at OneWelcome. The original config was aimed at typescript development so if you're using pure JS you might need to adjust some rules.

General info

This project contains config and instructions for 4 different tools that all work together to provide an easy and optimized developer experience.

  • eslint for linting.
  • prettier for code style/formatting.
  • husky for pre-commit hooks to enforce the linting and formatting.
  • lint-staged for easily managing the husky config and enabling it on git staged files.

Installation

1. General setup

Install as a development dependency:

npm i @onewelcome/eslint-config-shared-codestyle -D

Install the peerDependencies relevant for JS.

npm i -D eslint-plugin-unused-imports eslint prettier eslint-config-prettier eslint-plugin-prettier

2. (optional) Typescript-specific setup

Install the same peerDependencies used for JS development + typescript specific packages:

npm i -D @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint-plugin-unused-imports eslint prettier eslint-config-prettier eslint-plugin-prettier

3. Final setup

Finish of with the following command, which will install both husky and lint-staged and will add some default configuration to your package.json (see this link for more info)

npx mrm@2 lint-staged

Usage

Add a .eslintrc file to the root of your project:

{
    "extends": "@onewelcome/eslint-config-shared-codestyle"
}

Add a .prettierrc.js file to the root of your project:

module.exports = {
  ...require("@onewelcome/eslint-config-shared-codestyle/.prettierrc")
  // You can overwrite the global config here...
};

Next, add a lint script to your package.json like this (mind the quotes around the regex and the extension. Either .js or .ts):

{
    scripts: {
        "lint": "eslint --fix '?(src|test|features)/**/*.ts'",
        ...
    }
}

The --fix will auto-fix 'unused imports' along with other minor issues.

Next, add a format script to your package.json like this (again mind the quotes around the regex and the extension. Either .js or .ts):

{
    scripts: {
        "format": "prettier --ignore-path .gitignore --write './(src|test|features)/**/*.ts'",
    }
}

Running this script will fix formatting for all your source and test files according to your prettier-config.

Customizing rules

You can configure rules in your project if you don't want to go with these defaults. For consistency though this is not recommended. If patterns emerge to enable/disable a certain rule it might be a better idea to just add it to this shared library so all projects follow them.

{
    "extends": "@onewelcome/eslint-config-shared-codestyle",
    "rules": {
        "@typescript-eslint/interface-name-prefix": "off",
        "@typescript-eslint/triple-slash-reference": "off"
    }
}

Typescript tsConfig Files

By default, this configuration will use the tsconfig.json file at the root of your project. This can possibly lead to errors for .ts files in your test, features and other folders. This is easily fixed by creating a tsconfig.eslint.json file like this:

{
    "extends": "./tsconfig.json",
    "include": [
        "src",
        "features",
        "test"
    ]
}

Then, point eslint to this file in your .eslintrc file:

{
    "parserOptions": {
        "project": "./tsconfig.eslint.json"
    },
    "extends": "@onewelcome/eslint-config-shared-codestyle"
}