@codemod/eslint-custom-rules-v8-to-v9
Automatically migrate your custom ESLint rules from v8 to v9 format.
Overview
This codemod transforms your custom ESLint rules to be compatible with ESLint v9. It handles all breaking changes in the custom rule API, including context method removals, new rule structure requirements, and deprecated APIs.
What This Codemod Does
This codemod performs a comprehensive migration of custom ESLint rules from v8 to v9. It handles the following breaking changes from the official ESLint v9 migration guide:
- ✅ Removed multiple
contextmethods - migrates tosourceCodeequivalents - ✅ Removed
sourceCode.getComments()- converts to combination ofgetCommentsBefore/Inside/After - ✅ Removed
CodePath#currentSegments- adds code path tracking logic - ✅ Function-style rules are no longer supported - converts to object format with
metaandcreate
Detailed Transformations:
Custom Rule Migration
Transforms your custom ESLint rules to the new format:
- Converts old function-based rule exports to the new object format with
metaandcreateproperties - Updates
contextmethod calls to usecontext.sourceCode(e.g.,context.getSource()→contextSourceCode.getText()) - Migrates deprecated methods:
getSource→getTextgetSourceLines→getLinesgetComments→ combination ofgetCommentsBefore/Inside/AftergetAncestors,getScope,markVariableAsUsedwith TODO comments for new parameters
- Handles
currentSegmentsAPI changes by adding necessary code path tracking - Detects fixable rules and adds
fixable: "code"to meta
Usage
Migrate Custom Rules
Run the codemod and provide paths to your rule files or directories:
bash
You'll be prompted to provide paths to your rule files or directories:
bash
Manual Steps Required
After running this codemod, you need to:
-
Review TODO comments in migrated custom rules for context method migrations:
Removed on contextReplacement on SourceCodecontext.getAncestors()sourceCode.getAncestors(node)context.getScope()sourceCode.getScope(node)context.markVariableAsUsed(name)sourceCode.markVariableAsUsed(name, node) -
Test your custom rules:
bash