-
Notifications
You must be signed in to change notification settings - Fork 15
Upgrade to analyzer ^14.0.0 #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,16 @@ the AST. | |
|
|
||
| Inspired by and based on [Facebook's `codemod` library][facebook-codemod]. | ||
|
|
||
| ## Requirements | ||
|
|
||
| - Dart SDK `^3.13.0` | ||
| - [`package:analyzer`][analyzer] `^14.0.0` | ||
|
|
||
| Suggestors that use the analyzer's AST or element APIs should be written | ||
| against analyzer 14. Notably, library names are represented by `DottedName` | ||
| nodes (use `DottedName.tokens`), `LibraryIdentifier` no longer exists, and | ||
| parse/analysis diagnostics expose `diagnosticCode` instead of `errorCode`. | ||
|
|
||
| ## Demo | ||
|
|
||
|  | ||
|
|
@@ -21,10 +31,10 @@ apply code modifications and refactors via an interactive CLI. To that end, | |
| the following function is provided: | ||
|
|
||
| ```dart | ||
| Future<int> runInteractiveCodemod(Iterable<File> files, Suggestor suggestor); | ||
| Future<int> runInteractiveCodemod(Iterable<String> filePaths, Suggestor suggestor); | ||
|
Comment on lines
-24
to
+34
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note to self - this is just aligning the docs with the code; no breaking change was made in this PR. |
||
| ``` | ||
|
|
||
| Calling this will tell codemod run the `suggestor` on each file in `files`. For | ||
| Calling this will tell codemod run the `suggestor` on each file in `filePaths`. For | ||
| each file, the suggestor will return a stream of patches that should be | ||
| suggested to the user. As patches are suggested and accepted by the user, | ||
| codemod handles applying them to the files and writing the result to disk. | ||
|
|
@@ -122,7 +132,8 @@ Consider the following suggestor that removes all deprecated declarations | |
| (i.e. classes, constructors, variables, methods, etc.): | ||
|
|
||
| ```dart | ||
| import 'package:analyzer/analyzer.dart'; | ||
| import 'package:analyzer/dart/ast/ast.dart'; | ||
| import 'package:analyzer/dart/ast/visitor.dart'; | ||
| import 'package:codemod/codemod.dart'; | ||
|
|
||
| class DeprecatedRemover extends GeneralizingAstVisitor<void> | ||
|
|
@@ -326,8 +337,7 @@ Let's use the `DeprecatedRemover` suggestor example from above to demonstrate | |
| testing: | ||
|
|
||
| ```dart | ||
| import 'package:codemod/codemod.dart'; | ||
| import 'package:source_span/source_span.dart'; | ||
| import 'package:codemod/test.dart'; | ||
| import 'package:test/test.dart'; | ||
|
|
||
| void main() { | ||
|
|
@@ -365,8 +375,7 @@ that has access to the whole package and its dependencies. You can then add | |
| source file(s) and use the wrapping `FileContext`s to test suggestors. | ||
|
|
||
| ```dart | ||
| import 'package:codemod/codemod.dart'; | ||
| import 'package:source_span/source_span.dart'; | ||
| import 'package:codemod/test.dart'; | ||
| import 'package:test/test.dart'; | ||
|
|
||
| void main() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -138,7 +138,7 @@ Future<int> runInteractiveCodemodSequence( | |
| } | ||
| return ExitCode.success.code; | ||
| } | ||
| return overrideAnsiOutput<Future<int>>( | ||
| return await overrideAnsiOutput<Future<int>>( | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. had to fix analyzer warnings since it was failing now under newer dart |
||
| stdout.supportsAnsiEscapes, | ||
| () => _runInteractiveCodemod(filePaths, suggestors, parsedArgs, | ||
| defaultYes: defaultYes, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,12 +20,10 @@ import 'package:test/test.dart'; | |
|
|
||
| class MockPatch extends Mock implements Patch {} | ||
|
|
||
| @override | ||
| Stream<Patch> fooSuggestor(_) async* { | ||
| yield FooPatch(); | ||
| } | ||
|
|
||
| @override | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. more analyzer warnings |
||
| Stream<Patch> barSuggestor(_) async* { | ||
| yield BarPatch(); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will follow up with a format-all-the-code PR