From 9613e6205b43c784305ced2d3c85bd21b7ecf1ed Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Wed, 4 Nov 2026 16:03:31 -0500 Subject: [PATCH 1/6] fix(lint): key server-fact capability pairs on the holding fact object Follow-up to #22904 review. - Test the object that holds the can* member (via factName) instead of the root segment, so props.facts.canA && props.facts.canB, this.facts.* and section.billingFacts.* are caught, and facts.dialog.canClose is not. - Flag any two can* members of fact objects, not only same-owner pairs, so billingFacts.canTopUp && seatFacts.canChangeSeats is reported. - Skip detail fields ending in Refusal/Denial/Reason (canTopUpRefusal), so a served refusal rendered next to its capability passes. - Share the .value-stripping member walk between the pair check and isPresenceDefault, and pin the object-of-refs branch with a test. - Move facts.canTopUp && options.canTopUp to a case named as a known scope limit. --- tools/oxlint-plugins/serverFacts.test.ts | 64 +++++++++++++++++++++++- tools/oxlint-plugins/serverFacts.ts | 57 ++++++++++++--------- 2 files changed, 95 insertions(+), 26 deletions(-) diff --git a/tools/oxlint-plugins/serverFacts.test.ts b/tools/oxlint-plugins/serverFacts.test.ts index 7039690e928..91d79f06209 100644 --- a/tools/oxlint-plugins/serverFacts.test.ts +++ b/tools/oxlint-plugins/serverFacts.test.ts @@ -182,7 +182,32 @@ function deriveSection(facts: SectionFacts) { function deriveSection(facts: SectionFacts) { const a = facts.canTopUp && !facts.isLoading const b = facts.autoTopUpEnabled && facts.hasSeats - const c = facts.canTopUp && options.canTopUp +} +` + }, + { + name: 'known scope limit: a fact capability gated by a capability-named member of an unnamed object', + code: ` +function deriveSection(facts: SectionFacts) { + return facts.canTopUp && options.canTopUp +} +` + }, + { + name: 'a served refusal rendered next to its capability', + code: ` +function describe(facts: AddCreditsFacts) { + const a = !facts.canTopUp && facts.canTopUpRefusal + const b = facts.canTopUpRefusal ?? facts.canTopUpReason + const c = facts.canChangeSeats || facts.canChangeSeatsDenial +} +` + }, + { + name: 'capability-named members of an object nested inside a facts object', + code: ` +function deriveSection(facts: SectionFacts) { + return facts.dialog.canClose && facts.dialog.canOpen } ` }, @@ -209,6 +234,43 @@ function deriveSection(facts: SectionFacts) { { messageId: 'combined', data: { operator: '||' } } ] }, + { + name: 'two capability members of a facts object held under another object', + code: ` +function deriveSection(props: Props, section: Section) { + if (props.facts.canManageAutoTopUp && props.facts.canTopUp) return 'card' + if (section.billingFacts.canTopUp || section.billingFacts.canChangeSeats) return 'seats' + return this.facts.canTopUp && this.facts.canChangeSeats +} +`, + errors: [ + { messageId: 'combined', data: { operator: '&&' } }, + { messageId: 'combined', data: { operator: '||' } }, + { messageId: 'combined', data: { operator: '&&' } } + ] + }, + { + name: 'capability members of two different fact objects combined', + code: ` +function deriveSection(billingFacts: BillingFacts, seatFacts: SeatFacts) { + if (billingFacts.canTopUp && seatFacts.canChangeSeats) return 'card' + return facts.canTopUp || capabilities.canManageBilling +} +`, + errors: [ + { messageId: 'combined', data: { operator: '&&' } }, + { messageId: 'combined', data: { operator: '||' } } + ] + }, + { + name: 'capability refs of an untracked capabilities object combined', + code: ` +function deriveSection(capabilities: BillingCapabilities) { + return capabilities.canTopUp.value && !capabilities.canManageAutoTopUp.value +} +`, + errors: [{ messageId: 'combined', data: { operator: '&&' } }] + }, { name: '#15675 capability chosen by isCloud with a role fallback', code: ` diff --git a/tools/oxlint-plugins/serverFacts.ts b/tools/oxlint-plugins/serverFacts.ts index f582c7cbe70..a40b342fe6b 100644 --- a/tools/oxlint-plugins/serverFacts.ts +++ b/tools/oxlint-plugins/serverFacts.ts @@ -10,12 +10,14 @@ type VisitedNode = Parameters< type Expression = VisitedNode<'LogicalExpression'>['left'] type AstNode = Expression['parent'] type Ternary = VisitedNode<'ConditionalExpression'> +type Member = Extract const CAPABILITY_SOURCES: ReadonlySet = new Set([ 'useBillingCapabilities' ]) const CAPABILITY_BINDING = /^can[A-Z]\w*$/ const CAPABILITY_FIELD = /^can_[a-z_]+$/ +const CAPABILITY_DETAIL = /(?:Refusal|Denial|Reason)$/ const SERVER_FACT_OWNER = /^(?:\w*Facts|facts|\w*Capabilities|capabilities)$/ const PENDING_FACT_WRAPPER = 'pendingServerFact' const LOCAL_UI_STATE: ReadonlySet = new Set([ @@ -442,29 +444,26 @@ function memberPath(node: AstNode): string | undefined { : `${object}.${expression.property.name}` } -function capabilityMemberOwner(node: AstNode): string | undefined { - const inner = negated(node) - if (inner) return capabilityMemberOwner(inner) - const expression = unwrap(node) - if (expression.type !== 'MemberExpression' || expression.computed) { - return undefined - } - if (expression.property.name === 'value') { - return capabilityMemberOwner(expression.object) - } - const owner = memberPath(expression.object) - return CAPABILITY_BINDING.test(expression.property.name) && - owner !== undefined && - SERVER_FACT_OWNER.test(owner.split('.')[0]) - ? owner - : undefined +function isFactObjectCapability(node: AstNode): boolean { + if (node.type !== 'MemberExpression' || node.computed) return false + const property = node.property.name + return ( + CAPABILITY_BINDING.test(property) && + !CAPABILITY_DETAIL.test(property) && + SERVER_FACT_OWNER.test(factName(node.object) ?? '') + ) } -function combinesSiblingCapabilities(operands: AstNode[]): boolean { - const owners = operands.flatMap( - (operand) => capabilityMemberOwner(operand) ?? [] +function combinesFactObjectCapabilities(operands: AstNode[]): boolean { + return ( + operands.filter( + (operand) => + capabilityMember( + negated(operand) ?? operand, + isFactObjectCapability + ) !== undefined + ).length >= 2 ) - return new Set(owners).size < owners.length } interface LiteralDefault { @@ -497,18 +496,26 @@ function isNarrowedTernary(node: Ternary, isCapability: IsCapability): boolean { : impliesCapability(fallback.other, isCapability) } -function capabilityOwner( +function capabilityMember( node: AstNode, isCapability: IsCapability -): string | undefined { +): Member | undefined { const expression = unwrap(node) if (expression.type !== 'MemberExpression' || expression.computed) { return undefined } if (expression.property.name === 'value') { - return capabilityOwner(expression.object, isCapability) + return capabilityMember(expression.object, isCapability) } - return isCapability(expression) ? memberPath(expression.object) : undefined + return isCapability(expression) ? expression : undefined +} + +function capabilityOwner( + node: AstNode, + isCapability: IsCapability +): string | undefined { + const member = capabilityMember(node, isCapability) + return member && memberPath(member.object) } // `caps ? caps.can_top_up : false` is `caps?.can_top_up ?? false`. @@ -641,7 +648,7 @@ export const noCapabilityRecombination: Rule = { factOperands.length < 2 || !( operands.some(containsCapability) || - combinesSiblingCapabilities(operands) + combinesFactObjectCapabilities(operands) ) || onlyNarrowedByLocalState(node) || isInsidePendingFact(node) From c924a4f3bc6e17d1a0d5541bd11bf42692053992 Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Wed, 4 Nov 2026 16:34:08 -0500 Subject: [PATCH 2/6] fix(lint): skip can* detail fields on tracked capability sources too --- tools/oxlint-plugins/serverFacts.test.ts | 7 +++++++ tools/oxlint-plugins/serverFacts.ts | 10 ++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/tools/oxlint-plugins/serverFacts.test.ts b/tools/oxlint-plugins/serverFacts.test.ts index 91d79f06209..ad1565b8493 100644 --- a/tools/oxlint-plugins/serverFacts.test.ts +++ b/tools/oxlint-plugins/serverFacts.test.ts @@ -201,6 +201,13 @@ function describe(facts: AddCreditsFacts) { const b = facts.canTopUpRefusal ?? facts.canTopUpReason const c = facts.canChangeSeats || facts.canChangeSeatsDenial } +` + }, + { + name: 'detail fields of a tracked capability source rendered together', + code: ` +const capabilities = useBillingCapabilities() +const detail = capabilities.canTopUpRefusal.value ?? capabilities.canTopUpReason.value ` }, { diff --git a/tools/oxlint-plugins/serverFacts.ts b/tools/oxlint-plugins/serverFacts.ts index a40b342fe6b..d7ade73d74f 100644 --- a/tools/oxlint-plugins/serverFacts.ts +++ b/tools/oxlint-plugins/serverFacts.ts @@ -444,12 +444,14 @@ function memberPath(node: AstNode): string | undefined { : `${object}.${expression.property.name}` } +function isCapabilityMemberName(property: string): boolean { + return CAPABILITY_BINDING.test(property) && !CAPABILITY_DETAIL.test(property) +} + function isFactObjectCapability(node: AstNode): boolean { if (node.type !== 'MemberExpression' || node.computed) return false - const property = node.property.name return ( - CAPABILITY_BINDING.test(property) && - !CAPABILITY_DETAIL.test(property) && + isCapabilityMemberName(node.property.name) && SERVER_FACT_OWNER.test(factName(node.object) ?? '') ) } @@ -554,7 +556,7 @@ export const noCapabilityRecombination: Rule = { const property = node.property.name return ( CAPABILITY_FIELD.test(property) || - (CAPABILITY_BINDING.test(property) && + (isCapabilityMemberName(property) && capabilityObjects.has(factName(node.object) ?? '')) ) } From 8f484523cc757c9270e01774d51f2de55dd3636d Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Wed, 4 Nov 2026 17:34:32 -0500 Subject: [PATCH 3/6] fix(lint): let a served detail field sit beside its capability --- tools/oxlint-plugins/serverFacts.test.ts | 13 +++++++++++++ tools/oxlint-plugins/serverFacts.ts | 17 ++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/tools/oxlint-plugins/serverFacts.test.ts b/tools/oxlint-plugins/serverFacts.test.ts index ad1565b8493..406b7e93dca 100644 --- a/tools/oxlint-plugins/serverFacts.test.ts +++ b/tools/oxlint-plugins/serverFacts.test.ts @@ -208,6 +208,7 @@ function describe(facts: AddCreditsFacts) { code: ` const capabilities = useBillingCapabilities() const detail = capabilities.canTopUpRefusal.value ?? capabilities.canTopUpReason.value +const refusal = !capabilities.canTopUp.value && capabilities.canTopUpRefusal.value ` }, { @@ -278,6 +279,18 @@ function deriveSection(capabilities: BillingCapabilities) { `, errors: [{ messageId: 'combined', data: { operator: '&&' } }] }, + { + name: 'a capability combined with other state beside its served refusal', + code: ` +const capabilities = useBillingCapabilities() +const a = !capabilities.canTopUp.value && capabilities.canTopUpRefusal.value && isCloud +const b = capabilities.canTopUp.value && options.canTopUpReason +`, + errors: [ + { messageId: 'combined', data: { operator: '&&' } }, + { messageId: 'combined', data: { operator: '&&' } } + ] + }, { name: '#15675 capability chosen by isCloud with a role fallback', code: ` diff --git a/tools/oxlint-plugins/serverFacts.ts b/tools/oxlint-plugins/serverFacts.ts index d7ade73d74f..11fe95c7e4a 100644 --- a/tools/oxlint-plugins/serverFacts.ts +++ b/tools/oxlint-plugins/serverFacts.ts @@ -561,6 +561,21 @@ export const noCapabilityRecombination: Rule = { ) } + const isServedDetail = (member: AstNode): boolean => { + if (member.type !== 'MemberExpression' || member.computed) return false + const holder = factName(member.object) ?? '' + return ( + CAPABILITY_BINDING.test(member.property.name) && + CAPABILITY_DETAIL.test(member.property.name) && + (capabilityObjects.has(holder) || SERVER_FACT_OWNER.test(holder)) + ) + } + + const isFactOperand = (operand: AstNode): boolean => + !isLiteral(operand) && + capabilityMember(negated(operand) ?? operand, isServedDetail) === + undefined + const isCapabilitySource = (init: AstNode | null): boolean => isCapabilitySourceCall(init) || (init !== null && capabilityObjects.has(factName(init) ?? '')) @@ -645,7 +660,7 @@ export const noCapabilityRecombination: Rule = { LogicalExpression(node) { if (unwrap(node.parent).type === 'LogicalExpression') return const operands = logicalOperands(node) - const factOperands = operands.filter((operand) => !isLiteral(operand)) + const factOperands = operands.filter(isFactOperand) if ( factOperands.length < 2 || !( From 14d870c581ae7f63c10ed84e60e88c385fea7372 Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Wed, 4 Nov 2026 18:35:30 -0500 Subject: [PATCH 4/6] fix(lint): exempt a served detail only beside its own capability --- tools/oxlint-plugins/serverFacts.test.ts | 22 ++++++++++ tools/oxlint-plugins/serverFacts.ts | 54 ++++++++++++++++++------ 2 files changed, 63 insertions(+), 13 deletions(-) diff --git a/tools/oxlint-plugins/serverFacts.test.ts b/tools/oxlint-plugins/serverFacts.test.ts index 406b7e93dca..00b1897283b 100644 --- a/tools/oxlint-plugins/serverFacts.test.ts +++ b/tools/oxlint-plugins/serverFacts.test.ts @@ -291,6 +291,28 @@ const b = capabilities.canTopUp.value && options.canTopUpReason { messageId: 'combined', data: { operator: '&&' } } ] }, + { + name: 'a capability gated by a served detail of another capability or holder', + code: ` +const capabilities = useBillingCapabilities() +const a = capabilities.canTopUp.value && !billingFacts.canManageBillingReason +const b = !capabilities.canTopUp.value && billingFacts.canTopUpRefusal +const c = capabilities.canTopUp.value && capabilities.canManageBillingRefusal.value +`, + errors: [ + { messageId: 'combined', data: { operator: '&&' } }, + { messageId: 'combined', data: { operator: '&&' } }, + { messageId: 'combined', data: { operator: '&&' } } + ] + }, + { + name: 'a capability gated by its own served refusal as a boolean', + code: ` +const capabilities = useBillingCapabilities() +const a = capabilities.canTopUp.value || !capabilities.canTopUpRefusal.value +`, + errors: [{ messageId: 'combined', data: { operator: '||' } }] + }, { name: '#15675 capability chosen by isCloud with a role fallback', code: ` diff --git a/tools/oxlint-plugins/serverFacts.ts b/tools/oxlint-plugins/serverFacts.ts index 11fe95c7e4a..c85050a1f7d 100644 --- a/tools/oxlint-plugins/serverFacts.ts +++ b/tools/oxlint-plugins/serverFacts.ts @@ -456,6 +456,21 @@ function isFactObjectCapability(node: AstNode): boolean { ) } +function isCapabilityDetail(node: AstNode): boolean { + return ( + node.type === 'MemberExpression' && + !node.computed && + CAPABILITY_BINDING.test(node.property.name) && + CAPABILITY_DETAIL.test(node.property.name) + ) +} + +function memberKey(member: Member): string | undefined { + if (member.computed) return undefined + const holder = memberPath(member.object) + return holder && `${holder}.${member.property.name}` +} + function combinesFactObjectCapabilities(operands: AstNode[]): boolean { return ( operands.filter( @@ -561,20 +576,29 @@ export const noCapabilityRecombination: Rule = { ) } - const isServedDetail = (member: AstNode): boolean => { - if (member.type !== 'MemberExpression' || member.computed) return false - const holder = factName(member.object) ?? '' - return ( - CAPABILITY_BINDING.test(member.property.name) && - CAPABILITY_DETAIL.test(member.property.name) && - (capabilityObjects.has(holder) || SERVER_FACT_OWNER.test(holder)) + const isPairableCapability = (node: AstNode): boolean => + isCapabilityReference(node) || isFactObjectCapability(node) + + const capabilityKeys = (operands: AstNode[]): Set => + new Set( + operands.flatMap((operand) => { + const member = capabilityMember( + negated(operand) ?? operand, + isPairableCapability + ) + const key = member && memberKey(member) + return key ?? [] + }) ) - } - const isFactOperand = (operand: AstNode): boolean => - !isLiteral(operand) && - capabilityMember(negated(operand) ?? operand, isServedDetail) === - undefined + const isDetailOfPairedCapability = ( + operand: AstNode, + paired: Set + ): boolean => { + const detail = capabilityMember(operand, isCapabilityDetail) + const key = detail && memberKey(detail)?.replace(CAPABILITY_DETAIL, '') + return key !== undefined && paired.has(key) + } const isCapabilitySource = (init: AstNode | null): boolean => isCapabilitySourceCall(init) || @@ -660,7 +684,11 @@ export const noCapabilityRecombination: Rule = { LogicalExpression(node) { if (unwrap(node.parent).type === 'LogicalExpression') return const operands = logicalOperands(node) - const factOperands = operands.filter(isFactOperand) + const paired = capabilityKeys(operands) + const factOperands = operands.filter( + (operand) => + !isLiteral(operand) && !isDetailOfPairedCapability(operand, paired) + ) if ( factOperands.length < 2 || !( From 82b3726a72f453f9162f0e78cbca4380fb3d1626 Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Wed, 4 Nov 2026 20:24:59 -0500 Subject: [PATCH 5/6] fix(lint): scope served detail fields on fact objects to their own capability --- tools/oxlint-plugins/serverFacts.test.ts | 18 ++++++++++++++++++ tools/oxlint-plugins/serverFacts.ts | 23 +++++++++++++++-------- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/tools/oxlint-plugins/serverFacts.test.ts b/tools/oxlint-plugins/serverFacts.test.ts index 00b1897283b..d89098b97c6 100644 --- a/tools/oxlint-plugins/serverFacts.test.ts +++ b/tools/oxlint-plugins/serverFacts.test.ts @@ -200,6 +200,7 @@ function describe(facts: AddCreditsFacts) { const a = !facts.canTopUp && facts.canTopUpRefusal const b = facts.canTopUpRefusal ?? facts.canTopUpReason const c = facts.canChangeSeats || facts.canChangeSeatsDenial + const d = !facts.canTopUp && facts.canTopUpRefusal && !isLoading } ` }, @@ -313,6 +314,23 @@ const a = capabilities.canTopUp.value || !capabilities.canTopUpRefusal.value `, errors: [{ messageId: 'combined', data: { operator: '||' } }] }, + { + name: 'a fact-object capability gated by a served detail of another capability or holder', + code: ` +function f(billingFacts: BillingFacts, seatFacts: SeatFacts) { + return !billingFacts.canTopUp && seatFacts.canTopUpRefusal +} +function g(facts: SectionFacts) { + const a = facts.canTopUp && !facts.canManageBillingReason + const b = facts.canTopUp && !facts.canTopUpRefusal +} +`, + errors: [ + { messageId: 'combined', data: { operator: '&&' } }, + { messageId: 'combined', data: { operator: '&&' } }, + { messageId: 'combined', data: { operator: '&&' } } + ] + }, { name: '#15675 capability chosen by isCloud with a role fallback', code: ` diff --git a/tools/oxlint-plugins/serverFacts.ts b/tools/oxlint-plugins/serverFacts.ts index c85050a1f7d..840b21acf0f 100644 --- a/tools/oxlint-plugins/serverFacts.ts +++ b/tools/oxlint-plugins/serverFacts.ts @@ -471,15 +471,22 @@ function memberKey(member: Member): string | undefined { return holder && `${holder}.${member.property.name}` } +function isFactObjectField(node: AstNode): boolean { + return ( + node.type === 'MemberExpression' && + !node.computed && + CAPABILITY_BINDING.test(node.property.name) && + SERVER_FACT_OWNER.test(factName(node.object) ?? '') + ) +} + function combinesFactObjectCapabilities(operands: AstNode[]): boolean { + const fields = operands.flatMap( + (operand) => + capabilityMember(negated(operand) ?? operand, isFactObjectField) ?? [] + ) return ( - operands.filter( - (operand) => - capabilityMember( - negated(operand) ?? operand, - isFactObjectCapability - ) !== undefined - ).length >= 2 + fields.length >= 2 && fields.some((field) => !isCapabilityDetail(field)) ) } @@ -693,7 +700,7 @@ export const noCapabilityRecombination: Rule = { factOperands.length < 2 || !( operands.some(containsCapability) || - combinesFactObjectCapabilities(operands) + combinesFactObjectCapabilities(factOperands) ) || onlyNarrowedByLocalState(node) || isInsidePendingFact(node) From 031f2074f8ba0652c5eedeea9c1bdef19265ee80 Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Wed, 4 Nov 2026 20:35:19 -0500 Subject: [PATCH 6/6] fix(lint): resolve this-rooted holder paths when pairing served details --- tools/oxlint-plugins/serverFacts.test.ts | 1 + tools/oxlint-plugins/serverFacts.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/tools/oxlint-plugins/serverFacts.test.ts b/tools/oxlint-plugins/serverFacts.test.ts index d89098b97c6..86e7a2253f5 100644 --- a/tools/oxlint-plugins/serverFacts.test.ts +++ b/tools/oxlint-plugins/serverFacts.test.ts @@ -201,6 +201,7 @@ function describe(facts: AddCreditsFacts) { const b = facts.canTopUpRefusal ?? facts.canTopUpReason const c = facts.canChangeSeats || facts.canChangeSeatsDenial const d = !facts.canTopUp && facts.canTopUpRefusal && !isLoading + const e = !this.facts.canTopUp && this.facts.canTopUpRefusal } ` }, diff --git a/tools/oxlint-plugins/serverFacts.ts b/tools/oxlint-plugins/serverFacts.ts index 840b21acf0f..06c754b858f 100644 --- a/tools/oxlint-plugins/serverFacts.ts +++ b/tools/oxlint-plugins/serverFacts.ts @@ -435,6 +435,7 @@ function oneSideIsLocal( function memberPath(node: AstNode): string | undefined { const expression = unwrap(node) if (expression.type === 'Identifier') return expression.name + if (expression.type === 'ThisExpression') return 'this' if (expression.type !== 'MemberExpression' || expression.computed) { return undefined }