{"id":19969,"library":"eslint-plugin-utils","title":"ESLint Plugin Utils","description":"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).","status":"active","version":"0.4.1","language":"javascript","source_language":"en","source_url":"https://github.com/un-ts/eslint","tags":["javascript","eslint","eslint-utils","eslint-plugin-utils","typescript"],"install":[{"cmd":"npm install eslint-plugin-utils","lang":"bash","label":"npm"},{"cmd":"yarn add eslint-plugin-utils","lang":"bash","label":"yarn"},{"cmd":"pnpm add eslint-plugin-utils","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency - the utilities are designed to work with ESLint core","package":"eslint","optional":false},{"reason":"peer dependency - provides TypeScript utilities and types for rule creation","package":"@typescript-eslint/utils","optional":false}],"imports":[{"note":"ESM-only since v0.4.0; the package no longer supports CommonJS require()","wrong":"const { createRule } = require('eslint-plugin-utils')","symbol":"createRule","correct":"import { createRule } from 'eslint-plugin-utils'"},{"note":"Default export was removed in v0.4.0; all utilities are now named exports. Use 'import * as utils' or destructure named exports.","wrong":"import * as utils from 'eslint-plugin-utils'","symbol":"default","correct":"import eslintPluginUtils from 'eslint-plugin-utils'"},{"note":"Use this to reliably get the filename from a context object, works with both legacy and flat config.","symbol":"getFilename","correct":"import { getFilename } from 'eslint-plugin-utils'"},{"note":"Not to be confused with ESLint's built-in RuleTester; this is a re-export from @typescript-eslint/utils with enhanced features.","symbol":"RuleTester","correct":"import { RuleTester } from 'eslint-plugin-utils'"}],"quickstart":{"code":"import { createRule } from 'eslint-plugin-utils';\n\nexport const myRule = createRule({\n  name: 'my-rule',\n  meta: {\n    type: 'suggestion',\n    docs: {\n      description: 'Description of my rule',\n      recommended: 'error',\n    },\n    fixable: 'code',\n    schema: [\n      { type: 'string' }\n    ],\n  },\n  defaultOptions: ['defaultOption'],\n  create: (context, optionsWithDefault) => {\n    return {\n      Literal: (node) => {\n        const [option] = optionsWithDefault;\n        if (typeof node.value !== 'string') return;\n        if (node.value === option) {\n          context.report({\n            node,\n            message: 'Avoid using the default option: {{ option }}',\n            data: { option },\n            fix: (fixer) => fixer.replaceText(node, `'changed'`),\n          });\n        }\n      },\n    };\n  },\n});","lang":"typescript","description":"Shows how to create a simple ESLint custom rule using createRule from eslint-plugin-utils with type-safe options and a fixer."},"warnings":[{"fix":"Use import syntax instead of require(). If using CommonJS, upgrade to ESM or stick with v0.3.x.","message":"ESM-only since 0.4.0; require() is no longer supported.","severity":"breaking","affected_versions":">=0.4.0"},{"fix":"Replace import eslintPluginUtils from 'eslint-plugin-utils' with import * as utils from 'eslint-plugin-utils' or destructure named exports.","message":"Default export removed in 0.4.0; use named exports.","severity":"breaking","affected_versions":">=0.4.0"},{"fix":"Ensure you pass defaultOptions as part of the rule definition, even if empty array.","message":"The createRule function no longer accepts a 'create' callback without defaultOptions - use defaultOptions array in create.","severity":"deprecated","affected_versions":">=0.4.0"},{"fix":"Always provide a filename in flat config context or handle undefined case.","message":"The getFilename function may return undefined in flat config if used without a file name.","severity":"gotcha","affected_versions":">=0.4.0"},{"fix":"Install @typescript-eslint/utils as a dev dependency: npm install --save-dev @typescript-eslint/utils","message":"RuleTester from eslint-plugin-utils requires @typescript-eslint/utils as peer dependency; may cause missing package errors if not installed.","severity":"gotcha","affected_versions":">=0.4.0"},{"fix":"Use 'docs.recommended' as string like 'error' or 'warn' instead of boolean.","message":"The 'recommended' meta property is deprecated in favor of 'recommended' being a string severity in 'docs.recommended'? Verify with ESLint docs.","severity":"deprecated","affected_versions":">=0.4.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Set 'moduleResolution' to 'node16' or 'bundler' in tsconfig.json, or use 'esModuleInterop'.","cause":"Package is ESM-only and not resolved properly in TypeScript without 'moduleResolution': 'node16' or 'bundler'.","error":"Cannot find module 'eslint-plugin-utils' or its corresponding type declarations."},{"fix":"Change to import statement: import { createRule } from 'eslint-plugin-utils'","cause":"Attempted to use require() to import the package, but it's ESM-only.","error":"TypeError: createRule is not a function"},{"fix":"Add defaultOptions: [] to the rule definition.","cause":"Missing defaultOptions in rule definition when using createRule with no defaultOptions provided.","error":"Error: Cannot use 'in' operator to search for 'create' in undefined"},{"fix":"Ensure you have @typescript-eslint/parser installed and configured in ESLint config.","cause":"Using TypeScript-specific utilities without the required parser and plugin.","error":"Error: The 'parserServices' property requires TypeScript and @typescript-eslint/parser to be used."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}