Bogdanp / racket-review

A linter for Racket.
BSD 3-Clause "New" or "Revised" License
41 stars 4 forks source link

Checking for trailing expressions in `cond` #12

Closed abhillman closed 9 months ago

abhillman commented 9 months ago

This could be quite handy; i.e.

(define (do-thing) 123)
(cond [...] (do-thing) (error "bla bla))

... where there is a warning here about not having an else clause. Currently, a warning about else clauses is only raised if there are no trailing expressions.

abhillman commented 9 months ago

Related: https://github.com/Bogdanp/racket-review/issues/13

Bogdanp commented 9 months ago

We can check for square brackets and we already check for else clauses in cond:

$ cat test.rkt
#lang racket/base

(cond
  [1 2])
$ raco review test.rkt
test.rkt:3:1:warning:this cond expression does not have an else clause

But we can't check for clauses like in your example, because they could be valid. For example:

$ cat test.rkt
#lang racket/base

(define thing "hi")
(displayln
 (cond
   [thing]))
$ racket test.rkt
hi