Skip to content

Commit

Permalink
[Fix] correct generated type declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
ocavue committed Oct 12, 2024
1 parent 63aceff commit 4290504
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 30 deletions.
51 changes: 27 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const plugins = [
'react',
];

const SEVERITY_ERROR = /** @type {2} */ (2);
const SEVERITY_OFF = /** @type {0} */ (0);

const plugin = {
deprecatedRules,
rules: allRules,
Expand All @@ -39,28 +42,28 @@ const plugin = {
},
},
rules: {
'react/display-name': 2,
'react/jsx-key': 2,
'react/jsx-no-comment-textnodes': 2,
'react/jsx-no-duplicate-props': 2,
'react/jsx-no-target-blank': 2,
'react/jsx-no-undef': 2,
'react/jsx-uses-react': 2,
'react/jsx-uses-vars': 2,
'react/no-children-prop': 2,
'react/no-danger-with-children': 2,
'react/no-deprecated': 2,
'react/no-direct-mutation-state': 2,
'react/no-find-dom-node': 2,
'react/no-is-mounted': 2,
'react/no-render-return-value': 2,
'react/no-string-refs': 2,
'react/no-unescaped-entities': 2,
'react/no-unknown-property': 2,
'react/no-unsafe': 0,
'react/prop-types': 2,
'react/react-in-jsx-scope': 2,
'react/require-render-return': 2,
'react/display-name': SEVERITY_ERROR,
'react/jsx-key': SEVERITY_ERROR,
'react/jsx-no-comment-textnodes': SEVERITY_ERROR,
'react/jsx-no-duplicate-props': SEVERITY_ERROR,
'react/jsx-no-target-blank': SEVERITY_ERROR,
'react/jsx-no-undef': SEVERITY_ERROR,
'react/jsx-uses-react': SEVERITY_ERROR,
'react/jsx-uses-vars': SEVERITY_ERROR,
'react/no-children-prop': SEVERITY_ERROR,
'react/no-danger-with-children': SEVERITY_ERROR,
'react/no-deprecated': SEVERITY_ERROR,
'react/no-direct-mutation-state': SEVERITY_ERROR,
'react/no-find-dom-node': SEVERITY_ERROR,
'react/no-is-mounted': SEVERITY_ERROR,
'react/no-render-return-value': SEVERITY_ERROR,
'react/no-string-refs': SEVERITY_ERROR,
'react/no-unescaped-entities': SEVERITY_ERROR,
'react/no-unknown-property': SEVERITY_ERROR,
'react/no-unsafe': SEVERITY_OFF,
'react/prop-types': SEVERITY_ERROR,
'react/react-in-jsx-scope': SEVERITY_ERROR,
'react/require-render-return': SEVERITY_ERROR,
},
},
all: {
Expand All @@ -81,8 +84,8 @@ const plugin = {
jsxPragma: null, // for @typescript/eslint-parser
},
rules: {
'react/react-in-jsx-scope': 0,
'react/jsx-uses-react': 0,
'react/react-in-jsx-scope': SEVERITY_OFF,
'react/jsx-uses-react': SEVERITY_OFF,
},
},
},
Expand Down
1 change: 1 addition & 0 deletions lib/rules/forbid-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ module.exports = {
const propTypesSpecifier = node.specifiers.find((specifier) => (
'imported' in specifier
&& specifier.imported
&& 'name' in specifier.imported
&& specifier.imported.name === 'PropTypes'
));
if (propTypesSpecifier) {
Expand Down
1 change: 1 addition & 0 deletions lib/rules/forward-ref-uses-ref.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const messages = {
removeForwardRef: 'Remove forwardRef wrapper',
};

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
docs: {
Expand Down
4 changes: 3 additions & 1 deletion lib/rules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* eslint global-require: 0 */

/** @satisfies {Record<string, import('eslint').Rule.RuleModule>} */
module.exports = {
const rules = {
'boolean-prop-naming': require('./boolean-prop-naming'),
'button-has-type': require('./button-has-type'),
'checked-requires-onchange-or-readonly': require('./checked-requires-onchange-or-readonly'),
Expand Down Expand Up @@ -108,3 +108,5 @@ module.exports = {
'style-prop-object': require('./style-prop-object'),
'void-dom-elements-no-children': require('./void-dom-elements-no-children'),
};

module.exports = rules;
2 changes: 1 addition & 1 deletion lib/rules/jsx-fragments.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ module.exports = {
ImportDeclaration(node) {
if (node.source && node.source.value === 'react') {
node.specifiers.forEach((spec) => {
if ('imported' in spec && spec.imported && spec.imported.name === fragmentPragma) {
if ('imported' in spec && spec.imported && 'name' in spec.imported && spec.imported.name === fragmentPragma) {
if (spec.local) {
fragmentNames.add(spec.local.name);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/jsx-no-literals.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const messages = {
literalNotInJSXExpressionInElement: 'Missing JSX expression container around literal string: "{{text}}" in {{element}}',
};

/** @type {Exclude<import('eslint').Rule.RuleModule['meta']['schema'], unknown[]>['properties']} */
/** @type {Exclude<import('eslint').Rule.RuleModule['meta']['schema'], unknown[] | false>['properties']} */
const commonPropertiesSchema = {
noStrings: {
type: 'boolean',
Expand Down Expand Up @@ -182,6 +182,7 @@ const elementOverrides = {
},
};

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: /** @type {import('eslint').Rule.RuleModule["meta"]} */ ({
docs: {
Expand Down
1 change: 1 addition & 0 deletions lib/rules/jsx-props-no-spread-multi.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const messages = {
noMultiSpreading: 'Spreading the same expression multiple times is forbidden',
};

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
docs: {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ module.exports = {
}
node.specifiers.filter(((s) => 'imported' in s && s.imported)).forEach((specifier) => {
// TODO, semver-major: remove `in` check as part of jsdoc->tsdoc migration
checkDeprecation(node, 'imported' in specifier && `${MODULES[node.source.value][0]}.${specifier.imported.name}`, specifier);
checkDeprecation(node, 'imported' in specifier && 'name' in specifier.imported && `${MODULES[node.source.value][0]}.${specifier.imported.name}`, specifier);
});
},

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,11 @@
"@babel/plugin-syntax-do-expressions": "^7.24.7",
"@babel/plugin-syntax-function-bind": "^7.24.7",
"@babel/preset-react": "^7.24.7",
"@types/eslint": "=7.2.10",
"@types/estree": "0.0.52",
"@types/node": "^4.9.5",
"@typescript-eslint/parser": "^2.34.0 || ^3.10.1 || ^4 || ^5 || ^6.20 || ^7.14.1 || ^8.4",
"babel-eslint": "^8 || ^9 || ^10.1.0",
"eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8 || ^9.7",
"eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8 || ^9.10",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-doc-generator": "^1.7.1",
"eslint-plugin-eslint-plugin": "^2.3.0 || ^3.5.3 || ^4.0.1 || ^5.0.5",
Expand Down

0 comments on commit 4290504

Please sign in to comment.