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

Reorder keys #1960

Merged
merged 18 commits into from
Feb 16, 2022
Merged

Reorder keys #1960

merged 18 commits into from
Feb 16, 2022

Conversation

ErikSchierboom
Copy link
Member

@ErikSchierboom ErikSchierboom commented Feb 11, 2022

This PR makes the order of the keys in the canonical-data.json files consistent and adds a CI check to verify its order.
This is just a minor improvement, so if people are not convinced this is useful, I'm happy to not go through with this.

See https://github.com/ErikSchierboom/problem-specifications/runs/5158116886?check_suite_focus=true for an example of the output.

Closes #1705

@ErikSchierboom ErikSchierboom requested a review from a team as a code owner February 11, 2022 15:27

Dir.glob('exercises/*/canonical-data.json').each do |path|
json = JSON.parse(File.read(path))
invalid_tests = find_tests(json).select {|test| (CORRECT_ORDER & test.keys) != test.keys}
Copy link
Member

Choose a reason for hiding this comment

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

Nice


exit_code = 0

Dir.glob('exercises/*/canonical-data.json').each do |path|
Copy link
Member

Choose a reason for hiding this comment

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

You could parallize this :P

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea!

Copy link
Contributor

@SaschaMann SaschaMann left a comment

Choose a reason for hiding this comment

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

Can't read the Ruby script but otherwise this looks good

Copy link
Contributor

@wolf99 wolf99 left a comment

Choose a reason for hiding this comment

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

I don't know about the Ruby, but the resulting JSON looks good.


puts "#{path} has tests with the wrong key order:"
invalid_tests.each do |test|
puts "- Test: #{test['uuid']}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps this should include the description similarly to the mutation-check so that it's easier to find without CTRL F

@ErikSchierboom
Copy link
Member Author

@SaschaMann I've added the description to the output.

How do we want to merge this? As on squashed commit, two commits or many individual commits? My preference would be for the second option, but I'm fine with whatever.

@SaschaMann
Copy link
Contributor

I like it if the resulting changes are bundled with the script, that way it makes it easier to understand what actually changed if you can't read workflows or Ruby files. 1st and 2nd option both seem fine though, the 3rd seems a bit too noisy.

@SleeplessByte
Copy link
Member

I would just squash it.

Copy link
Member

@petertseng petertseng left a comment

Choose a reason for hiding this comment

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

No particular preference between two commits vs one.


exit_code = 0

Dir.glob('exercises/*/canonical-data.json').each do |path|
Copy link
Member

Choose a reason for hiding this comment

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

this has made it so that this can only be run from the root of the problem-specifications repo. If you want to instead make it runnable from anywhere, you should express the path relative from bin.

Suggested change
Dir.glob('exercises/*/canonical-data.json').each do |path|
Dir.glob("#{__dir__}/../exercises/*/canonical-data.json").each do |path|

But, I do not actually expect wanting to run it from anywhere else to be something that is often desired, so I'm Approving (in the GitHub sense of the word) anyway regardless of whether this change is made.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've applied the change, with a minor change to allow the printed path to be slightly clearer

@ErikSchierboom ErikSchierboom merged commit 7a8722a into exercism:main Feb 16, 2022
@ErikSchierboom
Copy link
Member Author

Thanks everyone!

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.

Order of canonical-data keys
6 participants