desloppify icon indicating copy to clipboard operation
desloppify copied to clipboard

TypeScript: orphaned/facade/test_coverage false positives in Expo Router + React Native monorepos (no config hook for entry points, platform extensions or test locations)

Open Nordm80 opened this issue 3 weeks ago • 1 comments

Running desloppify 1.0 on an Expo (React Native + web) repo with several apps built from one codebase, three detector classes produce findings that are false by construction. None of them can be expressed in .desloppify/config.json today: entry points are hard-coded (TS_ENTRY_PATTERNS in languages/typescript/plugin_contract.py, plus the Next.js conventions in engine/detectors/orphaned.py), and the only available knobs (exclude, ignore, zone_overrides) remove whole paths from every detector, which would hide real issues in the same directories.

1. Expo Router route files are entry points

Expo Router (file-based routing, like Next.js App Router) treats every file under an app/ directory as a route. Route files are never imported; a thin route that re-exports a screen is the documented pattern:

// apps/<app>/app/(tabs)/items/index.tsx
export { default } from '../../../screens/ItemListScreen';

desloppify reports these as orphaned ("zero importers, not an entry point") and facade ("Re-export facade (1 LOC) … 0 importers"). _layout.tsx files get the same orphaned finding. The Next.js special-casing in orphaned.py (_NEXTJS_APP_DIR_CONVENTIONS, gated on next.config.*) shows the shape of a fix: detect Expo Router (expo-router in package.json dependencies, or "main": "expo-router/entry") and treat every source file under the configured app roots as an entry. Expo Router also lets the root be moved (expo-router plugin root option / EXPO_ROUTER_APP_ROOT), so in a monorepo the roots are e.g. apps/*/app/.

2. Platform-specific extensions are not resolved

React Native / Metro resolves import { x } from './storage' to storage.native.ts, storage.ios.ts, storage.android.ts or storage.web.ts depending on platform (webpack/Vite setups for react-native-web do the same with resolve.extensions). The import graph only resolves the bare name, so the platform sibling is reported orphaned and its importer count is wrong:

lib/client.ts          import { storage } from './storage'
lib/storage.ts         (web)
lib/storage.native.ts  -> reported "Orphaned file: zero importers"

Suggested fix: when resolving a relative specifier, also try <name>.{native,ios,android,web}.<ext> and count an edge to each variant that exists (ideally configurable as platform_extensions).

3. Tests outside the module's own subtree are not counted

test_coverage reports untested_module / transitive_only for modules that have direct, dedicated tests when those tests live in another directory. With shared code in src/ and app-specific tests in apps/<app>/**/__tests__/:

src/components/Header.tsx                          -> "untested_module"
apps/<app>/components/__tests__/Header.test.tsx
    import Header from '../../../../src/components/Header';

Suggested fix: a test file that imports a module directly (an import-graph edge from a TEST-zone file) should count as direct coverage regardless of directory, or the test-to-source mapping should be configurable (e.g. test_roots).

4. (Minor) compile-only probe files

Some repos keep files that exist only to be type-checked (e.g. a Deno edge-function probe asserting a type contract). An entry_patterns (or extra_entry_patterns) config key would cover this and #1 generically.

Prior art

fallow has an Expo Router plugin and lets the project declare entry points in config, e.g. "entry": ["apps/*/app/**/*.{ts,tsx}", "<path to probe file>"] (the plugin only looks in the default app/ root, so monorepo roots need the explicit entry). fallow has no platform-extension resolution either (class 2). A per-project entry_patterns / platform_extensions / test_roots trio in config.json would let desloppify describe such a repo the same way.

Related: #705 (tsconfig paths), #933 (workspace package exports).

Impact

In our case a few dozen queue items per scan were of these classes. Because review and scan are gated on a drained objective queue, false positives that cannot be configured away block the workflow; the only per-item escape is plan skip --false-positive, which has to be repeated after every move/rename.

Happy to test a patch.

Nordm80 avatar Nov 07 '26 23:11 Nordm80

Another case for this issue: TypeScript tests that load the module with require('…') (needed inside jest.isolateModules) aren't counted as direct tests either, because TS_IMPORT_RE doesn't read require.

PR with test_roots (case 3) and the require fix: https://github.com/peteromallet/desloppify/pull/971

Nordm80 avatar Nov 10 '26 11:11 Nordm80