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.
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
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
}
};
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'
+ }
}
Run eslint via
npx eslint . --ext .js,.ts,.tsx,jsx
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',
}
@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
.