Skip to content

Refactor/lint hooks deps#21

Merged
kilbot merged 2 commits intomainfrom
refactor/lint-hooks-deps
Jan 29, 2026
Merged

Refactor/lint hooks deps#21
kilbot merged 2 commits intomainfrom
refactor/lint-hooks-deps

Conversation

@kilbot
Copy link
Copy Markdown
Contributor

@kilbot kilbot commented Jan 29, 2026

Summary by CodeRabbit

  • Refactor

    • Optimized import statements and removed unused dependencies across multiple components.
    • Simplified type declarations and improved component display names for better debugging experience.
    • Consolidated React Native and animation imports for cleaner codebase architecture.
  • Chores

    • Enhanced lint rule handling with configuration updates for hooks and error boundary management.
    • Minor text formatting improvements for consistent content rendering.

✏️ Tip: You can customize this high-level summary in your review settings.

Safe, no-behavior-change fixes across the monorepo:
- Remove 75+ unused imports, variables, and type declarations
- Fix no-undef errors by adding eslint-env node to Node.js scripts
- Fix react/no-unescaped-entities by escaping apostrophes in JSX
- Remove unused catch parameters
- Add missing displayName to forwardRef components
- Fix missing key props in iterators
- Replace empty interfaces with type aliases

Packages affected:
- @wcpos/core: 82 → 36 problems
- @wcpos/components: 43 → 25 problems
- @wcpos/web-bundle: 2 → 2 problems (all fixed, remaining are no-undef)
- @wcpos/main: 4 → 2 problems
- @wcpos/utils: 4 → 3 problems

Total reduction: 213 → 138 problems (~35% reduction)
Fixes for hooks dependency issues:
- Add eslint-disable comments for intentional patterns (cache busters, identity keys)
- Remove unnecessary dependencies where safe
- Add txInstance to translations context dependencies
- Fix stable ref patterns in collapsible primitives
- Remove unused type declarations and imports from query hooks

Query hooks cleaned:
- categories.tsx, customers.tsx, orders.tsx, products.ts
- tags.tsx, tax-rates.tsx, variations.ts

Packages affected:
- @wcpos/query: 33 → 15 problems
- @wcpos/components: Added eslint-disable for intentional patterns

Total reduction: 138 → 116 problems
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 29, 2026

📝 Walkthrough

Walkthrough

Comprehensive cleanup across the monorepo removing unused imports, type declarations, and dependencies. The changes consolidate import statements, add ESLint suppressions for intentional dependency patterns, add display names to components for debugging, escape HTML entities in user-facing text, and remove unused type definitions from query hooks.

Changes

Cohort / File(s) Summary
UI Text Escaping
apps/main/app/+not-found.tsx, apps/main/components/root-error.tsx
Escaped apostrophes in user-facing error messages using HTML entities (').
Component Display Names
packages/components/src/numpad/index.tsx, packages/components/src/pressable/index.tsx
Added displayName property assignments to improve React DevTools debugging.
Unused React Imports Removal
packages/core/src/contexts/app-state/use-hydration-suspense.ts, packages/core/src/screens/main/pos/contexts/current-order/use-new-order.ts, packages/core/src/screens/main/pos/hooks/use-add-product.ts, packages/core/src/screens/main/pos/hooks/use-add-variation.ts, packages/core/src/screens/main/products/add-product/index.tsx, packages/core/src/screens/main/hooks/use-base-tax-location.ts, packages/core/src/screens/main/hooks/use-tax-incl-or-excl.ts
Removed unused top-level React imports across multiple hook and component files.
Unused Lodash Imports Removal
packages/core/src/screens/main/contexts/tax-rates/tax-rates.helpers.ts, packages/core/src/screens/main/pos/cart/cells/edit-shipping-line/form.tsx, packages/core/src/utils/merge-stores.ts, packages/query/src/hooks/tags.tsx
Removed unused lodash functions (uniq, toString, isEmpty).
RxJS & Operator Imports Cleanup
packages/core/src/screens/main/components/product/filter-bar/index.tsx, packages/core/src/screens/main/hooks/use-collection.ts
Removed unused RxJS operators (startWith, tap) from imports.
Type Import & Alias Removals
packages/core/src/screens/main/contexts/use-pull-document.ts, packages/core/src/screens/main/pos/cart/customer.tsx, packages/core/src/screens/main/pos/cart/tabs.tsx, packages/core/src/screens/main/pos/hooks/use-add-product.ts, packages/core/src/screens/main/pos/hooks/use-add-variation.ts, packages/core/src/screens/main/pos/hooks/use-cart-lines.ts, packages/components/src/print/text.tsx
Removed unused type aliases and imports (e.g., RxDocument, OrderDocument, LineItem, TextUnderline).
Component-Specific Type/Import Cleanup
packages/components/src/label/index.tsx, packages/components/src/loader/index.tsx, packages/components/src/logo/logo.tsx, packages/core/src/screens/main/components/incl-excl-tax-radio-group.tsx, packages/core/src/screens/main/components/tax-display-radio-group.tsx
Removed unused type/component imports (PressableRef, Platform, StyleProp, ViewProps, FormItemProps).
Unused RxDB Imports Removal
packages/core/src/contexts/translations/cache.ts, packages/core/src/screens/main/contexts/use-pull-document.ts
Removed unused isRxDocument imports from 'rxdb'.
Query Hooks - Public Type/Interface Removals
packages/query/src/hooks/customers.tsx, packages/query/src/hooks/orders.tsx, packages/query/src/hooks/products.ts, packages/query/src/hooks/tags.tsx, packages/query/src/hooks/tax-rates.tsx, packages/query/src/hooks/variations.ts
Removed exported DocumentType type aliases and APIQueryParams interface definitions from query hooks.
ESLint Exhaustive-Deps Comment Additions
packages/components/src/collapsible/primitives.web.tsx, packages/components/src/input/index.tsx, packages/components/src/numpad/index.tsx, packages/query/src/use-query.ts, packages/query/src/use-relational-query.ts, packages/query/src/use-replication-state.ts
Added eslint-disable-next-line react-hooks/exhaustive-deps comments to suppress lint warnings for intentional dependency patterns.
Catch Clause Refactoring
packages/core/src/lib/url/parse-link-header.ts, packages/components/src/webview/index.tsx, packages/utils/src/logger/index.ts
Simplified catch clauses from catch (e) to catch where error object was unused.
Data Table Component Cleanup
packages/components/src/data-table/index.tsx, packages/components/src/data-table/index.web.tsx, packages/components/src/data-table/row.tsx
Removed unused animation imports, simplified dependencies, eliminated unused memoized values and imports (ActivityIndicator, FadeInUp, FadeOutUp, cn).
Cart-Related Type & Import Removals
packages/core/src/screens/main/pos/cart/rows/fee-line.tsx, packages/core/src/screens/main/pos/cart/rows/line-item.tsx, packages/core/src/screens/main/pos/cart/rows/shipping-line.tsx, packages/core/src/screens/main/pos/cart/index.tsx, packages/core/src/screens/main/pos/cart/table.tsx
Removed unused TableProps, RenderItem type aliases, and component imports (Button, ButtonGroup, Column, EmptyTableRow, Suspense, cn).
Component Props & Structure Simplification
apps/main/app/(app)/(drawer)/(pos)/(modals)/cart/add-misc-product.tsx
Removed Dialog UI wrapper, props interface, and related imports; simplified to render AddMiscProductForm directly.
Import Format & Consolidation Changes
packages/components/src/command/index.tsx, packages/components/src/format-number/format-number.tsx, packages/components/src/input/index.tsx, packages/components/src/select/index.tsx
Changed type declarations (interface to type alias), converted default imports to named imports, consolidated multi-line imports to single lines.
App State & Dependency Updates
packages/core/src/screens/main/components/header/user-menu.tsx, packages/core/src/contexts/translations/index.tsx, packages/core/src/screens/main/pos/products/scanner-button.tsx
Updated destructuring from state objects and hook returns (removed isWebApp, rest); extended useEffect dependencies (added txInstance).
Router & UI Utility Removals
packages/core/src/screens/main/pos/cart/add-cart-item-buttons.tsx, packages/core/src/screens/main/products/cells/actions.tsx
Removed unused router imports (expo-router) and navigation-related variables.
Miscellaneous Type & Utility Changes
packages/core/src/screens/main/components/customer-select.tsx, packages/components/src/tooltip/index.web.tsx, packages/components/src/virtualized-list/virtualized-list.tsx, packages/components/src/format/list.tsx, packages/core/src/screens/main/reports/orders/index.tsx, packages/core/src/utils/merge-stores.ts, packages/query/src/hooks/categories.tsx
Removed unused imports/types (useComboboxRootContext, TooltipTriggerProps, ItemProps, get); added React key props to list items; added explicit type annotation to parameter; replaced map-based lookups with Set-based approach.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐰 Whiskers twitching, I hop through the code,
Sweeping out dust from the cleanup road,
Unused imports, types cast away,
Cleaner burrows make for brighter days!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Refactor/lint hooks deps' directly reflects the primary changeset focus: removing unused imports, adding eslint-disable comments for React hooks dependencies, and cleaning up type declarations across the codebase.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
packages/components/src/format-number/format-number.tsx (1)

132-139: Pre-existing bug: index is undefined.

The getMaskAtIndex function references index on line 138, but this variable is never defined. The function is called with getMaskAtIndex(hashCount) on line 150, but the function signature doesn't accept any parameters.

🐛 Proposed fix
-	const getMaskAtIndex = React.useCallback(() => {
+	const getMaskAtIndex = React.useCallback((index: number) => {
 		const { mask = ' ' } = props;
 		if (typeof mask === 'string') {
 			return mask;
 		}

 		return mask[index] || ' ';
-	}, [props]);
+	}, [props.mask]);

Note: Also narrowed the dependency to props.mask since that's the only property used.

packages/core/src/screens/main/pos/cart/table.tsx (1)

208-210: Replace console.log and tighten the any type.
Use the logger and avoid any here.

✅ Proposed fix
 import { useObservableEagerState } from 'observable-hooks';

+import log from '@wcpos/utils/logger';
 import { ErrorBoundary } from '@wcpos/components/error-boundary';
 import { getFlexAlign } from '@wcpos/components/lib/utils';
@@
 		meta: {
-			onChange: (data: any) => {
-				console.log('onChange called without handler', data);
+			onChange: (data: unknown) => {
+				log.warn('onChange called without handler', data);
 			},

As per coding guidelines, use the logger library exclusively for logging and do not use the any type.

packages/components/src/numpad/index.tsx (1)

45-56: Improve comment clarity on mount-only effect intent.

The useEffect correctly runs only on mount (empty deps), and subsequent selection updates are properly handled by event handlers in handleButtonPress. The current eslint comment should explicitly clarify that ignoring value changes after mount is intentional:

✏️ Suggested improvement
-			// eslint-disable-next-line react-hooks/exhaustive-deps -- Intentionally empty - run once on mount
+			// eslint-disable-next-line react-hooks/exhaustive-deps -- Mount-only focus/selection; ignore later value updates intentionally
 			[]

This aligns with the coding guideline: "Before using useEffect, verify if the logic can be... If used, add a comment explaining WHY it is necessary." The enhanced comment makes explicit that value changes after mount are intentionally not re-triggering the effect, since selection is managed by event handlers instead.

🧹 Nitpick comments (6)
packages/components/src/format/list.tsx (1)

12-16: Prefer a stable key over array index (Line 14).

Using the array index can cause state/DOM mismatches when items are inserted/reordered. If items are strings, prefer a stable key derived from the content (and include the index only as a fallback for duplicates).

♻️ Suggested tweak
-					return <Text key={index}>{item}, </Text>;
+					return <Text key={`${item}-${index}`}>{item}, </Text>;
packages/components/src/label/index.tsx (1)

8-10: Import ordering: external dependency import should come before internal import.

Per coding guidelines, import order should be: React first → external dependencies → @wcpos/* internal imports. The @rn-primitives/types import (external) is placed after the internal ../lib/utils import.

♻️ Suggested fix for import ordering
 import * as LabelPrimitive from '@rn-primitives/label';
 import * as Slot from '@rn-primitives/slot';
+import type { SlottablePressableProps } from '@rn-primitives/types';

 import { cn } from '../lib/utils';
-
-import type { SlottablePressableProps } from '@rn-primitives/types';
packages/components/src/format-number/format-number.tsx (1)

186-188: Consider adding explicit type annotation.

The val parameter has an implicit any type. Per coding guidelines, explicit types should be used instead of any.

♻️ Suggested fix
-	const formatInput = React.useCallback((val) => {
+	const formatInput = React.useCallback((val: string) => {
 		return val;
 	}, []);
packages/components/src/data-table/index.web.tsx (1)

87-89: Replace console.log with the logger library.

As per coding guidelines, use @wcpos/utils/logger instead of console.log for logging.

♻️ Proposed fix

Add the import at the top of the file:

import { getLogger } from '@wcpos/utils/logger';

const logger = getLogger(['wcpos', 'components', 'DataTable']);

Then replace the console.log:

 meta: {
   expanded$,
   expandedRef,
   onChange: (data: any) => {
-    console.log('onChange called without handler', data);
+    logger.warn('onChange called without handler', { context: { data } });
   },
   ...tableMeta,
 },
packages/core/src/screens/main/components/customer-select.tsx (2)

76-81: Consider expanding the useEffect comment to explain WHY.

The cleanup effect is a valid use case, but per coding guidelines, the comment should explain WHY it's necessary, not just WHAT it does. For example: "Clear the search when unmounting to prevent stale search state from persisting in the query when the component remounts."


100-100: Avoid using any type for the query parameter.

The query: any violates the coding guideline to not use any type. Use the return type from useQuery or define a proper interface for the query object.

♻️ Suggested fix
-export function CustomerList({ query, withGuest }: { query: any; withGuest: boolean }) {
+export function CustomerList({ query, withGuest }: { query: ReturnType<typeof useQuery>; withGuest: boolean }) {

Alternatively, if useQuery exports a specific type, import and use that instead.

As per coding guidelines: "Do not use 'any' type; use strict types and generics instead"

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