diff options
author | Steve Purcell <steve@sanityinc.com> | 2023-11-03 17:21:05 +0000 |
---|---|---|
committer | Steve Purcell <steve@sanityinc.com> | 2023-11-03 17:38:29 +0000 |
commit | dd6542399977168fa9086ee6d5f0a6ed6e6aac2a (patch) | |
tree | 9ecd69361d894d16cce614f11679f328629efeba | |
parent | ee6b670eeaf95ed0fa88ea49e7037a351ed0352a (diff) |
Add support for functions provided by the compat package
-rw-r--r-- | .github/workflows/test.yml | 7 | ||||
-rw-r--r-- | package-lint-test.el | 15 | ||||
-rw-r--r-- | package-lint.el | 49 | ||||
-rwxr-xr-x | run-tests.sh | 2 |
4 files changed, 55 insertions, 18 deletions
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ce8b83a..7c6de23 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,9 +14,6 @@ jobs: strategy: matrix: emacs_version: - - 24.1 - - 24.2 - - 24.3 - 24.4 - 24.5 - 25.1 @@ -35,10 +32,6 @@ jobs: include: - emacs_version: snapshot experimental: true - - emacs_version: 24.1 - lint_ignore: 1 - - emacs_version: 24.2 - lint_ignore: 1 env: EMACS_LINT_IGNORE: ${{ matrix.lint_ignore }} steps: diff --git a/package-lint-test.el b/package-lint-test.el index e7944f5..7237b1f 100644 --- a/package-lint-test.el +++ b/package-lint-test.el @@ -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 diff --git a/package-lint.el b/package-lint.el index 6a5b793..62b6a27 100644 --- a/package-lint.el +++ b/package-lint.el @@ -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.4") (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 @@ -172,6 +172,30 @@ 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))) + (unless el-path + (error "compat package not installed")) + (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 @@ -636,17 +660,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" @@ -656,6 +684,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 () diff --git a/run-tests.sh b/run-tests.sh index d2e8528..5ef1ccb 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -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) \ |