Skip to content

Commit 28e369c

Browse files
authored
Use disallow instead of forbid in rule descriptions (#1777)
1 parent 09923af commit 28e369c

11 files changed

+118
-17
lines changed

docs/rules/no-await-expression-member.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Forbid member access from await expression
1+
# Disallow member access from await expression
22

33
<!-- Do not manually modify RULE_NOTICE part. Run: `npm run generate-rule-notices` -->
44
<!-- RULE_NOTICE -->

docs/rules/no-static-only-class.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Forbid classes that only have static members
1+
# Disallow classes that only have static members
22

33
<!-- Do not manually modify RULE_NOTICE part. Run: `npm run generate-rule-notices` -->
44
<!-- RULE_NOTICE -->

docs/rules/no-useless-fallback-in-spread.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Forbid useless fallback when spreading in object literals
1+
# Disallow useless fallback when spreading in object literals
22

33
<!-- Do not manually modify RULE_NOTICE part. Run: `npm run generate-rule-notices` -->
44
<!-- RULE_NOTICE -->

package.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,9 @@
161161
"files": [
162162
"rules/**/*.js"
163163
],
164-
"plugins": [
165-
"internal-rules"
166-
],
167-
"rules": {
168-
"internal-rules/prefer-negative-boolean-attribute": "error"
169-
}
164+
"extends": [
165+
"plugin:internal-rules/all"
166+
]
170167
}
171168
]
172169
},

readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Each rule has emojis denoting:
7373
| [no-array-method-this-argument](docs/rules/no-array-method-this-argument.md) | Disallow using the `this` argument in array methods. || 🔧 | 💡 |
7474
| [no-array-push-push](docs/rules/no-array-push-push.md) | Enforce combining multiple `Array#push()` into one call. || 🔧 | 💡 |
7575
| [no-array-reduce](docs/rules/no-array-reduce.md) | Disallow `Array#reduce()` and `Array#reduceRight()`. || | |
76-
| [no-await-expression-member](docs/rules/no-await-expression-member.md) | Forbid member access from await expression. || 🔧 | |
76+
| [no-await-expression-member](docs/rules/no-await-expression-member.md) | Disallow member access from await expression. || 🔧 | |
7777
| [no-console-spaces](docs/rules/no-console-spaces.md) | Do not use leading/trailing space between `console.log` parameters. || 🔧 | |
7878
| [no-document-cookie](docs/rules/no-document-cookie.md) | Do not use `document.cookie` directly. || | |
7979
| [no-empty-file](docs/rules/no-empty-file.md) | Disallow empty files. || | |
@@ -89,13 +89,13 @@ Each rule has emojis denoting:
8989
| [no-null](docs/rules/no-null.md) | Disallow the use of the `null` literal. || 🔧 | 💡 |
9090
| [no-object-as-default-parameter](docs/rules/no-object-as-default-parameter.md) | Disallow the use of objects as default parameters. || | |
9191
| [no-process-exit](docs/rules/no-process-exit.md) | Disallow `process.exit()`. || | |
92-
| [no-static-only-class](docs/rules/no-static-only-class.md) | Forbid classes that only have static members. || 🔧 | |
92+
| [no-static-only-class](docs/rules/no-static-only-class.md) | Disallow classes that only have static members. || 🔧 | |
9393
| [no-thenable](docs/rules/no-thenable.md) | Disallow `then` property. || | |
9494
| [no-this-assignment](docs/rules/no-this-assignment.md) | Disallow assigning `this` to a variable. || | |
9595
| [no-unreadable-array-destructuring](docs/rules/no-unreadable-array-destructuring.md) | Disallow unreadable array destructuring. || 🔧 | |
9696
| [no-unsafe-regex](docs/rules/no-unsafe-regex.md) | Disallow unsafe regular expressions. | | | |
9797
| [no-unused-properties](docs/rules/no-unused-properties.md) | Disallow unused object properties. | | | |
98-
| [no-useless-fallback-in-spread](docs/rules/no-useless-fallback-in-spread.md) | Forbid useless fallback when spreading in object literals. || 🔧 | |
98+
| [no-useless-fallback-in-spread](docs/rules/no-useless-fallback-in-spread.md) | Disallow useless fallback when spreading in object literals. || 🔧 | |
9999
| [no-useless-length-check](docs/rules/no-useless-length-check.md) | Disallow useless array length check. || 🔧 | |
100100
| [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 || 🔧 | |
101101
| [no-useless-spread](docs/rules/no-useless-spread.md) | Disallow unnecessary spread. || 🔧 | |

rules/no-await-expression-member.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ module.exports = {
7676
meta: {
7777
type: 'suggestion',
7878
docs: {
79-
description: 'Forbid member access from await expression.',
79+
description: 'Disallow member access from await expression.',
8080
},
8181
fixable: 'code',
8282
messages,

rules/no-static-only-class.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ module.exports = {
221221
meta: {
222222
type: 'suggestion',
223223
docs: {
224-
description: 'Forbid classes that only have static members.',
224+
description: 'Disallow classes that only have static members.',
225225
},
226226
fixable: 'code',
227227
messages,

rules/no-useless-fallback-in-spread.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ module.exports = {
6262
meta: {
6363
type: 'suggestion',
6464
docs: {
65-
description: 'Forbid useless fallback when spreading in object literals.',
65+
description: 'Disallow useless fallback when spreading in object literals.',
6666
},
6767
fixable: 'code',
6868
messages,

scripts/internal-rules/index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
'use strict';
22

3+
const pluginName = 'internal-rules';
4+
5+
const rules = [
6+
'prefer-negative-boolean-attribute',
7+
'prefer-disallow-over-forbid',
8+
];
9+
310
module.exports = {
4-
rules: {
5-
'prefer-negative-boolean-attribute': require('./prefer-negative-boolean-attribute.js'),
11+
rules: Object.fromEntries(rules.map(id => [id, require(`./${id}.js`)])),
12+
configs: {
13+
all: {
14+
plugins: [pluginName],
15+
rules: Object.fromEntries(rules.map(id => [`${pluginName}/${id}`, 'error'])),
16+
},
617
},
718
};

scripts/internal-rules/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"private": true,
33
"name": "eslint-plugin-internal-rules",
4+
"version": "0.0.0",
45
"description": "Internal rules",
56
"license": "MIT"
67
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
'use strict';
2+
const path = require('path');
3+
const {matches} = require('../../rules/selectors/index.js');
4+
const toLocation = require('../../rules/utils/to-location.js');
5+
6+
const messageId = path.basename(__filename, '.js');
7+
8+
const messageSelector = [
9+
matches([
10+
// `const messages = {...}`;
11+
[
12+
'VariableDeclarator',
13+
'[id.type="Identifier"]',
14+
'[id.name="messages"]',
15+
],
16+
// `{meta: {messages = {...}}}`;
17+
[
18+
'Property',
19+
'[key.type="Identifier"]',
20+
'[key.name="messages"]',
21+
],
22+
]),
23+
' > ',
24+
'ObjectExpression.init',
25+
' > ',
26+
'Property.properties',
27+
' > ',
28+
'Literal.value',
29+
].join('');
30+
31+
const descriptionSelector = [
32+
'Property',
33+
'[computed!=true]',
34+
' > ',
35+
'Literal.value',
36+
].join('');
37+
38+
const selector = matches([messageSelector, descriptionSelector]);
39+
40+
const words = [
41+
{word: 'forbid', replacement: 'disallow'},
42+
{word: 'forbidden', replacement: 'disallowed'},
43+
];
44+
45+
module.exports = {
46+
create(context) {
47+
return {
48+
[selector](node) {
49+
const {value} = node;
50+
if (typeof value !== 'string') {
51+
return;
52+
}
53+
54+
const message = node.raw.slice(1, -1);
55+
const lowerCased = message.toLowerCase();
56+
57+
for (let {word, replacement} of words) {
58+
const index = lowerCased.indexOf(word);
59+
60+
if (index === -1) {
61+
continue;
62+
}
63+
64+
const original = message.slice(index, index + word.length);
65+
66+
if (/^[A-Z]/.test(original)) {
67+
replacement = replacement[0].toUpperCase() + replacement.slice(1);
68+
}
69+
70+
const start = node.range[0] + index + 1;
71+
const range = [start, start + word.length];
72+
context.report({
73+
node,
74+
loc: toLocation(range, context.getSourceCode()),
75+
messageId,
76+
data: {original, replacement},
77+
fix: fixer => fixer.replaceTextRange(range, replacement),
78+
});
79+
80+
// Only report one problem
81+
return;
82+
}
83+
},
84+
};
85+
},
86+
meta: {
87+
fixable: 'code',
88+
messages: {
89+
[messageId]: 'Prefer use `{{replacement}}` over `{{original}}` in error message and rule description.',
90+
},
91+
},
92+
};

0 commit comments

Comments
 (0)