Skip to content

Commit

Permalink
fixed NPE with module level fields on static targets
Browse files Browse the repository at this point in the history
added -v / --verbose command line switch
  • Loading branch information
AlexHaxe committed Oct 28, 2024
1 parent 798699d commit 684f962
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 6 deletions.
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 (2.x.x)

- Added -v / --verbose command line switch
- Fixed null pointer exception with module level fields on static targets

## version 2.9.0 (2024-06-10)

- New check `FileNameCase` to check file names match module names ([#527](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/527))
Expand Down
6 changes: 3 additions & 3 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.2.15" into tokentree/1.2.15/haxelib
-cp ${HAXE_LIBCACHE}/tokentree/1.2.15/haxelib/src
-D tokentree=1.2.15
# @install: lix --silent download "haxelib:/tokentree#1.2.17" into tokentree/1.2.17/haxelib
-cp ${HAXE_LIBCACHE}/tokentree/1.2.17/haxelib/src
-D tokentree=1.2.17
2 changes: 2 additions & 0 deletions src/checkstyle/Checker.hx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Checker {
public var defineCombinations:Array<Array<String>>;
public var linesIdx:Array<LineIds>;
public var lineSeparator:String;
public var verbose:Bool;

var tokenTree:TokenTree;
var allowFailingAST:Bool;
Expand All @@ -34,6 +35,7 @@ class Checker {
baseDefines = [];
defineCombinations = [];
linesIdx = [];
verbose = false;
this.allowFailingAST = allowFailingAST;
}

Expand Down
4 changes: 3 additions & 1 deletion src/checkstyle/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ class Main {
TEXT_PATH = path;
},
@doc("Set reporter style (XSLT)")
["-x", "--xslt"] => function(style:String) STYLE = style,
["-x", "--xslt"] => function(style:String) STYLE = style,
@doc("verbose logging")
["-v", "--verbose"] => function() checker.verbose = true,
@doc("Sets the number of checker threads")
["--checkerthreads"] => function(num:Int) configParser.overrideCheckerThreads = num,
@doc("Generate a default config and exit")
Expand Down
1 change: 1 addition & 0 deletions src/checkstyle/ParserQueue.hx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class ParserQueue {
var checker:Checker = new Checker();
checker.baseDefines = templateChecker.baseDefines;
checker.defineCombinations = templateChecker.defineCombinations;
checker.verbose = templateChecker.verbose;
checker.loadFileContent(file);
if (!checker.createContext(file)) {
checker.unloadFileContent(file);
Expand Down
9 changes: 9 additions & 0 deletions src/checkstyle/checks/Check.hx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package checkstyle.checks;

import checkstyle.config.ExcludeRange;
import haxe.Timer;

class Check {
public var severity:SeverityLevel;
Expand Down Expand Up @@ -31,6 +32,10 @@ class Check {
}

public function run(checker:Checker):Array<Message> {
var startTime = Timer.stamp();
if (checker.verbose) {
Sys.println('${checker.file.name} - [${getModuleName()}] start');
}
reset();
this.checker = checker;
if (severity != SeverityLevel.IGNORE) {
Expand All @@ -41,6 +46,10 @@ class Check {
ErrorUtils.handleException(e, checker.file, getModuleName());
}
}
var endTime = Timer.stamp();
if (checker.verbose) {
Sys.println('${checker.file.name} - [${getModuleName()}] done. (${(endTime - startTime) * 1000}ms)');
}
return messages;
}

Expand Down
4 changes: 3 additions & 1 deletion src/checkstyle/utils/ComplexTypeUtils.hx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ class ComplexTypeUtils {
}

public static function walkStatic(s:Definition<StaticFlag, FieldType>, pos:Position, cb:ComplexTypeCallback) {
walkField(cast s, cb);
var field:Field = cast s;
field.kind = s.data;
walkField(field, cb);
}

public static function walkVar(v:Var, pos:Position, cb:ComplexTypeCallback) {
Expand Down
4 changes: 3 additions & 1 deletion src/checkstyle/utils/ExprUtils.hx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ class ExprUtils {
}

public static function walkStatic(s:Definition<StaticFlag, FieldType>, pos:Position, cb:Expr -> Void) {
walkField(cast s, cb);
var field:Field = cast s;
field.kind = s.data;
walkField(field, cb);
}

public static function walkVar(v:Var, cb:Expr -> Void) {
Expand Down

0 comments on commit 684f962

Please sign in to comment.