Skip to content

Commit b714407

Browse files
caroline223ljharb
authored andcommitted
[Docs] jsx-boolean-value: add jsdoc types for helper functions
1 parent ab72e48 commit b714407

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
2424
* [Refactor] `boolean-prop-naming`, `jsx-indent`: avoid assigning to arguments ([#3316][] @caroline223)
2525
* [Docs] [`sort-comp`]: add class component examples ([#3339][] @maurer2)
2626
* [Docs] [`jsx-no-useless-fragment`]: add more examples of correct code ([#3349][] @karlhorky)
27+
* [Docs] [`jsx-boolean-value`]: add jsdoc types for helper functions ([#3344][] @caroline223)
2728

2829
[#3350]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3350
2930
[#3349]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3349
31+
[#3344]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3344
3032
[#3339]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3339
3133
[#3335]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3335
3234
[#3331]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3331

lib/rules/jsx-boolean-value.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ const ALWAYS = 'always';
2222
const NEVER = 'never';
2323

2424
const errorData = new WeakMap();
25+
/**
26+
* @param {object} exceptions
27+
* @returns {object}
28+
*/
2529
function getErrorData(exceptions) {
2630
if (!errorData.has(exceptions)) {
2731
const exceptionProps = Array.from(exceptions, (name) => `\`${name}\``).join(', ');
@@ -30,15 +34,25 @@ function getErrorData(exceptions) {
3034
}
3135
return errorData.get(exceptions);
3236
}
33-
37+
/**
38+
* @param {string} configuration
39+
* @param {Set<string>} exceptions
40+
* @param {string} propName
41+
* @returns {boolean} propName
42+
*/
3443
function isAlways(configuration, exceptions, propName) {
3544
const isException = exceptions.has(propName);
3645
if (configuration === ALWAYS) {
3746
return !isException;
3847
}
3948
return isException;
4049
}
41-
50+
/**
51+
* @param {string} configuration
52+
* @param {Set<string>} exceptions
53+
* @param {string} propName
54+
* @returns {boolean} propName
55+
*/
4256
function isNever(configuration, exceptions, propName) {
4357
const isException = exceptions.has(propName);
4458
if (configuration === NEVER) {
@@ -109,7 +123,10 @@ module.exports = {
109123
const propName = node.name && node.name.name;
110124
const value = node.value;
111125

112-
if (isAlways(configuration, exceptions, propName) && value === null) {
126+
if (
127+
isAlways(configuration, exceptions, propName)
128+
&& value === null
129+
) {
113130
const data = getErrorData(exceptions);
114131
const messageId = data.exceptionsMessage ? 'setBoolean' : 'setBoolean_noMessage';
115132
report(context, messages[messageId], messageId, {
@@ -120,7 +137,12 @@ module.exports = {
120137
},
121138
});
122139
}
123-
if (isNever(configuration, exceptions, propName) && value && value.type === 'JSXExpressionContainer' && value.expression.value === true) {
140+
if (
141+
isNever(configuration, exceptions, propName)
142+
&& value
143+
&& value.type === 'JSXExpressionContainer'
144+
&& value.expression.value === true
145+
) {
124146
const data = getErrorData(exceptions);
125147
const messageId = data.exceptionsMessage ? 'omitBoolean' : 'omitBoolean_noMessage';
126148
report(context, messages[messageId], messageId, {

0 commit comments

Comments
 (0)