Tweak formatter output for readability (#26)#47
Merged
Conversation
Apply three default formatting tweaks requested in issue #26 (ported from the lbl-srg/modelica-buildings PR #2426 post-processing script into the formatter itself): 1. Keep a function call with a single argument on one line instead of breaking the argument onto its own line, e.g. pre(x), der(y), sin(z), sum(a .* b). Calls with two or more arguments are unchanged. Applies to both regular and external function calls. 2. Insert a single blank line before equation/initial equation, algorithm/initial algorithm, and public/protected section headers. The blank line is not duplicated when -extra-padding already adds one. 3. Collapse the stray empty line often left between the final </ul> and </html> of a revisions docstring (</ul>\n\n</html> -> </ul>\n</html>). Add a focused tweaks.mo fixture plus golden output, a unit test for the revisions blank-line collapse, and regenerate the affected golden files. Update README and CHANGELOG. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #26.
Implements the three formatting tweaks requested in the issue (ported from the lbl-srg/modelica-buildings PR #2426 post-processing script directly into the formatter, so they apply by default with no extra step):
1. Single-argument calls stay on one line
A function call with exactly one argument keeps its argument inline instead of breaking it onto its own line, so common wrappers like
pre(x),der(y),sin(z)andsum(a .* b)stay compact. Calls with two or more arguments are unchanged. Handled at the AST level for both regular (function_call_args) and external (external_function_call_args) calls, so nested multi-argument calls still break correctly.2. Blank line before section headers
A single blank line is inserted before
equation/initial equation,algorithm/initial algorithm, andpublic/protectedsection headers to separate them from the preceding declarations. AtrailingNewlinescounter ensures the blank line is not duplicated when-extra-paddingalready added one.3. Tidy revision docstrings
The stray empty line frequently left between the final
</ul>and</html>of arevisionsdocstring is removed (</ul>\n\n</html>→</ul>\n</html>), preserving the original tag casing and</html>indentation.Example
Tests / docs
tweaks.mofixture + golden output exercising all three tweaks, added to the example-file test table.TestCollapseRevisionListBlankLinecovering single/multiple blank lines, preserved indentation, case-insensitivity, and no-op cases..mo/.motfiles; every diff is an intended single-arg collapse or section blank line.README.md(new "Default formatting behavior" section) andCHANGELOG.md.make all(build + test) passes.