Skip to content

Commit 9c71818

Browse files
authored
Fixed object decl handling in RightCurly (#497)
* fixed object decl handling in RightCurly, fixes #496 * disable C++ for nightly builds
1 parent e143a8b commit 9c71818

File tree

8 files changed

+63
-11
lines changed

8 files changed

+63
-11
lines changed

.github/workflows/checkstyle-linux.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ jobs:
5656
- name: Build NodeJs version
5757
run: npx haxe buildJS.hxml
5858
- name: Build C++ version
59+
if: matrix.haxe-version != 'nightly'
5960
run: npx haxe buildCpp.hxml
6061
- name: Build JSON schema
6162
run: npx haxe buildSchema.hxml

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ script:
3131
- npx haxe build.hxml
3232
- npx haxe buildDebug.hxml
3333
- npx haxe buildJS.hxml
34-
- npx haxe buildCpp.hxml
34+
- if [[ "$HAXE_VERSION" != "nightly" ]]; then npx haxe buildCpp.hxml; fi
3535
- npx haxe buildSchema.hxml
3636
- npx haxe -D codecov_json buildTest.hxml
3737
- npx haxe testJava.hxml

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## dev branch / next version (2.x.x)
44

55
- Added support for final in `MagicNumber`, fixes [#494](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/494) ([#495](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/495))
6+
- Fixed handling `OBJECT_DECL` token in `RightCurly`, fixes [#496](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/496) ([#497](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/497))
67

78
## version 2.6.1 (2019-12-17)
89

build/Build.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import haxe.Timer;
44
helper class to build everything, avoids `--next`
55
**/
66
class Build {
7-
private static var exitCode:Int = 0;
7+
static var exitCode:Int = 0;
88

99
/**
1010
run all build files

checkstyle.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828
{
2929
"props": {
3030
"ignoreExtern": true,
31-
"format": "^[A-Z][A-Z0-9]*(_[A-Z0-9_]+)*$"
31+
"format": "^[A-Z][A-Z0-9]*(_[A-Z0-9_]+)*$",
32+
"tokens": [
33+
"INLINE"
34+
]
3235
},
3336
"type": "ConstantName"
3437
},

haxe_libraries/hxcpp.hxml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-D hxcpp=4.0.52
2-
# @install: lix --silent download "haxelib:/hxcpp#4.0.52" into hxcpp/4.0.52/haxelib
3-
# @run: haxelib run-dir hxcpp ${HAXE_LIBCACHE}/hxcpp/4.0.52/haxelib
4-
-cp ${HAXE_LIBCACHE}/hxcpp/4.0.52/haxelib/
1+
-D hxcpp=4.0.64
2+
# @install: lix --silent download "haxelib:/hxcpp#4.0.64" into hxcpp/4.0.64/haxelib
3+
# @run: haxelib run-dir hxcpp ${HAXE_LIBCACHE}/hxcpp/4.0.64/haxelib
4+
-cp ${HAXE_LIBCACHE}/hxcpp/4.0.64/haxelib/

src/checkstyle/checks/block/RightCurlyCheck.hx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,9 @@ class RightCurlyCheck extends Check {
7070
switch (type) {
7171
case BLOCK:
7272
case TYPEDEFDECL:
73-
if (!hasToken(TYPEDEF_DEF)) {
74-
continue;
75-
}
73+
if (!hasToken(TYPEDEF_DEF)) continue;
7674
case OBJECTDECL:
75+
if (!hasToken(OBJECT_DECL)) continue;
7776
case ANONTYPE:
7877
case UNKNOWN:
7978
}

test/checkstyle/checks/block/RightCurlyCheckTest.hx

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class RightCurlyCheckTest extends CheckTestCase<RightCurlyCheckTests> {
191191
@Test
192192
public function testArrayComprehension() {
193193
var check = new RightCurlyCheck();
194-
check.tokens = [ARRAY_COMPREHENSION];
194+
check.tokens = [ARRAY_COMPREHENSION, OBJECT_DECL];
195195
assertNoMsg(check, ARRAY_COMPREHENSION_ISSUE_114);
196196
assertNoMsg(check, ARRAY_COMPREHENSION_2_ISSUE_114);
197197

@@ -202,6 +202,45 @@ class RightCurlyCheckTest extends CheckTestCase<RightCurlyCheckTests> {
202202
check.option = ALONE;
203203
assertMsg(check, ARRAY_COMPREHENSION_ISSUE_114, MSG_NOT_SAME_LINE);
204204
assertNoMsg(check, ARRAY_COMPREHENSION_2_ISSUE_114);
205+
206+
check.tokens = [ARRAY_COMPREHENSION];
207+
check.option = ALONE_OR_SINGLELINE;
208+
assertNoMsg(check, ARRAY_COMPREHENSION_ISSUE_114);
209+
assertNoMsg(check, ARRAY_COMPREHENSION_2_ISSUE_114);
210+
211+
check.option = SAME;
212+
assertNoMsg(check, ARRAY_COMPREHENSION_ISSUE_114);
213+
assertNoMsg(check, ARRAY_COMPREHENSION_2_ISSUE_114);
214+
215+
check.option = ALONE;
216+
assertNoMsg(check, ARRAY_COMPREHENSION_ISSUE_114);
217+
assertNoMsg(check, ARRAY_COMPREHENSION_2_ISSUE_114);
218+
}
219+
220+
@Test
221+
public function testTokenIfNoObjectDecl() {
222+
var check = new RightCurlyCheck();
223+
check.tokens = [IF];
224+
check.option = ALONE;
225+
226+
assertMsg(check, SINGLELINE_IF, MSG_NOT_SAME_LINE);
227+
228+
assertNoMsg(check, SINGLELINE_FUNCTION);
229+
assertNoMsg(check, SINGLELINE_FOR);
230+
assertNoMsg(check, SINGLELINE_WHILE);
231+
assertNoMsg(check, SINGLELINE_TRY_CATCH);
232+
assertNoMsg(check, SINGLELINE_INTERFACE);
233+
assertNoMsg(check, SINGLELINE_CLASS);
234+
assertNoMsg(check, SINGLELINE_TYPEDEF);
235+
assertNoMsg(check, SINGLELINE_SWITCH);
236+
assertNoMsg(check, SINGLELINE_CASE);
237+
assertNoMsg(check, SINGLELINE_OBJECT);
238+
assertNoMsg(check, SINGLELINE_ABSTRACT);
239+
assertNoMsg(check, SINGLELINE_ENUM);
240+
assertNoMsg(check, SINGLELINE_NESTED_OBJECT);
241+
242+
assertNoMsg(check, CONSTRUCTOR_OBJECT_DECL_ISSUE_152);
243+
assertNoMsg(check, SINGLELINE_PATTERN_OBJECT);
205244
}
206245
}
207246

@@ -547,4 +586,13 @@ abstract RightCurlyCheckTests(String) to String {
547586
class Test {
548587
var field = new Object({x:0});
549588
}";
589+
var SINGLELINE_PATTERN_OBJECT = "
590+
class Test {
591+
public function foo() {
592+
var obj = {x: 1, y: 2};
593+
switch (obj) {
594+
case {x: 2, y: b}:
595+
}
596+
}
597+
}";
550598
}

0 commit comments

Comments
 (0)