55
66'use strict' ;
77
8- const ASTUtils = require ( 'jsx-ast-utils' ) ;
8+ const { elementType } = require ( 'jsx-ast-utils' ) ;
99
1010const isCreateElement = require ( '../util/isCreateElement' ) ;
1111const report = require ( '../util/report' ) ;
1212const docsUrl = require ( '../util/docsUrl' ) ;
1313
14- const messages = {
14+ const messages = /** @type { const } */ ( {
1515 missingProperty : '`checked` should be used with either `onChange` or `readOnly`.' ,
1616 exclusiveCheckedAttribute : 'Use either `checked` or `defaultChecked`, but not both.' ,
17- } ;
17+ } ) ;
1818
1919const targetPropSet = new Set ( [ 'checked' , 'onChange' , 'readOnly' , 'defaultChecked' ] ) ;
2020
21- const defaultOptions = {
21+ const defaultOptions = /** @type { const } */ ( {
2222 ignoreMissingProperties : false ,
2323 ignoreExclusiveCheckedAttribute : false ,
24- } ;
24+ } ) ;
2525
2626/**
2727 * @param {object[] } properties
@@ -63,6 +63,7 @@ module.exports = {
6363 create ( context ) {
6464 const options = { ...defaultOptions , ...context . options [ 0 ] } ;
6565
66+ /** @param {JSXOpeningElement | CallExpression } node */
6667 function reportMissingProperty ( node ) {
6768 report (
6869 context ,
@@ -72,6 +73,7 @@ module.exports = {
7273 ) ;
7374 }
7475
76+ /** @param {JSXOpeningElement | CallExpression } node */
7577 function reportExclusiveCheckedAttribute ( node ) {
7678 report (
7779 context ,
@@ -82,11 +84,10 @@ module.exports = {
8284 }
8385
8486 /**
85- * @param {ASTNode } node
87+ * @param {JSXOpeningElement | CallExpression } node
8688 * @param {Set<string> } propSet
87- * @returns {void }
8889 */
89- const checkAttributesAndReport = ( node , propSet ) => {
90+ function checkAttributesAndReport ( node , propSet ) {
9091 if ( ! propSet . has ( 'checked' ) ) {
9192 return ;
9293 }
@@ -101,17 +102,19 @@ module.exports = {
101102 ) {
102103 reportMissingProperty ( node ) ;
103104 }
104- } ;
105+ }
105106
106107 return {
108+ /** @param {JSXOpeningElement } node */
107109 JSXOpeningElement ( node ) {
108- if ( ASTUtils . elementType ( node ) !== 'input' ) {
110+ if ( elementType ( node ) !== 'input' ) {
109111 return ;
110112 }
111113
112114 const propSet = extractTargetProps ( node . attributes , 'name' ) ;
113115 checkAttributesAndReport ( node , propSet ) ;
114116 } ,
117+
115118 CallExpression ( node ) {
116119 if ( ! isCreateElement ( context , node ) ) {
117120 return ;
0 commit comments