# Add ESLint to a Chrome Extension

Yes. An agent adds an ESLint flat config that knows the chrome APIs, React and Jest to your TypeScript extension, fixes what it flags, adds it to CI and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-eslint/chrome-extension/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent clones the extension into its own cloud sandbox and reads how it is built before choosing a lint setup. In a project like chibat/chrome-extension-typescript-starter, `package.json` has `build` and `watch` scripts that run webpack with the configs under `webpack/`, `test` that runs Jest through `ts-jest`, and `style` that runs Prettier 2 over `src/**/*.{ts,tsx}`; the dependencies are React 18 and the dev dependencies include TypeScript 5, `@types/chrome` 0.0.158, Jest 29 and webpack 5. There is no ESLint dependency, config or script anywhere. `tsconfig.json` is strict with `jsx` set to `react`, `rootDir` `src` and ES6 modules, while the three files under `webpack/` are CommonJS and `tsconfig.test.json` switches module resolution for Jest.

Those three kinds of file need three kinds of rules, so the agent writes one `eslint.config.mjs` with separate blocks. For `src/**/*.{ts,tsx}` it uses typescript-eslint's recommended rules with the project's `tsconfig.json`, `eslint-plugin-react` and `eslint-plugin-react-hooks`, with the `chrome` global declared through the `webextensions` set from `globals` so `chrome.storage.sync.get` in `src/options.tsx` and `chrome.tabs.sendMessage` in `src/popup.tsx` are not reported as unknown globals. For `webpack/*.js` it declares Node globals and allows `require`. For `src/__tests__/**` it adds the Jest globals so `test` and `expect` in `src/__tests__/sum.ts` pass. `eslint-config-prettier` goes last so no formatting rule fights the existing `style` script, and `dist/` is ignored.

Then the agent runs the linter and reads every finding against the code rather than silencing rules. `src/content_script.tsx` registers an `onMessage` listener and `src/background.ts` schedules a `polling` function every thirty seconds with `setTimeout`; `src/popup.tsx` logs the reply to `console.log` and `src/options.tsx` returns a cleanup function from inside a `chrome.storage.sync.set` callback where nothing can call it. Where a rule reports something the code genuinely does wrong, the agent fixes it in a separate commit; where a rule is a matter of taste for this codebase, it turns the rule off in the config with a comment saying why, and it never adds a blanket `eslint-disable`.

To finish, it adds a `lint` script, pins the new dev dependencies in `package.json` and `package-lock.json`, and adds a `npm run lint` step to `.github/workflows/build.yml` between `npm ci` and `npm run build`, so the Node 20 and Node 22 matrix jobs both lint before they build. It runs `npm run lint`, `npm run build` and `npm test` in the sandbox and checks that `npm run style` leaves the files unchanged after the lint fixes, so the two tools agree.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add ESLint to this Chrome extension. Read package.json, tsconfig.json, tsconfig.test.json, jest.config.js, the files under webpack/ and src/, public/manifest.json and .github/workflows/build.yml first. Write an eslint.config.mjs flat config with typescript-eslint recommended rules for src/**/*.{ts,tsx} using the project tsconfig, eslint-plugin-react and eslint-plugin-react-hooks, the webextensions globals so chrome.* is defined, a block for webpack/*.js with Node and CommonJS globals, a block for src/__tests__ with Jest globals, eslint-config-prettier last, and dist/ ignored. Run the linter, fix findings that are real defects in their own commit, disable rules that do not fit this codebase with a comment saying why, and never use file-wide eslint-disable. Add a lint script, pin the dev dependencies, add npm run lint to build.yml between npm ci and npm run build, then run npm run lint, npm run build, npm test and npm run style and confirm style changes nothing. Open a pull request listing the rules enabled, each finding and what you did about it.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request on its own branch adding `eslint.config.mjs`, a `lint` script and the ESLint, typescript-eslint, React, React Hooks, `globals` and `eslint-config-prettier` dev dependencies in `package.json` and `package-lock.json`, and a lint step in `.github/workflows/build.yml`. Code changes under `src/` sit in their own commit, one per finding the agent treated as a defect, so a reviewer can accept the config and still argue about an individual fix.

The description lists the rule sets and the rules turned off, each with its one-line reason, and a table of findings with file, rule and outcome. The transcript at `GET /o/{org}/sessions/{id}/messages` keeps the first `npm run lint` run with every finding, the runs after each fix, and the `npm run build`, `npm test` and `npm run style` output, so the reviewer sees the linter go quiet rather than being told it did.

Before merging, a reviewer checks that the `chrome` global is typed rather than declared `any`, that the test block only applies under `src/__tests__/`, and that the CI step runs on both Node versions in the matrix. A follow-up on the same session can add `lint-staged` with a pre-commit hook, or raise rules from warn to error once the team has lived with them.

## Run it on every extension repository without a linter

A team that maintains several extensions from the same starter runs this once per repository. From your own server, send the body above to `POST /o/{org}/sessions` with each repository in `resources`, one run per repository, and a `request_id` that is a UUID v5 of the repository name so a retry is safe. Give the key a `webhook_url` and every run the key starts posts `run.completed` with `data.session_url` when its turn ends; a handler reads the pull request link from the session.

To keep the config honest after it lands, add an automation to the Project with a `github` trigger on `pull_request.opened` and `pull_request.synchronize` and a prompt that runs `npm run lint` on the pull request's branch and comments on new findings; the trigger clones that branch and adds the event after the prompt, and the automation starts at most `max_runs_per_hour` runs in an hour.

## Why run it on Rush?

Adding a linter to an existing codebase is mostly reading: which globals are real, which rules match how the code is written, which findings are bugs and which are noise. The agent does that reading against the actual files in its own sandbox, runs the linter after every change, and ships the decisions as a config with comments and a table, so nobody has to redo the triage from a wall of warnings.

Each `npm run lint`, `npm run build` and `npm test` and its output stay in the run's transcript, so the pull request's claim that the linter is clean is checkable, and the laptop that handed off the task is free while it happens. Several extensions can get the same config at once, each in its own sandbox and its own pull request.

## Frequently asked questions

### Will ESLint complain that chrome is not defined?

Not with this config. The block for `src/` adds the `webextensions` globals from the `globals` package, and `@types/chrome`, already a dev dependency, gives the calls their types, so `chrome.action.setBadgeText` in `src/popup.tsx` is both defined and typed.

### Does it conflict with the existing Prettier setup?

No. `eslint-config-prettier` is the last entry in the flat config and turns off every rule that overlaps with formatting, so `npm run style` stays the formatter and `npm run lint` stays about correctness. The agent runs both at the end to confirm they agree.

### Will it rewrite my code to satisfy the rules?

Only where a rule points at a real defect, and each such fix is its own commit with the rule named in the message. Rules that do not fit the codebase are disabled in the config with a reason, so the pull request can be merged without accepting any code change you disagree with.

### What about the webpack config files?

They are CommonJS files that use `require` and `__dirname`, so they get their own block with Node globals and `sourceType` set to `commonjs`. Without it the TypeScript rules for `src/` would report every `require` in `webpack/webpack.common.js`.

## More Chrome Extension jobs

- [Make a Chrome Extension Work in Firefox](https://getrush.ai/run/add-firefox-support/chrome-extension/)
- [Add i18n to a Chrome Extension from a Linear Issue](https://getrush.ai/run/add-i18n/chrome-extension/)
- [Add Keyboard Shortcuts to a Chrome Extension](https://getrush.ai/run/add-keyboard-shortcuts/chrome-extension/)

## The same job on other stacks

- [Add ESLint to a Node.js App](https://getrush.ai/run/add-eslint/nodejs/)
- [Add ESLint to a SolidJS App](https://getrush.ai/run/add-eslint/solidjs/)

## More jobs like this: Hand off a long task

- [Add Fastlane to a Flutter App](https://getrush.ai/run/add-fastlane/flutter/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
