diff --git a/packages/eslint-plugin-cli/rules/command-flags-with-env.js b/packages/eslint-plugin-cli/rules/command-flags-with-env.js index fbbcf0b73e7..3e281e42ad3 100644 --- a/packages/eslint-plugin-cli/rules/command-flags-with-env.js +++ b/packages/eslint-plugin-cli/rules/command-flags-with-env.js @@ -10,22 +10,22 @@ module.exports = { create(context) { return { PropertyDefinition(node) { - if (node.key.name === 'flags') { - node.value.properties.forEach((flag) => { - const arguments = flag.value?.arguments ?? [] - const argument = arguments[0] - if (!argument) { - return - } - const properties = argument.properties.map((property) => property.key.name) - if (!properties.includes('env')) { - context.report( - argument, - 'Flags must specify the environment variable that represents the flag through the env property', - ) - } - }) - } + if (node.key.name !== 'flags') return + + const flags = node.value?.properties ?? [] + flags.forEach((flag) => { + const argument = flag.value?.arguments?.[0] + if (!argument?.properties) { + return + } + const properties = argument.properties.map((property) => property.key.name) + if (!properties.includes('env')) { + context.report( + argument, + 'Flags must specify the environment variable that represents the flag through the env property', + ) + } + }) }, } },