Skip to content

Commit 3a907da

Browse files
authored
fixed null pointer issues (#666)
* fixed null pointer issues
1 parent 8328457 commit 3a907da

File tree

14 files changed

+339
-86
lines changed

14 files changed

+339
-86
lines changed

.haxerc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"version": "5645ecc",
2+
"version": "a985681",
33
"resolveLibs": "scoped"
44
}

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

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

5+
## version 1.14.5 (2023-02-15)
6+
7+
- Fixed null pointer issues ([#666](https://github.com/HaxeCheckstyle/haxe-formatter/issues/666))
8+
59
## version 1.14.4 (2022-12-14)
610

711
- Refactored PosInfosMacro to limit number of invocations of inner loop

haxe_libraries/tokentree.hxml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# @install: lix --silent download "haxelib:/tokentree#1.2.5" into tokentree/1.2.5/haxelib
2-
-cp ${HAXE_LIBCACHE}/tokentree/1.2.5/haxelib/src
3-
-D tokentree=1.2.5
1+
# @install: lix --silent download "haxelib:/tokentree#1.2.7" into tokentree/1.2.7/haxelib
2+
-cp ${HAXE_LIBCACHE}/tokentree/1.2.7/haxelib/src
3+
-D tokentree=1.2.7

haxelib.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"style"
99
],
1010
"description": "A code formatter for Haxe",
11-
"version": "1.14.4",
12-
"releasenote": "fixed some whitespace formatting issues - see CHANGELOG for details.",
11+
"version": "1.14.5",
12+
"releasenote": "fixed null pointer issue - see CHANGELOG for details.",
1313
"contributors": [
1414
"AlexHaxe",
1515
"Gama11"

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@haxecheckstyle/haxe-formatter",
3-
"version": "1.14.4",
3+
"version": "1.14.5",
44
"description": "A code formatter for Haxe",
55
"repository": {
66
"type": "git",

resources/hxformat-schema.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,11 +576,11 @@
576576
"formatter.config.WrapConditionType": {
577577
"anyOf": [
578578
{
579-
"description": "condition matches if item count is larger than or equal n characters",
579+
"description": "condition matches if item count is larger than or equal n items",
580580
"const": "itemCount >= n"
581581
},
582582
{
583-
"description": "condition matches if item count is less than or equal n characters",
583+
"description": "condition matches if item count is less than or equal n items",
584584
"const": "itemCount <= n"
585585
},
586586
{

src/formatter/config/WrapConfig.hx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,12 +516,12 @@ typedef WrapCondition = {
516516

517517
enum abstract WrapConditionType(String) {
518518
/**
519-
condition matches if item count is larger than or equal n characters
519+
condition matches if item count is larger than or equal n items
520520
**/
521521
var ItemCountLargerThan = "itemCount >= n";
522522

523523
/**
524-
condition matches if item count is less than or equal n characters
524+
condition matches if item count is less than or equal n items
525525
**/
526526
var ItemCountLessThan = "itemCount <= n";
527527

src/formatter/marker/MarkEmptyLines.hx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,9 @@ class MarkEmptyLines extends MarkerBase {
10631063
parsedCode.root.filterCallback(function(token:TokenTree, index:Int):FilterResult {
10641064
switch (token.tok) {
10651065
case Kwd(KwdIf):
1066-
removeEmptyLinesAroundBlock(token.children[1], config.emptyLines.beforeBlocks, Keep);
1066+
if ((token.children != null) && (token.children.length > 0)) {
1067+
removeEmptyLinesAroundBlock(token.children[1], config.emptyLines.beforeBlocks, Keep);
1068+
}
10671069
var block:Null<TokenTree> = token.access().firstOf(Kwd(KwdElse)).previousSibling().token;
10681070
if (block != null) {
10691071
removeEmptyLinesAroundBlock(block, Keep, config.emptyLines.afterBlocks);
@@ -1075,21 +1077,27 @@ class MarkEmptyLines extends MarkerBase {
10751077
removeEmptyLinesAroundBlock(block, config.emptyLines.beforeBlocks, Keep);
10761078
case Kwd(KwdFunction):
10771079
case Kwd(KwdFor):
1078-
removeEmptyLinesAroundBlock(token.children[1], config.emptyLines.beforeBlocks, Keep);
1080+
if ((token.children != null) && (token.children.length > 0)) {
1081+
removeEmptyLinesAroundBlock(token.children[1], config.emptyLines.beforeBlocks, Keep);
1082+
}
10791083
case Kwd(KwdDo):
10801084
removeEmptyLinesAroundBlock(token.getFirstChild(), config.emptyLines.beforeBlocks, Keep);
10811085
var block:Null<TokenTree> = token.access().lastChild().previousSibling().token;
10821086
removeEmptyLinesAroundBlock(block, Keep, config.emptyLines.afterBlocks);
10831087
case Kwd(KwdWhile):
1084-
if ((token.parent == null) || (!token.parent.tok.match(Kwd(KwdDo)))) {
1088+
if ((token.children != null)
1089+
&& (token.children.length > 0)
1090+
&& (token.parent == null || !token.parent.tok.match(Kwd(KwdDo)))) {
10851091
removeEmptyLinesAroundBlock(token.children[1], config.emptyLines.beforeBlocks, Keep);
10861092
}
10871093
case Kwd(KwdTry):
10881094
removeEmptyLinesAroundBlock(token.getFirstChild(), config.emptyLines.beforeBlocks, Keep);
10891095
var block:Null<TokenTree> = token.access().lastChild().previousSibling().token;
10901096
removeEmptyLinesAroundBlock(block, Keep, config.emptyLines.afterBlocks);
10911097
case Kwd(KwdCatch):
1092-
removeEmptyLinesAroundBlock(token.children[1], config.emptyLines.beforeBlocks, Keep);
1098+
if ((token.children != null) && (token.children.length > 0)) {
1099+
removeEmptyLinesAroundBlock(token.children[1], config.emptyLines.beforeBlocks, Keep);
1100+
}
10931101
default:
10941102
}
10951103
return GoDeeper;

src/formatter/marker/wrapping/MarkWrapping.hx

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -577,21 +577,23 @@ class MarkWrapping extends MarkWrappingBase {
577577
}
578578
}
579579
var first:Bool = true;
580-
for (child in itemStart.children) {
581-
switch (child.tok) {
582-
case Binop(OpBoolAnd), Binop(OpBoolOr):
583-
if (first) {
584-
itemStart = firstItemStart;
585-
first = false;
586-
}
587-
items.push(makeWrappableItem(itemStart, child));
588-
var next:Null<TokenInfo> = getNextToken(child);
589-
if (next == null) {
590-
return;
591-
}
592-
itemStart = next.token;
593-
default:
594-
continue;
580+
if (itemStart.children != null) {
581+
for (child in itemStart.children) {
582+
switch (child.tok) {
583+
case Binop(OpBoolAnd), Binop(OpBoolOr):
584+
if (first) {
585+
itemStart = firstItemStart;
586+
first = false;
587+
}
588+
items.push(makeWrappableItem(itemStart, child));
589+
var next:Null<TokenInfo> = getNextToken(child);
590+
if (next == null) {
591+
return;
592+
}
593+
itemStart = next.token;
594+
default:
595+
continue;
596+
}
595597
}
596598
}
597599
items.push(makeWrappableItem(itemStart, TokenTreeCheckUtils.getLastToken(itemStart)));
@@ -630,13 +632,15 @@ class MarkWrapping extends MarkWrappingBase {
630632
return;
631633
}
632634
var itemStart:TokenTree = next.token;
633-
for (child in itemContainer.children) {
634-
switch (child.tok) {
635-
case DblDot:
636-
break;
637-
default:
638-
var lastToken:TokenTree = TokenTreeCheckUtils.getLastToken(child);
639-
items.push(makeWrappableItem(child, lastToken));
635+
if (itemContainer.children != null) {
636+
for (child in itemContainer.children) {
637+
switch (child.tok) {
638+
case DblDot:
639+
break;
640+
default:
641+
var lastToken:TokenTree = TokenTreeCheckUtils.getLastToken(child);
642+
items.push(makeWrappableItem(child, lastToken));
643+
}
640644
}
641645
}
642646
queueWrapping({
@@ -709,17 +713,19 @@ class MarkWrapping extends MarkWrappingBase {
709713
return;
710714
}
711715
var itemStart:TokenTree = next.token;
712-
for (child in itemContainer.children) {
713-
switch (child.tok) {
714-
case Binop(OpAdd), Binop(OpSub):
715-
items.push(makeWrappableItem(itemStart, child));
716-
var next:Null<TokenInfo> = getNextToken(child);
717-
if (next == null) {
716+
if (itemContainer.children != null) {
717+
for (child in itemContainer.children) {
718+
switch (child.tok) {
719+
case Binop(OpAdd), Binop(OpSub):
720+
items.push(makeWrappableItem(itemStart, child));
721+
var next:Null<TokenInfo> = getNextToken(child);
722+
if (next == null) {
723+
continue;
724+
}
725+
itemStart = next.token;
726+
default:
718727
continue;
719-
}
720-
itemStart = next.token;
721-
default:
722-
continue;
728+
}
723729
}
724730
}
725731
items.push(makeWrappableItem(itemStart, TokenTreeCheckUtils.getLastToken(itemStart)));
@@ -850,6 +856,9 @@ class MarkWrapping extends MarkWrappingBase {
850856
});
851857
for (v in allVars) {
852858
var items:Array<WrappableItem> = [];
859+
if (v.children == null) {
860+
continue;
861+
}
853862
for (child in v.children) {
854863
var endToken:TokenTree = TokenTreeCheckUtils.getLastToken(child);
855864
items.push(makeWrappableItem(child, endToken));

0 commit comments

Comments
 (0)