Delete all nodes of a user using flags and rules
I did in this way without writing a single line of code.

1) Add action: Fetch entity by property: Choose Entity type as 'Node', Property as 'Author' and Data selector as 'flagged-node:author'. Choose variable label ('spam nodes' in my case) and variable name ('spam_nodes' in my case) as you wish.

2) Add Loop: Select Data selector as 'spam-nodes' (this will show as per your  variable label in step 1). Set variable label('spam node' in my case) and variable name('spam_item' in my case) as you wish.

3) Now click on 'Add action' link under 'Operations' column against the loop you have added in step 2. Select 'Delete Entity' and set the Data selector as 'spam-item' (this will show as per your variable label in step 2).