From 2768d65aa09195b538927ff38100a31de3beac14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Le=20Barbier?= Date: Sun, 17 Sep 2023 15:10:46 +0200 Subject: [PATCH] Remove dependency on rashell --- org.melusina.atelier.asd | 2 +- src/lint.lisp | 55 ++++++++++++++++++++++++++++------------ src/package.lisp | 1 - 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/org.melusina.atelier.asd b/org.melusina.atelier.asd index 5f960fd..78b83d8 100644 --- a/org.melusina.atelier.asd +++ b/org.melusina.atelier.asd @@ -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 diff --git a/src/lint.lisp b/src/lint.lisp index 38d0bae..fdf0a8c 100644 --- a/src/lint.lisp +++ b/src/lint.lisp @@ -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. @@ -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* @@ -778,6 +807,11 @@ 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 @@ -785,17 +819,6 @@ is called on pathnames on that list." (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' diff --git a/src/package.lisp b/src/package.lisp index c7db46e..fc6453e 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -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