/eslint-config-masterworks

ESLint configurations for Masterworks

Primary LanguageJavaScriptMIT LicenseMIT

eslint-config-masterworks

ESLint config presets for Masterworks.

Why

At Masterworks, we use JavaScript and TypeScript extensively across a multitude of repositories and environments. We want to have a consistent style across projects, enforce practices we deem "good", and catch those silly bugs & typos we all fall for once in a while.

In practice, every project is unique and one-fits-all solutions don't exist; some projects use JSX, some lack ES Modules support, some run in AWS Lambdas, some run in Internet Explorer 11, some use TypeScript, some don't, and so on.

For that reason, we don't recommend a single holistic config, instead, we group rules into several presets by their intended context and scope — trying to balance granularity and convenience — from which you can extend based on the project setup or runtime environment.

Before you continue

Read a little bit about ESLint and how to configure it if you haven't already. Also learn about Prettier if you don't know it yet.

If you're starting at Masterworks, you most probably won't need to worry about anything here, everything should be configured already and the project's README should give you guidance on how to lint your code as part of your contributing workflow.

That said, you can continue.

How

To extend any or all of the presets in this repo, you gonna need to install it first, along with its peer-dependencies.

Depending on the project, you might be using npm, yarn, or pnpm as your package manager. Be sure to find out this first by reading the project's README and if that fails, check for what kind of lock files live in the repo:

If you don't see any of those, or if you see more than one, consult with your team.

As a minimum, you are going to need to install eslint, eslint-plugin-import, and eslint-config-masterworks as dev-dependencies. Based on your project's package manager:

$ npm install --save-dev eslint eslint-plugin-import @masterworks/eslint-config-masterworks@github:MasterworksIO/eslint-config-masterworks#3.0.0
$ yarn install --save-dev eslint eslint-plugin-import @masterworks/eslint-config-masterworks@github:MasterworksIO/eslint-config-masterworks#3.0.0
$ pnpm install --save-dev eslint eslint-plugin-import @masterworks/eslint-config-masterworks@github:MasterworksIO/eslint-config-masterworks#3.0.0

Then create an .eslintrc.json (or any other of the formats supported by ESLint) if it doesn't exist already, and extend the base preset:

{
  "extends": [
    "@masterworks/eslint-config-masterworks/base"
  ],
}

Test the new config by linting your project:

$ npx eslint .

From now on, you can extend your config further with more presents, depending on your setup and/or environment, whatever makes sense.

The presets

Each preset has a target use-case and reasoning behind. Read each presets' README file to understand them. You will also need to check each presets' peer-dependencies.

There are also very opinionated presents regarding to coding style ending in -stylish. Most errors/warnings pointed out by these presets can be automatically fixed with eslint --fix but are still kept separated to distinguish aesthetics from function.

Prettier

We try to make every preset play nice with prettier. In theory, only the -stylish presets should ever touch rules that somehow overlap with prettier's concerns, and even in those, we try to delegate to prettier as much as possible.

When using @masterworks/eslint-config-masterworks presets, you should also use our prettier config. In your project's package.json:

{
  "name": "my-project",
  "prettier": "@masterworks/eslint-config-masterworks/prettier",
  "devDependencies": {
    "@masterworks/eslint-config-masterworks": "github:MasterworksIO/eslint-config-masterworks#3.0.0",
  }
}

License

See LICENSE