Skip to content

Commit

Permalink
fix: apply code reivew
Browse files Browse the repository at this point in the history
  • Loading branch information
developer-bandi committed Jan 10, 2024
1 parent 834fa5e commit 0ee0a2b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
4 changes: 2 additions & 2 deletions docs/rules/jsx-boolean-value.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ This rule will enforce one or the other to keep consistency in your code.

This rule takes two arguments. If the first argument is `"always"` then it warns whenever an attribute is missing its value. If `"never"` then it warns if an attribute has a `true` value. The default value of this option is `"never"`.

The second argument is optional. if provided, it must be an object. Three property is available.
The second argument is optional. if provided, it must be an object. These properties are supported:

First, the `"never"` and `"always"` properties are one set. The two properties cannot be set together. `"never"` must be used when the first argument is `"always"` and `"always"` must be used when the first argument is `"never"`. This property’s value must be an array of strings representing prop names.

The other is `"assumeUndefinedIsFalse"`. The default value of this option is false. if the first argument is `"never"` or the property of the second argument contains `"never"` , the corresponding property cannot have false.
When the first argument is `"never"`, a boolean `"assumeUndefinedIsFalse"` may be provided, which defaults to `false`. When `true`, an absent boolean prop will be treated as if it were explicitly set to `false`.

Examples of **incorrect** code for this rule, when configured with `"never"`, or with `"always", { "never": ["personal"] }`:

Expand Down
24 changes: 5 additions & 19 deletions lib/rules/jsx-boolean-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,6 @@ function isNever(configuration, exceptions, propName) {
}
return isException;
}
/**
* @param {object} configObject
* @returns {object} configObject
*/
function configObjectDefaultSetting(configObject) {
const defaultObject = Object.assign({}, configObject);
if (defaultObject.assumeUndefinedIsFalse === undefined) {
defaultObject.assumeUndefinedIsFalse = false;
}
return defaultObject;
}

const messages = {
omitBoolean: 'Value must be omitted for boolean attributes{{exceptionsMessage}}',
Expand Down Expand Up @@ -111,8 +100,7 @@ module.exports = {
type: 'boolean',
},
},
},
],
}],
additionalItems: false,
}, {
type: 'array',
Expand All @@ -127,17 +115,15 @@ module.exports = {
type: 'boolean',
},
},
},
],
}],
additionalItems: false,
},
],
}],
},
},

create(context) {
const configuration = context.options[0] || NEVER;
const configObject = configObjectDefaultSetting(context.options[1]);
const configObject = context.options[1] || {};
const exceptions = new Set((configuration === ALWAYS ? configObject[NEVER] : configObject[ALWAYS]) || []);

return {
Expand All @@ -161,7 +147,7 @@ module.exports = {
}
if (
isNever(configuration, exceptions, propName)
&& configObject.assumeUndefinedIsFalse === false
&& !configObject.assumeUndefinedIsFalse
&& value
&& value.type === 'JSXExpressionContainer'
&& value.expression.value === true
Expand Down

0 comments on commit 0ee0a2b

Please sign in to comment.