Skip to content

Commit e7cfbf1

Browse files
ocavueljharb
authored andcommitted
[Fix] correct generated type declaration
1 parent 5c23573 commit e7cfbf1

File tree

9 files changed

+40
-31
lines changed

9 files changed

+40
-31
lines changed

index.js

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function filterRules(rules, predicate) {
1111

1212
/**
1313
* @param {object} rules - rules object mapping rule name to rule module
14-
* @returns {Record<string, 2 | 'error'>}
14+
* @returns {Record<string, SEVERITY_ERROR | 'error'>}
1515
*/
1616
function configureAsError(rules) {
1717
return fromEntries(Object.keys(rules).map((key) => [`react/${key}`, 2]));
@@ -31,6 +31,9 @@ const plugins = [
3131
'react',
3232
];
3333

34+
const SEVERITY_ERROR = /** @type {2} */ (2);
35+
const SEVERITY_OFF = /** @type {0} */ (0);
36+
3437
const configs = {
3538
recommended: {
3639
plugins,
@@ -40,28 +43,28 @@ const configs = {
4043
},
4144
},
4245
rules: {
43-
'react/display-name': 2,
44-
'react/jsx-key': 2,
45-
'react/jsx-no-comment-textnodes': 2,
46-
'react/jsx-no-duplicate-props': 2,
47-
'react/jsx-no-target-blank': 2,
48-
'react/jsx-no-undef': 2,
49-
'react/jsx-uses-react': 2,
50-
'react/jsx-uses-vars': 2,
51-
'react/no-children-prop': 2,
52-
'react/no-danger-with-children': 2,
53-
'react/no-deprecated': 2,
54-
'react/no-direct-mutation-state': 2,
55-
'react/no-find-dom-node': 2,
56-
'react/no-is-mounted': 2,
57-
'react/no-render-return-value': 2,
58-
'react/no-string-refs': 2,
59-
'react/no-unescaped-entities': 2,
60-
'react/no-unknown-property': 2,
61-
'react/no-unsafe': 0,
62-
'react/prop-types': 2,
63-
'react/react-in-jsx-scope': 2,
64-
'react/require-render-return': 2,
46+
'react/display-name': SEVERITY_ERROR,
47+
'react/jsx-key': SEVERITY_ERROR,
48+
'react/jsx-no-comment-textnodes': SEVERITY_ERROR,
49+
'react/jsx-no-duplicate-props': SEVERITY_ERROR,
50+
'react/jsx-no-target-blank': SEVERITY_ERROR,
51+
'react/jsx-no-undef': SEVERITY_ERROR,
52+
'react/jsx-uses-react': SEVERITY_ERROR,
53+
'react/jsx-uses-vars': SEVERITY_ERROR,
54+
'react/no-children-prop': SEVERITY_ERROR,
55+
'react/no-danger-with-children': SEVERITY_ERROR,
56+
'react/no-deprecated': SEVERITY_ERROR,
57+
'react/no-direct-mutation-state': SEVERITY_ERROR,
58+
'react/no-find-dom-node': SEVERITY_ERROR,
59+
'react/no-is-mounted': SEVERITY_ERROR,
60+
'react/no-render-return-value': SEVERITY_ERROR,
61+
'react/no-string-refs': SEVERITY_ERROR,
62+
'react/no-unescaped-entities': SEVERITY_ERROR,
63+
'react/no-unknown-property': SEVERITY_ERROR,
64+
'react/no-unsafe': SEVERITY_OFF,
65+
'react/prop-types': SEVERITY_ERROR,
66+
'react/react-in-jsx-scope': SEVERITY_ERROR,
67+
'react/require-render-return': SEVERITY_ERROR,
6568
},
6669
},
6770
all: {
@@ -82,8 +85,8 @@ const configs = {
8285
jsxPragma: null, // for @typescript/eslint-parser
8386
},
8487
rules: {
85-
'react/react-in-jsx-scope': 0,
86-
'react/jsx-uses-react': 0,
88+
'react/react-in-jsx-scope': SEVERITY_OFF,
89+
'react/jsx-uses-react': SEVERITY_OFF,
8790
},
8891
},
8992
};

lib/rules/forbid-prop-types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ module.exports = {
195195
const propTypesSpecifier = node.specifiers.find((specifier) => (
196196
'imported' in specifier
197197
&& specifier.imported
198+
&& 'name' in specifier.imported
198199
&& specifier.imported.name === 'PropTypes'
199200
));
200201
if (propTypesSpecifier) {

lib/rules/forward-ref-uses-ref.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const messages = {
4141
removeForwardRef: 'Remove forwardRef wrapper',
4242
};
4343

44+
/** @type {import('eslint').Rule.RuleModule} */
4445
module.exports = {
4546
meta: {
4647
docs: {

lib/rules/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/* eslint global-require: 0 */
44

55
/** @satisfies {Record<string, import('eslint').Rule.RuleModule>} */
6-
module.exports = {
6+
const rules = {
77
'boolean-prop-naming': require('./boolean-prop-naming'),
88
'button-has-type': require('./button-has-type'),
99
'checked-requires-onchange-or-readonly': require('./checked-requires-onchange-or-readonly'),
@@ -108,3 +108,5 @@ module.exports = {
108108
'style-prop-object': require('./style-prop-object'),
109109
'void-dom-elements-no-children': require('./void-dom-elements-no-children'),
110110
};
111+
112+
module.exports = rules;

lib/rules/jsx-fragments.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ module.exports = {
170170
ImportDeclaration(node) {
171171
if (node.source && node.source.value === 'react') {
172172
node.specifiers.forEach((spec) => {
173-
if ('imported' in spec && spec.imported && spec.imported.name === fragmentPragma) {
173+
if ('imported' in spec && spec.imported && 'name' in spec.imported && spec.imported.name === fragmentPragma) {
174174
if (spec.local) {
175175
fragmentNames.add(spec.local.name);
176176
}

lib/rules/jsx-no-literals.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const messages = {
4545
literalNotInJSXExpressionInElement: 'Missing JSX expression container around literal string: "{{text}}" in {{element}}',
4646
};
4747

48-
/** @type {Exclude<import('eslint').Rule.RuleModule['meta']['schema'], unknown[]>['properties']} */
48+
/** @type {Exclude<import('eslint').Rule.RuleModule['meta']['schema'], unknown[] | false>['properties']} */
4949
const commonPropertiesSchema = {
5050
noStrings: {
5151
type: 'boolean',
@@ -182,6 +182,7 @@ const elementOverrides = {
182182
},
183183
};
184184

185+
/** @type {import('eslint').Rule.RuleModule} */
185186
module.exports = {
186187
meta: /** @type {import('eslint').Rule.RuleModule["meta"]} */ ({
187188
docs: {
@@ -485,7 +486,7 @@ module.exports = {
485486
});
486487
});
487488
},
488-
} : false, {
489+
} : {}, {
489490
Literal(node) {
490491
const resolvedConfig = getOverrideConfig(node) || config;
491492

lib/rules/jsx-props-no-spread-multi.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const messages = {
1616
noMultiSpreading: 'Spreading the same expression multiple times is forbidden',
1717
};
1818

19+
/** @type {import('eslint').Rule.RuleModule} */
1920
module.exports = {
2021
meta: {
2122
docs: {

lib/rules/no-deprecated.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ module.exports = {
229229
}
230230
node.specifiers.filter(((s) => 'imported' in s && s.imported)).forEach((specifier) => {
231231
// TODO, semver-major: remove `in` check as part of jsdoc->tsdoc migration
232-
checkDeprecation(node, 'imported' in specifier && `${MODULES[node.source.value][0]}.${specifier.imported.name}`, specifier);
232+
checkDeprecation(node, 'imported' in specifier && 'name' in specifier.imported && `${MODULES[node.source.value][0]}.${specifier.imported.name}`, specifier);
233233
});
234234
},
235235

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"@types/node": "^4.9.5",
6161
"@typescript-eslint/parser": "^2.34.0 || ^3.10.1 || ^4 || ^5 || ^6.20 || ^7.14.1 || ^8.4",
6262
"babel-eslint": "^8 || ^9 || ^10.1.0",
63-
"eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8 || ^9.7",
63+
"eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8 || ^9.10",
6464
"eslint-config-airbnb-base": "^15.0.0",
6565
"eslint-doc-generator": "^1.7.1",
6666
"eslint-plugin-eslint-plugin": "^2.3.0 || ^3.5.3 || ^4.0.1 || ^5.0.5",

0 commit comments

Comments
 (0)