Skip to content

Commit e045246

Browse files
authored
chore: modify how eslint is invoked from lint-staged for eslint migration (#32149)
* each pkg is responsible for its own lint-staged, because lerna does not play nicely with lint-staged * use on hierarchical lint-staged only for new eslint packages * rm unnecessary lint script * add blurb about lint-staged to the guide * fix for recursion * correct glob for old eslint
1 parent 4127264 commit e045246

File tree

5 files changed

+29
-31
lines changed

5 files changed

+29
-31
lines changed

guides/eslint-migration.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,39 +108,50 @@ For each package in the batch:
108108
- In each migrated package, add `@packages/eslint-config` to `devDependencies` (use a relative file path if not published to npm).
109109
- **Add ESLint as a dev dependency:**
110110
- Since `@packages/eslint-config` has ESLint as a peer dependency, add `eslint: "^9.18.0"` to `devDependencies`.
111-
4. **Run lint and autofix:**
111+
4. **Add lint-staged configuration:**
112+
- Add a `lint-staged` section to the package's `package.json`:
113+
```json
114+
{
115+
"lint-staged": {
116+
"**/*.{js,jsx,ts,tsx}": "eslint --fix"
117+
}
118+
}
119+
```
120+
- This ensures that when files are staged for commit, they are automatically linted and fixed using the package's local ESLint configuration.
121+
5. **Run lint and autofix:**
112122
- From the package root, run:
113123
```
114124
npx eslint . --ext .js,.ts,.tsx,.jsx --fix
115125
```
116126
- Manually fix any remaining lint errors.
117-
5. **Verify TypeScript configuration:**
127+
6. **Verify TypeScript configuration:**
118128
- Ensure the package has a valid `tsconfig.json` that works with the new ESLint config.
119129
- Run `npx tsc --noEmit` to check for TypeScript compilation errors.
120130
- Verify that the new ESLint config can properly parse TypeScript files in the package.
121-
6. **Run tests for the package** to ensure nothing broke.
122-
7. **Commit changes** with a clear message, e.g.:
131+
7. **Run tests for the package** to ensure nothing broke.
132+
8. **Commit changes** with a clear message, e.g.:
123133
```
124134
chore(npm/grep): migrate to @packages/eslint-config and remove legacy eslint-plugin-dev
125135
```
126136
127-
### 3. **Open a PR for Each Batch**
137+
### 4. **Open a PR for Each Batch**
128138
- Keep each migration PR focused (one batch per PR).
129139
- List all affected packages in the PR description.
130140
- Include a checklist for each package:
131141
- [ ] Removed old ESLint config
132142
- [ ] Added new config
143+
- [ ] Added lint-staged configuration
133144
- [ ] Ran lint and fixed errors
134145
- [ ] Ran tests
135146
136-
### 4. **Document Issues or Gaps**
147+
### 5. **Document Issues or Gaps**
137148
- If you hit any missing rules or plugin gaps, note them for follow-up.
138149
- If a package needs a custom override, add it in a local `eslint.config.ts` (prefer to upstream to the shared config if possible).
139150
140-
### 5. **Deprecate and Remove Old Plugin**
151+
### 6. **Deprecate and Remove Old Plugin**
141152
- Once all packages are migrated, remove `@cypress/eslint-plugin-dev` from the repo and CI.
142153
143-
### 6. **Simplify Lint-Staged Configuration**
154+
### 7. **Simplify Lint-Staged Configuration**
144155
After all packages are migrated, simplify the lint-staged configuration in root `package.json`:
145156
146157
```json
@@ -152,7 +163,7 @@ After all packages are migrated, simplify the lint-staged configuration in root
152163
}
153164
```
154165

155-
### 7. **Update Lerna/Monorepo Config**
166+
### 8. **Update Lerna/Monorepo Config**
156167
- Ensure all packages reference the new config in their `package.json`/`eslint.config.ts`.
157168
- Update documentation and developer onboarding guides.
158169

@@ -317,6 +328,7 @@ For each package, ensure you've completed:
317328
- [ ] Removed `.eslintrc*` files
318329
- [ ] Created `eslint.config.ts` with proper configuration
319330
- [ ] Added required dependencies (`eslint`, `@packages/eslint-config`, `jiti`)
331+
- [ ] Added lint-staged configuration to `package.json`
320332
- [ ] Created/updated `tsconfig.json` that extends base config
321333
- [ ] Updated ESLint scripts (removed `--ext` flag)
322334
- [ ] Ran `yarn lint` successfully

npm/grep/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
"cypress",
4141
"grep"
4242
],
43+
"lint-staged": {
44+
"**/*.{js,jsx,ts,tsx,json}": "eslint --fix"
45+
},
4346
"resolutions": {
4447
"jiti": "^2.4.2"
4548
},

npm/webpack-preprocessor/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,4 @@
7676
}
7777
}
7878
}
79-
}
79+
}

package.json

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -265,27 +265,7 @@
265265
]
266266
},
267267
"lint-staged": {
268-
"npm/grep/**/*.{js,jsx,ts,tsx}": "yarn lint:fix",
269-
"*.{js,jsx,ts,tsx,json,eslintrc,vue}": "eslint --fix",
270-
"cli/**/*.{js,jsx,ts,tsx,json,eslintrc,vue}": "eslint --fix",
271-
"packages/**/*.{js,jsx,ts,tsx,json,eslintrc,vue}": "eslint --fix",
272-
"scripts/**/*.{js,jsx,ts,tsx,json,eslintrc,vue}": "eslint --fix",
273-
"system-tests/**/*.{js,jsx,ts,tsx,json,eslintrc,vue}": "eslint --fix",
274-
"tooling/**/*.{js,jsx,ts,tsx,json,eslintrc,vue}": "eslint --fix",
275-
"npm/angular/**/*.{js,jsx,ts,tsx,json,eslintrc,vue}": "eslint --fix",
276-
"npm/cypress-schematic/**/*.{js,jsx,ts,tsx,json,eslintrc,vue}": "eslint --fix",
277-
"npm/eslint-plugin-dev/**/*.{js,jsx,ts,tsx,json,eslintrc,vue}": "eslint --fix",
278-
"npm/mount-utils/**/*.{js,jsx,ts,tsx,json,eslintrc,vue}": "eslint --fix",
279-
"npm/puppeteer/**/*.{js,jsx,ts,tsx,json,eslintrc,vue}": "eslint --fix",
280-
"npm/react/**/*.{js,jsx,ts,tsx,json,eslintrc,vue}": "eslint --fix",
281-
"npm/svelte/**/*.{js,jsx,ts,tsx,json,eslintrc,vue}": "eslint --fix",
282-
"npm/vite-dev-server/**/*.{js,jsx,ts,tsx,json,eslintrc,vue}": "eslint --fix",
283-
"npm/vite-plugin-cypress-esm/**/*.{js,jsx,ts,tsx,json,eslintrc,vue}": "eslint --fix",
284-
"npm/vue/**/*.{js,jsx,ts,tsx,json,eslintrc,vue}": "eslint --fix",
285-
"npm/webpack-batteries-included-preprocessor/**/*.{js,jsx,ts,tsx,json,eslintrc,vue}": "eslint --fix",
286-
"npm/webpack-dev-server/**/*.{js,jsx,ts,tsx,json,eslintrc,vue}": "eslint --fix",
287-
"npm/webpack-preprocessor/**/*.{js,jsx,ts,tsx,json,eslintrc,vue}": "eslint --fix",
288-
"npm/xpath/**/*.{js,jsx,ts,tsx,json,eslintrc,vue}": "eslint --fix",
268+
"**/*.{js,jsx,ts,tsx,json,eslintrc,vue}": "eslint --fix",
289269
"*workflows.yml": "node scripts/format-workflow-file.js"
290270
},
291271
"resolutions": {

packages/eslint-config/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,8 @@
2727
},
2828
"peerDependencies": {
2929
"eslint": "^9.31.0"
30+
},
31+
"lint-staged": {
32+
"**/*.{js,jsx,ts,tsx,json}": "eslint --fix"
3033
}
3134
}

0 commit comments

Comments
 (0)