eslint-no-restricted is a utility for generating highly customizable ESLint rules, serving as a powerful alternative to the core `no-restricted-syntax`, `no-restricted-globals`, and `no-restricted-properties` rules. Currently at version 0.1.1, the package is actively maintained with frequent minor releases, typically for feature enhancements and bug fixes. Its key differentiators include the ability to create individual ESLint rules for each specific restricted item (AST selector, global variable, or object property), allowing for granular control over severity levels and more precise disabling via comments. This contrasts with the core rules which lump all restrictions into a single configurable rule. Additionally, it supports message placeholders, enabling developers to create more targeted and informative error messages based on the code context. It supports Node.js `^20.9.0 || >=22.0.0` and is compatible with `eslint` versions `^8.57.0 || ^9 || ^10`, shipping with full TypeScript type definitions.
npm install eslint-no-restrictedVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates creating a custom ESLint rule that disallows `console.log` using `eslint-no-restricted/properties`, and integrating it into an ESLint configuration. It shows the `create` function for rule definition and how to expose it through a custom ESLint plugin.
Review TypeScript code consuming the `create` function's return value and adjust types if necessary to match the stricter `Plugin` interface. Consult the package's type definitions for the exact new shape.
Ensure Node.js environment is `^20.9.0 || >=22.0.0` as specified, and use version `0.0.10` or newer. Configure `tsconfig.json` with appropriate `moduleResolution` (e.g., `Node16` or `Bundler`) and `module` settings (e.g., `ESNext`).
Always ensure your `eslint` installation matches the peer dependency range (`^8.57.0 || ^9 || ^10`). Use `npm install` or `yarn add` to automatically resolve compatible versions, or manually check with `npm ls eslint`.
If using CommonJS, use `const { create } = require('eslint-no-restricted/properties');`. If using ESM, ensure `package.json` has `"type": "module"` or files end in `.mjs`, and verify bundler configuration correctly handles ESM imports. For TypeScript, ensure `moduleResolution` is correctly configured.Verify that your custom plugin (e.g., `my-eslint-plugin/index.ts`) is correctly exported and that its path is specified in the `plugins` array of your `.eslintrc` file. Also, ensure the rule name in `rules` (`'my-plugin/no-console-log'`) matches the plugin's name and the rule's `name` property.