-
-
Notifications
You must be signed in to change notification settings - Fork 550
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
Format using prettier #1917
Format using prettier #1917
Conversation
@@ -153,7 +153,7 @@ | |||
"digits": [0], | |||
"outputBase": 10 | |||
}, | |||
"expected": {"error": "input base must be >= 2"} | |||
"expected": { "error": "input base must be >= 2" } |
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.
Seems like prettier is a lot less opinionated about JSON than jq. That's good for arrays, but bad for cases like this where it would be nice to have fields (error
in this case) on their own lines.
Does prettier have any options to force this ?
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 don't think so. Prettier has (purposefully) few options: https://prettier.io/docs/en/options.html
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 feel like array formatting should just be left to humans since neither tool seems to do a good job when formatting this kind of human-readable data.
Perhaps #1705 should also be considered when choosing a formatter since there was agreement on an order. It would be nice if the tool could also sort the data according to the spec. |
The funny thing is that I started working on that and have a working jq script to re-order fields. That script though, re-formatted a bunch of files in the process, which is why I started looking into the formatting of the files.
Yes, I agree. I think the end conclusion is that we can do a one-time pass for consistent formatting, but with manual tweaks of the results. |
7fbc4ad
to
a08f3c8
Compare
I've manually tweaked the formatting. |
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 don't like the error change but that's personal preference; I don't have any real objections against it. I think for everything else, this is a lot better than what either tool produced without the manual tweaks.
I don't massively care either way, but I thought people would like this better 🤷 If someone else wants to chip in, I'm happy to change |
"description": "all strikes is a perfect game", | ||
"property": "score", | ||
"input": { | ||
"previousRolls": [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10] |
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 bowling
, is there some rule I can use to understand when the elements of previousRolls
are (or should be) on the same line as the [
and ]
versus when they are on different lines?
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. I've made them consistent.
@@ -15,7 +15,20 @@ | |||
"input": { | |||
"tonic": "C" | |||
}, | |||
"expected": [ "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" ] | |||
"expected": [ |
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 can't come up with a rule for why the chromatic scale starting at C should be on separate lines but F should be on one line. They have the same number of notes and the same sum of string lengths. What is the rule?
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.
Fixed
"wordsToSearchFor": [ | ||
"clojure" | ||
] | ||
"grid": ["jefblpepre", "tclojurerm"], |
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.
although putting them on one line is fine because this case doesn't ask to search for a word vertically, I'm kind of thinking that tracks might want to start presenting each on one line, to start introducing the idea that this should be a grid. And if tracks are going to start doing it, I suggest it's a good idea for the JSON to do it as well
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.
Agreed. I've now applied the same multi-line formatting for all array fields. Let me know what that looks like.
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.
Do I understand correctly that we cannot add CI checks because we are making case-by-case decisions for arrays? That's too bad, because that means there's a possibility of future changes being badly formatted. Given that, I'm not excited about this PR; I only feel completely ambivalent about it. But if someone really wants this, I support that desire, and therefore I approve.
@@ -37,7 +37,11 @@ | |||
"description": "Adding multiple students in the same grade in the roster", | |||
"property": "add", | |||
"input": { | |||
"students": [["Blair", 2], ["James", 2], ["Paul", 2]] |
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.
had I been the one making this PR, I would have kept the existing formatting, but I have no disagreement with the decision made in this PR.
"strings": [ | ||
"nail", | ||
"shoe", | ||
"horse", | ||
"rider", | ||
"message", | ||
"battle", | ||
"kingdom" | ||
] |
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 see that unlike the other "strings"
in this file, this one qualified to be on separate lines because it has many elements (so putting all on one line would make long). okay.
"comments": [ | ||
"If property based testing tools are available, a good property to test is reversing a string twice: reverse(reverse(string)) == string" | ||
], | ||
"comments": ["If property based testing tools are available, a good property to test is reversing a string twice: reverse(reverse(string)) == string"], |
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.
showing a place where a long comment was chosen to be the same line as the [
and ]
"comments": [ | ||
"This test aims to catch buggy implementations that check for duplicate spaces or hyphens." | ||
], |
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 contrast to a different place where a long comment was chosen to be on the same line as the [
and ]
, I see that here it was chosen to be on different lines than [
and ]
. I don't have an explanation, but I don't need one.
This PR was mostly a test to check whether the auto formatting used by prettier could be used to auto-format all files and what that would look like. Looking at the review comments, it looked like there were multiple cases where the formatting was not what we wanted. The way I envision this PR going forward was:
Once we've manually updated the files, we can exclude those files from being auto-formatted. This means that we would be able to have a CI check for the formatting, although there would still be a risk of the excluded files' formatting getting out of sync. Would this approach excite you slightly more? |
"comments": [ | ||
"Language implementations vary on the issue of unequal length strands.", | ||
"A language may elect to simplify this task by only presenting equal", |
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.
The leading spacing here looks a bit odd. But I'm on mobile so not sure and it is not worth blocking this PR for.
Well, having some files be checked is better than none, I think. So that is good. I'm even getting some ideas such as: Even though it appears prettier doesn't allow configuring whether array elements should go on their own, line, perhaps there is something we can write that would do that... then, we can use that tool in conjunction with prettier. We'd have a fixed list of exercises that tool should be run on, and it would run after prettier. In that way, every file will be automatically formatted. |
Ooh, that would be nice. Just on the off chance: would you potentially be interested in developing such a tool? Or do you have ideas on whether we could something like this with plain bash? |
Remind me what prettier does? Does it put all the elements on one line? Now this tool does need to respect indentation, so it may be a little involved for a shell script, though a shell script might be able to do it by counting the number of leading spaces in the line and adding two more. Now let's see. We're already running Python in CI, in https://github.com/exercism/problem-specifications/blob/main/bin/check-immutability.py, but there's a difference here in that check-immutability.py mainly needs to be run in CI, whereas it may be handy for contributors to be able to run this formatting thing, so a decision should be made with that in mind. I think it will be easier to get a better sense of what this should look like after formatting starts getting enforced in CI, with exercises excluded. Then, exercises can be un-excluded and this formatting tool can be tested. It's fine to keep talking about it in the meantime though. One thing I'm thinking about is whether it'll have any problems with strings that contain either |
I think it depends on the number of characters the array would take if presented on a single line. |
I've added a couple of commits: |
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 the ideal world, the commit entitled "Allow testing of formatting" would have been made easier to review by putting the lines that add the integrity
line and remove the URL portion after the #
into their own commit, but the problem was not so serious that I was forced to not approve.
Please consider the experience for a contributor who wants to make an addition to the JSON files but does not format it the same way prettier
would and therefore CI fails. Is the output informative enough to tell them how to remedy their problem? I will trust your judgment on what you decide is sufficient for you to say we have considered their experience.
0b470a1
to
2be235c
Compare
I've added a yarn command to format the JSON and updated the contributing documentation. I'll add a GHA workflow to allow maintainers to format JSON using a comment on a PR. |
With 3 approvals, I'm gonna merge this and do a GHA workflow formatting follow-up PR later. Thanks everyone! |
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.
Approving on principle.
Thanks everybody! |
* Format using prettier (exercism#1917) Format using prettier * updated description of anagrams exercise (exercism#1928) * updated description of anagrams * changed anagram description to be one-sentence-per-line * updated description of anagrams to use sets * Update Licence Give a look at the discussion in BR exercism#1930 * rational-numbers: test to reduce abs value (exercism#1938) * Change saddle point references to row, column (exercism#1948) * word-search: Add test case * Update exercises/word-search/canonical-data.json Agreed. Co-authored-by: Erik Schierboom <[email protected]> * meetup: improve descriptions by saying why each case is tested (exercism#1919) descriptions show whether a date is the first, last, or an arbitrary middle date of the week. This helps understand why certain cases are selected. Closes exercism#974 * word-search: Add cases checking for concatenation and wrapping The author of this commit thinks that concatenation is highly unlikely, but the wrapping might be useful to check in languages that allow negative indices. * `flatten-array` Add additional test cases (exercism#1953) * Add additional test cases to flatten-array * Update exercises/flatten-array/canonical-data.json Co-authored-by: Peter Tseng <[email protected]> Co-authored-by: BethanyG <[email protected]> Co-authored-by: Peter Tseng <[email protected]> * Fix bowling game copy (exercism#1955) Fixes exercism#1954 * Add action to format code (exercism#1941) * build(deps): bump DavidAnson/markdownlint-cli2-action (exercism#1952) Bumps [DavidAnson/markdownlint-cli2-action](https://github.com/DavidAnson/markdownlint-cli2-action) from 5.0.0 to 5.1.0. - [Release notes](https://github.com/DavidAnson/markdownlint-cli2-action/releases) - [Commits](DavidAnson/markdownlint-cli2-action@b3c3b40...744f913) --- updated-dependencies: - dependency-name: DavidAnson/markdownlint-cli2-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Reduced rational nr. should be in standard form. (exercism#1958) * Reduced rational should be in standard form. The current instructors fail to mention that a reduced rational number should always be rendered in standard form (without any negative value at the denominator). * remove superflous blank lines; fix wording * scale-generator: use flat and sharp symbols (exercism#1942) * Update configlet part in README (exercism#1949) Co-authored-by: ee7 <[email protected]> * phone number: only one problem per test input (exercism#1959) * [Phone Number] Only one problem per test input Because the area code is not allowed to start with 0 or 1, inputs designed to elicit other errors should not use area codes that start with either of those digits. * Respect immutability * Correct field name: s/comment/comments/ * Comments should contain a list. * Allow prettier to improve comments * book-store: reorder keys * darts: reorder keys * grade-school: reorder keys * hamming: reorder keys * high-scores: reorder keys * largest-series-product: reorder keys * list-ops: reorder keys * luhn: reorder keys * triangle: reorder keys * scale-generator: reorder keys * saddle-points: reorder keys * diffie-hellman: reorder keys * collatz-conjecture: reorder keys * anagram: reorder keys * accumulate: reorder keys * Add CI script to check correct order of keys Co-authored-by: Bart Massey <[email protected]> Co-authored-by: y8l <[email protected]> Co-authored-by: Ivan Ivanov <[email protected]> Co-authored-by: Damian C. Rossney <[email protected]> Co-authored-by: mariohuq <[email protected]> Co-authored-by: mariohuq <[email protected]> Co-authored-by: Peter Tseng <[email protected]> Co-authored-by: Peter Tseng <[email protected]> Co-authored-by: AH WEI <[email protected]> Co-authored-by: BethanyG <[email protected]> Co-authored-by: Cedd Burge <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Davide Alberto Molin <[email protected]> Co-authored-by: wolf99 <[email protected]> Co-authored-by: June <[email protected]> Co-authored-by: ee7 <[email protected]> Co-authored-by: Leah Hanson <[email protected]>
As a counterpart to #1916, this PR formats the
canonical-data.json
files used prettier.