DEV Community

Jules Sarah
Jules Sarah

Posted on

AI Wrote Half Your React Native Codebase. These Automated Checks Catch Its Most Common Mistakes

code review doesn't scale when an AI agent writes hundreds of lines an hour. The fix is to let machines check the machine. AI-generated code has predictable failure modes: dead code, duplication, any escapes, floating promises, broken hook dependencies, architecture drift, tests that test nothing, unnecessary or invented packages, leaked secrets and database tables without security rules. Each one has a tool that catches it. Put them in CI, and reviewers can spend their time on what tools can't judge.

AI coding tools are good enough that the bottleneck is now review. A human can carefully read maybe a few hundred lines an hour. An agent can produce thousands. Something has to give, and it's usually review quality.

The good news: the mistakes AI makes are not random. They repeat, and most of them can be detected automatically. Here are the ten most common in React Native and TypeScript projects, with the check that catches each.

1. Dead code and unused dependencies

What happens: agents create helpers "just in case", leave old versions of components behind after a refactor and install packages they end up not using.

The check: Knip finds unused files, exports and dependencies in TypeScript projects.

npx knip
Enter fullscreen mode Exit fullscreen mode

Run it weekly at minimum. Every unused file is something the next agent session might read, copy or "fix".

2. Duplicated logic

What happens: each prompt is solved fresh, so you end up with three date formatters and two slightly different useUser hooks.

The check: jscpd detects copy-pasted code across the project.

npx jscpd src --min-tokens 50 --threshold 3
Enter fullscreen mode Exit fullscreen mode

--threshold 3 fails if more than 3% of the code is duplicated. Start with a threshold that matches today's codebase, then lower it over time.

3. Type escapes with any

What happens: when types get hard, agents reach for any, as unknown as, or // @ts-ignore, which hides exactly the bugs TypeScript exists to catch.

The check: strict TypeScript plus lint rules that forbid the escape hatches.

{
  "compilerOptions": {
    "strict": true,
    "noUncheckedIndexedAccess": true
  }
}
Enter fullscreen mode Exit fullscreen mode

Add @typescript-eslint/no-explicit-any and the no-unsafe-* rules from typescript-eslint's type-checked configs (see the ESLint config below), and ban @ts-ignore with @typescript-eslint/ban-ts-comment.

4. Floating promises

What happens: generated code calls async functions without await or error handling. It works in the demo and fails silently in production when the network does.

The check: @typescript-eslint/no-floating-promises, which requires type-aware linting:

// eslint.config.js (adapt to your setup; Expo's default ESLint config is a good base)
const tseslint = require('typescript-eslint');
const reactHooks = require('eslint-plugin-react-hooks');

module.exports = tseslint.config(
  ...tseslint.configs.recommendedTypeChecked,
  {
    languageOptions: {
      parserOptions: { projectService: true, tsconfigRootDir: __dirname },
    },
    plugins: { 'react-hooks': reactHooks },
    rules: {
      '@typescript-eslint/no-explicit-any': 'error',
      '@typescript-eslint/no-floating-promises': 'error',
      '@typescript-eslint/ban-ts-comment': 'error',
      'react-hooks/rules-of-hooks': 'error',
      'react-hooks/exhaustive-deps': 'error',
    },
  }
);
Enter fullscreen mode Exit fullscreen mode

5. Broken hook dependencies

What happens: useEffect with missing dependencies (stale data) or object dependencies that change every render (infinite fetch loops). Agents frequently silence the warning instead of fixing it.

The check: react-hooks/exhaustive-deps as an error, not a warning, plus a rule in your agent instructions: never disable this rule with a comment.

6. Architecture drift

What happens: the agent imports whatever works. Screens import other screens' internals, features reach into each other and the folder structure stops meaning anything.

The check: encode your boundaries as rules. The simplest version is ESLint's no-restricted-imports:

'no-restricted-imports': ['error', {
  patterns: [
    { group: ['@/features/*/internal/*'], message: 'Import from the feature index instead.' },
  ],
}],
Enter fullscreen mode Exit fullscreen mode

For larger apps, dependency-cruiser lets you write rules like "features can't import from other features" and "screens can't import from the data layer directly". Then check for cycles, which agents also introduce:

npx madge --circular --extensions ts,tsx src
Enter fullscreen mode Exit fullscreen mode

7. Tests that test nothing

What happens: agents write many tests, and coverage looks great. But many tests assert the implementation ("the function was called") rather than behavior ("the user sees an error when sign-in fails"). They pass even when the feature is broken.

The check: coverage can't detect this. Mutation testing can: it makes small changes to your code (flipping a condition, removing a line) and checks whether any test fails. If no test notices, the tests aren't really testing that code.

npx stryker run
Enter fullscreen mode Exit fullscreen mode

Mutation testing is slow, so run it on critical modules (auth, payments, data access) rather than the whole app, and on a schedule rather than every commit.

8. Unnecessary or invented packages

What happens: agents add a dependency for a five-line function, pick a web-only library in a React Native app, or occasionally suggest a package name that doesn't exist. That last one is a real supply-chain risk: attackers register commonly hallucinated package names, hoping someone installs them.

The checks:

  • Review every package.json change in pull requests, even when the rest of the diff looks fine.
  • Verify new packages exist and are established (downloads, maintainers, repository) before installing.
  • In Expo projects, npx expo install --check flags native packages whose versions don't match your SDK.
  • Knip (check 1) catches dependencies that were added and never used.

9. Secrets in code

What happens: to "make it work", agents paste API keys into source files or put server secrets into EXPO_PUBLIC_ variables, which are bundled into the app and readable by anyone.

The checks:

gitleaks detect --source .
Enter fullscreen mode Exit fullscreen mode

Run a secret scanner like gitleaks in CI and as a pre-commit hook, and add a simple custom check that fails if names like SERVICE_ROLE or SECRET appear in any EXPO_PUBLIC_ variable.

10. Database tables without security rules

What happens: if your app uses Supabase, the anon key ships in the app, and Row Level Security is what protects data. Agents create tables in migrations and forget to enable RLS, or loosen a policy to using (true) to make an error disappear.

The checks:

-- Tables in exposed schemas without RLS: should return zero rows
select tablename from pg_tables
where schemaname = 'public' and rowsecurity = false;
Enter fullscreen mode Exit fullscreen mode

Run it in CI against a local database built from your migrations, and search new migrations for using (true). Supabase's dashboard Security Advisor also flags common problems.

Putting it together in CI

name: quality
on: [pull_request]
jobs:
  checks:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
      - run: npm ci
      - run: npx tsc --noEmit
      - run: npx eslint .
      - run: npx knip
      - run: npx jscpd src --min-tokens 50 --threshold 3
      - run: npx madge --circular --extensions ts,tsx src
      - run: npx expo install --check
      - run: npm test
Enter fullscreen mode Exit fullscreen mode

Add the secret scan and the database check as separate jobs, and run mutation testing on a schedule.

Introduce the checks gradually. Turning everything on at once in an existing codebase produces hundreds of failures and gets the whole setup ignored. Start with the checks that matter most for your app (often types, floating promises and secrets), fix the existing issues, then add the next one.

Feed the results back to the agent

The final step is what makes this compound: when a check fails, the agent should fix it, and when the same failure happens twice, add a rule to your agent's instruction file (CLAUDE.md, AGENTS.md or your tool's equivalent):

  • "Never use any; define a type."
  • "Never disable react-hooks/exhaustive-deps."
  • "Check that a package exists and is maintained before adding it."
  • "Every new table enables RLS in the same migration."

Most AI coding tools can run these commands themselves. Tell the agent to run the type-check and linter before it reports a task as done, and it will catch many of its own mistakes before you ever see them.

What the checks can't do

Automated checks catch the predictable mistakes. They can't tell you whether the feature solves the right problem, whether the UX makes sense on a small Android phone or whether the data model will hold up next year. That's where human review should go, and with the mechanical issues automated, there's finally time for it.

Which AI code smell shows up most in your codebase? Share it, and the check you use for it, in the comments.

Top comments (0)