{"id":15606,"library":"eslint-no-restricted","title":"ESLint No Restricted Utility","description":"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.","status":"active","version":"0.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/bradzacher/eslint-no-restricted","tags":["javascript","eslint","typescript"],"install":[{"cmd":"npm install eslint-no-restricted","lang":"bash","label":"npm"},{"cmd":"yarn add eslint-no-restricted","lang":"bash","label":"yarn"},{"cmd":"pnpm add eslint-no-restricted","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency as it's an ESLint utility. Requires ESLint v8.57.0, v9, or v10.","package":"eslint","optional":false}],"imports":[{"note":"The `create` function is exported from specific sub-paths like `/globals`, `/properties`, or `/syntax`, not directly from the root package.","wrong":"import { create } from 'eslint-no-restricted';","symbol":"create","correct":"import { create } from 'eslint-no-restricted/globals';"},{"note":"`RuleBase` is a shared interface for common rule options and should be imported as a type from the `/shared` sub-path for TypeScript usage.","symbol":"RuleBase","correct":"import type { RuleBase } from 'eslint-no-restricted/shared';"},{"note":"`RuleConfig` is a type definition that is specific to the type of restricted rule being created (e.g., `/globals`, `/properties`, or `/syntax`). Import the one relevant to your specific rule definition.","symbol":"RuleConfig","correct":"import type { RuleConfig } from 'eslint-no-restricted/properties';"}],"quickstart":{"code":"import { create } from 'eslint-no-restricted/properties';\nimport type { RuleConfig } from 'eslint-no-restricted/properties';\nimport path from 'path';\n\n// my-eslint-plugin/rules/no-console-log.ts\nconst noConsoleLogRuleConfig: RuleConfig = {\n  name: 'no-console-log',\n  message: 'Using {{property}} on {{object}} is not allowed. Please use a dedicated logger instead.',\n  properties: {\n    object: 'console',\n    property: 'log',\n  },\n  defaultLevel: 'error',\n  docUrl: 'https://example.com/docs/no-console-log',\n};\n\nconst noConsoleLog = create(noConsoleLogRuleConfig);\n\n// my-eslint-plugin/index.ts (main plugin file)\nexport = {\n  rules: {\n    'no-console-log': noConsoleLog,\n  },\n  // Optionally, you can add recommended configs\n  // configs: {\n  //   recommended: {\n  //     plugins: ['my-plugin'],\n  //     rules: {\n  //       'my-plugin/no-console-log': 'error',\n  //     },\n  //   },\n  // },\n};\n\n// .eslintrc.js (example ESLint configuration)\n// module.exports = {\n//   root: true,\n//   plugins: [\n//     // Assuming your custom plugin is in a directory relative to .eslintrc.js\n//     path.resolve(__dirname, 'my-eslint-plugin'),\n//   ],\n//   rules: {\n//     'my-eslint-plugin/no-console-log': 'error',\n//     'no-debugger': 'error',\n//   },\n//   parserOptions: {\n//     ecmaVersion: 'latest',\n//     sourceType: 'module',\n//   },\n//   env: {\n//     node: true,\n//     browser: true,\n//   },\n// };","lang":"typescript","description":"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."},"warnings":[{"fix":"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.","message":"Version 0.1.0 introduced a 'narrowing down' of the `create*` return type. This change might cause TypeScript compilation errors if existing code relied on a broader or less specific type for the plugin object returned by `create` functions.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"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`).","message":"Prior to version 0.0.10, there were issues with TypeScript mistakenly reporting named exports for Node.js 16 when using ESM. Although fixed, developers should be mindful of correct module resolution settings, especially in mixed ESM/CJS environments or when using older Node.js versions, to avoid similar import or type-resolution problems.","severity":"gotcha","affected_versions":"<0.0.10"},{"fix":"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`.","message":"This package is a utility for creating ESLint rules and has `eslint` as a peer dependency. Incompatible `eslint` versions can lead to runtime errors or unexpected behavior.","severity":"gotcha","affected_versions":">=0.0.1"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"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.","cause":"Incorrect CommonJS `require()` syntax or improper ESM setup when using a bundler (like Webpack) that tries to resolve a default export that doesn't exist, or when running in a Node.js environment that struggles with ESM interop for the module.","error":"TypeError: (0 , eslint_no_restricted_properties__WEBPACK_IMPORTED_MODULE_0__.create) is not a function"},{"fix":"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.","cause":"The custom ESLint rule created with `eslint-no-restricted` was not correctly registered in the `.eslintrc` configuration file under the `plugins` or `rules` section, or the path to the custom plugin is incorrect.","error":"ESLint: Definition for rule 'my-plugin/no-console-log' was not found."}],"ecosystem":"npm"}