jackfirth / resyntax

A Racket refactoring engine
Apache License 2.0
56 stars 10 forks source link

Suggest using `when` / `unless` instead of `cond` when branch always throws #159

Closed jackfirth closed 2 years ago

jackfirth commented 2 years ago

Saw this code today:

(cond
 [(< (length stack) 2)
  (raise-read-error "parser: Cannot continue after error"
                    #f #f #f #f #f)]
 [else
  (set! stack (cdr stack))
  (remove-states)])

Assuming the enclosing context is an internal definition context, that can be refactored to use when instead:

(when (< (length stack) 2)
  (raise-read-error "parser: Cannot continue after error"
                    #f #f #f #f #f))
(set! stack (cdr stack))
(remove-states)

This can be detected with the help of an always-throws syntax class of some sort that matched calls to functions like raise-read-error, raise-syntax-error, raise-arguments-error, etc.

jackfirth commented 2 years ago

Oops, that commit didn't close this issue, it closed #157.