Skip to content

Commit

Permalink
Update: rename id-blacklist to id-denylist (fixes #13407) (#13408)
Browse files Browse the repository at this point in the history
* Update: rename id-blacklist to id-denylist (fixes #13407)

* Update index.js
  • Loading branch information
kaicataldo committed Jun 25, 2020
1 parent bcf1777 commit 004adae
Show file tree
Hide file tree
Showing 6 changed files with 1,385 additions and 1,382 deletions.
16 changes: 8 additions & 8 deletions docs/rules/id-blacklist.md → docs/rules/id-denylist.md
@@ -1,20 +1,20 @@
# disallow specified identifiers (id-blacklist)
# disallow specified identifiers (id-denylist)

> "There are only two hard things in Computer Science: cache invalidation and naming things." — Phil Karlton
Bad names can lead to hard-to-decipher code. Generic names, such as `data`, don't infer much about the code and the values it receives. This rule allows you to configure a blacklist of bad identifier names, that you don't want to see in your code.
Generic names can lead to hard-to-decipher code. This rule allows you to specify a deny list of disallowed identifier names to avoid this practice.

## Rule Details

This rule disallows specified identifiers in assignments and `function` definitions.

This rule will catch blacklisted identifiers that are:
This rule will catch disallowed identifiers that are:

- variable declarations
- function declarations
- object properties assigned to during object creation

It will not catch blacklisted identifiers that are:
It will not catch disallowed identifiers that are:

- function calls (so you can still use functions you do not have control over)
- object properties (so you can still use objects you do not have control over)
Expand All @@ -27,14 +27,14 @@ For example, to restrict the use of common generic identifiers:

```json
{
"id-blacklist": ["error", "data", "err", "e", "cb", "callback"]
"id-denylist": ["error", "data", "err", "e", "cb", "callback"]
}
```

Examples of **incorrect** code for this rule with sample `"data", "callback"` restricted identifiers:

```js
/*eslint id-blacklist: ["error", "data", "callback"] */
/*eslint id-denylist: ["error", "data", "callback"] */

var data = {...};

Expand All @@ -54,7 +54,7 @@ var itemSet = {
Examples of **correct** code for this rule with sample `"data", "callback"` restricted identifiers:

```js
/*eslint id-blacklist: ["error", "data", "callback"] */
/*eslint id-denylist: ["error", "data", "callback"] */

var encodingOptions = {...};

Expand All @@ -79,4 +79,4 @@ foo.data; // all property names that are not assignments are ignored

## When Not To Use It

You can turn this rule off if you are happy for identifiers to be named freely.
You can turn this rule off if you do not want to restrict the use of certain identifiers.
24 changes: 12 additions & 12 deletions lib/rules/id-blacklist.js → lib/rules/id-denylist.js
@@ -1,6 +1,6 @@
/**
* @fileoverview Rule that warns when identifier names that are
* blacklisted in the configuration are used.
* specified in the configuration are used.
* @author Keith Cirkel (http://keithcirkel.co.uk)
*/

Expand Down Expand Up @@ -117,7 +117,7 @@ module.exports = {
description: "disallow specified identifiers",
category: "Stylistic Issues",
recommended: false,
url: "https://eslint.org/docs/rules/id-blacklist"
url: "https://eslint.org/docs/rules/id-denylist"
},

schema: {
Expand All @@ -128,25 +128,25 @@ module.exports = {
uniqueItems: true
},
messages: {
blacklisted: "Identifier '{{name}}' is blacklisted."
restricted: "Identifier '{{name}}' is restricted."
}
},

create(context) {

const blacklist = new Set(context.options);
const denyList = new Set(context.options);
const reportedNodes = new Set();

let globalScope;

/**
* Checks whether the given name is blacklisted.
* Checks whether the given name is restricted.
* @param {string} name The name to check.
* @returns {boolean} `true` if the name is blacklisted.
* @returns {boolean} `true` if the name is restricted.
* @private
*/
function isBlacklisted(name) {
return blacklist.has(name);
function isRestricted(name) {
return denyList.has(name);
}

/**
Expand All @@ -172,8 +172,8 @@ module.exports = {

/*
* Member access has special rules for checking property names.
* Read access to a property with a blacklisted name is allowed, because it can be on an object that user has no control over.
* Write access isn't allowed, because it potentially creates a new property with a blacklisted name.
* Read access to a property with a restricted name is allowed, because it can be on an object that user has no control over.
* Write access isn't allowed, because it potentially creates a new property with a restricted name.
*/
if (
parent.type === "MemberExpression" &&
Expand Down Expand Up @@ -205,7 +205,7 @@ module.exports = {
if (!reportedNodes.has(node)) {
context.report({
node,
messageId: "blacklisted",
messageId: "restricted",
data: {
name: node.name
}
Expand All @@ -221,7 +221,7 @@ module.exports = {
},

Identifier(node) {
if (isBlacklisted(node.name) && shouldCheck(node)) {
if (isRestricted(node.name) && shouldCheck(node)) {
report(node);
}
}
Expand Down
5 changes: 4 additions & 1 deletion lib/rules/index.js
Expand Up @@ -56,7 +56,10 @@ module.exports = new LazyLoadingRuleMap(Object.entries({
"grouped-accessor-pairs": () => require("./grouped-accessor-pairs"),
"guard-for-in": () => require("./guard-for-in"),
"handle-callback-err": () => require("./handle-callback-err"),
"id-blacklist": () => require("./id-blacklist"),

// Renamed to id-denylist.
"id-blacklist": () => require("./id-denylist"),
"id-denylist": () => require("./id-denylist"),
"id-length": () => require("./id-length"),
"id-match": () => require("./id-match"),
"implicit-arrow-linebreak": () => require("./implicit-arrow-linebreak"),
Expand Down

0 comments on commit 004adae

Please sign in to comment.