codemod
Write and run automated code modifications on a codebase. Primarily geared towards updating and refactoring Dart code, but can modify any files.
1.2.1
6.9K downloads/mo
#3422 most downloaded on pub.dev
Workiva/dart_codemod
What this package is like to depend on
Last release 3 months ago
28 Apr 2026
Release timing varies
gaps range from 3 weeks to 2.4 years
Nearly every release is documented
notes for 16 of 16 stable releases
Nothing withdrawn
no release was ever pulled
8 years old
16 releases · first in 2019
1 release in the last 12 months
see the full history below
Release timeline
16 releases · Jan 2019 to Apr 2026Releases
latest 16-
1.2.128 Apr 2026Release notes
Open source →Info
Build: (waiting for build to complete)
Skynet Results: (waiting for Skynet results)
Pipeline: (waiting for pipeline to start)
This patch release includes the following changes:Miscellaneous
-
#81 FEDX-685-take1 : GHA OSS changes to dart_codemod
- FEDX-685 GHA OSS changes
-
#93 Allow analyzer 10
-
#94 RM-230186 Release dart_codemod 1.2.1
- RM-230186 RELEASE dart_codemod 1.2.1
Notes created on Tuesday, April 28 02:00 PM UTC
-
-
1.2.018 Dec 2023Release notes
Open source →Info
Build: https://ci.webfilings.com/build/5317099
Skynet Results: https://wf-skynet-hrd.appspot.com/apps/test/smithy/5317099/latest
Pipeline: No Pipeline
This minor release includes the following changes:New Features and Improvements
- #74 FEDX-522 Add APIs to help test suggestors with resolved AST
- FEDX-522 Improve dart codemod testability
Miscellaneous
- #77 RM-221592 Release dart_codemod 1.2.0
- RM-221592 RELEASE dart_codemod 1.2.0
Notes created on Monday, December 18 05:58 PM UTC
Release notes
Open source →- Add
PackageContextForTesttopackage:codemod/test.dartto help test suggestors that require a fully resolved AST from the analyzer (for example: suggestors using theAstVisitingSuggestormixin withshouldResolveAstenabled).
- #74 FEDX-522 Add APIs to help test suggestors with resolved AST
-
1.1.031 Oct 2023Release notes
Open source →Info
Build: https://ci.webfilings.com/build/5138313
Skynet Results: https://wf-skynet-hrd.appspot.com/apps/test/smithy/5138313/latest
Pipeline: No Pipeline
This minor release includes the following changes:Miscellaneous
-
#66 Raise analyzer minimum & unpin meta
-
#67 Pin mockito 5
-
#69 Rollout Analyzer 5
-
#72 Dart 2.19
-
#73 RM-161448 Release dart_codemod 1.1.0 with Dart 3 support
- RM-161448 RELEASE dart_codemod 1.1.0
Notes created on Tuesday, October 31 06:07 PM UTC
-
-
1.0.1122 Sep 2022Release notes
Open source →Info
Build: https://ci.webfilings.com/build/3932548
Skynet Results: https://wf-skynet-hrd.appspot.com/apps/test/smithy/3932548/latest
Pipeline: No Pipeline
This patch release includes the following changes:Miscellaneous
-
#64 Analyzer v3, v4, and v5
-
#65 RM-161063 Release dart_codemod 1.0.11
- RM-161063 RELEASE dart_codemod 1.0.11
Notes created on Thursday, September 22 10:39 PM UTC
-
-
1.0.1020 Sep 2022Release notes
Open source →Info
Build: https://ci.webfilings.com/build/3924638
Skynet Results: https://wf-skynet-hrd.appspot.com/apps/test/smithy/3924638/latest
Pipeline: No Pipeline
This patch release includes the following changes:Miscellaneous
- #62 FEA-661: Update to analyer v2
- FEA-661 Update to analyer v2
- #63 RM-157378 Release dart_codemod 1.0.10
- RM-157378 RELEASE dart_codemod 1.0.10
Notes created on Tuesday, September 20 08:57 PM UTC
- #62 FEA-661: Update to analyer v2
-
1.0.229 Sep 2021 -
1.0.109 Jun 2021 -
1.0.027 Apr 2021Release notes
Open source →- Null-safety release.
AstVisitingSuggestor.contextwill throw aStateErrorif accessed outside one of the visitor methods.
-
0.3.108 Apr 2021 -
0.3.016 Mar 2021Release notes
Open source →-
Breaking:
runInteractiveCodemodandrunInteractiveCodemodSequenceare both now async. -
Breaking:
Suggestoris now a function typedef instead of a class. Addtionally, it takes the newFileContexttype as its only parameter (previously thegeneratePatchesmethod took aSourceFile) and now must return aStream<Patch>instead ofIterable<Patch>.If you were extending
Suggestor, you can either change the class to a function like so:final String licenseHeader = '...'; - class LicenseHeaderInserter implements Suggestor { - @override - bool shouldSkip(String sourceFileContents) => - sourceFileContents.trimLeft().startsWith(licenseHeader); - - @override - Iterable<Patch> generatePatches(SourceFile sourceFile) sync* { - yield Patch(sourceFile, sourceFile.span(0, 0), licenseHeader); - } - } + Stream<Patch> licenseHeaderInserter(FileContext context) async* { + // Skip if license header already exists. + if (context.sourceText.trimLeft().startsWith(licenseHeader)) return; + + yield Patch(licenseHeader, 0, 0); + }Or rename the
generatePatches()method tocall()so that the class is callable like a function:final String licenseHeader = '...'; - class LicenseHeaderInserter implements Suggestor { + class LicenseHeaderInserter { - @override bool shouldSkip(String sourceFileContents) => sourceFileContents.trimLeft().startsWith(licenseHeader); - @override - Iterable<Patch> generatePatches(SourceFile sourceFile) sync* { + Stream<Patch> call(FileContext context) async* { + if (shouldSkip(context.sourceText)) return; - yield Patch(sourceFile, sourceFile.span(0, 0), licenseHeader); + yield Patch(licenseHeader, 0, 0); } } -
Breaking: Simplify the
Patchclass to now only encapsulate the updated text, start offset, and end offset.- yield Patch(sourceFile, sourceFile.span(5, 10), 'updated text'); + yield Patch('updated text', 5, 10); -
Breaking: Rename
AstVisitingSuggestorMixintoAstVisitingSuggestorsince theMixinsuffix was redundant. -
Breaking: Remove
AggregateSuggestorclass in favor of anaggregate(Iterable<Suggestor> suggestors)function. -
Breaking: Move
applyPatchesfrom the mainpackage:codemod/codemod.dartentrypoint to the newpackage:codemod/test.dartentrypoint to make its intended usage clear. -
Add a
shouldResolveAst(FileContext context)method toAstVisitingSuggestor. Defaults to false (since resolving is slower), but can be overridden to true if the fully resolved AST is needed.- Add example of such a codemod: see example/is_even_or_odd_suggestor.dart
-
Add
package:codemod/test.dartentrypoint for testing suggestors. This entrypoint exports three functions:-
Future<FileContext> fileContextForTest(String name, String contents) -
void expectSuggestorGeneratesPatches(Suggestor suggestor, FileContext context, dynamic resultMatcher) -
String applyPatches(SourceFile sourceFile, Iterable<Patch> patches)The first two should be sufficient for testing most suggestors.
-
-
Use GitHub Actions for CI (remove Travis CI).
-
-
0.2.006 Apr 2020Release notes
Open source →-
Breaking Change: remove the
FileQueryclass. TherunInteractiveCodemod()function now expects anIterable<File>instead of aFileQuery. This is intended to simplify consumption;package:globcan be used to easily query for the desired files. -
Breaking Change: remove
createPathFilter()- this was used withFileQueryand can be replaced by custom logic now thatrunInteractiveCodemod()accepts anIterable<File>. -
Breaking Change: remove
isDartFile()- usepackage:globinstead to target files with the.dartextension (e.g.Glob('**.dart')). -
Add a
filePathsFromGlob()utility function that takes aGlobinstance and returns the file paths matched by the glob, but filtered to exclude hidden files (e.g. files in.dart_tool/). This is intended to serve the most common use case of running codemods on Dart projects, e.g.:runInteractiveCodemod( filePathsFromGlob(Glob('**.dart', recursive: true)), suggestor);
-
Widen Analyzer dependency range to include
0.39.x. -
Make
Patchoverrideoperator ==andhashCodeso that instances can be compared for equality. If twoPatchinstances target the same span in the same file and have the sameupdatedText, they are considered equal. -
AstVisitingSuggestorMixinnow de-duplicates patches suggested for each source file. This can be useful for recursive and generalizing AST visitors that may end up suggesting duplicate patches in parts of the AST that get handled by multiplevisitmethods. -
Improve the error/help output when overlapping patches are found.
-
-
0.1.519 Aug 2019Release notes
Open source →-
Widen Analyzer dependency range from
^0.37.0to>=0.37.0 <0.39.0. -
Exclude
build/folder when a codemod gets run.
-
-
0.1.410 Jul 2019Release notes
Open source →- Prompts the user to either skip overlapping patches or quit when they are found.
-
0.1.305 Feb 2019Release notes
Open source →-
Codemod authors can now augment the help output and the changes required output via
runInteractiveCodemod()andrunInteractiveCodemodSequence()using the optionaladditionalHelpOutputandchangesRequiredOutputparams.-
If
additionalHelpOutputis given, it will be printed to stderr after the default help output when the codemod is run with the-h|--helpflag. -
If
changesRequiredOutputis given, it will be printed to stderr after the default output when the codemod is run with the--fail-on-changesflag and changes are in fact required.
-
-
-
0.1.223 Jan 2019Release notes
Open source →-
Fix a typing issue with the
AggregateSuggestor's constructor param. -
Add tests for
AggregateSuggestorandAstVisitingSuggestorMixin
-
-
0.1.116 Jan 2019