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

RightCurlyCheck complains about OBJECT_DECL when it isn't in token list #496

Closed
karliss opened this issue Mar 1, 2020 · 2 comments
Closed

Comments

@karliss
Copy link

karliss commented Mar 1, 2020

Here is the testcase I tried. I would expect there to be no errors about object declarations if configuration tokens contain only IF.

	@Test
	public function testTokens() {
		var check = new RightCurlyCheck();
		check.tokens = [IF];
		check.option = ALONE;

		assertMsg(check, SINGLELINE_IF, MSG_NOT_SAME_LINE);

		assertNoMsg(check, SINGLELINE_FUNCTION);
		assertNoMsg(check, SINGLELINE_FOR);
		assertNoMsg(check, SINGLELINE_WHILE);
		assertNoMsg(check, SINGLELINE_TRY_CATCH);
		assertNoMsg(check, SINGLELINE_INTERFACE);
		assertNoMsg(check, SINGLELINE_CLASS);
		assertNoMsg(check, SINGLELINE_TYPEDEF);
		assertNoMsg(check, SINGLELINE_SWITCH);
		assertNoMsg(check, SINGLELINE_CASE);
		assertNoMsg(check, SINGLELINE_OBJECT); // this one fails
		assertNoMsg(check, SINGLELINE_ABSTRACT);
		assertNoMsg(check, SINGLELINE_ENUM);
		assertNoMsg(check, SINGLELINE_NESTED_OBJECT); // this one fails

		assertNoMsg(check, CONSTRUCTOR_OBJECT_DECL_ISSUE_152); // this one fails
		assertNoMsg(check, SINGLELINE_PATTERN_OBJECT); // this one fails
	}
	var SINGLELINE_PATTERN_OBJECT = "
	class Test {
		public function foo() {
			var obj = {x: 1, y: 2};
			switch (obj) {
				case {x: 2, y: b}:
			}
		}
	}";
@karliss
Copy link
Author

karliss commented Mar 1, 2020

Is there a reason why the code can't do just hasToken(type) instead of the more complicated parent type check? I am not familiar with the structure created by parser haxeCheckStyle uses but can't the parent for object declaration be almost anything?

AlexHaxe added a commit to AlexHaxe/haxe-checkstyle that referenced this issue Mar 1, 2020
@AlexHaxe
Copy link
Member

AlexHaxe commented Mar 1, 2020

RightCurly uses tokentree to find curly braces. tokentree provides an easy way to find tokens, but sometimes it's harder to figure out what that token does and how it's used. Sometimes you have to look a few tokens up, down or sideways to see what's around a token and understand it's meaning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants