generated from jackfirth/racket-package-template
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #28. The implementation is pretty basic and ignores things like `(provide (for-syntax x x))` but it catches the simple case.
- Loading branch information
Showing
3 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
default-recommendations/require-and-provide-suggestions-test.rkt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#lang resyntax/testing/refactoring-test | ||
|
||
|
||
require: resyntax/default-recommendations require-and-provide-suggestions | ||
|
||
|
||
header: | ||
- #lang racket/base | ||
|
||
|
||
test: "duplicate provided identifiers should be removed" | ||
---------------------------------------- | ||
(provide foo | ||
foo | ||
foo) | ||
(define foo 1) | ||
---------------------------------------- | ||
---------------------------------------- | ||
(provide foo) | ||
(define foo 1) | ||
---------------------------------------- | ||
|
||
|
||
test: "removing duplicate provided identifiers leaves other exports unchanged" | ||
---------------------------------------- | ||
(provide a | ||
foo | ||
b | ||
foo | ||
c) | ||
(define a 1) | ||
(define b 1) | ||
(define c 1) | ||
(define foo 1) | ||
---------------------------------------- | ||
---------------------------------------- | ||
(provide a | ||
foo | ||
b | ||
c) | ||
(define a 1) | ||
(define b 1) | ||
(define c 1) | ||
(define foo 1) | ||
---------------------------------------- | ||
|
||
|
||
test: "provide deduplication doesn't affect exports at different phases" | ||
---------------------------------------- | ||
(provide foo | ||
(for-syntax foo)) | ||
(require (for-syntax racket/base)) | ||
(define foo 1) | ||
(begin-for-syntax | ||
(define foo 2)) | ||
---------------------------------------- |
43 changes: 43 additions & 0 deletions
43
default-recommendations/require-and-provide-suggestions.rkt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#lang racket/base | ||
|
||
|
||
(require racket/contract/base) | ||
|
||
|
||
(provide | ||
(contract-out | ||
[require-and-provide-suggestions refactoring-suite?])) | ||
|
||
|
||
(require racket/list | ||
rebellion/private/static-name | ||
resyntax/refactoring-rule | ||
resyntax/refactoring-suite | ||
syntax/parse) | ||
|
||
|
||
;@---------------------------------------------------------------------------------------------------- | ||
|
||
|
||
(define-syntax-class export-spec | ||
#:attributes (id) | ||
(pattern id:id)) | ||
|
||
|
||
(define-refactoring-rule provide-deduplication | ||
#:description "Providing the same identifier multiple times is unnecessary." | ||
#:literals (provide) | ||
(provide spec:export-spec ...) | ||
#:when (check-duplicate-identifier (attribute spec.id)) | ||
|
||
#:with (deduped-spec ...) | ||
(remove-duplicates (attribute spec) bound-identifier=? | ||
#:key (λ (spec-stx) (syntax-parse spec-stx [:export-spec #'id]))) | ||
|
||
(provide deduped-spec ...)) | ||
|
||
|
||
(define require-and-provide-suggestions | ||
(refactoring-suite | ||
#:name (name require-and-provide-suggestions) | ||
#:rules (list provide-deduplication))) |