-
Notifications
You must be signed in to change notification settings - Fork 78
Description
This issue is to organise and track efforts to implement BlueStyle as a Custom Style. Similar to how YASGuide is now available in JuliaFormatter via YASStyle. (see issue #198 and PRs #214, #217).
I think the first step is to come up with a list of cases where BlueStyle recommends a style change that is currently not available via DefaultStyle or YASStyle...
TO DOs (see comment below for details/examples):
- Module Imports
- Imports at top of file (see also send
usingandimport statementsto the top #284) - Order imports alphabetically (see also Sort imports #257)
- One module import per line
- Prefer
usingoverimport
- Imports at top of file (see also send
Global Variables (not possible?)Function Naming (not possible)- module exports (see Add preferences on function exports for BlueStyle #358)
- Method Definitions
- Only use short-form function definitions when they fit on a single line
- When using long-form functions always use the return keyword (but not in
doblocks) (second highest priority) (BlueStyle - implement top 3 issues #295) - use
return nothingrather than barereturn(94cb799)
- Keyword Arguments
- No whitespace in keyword arguments
- Separate keyword arguments from positional arguments with a
;semicolon (third highest priority) (BlueStyle - implement top 3 issues #295)
- Whitespace
- Avoid extraneous whitespace immediately inside brackets
- Avoid extraneous whitespace immediately before a comma or semicolon
- Avoid whitespace around
:in ranges, add brackets to clarify - Avoid whitespace for alignment
- Surround most binary operators with a single space
- except
^ - except
//(Give//the same binaryop whitespace exception as^#288)
- except
- Avoid using whitespace between unary operands and the expression
- Avoid extraneous empty lines
- Function calls which cannot fit on a single line within the line limit should be broken up such that... (see below)
- Function calls which cannot fit on a single line can allow all arguments on a second line if they fit within the line limit (see Implement BlueStyle #283 (comment), BlueStyle - implement top 3 issues #295)
- Assignments using expanded notation for arrays or tuples should have the first open bracket on the same line assignment operator
- Assignments using function calls should have the first open bracket on the same line as the assignment operator (highest priority, since it is much more common than other things that need to be implemented) (BlueStyle - implement top 3 issues #295)
- Triple-quotes and triple-backticks written over multiple lines should be indented. The opening quotes should be on the same line as the assignment operator.
- Blank lines between multi-line block (ending
end)Blank lines before return (pending Simplify some current guidance to "have a blank line between multi-line blocks"? JuliaDiff/BlueStyle#61)
- NamedTuples
- The
=character in NamedTuples should be spaced as in keyword arguments (i.e. likex=1, no spaces) - Empty NamedTuple written
NamedTuple()not(;)(also see related issue JuliaFormatter changes empty NamedTuple(;)to empty Tuple()#285)No leading;(but pending Relax opinion on use of;in NamedTuples? JuliaDiff/BlueStyle#62)
- The
- Numbers
-
Float64numbers should always include a leading and/or trailing zero -
Float32numbers should always include a leading and/or trailing zero (see Float32 edge cases of leading/trailing0in floating points #286)
-
- Ternary Operator
- limit to one line (Conditional to if option #308)
- do not chain (746c456)
- Short-circuit operators for control-flow
- only on one line? (...pending Short-circuit logic used as control flow should only be used on a single line JuliaDiff/BlueStyle#72)
- For loops
- For loops should always use
in, never=or∈.
- For loops should always use
Type annotation (not possible for BlueStyle advice)Package version specifications (not possible)- Comments
- inline comments separated by at least two spaces from the expression and have space after
#. - Only use inline comments if they fit within the line length limit (see also Imposing margin on comments #197)
- inline comments separated by at least two spaces from the expression and have space after
Still to look into:
- Formatting docstrings
Could maybe also look into, but leaving these for now:
- Testsets formatting
- Test Comparisons
Going through this i realise that BlueStyle has a lot of things that cannot be automated, and that is fine. I think the intended use case for the formatter is an environment where collaborators know what style is intended and attempt to follow it, but don't have to sweat the details and don't have to rely on code review to fix whitespace style issues. I think this also means that its much more important that the formatter doesn't make "good" style into "bad" style, than it is to make all "bad" cases "good" (and all cases wouldn't be realistic anyway).