An opinionated, but sane ESLint shareable config that I used in my projects ✔
npm install -D @hazmi35/eslint-config # npm
pnpm add -D @hazmi35/eslint-config # pnpm
yarn add -D @hazmi35/eslint-config # yarn
This package has the required dependency installed automatically by peer dependencies by default on npm v7+, pnpm, or yarn. Install them manually if not.
This package requires ESLint Flat Configuration.
Available configurations:
- common - Common JavaScript rules.
- typescript - For usage with TypeScript
- stylistic - For code styling with ESLint Stylistic. (Exclusive with Prettier)
- prettier - For code styling with Prettier. (Exclusive with ESLint Stylistic)
- browser - For usage within a browser environment (DOM and Web APIs).
- node - For usage within a Node.js or Bun environment.
- edge - For usage within an edge/serverless environment. For example Cloudflare Workers.
- modules - For usage with ES Modules.
- ignores - To enable global ignores for ESLint. Needed for ESLint to ignore files that shouldn't be linted.
Create an eslint.config.js
file in the root of your project and add the following code:
Node.js with ESM
import { common, modules, node, stylistic, ignores } from "@hazmi35/eslint-config";
export default [...common, ...modules, ...node, ...stylistic, ...ignores];
Node.js with CJS
module.exports = (async () => {
const { common, node, stylistic, ignores } = await import("@hazmi35/eslint-config");
return [...common, ...node, ...stylistic, ...ignores];
})();
Node.js with TypeScript
import { common, modules, node, stylistic, typescript, ignores } from "@hazmi35/eslint-config";
export default [...common, ...modules, ...node, ...stylistic, ...typescript, ...ignores];
Usage with Prettier
import { common, modules, node, prettier, ignores } from "@hazmi35/eslint-config";
// Prettier must not be used with stylistic config, because it will conflict with each other.
export default [...common, ...modules, ...node, ...prettier, ...ignores];
Extending rules
Extending rules using the extend function is recommended.
import { common, extend, modules, node, stylistic, typescript, ignores } from "./index.js";
export default [...common, ...modules, ...node, ...stylistic, ...ignores, ...extend(typescript, [
{
rule: "typescript/no-unnecessary-condition",
option: [
"warn",
{
allowConstantLoopConditions: false
}
]
// or
option: ["off"]
}
])];