@@ -195,6 +195,56 @@ 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 ) {
229
+ return false ;
230
+ }
231
+
232
+ const expStmt = node . parent . parent ;
233
+ const isInBlockStmtWithinDoExp = (
234
+ expStmt . parent &&
235
+ expStmt . parent . type === 'BlockStatement' &&
236
+ expStmt . parent . parent &&
237
+ expStmt . parent . parent . type === 'DoExpression'
238
+ ) ;
239
+ if ( ! isInBlockStmtWithinDoExp ) {
240
+ return false ;
241
+ }
242
+
243
+ const blockStmt = expStmt . parent ;
244
+ const blockStmtLastElm = blockStmt . body [ blockStmt . body . length - 1 ] ;
245
+ return blockStmtLastElm === expStmt ;
246
+ }
247
+
198
248
/**
199
249
* Check indent for nodes list
200
250
* @param {ASTNode } node The node to check
@@ -239,7 +289,8 @@ module.exports = {
239
289
const indent = (
240
290
prevToken . loc . start . line === node . loc . start . line ||
241
291
isRightInLogicalExp ( node ) ||
242
- isAlternateInConditionalExp ( node )
292
+ isAlternateInConditionalExp ( node ) ||
293
+ isLastExpInDoExp ( node )
243
294
) ? 0 : indentSize ;
244
295
checkNodesIndent ( node , parentElementIndent + indent ) ;
245
296
}
0 commit comments