-
Notifications
You must be signed in to change notification settings - Fork 7
Quick fix experiment #254
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
Draft
alanknight-wk
wants to merge
6
commits into
master
Choose a base branch
from
quick_fix_experiment
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Quick fix experiment #254
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ca7ddc9
Experiment at a fast codemod executable invokeable from IDE extensions
alanknight-wk 4036cc7
include the files
alanknight-wk f207280
A simple single-string migrator
alanknight-wk db79a2f
Minimal tests
alanknight-wk 5aca263
Pass the character offset
alanknight-wk aec1a08
Merge branch 'master' into quick_fix_experiment
alanknight-wk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // Copyright 2021 Workiva Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| export 'package:over_react_codemod/src/executables/intl_quick_migration.dart'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| // Copyright 2021 Workiva Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| import 'dart:io'; | ||
|
|
||
| import 'package:args/args.dart'; | ||
| import 'package:codemod/codemod.dart'; | ||
| import 'package:file/file.dart'; | ||
| import 'package:file/local.dart'; | ||
| import 'package:over_react_codemod/src/intl_suggestors/intl_messages.dart'; | ||
| import 'package:over_react_codemod/src/intl_suggestors/intl_migrator.dart'; | ||
| import 'package:path/path.dart' as p; | ||
|
|
||
| typedef Migrator = Stream<Patch> Function(FileContext); | ||
|
|
||
| final FileSystem fs = const LocalFileSystem(); | ||
|
|
||
| final parser = ArgParser() | ||
| ..addFlag( | ||
| 'help', | ||
| abbr: 'h', | ||
| negatable: false, | ||
| help: 'Prints this help output.', | ||
| ) | ||
| ..addFlag( | ||
| 'verbose', | ||
| abbr: 'v', | ||
| negatable: false, | ||
| help: 'Outputs all logging to stdout/stderr.', | ||
| ); | ||
|
|
||
| late ArgResults parsedArgs; | ||
|
|
||
| void main(List<String> args) async { | ||
| parsedArgs = parser.parse(args); | ||
| if (parsedArgs['help'] as bool) { | ||
| printUsage(); | ||
| return; | ||
| } | ||
|
|
||
| if (parsedArgs.rest.isEmpty) { | ||
| print('You have to specify a file'); | ||
| exit(1); | ||
| } | ||
| var intlPath = p.canonicalize(p.absolute((parsedArgs.rest.first))); | ||
|
|
||
| await migratePackage(fs.currentDirectory.path, intlPath); | ||
| } | ||
|
|
||
| void printUsage() { | ||
| stderr.writeln('Migrates a particular string to an intl message.'); | ||
| stderr.writeln(); | ||
| stderr.writeln('Usage:'); | ||
| stderr.writeln(' intl_quick [arguments]'); | ||
| stderr.writeln(); | ||
| stderr.writeln('Options:'); | ||
| stderr.writeln(parser.usage); | ||
| } | ||
|
|
||
| /// Migrate files included in [paths] within [packagePath]. | ||
| /// | ||
| /// We expect [paths] to be absolute. | ||
| Future<void> migratePackage(String packagePath, String path) async { | ||
| final packageName = p.basename(packagePath); | ||
|
|
||
| final IntlMessages messages = IntlMessages(packageName, | ||
| directory: fs.currentDirectory, packagePath: packagePath); | ||
|
|
||
| exitCode = await runMigrators([path], [], messages, packageName); | ||
|
|
||
| messages.write(force: false); | ||
| // This will leave the intl.dart file unformatted, but that takes too long, so we'll just leave it out. | ||
| } | ||
|
|
||
| Future<int> runMigrators(List<String> packageDartPaths, | ||
| List<String> codemodArgs, IntlMessages messages, String packageName) async { | ||
| // final intlPropMigrator = IntlMigrator(messages.className, messages); | ||
| final constantStringMigrator = | ||
| ConstantStringMigrator(messages.className, messages); | ||
| // final importMigrator = (FileContext context) => | ||
| // intlImporter(context, packageName, messages.className); | ||
|
|
||
| // List<List<Migrator>> migrators = [ | ||
| // [intlPropMigrator], | ||
| // [constantStringMigrator], | ||
| // [importMigrator], | ||
| // ]; | ||
|
|
||
| var result = await runInteractiveCodemod( | ||
| packageDartPaths, constantStringMigrator, | ||
| defaultYes: true); | ||
| return result; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should probably run the importer too, so unwind the change to run only a single migrator. But we shouldn't (I think) need the change that runs them all sequentially. Or we could let the IDE Extension still do the import.