reactioncommerce / reaction-eslint-config

Reaction Eslint Configuration
MIT License
5 stars 6 forks source link

Make config modular #22

Open rosshadden opened 4 years ago

rosshadden commented 4 years ago

Problem

Right now our main and only config in this project is both react-specific and test-specific. It uses the plugins jest, jsx-ally, react, and react-hooks. It also sets the jest, mocha, browser, and node environments to true.

The above has the following implications:

Solution

We can make our config modular. We will have a base config file that is universally applicable and env-agnostic. No node config, no browser config, no tests config. We can then have specific environment files that extend these. One for browser, one for specifically react which would extend browser, one for node, one for tests.

The official eslint docs for doing so can be found here.

An example node environment config:

// environments/node.js
module.exports = {
  extends: [
    "@reactioncommerce",
    "plugin:node/recommended"
  ],
  env: {
    "node": true,
    "shared-node-browser": false
  }
};

Using this same pattern we could also make different "modules" which would have config for certain agnostic libraries or scenarios. Things like MongoDB, jsdoc, jest, react, or lodash. For example, consider the popular library lodash. A lodash module would specify the lodash plugin, extend the recommended config, and then override any rules we may desire. This example would look something like this:

// modules/lodash.js
module.exports = {
  plugins: [ "lodash" ],
  extends: [ "plugin:lodash/recommended" ],
  rules: {
    "lodash/prefer-constant": [ 2, false, true ],
    "lodash/chain-style": [ 2, "explicit" ]
  }
};

Projects (including this project which can eat its own dogfood) could then cherry-pick the modules they want, or use our pre-configured environments which should be good for most of our uses.

Breaking changes

This will have ramifications. My desired plan is to rely on semver, where people should not blindly update over a major version without doing their research first.

aldeed commented 4 years ago

Seems like a good plan @rosshadden. Some additional thoughts:

brent-hoover commented 4 years ago

I went to open this ticket but it was already here. This change would be really helpful and for pure node linting the current code has a lot of bloat.