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

Unexpected/Inconsistent behavior for if one liner #60

Open
FlorianPfaff opened this issue Feb 8, 2019 · 3 comments
Open

Unexpected/Inconsistent behavior for if one liner #60

FlorianPfaff opened this issue Feb 8, 2019 · 3 comments
Assignees
Labels

Comments

@FlorianPfaff
Copy link

FlorianPfaff commented Feb 8, 2019

Hi,
thanks for addressing my last issue. Since this is so actively maintained, I thought you may be interested in another issue that is, however, not as critical.
I'll explain it on MWEs.
if 0 == 0, a = 1 + 1, end
is kept as it is by the tool. However,
if 0 == 0, a = 1 + 1; end
is turned into
if 0 == 0, a = 1 + 1;
end

I think these cases should behave identically. I personally prefer the former behavior because it does allow one liners. However, I can also understand if one liners are eliminated - in this case, however, the a = 1 + 1; expression should also put in a separate line.

Anyways, thanks again. And it's not an important issue because it does not break the code after all.

@davidvarga davidvarga self-assigned this Feb 10, 2019
@davidvarga
Copy link
Owner

davidvarga commented Feb 10, 2019

It's an unfortunate side-effect of "AllowMultipleStatementsPerLine": The idea is, that if this option is enabled:

a = 2; b = 3; is formatted as

a = 2;
b = 3;

At the moment, the "multiple statement" only means that multiple parts can be found where the closing character is semicolon (";").

One liner if-s (and this is also valid to for and while loops) theoretically could be supported, but for example:

if 0 == 0, a = 1 + 1; end -> Should remain one-liner
if 0 == 0, a = 1 + 1; b = 2 + 2; end -> Should remain one-liner, or should be formatted as?:

if 0 == 0,
    a = 1 + 1;
    b = 2 + 2;
end

I personally would expect the one-liner form. And I could imagine 3 new options below "AllowMultipleStatementsPerLine":

  • AllowOneLinerIf
  • AllowOneLinerFor
  • AllowOneLinerWhile

What do you think?

@FlorianPfaff
Copy link
Author

FlorianPfaff commented Feb 10, 2019

That definitely sounds like a thorough solution.

I would expect both of your examples to stay one-liners if "AllowOneLinerIf" if set to true. While I would avoid multiple statements in an if one-liner, I can think of examples that may make sense, e.g., to avoid distracation from plotting commands such as
if ishold, hold('off'); cla; end

Anyways, thanks again, your enthusiasm for this project is really commendable.

@davidvarga
Copy link
Owner

The new rule was not yet implemented yet, but single-statement lines are now untouched even if "AllowOneLinerIf" is set to false.

So e.g.

if true, a = 1; end

will be untouched.

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

No branches or pull requests

2 participants