Skip to content

Migrate dartdoc_options.dart #2749

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

Merged
merged 12 commits into from
Aug 23, 2021
Merged

Conversation

jcollins-g
Copy link
Contributor

@jcollins-g jcollins-g commented Aug 18, 2021

This one was tricksy because it involves argument parsing and yaml parsing, two areas that are null minefields.

Significant nullability choices:

  • .parent is mostly non-nullable except for a specially defined root node that will throw if you try to access its parent. Makes things easier to read, but the way that trees of options are constructed doesn't quite sit right with me now -- those late declarations hang around too long before being written to. Added a TODO around that as I don't have a good alternative just yet.
  • valueAt is nullable. It's just too hard to try to restrict that given how package:args works and yaml giving us nulls. If we happen to know some values aren't nullable, we can wrap them in the future.
  • operator [] is non-nullable. I think this is the right choice as child nodes in the option tree are defined by the programmer, and we should never be trying to look up an undefined option. Changing this found some bugs, too.

Most everything else follows naturally from these choices and from #2745.

* more specific imports in options

* do not allow autoinitialization

* dartfmt

* parameterize the valueWithContext type

* Use alternative constructors instead of externalizing, didn't realize the autodetect was so widely used

* more subclasses
@google-cla google-cla bot added the cla: yes Google CLA check succeeded. label Aug 18, 2021
@jcollins-g
Copy link
Contributor Author

Also, the tests are not migrated; after running into trouble and reading this, I've decided trying to work around the problem of entry points triggering strong nullability checks by default in tests is too much to be worth it. So we'll just settle for a Test Skitching Development style.

@jcollins-g jcollins-g requested a review from bwilkerson August 18, 2021 23:43
@jcollins-g jcollins-g marked this pull request as ready for review August 18, 2021 23:45
Copy link
Member

@srawlins srawlins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it

var categoryMap = entry.value;
if (categoryMap is Map) {
displayName = categoryMap['displayName']?.toString();
documentationMarkdown = categoryMap['markdown']?.toString();
var displayName = categoryMap['displayName']?.toString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha easy win

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, my early Dart code was a little cringey, I'm happy to give it a touch up as part of this migration :-)

ToolRunner _runner;

ToolRunner get runner => _runner ??= ToolRunner(this);
late ToolRunner runner = ToolRunner(this);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slick

pathContext = p.Context(current: canonicalDirectoryPath);
}
_OptionValueWithContext(this.value, String path, {this.definingFile})
: canonicalDirectoryPath = p.canonicalize(path),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 nice refactor

var value = valueWithContext.value;
if (value is String) {
resolvedPaths = [valueWithContext.resolvedValue as String];
} else if (value is List<String>) {
resolvedPaths = valueWithContext.resolvedValue as List<String>;
} else if (value is Map<String, String>) {
resolvedPaths = (valueWithContext.resolvedValue as Map).values.toList();
resolvedPaths = (valueWithContext.resolvedValue as Map).values.toList()
as List<String>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if a spread formats nicer? Something like

resolvedPaths = [
    ...(valueWithContext.resolvedValue as Map).values,
]

Not sure if there is a type error there, or if it actually would format nicer...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, spread format is win here, good call

DartdocOptionRoot(String name, ResourceProvider resourceProvider)
: super(name, resourceProvider);

late final ArgParser __argParser =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the double underscore a pattern from before the null safety migration, or new?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's from before. I wrote this when I was still trying to write Python in Dart. I can change.

@srawlins
Copy link
Member

Quick question Big question: have you benchmarked along the null safety migration?

I'd be curious to know if the time-to-document Flutter has changed (I doubt it would), and more curious to know if the lazy initialization changes perhaps lead to different max memory usage. I think I doubt this too because theoretically the late final laziness is exactly the same as the explicit memoization laziness, but in practice...

@jcollins-g
Copy link
Contributor Author

I haven't benchmarked it yet; was planning to though when the NNBD migration is a little closer

@jcollins-g jcollins-g merged commit bcc0043 into dart-lang:nnbd Aug 23, 2021
@jcollins-g jcollins-g deleted the nnbd-ddoptions branch August 23, 2021 21:46
srawlins added a commit that referenced this pull request Jan 12, 2022
* Start the NNBD migration branch with additional github configuration and a basic "non-migration" of all libraries (#2739)

* Update analyzer version to 2.0.0

* grind build for analyzer 2

* First steps toward migrating

* Basic migration infrastruture for new NNBD branch

* use separate workflow file for nnbd branch, for clarity

* thinko

* Merge master into nnbd branch (#2747)

* Switch to using CompilationUnitElement.classes (#2743)

* Prepare dartdoc_options for migration (#2745)

* more specific imports in options

* do not allow autoinitialization

* dartfmt

* parameterize the valueWithContext type

* Use alternative constructors instead of externalizing, didn't realize the autodetect was so widely used

* more subclasses

* Empty commit to straighten out GitHub Actions

* Convert options/logging libraries to null safety (#2748)

* Update analyzer version to 2.0.0

* grind build for analyzer 2

* First steps toward migrating

* Start migrating some things around the edges and see what happens

* Basic migration infrastruture for new NNBD branch

* use separate workflow file for nnbd branch, for clarity

* thinko

* Switch to using CompilationUnitElement.classes (#2743)

* Ignore null safe import warnings for presubmits

* Prepare dartdoc_options for migration (#2745)

* more specific imports in options

* do not allow autoinitialization

* dartfmt

* parameterize the valueWithContext type

* Use alternative constructors instead of externalizing, didn't realize the autodetect was so widely used

* more subclasses

* Empty commit to straighten out GitHub Actions

* dartfmt

* update NNBD branch from head (#2758)

* Switch to using CompilationUnitElement.classes (#2743)

* Prepare dartdoc_options for migration (#2745)

* more specific imports in options

* do not allow autoinitialization

* dartfmt

* parameterize the valueWithContext type

* Use alternative constructors instead of externalizing, didn't realize the autodetect was so widely used

* more subclasses

* Disable the unstable template checks and prepare for 2.14 stable. (#2752)

* Disable one of the template checks?  and add beta branch for testing

* beta is the new stable

* empty commit - force check reset

* Add a blurb to the README about requiring analysis (#2753)

* Allow comment references on generic typedefs (#2756)

Co-authored-by: Janice Collins <[email protected]>

* Prepare for dartdoc 2.0.0 (#2754)

* Prepare for dartdoc 2.0.0

* Update changelog for additional bugfix

Co-authored-by: Simon Binder <[email protected]>

* Migrate dartdoc_options.dart (#2749)

* Switch to using CompilationUnitElement.classes (#2743)

* Prepare dartdoc_options for migration (#2745)

* more specific imports in options

* do not allow autoinitialization

* dartfmt

* parameterize the valueWithContext type

* Use alternative constructors instead of externalizing, didn't realize the autodetect was so widely used

* more subclasses

* flatten

* Disable the unstable template checks and prepare for 2.14 stable. (#2752)

* Disable one of the template checks?  and add beta branch for testing

* beta is the new stable

* empty commit - force check reset

* Add a blurb to the README about requiring analysis (#2753)

* Allow comment references on generic typedefs (#2756)

Co-authored-by: Janice Collins <[email protected]>

* Prepare for dartdoc 2.0.0 (#2754)

* Prepare for dartdoc 2.0.0

* Update changelog for additional bugfix

* review comments

Co-authored-by: Simon Binder <[email protected]>

* Migrate package_meta, io_utils, and utils. (#2760)

* flatten

* Review comments

* opt-out for inheriting container

* A few more libraries migrated

* Migrate warnings.dart (#2787)

* Migrate mustachio to null safety (#2801)

* Migrate various util and small libraries (#2805)

* Migrate tool_runner to NNBD (#2804)

* Migrate tool runner

* dartfmt

* getAs -> getValueAs

* comment

* Migrate the renderers to NNBD (#2816)

* Migrate renderers

* dartfmt

* Migrate most mustachio tests to null safety (#2810)

* Merge main branch to NNBD (#2826)

* Refactor more documentation comment generation into DocumentationComment (#2817)

* Straight move

* Partial

* delete experiment

* rebuild

* remove ??= from a cut and paste

* Continuing the crushing down of documentation handling (#2818)

* Straight move

* Partial

* delete experiment

* rebuild

* moved computeDocumentationComment and documentationComment

* Move more documentation comment handling

* remove ??= from a cut and paste

* Documentation comment move for combos

* better as a getter

* Remove all deprecated bits in preparation for next release (#2821)

* Remove all deprecated bits in preparation for next release

* make some things final

* documentationComment can now be non-nullable (#2819)

* Straight move

* Partial

* delete experiment

* rebuild

* moved computeDocumentationComment and documentationComment

* Move more documentation comment handling

* remove ??= from a cut and paste

* Documentation comment move for combos

* better as a getter

* Untangle synthetic combo documentation in preparing for non-null

* rebuild

* documentationComment can be made non-nullable

* Update test.yaml to delete sdk check from beta branch

* tab conversion error

* correct name

* Stop testing beta in the bots (#2824)

* disable beta

* try switching on stable

* stable doesn't work for a lot of things now either :-(

* try enabling the main bot

* Change "dartfmt" -> "dart format". (#2822)

Co-authored-by: Janice Collins <[email protected]>

Co-authored-by: Bob Nystrom <[email protected]>

* Migrate more libraries to NNBD (#2827)

* migrate category

* Migrate model_comment_reference and the parser

* Fix test failure

* Migrate comment_referable and model_object_builder (#2832)

* squash

* fix error in filter setup

* fix test

* Migrate element_type to nnbd (#2834)

* Migrate markdown_processor and matching_link_result to NNBD (#2835)

* Migrate element_type to nnbd

* Migrate markdown_processor and matching_link_result

* Migrate most of lib/src/generators to nnbd (#2837)

* squash

* empty commit - reset actions

* Migrate most of the non-ModelElement bits of lib (#2838)

* squash

* rebuild

* Fixup hints

* Migrate most of what's left in tools/ (#2840)

* squash

* rebuild

* migrate more things

* subprocess

* type adjustment in grinder

* comments

* Canonicalize default input dir

* Revert "Canonicalize default input dir"

This reverts commit 5d76a51.

* Just disable the test, something odd is going on with MemoryResourceProvider.

* Migrate ModelElement and subclasses to NNBD (#2843)

* squash

* rebuild

* migrate more things

* subprocess

* type adjustment in grinder

* partial

* partial 2

* no errors, ship it

* clean up a lot of warnings

* All warnings done so really ship it

* dartfmt

* close

* manual changes on renderers

* comments

* partial

* fix some errors post-migration

* holy cow it passes the tests now

* make mustache happier and clean up an interface

* forgot to remove a fixme

* Work around strange super-not-allowed error in stable

* review comments

* Migrate runtime renderer to NNBD (#2849)

* squash from chain merges

* Things seem to work now, if not completely cleanly.

* Get runtime_renderer_render_test ready for NNBD strong mode, fix a few more problems

* deconfuse github

* add todo

* Update nnbd branch for latest changes and new resources-dir option (#2867)

* Stop using JavaFile. (#2856)

* Add a resources-dir option (#2857)

* Skip sdk-analyzer job (#2863)

* Use 'index' to access the enum value index. (#2865)

Co-authored-by: Sam Rawlins <[email protected]>

* Re-enable sdk-analyzer job, but make it not failing (#2864)

* Update new resources-dir option for null safety

* Fix html generator test merge

Co-authored-by: Konstantin Scheglov <[email protected]>
Co-authored-by: Sam Rawlins <[email protected]>

* Utilize new Object.hash function instead of quiver code (#2868)

* Minor cleanup to lints and some top level files (#2872)

* Cleanup categorization to simplify template generation migration (#2875)

* Cleanup model_element migration and surrounding accesses (#2876)

* Migrate the generated AOT renderers to null safety (#2874)

* Cleanup package_graph migration (#2869)

* Migrate several test files to null safety (#2871)

* Migrate comment_referable tests (#2877)

* Migrate tool/grind.dart to null safety (#2870)

* Migrate more tests; correct other migration bits (#2880)

* Correct some bad mustachio migration; migrate mustachio tests (#2879)

* Migrate the testing/ packages (#2881)

* Migrate most end2end tests; null safety tweaks (#2882)

* Make a few more nullable fields late final (#2883)

* Migrate model_test, the last file, to null safety (#2884)

* Merge master branch into nnbd branch (#2885)

* Stop using JavaFile. (#2856)

* Add a resources-dir option (#2857)

* Skip sdk-analyzer job (#2863)

* Use 'index' to access the enum value index. (#2865)

Co-authored-by: Sam Rawlins <[email protected]>

* Re-enable sdk-analyzer job, but make it not failing (#2864)

Co-authored-by: Konstantin Scheglov <[email protected]>

Co-authored-by: Janice Collins <[email protected]>
Co-authored-by: Simon Binder <[email protected]>
Co-authored-by: Bob Nystrom <[email protected]>
Co-authored-by: Parker Lougheed <[email protected]>
Co-authored-by: Konstantin Scheglov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Google CLA check succeeded.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants