# Add ESLint to a Node.js App

Yes. An agent replaces JSHint with an ESLint flat config that keeps your existing rules, Cypress globals and ignores, fixes what it flags, updates CI and opens a PR.

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

## What the agent does

The agent clones the app into its own cloud sandbox and reads how it is linted today before it writes a new config. In a Node.js app like OWASP/NodeGoat, `package.json` has no `lint` script; linting runs through `Gruntfile.js`, whose `jshint` task reads `.jshintrc` and whose `precommit` task runs `jsbeautifier` then `jshint` over `app/assets/js`, `config`, `app/data`, `app/routes`, `server.js`, `artifacts` and `test`. `.jshintrc` sets `node` and `browser` globals, `esversion` 9, `eqeqeq`, `camelcase`, `latedef`, `newcap`, `noarg`, `noempty`, double `quotmark`, `strict`, `indent` 4 and `maxlen` 120, turns `unused` off, and carries an override for `test/e2e/**` that declares `cy`, `Cypress` and the Mocha globals. `.jshintignore` skips `node_modules/` and `app/assets/vendor/`. CI in `.github/workflows/lint.yml` runs `npx --no-install jshint@2.12.0 .` on Node 14, and `e2e-test.yml` runs Cypress against a MongoDB container.

The agent writes `eslint.config.js`, a flat config, and translates each JSHint option into its ESLint counterpart rather than starting from a preset and hoping: `eqeqeq`, `camelcase`, `no-use-before-define` for `latedef`, `new-cap`, `no-caller` for `noarg`, `no-empty`, `quotes` set to double, `strict` set to `global` because every file begins with `"use strict"`, `indent` at 4, `max-len` at 120, and `no-unused-vars` off to match `unused: false`. It starts from `@eslint/js` recommended for the rules JSHint had no name for, uses the `globals` package for `node` and, on `app/assets/js/**`, `browser`, and adds a block for `test/e2e/**` with the Cypress and Mocha globals so the override from `.jshintrc` survives. The `ignores` entry carries over `node_modules` and `app/assets/vendor` from `.jshintignore` and adds `test/e2e/videos` and `test/e2e/screenshots`, which `.gitignore` already excludes. The config file documents every mapping in a comment, so the next person can see that no rule was quietly dropped.

One property of this repository decides what the agent fixes. NodeGoat is a deliberately vulnerable training app: `server.js` has the `helmet`, `csurf` and HTTPS fixes commented out next to `// Fix for A5` and `// Fix for A6` notes, and the route and data-access files contain the flaws the tutorial teaches. So the agent fixes only what the translated style rules flag, such as quote style or a missing `use strict`, and does not add a security plugin or touch the intentional weaknesses; where a recommended rule fires on code the tutorial relies on, it adds a scoped `eslint-disable-next-line` with the reason instead of rewriting the lesson. Then it removes `jshint` and `grunt-contrib-jshint` from `devDependencies`, deletes `.jshintrc` and `.jshintignore`, adds a `lint` script, and changes the Gruntfile's `precommit` task to run `jsbeautifier` and then ESLint through the same `child_process.exec` pattern the `db-reset` task already uses, so `grunt precommit` keeps its name.

CI follows. `lint.yml` changes from `npx jshint` to `npm ci` and `npm run lint`, and its Node version moves up to one that current ESLint supports, while `e2e-test.yml` and its Node matrix stay as they are because the Cypress suite is unrelated to linting. The agent runs `npm ci` and `npm run lint` until the output is clean, and `npm test`, which is `grunt test`; that task points `mochaTest:unit` at `test/unit/*.js`, a directory that does not exist in the repository, so the agent notes that it passes trivially and that the real behavioural check is the Cypress suite in CI.

## Start it with one API call

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

```json
{
  "agent": "claude",
  "input": "Replace JSHint with ESLint in this Node.js app. Read package.json, Gruntfile.js, .jshintrc, .jshintignore, .gitignore, server.js, the files under app/, config/, artifacts/ and test/, and every workflow under .github/workflows first. Write eslint.config.js as a flat config that translates each .jshintrc option to its ESLint rule (eqeqeq, camelcase, no-use-before-define, new-cap, no-caller, no-empty, double quotes, strict global, indent 4, max-len 120, no-unused-vars off), starts from @eslint/js recommended, uses the globals package for node everywhere and browser under app/assets/js, keeps the test/e2e override with Cypress and Mocha globals, and ignores node_modules, app/assets/vendor and the Cypress videos and screenshots directories. Comment each mapping. This is a deliberately vulnerable training app: fix only what the style rules flag, do not add security rules or plugins, and do not change the intentional vulnerabilities; use a scoped disable comment with a reason where a recommended rule hits tutorial code. Add a lint script, remove jshint and grunt-contrib-jshint and the two .jshint files, make the Gruntfile precommit task run jsbeautifier then eslint, and update lint.yml to run npm ci and npm run lint on a Node version ESLint supports without touching e2e-test.yml. Run npm ci, npm run lint and npm test, and open a pull request with the rule mapping table, the list of fixes made, every disable comment and its reason, and the command output.",
  "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 that adds `eslint.config.js`, edits `package.json` for the `lint` script and the swapped dev dependencies with the updated `package-lock.json`, edits `Gruntfile.js` so `precommit` calls ESLint, updates `.github/workflows/lint.yml`, deletes `.jshintrc` and `.jshintignore`, and makes the mechanical fixes the translated rules required across `app/`, `config/` and `server.js`. `e2e-test.yml`, the Cypress tests and the tutorial's intentional vulnerabilities are untouched.

The description has a table with each `.jshintrc` option, the ESLint rule that replaced it and its setting, a list of files changed by fixes with the rule that drove each, and every `eslint-disable` comment with its reason. It ends with the `npm run lint` and `npm test` output. The transcript at `GET /o/{org}/sessions/{id}/messages` keeps each command and its output, so a reviewer can see that the final lint run reports nothing rather than read a sentence saying so.

Before merging, a reviewer checks the disable comments one by one, confirms that no vulnerability the tutorial teaches was accidentally fixed, and decides whether `jsbeautifier` should give way to Prettier in a later change. A follow-up on the same session can add `eslint-plugin-security` behind a separate config block for the branches where fixes are applied, or wire the lint into a pre-commit hook.

## Run it on every repository still on JSHint

A team that owns several older Node.js services runs this once per repository. From a script, 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.

Once the config is in, 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 only on findings the base branch did not have. The trigger clones that branch and places the event after the prompt, and the automation starts at most `max_runs_per_hour` runs in an hour.

## Why run it on Rush?

Swapping linters is a translation problem: every option in the old config means something, and a preset that ignores them changes what the team agreed to check. The agent reads `.jshintrc`, the Gruntfile and the workflows in its own sandbox, writes the mapping down, and in a repository like this one also reads the intent behind the code, so a training app stays a training app.

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

## Frequently asked questions

### Will it fix the security problems ESLint finds?

Not in a repository that exists to teach them. NodeGoat keeps its `helmet`, `csurf` and HTTPS fixes commented out on purpose, so the agent limits itself to style rules translated from `.jshintrc`, adds no security plugin, and marks any recommended rule that trips on tutorial code with a scoped disable and a reason. In an ordinary service the same run would fix those findings.

### Why a flat config?

Because current ESLint reads `eslint.config.js` and the older `.eslintrc` format is on its way out. The flat config also makes the per-directory blocks for browser code and Cypress tests explicit, which is where the `.jshintrc` override lived.

### Does the Node version in CI change?

Only in `lint.yml`, where JSHint ran on Node 14 and current ESLint needs a newer runtime. The Cypress workflow keeps its Node matrix, because the application itself is not being upgraded and that suite is what checks it.

### What happens to grunt precommit?

It keeps its name and order: `jsbeautifier` first, then the linter, now ESLint invoked through `child_process.exec` the way the Gruntfile already runs `db-reset`. `grunt-contrib-jshint` leaves `devDependencies`, and `npm run lint` is the direct way to run the same check.

### Can Prettier come in at the same time?

It could, but the pull request keeps formatting out so the diff is readable: `jsbeautifier` still formats and ESLint only lints. Replacing `jsbeautifier` with Prettier and `eslint-config-prettier` is a one-change follow-up on the same session.

## More Node.js jobs

- [Add Graceful Shutdown to a Node.js Server](https://getrush.ai/run/add-graceful-shutdown/nodejs/)
- [Add a Health Check Endpoint to a Node.js App](https://getrush.ai/run/add-health-checks/nodejs/)
- [Add Input Validation to a Node.js Express App](https://getrush.ai/run/add-input-validation/nodejs/)

## The same job on other stacks

- [Add ESLint to a SolidJS App](https://getrush.ai/run/add-eslint/solidjs/)
- [Add ESLint to a Chrome Extension](https://getrush.ai/run/add-eslint/chrome-extension/)

## 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/)
