Skip to content

Commit

Permalink
fixed metadata whitespace, fixes #263 (#265)
Browse files Browse the repository at this point in the history
* fixed metadata whitespace, fixes #263
* use stderr for error messages, fixes #262
* fixed index out of bound, fixes #203
  • Loading branch information
AlexHaxe authored Nov 6, 2018
1 parent 7e27b6c commit af5f8a1
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 6 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
- Fixed sameline options for `sameLine.caseBody` and `sameLine.expressionCase` [#250](https://github.com/HaxeCheckstyle/haxe-formatter/issues/250)
- Fixed conditional indentation with `indentation.conditionalPolicy` set to `alignedIncrease` [#253](https://github.com/HaxeCheckstyle/haxe-formatter/issues/253)
- Fixed truncation of interface conditionals extends, fixes [#259](https://github.com/HaxeCheckstyle/haxe-formatter/issues/259) ([#260](https://github.com/HaxeCheckstyle/haxe-formatter/issues/260))
- Fixed multiline string interpolation, fixes #261 ([#264](https://github.com/HaxeCheckstyle/haxe-formatter/issues/264))
- Fixed multiline string interpolation, fixes [#261](https://github.com/HaxeCheckstyle/haxe-formatter/issues/261), fixes [#203](https://github.com/HaxeCheckstyle/haxe-formatter/issues/203) ([#264](https://github.com/HaxeCheckstyle/haxe-formatter/issues/264) + [#265](https://github.com/HaxeCheckstyle/haxe-formatter/issues/265))
- Fixed send error messages to stderr, fixes [#262](https://github.com/HaxeCheckstyle/haxe-formatter/issues/262) ([#265](https://github.com/HaxeCheckstyle/haxe-formatter/issues/265))
- Fixed metadata whitespace, fixes [#263](https://github.com/HaxeCheckstyle/haxe-formatter/issues/263) ([#265](https://github.com/HaxeCheckstyle/haxe-formatter/issues/265))
- Changed `sameLine.expressionCase` to `keep` [#250](https://github.com/HaxeCheckstyle/haxe-formatter/issues/250)
- Refactored call and parameter wrapping [#247](https://github.com/HaxeCheckstyle/haxe-formatter/issues/247)
- Refactored method chain wrapping [#247](https://github.com/HaxeCheckstyle/haxe-formatter/issues/247)
Expand Down
4 changes: 2 additions & 2 deletions src/formatter/Cli.hx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Cli {
try {
argHandler.parse(args);
} catch (e:Any) {
Sys.println(e + "\n");
Sys.stderr().writeString(e + "\n");
printHelp();
Sys.exit(1);
}
Expand Down Expand Up @@ -167,7 +167,7 @@ class Cli {
}
case Failure(errorMessage):
FormatStats.incFailed();
Sys.println('Failed to format $path: $errorMessage');
Sys.stderr().writeString('Failed to format $path: $errorMessage');
exitCode = 1;
case Disabled:
FormatStats.incDisabled();
Expand Down
3 changes: 3 additions & 0 deletions src/formatter/marker/MarkSameLine.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ class MarkSameLine extends MarkerBase {
markDollarSameLine();

parsedCode.root.filterCallback(function(token:TokenTree, index:Int):FilterResult {
if ((token.parent != null) && (token.parent.is(At))) {
return GO_DEEPER;
}
switch (token.tok) {
case Kwd(KwdIf):
markIf(token);
Expand Down
4 changes: 1 addition & 3 deletions src/formatter/marker/MarkTokenText.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import haxeparser.HaxeLexer;
import tokentree.TokenStreamProgress;
import tokentree.walk.WalkStatement;
import tokentree.TokenStream;
import formatter.config.Config;
import formatter.config.IndentationConfig;
import formatter.codedata.CodeLines;
import formatter.codedata.ParseFile;
import formatter.codedata.ParsedCode;
Expand Down Expand Up @@ -58,7 +56,7 @@ class MarkTokenText extends MarkerBase {
continue;
}
var formatted:String = formatFragment(fragment);
start += formatted.length - fragment.length;
start += formatted.length;
text = text.substr(0, index + 2) + formatted + text.substr(indexEnd);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/formatter/marker/MarkWhitespace.hx
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ class MarkWhitespace extends MarkerBase {
prev.whitespaceAfter = Space;
case Const(_):
prev.whitespaceAfter = Space;
case At:
return;
default:
}
}
Expand Down
20 changes: 20 additions & 0 deletions test/testcases/whitespace/issue_263_metatdata_do.hxtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{}


---


class Main {
function loadAndTrace() {
@when(connectionEstablished) @do(cnx) cnx.send(message);
}
}


---

class Main {
function loadAndTrace() {
@when(connectionEstablished) @do(cnx) cnx.send(message);
}
}

0 comments on commit af5f8a1

Please sign in to comment.