eslint-plugin-utils is a utility library for building ESLint plugins and custom rules, developed as part of the un-ts monorepo. The current stable version is 0.4.1, released in December 2024, with a focus on compatibility with ESLint flat config and TypeScript. It provides helpers for rule creation, schema validation, and AST traversal, reducing boilerplate for ESLint plugin authors. Key differentiators include first-class TypeScript support with bundled types, dependency on @typescript-eslint/utils for type-safe rule creation, and support for both legacy and flat ESLint configurations. The package follows semver and is updated as part of a monorepo with several related plugins (text, markup, htm).
npm install eslint-plugin-utilsVerified import paths — ran on the pinned version, not inferred.
Shows how to create a simple ESLint custom rule using createRule from eslint-plugin-utils with type-safe options and a fixer.
Use import syntax instead of require(). If using CommonJS, upgrade to ESM or stick with v0.3.x.
Replace import eslintPluginUtils from 'eslint-plugin-utils' with import * as utils from 'eslint-plugin-utils' or destructure named exports.
Ensure you pass defaultOptions as part of the rule definition, even if empty array.
Always provide a filename in flat config context or handle undefined case.
Install @typescript-eslint/utils as a dev dependency: npm install --save-dev @typescript-eslint/utils
Use 'docs.recommended' as string like 'error' or 'warn' instead of boolean.
Set 'moduleResolution' to 'node16' or 'bundler' in tsconfig.json, or use 'esModuleInterop'.
Change to import statement: import { createRule } from 'eslint-plugin-utils'Add defaultOptions: [] to the rule definition.
Ensure you have @typescript-eslint/parser installed and configured in ESLint config.