This shared ESLint config for TypeScript + Node.js is a strict, opinionated set of rules enforcing best practices.
eslint-config-magenta helps you…
- 🚀 …write readable code with enforced complexity limits and consistent style.
- 📝 …avoid common pitfalls like dynamic
delete
and unguardedfor…in
loops. - 🚧 …remove debugging artifacts like
console.log
andFIXME
comments before you commit. - 🔍 …discover ways to optimize your code for type safety and speed.
This package has several peer dependencies that must be present for it to work properly.
-
eslint
(linter) -
@typescript-eslint/
-
parser
(typescript parser for ESLint) -
eslint-plugin
(linter rules for ESLint)
-
-
typescript
(type checker) eslint-plugin-unicorn
eslint-plugin-node
eslint-plugin-deprecation
Use your favorite package manager to install. If your package manager does not install peer dependencies automatically (default behavior with pnpm and yarn), you can copy one of these commands to install everything at once.
pnpm add -D eslint-config-magenta eslint-plugin-deprecation eslint-plugin-unicorn eslint-plugin-node @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint typescript
# or
yarn add -D eslint-config-magenta eslint-plugin-deprecation eslint-plugin-unicorn eslint-plugin-node @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint typescript
# or
npm i -D eslint-config-magenta eslint-plugin-deprecation eslint-plugin-unicorn eslint-plugin-node @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint typescript
Add one of the following to your ESLint config:
// .eslintrc.cjs
module.exports = {
extends: ["magenta"],
parserOptions: {
project: "./tsconfig.json",
},
};
// .eslintrc.json
{
"extends": ["magenta"],
"parserOptions": {
"project": "./tsconfig.json"
}
}
# .eslintrc.yaml
extends:
- magenta
parserOptions:
project: ./tsconfig.json
Yes. You can use rulesets independently by extending magenta/base
,
magenta/unicorn
, and/or magenta/node
in your ESLint config. For example, to
only enforce the base rules and eslint-plugin-unicorn
rules:
{
"extends": ["magenta/base", "magenta/unicorn"],
// ...
}
If you're not using the configuration for one of eslint-plugin-unicorn
or
eslint-plugin-node
, you can uninstall that plugin.
This linter config prefers using the node:
protocol to import core modules.
Consider adding this prefix (e.g. node:fs
, node:assert/strict
) or disabling
@typescript-eslint/no-restricted-imports
.