Skip to content
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

Implement .rcompare() method #30

Merged
merged 2 commits into from
Aug 4, 2017
Merged

Conversation

LucianBuzzo
Copy link
Contributor

Connects to #24

change-type: minor

@LucianBuzzo LucianBuzzo self-assigned this Aug 1, 2017
src/index.ts Outdated
* @returns {number} Returns `0` if `versionA == versionB`,
* or `-1` if `versionA` is greater, or `1` if `versionB` is greater.
* null values are always weighted above string values, and string values are always
* weighted above valid semver values.
Copy link

Choose a reason for hiding this comment

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

You've flipped the order of this description (B > A, instead of A > B), and also the ordering of these comparisons (null > string, instead of string > null). I think that makes this 2nd sentence here wrong, as it's kind of become a double negative.

In practice, rcompare(null, 'a string') and rcompare('a string', '1.2.3') return 1, and this description says the opposite.

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'll tidy up the description here and on the compare method

src/index.ts Outdated
*
* resinSemver.compare('Resin OS 2.0.0+rev4 (prod)', 'Resin OS 1.16.0'); //--> 1
*
* resinSemver.compare('Resin OS 1.16.0', 'Resin OS 1.16.0'); //--> 0
Copy link

Choose a reason for hiding this comment

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

These examples should all be rcompare, not compare.

src/index.ts Outdated
*
* resinSemver.compare('Resin OS 1.16.0', 'Resin OS 2.0.0+rev4 (prod)'); //--> -1
*
* resinSemver.compare('Resin OS 2.0.0+rev4 (prod)', 'Resin OS 1.16.0'); //--> 1
Copy link

Choose a reason for hiding this comment

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

You've flipped the result of the three examples above correctly, but they've got the wrong results, I think? Looks like that's because they're wrong in compare too.

I dream of a world in which python's doctest is standard in every other language, but until then, we're going to have to endless manually sanity check example docs like this 😭. If you've got a brilliant idea for including the tests as examples in here though, I'd love to hear it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pimterry I did some experimentation and I'm able to programmatically get output like this https://github.com/resin-io-modules/resin-semver/blob/docs-test/test.md
Ideally, I'd like to prettify the output more, but I think this is a good start. What do you think?

Copy link

Choose a reason for hiding this comment

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

Haha, that is awesome. Yes, output like that would be amazing, and lets us skip this manual example writing entirely.

This is extremely cool. I can't overstate how cool this is. I'd love it for the SDK, and I'm sure we could come up with all sorts of other places in future too across the whole of Resin, we've got loads of docs like this that are messy and easily get inaccurate. Good encouragement for us to get useful tests in place too. Even outside Resin, I expect we could make an exciting visible open-source project from it that other people would want to use. I'm super into this.

Not sure if it's useful, but one thing that might help make the code for this a little simpler would be to hook it into the actual testing process, with a mocha reporter, rather than having to run TS and find the test file(s) yourself. There's already a built-in mocha reporter that outputs markdown with the results and body of all the tests run, which might help here: https://github.com/mochajs/mocha/blob/master/lib/reporters/markdown.js#L86-L92.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oooh yep the markdown reporter is a revelation!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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've merged the auto generated example into this branch and I'll look into separating the code into a standalone module in the future

Copy link

@pimterry pimterry left a comment

Choose a reason for hiding this comment

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

Oops, sorry, wrong button 😄

src/index.ts Outdated
* resinSemver.compare('Resin OS 1.16.0', 'Resin OS 1.16.0'); //--> 0
*/
export const rcompare = (versionA: string | null, versionB: string | null): number => {
return 0 - compare(versionA, versionB);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't want to sound silly, but why aren't we using the unary - operator?

Copy link

Choose a reason for hiding this comment

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

I assumed it's just a clarity/style thing - I'm fine with either one, whatever everybody else prefers

Connects to #24

JSDoc examples are now automatically generated using the mocha markdown reporter

change-type: minor
Copy link

@pimterry pimterry left a comment

Choose a reason for hiding this comment

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

This makes me deliriously happy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants