Skip to content

Commit

Permalink
added whitespace.addLineCommentSpace to ensure whitespace after // (#388
Browse files Browse the repository at this point in the history
)

* added whitespace.addLineCommentSpace to ensure whitespace after //
  • Loading branch information
AlexHaxe authored Mar 3, 2019
1 parent a18ca40 commit 1419ee6
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Added `wrapping.metadataCallParameter` ([#370](https://github.com/HaxeCheckstyle/haxe-formatter/issues/370))
- Added `emptyLines.macroClassEmptyLines`, fixes [#377](https://github.com/HaxeCheckstyle/haxe-formatter/issues/377) ([#383](https://github.com/HaxeCheckstyle/haxe-formatter/issues/383))
- Added `emptyLines.lineCommentsBetweenTypes` and `emptyLines.lineCommentsBetweenTypes` to separate line comments from types and functions ([#387](https://github.com/HaxeCheckstyle/haxe-formatter/issues/387))
- Added `whitespace.addLineCommentSpace` to ensure a space after `//` ([#388](https://github.com/HaxeCheckstyle/haxe-formatter/issues/388))
- Fixed type parameter constraint with structure type, fixes [#337](https://github.com/HaxeCheckstyle/haxe-formatter/issues/337) ([#349](https://github.com/HaxeCheckstyle/haxe-formatter/issues/349))
- Fixed wrapping of OpBool chains with null ([#349](https://github.com/HaxeCheckstyle/haxe-formatter/issues/349))
- Fixed line comments after typedefs, fixes [#331](https://github.com/HaxeCheckstyle/haxe-formatter/issues/331) ([#349](https://github.com/HaxeCheckstyle/haxe-formatter/issues/349))
Expand Down
1 change: 1 addition & 0 deletions resources/default-hxformat.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
"whileBody": "next"
},
"whitespace": {
"addLineCommentSpace": true,
"arrowFunctionsPolicy": "around",
"binopPolicy": "around",
"bracesConfig": {
Expand Down
5 changes: 5 additions & 0 deletions resources/formatter-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,11 @@
],
"propertyOrder": 12
},
"addLineCommentSpace": {
"description": "ensure a space after '//'",
"type": "boolean",
"propertyOrder": 30
},
"catchPolicy": {
"type": "string",
"enum": [
Expand Down
5 changes: 5 additions & 0 deletions src/formatter/config/WhitespaceConfig.hx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ typedef WhitespaceConfig = {
only applies spaces, no newlines or wrapping
**/
@:default(true) @:optional var formatStringInterpolation:Bool;

/**
ensure a space after '//'
**/
@:default(true) @:optional var addLineCommentSpace:Bool;
}

typedef ParenWhitespaceConfig = {
Expand Down
5 changes: 4 additions & 1 deletion src/formatter/marker/MarkTokenText.hx
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ class MarkTokenText extends MarkerBase {
if (~/^[\/\*\-\s]+/.match(text)) {
return "//" + text.rtrim();
}
return "// " + text.trim();
if (config.whitespace.addLineCommentSpace) {
return "// " + text.trim();
}
return "//" + text.trim();
}
}
14 changes: 7 additions & 7 deletions test/testcases/emptylines/line_comments_between_types.hxtest
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@

---

// class Main {
//class Main {
class Main {}

// class Main {
//class Main {
typedef Main = String;
// class Main {
//class Main {

class Main {}

// class Main {
// }
//class Main {
//}
typedef Main = String;
// class Main {
// }
//class Main {
//}

---

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"whitespace" : {
"addLineCommentSpace": false
}
}

---

//class Main {
class Main {}

//class Main {
typedef Main = String;
//class Main {

class Main {}

//class Main {
//}
typedef Main = String;
//class Main {
//}

---

//class Main {

class Main {}

//class Main {

typedef Main = String;

//class Main {

class Main {}

//class Main {
//}

typedef Main = String;

//class Main {
//}
27 changes: 27 additions & 0 deletions test/testcases/whitespace/single_line_comments_no_space.hxtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"whitespace" : {
"addLineCommentSpace": false
}
}

---

class Main{
//*************************
// Test
// Test
//Test
///////////////////////////
static function main(){}
}

---

class Main {
//*************************
// Test
// Test
//Test
///////////////////////////
static function main() {}
}

0 comments on commit 1419ee6

Please sign in to comment.