Skip to content

✅ Eslint configuration describing rules for JS used at Adeira. This repository is automatically exported from https://github.com/adeira/universe via Shipit

License

Notifications You must be signed in to change notification settings

adeira/eslint-config-adeira

Repository files navigation

Eslint config designed to work well for Adeira projects. It's especially powerful in combination with Flow and hermes-eslint.

Usage

Before you start you should remove all Eslint plugins and Prettier from your package.json files. This package takes care of all the plugins that are necessary. You should install additional plugins only when you need to add some extra rules. It's a good idea to contribute these rules back to this package so everyone can benefit from it.

Install this package (as well as Eslint):

yarn add eslint @adeira/eslint-config --dev

And use it in your .eslintrc.js:

module.exports = {
  root: true,
  extends: [
    '@adeira/eslint-config',

    // - OR -
    // '@adeira/eslint-config/strict',
  ],
};

Strict version of the config turns some warnings into errors. We use warnings as a migration strategy for the future breaking release, however, you can make the config more strict even today (so your CI will fail). Not all warnings are turned into errors - only the ones considered to be errors in the future version. Please be aware that strict mode is like living on the edge: minor upgrade can break your CI (while others will get only warnings). You will be ready for the future major version though.

It's recommended using hermes-eslint parser with this config (you need to install it separately):

const OFF = 0;
const WARN = 1;
const ERROR = 2;

module.exports = {
  root: true,

  extends: ['@adeira/eslint-config/strict'],

  parser: 'hermes-eslint',
  parserOptions: {
    sourceType: 'module',
  },

  env: {
    es6: true,
    jest: true,
    node: true,
  },
};

Please note that you should not ignore Eslint warnings! These warnings are helping you to migrate to the future major version. Some of them will turn into errors in the next major version bump.

Config subsets

The standard config contains a large number of rules, which may not always work for specific projects. There is no need to use the full package only, smaller configs are also available:

  • @adeira/eslint-config/base - only the basic and most important JavaScript rules
  • @adeira/eslint-config/fbt¹ - FBT related rules
  • @adeira/eslint-config/flowtype - Flow related rules
  • @adeira/eslint-config/jest - Jest related rules
  • @adeira/eslint-config/next¹ - Next.js related rules
  • @adeira/eslint-config/react - React related rules (React, RN, Hooks, accessibility)
  • @adeira/eslint-config/relay - Relay related rules
¹ subset not included in the default `@adeira/eslint-config` or `@adeira/eslint-config/strict`

Use them in your .eslintrc.js:

module.exports = {
  root: true,
  extends: [
    '@adeira/eslint-config/base',
    '@adeira/eslint-config/react',
    '@adeira/eslint-config/jest',
  ],
};

Alternatively, you can extend the default preset with additional optional rules:

module.exports = {
  extends: [
    '@adeira/eslint-config',
    '@adeira/eslint-config/next', // optional Next.js rules not included by default
  ],

  // The following settings might be needed in case you are trying to apply Next.js preset inside
  // monorepo subdirectory, see: https://nextjs.org/docs/basic-features/eslint#rootdir
  settings: {
    next: { rootDir: __dirname },
  },
};

Prior art

About

✅ Eslint configuration describing rules for JS used at Adeira. This repository is automatically exported from https://github.com/adeira/universe via Shipit

Resources

License

Stars

Watchers

Forks