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

@39digits/eslint-config-react

v1.0.2

Published

An ESLint shareable config for use on React projects including Prettier and optional TypeScript support

Downloads

10

Readme

ESLint config for React with Prettier and TypeScript support

Quick-start

Installation

Either use install-peerdeps via npx to install this shareable config and its peer dependencies automatically.

npx install-peerdeps --dev @39digits/eslint-config-react

Or explicitly install everything in one line using npm.

npm install --save-dev eslint babel-eslint @39digits/eslint-config-react eslint-config-prettier eslint-plugin-import eslint-plugin-react eslint-plugin-react-hooks prettier

Usage

Now create a .eslintrc.js configuration file in your project root and add @39digits/eslint-config-react to the extends field. Add any extra rules you want to use under the rules section.

{
  "extends": ["@39digits/eslint-config-react"],
  "rules": {
    // ...
  }
}

Create a .prettierrc configuration file in your project root and populate with your preferred formatting preferences.

My personal preferences are as follows.

{
  "singleQuote": true,
  "semi": true,
  "useTabs": false
}

If you like the Prettier defaults, simply leave the config object empty.

A note on Prettier usage

My shareable config only uses the ESLint Prettier Config and does not make use of the ESLint Prettier Plugin. This is the recommended method of integrating Prettier with your linter.

The Prettier Config will turn off any ESLint rules that should only be handled by Prettier itself. This ensures ESlint focuses on checking code quality; Prettier to format it.

Many shareable configs that use the Prettier Plugin will set Prettier preferences as actual linting rules. I don't feel comfortable hiding these settings from the project view and instead rely on an easily discoverable .prettierrc configuration file with explicit rules in the project root.

Enabling Typescript Support

Installation

I did not include the TypeScript modules in the peerDependencies of package.json to avoid npm complaining on projects that won't use TypeScript at all. You will need to install the dependencies manually.

npm install --save-dev typescript @typescript-eslint/parser @typescript-eslint/eslint-plugin

Note: Install these packages in addition to the main shareable config packages.

You may also wish to install some types while you're at it - these will change depending on your project's requirements.

npm install --save-dev @types/react @types/node

Usage

Separate Linting for JavaScript and TypeScript files

I prefer using the TypeScript parser and TypeScript linting rules on *.ts or *.tsx files only. I then leave the JavaScript linting to babel-eslint.

To achieve this we can use ESLint's overrides feature. This ensures the TypeScript linting rules do not, for example, complain about no return type on a function inside of a *.js file.

There is one caveat in that any project specific rules do not cascade. Any rules defined in our local .eslintrc.js file needs to be replicated within the overrides section. I recommend setting any local rules within a variable and then applying that to each section to avoid unnecessary duplication and bugs.

// .eslintrc.js
const commonRules = {
  // Example rule...
  'prefer-const': 'error',
};

module.exports = {
  extends: ['@39digits/eslint-config-react'],
  rules: commonRules,
  overrides: [
    {
      files: ['**/*.ts', '**/*.tsx'],
      extends: ['@39digits/eslint-config-react/typescript'],
      rules: commonRules,
    },
  ],
};

TypeScript All The Things!

Other times you may want to run everything through @typescript-eslint/parser and the TypeScript linting rules.

// .eslintrc.js
module.exports = {
  extends: ['@39digits/eslint-config-react/typescript'],
  rules: {
    // ...
  },
};

Setup Visual Studio Code

Install the ESLint and Prettier Visual Studio Code extensions.

Add the following to your Visual Studio Code settings.json preferences file.

{
  // When you save a file it will run any formatters (i.e. Prettier)
  "editor.formatOnSave": true,
  // Ensure the Prettier extension is used as the default formatter
  "[javascript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  // This requires a .prettierrc file in the project root.
  // If there is no config file then Prettier will not run.
  // This is useful if you work on projects not (yet) using Prettier
  // to avoid huge commits existing of largely formatting changes
  // Reference: https://github.com/prettier/prettier-vscode#prettierrequireconfig-default-false
  "prettier.requireConfig": true
}

Now Prettier will automatically format your code when you save any supported file. ESLint will also now show visual indicators for any code not adhering to your rules.

Happy coding!

License

MIT.