Skip to content

Commit

Permalink
Add support for functions provided by the compat package
Browse files Browse the repository at this point in the history
  • Loading branch information
purcell committed Nov 3, 2023
1 parent ee6b670 commit 34f5929
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 11 deletions.
15 changes: 15 additions & 0 deletions package-lint-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,21 @@ Alternatively, depend on (emacs \"24.3\") or greater, in which cl-lib is bundled
";; Package-Requires: ((seq \"1\"))
\(seq-length '(foo))"))))

(ert-deftest package-lint-test-error-new-compat-functions ()
(should
(equal
'((6 1 error "You should depend on (emacs \"27.1\") or the compat package if you need `proper-list-p'."))
(package-lint-test--run
"(proper-list-p '(foo))"))))

(ert-deftest package-lint-test-accepts-new-functions-with-compat ()
(should
(equal
'()
(package-lint-test--run
";; Package-Requires: ((compat \"29\"))
\(proper-list-p '(foo))"))))

(ert-deftest package-lint-test-error-nonstandard-symbol-separator ()
(should
(equal
Expand Down
47 changes: 37 additions & 10 deletions package-lint.el
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
;; URL: https://github.com/purcell/package-lint
;; Keywords: lisp
;; Version: 0.19
;; Package-Requires: ((cl-lib "0.5") (emacs "24.1") (let-alist "1.0.6"))
;; Package-Requires: ((cl-lib "0.5") (emacs "24.1") (let-alist "1.0.6") (compat "29.1"))

;; 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
Expand Down Expand Up @@ -172,6 +172,28 @@ symbol such as `variable-added'.")
(let-alist (package-lint-symbol-info sym)
(or .function-added .function-removed)))

(defconst package-lint--supported-symbols
(let (symbols functions)
(dolist (ver '(25 26 27 28 29))
(let ((el-path (locate-library (format "compat-%d.el" ver) t)))
(with-temp-buffer
(insert-file-contents el-path)
(goto-char (point-min))
;; TODO convert to rx
(while (search-forward-regexp "^(compat-\\(defun\\|\\defvar\\) +\\_<\\(.*?\\)\\_>" nil t)
(pcase (match-string 1)
("defvar" (push (intern (match-string 2)) symbols))
("defun" (push (intern (match-string 2)) functions)))))))
(cons symbols functions))
"A cons cell of (VARS . FUNCTIONS) supported by \"compat\".")

(defun package-lint--supported-by-compat (type sym)
"Return non-nil if SYM is supported by the \"compat\" package.
TYPE is `function' or `variable'."
(memq sym (pcase type
(`function (cdr package-lint--supported-symbols))
(_ nil))))

(defconst package-lint--sane-prefixes
(rx
string-start
Expand Down Expand Up @@ -636,17 +658,21 @@ type of the symbol, either FUNCTION or FEATURE."
(available-backport (car available-backport-with-ver))
(required-backport-version (cadr available-backport-with-ver))
(matching-dep (when available-backport
(assoc available-backport valid-deps))))
(unless (or (and matching-dep
(or (not required-backport-version)
(version-list-<= (version-to-list required-backport-version)
(cadr matching-dep))))
(and (eq type 'function)
(or (package-lint--seen-fboundp-check-for sym)
(package-lint--is-a-let-binding))))
(assoc available-backport valid-deps)))
(compat-support (package-lint--supported-by-compat type (intern sym)))
(compat-in-deps (assoc 'compat valid-deps)))
(unless (or
(and compat-support compat-in-deps)
(and matching-dep
(or (not required-backport-version)
(version-list-<= (version-to-list required-backport-version)
(cadr matching-dep))))
(and (eq type 'function)
(or (package-lint--seen-fboundp-check-for sym)
(package-lint--is-a-let-binding))))
(list
'error
(format "You should depend on (emacs \"%s\")%s if you need `%s'."
(format "You should depend on (emacs \"%s\")%s%s if you need `%s'."
(mapconcat #'number-to-string added-in-version ".")
(if available-backport
(format " or the %s package"
Expand All @@ -656,6 +682,7 @@ type of the symbol, either FUNCTION or FEATURE."
required-backport-version)
available-backport))
"")
(if compat-support " or the compat package" "")
sym)))))))))))

(defun package-lint--check-eval-after-load ()
Expand Down
2 changes: 1 addition & 1 deletion run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

EMACS="${EMACS:=emacs}"

NEEDED_PACKAGES="cl-lib let-alist"
NEEDED_PACKAGES="cl-lib let-alist compat"

INIT_PACKAGE_EL="(progn \
(require 'package) \
Expand Down

0 comments on commit 34f5929

Please sign in to comment.