Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion cli.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
racket/logging
racket/match
racket/path
racket/port
rebellion/base/comparator
rebellion/base/range
rebellion/collection/entry
Expand All @@ -33,7 +34,7 @@
;@----------------------------------------------------------------------------------------------------


(define-enum-type resyntax-output-format (plain-text github-pull-request-review git-commit-message))
(define-enum-type resyntax-output-format (plain-text github-pull-request-review git-commit-message json))
(define-enum-type resyntax-fix-method (modify-files create-multiple-git-commits))
(define-record-type resyntax-analyze-options (targets suite output-format output-destination))

Expand Down Expand Up @@ -160,6 +161,10 @@ changed relative to baseref are analyzed and fixed."
"Report results in the form of a Git commit message printed to stdout."
(set! output-format git-commit-message))

("--output-as-json"
"Report results in the form of a JSON object printed to stdout."
(set! output-format json))

("--refactoring-suite"
modpath
suite-name
Expand Down Expand Up @@ -293,6 +298,8 @@ For help on these, use 'analyze --help' or 'fix --help'."
(match output-format
[(== git-commit-message)
(resyntax-fix-print-git-commit-message analysis)]
[(== json)
(resyntax-fix-print-json analysis)]
[(== plain-text)
(resyntax-fix-print-plain-text-summary analysis)]))

Expand Down Expand Up @@ -344,5 +351,37 @@ For help on these, use 'analyze --help' or 'fix --help'."
(newline)))


(define (resyntax-fix-print-json analysis)
(define total-fixes (resyntax-analysis-total-fixes analysis))
(define total-files (resyntax-analysis-total-sources-modified analysis))
(define fix-counts-by-rule
(transduce (in-hash-entries (multiset-frequencies (resyntax-analysis-rules-applied analysis)))
(sorting #:key entry-value #:descending? #true)
#:into into-list))

;; Build commit message
(define commit-message
(with-output-to-string
(λ ()
(define issue-string (if (> total-fixes 1) "issues" "issue"))
(define file-string (if (> total-files 1) "files" "file"))
(if (zero? total-fixes)
(printf "Resyntax found no issues.")
(printf "Automated Resyntax fixes\n\nResyntax fixed ~a ~a in ~a ~a."
total-fixes issue-string total-files file-string))
(unless (zero? total-fixes)
(printf "\n")
(for ([rule+count (in-list fix-counts-by-rule)])
(match-define (entry rule count) rule+count)
(define occurrence-string (if (> count 1) "occurrences" "occurrence"))
(printf "\n * Fixed ~a ~a of `~a`" count occurrence-string rule))))))

;; Output JSON
(write-json
(hasheq 'commit_message commit-message
'fix_count total-fixes))
(newline))


(module+ main
(resyntax-run))