diff --git a/CHANGELOG.md b/CHANGELOG.md index 0db42758a4..4170a4edf4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,9 +24,11 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange * [Refactor] `boolean-prop-naming`, `jsx-indent`: avoid assigning to arguments ([#3316][] @caroline223) * [Docs] [`sort-comp`]: add class component examples ([#3339][] @maurer2) * [Docs] [`jsx-no-useless-fragment`]: add more examples of correct code ([#3349][] @karlhorky) +* [Docs] [`jsx-boolean-value`]: add jsdoc types for helper functions ([#3344][] @caroline223) [#3350]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3350 [#3349]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3349 +[#3344]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3344 [#3339]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3339 [#3335]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3335 [#3331]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3331 diff --git a/lib/rules/jsx-boolean-value.js b/lib/rules/jsx-boolean-value.js index d68b1ebdf6..43395e2490 100644 --- a/lib/rules/jsx-boolean-value.js +++ b/lib/rules/jsx-boolean-value.js @@ -22,6 +22,10 @@ const ALWAYS = 'always'; const NEVER = 'never'; const errorData = new WeakMap(); +/** + * @param {object} exceptions + * @returns {object} + */ function getErrorData(exceptions) { if (!errorData.has(exceptions)) { const exceptionProps = Array.from(exceptions, (name) => `\`${name}\``).join(', '); @@ -30,7 +34,12 @@ function getErrorData(exceptions) { } return errorData.get(exceptions); } - +/** + * @param {string} configuration + * @param {Set} exceptions + * @param {string} propName + * @returns {boolean} propName +*/ function isAlways(configuration, exceptions, propName) { const isException = exceptions.has(propName); if (configuration === ALWAYS) { @@ -38,7 +47,12 @@ function isAlways(configuration, exceptions, propName) { } return isException; } - +/** + * @param {string} configuration + * @param {Set} exceptions + * @param {string} propName + * @returns {boolean} propName + */ function isNever(configuration, exceptions, propName) { const isException = exceptions.has(propName); if (configuration === NEVER) { @@ -109,7 +123,10 @@ module.exports = { const propName = node.name && node.name.name; const value = node.value; - if (isAlways(configuration, exceptions, propName) && value === null) { + if ( + isAlways(configuration, exceptions, propName) + && value === null + ) { const data = getErrorData(exceptions); const messageId = data.exceptionsMessage ? 'setBoolean' : 'setBoolean_noMessage'; report(context, messages[messageId], messageId, { @@ -120,7 +137,12 @@ module.exports = { }, }); } - if (isNever(configuration, exceptions, propName) && value && value.type === 'JSXExpressionContainer' && value.expression.value === true) { + if ( + isNever(configuration, exceptions, propName) + && value + && value.type === 'JSXExpressionContainer' + && value.expression.value === true + ) { const data = getErrorData(exceptions); const messageId = data.exceptionsMessage ? 'omitBoolean' : 'omitBoolean_noMessage'; report(context, messages[messageId], messageId, {