Skip to content
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

insertNewLineAroundBlocks interprets inline conditions as a "block" #47

Open
maranomynet opened this issue Oct 17, 2018 · 4 comments
Open

Comments

@maranomynet
Copy link

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.

@maranomynet maranomynet changed the title insertNewLineAroundBlocks interprets inline conditions as a "block" insertNewLineAroundBlocks interprets inline conditions as a "block" Oct 17, 2018
@ThisIsManta
Copy link
Owner

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.

@maranomynet
Copy link
Author

maranomynet commented Oct 23, 2018

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.

@ThisIsManta
Copy link
Owner

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
}

@maranomynet
Copy link
Author

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
}

?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants