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

Two empty lines after functions/vars not working #665

Open
sebthom opened this issue Jan 13, 2023 · 3 comments
Open

Two empty lines after functions/vars not working #665

sebthom opened this issue Jan 13, 2023 · 3 comments
Labels
bug Something isn't working emptylines missing or incorrect empty line

Comments

@sebthom
Copy link

sebthom commented Jan 13, 2023

Describe the bug

Setting any of the following emptyLines/classEmptyLines options to insert/keep two lines instead of one are ignored by the formatter:

"afterStaticFunctions": 2,
"afterStaticVars": 2,
"afterVars": 2,
"betweenStaticFunctions": 2,
"betweenFunctions": 2

Input file

class Example {

   static final staticField1 = "";
   static final staticField2 = "";


   final field1 = "";
   final field2 = "";


   static function staticFunc1() {
      trace("hi");
   }


   static function staticFunc2() {
      trace("hi");
   }


   function func1() {
      trace("hi");
   }


   function func2() {
      trace("hi");
   }
}

Broken output

class Example {

   static final staticField1 = "";
   static final staticField2 = "";

   final field1 = "";
   final field2 = "";

   static function staticFunc1() {
      trace("hi");
   }

   static function staticFunc2() {
      trace("hi");
   }

   function func1() {
      trace("hi");
   }

   function func2() {
      trace("hi");
   }
}

Expected output

class Example {

   static final staticField1 = "";
   static final staticField2 = "";


   final field1 = "";
   final field2 = "";


   static function staticFunc1() {
      trace("hi");
   }


   static function staticFunc2() {
      trace("hi");
   }


   function func1() {
      trace("hi");
   }


   function func2() {
      trace("hi");
   }
}

Optional: hxformat.json

{
    "emptyLines": {
        "beforeDocCommentEmptyLines": "ignore",
        "classEmptyLines": {
            "beginType": 1,
            "afterVars": 2,
            "afterStaticFunctions": 2,
            "afterStaticVars": 2,
            "betweenStaticFunctions": 2,
            "betweenFunctions": 2
        },
        "afterLeftCurly": "keep",
        "betweenTypes": 2,
        "maxAnywhereInFile": 2
    }
}
@AlexHaxe
Copy link
Member

unless you set "existingBetweenFields": "remove" current behaviour of formatter is to keep just one empty line between fields and that will beat any of the other settings.

your current sample would work if you removed all empty lines between fields from input. problem is: next formatter run will reduce all double empty lines to just one, because of keep setting.

keep option probably should count number of empty lines in input to add correct amount of empty lines to output.

@AlexHaxe AlexHaxe added emptylines missing or incorrect empty line bug Something isn't working labels Jan 14, 2023
@sebthom
Copy link
Author

sebthom commented Jan 14, 2023

Thanks for your hints! when I set existingBetweenFields to remove it actually works. It however feels very counter intuitive. I feel like the name and values of that option are misleading. Also, even though it is called existingBetweenFields it also affects empty lines between functions.

Unfortunately when setting existingBetweenFields to remove, as the name implies, all empty lines between fields are removed. So I cannot have something like

class Example {

   final field1 = "";
   final field2 = "";

   final field3 = "";
   final field4 = "";


   function func1() {
      trace("hi");
   }


   function func2() {
      trace("hi");
   }
}

@AlexHaxe
Copy link
Member

Also, even though it is called existingBetweenFields it also affects empty lines between functions.

functions are fields.

Unfortunately when setting existingBetweenFields to remove, as the name implies, all empty lines between fields are removed.

yeah, that is the downside of remove, you can't have custom empty lines to separate different groups of fields. that's why keep is default. it needs a overhaul to support more than one empty line between fields.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working emptylines missing or incorrect empty line
Projects
None yet
Development

No branches or pull requests

2 participants