From 0ee0a2b7f25e393b89ee636f1f1488c73ab1ac44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=80=E1=85=B5=E1=86=B7=E1=84=89=E1=85=A1=E1=86=BC?= =?UTF-8?q?=E1=84=83=E1=85=AE?= Date: Thu, 11 Jan 2024 07:58:32 +0900 Subject: [PATCH] fix: apply code reivew --- docs/rules/jsx-boolean-value.md | 4 ++-- lib/rules/jsx-boolean-value.js | 24 +++++------------------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/docs/rules/jsx-boolean-value.md b/docs/rules/jsx-boolean-value.md index e80091ec9a..e1082f2a79 100644 --- a/docs/rules/jsx-boolean-value.md +++ b/docs/rules/jsx-boolean-value.md @@ -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"] }`: diff --git a/lib/rules/jsx-boolean-value.js b/lib/rules/jsx-boolean-value.js index 61b3a26f23..ae6dda0da7 100644 --- a/lib/rules/jsx-boolean-value.js +++ b/lib/rules/jsx-boolean-value.js @@ -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}}', @@ -111,8 +100,7 @@ module.exports = { type: 'boolean', }, }, - }, - ], + }], additionalItems: false, }, { type: 'array', @@ -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 { @@ -161,7 +147,7 @@ module.exports = { } if ( isNever(configuration, exceptions, propName) - && configObject.assumeUndefinedIsFalse === false + && !configObject.assumeUndefinedIsFalse && value && value.type === 'JSXExpressionContainer' && value.expression.value === true