@resturant-webtool/eslint-config-bases

About
Example of composable eslint config bases that can be easily shared and fine-tuned by apps and
packages that lives in a monorepo.
Features
- Monorepo friendly: Each workspace can have its own config.
- Composable: Compose your workspace eslint config from pre-defined bases.
- Peace of mind: Plugins does not need to be installed per workspaces, thx to @rushstack/eslint-patch.
- Performance!: Plugins enabled on file conventions patterns to increase perf.
Install
Add the following devDependencies to workspace (apps/packages in monorepo) or main project package.json.
$ yarn add --dev eslint @resturant-webtool/eslint-config-bases
PS: To keep the size low, if you use the following plugins:
- graphql:
yarn add --dev @graphql-eslint/eslint-plugin
- mdx:
yarn add --dev eslint-plugin-mdx
.
- tailwind:
yarn add --dev eslint-plugin-tailwindcss
.
In one line
yarn add
Usage
Create an ./apps/my-app/.eslintrc.js
or ./apps/my-app/.eslintrc.cjs
file that extends any of the existing base configs. For example:
require("@resturant-webtool/eslint-config-bases/patch/modern-module-resolution");
module.exports = {
root: true,
parserOptions: {
tsconfigRootDir: __dirname,
project: "tsconfig.json",
},
ignorePatterns: ["**/node_modules", "**/.cache", "build", ".next"],
extends: [
"@resturant-webtool/eslint-config-bases/typescript",
"@resturant-webtool/eslint-config-bases/sonar",
"@resturant-webtool/eslint-config-bases/regexp",
"@resturant-webtool/eslint-config-bases/react",
"@resturant-webtool/eslint-config-bases/react-query",
"@resturant-webtool/eslint-config-bases/jest",
"@resturant-webtool/eslint-config-bases/rtl",
"@resturant-webtool/eslint-config-bases/prettier-plugin",
],
rules: {
},
overrides: [
],
};
Tip:
- Prettier:
@resturant-webtool/eslint-config-bases/prettier-plugin
and @resturant-webtool/eslint-config-bases/prettier-config
are
mutually exclusives. Choose one. The prettier-config
suppose that you run prettier independently. The prettier-plugin
will run prettier for you. Easiest the prettier-plugin
, fastest prettier-config
(this mostly depends
if you set up and persist caches as well)
- Performance: Some rules are known to be slow (ie:
import/namespace
...). Slowest identified rules are disabled depending
on context (ie: *.test.tsx?
might not need everything). Depending on project
it's possible to disable entirely some slow rules (ie: 'import/namespace': 'off'
). A good tip
run eslint with the TIMING=1
to identify slow rules.
Bases
You can find the bases in ./src/bases.
typescript | all | Naming conventions, consistent imports, import sorting... |
sonar | *.{js,jsx,ts,tsx} | Keep levels of code complexity sane. (excl test and stories) |
regexp | *.{js,jsx,jsx,tsx} | Keep regexp consistent and safer. |
react | *.{jsx,tsx} | Recommendations for react, react-hooks and jsx projects. |
react-query | **/?(*.)+(test).{js,jsx,ts,tsx} | Enforce "recommended" react-query usage. |
jest | **/?(*.)+(test).{js,jsx,ts,tsx} | Catch inconsistencies or error in jest tests. |
rtl | **/?(*.)+(test).{js,jsx,ts,tsx} | Potential errors / deprecations in react-testing-library tests. |
graphql-schema | *.graphql | Ensure validity of graphql schema files. |
mdx | all | Mdx validation |
storybook | *.stories.{ts,tsx,mdx} | Potential errors / deprecations in stories. |
playwright | **/e2e/**/*.test.{js,ts} | Keep "recommended" playwright usage. |
prettier-plugin | all | Post configure eslint for prettier compatibility. |
Notes:
- The order is important. Some bases will disable or tune previously defined
rules. For example the react base will tune the naming conventions
for function components and increase recommended cognitive complexity. The typescript base
will also relax conventions for javascript files.
- Based on filename conventions some rules are relaxed or disabled to avoid false positives and
keep a good level of performance. For example the sonar base won't run on
test and storybook files. If you work on different conventions the patterns must be updated.
Cyclic deps
Due to performance considerations the import/no-cycle isn't enabled by default. This rule
can prevent subtle and hard to debug bugs. Depending on the project you can enable it either
by setting and env variable ESLINT_IMPORT_NO_CYCLE=true yarn lint
(will default to import/no-cycle: 2
) or by adding it
to the extended rules.
Prettier integration
Two ways to work with prettier.
@resturant-webtool/eslint-config-bases/prettier-plugin
- eslint will run prettier under the hood
@resturant-webtool/eslint-config-bases/prettier-config
- eslint will just disable some conflicting rules (so you'll need to run prettier after)
The first method is recommended for simplicity. For best perf use the cache option to run eslint.
Tune the behaviour by creating a config in .prettierrc.js
const { getPrettierConfig } = require("@resturant-webtool/eslint-config-bases/helpers");
module.exports = {
...getPrettierConfig(),
overrides: [
],
};
Tip: You can tune the provided prettier.base.config for your own needs.
Notes
Typescript
Generic typescript project, mostly based on
Sonarjs
React
Jest
React Testing Library
Regexp
Mdx
To tune the behaviour, you can add setting in the top level config
module.exports = {
settings: {
"mdx/code-blocks": true,
"mdx/language-mapper": {},
},
};
Etc
...