Gathering detailed insights and metrics for eslint-no-restricted
Gathering detailed insights and metrics for eslint-no-restricted
Gathering detailed insights and metrics for eslint-no-restricted
Gathering detailed insights and metrics for eslint-no-restricted
An eslint plugin for quickly and easily creating no-restricted-syntax rules
npm install eslint-no-restricted
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
5 Stars
14 Commits
1 Watching
2 Branches
1 Contributors
Updated on 19 Nov 2024
TypeScript (84.51%)
JavaScript (15.49%)
Cumulative downloads
Total Downloads
Last day
-9.1%
12,763
Compared to previous day
Last week
25.7%
69,077
Compared to previous week
Last month
0%
168,229
Compared to previous month
Last year
0%
168,229
Compared to previous year
1
1
24
An eslint utility for quickly and easily creating no-restricted-syntax rules.
This utility is a more powerful alternative to the core rules no-restricted-syntax
, no-restricted-globals
, and no-restricted-properties
.
There are two major features you get with this utility over the core rules:
(1) This utility creates one rule per selector/global/property, rather than having one rule for everything. Having multiple rules is useful for many reasons! It allows you to:
(2) This utility allows you to create messages with placeholders. This is powerful because it allows you to provide more targeted, less generic messages to provide a better and more understandable DevX.
1npm i eslint-no-restricted
For brevity following example shows usage of the no-restricted-syntax
utility - but the same API is available for the globals
and properties
variants too.
1// eslint.config.mjs
2
3import createNoRestrictedSyntax from 'eslint-no-restricted/syntax';
4
5const noRestrictedSyntax = createNoRestrictedSyntax(
6 // define a single selector with a message
7 {
8 message: 'errors on identifiers named foo',
9 name: 'ban-the-name-foo',
10 selector: 'Identifier[name = "foo"]',
11 },
12
13 // define multiple selectors with the same message
14 {
15 message: 'errors on the string "bar"',
16 name: 'do-not-allow-the-string-bar',
17 selector: [
18 'Literal[value = "bar"]',
19 'TemplateLiteral[quasis.length = 1] > TemplateElement[value.cooked = "bar"]',
20 ],
21 },
22
23 // define one or more selectors with a placeholder derived from the matched node
24 {
25 message: 'this message has a placeholder ->{{placeholder}}<-',
26 messageData: (node, sourceCode) => {
27 if (node.parent?.type === 'VariableDeclarator') {
28 return {
29 placeholder: sourceCode.getText(node.parent.id),
30 };
31 }
32 return {
33 placeholder: 'wtf',
34 };
35 },
36 name: 'disallow-the-number-1',
37 selector: 'Literal[value = 1]',
38 },
39);
40
41export default [
42 // turn on all of the rules using the auto-generated configuration
43 noRestrictedSyntax.configs.recommended,
44
45 // you can also manually configure the rules
46 {
47 files: ['**/some-glob/*.js'],
48 plugins: {
49 nrs: noRestrictedSyntax,
50 },
51 rules: {
52 'nrs/disallow-the-number-1': 'off',
53 },
54 },
55];
No vulnerabilities found.
No security vulnerabilities found.