Skip to content

Commit

Permalink
lint: track define-like identifier usages
Browse files Browse the repository at this point in the history
  • Loading branch information
Bogdanp committed Mar 6, 2024
1 parent 275a482 commit 6f0d247
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lint.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -716,17 +716,19 @@
#:do [(pop-scope!)
(pop-scope!)])

(pattern (_:define-like
(pattern (define-id:define-like
name:define-identifier
~!
e:expression ...+))
e:expression ...+)
#:do [(track-binding-usage! (format-binding "~a" #'define-id))])

(pattern (_:define-like
(pattern (define-id:define-like
hdr:function-header
~!
(~do (push-scope!))
e:expression ...+)
#:do [(for ([_ (in-range (add1 (attribute hdr.depth)))])
#:do [(track-binding-usage! (format-binding "~a" #'define-id))
(for ([_ (in-range (add1 (attribute hdr.depth)))])
(pop-scope!))]))

(define-syntax-class root-module-path
Expand Down
11 changes: 11 additions & 0 deletions tests/lint/define-syntax-rule.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#lang racket/base

(require (for-syntax racket/base))

(define-syntax-rule (define-keywords id ...)
(begin
(provide id ...)
(define-syntax (id stx)
(raise-syntax-error 'id "not allowed outside special form" stx)) ...))

(define-keywords foo bar baz)
1 change: 1 addition & 0 deletions tests/lint/define-syntax-rule.rkt.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/define-syntax-rule.rkt:11:18:warning:identifier 'foo' is never used

0 comments on commit 6f0d247

Please sign in to comment.