Skip to content

feat: add react action-enforcement example with custom lint rule#1296

Draft
hugiex wants to merge 1 commit intoTanStack:mainfrom
hugiex:feature/action-enforcement-example
Draft

feat: add react action-enforcement example with custom lint rule#1296
hugiex wants to merge 1 commit intoTanStack:mainfrom
hugiex:feature/action-enforcement-example

Conversation

@hugiex
Copy link
Contributor

@hugiex hugiex commented Feb 25, 2026

🎯 Changes

Follow up the issue: #996
Create an example and demonstrates two lint-based enforcement approaches for TanStack DB usage in feature/UI code.

There are two options:
1. Use existed rule - Strict Boundary Approach (no-restricted-imports)
This approach blocks feature modules from importing collections at all.

Policy: src/features/** cannot import @/db/collections/*
Effect: features must use action/query wrappers only
Pros: very strong architectural boundary, simple ESLint config
Cons: less ergonomic for read paths (useLiveQuery often requires extra wrapper hooks)

// eslint config
      // This forces all reads/writes through query hooks and action modules.
      'no-restricted-imports': [
        'error',
        {
          patterns: [
            {
              group: ['@/db/collections/*'],
              message:
                'Feature modules cannot import collections directly. Use query hooks and action modules.',
            },
          ],
        },
      ],
image

2. Targeted Mutation Approach (Custom ESLint Rule)
This approach allows collection imports for reads, but forbids direct mutation calls in feature code.

Policy: in src/features/**, direct calls to collection mutation methods are forbidden (insert, update, delete, upsert)
Effect: useLiveQuery with direct collection imports remains allowed; writes must go through centralized boundaries (actions/hooks)
Pros: better DX for reads, enforces the core safety rule on writes
Cons: more implementation complexity (custom plugin/rule)

      // Features can read from collections, but write operations must go through actions.
      'tanstack-architecture/no-direct-collection-mutations': [
        'error',
        {
          collectionImportPatterns: ['^@/db/collections/'],
          mutationMethods: ['insert', 'update', 'delete', 'upsert'],
        },
      ],
image

NOTE: this PR just for example, DO NOT merge this

✅ Checklist

  • I have tested this code locally with pnpm test.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

@changeset-bot
Copy link

changeset-bot bot commented Feb 25, 2026

⚠️ No Changeset found

Latest commit: 645a14f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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