From 9a9ee35fe7db1c479aae14c1e0f65f59c0b8aa90 Mon Sep 17 00:00:00 2001 From: AlexHaxe Date: Sat, 27 Aug 2022 23:57:43 +0200 Subject: [PATCH] added support for inline markup, fixes #523, fixes #624 (#655) * added support for inline markup, fixes #523, fixes #624 --- .haxerc | 2 +- CHANGELOG.md | 4 + haxe_libraries/tokentree.hxml | 6 +- haxelib.json | 4 +- package-lock.json | 4 +- package.json | 2 +- src/formatter/codedata/ParsedCode.hx | 9 +++ src/formatter/import.hx | 2 +- test/TestCaseMacro.hx | 6 +- test/testcases/other/inline_markup.hxtest | 76 +++++++++++++++++++ .../other/issue_523_inline_markup.hxtest | 50 ++++++++++++ .../other/issue_624_inline_markup.hxtest | 33 ++++++++ 12 files changed, 185 insertions(+), 13 deletions(-) create mode 100644 test/testcases/other/inline_markup.hxtest create mode 100644 test/testcases/other/issue_523_inline_markup.hxtest create mode 100644 test/testcases/other/issue_624_inline_markup.hxtest diff --git a/.haxerc b/.haxerc index ec50a4f8..bb6b6589 100644 --- a/.haxerc +++ b/.haxerc @@ -1,4 +1,4 @@ { - "version": "651ecf3", + "version": "779b005", "resolveLibs": "scoped" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bd3ab1a..f0641350 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## dev branch / next version (1.x.x) +## version 1.14.0 (2022-08-27) + +- Added support for inline markup, fixes [#523](https://github.com/HaxeCheckstyle/haxe-formatter/issues/523) + [#624](https://github.com/HaxeCheckstyle/haxe-formatter/issues/624) ([#655](https://github.com/HaxeCheckstyle/haxe-formatter/issues/655)) + ## version 1.13.1 (2022-04-26) - Fixed conditional line ends / wrapping ([#654](https://github.com/HaxeCheckstyle/haxe-formatter/issues/654)) diff --git a/haxe_libraries/tokentree.hxml b/haxe_libraries/tokentree.hxml index ea3e15c4..cd40b7e8 100644 --- a/haxe_libraries/tokentree.hxml +++ b/haxe_libraries/tokentree.hxml @@ -1,3 +1,3 @@ -# @install: lix --silent download "haxelib:/tokentree#1.1.2" into tokentree/1.1.2/haxelib --cp ${HAXE_LIBCACHE}/tokentree/1.1.2/haxelib/src --D tokentree=1.1.2 \ No newline at end of file +# @install: lix --silent download "haxelib:/tokentree#1.2.0" into tokentree/1.2.0/haxelib +-cp ${HAXE_LIBCACHE}/tokentree/1.2.0/haxelib/src +-D tokentree=1.2.0 \ No newline at end of file diff --git a/haxelib.json b/haxelib.json index 9dccc49f..b1931d37 100644 --- a/haxelib.json +++ b/haxelib.json @@ -8,8 +8,8 @@ "style" ], "description": "A code formatter for Haxe", - "version": "1.13.1", - "releasenote": "fixed conditional line ends / wrapping, fixed whitespace after from/to with arrow functions - see CHANGELOG for details.", + "version": "1.14.0", + "releasenote": "added support for inline markup - see CHANGELOG for details.", "contributors": [ "AlexHaxe", "Gama11" diff --git a/package-lock.json b/package-lock.json index 7b672ad4..051e2953 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@haxecheckstyle/haxe-formatter", - "version": "1.13.1", + "version": "1.14.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@haxecheckstyle/haxe-formatter", - "version": "1.13.1", + "version": "1.14.0", "license": "MIT", "bin": { "haxe-formatter": "bin/formatter.js" diff --git a/package.json b/package.json index 25de5820..f5c3a4e1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@haxecheckstyle/haxe-formatter", - "version": "1.13.1", + "version": "1.14.0", "description": "A code formatter for Haxe", "repository": { "type": "git", diff --git a/src/formatter/codedata/ParsedCode.hx b/src/formatter/codedata/ParsedCode.hx index fa8f2296..fecca492 100644 --- a/src/formatter/codedata/ParsedCode.hx +++ b/src/formatter/codedata/ParsedCode.hx @@ -72,6 +72,15 @@ class ParsedCode { skipCount = 1; case Binop(OpGte): skipCount = 1; + case Const(CMarkup(_)): + var skipIndex = index + 1; + while (true) { + if (tokens[skipIndex].pos.min >= token.pos.max) { + break; + } + skipCount++; + skipIndex++; + } case Const(CInt(v)): if (v.startsWith("-")) { skipCount = 1; diff --git a/src/formatter/import.hx b/src/formatter/import.hx index 4f05fad8..ef92f20e 100644 --- a/src/formatter/import.hx +++ b/src/formatter/import.hx @@ -1,9 +1,9 @@ package formatter; #if (tokentree && !macro) -import byte.ByteData; import haxe.io.Bytes; import haxe.macro.Expr; +import byte.ByteData; import haxeparser.Data; import tokentree.TokenTree; import tokentree.TokenTreeAccessHelper; diff --git a/test/TestCaseMacro.hx b/test/TestCaseMacro.hx index a249a3a7..57b4792f 100644 --- a/test/TestCaseMacro.hx +++ b/test/TestCaseMacro.hx @@ -1,8 +1,8 @@ -import haxe.macro.Expr; -import haxe.macro.Context; import haxe.io.Path; -import sys.io.File; +import haxe.macro.Context; +import haxe.macro.Expr; import sys.FileSystem; +import sys.io.File; class TestCaseMacro { #if macro diff --git a/test/testcases/other/inline_markup.hxtest b/test/testcases/other/inline_markup.hxtest new file mode 100644 index 00000000..509e5c77 --- /dev/null +++ b/test/testcases/other/inline_markup.hxtest @@ -0,0 +1,76 @@ +{} + +--- + +function inline_markup() { + + + static var SRC = + + @exampleText("!") + + + ; + + super (); + super (); + + ; + ; + ; + +
; + $${x < foo ? "a" : "b"}; + + ; + ; + + ; + ; + + static var SRC = + for( x in arr ) + + for( y in arr ) { + + + } + +} + +--- + +function inline_markup() { + + + static var SRC = + @exampleText("!") + + + ; + + super(); + super(); + + ; + ; + ; + +
; + $${x < foo ? "a" : "b"}; + + ; + ; + + ; + ; + + static var SRC = + for( x in arr ) + + for( y in arr ) { + + + } + +} diff --git a/test/testcases/other/issue_523_inline_markup.hxtest b/test/testcases/other/issue_523_inline_markup.hxtest new file mode 100644 index 00000000..3fb33df1 --- /dev/null +++ b/test/testcases/other/issue_523_inline_markup.hxtest @@ -0,0 +1,50 @@ +{ + "indentation": { + "character": " " + }, + "sameLine": { + "ifBody": "keep", + "elseIf": "keep", + "elseBody": "keep", + "forBody": "keep", + "whileBody": "keep" + } +} + +--- + +class Test { + function main() { + final user = "usr"; + + XmlTools.toString( + + + + ${user} + + + + + + ); + } +} + +--- + +class Test { + function main() { + final user = "usr"; + + XmlTools.toString( + + + ${user} + + + + + ); + } +} diff --git a/test/testcases/other/issue_624_inline_markup.hxtest b/test/testcases/other/issue_624_inline_markup.hxtest new file mode 100644 index 00000000..719df756 --- /dev/null +++ b/test/testcases/other/issue_624_inline_markup.hxtest @@ -0,0 +1,33 @@ +{} + +--- + +// https://heaps.io/documentation/domkit.html +class SampleView extends h2d.Flow implements h2d.domkit.Object { + + static var SRC = + + Hello World! + + + + public function new(tile:h2d.Tile,?parent) { + super(parent); + initComponent(); + } +} + +--- + +// https://heaps.io/documentation/domkit.html +class SampleView extends h2d.Flow implements h2d.domkit.Object { + static var SRC = + Hello World! + + + + public function new(tile:h2d.Tile, ?parent) { + super(parent); + initComponent(); + } +}