ESLint Plugin Format
raw JSON → 2.0.1 verified Sat Apr 25 auth: no javascript
An ESLint plugin that integrates multiple formatters (Prettier, dprint, oxfmt) for formatting various languages directly through ESLint rules. Current stable version is 2.0.1, released with support for ESLint v8 through v10, TypeScript types included. Key differentiators: side-effects-free, flat config native, supports multiple formatters in one plugin, and does not require language detection or external config files. Each file type must be explicitly configured with a formatter and options, giving full control but requiring manual setup.
Common errors
error Cannot find module 'eslint-plugin-format' ↓
cause Missing dependency or using incorrect import path in CJS context
fix
Run 'npm install eslint-plugin-format --save-dev'. For CJS, pin to v1.x or use dynamic import().
error Error: The 'format/prettier' rule expects a `parser` option ↓
cause Prettier parser not specified in rule options
fix
Add parser option: 'format/prettier': ['error', { parser: 'css' }]
error Error: dprint plugin not found ↓
cause Path to dprint WASM plugin is incorrect or plugin not installed
fix
Verify the path: plugin: 'node_modules/dprint-plugin-<name>/plugin.wasm' or use an absolute path.
error TypeError: format is not a function ↓
cause Using destructured import `{ format }` instead of default import
fix
Use
import format from 'eslint-plugin-format' Warnings
breaking CJS support dropped in v2.0.0 ↓
fix Use ESM imports. If CJS is required, pin to v1.x (e.g., 'eslint-plugin-format': '^1.5.0')
gotcha No default configs: formatters only apply to files explicitly configured with a rule ↓
fix Add a rule with matching `files` pattern for each file type you want to format. The plugin does not apply to all files automatically.
deprecated Prettier parser option may be deprecated in future versions; prefer explicit parser per file type ↓
fix Always specify a parser in format/prettier options. The rule will not infer from file extension.
gotcha dprint requires WASM plugins; local paths may fail if binary not found ↓
fix Ensure dprint plugin WASM files are installed or use a URL. Example: plugin: 'node_modules/dprint-plugin-malva/plugin.wasm'
breaking oxfmt rule changed behavior for unsupported file types in v2.0.1 ↓
fix Upgrade to >=2.0.1 to ignore unsupported file type errors gracefully.
Install
npm install eslint-plugin-format yarn add eslint-plugin-format pnpm add eslint-plugin-format Imports
- format (default) wrong
import { format } from 'eslint-plugin-format'correctimport format from 'eslint-plugin-format' - parserPlain wrong
import { parserPlain } from 'eslint-plugin-format'correctimport format from 'eslint-plugin-format'; const { parserPlain } = format - CommonJS require wrong
const { format } = require('eslint-plugin-format')correctconst format = require('eslint-plugin-format')
Quickstart
// eslint.config.js
import format from 'eslint-plugin-format'
export default [
{
files: ['**/*.css'],
languageOptions: {
parser: format.parserPlain,
},
plugins: {
format,
},
rules: {
'format/prettier': ['error', { parser: 'css' }],
},
},
{
files: ['**/*.toml'],
languageOptions: {
parser: format.parserPlain,
},
plugins: {
format,
},
rules: {
'format/dprint': ['error', { language: 'toml' }],
},
},
]