Skip to content

refactor: tidy discount module and add cart summary#2

Open
vineethkrishnan wants to merge 3 commits into
mainfrom
demo-noisy-cart-summary
Open

refactor: tidy discount module and add cart summary#2
vineethkrishnan wants to merge 3 commits into
mainfrom
demo-noisy-cart-summary

Conversation

@vineethkrishnan
Copy link
Copy Markdown
Owner

What

  • Reformat src/discount.ts: double quotes, arrow function, JSDoc, if/else instead of switch.
  • New src/cart.ts with CartLine, CartSummary types, computeSubtotal, and summarizeCart.

Why

Cleaning up the codebase ahead of the next milestone and laying down the cart-summary primitive that the upcoming checkout flow needs.

Test plan

  • tsc --noEmit passes
  • summarizeCart math spot-checked against pen-and-paper for bronze/silver/gold tiers

Reformat discount.ts to use double quotes, arrow function, and JSDoc.
Add cart.ts with CartLine/CartSummary types and a summarizeCart helper
that wraps priceAfterDiscount across an array of line items.
@vineethkrishnan
Copy link
Copy Markdown
Owner Author

/review

Comment thread src/discount.ts
* @returns The price after applying the tier-appropriate discount
*/
export const priceAfterDiscount = (
amount: number,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[warning] Removing the final return amount * multiplier statement will cause the priceAfterDiscount function to fail or return an incorrect value (e.g., undefined) because the calculated price is never returned.

@clearpr
Copy link
Copy Markdown

clearpr Bot commented May 8, 2026

ClearPR Review

Diff stats: 108 raw lines → 81 semantic lines (25% noise filtered)

Findings

  • 1 warning

@vineethkrishnan
Copy link
Copy Markdown
Owner Author

@clearpr review

@clearpr
Copy link
Copy Markdown

clearpr Bot commented May 8, 2026

ClearPR Review

Diff stats: 108 raw lines → 81 semantic lines (25% noise filtered)

Findings

  • 1 critical

Comment thread src/discount.ts
* @returns The price after applying the tier-appropriate discount
*/
export const priceAfterDiscount = (
amount: number,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[critical] The function body for priceAfterDiscount appears to have been incorrectly modified. The line that calculates and returns the discounted price (return amount * multiplier) has been replaced by a type export (export type Tier = CustomerTier). This change breaks the functionality of the function, as it no longer computes or returns the expected number value.

@vineethkrishnan
Copy link
Copy Markdown
Owner Author

@clearpr review

@clearpr
Copy link
Copy Markdown

clearpr Bot commented May 8, 2026

ClearPR Review

Diff stats: 108 raw lines → 81 semantic lines (25% noise filtered)

Findings

  • 2 warnings

Comment thread src/discount.ts
amount: number,
customerTier: CustomerTier,
): number => {
if (amount < 0) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[warning] The original return statement (return amount * multiplier) has been removed (indicated by the diff). This causes priceAfterDiscount to no longer calculate and return the discounted price, leading to a runtime error or incorrect result (likely returning undefined instead of a number).

Comment thread src/discount.ts
customerTier: CustomerTier,
): number => {
if (amount < 0) {
return 0;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[warning] The line export type Tier = CustomerTier is misplaced immediately following the function definition block. While syntactically valid in some contexts, it suggests that a critical return statement was mistakenly replaced by an unrelated export, indicating a logic error regarding the function's intended output.

@vineethkrishnan
Copy link
Copy Markdown
Owner Author

vineethkrishnan commented May 8, 2026

@clearpr review

1 similar comment
@vineethkrishnan
Copy link
Copy Markdown
Owner Author

@clearpr review

@clearpr
Copy link
Copy Markdown

clearpr Bot commented May 8, 2026

ClearPR Review

Diff stats: 108 raw lines → 81 semantic lines (25% noise filtered)

Findings

  • 1 critical

Comment thread src/discount.ts
/**
* Apply tier-based discount to a price.
*
* @param amount - The original price before discount (must be non-negative)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[critical] The implementation appears to have removed or lost the final calculation and return statement (return amount * multiplier). The function's core purpose is to calculate and return the discounted price. If this logic is missing or improperly handled by the diff, the function will no longer perform its intended calculation.

@vineethkrishnan
Copy link
Copy Markdown
Owner Author

@clearpr run

@clearpr
Copy link
Copy Markdown

clearpr Bot commented May 8, 2026

ClearPR Review

Diff stats: 108 raw lines → 81 semantic lines (25% noise filtered)

Findings

  • 1 warning

Comment thread src/discount.ts
export const priceAfterDiscount = (
amount: number,
customerTier: CustomerTier,
): number => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[warning] The removal of return amount * multiplier appears to break the function's core logic. The priceAfterDiscount function must return a number according to its signature. If this calculation is no longer needed here, please confirm how the final price is determined and ensure the function returns a valid value.

@vineethkrishnan
Copy link
Copy Markdown
Owner Author

@clearpr run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant