Skip to content

Commit

Permalink
Use disallow instead of forbid in rule descriptions (#1777)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker authored Mar 31, 2022
1 parent 09923af commit 28e369c
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docs/rules/no-await-expression-member.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Forbid member access from await expression
# Disallow member access from await expression

<!-- Do not manually modify RULE_NOTICE part. Run: `npm run generate-rule-notices` -->
<!-- RULE_NOTICE -->
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-static-only-class.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Forbid classes that only have static members
# Disallow classes that only have static members

<!-- Do not manually modify RULE_NOTICE part. Run: `npm run generate-rule-notices` -->
<!-- RULE_NOTICE -->
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-useless-fallback-in-spread.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Forbid useless fallback when spreading in object literals
# Disallow useless fallback when spreading in object literals

<!-- Do not manually modify RULE_NOTICE part. Run: `npm run generate-rule-notices` -->
<!-- RULE_NOTICE -->
Expand Down
9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,9 @@
"files": [
"rules/**/*.js"
],
"plugins": [
"internal-rules"
],
"rules": {
"internal-rules/prefer-negative-boolean-attribute": "error"
}
"extends": [
"plugin:internal-rules/all"
]
}
]
},
Expand Down
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Each rule has emojis denoting:
| [no-array-method-this-argument](docs/rules/no-array-method-this-argument.md) | Disallow using the `this` argument in array methods. || 🔧 | 💡 |
| [no-array-push-push](docs/rules/no-array-push-push.md) | Enforce combining multiple `Array#push()` into one call. || 🔧 | 💡 |
| [no-array-reduce](docs/rules/no-array-reduce.md) | Disallow `Array#reduce()` and `Array#reduceRight()`. || | |
| [no-await-expression-member](docs/rules/no-await-expression-member.md) | Forbid member access from await expression. || 🔧 | |
| [no-await-expression-member](docs/rules/no-await-expression-member.md) | Disallow member access from await expression. || 🔧 | |
| [no-console-spaces](docs/rules/no-console-spaces.md) | Do not use leading/trailing space between `console.log` parameters. || 🔧 | |
| [no-document-cookie](docs/rules/no-document-cookie.md) | Do not use `document.cookie` directly. || | |
| [no-empty-file](docs/rules/no-empty-file.md) | Disallow empty files. || | |
Expand All @@ -89,13 +89,13 @@ Each rule has emojis denoting:
| [no-null](docs/rules/no-null.md) | Disallow the use of the `null` literal. || 🔧 | 💡 |
| [no-object-as-default-parameter](docs/rules/no-object-as-default-parameter.md) | Disallow the use of objects as default parameters. || | |
| [no-process-exit](docs/rules/no-process-exit.md) | Disallow `process.exit()`. || | |
| [no-static-only-class](docs/rules/no-static-only-class.md) | Forbid classes that only have static members. || 🔧 | |
| [no-static-only-class](docs/rules/no-static-only-class.md) | Disallow classes that only have static members. || 🔧 | |
| [no-thenable](docs/rules/no-thenable.md) | Disallow `then` property. || | |
| [no-this-assignment](docs/rules/no-this-assignment.md) | Disallow assigning `this` to a variable. || | |
| [no-unreadable-array-destructuring](docs/rules/no-unreadable-array-destructuring.md) | Disallow unreadable array destructuring. || 🔧 | |
| [no-unsafe-regex](docs/rules/no-unsafe-regex.md) | Disallow unsafe regular expressions. | | | |
| [no-unused-properties](docs/rules/no-unused-properties.md) | Disallow unused object properties. | | | |
| [no-useless-fallback-in-spread](docs/rules/no-useless-fallback-in-spread.md) | Forbid useless fallback when spreading in object literals. || 🔧 | |
| [no-useless-fallback-in-spread](docs/rules/no-useless-fallback-in-spread.md) | Disallow useless fallback when spreading in object literals. || 🔧 | |
| [no-useless-length-check](docs/rules/no-useless-length-check.md) | Disallow useless array length check. || 🔧 | |
| [no-useless-promise-resolve-reject](docs/rules/no-useless-promise-resolve-reject.md) | Disallow returning/yielding `Promise.resolve/reject()` in async functions or promise callbacks || 🔧 | |
| [no-useless-spread](docs/rules/no-useless-spread.md) | Disallow unnecessary spread. || 🔧 | |
Expand Down
2 changes: 1 addition & 1 deletion rules/no-await-expression-member.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Forbid member access from await expression.',
description: 'Disallow member access from await expression.',
},
fixable: 'code',
messages,
Expand Down
2 changes: 1 addition & 1 deletion rules/no-static-only-class.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Forbid classes that only have static members.',
description: 'Disallow classes that only have static members.',
},
fixable: 'code',
messages,
Expand Down
2 changes: 1 addition & 1 deletion rules/no-useless-fallback-in-spread.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Forbid useless fallback when spreading in object literals.',
description: 'Disallow useless fallback when spreading in object literals.',
},
fixable: 'code',
messages,
Expand Down
15 changes: 13 additions & 2 deletions scripts/internal-rules/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
'use strict';

const pluginName = 'internal-rules';

const rules = [
'prefer-negative-boolean-attribute',
'prefer-disallow-over-forbid',
];

module.exports = {
rules: {
'prefer-negative-boolean-attribute': require('./prefer-negative-boolean-attribute.js'),
rules: Object.fromEntries(rules.map(id => [id, require(`./${id}.js`)])),
configs: {
all: {
plugins: [pluginName],
rules: Object.fromEntries(rules.map(id => [`${pluginName}/${id}`, 'error'])),
},
},
};
1 change: 1 addition & 0 deletions scripts/internal-rules/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"private": true,
"name": "eslint-plugin-internal-rules",
"version": "0.0.0",
"description": "Internal rules",
"license": "MIT"
}
92 changes: 92 additions & 0 deletions scripts/internal-rules/prefer-disallow-over-forbid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
'use strict';
const path = require('path');
const {matches} = require('../../rules/selectors/index.js');
const toLocation = require('../../rules/utils/to-location.js');

const messageId = path.basename(__filename, '.js');

const messageSelector = [
matches([
// `const messages = {...}`;
[
'VariableDeclarator',
'[id.type="Identifier"]',
'[id.name="messages"]',
],
// `{meta: {messages = {...}}}`;
[
'Property',
'[key.type="Identifier"]',
'[key.name="messages"]',
],
]),
' > ',
'ObjectExpression.init',
' > ',
'Property.properties',
' > ',
'Literal.value',
].join('');

const descriptionSelector = [
'Property',
'[computed!=true]',
' > ',
'Literal.value',
].join('');

const selector = matches([messageSelector, descriptionSelector]);

const words = [
{word: 'forbid', replacement: 'disallow'},
{word: 'forbidden', replacement: 'disallowed'},
];

module.exports = {
create(context) {
return {
[selector](node) {
const {value} = node;
if (typeof value !== 'string') {
return;
}

const message = node.raw.slice(1, -1);
const lowerCased = message.toLowerCase();

for (let {word, replacement} of words) {
const index = lowerCased.indexOf(word);

if (index === -1) {
continue;
}

const original = message.slice(index, index + word.length);

if (/^[A-Z]/.test(original)) {
replacement = replacement[0].toUpperCase() + replacement.slice(1);
}

const start = node.range[0] + index + 1;
const range = [start, start + word.length];
context.report({
node,
loc: toLocation(range, context.getSourceCode()),
messageId,
data: {original, replacement},
fix: fixer => fixer.replaceTextRange(range, replacement),
});

// Only report one problem
return;
}
},
};
},
meta: {
fixable: 'code',
messages: {
[messageId]: 'Prefer use `{{replacement}}` over `{{original}}` in error message and rule description.',
},
},
};

0 comments on commit 28e369c

Please sign in to comment.