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
Code Formatter #724
Code Formatter #724
Commits on Jul 7, 2017
-
-
-
-
-
-
Treat SIGNIFICANT_WHITE_SPACE as whitespace
Don't build a Block for SIGNIFICANT_WHITE_SPACE ASTNodes since Whitespace class will consume them.
-
-
-
Separate not from other unary operators
`not` must be a separate token (NOT_OPERATOR) from the symbolic unary operators (UNARY_OPERATOR) as the symbolic operators in most styles have no space around them, but `not`, being a word, requires a space so that it doesn't merge with its argument to form an IDENTIFIER.
-
Flatten END_OF_EXPRESSION to separate COMMENTs
END_OF_EXPRESSION was being treated as an EOL if its first child was an EOL, but this was a bug because I forgot that it could include COMMENT interleaved with EOL because COMMENT never appears in Elixir.bnf, which was using to make Block.
-
-
-
-
-
-
-
-
-
Allow to configure whether there is a space after capture operator, but prevent & before another & from being combined and forming a &&.
-
-
-
-
-
-
-
Space around || and ||| is customizable, but space around `or` is fixed to 1 space to prevent fusion with surrounding identifiers.
-
Always 1 space around `and`. Space around `&&` and `&&&` is configurable.
-
-
-
-
-
-
-
-
-
No spaces by default around ..
Separate .. from other two operators as most style guides don't have a space around .. when it's used as a range operator.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Looking at my actual code, I use the same size for normal and continuation indent.
-
-
-
-
-
-
-
-
-
-
-
-
Inline getLineNumber(ASTNode), so that document is only gotten once, for the parent node as it will be the same for boh children.
-
Redo list indent and do tuple indent like anonymous functions, so that unindenting of final argument works for tuples and lists too with the special handling of single argument calls with UNINDENTED_ONLY_ARGUMENT_TOKEN_SET.
-
Unify buildListChildren and buildTupleChildren
-
Use buildContainerChildren for maps and structs
Map handling can be vastly simplified by using LESS Alignments and allowing the default alignment rules to work.
-
-
-
Align two operands, so that multiline concatenated strings line up on the left.
-
-
-
-
-
Flatten IDENTIFIER in calls to IDENTIFIER_TOKEN
IDENTIFER is in grammar only so that getNameIdentifier can be called on the PsiElement. It serves no purpose for formatting.
-
-
-
-
So that guards don't use a continuation indent when wrapping.
-
Match Operation Enforce Indent to Children
Ensures that do block in match indents to align with start of match instead of line when used in an assert.
-
Comparison operation enforce indent to children
Ensure that == as argument to assert has the right operand wrap and align with left operand of ==.
-
-
Treate parentheticalStab same as fn and do blocks
Ensures that that stabs are flattened the same
-
Extend buildCapturedMultiplicationOperationChildren to matched calls
Ensures that `/` in `&NAME/ARITY` and `&QUALIFIER.NAME/ARITY` has no spaces around it when function reference is an argument to a call because the outer call is unmatched while the argument is matched.
-
Don't wrap internals of parentheses, but do wrap after do and block items that don't have stab operations instead of always wrapping stab->stabBody->*.
-
-
Comments in spec align with operands
Comments end up being children of the `|` operator rule, so they didn't have the same alignment as the operands.
-
Compact wrapping and alignment of multiple aliases
Unlike tuples, only wrap when necessary in multiple aliases curly braces and align aliases inside curly braces instead of to the opening curly brace.
-
-
Always wrap keys nested under keys
Extend keyword under keywords to associations too.
-
-
Flatten endOfExpression in containers
Interpolation is a container and it can have endOfExpression because inside interpolation is elixirFile, which has endOfExpression for the root newlines.
-
Compact interpolation wrapping
For the majority of Line children mark them as WrapType.NONE, as adding new spaces or newlines in a string will change its meaning. Only things inside interpolation or the closing curly itself will allowed to wrap, to prevent injection of significant spaces or newlines.
-
-
-
-
By flattening, empty sigilModifiers can be completely removed, which is good because empty blocks screw up spacing.
-
Remove newlines from pipelines
Allows converting |> at end of line to |> at start of line.
-
noParenthesesKeyword alignment
Ensure that containers that are keyword values align their closing element to the keyword value start so that it doesn't lead to the None indent going all the way to the start of the noParenthesesOneArgument call.
-
Use Indent and flattening for containers that are keyword values
by flattening the opening and closing elements into the same block as the keyword key, the closing element can be indented None relative to the direct parent of the keyword key.
-
-
-
-
Structure bitString the same as tuple
`tuple` has `containerArgument? EOL*` while `bitString` had `(containerArguments EOL*)?`, which lead to false parse errors for some keywords in tuple test cases.
-
No bitstrings in alembic, calcinator, or retort, so need to add synthetic tests based on tuple cases.
-
The `name: arity` keyword pairs for selective `import` using `only:` or `except:` are always neste keywords, but the usage of `import` with the selective import is meant to allow for compact import, so it doesn't make sense to apply keyword exclusivity to import.
-
Do not ALWAY wrap keywords under unmatch call
do:
Ensure that `def` and `defp` one-liners remain one-liners, but the formatter will still show when it really needs to be manually converted to do block format.
-
Search for keywords and containers at correct level in maps/structs
When switching to use `containerValueWrap` for maps and structs, failed to take into account that (1) maps use both keywords and associations and (2) those pair collections aren't direct children of the map/struct, but under the mapArguments's update or construction arguments.
-
-
-
-
-
Don't build zero-length children blocks
Empty blocks result in an error before IntelliJ IDEA 2016.3. SIGIL_MODIFIERS were empty blocks.
-
Don't build HeredocLinWhiteSpaceTokenBlock shorter than prefix
It results in an zero-length effective TextRange, which makes it an empty block, which is in error before 2016.3.
-
Printing AST clogs log and slows formatting
-
-
-
-
-
-
-
-
-
-
-
-
-
-