Registry / testing / eslint-no-restricted

eslint-no-restricted

JSON →
library0.1.1jsnpmunverified

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-restricted
INSTALL
IMPORT
SIG · ESLINT-NO-RESTRICT
E
eslint-no-restricted
testingjavascriptv0.1.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

create
import { create } from 'eslint-no-restricted/globals';
import { create } from 'eslint-no-restricted';
The `create` function is exported from specific sub-paths like `/globals`, `/properties`, or `/syntax`, not directly from the root package.
RuleBase
import type { RuleBase } from 'eslint-no-restricted/shared';
`RuleBase` is a shared interface for common rule options and should be imported as a type from the `/shared` sub-path for TypeScript usage.
RuleConfig
import type { RuleConfig } from 'eslint-no-restricted/properties';
`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.

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.

import { create } from 'eslint-no-restricted/properties'; import type { RuleConfig } from 'eslint-no-restricted/properties'; import path from 'path'; // my-eslint-plugin/rules/no-console-log.ts const noConsoleLogRuleConfig: RuleConfig = { name: 'no-console-log', message: 'Using {{property}} on {{object}} is not allowed. Please use a dedicated logger instead.', properties: { object: 'console', property: 'log', }, defaultLevel: 'error', docUrl: 'https://example.com/docs/no-console-log', }; const noConsoleLog = create(noConsoleLogRuleConfig); // my-eslint-plugin/index.ts (main plugin file) export = { rules: { 'no-console-log': noConsoleLog, }, // Optionally, you can add recommended configs // configs: { // recommended: { // plugins: ['my-plugin'], // rules: { // 'my-plugin/no-console-log': 'error', // }, // }, // }, }; // .eslintrc.js (example ESLint configuration) // module.exports = { // root: true, // plugins: [ // // Assuming your custom plugin is in a directory relative to .eslintrc.js // path.resolve(__dirname, 'my-eslint-plugin'), // ], // rules: { // 'my-eslint-plugin/no-console-log': 'error', // 'no-debugger': 'error', // }, // parserOptions: { // ecmaVersion: 'latest', // sourceType: 'module', // }, // env: { // node: true, // browser: true, // }, // };
Debug
Known issues
breakingVersion 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.
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.
affects: >=0.1.0
gotchaPrior 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.
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`).
affects: <0.0.10
gotchaThis 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.
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`.
affects: >=0.0.1
Errors
Common errors & fixes
TypeError: (0 , eslint_no_restricted_properties__WEBPACK_IMPORTED_MODULE_0__.create) is not a function
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.
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.
ESLint: Definition for rule 'my-plugin/no-console-log' was not found.
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.
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.
Upgrade
Version history
0.1.1latest on npm
Audit
Dependencies
eslintrequiredPeer dependency as it's an ESLint utility. Requires ESLint v8.57.0, v9, or v10.
Agent activity
4 hits · last 30 days
node
4
Resources
eslint-no-restricted — npm install eslint-no-restricted · libregistry