-
-
Notifications
You must be signed in to change notification settings - Fork 80
Fix awkward line splits from JuliaFormatter #1306
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
Fix awkward line splits from JuliaFormatter #1306
Conversation
- Keep tuple assignments (fig, ax, plt) on single lines - Fix split function calls and constant definitions - Improve readability by keeping related elements together - Binary operations with long warnings kept more readable These changes address formatting issues introduced by JuliaFormatter that made the code less readable by splitting logical units across lines.
Background on this formatting issueThis PR addresses a long-standing issue with JuliaFormatter that has affected multiple SciML packages. Here's the comprehensive background: The ProblemJuliaFormatter has been overly aggressive in breaking lines, particularly with:
History of Complaints and Prior Work
Related JuliaFormatter Issues and PRsThis is a well-known problem with many attempts to fix it: Issues:
Pull Requests attempting fixes:
Despite all these attempts, the issue persists, particularly affecting SciML packages where plotting functions and scientific computing patterns often involve multiple return values. The SolutionI'm working on a comprehensive PR to JuliaFormatter that makes the formatter more conservative about breaking lines, building on the lessons learned from previous attempts. The key improvements:
VerificationAll changes in this PR have been tested with the updated JuliaFormatter to ensure they won't be reverted. The test suite includes specific cases for:
This should significantly improve code readability across the SciML ecosystem once the JuliaFormatter improvements are merged. Why This MattersThe current formatting makes code harder to read and understand, particularly for:
By fixing these formatting issues, we improve the developer experience across the entire SciML ecosystem. |
Detailed breakdown of changes in this PRHere's a file-by-file breakdown of the formatting fixes: 1.
|
How to Identify and Fix JuliaFormatter Line Split IssuesWhat to Look ForWhen reviewing code after running JuliaFormatter, watch for these problematic patterns: 1. Split Tuple Assignments❌ Bad: fig, ax,
plt = scatterlines(data)
x, y,
z = process_coordinates(data) ✅ Good: fig, ax, plt = scatterlines(data)
x, y, z = process_coordinates(data) 2. Split Function Calls❌ Bad: result = some_function(
arg1)
writable_ps = dependency_split\!(remaining_ps,
[remaining_ps; remaining_sps; remaining_vars]) ✅ Good: result = some_function(arg1)
writable_ps = dependency_split\!(remaining_ps, [remaining_ps; remaining_sps; remaining_vars]) 3. Split Constant Definitions❌ Bad: const MY_TUPLE = (first_element, second_element,
third_element)
CONNECTION_TYPE_FS = (
func1, func2, func3) ✅ Good: const MY_TUPLE = (first_element, second_element, third_element)
CONNECTION_TYPE_FS = (func1, func2, func3) 4. Split Binary Operations❌ Bad: condition &&
(@warn "Long warning message") ✅ Good: condition && (@warn "Long warning message") How to Fix These Issues
Rules of Thumb
Common Patterns in SciMLThese patterns should generally stay together:
When Splits ARE AppropriateLine breaks are good when:
Remember: The goal is readable, maintainable code. JuliaFormatter is a tool to help, not a strict rulebook. Use your judgment to keep code clear and logical. |
domluna/JuliaFormatter.jl#934 should be the final PR required in order to ensure that behavior doesn't come back. All of these cases were added as MWEs to the test suite. |
Major note to Claude: JuliaFormatter will not reverse line breaks. The best way to solve such issues is to fully revert by bring all line breaks back to a single line and then letting the formatter run |
I'll handle Arblib updates separately. |
Summary
This PR fixes awkward line splits that were introduced by JuliaFormatter, making the code more readable by keeping logical units together.
Changes Made
1. Fixed tuple assignments in plotting functions
fig, ax, plt = ...
andfig, ax, hm = ...
now stay on single linesext/CatalystCairoMakieExtension/cairo_makie_extension_spatial_modelling.jl
ext/CatalystGraphMakieExtension/graph_makie_extension_spatial_modelling.jl
2. Fixed constant definitions
src/reactionsystem_serialisation/serialise_fields.jl
(CONTINUOUS_EVENTS_FS, DISCRETE_EVENTS_FS, CONNECTION_TYPE_FS)src/reaction.jl
(NON_CONSTANT_JUMP_SCALES)3. Fixed split function calls
src/reactionsystem_serialisation/serialise_fields.jl
(dependency_split! calls)src/dsl.jl
(read_equations_option!, read_observables_option)4. Improved readability of long lines
src/chemistry_functionality.jl
src/dsl.jl
(bwd_arrows, option_keys)Verification
These changes have been tested with an updated version of JuliaFormatter (PR pending) to ensure they won't be reverted. The updated formatter is more conservative about breaking lines, especially for:
=
Related Issues
This addresses formatting issues similar to those seen in:
🤖 Generated with Claude Code