codemod
1.2.2, released 8 weeks ago by workiva.com
Write and run automated code modifications and refactors on a codebase.
What it does
Provides utilities to write suggestor functions that analyze source files using package:analyzer, yield text patches, and run them via an interactive CLI. It supports regex, AST visitors, and test helpers to verify code refactoring logic.
AI-written summary of version 1.2.2, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need to automate large-scale refactoring or code updates across multiple files.
- You are building a custom CLI tool to migrate Dart code or configuration files.
- You want to write interactive codemods that prompt the user before applying patches.
Skip it when
- You only need standard code generation during build time (use build_runner instead).
- You are looking for a simple static analysis linter without modifying code.
Strengths
- Leverages package:analyzer APIs for robust AST traversal and modification.
- Interactive CLI handles user confirmation for patches.
- Includes testing helpers like PackageContextForTest for verifying resolved AST suggestors.
Weaknesses
- Requires familiarity with the analyzer package API for complex AST-based transforms.
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 11
Add codemod to pubspec.yaml dependencies and create a main script that calls runInteractiveCodemod.
import 'dart:io';
import 'package:codemod/codemod.dart';
void main(List<String> args) async {
exitCode = await runInteractiveCodemod(
['pubspec.yaml'],
regexSubstituter,
args: args,
);
}Alternatives
Packages that do the same job and could replace codemod.
- lint_staged
Run linters and custom commands on git staged files for Flutter and Dart projects
44Compare
Works with
Packages commonly used together with codemod: ones it builds on, ones built on it, and its own family.
- analyzercodemod depends on itPerforms static analysis of Dart code for tool integration and embedding.
- stack_tracecodemod depends on itProvides parsing, inspection, and readable formatting of Dart stack traces.
- globcodemod depends on itA file and directory globbing library that supports Bash-style path matching and listing.
- iocodemod depends on itUtilities for the Dart VM Runtime including ANSI colors, file copying, and exit code values.
- source_spancodemod depends on itStandard representation for source code locations, spans, and human-friendly error messages.
- testcodemod depends on itA full featured library for writing and running Dart tests across platforms.
- argscodemod depends on itLibrary for parsing raw command-line arguments into options and values using GNU and POSIX styles.
- loggingcodemod depends on itProvides configurable logging with levels and stream listeners for Dart apps.