stylus-supremacy
stylus-supremacy copied to clipboard
`insertNewLineAroundBlocks` interprets inline conditions as a "block"
If insertNewLineAroundBlocks option is true then this block of variable assignments:
$color = red;
$name = 'John';
$greet = 'Hi ' + $name if ($name);
$err = 'Name missing' unless ($name);
$something = 9000;
$other = 42;
gets broken up as if the if and unless conditions are blocks of their own, like so:
$color = red;
$name = 'John';
$greet = 'Hi ' + $name if ($name);
$err = 'Name missing' unless ($name);
$something = 9000;
$other = 42;
Which is a bit surprising and can turn ugly quite fast.
There are actually a type of Block regarding the Stylus compiler. Hence, this is not really a bug from Stylus Supremacy, unless people want an exception.
This is also a simple variable assignment, so the question is which one wins over. :-)
In my experience these sort of lines will be sitting in the middle of other variable assignments, and the resulting breakup patterns will look surprising and out of character compared to the rest of the formatting.
I'd say that if the line starts with variable = ... then treat it as variable assignment, but if it starts with if (...) then treat as a block.
Well, it doesn't matter if the statement starts with if or var =. The Stylus compiler will parse them as if-block anyway.
The below code compiles to an AST in exactly the same way.
$var = 123 if ($xxx)
if ($xxx) {
$var = 123
}
I see, so even if from the human developer's end there's a difference, the parser can't see the difference?
How come then does the formatter retain the single-line syntax and doesn't normalize it into
if ($xxx) {
$var = 123
}
?