Skip to content
jshacks.dev
Tooling

Share an ESLint config across packages

Share one ESLint 9 flat config across workspace packages by exporting an array from a package and spreading it into each package's eslint.config.js.

1 min read
Summarize in AI

A flat config is a plain array of objects, so sharing it is a normal import. Put the shared rules in their own workspace package and spread them where you need them.

packages/eslint-config/index.jsJavaScript
import js from '@eslint/js';

export const base = [
  js.configs.recommended,
  { rules: { eqeqeq: 'error', 'no-var': 'error' } },
];
packages/web/eslint.config.jsJavaScript
import { base } from '@acme/eslint-config';

export default [
  ...base,
  { files: ['src/**/*.js'], rules: { 'no-console': 'warn' } },
];
packages/eslint-config/package.jsonJSON
{
  "name": "@acme/eslint-config",
  "version": "1.0.0",
  "type": "module",
  "exports": "./index.js"
}

Each package still owns an eslint.config.js, because ESLint looks for the config next to the file it lints, starting from where you run it. Later objects override earlier ones, so a package adds its own object after the spread. Flat config is covered in the ESLint configuration docs.

Do not export a single merged object from the shared package. Export the array, so each consumer can spread it and keep control of the order.

Taggedeslint
Share

More snippets

Tooling

Create a Vite project from a template

Create a Vite project from a template with npm create vite, choose the vanilla-ts or react-ts template and see which files it generates.

1 min read
Tooling

Configure VS Code settings for a team

Share VS Code settings and recommended extensions with a team by committing a .vscode folder with settings.json and extensions.json.

1 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.