From 9a732e5a2be40fd726a07680a7bf88a9ac0b301c Mon Sep 17 00:00:00 2001 From: AlexHaxe Date: Tue, 19 Mar 2019 23:42:23 +0100 Subject: [PATCH] fixed conditionals in arguments with question mark, fixes #397 --- CHANGELOG.md | 9 ++++++--- src/formatter/marker/MarkWhitespace.hx | 5 ++++- ...e_397_conditionals_in_function_args.hxtest | 20 +++++++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 test/testcases/whitespace/issue_397_conditionals_in_function_args.hxtest diff --git a/CHANGELOG.md b/CHANGELOG.md index fb61e567..134bf2d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,16 +2,19 @@ ## dev branch / next version (1.x.x) -## version 1.5.1 (2019-03-06) - -- Fixed vanishing string literals at end of file ([#391](https://github.com/HaxeCheckstyle/haxe-formatter/issues/391)) - Fixed specifiying an entry point for tokentree, fixes [#393](https://github.com/HaxeCheckstyle/haxe-formatter/issues/393) +- Fixed whitespace for conditionals in function arguments with question mark, fixes [#397](https://github.com/HaxeCheckstyle/haxe-formatter/issues/397) +- Fixed unary OpSub in arrays - Changed default value for `excludes` to include `.git` folders ([#399](https://github.com/HaxeCheckstyle/haxe-formatter/issues/399)) - Changed using comma as an indicator for simple wrapping ([#403](https://github.com/HaxeCheckstyle/haxe-formatter/issues/403)) - Changed formatter api calls, fixes [#393](https://github.com/HaxeCheckstyle/haxe-formatter/issues/393) ([#403](https://github.com/HaxeCheckstyle/haxe-formatter/issues/403)) - Changed command line help text, fixes [#400](https://github.com/HaxeCheckstyle/haxe-formatter/issues/400) ([#402](https://github.com/HaxeCheckstyle/haxe-formatter/issues/402)) - Replaced custom schema generator with json2objects ([#398](https://github.com/HaxeCheckstyle/haxe-formatter/issues/398)) +## version 1.5.1 (2019-03-06) + +- Fixed vanishing string literals at end of file ([#391](https://github.com/HaxeCheckstyle/haxe-formatter/issues/391)) + ## version 1.5.0 (2019-03-04) - Added `wrapping.opAddSubChain` ([#370](https://github.com/HaxeCheckstyle/haxe-formatter/issues/370)) diff --git a/src/formatter/marker/MarkWhitespace.hx b/src/formatter/marker/MarkWhitespace.hx index f1d42795..25bfee3f 100644 --- a/src/formatter/marker/MarkWhitespace.hx +++ b/src/formatter/marker/MarkWhitespace.hx @@ -245,6 +245,9 @@ class MarkWhitespace extends MarkerBase { case Const(CIdent(_)): whitespace(token, After); return; + case Question: + whitespace(token, After); + return; default: } } @@ -399,7 +402,7 @@ class MarkWhitespace extends MarkerBase { if (next != null) { switch (next.token.tok) { case Comma, Semicolon: - case Const(_), Kwd(_), POpen, BrOpen, BkOpen: + case Const(_), Kwd(_), POpen, BrOpen, BkOpen, Question: whitespace(token, After); default: } diff --git a/test/testcases/whitespace/issue_397_conditionals_in_function_args.hxtest b/test/testcases/whitespace/issue_397_conditionals_in_function_args.hxtest new file mode 100644 index 00000000..c7b05c85 --- /dev/null +++ b/test/testcases/whitespace/issue_397_conditionals_in_function_args.hxtest @@ -0,0 +1,20 @@ +{} + + +--- + +class Main { + static function foo(#if false bar:Int, #else baz:int, #end foobar:Int) {} + static function foo(#if false ?bar:Int, #end ?foobar:Int) {} + static function foo(#if false ?bar:Int, #else ?baz:Int, #end ?foobar:Int) {} +} + +--- + +class Main { + static function foo(#if false bar:Int, #else baz:int, #end foobar:Int) {} + + static function foo(#if false ?bar:Int, #end ?foobar:Int) {} + + static function foo(#if false ?bar:Int, #else ?baz:Int, #end ?foobar:Int) {} +}