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 false unnecessary constructor warning #299

Merged
merged 1 commit into from
Oct 9, 2016
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
8 changes: 4 additions & 4 deletions src/checkstyle/checks/design/UnnecessaryConstructorCheck.hx
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ class UnnecessaryConstructorCheck extends Check {
var acceptableTokens:Array<TokenTree> = cls.filter([
Kwd(KwdFunction),
Kwd(KwdVar)
], ALL);
], FIRST);

var haveConstructor:Bool = false;
var staticTokens:Int = 0;
var constructorPos = null;
for (token in acceptableTokens) {
if (token.filter([Kwd(KwdNew)], FIRST).length > 0) {
if (token.filter([Kwd(KwdNew)], FIRST, 2).length > 0) {
haveConstructor = true;
constructorPos = token.pos;
continue;
}

if (token.filter([Kwd(KwdStatic)], FIRST).length > 0) {
if (token.filter([Kwd(KwdStatic)], FIRST, 2).length > 0) {
staticTokens++;
continue;
}
Expand All @@ -42,4 +42,4 @@ class UnnecessaryConstructorCheck extends Check {
}
}
}
}
}
4 changes: 2 additions & 2 deletions test/TestMain.hx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TestMain {
Sys.exit(success ? 0 : 1);
}

static function setupCoverageReport() {
function setupCoverageReport() {
var client:PrintClient = new PrintClient();
var logger = MCoverage.getLogger();
logger.addClient(client);
Expand Down Expand Up @@ -71,4 +71,4 @@ class TestMain {
}
}

typedef LineCoverageResult = Dynamic;
typedef LineCoverageResult = Dynamic;
17 changes: 16 additions & 1 deletion test/checks/design/UnnecessaryConstructorCheckTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class UnnecessaryConstructorCheckTest extends CheckTestCase<UnnecessaryConstruct
public function testJustWithConstructor() {
assertNoMsg(new UnnecessaryConstructorCheck(), TEST6);
}

public function testStaticOnlyWithNew() {
assertNoMsg(new UnnecessaryConstructorCheck(), TEST_STATIC_ONLY_WITH_NEW);
}
}

@:enum
Expand Down Expand Up @@ -89,4 +93,15 @@ abstract UnnecessaryConstructorCheckTests(String) to String {
class Test {
public function new() {}
}";
}

var TEST_STATIC_ONLY_WITH_NEW = "
class Test
{
public static var VAR1(default, null):String;

public static function init():Void
{
VAR1 = new String();
}
}";
}