Skip to content

Latest commit

 

History

History
100 lines (74 loc) · 2.53 KB

README.md

File metadata and controls

100 lines (74 loc) · 2.53 KB

@moralisweb3/eslint-config

Eslint rules, used by Moralis for projects with TypeScript.

These rules are based on community standards and inspired by the airbnb and google presets, without taking too much opinionated/formatting rules into account.

Usage

1. Install dependencies

npm install @moralisweb3/eslint-config \
            @typescript-eslint/eslint-plugin@^5.13.0 \
            @eslint-plugin-etc@^2.0.2 \
            @typescript-eslint/parser@^5.0.0 \
            --save-dev

or

yarn add @moralisweb3/eslint-config \
         @typescript-eslint/eslint-plugin@^5.13.0 \
         @eslint-plugin-etc@^2.0.2 \
         @typescript-eslint/parser@^5.0.0 \
         -D

2. Configure Eslint

Add @moralisweb3 to your eslint config file (.eslint or .eslint.js), or create a new one if it doesn't exist.

extends: [
+ '@moralisweb3'
]

Add any additional rules/plugins etc. you want to use.

{
  extends: ['@moralisweb3'],
  plugins: [/* any plugins */],
  rules: {
    // Any other rules
  }
};

3. Configure the ESLint TypeScript parser

This config requires knowledge of your TypeScript config.

In your ESLint config, set parserOptions.project to the path of your tsconfig.json.

For example:

{
  extends: ['@moralisweb3'],
+ parserOptions: {
+   project: './tsconfig.json'
+ }
}

4. Run eslnt

Run eslint via

npx eslint . --ext .js,.ts,.tsx,jsx

FAQ

I get this error when running ESLint: "The file must be included in at least one of the projects provided"

This means you are attempting to lint a file that tsconfig.json doesn't include.

A common fix is to create a tsconfig.eslint.json file, which extends your tsconfig.json file and includes all files you are linting.

{
  "extends": "./tsconfig.json",
  "include": ["src/**/*.ts", "src/**/*.js", "test/**/*.ts"]
}

Update your ESLint config file:

parserOptions: {
-  project: './tsconfig.json',
+  project: './tsconfig.eslint.json',
}

Why do I need the peer dependencies?

@typescript-eslint/eslint-plugin is a peer dependency due to a limitation within ESLint. See issue, RFC, and progress.

@typescript-eslint/parser is a peer dependency because the version number must match @typescript-eslint/eslint-plugin.