Skip to main content
The defineConfig helper provides type safety and IDE autocompletion when defining ESLint flat configuration files.

Import

const { defineConfig } = require("eslint/config");

// or ES modules
import { defineConfig } from "eslint/config";

Usage

Basic Usage

const { defineConfig } = require("eslint/config");

module.exports = defineConfig({
  rules: {
    "no-console": "error",
    "no-var": "warn"
  }
});

With TypeScript

The primary benefit of defineConfig is type checking in TypeScript projects:
import { defineConfig } from "eslint/config";

export default defineConfig({
  languageOptions: {
    ecmaVersion: 2022,
    sourceType: "module"
  },
  rules: {
    "no-unused-vars": "error"
  }
});

Array of Configs

const { defineConfig } = require("eslint/config");

module.exports = defineConfig([
  {
    files: ["**/*.js"],
    rules: {
      "no-console": "error"
    }
  },
  {
    files: ["**/*.test.js"],
    rules: {
      "no-console": "off"
    }
  }
]);

Function Signature

function defineConfig(config)
config
Config | Config[]
required
A single configuration object or an array of configuration objects.
config
Config | Config[]
Returns the same config(s) passed in, with full type information.

Examples

const { defineConfig } = require("eslint/config");

module.exports = defineConfig({
  languageOptions: {
    ecmaVersion: 2024,
    sourceType: "module",
    globals: {
      window: "readonly",
      document: "readonly"
    }
  },
  rules: {
    "no-console": "warn",
    "no-unused-vars": "error",
    "prefer-const": "error"
  }
});

Benefits

Type Safety

When using TypeScript or JSDoc, defineConfig provides full type checking:
// This will show a type error
module.exports = defineConfig({
  rules: {
    "invalid-rule-name": "error" // IDE will warn about unknown rule
  }
});

IDE Autocompletion

defineConfig enables autocompletion in editors that support TypeScript:
  • Property name suggestions
  • Valid values for options
  • Inline documentation

Runtime Validation

While the primary purpose is type safety, defineConfig also provides runtime validation in development:
const { defineConfig } = require("eslint/config");

// Runtime error if config structure is invalid
module.exports = defineConfig({
  rules: null // Error: rules must be an object
});