-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[go_router_builder] Removes path_to_regexp
from the dependencies
#4524
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
[go_router_builder] Removes path_to_regexp
from the dependencies
#4524
Conversation
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!). If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'route.dart'; | ||
|
||
final RegExp _parameterRegExp = RegExp(r':(\w+)(\((?:\\.|[^\\()])+\))?'); | ||
|
||
/// Converts a [pattern] such as `/user/:id` into [RegExp]. | ||
/// | ||
/// The path parameters can be specified by prefixing them with `:`. The | ||
/// `parameters` are used for storing path parameter names. | ||
/// | ||
/// | ||
/// For example: | ||
/// | ||
/// `pattern` = `/user/:id/book/:bookId` | ||
/// | ||
/// The `parameters` would contain `['id', 'bookId']` as a result of calling | ||
/// this method. | ||
/// | ||
/// To extract the path parameter values from a [RegExpMatch], pass the | ||
/// [RegExpMatch] into [extractPathParameters] with the `parameters` that are | ||
/// used for generating the [RegExp]. | ||
RegExp patternToRegExp(String pattern, List<String> parameters) { | ||
final StringBuffer buffer = StringBuffer('^'); |
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.
This file in this commit (chore: Copy path_utils.dart from go_router) is a literal copy past from go_router
's path_utils.dart
file https://github.com/flutter/packages/blob/main/packages/go_router/lib/src/path_utils.dart
|
||
/// Extracts arguments from the `match` and maps them by parameter name. | ||
/// | ||
/// The [parameters] should originate from the call to [patternToRegExp] that | ||
/// creates the [RegExp]. | ||
Map<String, String> extractPathParameters( | ||
List<String> parameters, RegExpMatch match) { | ||
return <String, String>{ | ||
for (int i = 0; i < parameters.length; ++i) | ||
parameters[i]: match.namedGroup(parameters[i])! | ||
}; | ||
} | ||
|
||
/// Concatenates two paths. | ||
/// |
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.
In this commit (revamp: Remove unused methods) I'm only deleting methods that are not used
/// `pattern` = `/user/:id/book/:bookId` | ||
/// | ||
/// The `parameters` would contain `['id', 'bookId']` as a result of calling | ||
/// this method. | ||
/// | ||
/// To extract the path parameter values from a [RegExpMatch], pass the | ||
/// [RegExpMatch] into [extractPathParameters] with the `parameters` that are | ||
/// used for generating the [RegExp]. | ||
RegExp patternToRegExp(String pattern, List<String> parameters) { | ||
final StringBuffer buffer = StringBuffer('^'); | ||
int start = 0; | ||
for (final RegExpMatch match in _parameterRegExp.allMatches(pattern)) { | ||
if (match.start > start) { | ||
buffer.write(RegExp.escape(pattern.substring(start, match.start))); | ||
} | ||
final String name = match[1]!; | ||
final String? optionalPattern = match[2]; | ||
final String regex = optionalPattern != null | ||
? _escapeGroup(optionalPattern, name) | ||
: '(?<$name>[^/]+)'; | ||
buffer.write(regex); | ||
parameters.add(name); | ||
start = match.end; | ||
} | ||
|
||
if (start < pattern.length) { | ||
buffer.write(RegExp.escape(pattern.substring(start))); | ||
} | ||
|
||
if (!pattern.endsWith('/')) { | ||
buffer.write(r'(?=/|$)'); | ||
} | ||
return RegExp(buffer.toString(), caseSensitive: false); | ||
} |
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.
In this commit (refactor: Simplify path utils methods to only keep what is used),
I'm only deleting and simplifying patternToRegExp
. We don't need to use the returned RegExp
. So instead I'm returning the parameters
(and I don't need the parameter parameters
anymore)
I believe this PR can have a no-test exemption. This is a revamp and the current tests should cover it already |
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.
can you remove the path_to_regexp in script/configs/allowed_unpinned_deps.yaml, too?
@@ -2,7 +2,7 @@ name: go_router_builder | |||
description: >- | |||
A builder that supports generated strongly-typed route helpers for | |||
package:go_router | |||
version: 2.2.2 | |||
version: 2.3.0 |
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.
There isn't a new feature, should probably update patch version.
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.
Sure, I did it in chore: Only update patch version
I removed it in ci: Remove path_to_regexp from allowed unpinned deps |
It looks like the branch is outdated so the ci.yaml failed. can you rebase off latest main? |
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.
LGTM
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.
LGTM, thanks!
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.
LGTM
it's probably worth throwing in a few unit tests for the functions in packages/go_router_builder/lib/src/path_utils.dart, just so that the next person to refactor them can be confident they didn't break anything subtle about that code. |
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.
As @Hixie stated, please add some tests and re-request my review once done
…emove-path-to-regexp-from-dependencies-2
I added some unit tests in tests: Add path_utils unit test |
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.
LGTM
flutter/packages@2266a76...8028caf 2023-07-24 [email protected] Roll Flutter from a8c8c55 to d7ed5dc (7 revisions) (flutter/packages#4556) 2023-07-23 [email protected] Roll Flutter from e8b397c to a8c8c55 (11 revisions) (flutter/packages#4552) 2023-07-22 [email protected] Roll Flutter from 9cfbf6b to e8b397c (12 revisions) (flutter/packages#4550) 2023-07-21 [email protected] [ci] Clean up except exclusion list (flutter/packages#4547) 2023-07-21 [email protected] [go_router] Replaces uri related properties in GoRouterState (flutter/packages#4392) 2023-07-21 [email protected] [webview_flutter_wkwebview] Updates pigeon version to `10.1.4` (flutter/packages#4548) 2023-07-21 [email protected] [pigeon] Adds package name to method channel. (flutter/packages#4443) 2023-07-21 [email protected] [ci] Migrate remaing unblocked repo checks to LUCI (flutter/packages#4543) 2023-07-21 [email protected] [go_router] Remove unused dependency (flutter/packages#4545) 2023-07-21 [email protected] Roll Flutter from d07e8ae to 9cfbf6b (58 revisions) (flutter/packages#4544) 2023-07-21 [email protected] Adding myself and Michele to AUTHORS (flutter/packages#4527) 2023-07-21 [email protected] [go_router_builder] Removes `path_to_regexp` from the dependencies (flutter/packages#4524) 2023-07-21 [email protected] [google_maps_flutter_web] Adds options for gesture handling and tilt controls. (flutter/packages#4521) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
flutter/packages@2266a76...8028caf 2023-07-24 [email protected] Roll Flutter from a8c8c55 to d7ed5dc (7 revisions) (flutter/packages#4556) 2023-07-23 [email protected] Roll Flutter from e8b397c to a8c8c55 (11 revisions) (flutter/packages#4552) 2023-07-22 [email protected] Roll Flutter from 9cfbf6b to e8b397c (12 revisions) (flutter/packages#4550) 2023-07-21 [email protected] [ci] Clean up except exclusion list (flutter/packages#4547) 2023-07-21 [email protected] [go_router] Replaces uri related properties in GoRouterState (flutter/packages#4392) 2023-07-21 [email protected] [webview_flutter_wkwebview] Updates pigeon version to `10.1.4` (flutter/packages#4548) 2023-07-21 [email protected] [pigeon] Adds package name to method channel. (flutter/packages#4443) 2023-07-21 [email protected] [ci] Migrate remaing unblocked repo checks to LUCI (flutter/packages#4543) 2023-07-21 [email protected] [go_router] Remove unused dependency (flutter/packages#4545) 2023-07-21 [email protected] Roll Flutter from d07e8ae to 9cfbf6b (58 revisions) (flutter/packages#4544) 2023-07-21 [email protected] Adding myself and Michele to AUTHORS (flutter/packages#4527) 2023-07-21 [email protected] [go_router_builder] Removes `path_to_regexp` from the dependencies (flutter/packages#4524) 2023-07-21 [email protected] [google_maps_flutter_web] Adds options for gesture handling and tilt controls. (flutter/packages#4521) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
flutter/packages@2266a76...8028caf 2023-07-24 [email protected] Roll Flutter from a8c8c55 to d7ed5dc (7 revisions) (flutter/packages#4556) 2023-07-23 [email protected] Roll Flutter from e8b397c to a8c8c55 (11 revisions) (flutter/packages#4552) 2023-07-22 [email protected] Roll Flutter from 9cfbf6b to e8b397c (12 revisions) (flutter/packages#4550) 2023-07-21 [email protected] [ci] Clean up except exclusion list (flutter/packages#4547) 2023-07-21 [email protected] [go_router] Replaces uri related properties in GoRouterState (flutter/packages#4392) 2023-07-21 [email protected] [webview_flutter_wkwebview] Updates pigeon version to `10.1.4` (flutter/packages#4548) 2023-07-21 [email protected] [pigeon] Adds package name to method channel. (flutter/packages#4443) 2023-07-21 [email protected] [ci] Migrate remaing unblocked repo checks to LUCI (flutter/packages#4543) 2023-07-21 [email protected] [go_router] Remove unused dependency (flutter/packages#4545) 2023-07-21 [email protected] Roll Flutter from d07e8ae to 9cfbf6b (58 revisions) (flutter/packages#4544) 2023-07-21 [email protected] Adding myself and Michele to AUTHORS (flutter/packages#4527) 2023-07-21 [email protected] [go_router_builder] Removes `path_to_regexp` from the dependencies (flutter/packages#4524) 2023-07-21 [email protected] [google_maps_flutter_web] Adds options for gesture handling and tilt controls. (flutter/packages#4521) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Fixes flutter/flutter#130817
Relates to flutter/flutter#122713
If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.