Skip to content

Commit b6dcf73

Browse files
committed
adjusted right curly check for typedef and object decls
1 parent 61fffff commit b6dcf73

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

checkstyle/checks/RightCurlyCheck.hx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,13 @@ class RightCurlyCheck extends Check {
103103

104104
function checkTypeDef(td:TypeDecl) {
105105
var firstPos:Position = null;
106+
var maxPos:Int = td.pos.max;
106107

107108
ComplexTypeUtils.walkTypeDecl(td, function(t:ComplexType, name:String, pos:Position) {
108109
if (firstPos == null) {
109110
if (pos != td.pos) firstPos = pos;
110111
}
112+
if (pos.max > maxPos) maxPos = pos.max;
111113
if (!hasToken(OBJECT_DECL)) return;
112114
switch(t) {
113115
case TAnonymous(_):
@@ -117,6 +119,10 @@ class RightCurlyCheck extends Check {
117119
});
118120
if (firstPos == null) return;
119121
if (!hasToken(TYPEDEF_DEF)) return;
122+
// td.pos only holds pos info about the type itself
123+
// members only hold pos info about themself
124+
// so real pos.max is pos.max of last member + 1
125+
td.pos.max = maxPos + 1;
120126
checkPos(td.pos, isSingleLine (td.pos.min, td.pos.max));
121127
}
122128

@@ -126,9 +132,9 @@ class RightCurlyCheck extends Check {
126132
switch(e.expr) {
127133
case EObjectDecl(fields):
128134
if (!hasToken(OBJECT_DECL)) return;
129-
var linePos:LinePos = checker.getLinePos(e.pos.min);
130-
var line:String = checker.lines[linePos.line];
131-
//checkLeftCurly(line, e.pos);
135+
if (fields.length <= 0) return;
136+
var lastExpr:Expr = fields[fields.length - 1].expr;
137+
checkBlocks(lastExpr, isSingleLine(e.pos.min, lastExpr.pos.max));
132138
case EFunction(_, f):
133139
if (!hasToken(FUNCTION)) return;
134140
checkBlocks(f.expr, isSingleLine(e.pos.min, f.expr.pos.max));

0 commit comments

Comments
 (0)