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
Apply Clippy Suggestions #81
Conversation
Satisfies: ```shell cargo clippy -- \ -W clippy::pedantic \ -A clippy::used_underscore_binding \ -A clippy::missing_errors_doc \ -A clippy::too_many_lines ```
One could also think of adding the Clippy command to the github action in order to enforce consistent style for the project. |
Satisfies: ```shell cargo clippy -- \ -W clippy::pedantic \ -A clippy::used_underscore_binding \ -A clippy::missing_errors_doc ``` Introduce a pattern where alongside `consume` a new function `try_from_attributes` is implemented for components (`Gpx` and `Waypoint` so far). This shortens the usually very long `consume` and gives the reader a clear distinction about the two parsing phases.
Satisfies: ```shell cargo clippy -- \ -W clippy::pedantic \ -A clippy::used_underscore_binding ```
7cbf03c
to
26db030
Compare
Honestly, I'm not that big of a fan with the default set of warnings, not to mention We can merge these ones, but I didn't have a chance to look over them yet. |
Regarding |
Okay, I see. One counter argument is that, at least for me, it is confusing to see a lot of warnings on a fresh clone and it's easy to overlook which of them one added over the course of development.
What alternative do you suggest? |
Please stop using
|
…and `Link` Satisfies: ```shell cargo clippy -- \ -W clippy::pedantic ```
I agree but it makes the linter happy ¯\_(ツ)_/¯. How about |
Nah, let's go with |
You'd wonder what people have tried 😄 |
GpxVersion::Gpx10 => Ok("http://www.topografix.com/GPX/1/0"), | ||
GpxVersion::Gpx11 => Ok("http://www.topografix.com/GPX/1/1"), | ||
version => Err(GpxError::UnknownVersionError(version)), | ||
GpxVersion::Gpx10 => Ok("https://www.topografix.com/GPX/1/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.
Let's not do this, that URL identifies the schema, and it's not meant to be browsed. See the targetNamespace
in https://www.topografix.com/GPX/1/1/gpx.xsd.
} else { | ||
break; | ||
} | ||
let next_event = match context.reader.peek() { |
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.
I like this (nested matching in next_event
), but the try_from_attributes
just looks like a not very successful attempt to shrink the function.
Not strongly against it, but it feels a bit pointless.
} else { | ||
break; | ||
} | ||
let next_event = match context.reader.peek() { |
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.
Same as in the other file.
@@ -44,23 +43,24 @@ pub fn consume<R: Read>(context: &mut Context<R>, tagname: &'static str) -> GpxR | |||
if !(-180.0..180.0).contains(&longitude) { | |||
return Err(GpxError::LonLatOutOfBoundsError( | |||
"Longitude", | |||
"[-180.0, 180.0", | |||
"[-180.0, 180.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.
👍
/// | ||
/// # Errors | ||
/// | ||
/// Propagates errors from [consume](crate::parser::gpx::consume). |
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.
I'd drop these or phrase them differently, consume
isn't even a public function.
@@ -6,6 +6,9 @@ | |||
fix error handling bug on track parsing, | |||
apply Clippy suggestion | |||
- [#80](https://github.com/georust/gpx/pull/72): Update MSRV to 1.57.0 | |||
- [#81](https://github.com/georust/gpx/pull/81): Rename the field `_type` to `type_` for `Route`, `Track`, `Waypoint` |
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.
I'd simply say
Rename
Route::_type
,Track::_type
,Waypoint::_type
,Link::_type
totype_
.
The reasoning can be found in the PR anyway.
@0b11001111 bist du noch da? 😄 |
Yes, just being busy these days :P I'll come back on this by next weekend, hopefully ;) |
Closing for inactivity. Please file another PR if you decide to come back to this, or maybe one for each lint. |
CHANGELOG.md
if knowledge of this change could be valuable to users.Hey folks, I had to burn some spare time and ran
clippy -- -W clippy::pedantic
against the project.I applied most of the suggestions and now running
clippy -- -W clippy::pedantic -A clippy::used_underscore_binding
passes.The
clippy::used_underscore_binding
rule still fails because ofWaypoint::_type
.Renaming it would break the API, hence I did not do that.
I suggest to rename the field in some future release to something that aligns with Rust's naming convention ;)
Additionally, I refactored the
consume
functions in the parser modules as some of the were super long.If applicable, I introduced a private
try_from_attribute
function that is used for component initialization.Since this PR is mostly about cosmetics and doesn't change any semantics (hopefully), I did not put it in the changelog :P