Skip to content

Commit

Permalink
Remove dependency on rashell
Browse files Browse the repository at this point in the history
  • Loading branch information
foretspaisibles committed Sep 17, 2023
1 parent e109fe3 commit 2768d65
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
2 changes: 1 addition & 1 deletion org.melusina.atelier.asd
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
:description "An atelier for Lisp developers"
:author "Michaël Le Barbier"
:depends-on (#:alexandria
#:uiop
#:cl-ppcre
#:org.melusina.rashell
#:osicat
#:trivia)
:components
Expand Down
55 changes: 39 additions & 16 deletions src/lint.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,38 @@ for CONTENTS are a string or a list of strings."
:using (hash-value linter) :of *linter-table*
:when (linter-match linter pathname)
:return linter))


(defun find-lintable-files (pathnames)
"Find regular files under PATHNAMES that are relevant for the linter."
(let ((prune
'(".DS_Store" ".git" ".hg" ".svn" "CVS" "*.fasl" "obj" "target")))
(flet ((predicate ()
(loop :for prune-iterator :on prune
:for name = (car prune-iterator)
:for last-p = (null (cdr prune-iterator))
:append (list "(" "-name" name "-a" "-prune" ")" "-o")
:when last-p
:append (list "(" "-type" "f" "-a" "-print" ")")))
(pathnames ()
(loop :for pathname :in pathnames
:collect
(etypecase pathname
(string
pathname)
(pathname
(namestring pathname))))))
(let* ((process
(uiop:launch-program (append '("find") (pathnames) (predicate))
:output :stream))
(process-output
(uiop:process-info-output process)))
(flet ((next-lintable-file ()
(let ((next-line
(read-line process-output nil nil)))
(when next-line
(pathname next-line)))))
#'next-lintable-file)))))

(defun lint (&rest pathnames)
"Lint file PATHNAMES with the given linters.
Expand All @@ -729,9 +760,7 @@ is called on pathnames on that list."
(when (listp (first pathnames))
(return-from lint
(apply #'lint (first pathnames))))
(labels ((finalize (hints lines)
(values hints (join-lines lines)))
(lint-1 (pathname)
(labels ((lint-1 (pathname)
(let ((*hint-pathname*
pathname)
(*linter*
Expand Down Expand Up @@ -778,24 +807,18 @@ is called on pathnames on that list."
(describe c *error-output*)
(uiop:quit 1))))
(lint-1 pathname)))))
(hints ()
(loop :with next = (find-lintable-files pathnames)
:for pathname = (funcall next)
:while pathname
:append (handler-lint-1 pathname)))
(epilogue (hints)
(format-hints-by-file-then-code t hints)
(cond
(*linter-interactive-p*
(not hints))
(t
(uiop:quit (if hints 1 0))))))
(let ((hints nil))
(rashell:do-find (pathname ('(:or
(:and (:name ".DS_Store") :prune)
(:and (:name ".git") :prune)
(:and (:name ".hg") :prune)
(:and (:name ".svn") :prune)
(:and (:name "CVS") :prune)
(:and (:name "*.fasl") :prune)
(:and (:has-kind :regular) :print))
pathnames))
(setf hints (nconc hints (handler-lint-1 (pathname pathname)))))
(epilogue hints))))
(epilogue (hints))))

;;;; End of file `lint.lisp'
1 change: 0 additions & 1 deletion src/package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
;;;; are also available at https://opensource.org/licenses/MIT

(defpackage #:org.melusina.atelier
(:local-nicknames (#:rashell #:org.melusina.rashell))
(:use #:common-lisp)
(:import-from #:alexandria
#:hash-table-keys
Expand Down

0 comments on commit 2768d65

Please sign in to comment.