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
Help: Classes: code style update #6306
base: develop
Are you sure you want to change the base?
Help: Classes: code style update #6306
Conversation
A tip for reviewing the changes: take a broad look at the types of changes. Any individual change may seem trivial, but then in other instances it's (hopefully) more clear why this is useful. This was a fairly automated task, with a human in the loop. There was plenty of bulk replace on a file-by-file basis, one rule or partial rule at a time. So the trivial and non-trivial changes came at equal cost. |
a6d4dc7
to
3a960b5
Compare
I've gone through about the top quarter or so files (alphabetically) in detail, and scanned through the rest, and I haven't been able to find any mistakes. I think it might be worth 'taking the plunge' and just merging this. |
Thanks for this! I know that applying or enforcing styles is a controversial topic here, but I personally think that having a more consistent style throughout the documentation helps new users, and any improvement or work on the documentation is always welcomed. One thing I would like to add to such an effort would be a way for future commits to automatically apply this style as well - that is the beauty of a style guide, no more discussion and work to enforce a certain style. You mentioned that you used regex to identify and modify the existing code - we could add this as a check/script via a git hook, so that any new commits would have to pass this check/script as well, which would also automatically suggest/apply any necessary changes by diffing them with your staged files. The CI could also tell us the style guide status of a commit in this case. I suggested something like this in #6096, but maybe it makes sense to try again here? If others think this would be a good thing to implement, I could provide the necessary code, but in this case we should bundle the "git-hook" implementation with these changes. |
Thanks for having a look!
I considered this, and it's really unavoidable. But the plan is to squash it to one commit on merge so that any given help file only has one blame commit in its history for this whole update. And I agree the doc files are low stakes relative to making this kind of change to the code base proper (otherwise I probably wouldn't have even undertaken the effort).
I agree this would be a great addition! ... but out of scope for this PR and frankly beyond my capacity atm ;) It's a fruitful discussion to have though—it would be higher impact and worthwhile. Given the larger scope and changes to process that would imply I'll comment on that idea in the Discussion page. |
added: Space follows comment slashes, and precedes them when inline |
find: \{(?:\s*)arg(?:\s+)([^;]+); replace: { |$1| Rule: Use pipes instead of the arg keyword to express parameter lists. https://github.com/supercollider/supercollider/wiki/Style-Guidelines%3A-SuperCollider#rule-use-pipes-instead-of-the-arg-keyword-to-express-parameter-lists
Rule: Add spaces within curly brackets https://github.com/supercollider/supercollider/wiki/Style-Guidelines%3A-SuperCollider#rule-add-spaces-within-curly-brackets--but-not-parentheses--square-brackets--or-argument-lists- find \{\s*\|([^}]+)\} replace { |$1 } followed by removing double spaces before closing curly bracket
Recommendation: don't place a semicolon after the final statement of a method or function. https://github.com/supercollider/supercollider/wiki/Style-Guidelines%3A-SuperCollider#recommendation-dont-place-a-semicolon-after-the-final-statement-of-a-method-or-function
Rule: Add spaces within curly brackets {}, but not parentheses (), square brackets [], or argument lists ||. https://github.com/supercollider/supercollider/wiki/Style-Guidelines%3A-SuperCollider#rule-add-spaces-within-curly-brackets--but-not-parentheses--square-brackets--or-argument-lists-
This search will get you part of the way: find \( * ([^[\]]+?) * \) replace ($1) Rule: Add spaces within curly brackets {}, but not parentheses (), square brackets [], or argument lists ||. https://github.com/supercollider/supercollider/wiki/Style-Guidelines%3A-SuperCollider#rule-add-spaces-within-curly-brackets--but-not-parentheses--square-brackets--or-argument-lists-
Rule: Use spaces around binary operators Binary operators, including key binary operators, should have one space before and after. https://github.com/supercollider/supercollider/wiki/Style-Guidelines%3A-SuperCollider#rule-use-spaces-around-binary-operators search (?<!:|http|https|[0-9]|\s|"|\():(?!:| |\n|\t|%|-|"|//) replace (colon followed by space) :
Find ;(?=[^\s\n":]) replace ; (semicolon followed by space)
find (?<![ <=>~])=(?![ <=>]) replace =
Find ,{ replace , {
Find ,(?![\s\n\d]) replace , (comma-space) Note this regex avoids consecutive numbers like 1,2,3,4 Rule: Add spaces after commas. https://github.com/supercollider/supercollider/wiki/Style-Guidelines%3A-SuperCollider#rule-add-spaces-after-commas
Tried to avoid doing this when there appeared to be an intentional alignment, e.g. aligning comments between lines
basic string search for left pipe: { | replace with { | (no trailing space) find right pipe: ([a-zA-Z0-9]) \|(?!\|) replace with $1| https://github.com/supercollider/supercollider/wiki/Style-Guidelines%3A-SuperCollider#rule-add-spaces-within-curly-brackets--but-not-parentheses--square-brackets--or-argument-lists-
find ([^0-9]),(?![\s\n]) replace $1, (comma followed by space)
find (\d),(?=\d) replace $1, Note: There were lots of false replacements when doing "replace all" on files, that had to be manually spotted individually re-run
Find (?<=[^<>=!+ ])= replace = (space,=) This had a high occurence of unwanted matches asdf
search ,(?=\S) replace , (comma, space)
for missing preceding space (?<=[^\s:])\/\/ for missing trailing space (?<!\S)\/{2}(?=\S)
3eafc8d
to
14cee73
Compare
Note: This PR is meant for review of the implementation details, I've started a Discussion [#6307] to capture higher-level thoughts on whether this is a good idea, the scope, etc.
Purpose and Motivation
It stumbled into the project when playing with project-wide regex search and replace in VS Code, and before I knew it … 🕳️ 🐇
The general motivation is that the docs vary widely in quality and consistency of code examples, and this is a step toward cleaning it up.
There are almost no syntactic changes here, the vast majority of changes here are just handling whitespace. So in effect the examples just breathe a bit better, IMO. There are a few other advantages I see:
Notes on scope
If successful, this PR can set a template for mapping onto other docs in the future (I’m roughly documenting the regex search-and-replace criteria)
Types of changes / implementation details
Each commit of the PR roughly corresponds to a rule or partial filling of the rule. See those for more details.
Here is a summary of the rules implemented:
A large portion of the changes are summed up by this Rule:
Add spaces within curly brackets {}, but not parentheses (), square brackets [], or argument lists ||.
Use pipes instead of the arg keyword to express parameter lists.
Space follows a comma (numeric chars on either side or if preceded by non-numeric char)
Remove semicolon preceding a closing paren
Remove space preceding comma
Remove double spaces (tried to avoid this when there appeared to be an intentional alignment, e.g. aligning comments between lines)
Add space after commas (exception: huge arrays)
Surround equals signs with spaces
Spaces follow semi colons when code is inline
Spaces follow key operators
Space follows comment slashes, and precedes them when inline
No semicolon after the final statement of a function (recommendation)
Removing double spaces before closing curly bracket
Notably left out: spaces around operators - this was in part because, despite this being a rule, I could see this being a point of contention. And, admittedly, this is would be less straightforward to implement and likely a good deal more work. But, I’m happy to give it a go to catch a substantial number of instances of this.
The
arg
keyword is replaced by pipes. It’s on my TODO list to restore the arg keyword in help files that may directly refer to it, but otherwise the pipes rule is enforced broadly. Some may have feelings about his.To-do list
Merge notes