-
Notifications
You must be signed in to change notification settings - Fork 138
refactor: avoid http_methods dependency #514
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
base: master
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -14,7 +14,6 @@ environment: | |
| sdk: ^3.3.0 | ||
|
|
||
| dependencies: | ||
| http_methods: ^1.1.0 | ||
| meta: ^1.3.0 | ||
| shelf: ^1.0.0 | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,13 +22,30 @@ import 'package:analyzer/dart/element/element.dart' | |
| import 'package:analyzer/dart/element/type.dart' show ParameterizedType; | ||
| import 'package:build/build.dart' show BuildStep, log; | ||
| import 'package:code_builder/code_builder.dart' as code; | ||
| import 'package:http_methods/http_methods.dart' show isHttpMethod; | ||
| import 'package:shelf/shelf.dart' as shelf; | ||
| import 'package:shelf_router/shelf_router.dart' as shelf_router; | ||
| import 'package:shelf_router/src/router_entry.dart' // ignore: implementation_imports | ||
| show RouterEntry; | ||
| import 'package:source_gen/source_gen.dart' as g; | ||
|
|
||
| /// Returns true if [method] is a valid HTTP method. | ||
| bool isHttpMethod(String method) { | ||
| switch (method.toUpperCase()) { | ||
| case 'GET': | ||
| case 'HEAD': | ||
| case 'POST': | ||
| case 'PUT': | ||
| case 'DELETE': | ||
| case 'CONNECT': | ||
| case 'OPTIONS': | ||
| case 'TRACE': | ||
| case 'PATCH': | ||
| return true; | ||
| default: | ||
| return false; | ||
| } | ||
| } | ||
|
Comment on lines
+31
to
+47
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. To avoid code duplication, you should import the You can remove this function and add the following import at the top of the file: import 'package:shelf_router/src/router.dart' show isHttpMethod; // ignore: implementation_importsThis follows the existing pattern in this file of importing from |
||
|
|
||
| // Type checkers that we need later | ||
| const _routeType = g.TypeChecker.typeNamed( | ||
| shelf_router.Route, | ||
|
|
||
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.
For better readability and maintainability, you could use a
Setof HTTP methods for this check. Using aconstset is efficient and makes the collection of valid methods explicit and easier to manage.