Skip to content

Commit

Permalink
fixed overload support, fixes #626 (#627)
Browse files Browse the repository at this point in the history
* fixed overload support, fixes #626
* updated to latest haxeparser and tokentreee
* retired Haxe 3.4.7 compilation support
  • Loading branch information
AlexHaxe authored Dec 20, 2020
1 parent fdd1fba commit 066f8c5
Show file tree
Hide file tree
Showing 33 changed files with 139 additions and 130 deletions.
26 changes: 8 additions & 18 deletions .github/workflows/formatter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
build:
strategy:
matrix:
haxe-version: ['3.4.7', '4.0.5', '4.1.4', 'nightly']
haxe-version: ['4.0.5', '4.1.4', 'nightly']
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
Expand All @@ -33,11 +33,6 @@ jobs:
run: |
npx lix download haxe ${{ matrix.haxe-version }}
npx lix use haxe ${{ matrix.haxe-version }}
- name: Prepare Haxe 3 dependencies
if: matrix.haxe-version == '3.4.7'
run: |
mv haxe_libraries haxe4_libraries
mv haxe3_libraries haxe_libraries
- name: Run lix download
run: npx lix download
- name: Print versions
Expand All @@ -55,14 +50,9 @@ jobs:
run: npx haxe buildJava.hxml
- name: Build JSON schema
run: npx haxe buildSchema.hxml
- name: Run Neko tests
if: matrix.haxe-version == '3.4.7'
run: npx haxe -D codecov_json test.hxml
- name: Run eval tests
if: (matrix.haxe-version != '3.4.7' && matrix.haxe-version != 'nightly')
run: npx haxe -D codecov_json test.hxml
- name: Run Java tests
if: matrix.haxe-version != 'nightly'
run: npx haxe -D codecov_json testJava.hxml
- name: Run Node version with --check
run: node run.js -s . --check
Expand All @@ -75,12 +65,12 @@ jobs:
run: |
rm run.js
npx neko run.n -s . --check
- name: publish artifacts
if: (matrix.haxe-version == '4.1.4' && matrix.platform == 'ubuntu-latest')
uses: actions/upload-artifact@v2
with:
name: formatter.js
path: bin/formatter.js
# - name: publish artifacts
# if: (matrix.haxe-version == '4.1.4' && matrix.platform == 'ubuntu-latest')
# uses: actions/upload-artifact@v2
# with:
# name: formatter.js
# path: bin/formatter.js
- name: Upload results to codecov
if: success() && matrix.platform == 'ubuntu-latest' && (matrix.haxe-version == '3.4.7' || matrix.haxe-version == '4.1.4')
if: success() && matrix.platform == 'ubuntu-latest' && (matrix.haxe-version == '4.1.4')
run: bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports"
7 changes: 2 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ node_js:
dist: xenial

env:
- HAXE_VERSION=haxe347
- HAXE_VERSION=haxe4
- HAXE_VERSION=nightly

install:
- npm install
- if [[ "$HAXE_VERSION" == "haxe347" ]]; then mv haxe_libraries haxe4_libraries; mv haxe3_libraries haxe_libraries; fi
- if [[ "$HAXE_VERSION" == "haxe347" ]]; then npx lix download haxe 3.4.7; npx lix use haxe 3.4.7; fi
- if [[ "$HAXE_VERSION" == "haxe4" ]]; then npx lix download haxe 4.1.4; npx lix use haxe 4.1.4; fi
- if [[ "$HAXE_VERSION" == "nightly" ]]; then npx lix download haxe nightly; npx lix use haxe nightly; fi
- npx lix download
Expand All @@ -26,8 +23,8 @@ script:
- npx haxe buildNeko.hxml
- npx haxe buildJava.hxml
- npx haxe buildSchema.hxml
- if [[ "$HAXE_VERSION" != "nightly" ]]; then npx haxe test.hxml -D codecov_json; fi
- if [[ "$HAXE_VERSION" != "nightly" ]]; then npx haxe testJava.hxml -D codecov_json; fi
- npx haxe test.hxml -D codecov_json
- npx haxe testJava.hxml -D codecov_json
- node run.js -s . --check
- java -jar out/Cli.jar -s . --check
- neko run.n -s . --check
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## dev branch / next version (1.x.x)

- Fixed support for overload access modifier, fixes [#626](https://github.com/HaxeCheckstyle/haxe-formatter/issues/626) ([#627](https://github.com/HaxeCheckstyle/haxe-formatter/issues/627))
- Retired Haxe 3.4.7 compile support ([#627](https://github.com/HaxeCheckstyle/haxe-formatter/issues/627))

## version 1.11.2 (2020-11-04)

- Fixed array type parameter, fixes [#622](https://github.com/HaxeCheckstyle/haxe-formatter/issues/622) ([#623](https://github.com/HaxeCheckstyle/haxe-formatter/issues/623))
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ haxelib install formatter
- Run `haxelib run formatter -s src` to format folder `src`.
- Run `haxelib run formatter -s src -s test` to format folders `src` and `test`.

If the `node` command is available on your system, the formatter automatically uses its NodeJS version instead of a Neko build (which is considerably faster).
Note: haxelib version of formatter comes with both a NodeJS and a Neko version. when running `haxelib run formatter` it always launches Neko version (`run.n`). however Neko version will check for NodeJS (simply by calling `node -v` and checking its exit code). if you have NodeJS installed and working, then it will spawn a new process running `run.js` and passing all of your command line parameters to it. so you might end up running Neko or NodeJS versions of formatter depending on your system setup and installed software.
NodeJS version is noticeably faster than Neko. so it's the preferred version to run when bulk formatting larger code bases.
if you see dramatically slower performance when formatting the same codebase on multiple machines, it might be caused by one of the systems not being able to switch to NodeJS version and doing all the work in Neko instead.

### Single File Formatting

Expand Down
3 changes: 0 additions & 3 deletions haxe3_libraries/exception.hxml

This file was deleted.

4 changes: 0 additions & 4 deletions haxe3_libraries/haxeparser.hxml

This file was deleted.

3 changes: 0 additions & 3 deletions haxe3_libraries/hxargs.hxml

This file was deleted.

4 changes: 0 additions & 4 deletions haxe3_libraries/hxcpp.hxml

This file was deleted.

5 changes: 0 additions & 5 deletions haxe3_libraries/hxjava.hxml

This file was deleted.

3 changes: 0 additions & 3 deletions haxe3_libraries/hxjsonast.hxml

This file was deleted.

6 changes: 0 additions & 6 deletions haxe3_libraries/hxnodejs.hxml

This file was deleted.

3 changes: 0 additions & 3 deletions haxe3_libraries/hxparse.hxml

This file was deleted.

4 changes: 0 additions & 4 deletions haxe3_libraries/json2object.hxml

This file was deleted.

3 changes: 0 additions & 3 deletions haxe3_libraries/mconsole.hxml

This file was deleted.

5 changes: 0 additions & 5 deletions haxe3_libraries/mcover.hxml

This file was deleted.

4 changes: 0 additions & 4 deletions haxe3_libraries/mlib.hxml

This file was deleted.

6 changes: 0 additions & 6 deletions haxe3_libraries/munit.hxml

This file was deleted.

4 changes: 0 additions & 4 deletions haxe3_libraries/safety.hxml

This file was deleted.

5 changes: 0 additions & 5 deletions haxe3_libraries/test-adapter.hxml

This file was deleted.

3 changes: 0 additions & 3 deletions haxe3_libraries/tokentree.hxml

This file was deleted.

4 changes: 2 additions & 2 deletions haxe_libraries/haxeparser.hxml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @install: lix --silent download "gh://github.com/simn/haxeparser#00b509e8690300ca6366aa8d0d4d97bd29fbcf2b" into haxeparser/3.3.0/github/00b509e8690300ca6366aa8d0d4d97bd29fbcf2b
# @install: lix --silent download "gh://github.com/Simn/haxeparser#7649b016b86ff16676110a7cddcbe186a5101ca6" into haxeparser/3.3.0/github/7649b016b86ff16676110a7cddcbe186a5101ca6
-lib hxparse
-cp ${HAXE_LIBCACHE}/haxeparser/3.3.0/github/00b509e8690300ca6366aa8d0d4d97bd29fbcf2b/src
-cp ${HAXE_LIBCACHE}/haxeparser/3.3.0/github/7649b016b86ff16676110a7cddcbe186a5101ca6/src
-D haxeparser=3.3.0
6 changes: 3 additions & 3 deletions haxe_libraries/hxparse.hxml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-D hxparse=4.0.0
# @install: lix --silent download "gh://github.com/Simn/hxparse#f61faa2021f2abb85360f997ff72c4156c891adc" into hxparse/4.0.0/github/f61faa2021f2abb85360f997ff72c4156c891adc
-cp ${HAXE_LIBCACHE}/hxparse/4.0.0/github/f61faa2021f2abb85360f997ff72c4156c891adc/src
# @install: lix --silent download "gh://github.com/Simn/hxparse#93f67419852e96daa2b81901c43a77e878c8c2bc" into hxparse/4.0.1/github/93f67419852e96daa2b81901c43a77e878c8c2bc
-cp ${HAXE_LIBCACHE}/hxparse/4.0.1/github/93f67419852e96daa2b81901c43a77e878c8c2bc/src
-D hxparse=4.0.1
4 changes: 2 additions & 2 deletions haxe_libraries/json2object.hxml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @install: lix --silent download "haxelib:/json2object#3.8.1" into json2object/3.8.1/haxelib
# @install: lix --silent download "gh://github.com/elnabo/json2object#a6845b4826151271dd34c69631ffda0886abd562" into json2object/3.8.1/github/a6845b4826151271dd34c69631ffda0886abd562
-lib hxjsonast
-cp ${HAXE_LIBCACHE}/json2object/3.8.1/haxelib/src
-cp ${HAXE_LIBCACHE}/json2object/3.8.1/github/a6845b4826151271dd34c69631ffda0886abd562/src
-D json2object=3.8.1
8 changes: 3 additions & 5 deletions haxe_libraries/munit.hxml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# @install: lix --silent download "haxelib:/munit#2.3.4" into munit/2.3.4/haxelib
# @run: haxelib run-dir munit ${HAXE_LIBCACHE}/munit/2.3.4/haxelib
-lib mcover
# @install: lix --silent download "gh://github.com/AlexHaxe/MassiveUnit#645952947a10d27f2460321eb9c6c9e2a93b997d" into MassiveUnit/0.0.0/github/645952947a10d27f2460321eb9c6c9e2a93b997d
-lib mlib
-cp ${HAXE_LIBCACHE}/munit/2.3.4/haxelib/
-D munit=2.3.4
-cp ${HAXE_LIBCACHE}/MassiveUnit/0.0.0/github/645952947a10d27f2460321eb9c6c9e2a93b997d/src
-D munit=2.3.5
4 changes: 2 additions & 2 deletions haxe_libraries/tokentree.hxml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# @install: lix --silent download "haxelib:/tokentree#1.0.31" into tokentree/1.0.31/haxelib
-cp ${HAXE_LIBCACHE}/tokentree/1.0.31/haxelib/src
# @install: lix --silent download "gh://github.com/HaxeCheckstyle/tokentree#8d317ea6b0c472234c154ce21ec92f2cf1629d3e" into tokentree/1.0.31/github/8d317ea6b0c472234c154ce21ec92f2cf1629d3e
-cp ${HAXE_LIBCACHE}/tokentree/1.0.31/github/8d317ea6b0c472234c154ce21ec92f2cf1629d3e/src
-D tokentree=1.0.31
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/formatter/codedata/ParsedCode.hx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package formatter.codedata;

import haxeparser.HaxeLexer;
import hxparse.ParserError;
import tokentree.TokenTreeBuilder;

class ParsedCode {
Expand Down Expand Up @@ -257,6 +258,10 @@ class ParsedCode {
tokens.push(t);
t = lexer.token(haxeparser.HaxeLexer.tok);
}
} catch (e:ParserError) {
throw 'failed to make tokens - ParserError: $e (${e.pos})';
} catch (e:LexerError) {
throw 'failed to make tokens - LexerError: ${e.msg} (${e.pos})';
} catch (e:Any) {
throw 'failed to make tokens $e';
}
Expand Down
3 changes: 0 additions & 3 deletions src/formatter/marker/Indenter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -557,10 +557,7 @@ class Indenter {
return false;
case Kwd(KwdVar):
return true;
case Const(CIdent(MarkEmptyLines.FINAL)):
#if (haxe_ver >= 4.0)
case Kwd(KwdFinal):
#end
case Binop(OpAssign):
return true;
default:
Expand Down
16 changes: 2 additions & 14 deletions src/formatter/marker/MarkEmptyLines.hx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import formatter.codedata.CodeLines;
import formatter.config.EmptyLinesConfig;

class MarkEmptyLines extends MarkerBase {
public static inline var FINAL:String = "final";

public function run() {
keepExistingEmptyLines();

Expand Down Expand Up @@ -259,7 +257,7 @@ class MarkEmptyLines extends MarkerBase {
var block:TokenTree = c.access().firstChild().firstOf(BrOpen).token;
markBeginAndEndType(block, typeConfig.beginType, typeConfig.endType);

var finalTokDef:TokenDef = #if haxe4 Kwd(KwdFinal); #else Const(CIdent(FINAL)); #end
// var finalTokDef:TokenDef = Kwd(KwdFinal);
var fields:Array<TokenTree> = findClassAndAbstractFields(c);
var prevToken:TokenTree = null;
var prevTokenType:TokenFieldType = null;
Expand Down Expand Up @@ -298,7 +296,7 @@ class MarkEmptyLines extends MarkerBase {
var block:TokenTree = c.access().firstChild().firstOf(BrOpen).token;
markBeginAndEndType(block, typeConfig.beginType, typeConfig.endType);

var finalTokDef:TokenDef = #if haxe4 Kwd(KwdFinal); #else Const(CIdent(FINAL)); #end
// var finalTokDef:TokenDef = Kwd(KwdFinal);
var functions:Array<TokenTree> = findClassAndAbstractFields(c);
var prevToken:TokenTree = null;
var prevTokenType:TokenFieldType = null;
Expand All @@ -319,12 +317,8 @@ class MarkEmptyLines extends MarkerBase {
return switch (token.tok) {
case Kwd(KwdFunction), Kwd(KwdVar):
FoundSkipSubtree;
case Const(CIdent(FINAL)):
FoundSkipSubtree;
#if haxe4
case Kwd(KwdFinal):
FoundSkipSubtree;
#end
case At:
SkipSubtree;
default:
Expand Down Expand Up @@ -780,12 +774,8 @@ class MarkEmptyLines extends MarkerBase {
FoundSkipSubtree;
case Kwd(KwdVar), Kwd(KwdFunction):
FoundSkipSubtree;
case Const(CIdent(FINAL)):
FoundSkipSubtree;
#if haxe4
case Kwd(KwdFinal):
FoundSkipSubtree;
#end
default:
GoDeeper;
}
Expand Down Expand Up @@ -994,9 +984,7 @@ class MarkEmptyLines extends MarkerBase {
case Kwd(KwdInterface):
case Kwd(KwdTypedef):
case Const(CIdent(_)):
#if haxe4
case Kwd(KwdFinal):
#end
case Sharp(_):
next = null;
case CommentLine(_):
Expand Down
24 changes: 15 additions & 9 deletions src/formatter/marker/MarkWhitespace.hx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ class MarkWhitespace extends MarkerBase {
case Binop(OpGt):
markGt(token);
case Binop(OpInterval):
whitespace(token, config.whitespace.intervalPolicy);
#if (haxe_ver >= 4.0)
markOpSpread(token);
case Binop(OpIn):
markIn(token);
#end
case Binop(OpMult):
if (TokenTreeCheckUtils.isImport(token.parent)) {
whitespace(token, None);
Expand Down Expand Up @@ -78,8 +76,6 @@ class MarkWhitespace extends MarkerBase {
markSharp(token);
case Semicolon:
markSemicolon(token);
case Const(CIdent(MarkEmptyLines.FINAL)):
whitespace(token, After);
case Const(CIdent("from")), Const(CIdent("to")):
var parent:Null<TokenTree> = token.access().parent().parent().matches(Kwd(KwdAbstract)).token;
if (parent != null) {
Expand All @@ -103,6 +99,20 @@ class MarkWhitespace extends MarkerBase {
});
}

function markOpSpread(token) {
var prev:Null<TokenInfo> = getPreviousToken(token);
var policy:WhitespacePolicy = config.whitespace.intervalPolicy;
if (prev != null) {
policy = switch (prev.token.tok) {
case Comma:
config.whitespace.intervalPolicy.add(Before);
default:
config.whitespace.intervalPolicy;
}
}
whitespace(token, policy);
}

function markGt(token:TokenTree) {
if (TokenTreeCheckUtils.isOpGtTypedefExtension(token)) {
whitespace(token, config.whitespace.typeExtensionPolicy);
Expand Down Expand Up @@ -278,10 +288,6 @@ class MarkWhitespace extends MarkerBase {
whitespace(token, config.whitespace.tryPolicy);
case Kwd(KwdCatch):
whitespace(token, config.whitespace.catchPolicy);
#if (haxe_ver < 4.0)
case Kwd(KwdIn):
markIn(token);
#end
case Kwd(KwdReturn):
whitespace(token, After);
case Kwd(KwdUntyped):
Expand Down
Loading

0 comments on commit 066f8c5

Please sign in to comment.