Skip to content

[go_router_builder] Adopt code excerpts in README #5698

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

Closed
wants to merge 4 commits into from

Conversation

mike-v2
Copy link
Contributor

@mike-v2 mike-v2 commented Dec 16, 2023

Remove 'Import' section
Updates the README to use a compiled excerpt source for its example of using go_router_builder plugin.

Part of flutter/flutter#102679

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@@ -1,34 +1,5 @@
## Usage

### Dependencies
Copy link
Contributor

Choose a reason for hiding this comment

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

Why remove these parts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Stuart said to remove the "Import" sections from the READMEs.. I assumed that would also apply to Dependencies.

Copy link
Contributor

Choose a reason for hiding this comment

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

installing https://pub.dev/packages/go_router_builder/install page seems to be generic, and does not really work for build_runner.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a separate .yaml file to store the code snippet for the "Dependencies" section since the existing one uses a relative path for go_router_builder. I'm not sure if this was the best way to do it though.

Copy link
Contributor

Choose a reason for hiding this comment

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

installing https://pub.dev/packages/go_router_builder/install page seems to be generic, and does not really work for build_runner.

That's dart-lang/pub-dev#3403, FYI.

Copy link
Contributor

Choose a reason for hiding this comment

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

I added a separate .yaml file to store the code snippet for the "Dependencies" section since the existing one uses a relative path for go_router_builder. I'm not sure if this was the best way to do it though.

This doesn't actually accomplish anything, unfortunatetly, since there's no mechanism by which a random .yaml file would be kept updated. Since we don't have an authoritative source to pull the excerpt from, you can just not except for that block. The tool doesn't enforce excerpts for yaml.

Add comment explaining purpose of readme_excerpts.dart and readme_excerpts.yaml
Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

Looks good to me other than some small comments, thanks! I'll leave final approval to @chunhtai since there are some changes to the example code, and I'm not familiar enough with this codebase to know how important they are to the understandability.

```dart
import 'package:go_router/go_router.dart';

part 'this_file.g.dart';
part 'readme_excerpts.g.dart';
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: this naming is just a convention for our convenience since it usually doesn't matter, but having it in the readme with this name seems potentially confusing to package clients. How about we call the file something like example_builder_output.g.dart?

path: 'family/:familyId',
)
path: 'family/:fid',
// ···
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's include the closing ) here, even though it'll mean an extra plaster. Same for similar cases later in the file; it's just less confusing if we don't have unbalanced ([{s.

@TypedGoRoute<LoginRoute>(path: '/login')
class LoginRoute extends GoRouteData {...}
@TypedGoRoute<LoginRoute>(
path: '/login',
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Seems like we could remove the trailing comma in the source here?

```dart
void _tap() => PersonRoute(fid: 'f2', pid: 'p1').go(context);
onTap: () => PersonRoute(family.id, p.id).go(context),
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not familiar with the go_router code; are there both named and positional versions of the constructors? I see one below that still have the pid:.

If so, it seems like we should be using the named versions, as they are safer?

Copy link
Contributor

Choose a reason for hiding this comment

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

we should probably shows the same version in both code excerpt.

@mike-v2 can you update the code sample?

Copy link
Contributor

Choose a reason for hiding this comment

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

This file can be removed, per my other comment.

Rename 'readme_excerpts' generated file
Fix formatting errors
```dart
void _tap() => PersonRoute(fid: 'f2', pid: 'p1').go(context);
onTap: () => PersonRoute(family.id, p.id).go(context),
Copy link
Contributor

Choose a reason for hiding this comment

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

we should probably shows the same version in both code excerpt.

@mike-v2 can you update the code sample?

// #docregion Import
import 'package:go_router/go_router.dart';

part 'example_builder_output.g.dart';
Copy link
Contributor

Choose a reason for hiding this comment

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

why we use different name for the generated file?

@chunhtai
Copy link
Contributor

Hi @mike-v2 are you still working on this pr?

@chunhtai
Copy link
Contributor

chunhtai commented May 2, 2024

Closing this one for now. Feel free to reopen when you have time

@chunhtai chunhtai closed this May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants