@@ -195,6 +195,52 @@ module.exports = {
195
195
) ;
196
196
}
197
197
198
+ /**
199
+ * Check if the node is the last statement within a do expression
200
+ * @param {ASTNode } node The node to check
201
+ * @return {Boolean } true if its the case, false if not
202
+ */
203
+ function isLastExpInDoExp ( node ) {
204
+ /*
205
+ Detect the structure below:
206
+ DoExpression {
207
+ body: (
208
+ BlockStatement {
209
+ body: [
210
+ (...),
211
+ ExpressionStatement {
212
+ body: (
213
+ JSXElement {
214
+ openingElement: (node)
215
+ }
216
+ )
217
+ }
218
+ ]
219
+ }
220
+ )
221
+ }
222
+ */
223
+ const isInExpStmt = (
224
+ node . parent &&
225
+ node . parent . parent &&
226
+ node . parent . parent . type === 'ExpressionStatement'
227
+ ) ;
228
+ if ( ! isInExpStmt ) return false ;
229
+
230
+ const expStmt = node . parent . parent ;
231
+ const isInBlockStmtWithinDoExp = (
232
+ expStmt . parent &&
233
+ expStmt . parent . type === 'BlockStatement' &&
234
+ expStmt . parent . parent &&
235
+ expStmt . parent . parent . type === 'DoExpression'
236
+ ) ;
237
+ if ( ! isInBlockStmtWithinDoExp ) return false ;
238
+
239
+ const blockStmt = expStmt . parent ;
240
+ const blockStmtLastElm = blockStmt . body [ blockStmt . body . length - 1 ]
241
+ return blockStmtLastElm === expStmt ;
242
+ }
243
+
198
244
/**
199
245
* Check indent for nodes list
200
246
* @param {ASTNode } node The node to check
@@ -239,7 +285,8 @@ module.exports = {
239
285
const indent = (
240
286
prevToken . loc . start . line === node . loc . start . line ||
241
287
isRightInLogicalExp ( node ) ||
242
- isAlternateInConditionalExp ( node )
288
+ isAlternateInConditionalExp ( node ) ||
289
+ isLastExpInDoExp ( node )
243
290
) ? 0 : indentSize ;
244
291
checkNodesIndent ( node , parentElementIndent + indent ) ;
245
292
}
0 commit comments