Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed handling of default setters/getters in IndentationCheck #391

Merged
merged 2 commits into from
Apr 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 25 additions & 23 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
## next version (2.x.x)

- Fixed handling of default setters/getters in indentation check [#391](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/391)

## version 2.2.1

- New check IndentationCheck [#387](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/387)
- New CHANGES.md
- Added a reset function for checks ([#279](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/279))
- Added unittest for [#78](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/78)
- Fixed XMLReporter output after introducing multithreading in 2.2.0 [#389](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/389)
- Updated formula for number of pre-parsed files [#386](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/386)
- Removed conditional section for unittest [#181](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/181)
- New check IndentationCheck [#387](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/387)
- New CHANGES.md
- Added a reset function for checks ([#279](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/279))
- Added unittest for [#78](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/78)
- Fixed XMLReporter output after introducing multithreading in 2.2.0 [#389](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/389)
- Updated formula for number of pre-parsed files [#386](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/386)
- Removed conditional section for unittest [#181](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/181)

## version 2.2.0

- Added support for Binop(OpIn) [#352](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/352) ([#359](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/359))
- Added 1 parser and n checker threads ([#374](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/374))
use `-checkerthreads n` to change number of checker threads (range:1-15 default: 5)
use `-nothreads` to turn off threads and use old behaviour
use `numberOfCheckerThreads` in config file to set number of checker threads (see `resources/default-conmfig.json`)
- Fixed allow same regex logic for "all" excludes, fixes [#361](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/361) ([#362](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/362))
- Fixed altering position info in RightCurlyCheck ([#367](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/367))
- Fixed multiple metadatas infront of statement ([#369](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/369))
- Fixed C++ compilation ([#376](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/376))
- Fixed coverage ([#378](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/378))
- Fixed compilation to JS (used in vscode-checkstyle extension) ([#379](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/379))
- Fixed support for comments in var and parameter definitions, fixes [#363](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/363) ([#364](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/364))
- Fixed support for expression metadata in token tree, fixes [#365](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/365) ([#366](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/366))
- Refactored object decl handling in token tree ([#372](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/372))
- Refactored unit testing from haxe.unit to munit ([#377](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/377))
- Removed Patreon link ([#375](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/375))
- Added support for Binop(OpIn) [#352](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/352) ([#359](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/359))
- Added 1 parser and n checker threads ([#374](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/374))
* use `-checkerthreads n` to change number of checker threads (range:1-15 default: 5)
* use `-nothreads` to turn off threads and use old behaviour
* use `numberOfCheckerThreads` in config file to set number of checker threads (see `resources/default-conmfig.json`)
- Fixed allow same regex logic for "all" excludes, fixes [#361](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/361) ([#362](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/362))
- Fixed altering position info in RightCurlyCheck ([#367](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/367))
- Fixed multiple metadatas infront of statement ([#369](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/369))
- Fixed C++ compilation ([#376](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/376))
- Fixed coverage ([#378](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/378))
- Fixed compilation to JS (used in vscode-checkstyle extension) ([#379](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/379))
- Fixed support for comments in var and parameter definitions, fixes [#363](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/363) ([#364](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/364))
- Fixed support for expression metadata in token tree, fixes [#365](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/365) ([#366](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/366))
- Refactored object decl handling in token tree ([#372](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/372))
- Refactored unit testing from haxe.unit to munit ([#377](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/377))
- Removed Patreon link ([#375](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/375))
76 changes: 52 additions & 24 deletions src/checkstyle/checks/whitespace/IndentationCheck.hx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,17 @@ class IndentationCheck extends Check {
function calcLineIndentation():Array<Int> {
var lineIndentation:Array<Int> = [for (i in 0...checker.lines.length) 0];

var searchFor:Array<TokenDef> = [BrOpen, BkOpen, Kwd(KwdIf), Kwd(KwdElse), Kwd(KwdFor), Kwd(KwdDo), Kwd(KwdWhile), Kwd(KwdCase), Kwd(KwdDefault)];
var searchFor:Array<TokenDef> = [
BrOpen,
BkOpen,
Kwd(KwdIf),
Kwd(KwdElse),
Kwd(KwdFor),
Kwd(KwdDo),
Kwd(KwdWhile),
Kwd(KwdCase),
Kwd(KwdDefault)
];
var tokenList:Array<TokenTree> = checker.getTokenTree().filter(searchFor, ALL);
for (token in tokenList) {
switch (token.tok) {
Expand All @@ -104,41 +114,59 @@ class IndentationCheck extends Check {
increaseBlockIndent(token, lineIndentation);
case BrOpen:
increaseBlockIndent(token, lineIndentation);
case Kwd(KwdIf):
var child:TokenTree = token.getLastChild();
if (child.is(Kwd(KwdElse))) {
child = token.children[token.children.length - 2];
}
if (child.is(BrOpen)) continue;
increaseIndentIfNextLine(token, child, lineIndentation);
case Kwd(KwdElse):
var child:TokenTree = token.getFirstChild();
if (child.is(BrOpen)) continue;
increaseIndentIfNextLine(token, child, lineIndentation);
case Kwd(KwdFor):
var child:TokenTree = token.getLastChild();
if (child.is(BrOpen)) continue;
increaseIndentIfNextLine(token, child, lineIndentation);
case Kwd(KwdDo):
var child:TokenTree = token.getFirstChild();
if (child.is(BrOpen)) continue;
increaseIndentIfNextLine(token, child, lineIndentation);
case Kwd(KwdWhile):
var child:TokenTree = token.getLastChild();
if (child.is(BrOpen)) continue;
increaseIndentIfNextLine(token, child, lineIndentation);
case Kwd(KwdIf), Kwd(KwdElse):
calcLineIndentationIf(token, lineIndentation);
case Kwd(KwdFor), Kwd(KwdDo), Kwd(KwdWhile):
calcLineIndentationLoops(token, lineIndentation);
case Kwd(KwdCase):
var child:TokenTree = token.getLastChild();
increaseRangeIndent(child.getPos(), lineIndentation);
case Kwd(KwdDefault):
var child:TokenTree = token.getLastChild();
// getter/setter 'default' has no childs
if (child == null) continue;
increaseRangeIndent(child.getPos(), lineIndentation);
default:
}
}
return lineIndentation;
}

function calcLineIndentationIf(token:TokenTree, lineIndentation:Array<Int>) {
switch (token.tok) {
case Kwd(KwdIf):
var child:TokenTree = token.getLastChild();
if (child.is(Kwd(KwdElse))) {
child = token.children[token.children.length - 2];
}
if (child.is(BrOpen)) return;
increaseIndentIfNextLine(token, child, lineIndentation);
case Kwd(KwdElse):
var child:TokenTree = token.getFirstChild();
if (child.is(BrOpen)) return;
increaseIndentIfNextLine(token, child, lineIndentation);
default:
}
}

function calcLineIndentationLoops(token:TokenTree, lineIndentation:Array<Int>) {
switch (token.tok) {
case Kwd(KwdFor):
var child:TokenTree = token.getLastChild();
if (child.is(BrOpen)) return;
increaseIndentIfNextLine(token, child, lineIndentation);
case Kwd(KwdDo):
var child:TokenTree = token.getFirstChild();
if (child.is(BrOpen)) return;
increaseIndentIfNextLine(token, child, lineIndentation);
case Kwd(KwdWhile):
var child:TokenTree = token.getLastChild();
if (child.is(BrOpen)) return;
increaseIndentIfNextLine(token, child, lineIndentation);
default:
}
}

function calcWrapStatements():Array<Bool> {
var wrapped:Array<Bool> = [for (i in 0...checker.lines.length) false];

Expand Down
1 change: 1 addition & 0 deletions test/checks/whitespace/IndentationCheckTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ abstract IndentationCheckTests(String) to String {
var CORRECT_TAB_INDENT = "
class Test {
static inline var INDENTATION_CHARACTER_CHECK_TEST:Int = 100;
public var type(default, null):CheckType;
public function new() {}
public function test() {
// comment
Expand Down