Skip to content

Commit

Permalink
added wraaping location to allow wrapiping before delimiter, fixes Ha…
Browse files Browse the repository at this point in the history
…xeCheckstyle#299

fixed anon types and leftCurly=both, fixes HaxeCheckstyle#301
fixed same line handling of expressionIf, fixes HaxeCheckstyle#304
fixed indentation of object literals, fixes HaxeCheckstyle#305
fixed same line handling of cases with object patterns, fixes HaxeCheckstyle#306
fixed empty line after class metadata with function, fixes HaxeCheckstyle#307
fixed missing space between Comman and POpen, fixes HaxeCheckstyle#308
refactored to increase null safety
  • Loading branch information
AlexHaxe committed Feb 3, 2019
1 parent a050be8 commit 950d6f5
Show file tree
Hide file tree
Showing 44 changed files with 1,146 additions and 235 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@
- Added haxe-test-adapter [#286](https://github.com/HaxeCheckstyle/haxe-formatter/issues/286) + [#287](https://github.com/HaxeCheckstyle/haxe-formatter/issues/287) + [#289](https://github.com/HaxeCheckstyle/haxe-formatter/issues/289)
- Added `wrapping.implementsExtends` [#288](https://github.com/HaxeCheckstyle/haxe-formatter/issues/288)
- Added `emptylines.afterFileHeaderComment`and `emptylines.betweenMultilineComments` fixes [#292](https://github.com/HaxeCheckstyle/haxe-formatter/issues/292) ([#296](https://github.com/HaxeCheckstyle/haxe-formatter/issues/296))
- Added wrapping location to allow wrapping before delimiting token, fixes [#299](https://github.com/HaxeCheckstyle/haxe-formatter/issues/299) ()
- Fixed whitespace of type check in array comprehension, fixes [#284](https://github.com/HaxeCheckstyle/haxe-formatter/issues/284) ([#285](https://github.com/HaxeCheckstyle/haxe-formatter/issues/285))
- Fixed conditional modifier handling, fixes [#291](https://github.com/HaxeCheckstyle/haxe-formatter/issues/291) ([#293](https://github.com/HaxeCheckstyle/haxe-formatter/issues/293))
- Fixed whitespace after left curly in anon type hints [#297](https://github.com/HaxeCheckstyle/haxe-formatter/issues/297)
- Fixed anon types handling when `leftCurly` is set to `both`, fixes [#301](https://github.com/HaxeCheckstyle/haxe-formatter/issues/301) ()
- Fixed same line handling of `expressionIf`, fixes [#304](https://github.com/HaxeCheckstyle/haxe-formatter/issues/304) ()
- Fixed indentation of object literals, fixes [#305](https://github.com/HaxeCheckstyle/haxe-formatter/issues/305) ()
- Fixed same line handling of cases with object pattern, fixes [#306](https://github.com/HaxeCheckstyle/haxe-formatter/issues/306) ()
- Fixed empty line after metadata with function, fixes [#307](https://github.com/HaxeCheckstyle/haxe-formatter/issues/307) ()
- Fixed missing space before `(`, fixes [#308](https://github.com/HaxeCheckstyle/haxe-formatter/issues/308) ()
- Removed stacktrace from output with invalid `hxformat.json` files, fixes [#300](https://github.com/HaxeCheckstyle/haxe-formatter/issues/300) ()

## version 1.3.0 (2018-12-05)

Expand Down
2 changes: 2 additions & 0 deletions buildCommon.hxml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
-lib json2object
-lib hxargs
-lib compiletime
-lib safety

-cp src

-main formatter.Cli
# --macro nullSafety('formatter')
1 change: 1 addition & 0 deletions buildSchema.hxml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
-lib hxparse
-lib json2object
-lib hxargs
-lib safety

-cp src
-cp schema
Expand Down
1 change: 1 addition & 0 deletions buildTest.hxml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
-lib mcover
-lib munit
-lib compiletime
-lib safety
-lib haxe-test-adapter

# -D debugLog
Expand Down
1 change: 1 addition & 0 deletions display.hxml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
-lib mcover
-lib munit
-lib compiletime
-lib safety
-lib haxe-test-adapter
22 changes: 20 additions & 2 deletions resources/formatter-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"propertyOrder": 1
},
"conditionalPolicy": {
"description": "only applies to non inlined conditionals\n\t\t\"fixedZero\" = all conditional statements should start in column 1\n\t\t\"aligned\" = conditional statements share indentation of surrounding code\n\t\t\"alignedIncrease\" = same as \"aligned\" but will increase indent by +1 for enclosed code",
"description": "only applies to non inlined conditionals\n\t\t\"fixedZero\" = all conditional statements should start in column 1\n\t\t\"aligned\" = conditional statements share indentation of surrounding code\n\t\t\"alignedIncrease\" = same as \"aligned\" but will increase indent by +1 for enclosed code\n\t\t\"alignedDecrease\" = same as \"aligned\" but will decrease indent by -1 for enclosed code",
"type": "string",
"enum": [
"fixedZero",
Expand Down Expand Up @@ -143,10 +143,19 @@
],
"propertyOrder": 1
},
"defaultLocation": {
"description": "default wrapping location before / after last token",
"type": "string",
"enum": [
"beforeLast",
"afterLast"
],
"propertyOrder": 2
},
"defaultAdditionalIndent": {
"description": "adds indentation to all wrapped lines when applying defaultWrap",
"type": "integer",
"propertyOrder": 2
"propertyOrder": 3
},
"rules": {
"description": "list of wrapping rules\n\t\twrapping uses only the first rule whose conditions evaluates to true",
Expand Down Expand Up @@ -369,6 +378,15 @@
"additionalIndent": {
"description": "adds indentation to all wrapped lines",
"type": "integer",
"propertyOrder": 3
},
"location": {
"description": "default wrapping location before / after last token",
"type": "string",
"enum": [
"beforeLast",
"afterLast"
],
"propertyOrder": 2
},
"type": {
Expand Down
1 change: 1 addition & 0 deletions schema/import.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
using Safety;
6 changes: 4 additions & 2 deletions src/formatter/Cli.hx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class Cli {
#end

if (Sys.getEnv("HAXELIB_RUN") == "1") {
Sys.setCwd(args.pop());
if (args.length > 0) {
Sys.setCwd(args.pop().unsafe());
}
}

var paths = [];
Expand Down Expand Up @@ -167,7 +169,7 @@ class Cli {
}
case Failure(errorMessage):
FormatStats.incFailed();
Sys.stderr().writeString('Failed to format $path: $errorMessage');
Sys.stderr().writeString('Failed to format $path: $errorMessage\n');
exitCode = 1;
case Disabled:
FormatStats.incDisabled();
Expand Down
8 changes: 6 additions & 2 deletions src/formatter/Formatter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ class Formatter {
var config:Config = loadConfig(file.name);
return formatFileWithConfig(file, config, tokenData);
} catch (e:Any) {
#if debug
var callstack = CallStack.toString(CallStack.exceptionStack());
return Failure(e + "\n" + callstack + "\n\n");
#else
return Failure(e);
#end
}
}

Expand Down Expand Up @@ -66,7 +70,7 @@ class Formatter {
markWrapping.run();
markEmptyLines.run();

markTokenText.finalRun(null);
markTokenText.finalRun();

var lines:CodeLines = new CodeLines(parsedCode, indenter);
lines.applyWrapping(config.wrapping);
Expand All @@ -83,7 +87,7 @@ class Formatter {

function loadConfig(fileName:String):Config {
var config:Config = new Config();
var configFileName:String = determineFormatterConfig(fileName);
var configFileName:Null<String> = determineFormatterConfig(fileName);
if (configFileName == null) {
return config;
}
Expand Down
4 changes: 2 additions & 2 deletions src/formatter/codedata/CodeLine.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import formatter.marker.Indenter;

class CodeLine {
var parts:Array<CodePart>;
var currentPart:CodePart;
var currentPart:Null<CodePart>;

public var indent:Int;
public var emptyLinesAfter:Int;
Expand All @@ -31,7 +31,7 @@ class CodeLine {
firstLineLength: -1,
lastLineLength: -1
};
parts.push(currentPart);
parts.push(currentPart.unsafe());
}
currentPart.lastToken = tokenInfo.token;
if ((tokenInfo.whitespaceAfter == Space) && (tokenInfo.spacesAfter > 0)) {
Expand Down
2 changes: 1 addition & 1 deletion src/formatter/codedata/CodeLines.hx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CodeLines {
}

function buildLines() {
var line:CodeLine = null;
var line:Null<CodeLine> = null;
var index:Int = 0;
while (index < parsedCode.tokenList.tokens.length) {
var tokenInfo:TokenInfo = parsedCode.tokenList.getTokenAt(index);
Expand Down
Loading

0 comments on commit 950d6f5

Please sign in to comment.