summaryrefslogtreecommitdiff
path: root/lisp/use-package/use-package-lint.el
diff options
context:
space:
mode:
authorStefan Kangas <stefankangas@gmail.com>2022-12-08 18:01:30 +0100
committerStefan Kangas <stefankangas@gmail.com>2022-12-08 18:01:30 +0100
commite950f5a663ad3501e50f43ef6c0a7fd220e0c1f2 (patch)
treec6f8d28d3576fb74898884bf83b967bc2550eaf0 /lisp/use-package/use-package-lint.el
parent9c21eae60c470fde4b5c4a86c0b0dcf3ff480a79 (diff)
parent5bcd0cee0fc5eba81d254cba91459ba340c71dd3 (diff)
downloademacs-e950f5a663ad3501e50f43ef6c0a7fd220e0c1f2.tar.gz
emacs-e950f5a663ad3501e50f43ef6c0a7fd220e0c1f2.tar.bz2
emacs-e950f5a663ad3501e50f43ef6c0a7fd220e0c1f2.zip
Merge branch 'feature/use-package' into emacs-29
Diffstat (limited to 'lisp/use-package/use-package-lint.el')
-rw-r--r--lisp/use-package/use-package-lint.el76
1 files changed, 76 insertions, 0 deletions
diff --git a/lisp/use-package/use-package-lint.el b/lisp/use-package/use-package-lint.el
new file mode 100644
index 00000000000..2092c0d269c
--- /dev/null
+++ b/lisp/use-package/use-package-lint.el
@@ -0,0 +1,76 @@
+;;; use-package-lint.el --- Attempt to find errors in use-package declarations -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2012-2022 Free Software Foundation, Inc.
+
+;; Author: John Wiegley <johnw@newartisans.com>
+;; Maintainer: John Wiegley <johnw@newartisans.com>
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Provides the command `M-x use-package-lint'.
+
+;;; Code:
+
+(require 'cl-lib)
+(require 'use-package-core)
+
+(defun use-package-lint-declaration (name plist)
+ (dolist (path (plist-get plist :load-path))
+ (unless (file-exists-p path)
+ (display-warning
+ 'use-package
+ (format "%s :load-path does not exist: %s"
+ name path) :error)))
+
+ (unless (or (plist-member plist :disabled)
+ (plist-get plist :no-require)
+ (locate-library (use-package-as-string name) nil
+ (plist-get plist :load-path)))
+ (display-warning
+ 'use-package
+ (format "%s module cannot be located" name) :error))
+
+ ;; (dolist (command (plist-get plist :commands))
+ ;; (unless (string= (find-lisp-object-file-name command nil)
+ ;; (locate-library (use-package-as-string name) nil
+ ;; (plist-get plist :load-path)))
+ ;; (display-warning
+ ;; 'use-package
+ ;; (format "%s :command is from different path: %s"
+ ;; name (symbol-name command)) :error)))
+ )
+
+;;;###autoload
+(defun use-package-lint ()
+ "Check for errors in `use-package' declarations.
+For example, if the module's `:if' condition is met, but even
+with the specified `:load-path' the module cannot be found."
+ (interactive)
+ (save-excursion
+ (goto-char (point-min))
+ (let ((re (eval use-package-form-regexp-eval)))
+ (while (re-search-forward re nil t)
+ (goto-char (match-beginning 0))
+ (let ((decl (read (current-buffer))))
+ (when (eq (car decl) 'use-package)
+ (use-package-lint-declaration
+ (use-package-as-string (cadr decl))
+ (use-package-normalize-keywords
+ (cadr decl) (cddr decl)))))))))
+
+(provide 'use-package-lint)
+
+;;; use-package-lint.el ends here