From 69ff29044d68a7e86e6092f40da6291ad10da6f8 Mon Sep 17 00:00:00 2001 From: vemv Date: Fri, 15 Sep 2023 20:02:20 +0200 Subject: [PATCH] x --- .circleci/config.yml | 140 +++++++++++++++++++------ .gitignore | 2 + Cask | 9 -- Eldev | 20 ++++ Makefile | 54 +++------- README.md | 14 --- clj-refactor.el | 79 ++++++++------ test/clj-refactor-bytecomp-warnings.el | 40 ------- test/test-checks.el | 31 ------ watch-tests.watchr | 45 -------- 10 files changed, 192 insertions(+), 242 deletions(-) delete mode 100644 Cask create mode 100644 Eldev delete mode 100644 test/clj-refactor-bytecomp-warnings.el delete mode 100644 test/test-checks.el delete mode 100644 watch-tests.watchr diff --git a/.circleci/config.yml b/.circleci/config.yml index 73b82bfb..92633ed5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,48 +1,120 @@ version: 2.1 -# Default actions to perform on each Emacs version -default: &default-steps - environment: - TERM: xterm - steps: - - checkout - - run: apt-get update && apt-get install make - - run: cask upgrade-cask || true - - run: make elpa - - run: emacs --version - - run: cask --version - - run: make test - # Make sure to run test-checks before test-bytecomp, as test-bytecomp autogenerates - # files which won't pass test-checks. - # disabled - see https://github.com/clojure-emacs/clj-refactor.el/issues/491 - #- run: make test-checks - #- run: make test-bytecomp +orbs: + win: circleci/windows@2.2.0 -# Enumerated list of Emacs versions -jobs: +commands: + setup: + steps: + - checkout + - run: + name: Install Eldev + command: curl -fsSL https://raw.github.com/doublep/eldev/master/webinstall/circle-eldev > x.sh && source ./x.sh + - run: + name: Install unzip + command: apt-get update && apt-get install unzip + + setup-macos: + steps: + - checkout + - run: + name: Install Emacs latest + command: | + brew install homebrew/cask/emacs + - run: + name: Install Eldev + command: curl -fsSL https://raw.github.com/doublep/eldev/master/webinstall/circle-eldev > x.sh && source ./x.sh + + setup-windows: + steps: + - checkout + - run: + name: Install Eldev + command: | + # Remove expired DST Root CA X3 certificate. Workaround + # for https://debbugs.gnu.org/cgi/bugreport.cgi?bug=51038 + # bug on Emacs 27.2. + gci cert:\LocalMachine\Root\DAC9024F54D8F6DF94935FB1732638CA6AD77C13 + gci cert:\LocalMachine\Root\DAC9024F54D8F6DF94935FB1732638CA6AD77C13 | Remove-Item + (iwr https://raw.github.com/doublep/eldev/master/webinstall/circle-eldev.ps1).Content | powershell -command - + test: + steps: + - run: + name: Run regression tests + command: eldev -dtT -p test + lint: + steps: + - run: + name: Run regression tests + command: eldev -dtT compile - test-emacs-26: +jobs: + test-ubuntu-emacs-26: docker: - - image: silex/emacs:26-ci-cask + - image: silex/emacs:26-ci entrypoint: bash - <<: *default-steps - - test-emacs-27: + steps: + - setup + - test + - lint + test-ubuntu-emacs-27: docker: - - image: silex/emacs:27-ci-cask + - image: silex/emacs:27-ci entrypoint: bash - <<: *default-steps - - test-emacs-master: + steps: + - setup + - test + - lint + test-ubuntu-emacs-28: + docker: + - image: silex/emacs:28-ci + entrypoint: bash + steps: + - setup + - test + - lint + test-ubuntu-emacs-29: + docker: + - image: silex/emacs:29-ci + entrypoint: bash + steps: + - setup + - test + - lint + test-ubuntu-emacs-master: docker: - - image: silex/emacs:master-ci-cask + - image: silex/emacs:master-ci entrypoint: bash - <<: *default-steps + steps: + - setup + - test + - lint + test-macos-emacs-latest: + macos: + xcode: "14.0.0" + steps: + - setup-macos + - test + - lint + test-windows-emacs-latest: + executor: win/default + steps: + - run: + name: Install Emacs latest + command: | + choco install emacs + - setup-windows + - test + - lint workflows: - version: 2 + version: 2.1 ci-test-matrix: jobs: - - test-emacs-26 - - test-emacs-27 - - test-emacs-master + - test-ubuntu-emacs-26 + - test-ubuntu-emacs-27 + - test-ubuntu-emacs-28 + - test-ubuntu-emacs-29 + - test-ubuntu-emacs-master + - test-windows-emacs-latest + - test-macos-emacs-latest diff --git a/.gitignore b/.gitignore index cfea5ef7..1e2cec6e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ elpa tmp .ecukes-failing-scenarios clj-refactor.elc +/.eldev +/clj-refactor-autoloads.el diff --git a/Cask b/Cask deleted file mode 100644 index 1a711d10..00000000 --- a/Cask +++ /dev/null @@ -1,9 +0,0 @@ -(source gnu) -(source melpa) - -(package-file "clj-refactor.el") - -(development - (depends-on "ecukes") - (depends-on "espuds") - (depends-on "buttercup")) diff --git a/Eldev b/Eldev new file mode 100644 index 00000000..92b93400 --- /dev/null +++ b/Eldev @@ -0,0 +1,20 @@ +; -*- mode: emacs-lisp; lexical-binding: t; no-byte-compile: t -*- + +(eldev-require-version "0.6") + +(eldev-use-package-archive 'gnu) +;; For compatibility; e.g. with MELPA Stable one test fails. +(eldev-use-package-archive 'melpa-unstable) + +(eldev-use-plugin 'autoloads) + +;; (eldev-add-extra-dependencies 'test 'a) + +;; CIDER cannot be compiled otherwise. +(setf eldev-build-load-before-byte-compiling t) + +(setf eldev-lint-default '(elisp)) +(with-eval-after-load 'elisp-lint + ;; We will byte-compile with Eldev. + (setf elisp-lint-ignored-validators '("package-lint" "fill-column" "byte-compile") + enable-local-variables :safe)) diff --git a/Makefile b/Makefile index ce1716b0..4a441526 100644 --- a/Makefile +++ b/Makefile @@ -1,47 +1,23 @@ -CASK = cask -export EMACS ?= emacs -EMACSFLAGS = +.PHONY: clean compile lint test +.DEFAULT_GOAL := all -PKGDIR := $(shell EMACS=$(EMACS) $(CASK) package-directory) - -SRCS = $(wildcard *.el) -OBJS = $(SRCS:.el=.elc) - -.PHONY: compile unit-tests integration-tests test clean elpa - -all: compile - -elpa-$(EMACS): - $(CASK) install - $(CASK) update - touch $@ - -elpa: elpa-$(EMACS) - -elpaclean: - rm -f elpa* - rm -rf .cask # Clean packages installed for development - -compile: elpa - $(CASK) build +# Something like this can be handy if you need Eldev to run on an Emacs other than your default one: +# export ELDEV_EMACS="$HOME/emacs28/Emacs.app/Contents/MacOS/Emacs" clean: - rm -f $(OBJS) - -integration-tests: $(PKGDIR) - $(CASK) exec ecukes --no-win + echo -unit-tests: - $(CASK) exec buttercup -L . +# You can find a generic `eldev` installation script in https://github.com/emacs-eldev/eldev/blob/master/webinstall/eldev +# (Don't use the one defined for CircleCI in your local machine) -test: unit-tests integration-tests +lint: clean + eldev lint -test-checks: - $(CASK) exec $(EMACS) --no-site-file --no-site-lisp --batch \ - -l test/test-checks.el ./ +# Checks for byte-compilation warnings. +compile: clean + eldev -dtT compile --warnings-as-errors -test-bytecomp: $(SRCS:.el=.elc-test) +test: clean + eldev -dtT -p test -%.elc-test: %.el elpa - $(CASK) exec $(EMACS) --no-site-file --no-site-lisp --batch \ - -l test/clojure-mode-bytecomp-warnings.el $ +all: lint compile test diff --git a/README.md b/README.md index c3161247..0c668bdb 100644 --- a/README.md +++ b/README.md @@ -137,18 +137,10 @@ You'll find the repo at: https://github.com/clojure-emacs/clj-refactor.el -To fetch the test dependencies, install -[cask](https://github.com/cask/cask) if you haven't already, -then: - - $ cd /path/to/clj-refactor - $ cask - Run the tests with: $ make test - Before submitting a patch, or a pull request, make sure all tests are passing and that your patch is in line with the [contribution guidelines](.github/CONTRIBUTING.md). @@ -160,12 +152,6 @@ Thanks to [everyone](https://github.com/clojure-emacs/clj-refactor.el/graphs/con Due to clj-refactor's kinship with CIDER, you can get help for it in most CIDER-related support channels. -### Discord - -CIDER has its own Discord chat server, created by CIDER's -author Bozhidar. You can join the Discord server -[here](https://discord.com/invite/nFPpynQPME). - ### Slack CIDER has an official [Clojurians Slack](https://clojurians.slack.com/) - `#cider`. The channel is very active and is a great way to diff --git a/clj-refactor.el b/clj-refactor.el index 1dd502af..6ece4b44 100644 --- a/clj-refactor.el +++ b/clj-refactor.el @@ -128,7 +128,8 @@ This only applies to dependencies added by `cljr-add-project-dependency'." :safe #'booleanp) (defcustom cljr-insert-newline-after-require t - "If t, `cljr-clean-ns' will place a newline after the `:require` and `:import` tokens." + "If t, `cljr-clean-ns' will place a newline after the `:require` +and `:import` tokens." :type 'boolean :safe #'booleanp) @@ -178,6 +179,8 @@ will not work as expected in such REPLs." :type 'boolean :safe #'booleanp) +(define-obsolete-variable-alias 'cljr-find-usages-ignore-analyzer-errors 'cljr-ignore-analyzer-errors "2.3.0") + (defcustom cljr-ignore-analyzer-errors nil "If t, `cljr-find-usages' `cljr-inline-symbol' `cljr-rename-symbol' ignores namespaces that cannot be analyzed. @@ -190,8 +193,6 @@ won't run if there is a broken namespace in the project." :type 'boolean :safe #'booleanp) -(define-obsolete-variable-alias 'cljr-find-usages-ignore-analyzer-errors 'cljr-ignore-analyzer-errors "2.3.0") - (defcustom cljr-auto-eval-ns-form t "When true refactorings which change the ns form also trigger its re-evaluation." @@ -210,7 +211,8 @@ won't run if there is a broken namespace in the project." (defcustom cljr-cljc-clojure-test-declaration "#?(:clj [clojure.test :as t] :cljs [cljs.test :as t :include-macros true])" - "The require form to use when clojure.test and cljs.test is in use in a cljc file." + "The require form to use when clojure.test and cljs.test is in use +in a cljc file." :type 'string :safe #'stringp) @@ -230,7 +232,8 @@ won't run if there is a broken namespace in the project." :safe #'stringp) (defcustom cljr-inject-dependencies-at-jack-in t - "When nil, do not inject repl dependencies (most likely nREPL middlewares) at `cider-jack-in' time." + "When nil, do not inject repl dependencies (most likely nREPL middlewares) +at `cider-jack-in' time." :type 'boolean :safe #'booleanp) @@ -273,7 +276,8 @@ if it appears to be unused." (defvar cljr--file-column-pattern "^\\(.+?\\):\\([1-9][0-9]*\\):\\([0-9][0-9]*\\): " - "A regexp pattern that groups output into filename, line number and column number.") + "A regexp pattern that groups output into filename, +line number and column number.") (defvar cljr--debug-mode nil) @@ -1961,8 +1965,9 @@ context. Valid outputs include, but are not limited to `:clj', (cdr (assoc key map))) (defcustom cljr-suggest-namespace-aliases t - "If `t', `namespace-aliases' and `cljr-slash' will take into account suggested namespace aliases, -following this convention: https://stuartsierra.com/2015/05/10/clojure-namespace-aliases" + "If `t', `namespace-aliases' and `cljr-slash' will take into account +suggested namespace aliases, following this convention: +https://stuartsierra.com/2015/05/10/clojure-namespace-aliases" :group 'cljr :type 'boolean) @@ -2131,10 +2136,12 @@ Filters out existing alias in the namespace, or a global alias ;;;###autoload (defun cljr-slash () - "Inserts / as normal, but also checks for common namespace shorthands to require. -If `cljr-magic-requires' is non-nil, executing this command after one of the aliases -listed in `cljr-magic-require-namespaces', or any alias used elsewhere in the project, -will add the corresponding require statement to the ns form." + "Inserts / as normal, but also checks for common namespace shorthands +to require. +If `cljr-magic-requires' is non-nil, executing this command after one +of the aliases listed in `cljr-magic-require-namespaces', or any alias +used elsewhere in the project, will add the corresponding require statement +to the ns form." (interactive) (insert "/") (when-let (alias-ref (and cljr-magic-requires @@ -2865,8 +2872,8 @@ See: https://github.com/clojure-emacs/clj-refactor.el/wiki/cljr-rename-symbol" (defun cljr--replace-refer-all (ns alias) "Replaces :refer :all style require with alias :as style require. -Also adds the alias prefix to all occurrences of public symbols in the namespace. -" +Also adds the alias prefix to all occurrences of public symbols +in the namespace." (cljr--ensure-op-supported "find-used-publics") (let ((filename (funcall cider-to-nrepl-filename-function (buffer-file-name)))) (let* ((alias (or alias @@ -3153,9 +3160,9 @@ See: https://github.com/clojure-emacs/clj-refactor.el/wiki/cljr-add-missing-libs (defun cljr--dependency-at-point () "Returns project dependency at point. -Recognizes both leiningen- and deps.edn-style dependencies, but the latter is always -transformed back to leiningen dependency vector which is what nrepl backend -expects for hot-loading." +Recognizes both leiningen- and deps.edn-style dependencies, +but the latter is always transformed back to Leiningen dependency vector +which is what nrepl backend expects for hot-loading." (save-excursion (ignore-errors (while (not (cljr--looking-at-dependency-p)) @@ -3431,17 +3438,27 @@ See: https://github.com/clojure-emacs/clj-refactor.el/wiki/cljr-inline-symbol" (cljr--post-command-message "No occurrences of '%s' found. Deleted the definition." symbol))))) (cljr--indent-defun))) -(defun cljr--version (&optional remove-package-version) - "Get the version of `clj-refactor' from the package header. - -if REMOVE-PACKAGE_VERSION is t get rid of the (package: 20150828.1048) suffix." - (let ((version (replace-regexp-in-string "snapshot" "-SNAPSHOT" - (string-trim (pkg-info-version-info 'clj-refactor))))) - (if remove-package-version - (replace-regexp-in-string " (.*)" "" version) - version))) - -;; We used to derive the version out of `(cljr--version t)`, +(defvar cljr-version) + +(defun cljr--pkg-version () + "Extract the package version from its package metadata." + ;; Use `cond' below to avoid a compiler unused return value warning + ;; when `package-get-version' returns nil. See cider#3181. + ;; FIXME: Inline the logic from package-get-version and adapt it + (cond ((fboundp 'package-get-version) + (package-get-version)))) + +(defun cljr--version (&optional _for-compat) + "Retrieve the version." + (if (string-match-p "-snapshot" cljr-version) + (let ((pkg-version (cljr--pkg-version))) + (if pkg-version + ;; snapshot versions include the MELPA package version + (format "%s (package: %s)" cljr-version pkg-version) + cljr-version)) + cljr-version)) + +;; We used to derive the version out of `(cljr--version)`, ;; but now prefer a fixed version to fully decouple things and prevent unforeseen behavior. ;; This suits better our current pace of development. (defcustom cljr-injected-middleware-version "3.9.0" @@ -3449,7 +3466,8 @@ if REMOVE-PACKAGE_VERSION is t get rid of the (package: 20150828.1048) suffix." You can customize this in order to try out new releases. -If customizing it, you most likely should `(setq cljr-suppress-middleware-warnings nil)' too, +If customizing it, you most likely should +`(setq cljr-suppress-middleware-warnings nil)' too, for avoiding a warning that would be irrelevant for this case." :type 'string :safe #'stringp @@ -4348,7 +4366,8 @@ See: https://github.com/clojure-emacs/clj-refactor.el/wiki/cljr-change-function- ;;;###autoload (defun cljr--inject-jack-in-dependencies () "Inject the REPL dependencies of clj-refactor at `cider-jack-in'. -If injecting the dependencies is not preferred set `cljr-inject-dependencies-at-jack-in' to nil." +If injecting the dependencies is not preferred set +`cljr-inject-dependencies-at-jack-in' to nil." (when (and cljr-inject-dependencies-at-jack-in (fboundp 'cider-add-to-alist) (boundp 'cider-preferred-build-tool) diff --git a/test/clj-refactor-bytecomp-warnings.el b/test/clj-refactor-bytecomp-warnings.el deleted file mode 100644 index c137c03b..00000000 --- a/test/clj-refactor-bytecomp-warnings.el +++ /dev/null @@ -1,40 +0,0 @@ -;;; clj-refactor-bytecomp-warnings.el --- Check for byte-compilation problems - -;; Copyright © 2012-2020 Bozhidar Batsov and contributors -;; -;; 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 . - -;; This file is not part of GNU Emacs. - -;;; Commentary: - -;; This is a script to be loaded while visiting a `clj-refactor' source file. -;; It will prepare all requirements and then byte-compile the file and signal an -;; error on any warning. For example: -;; -;; emacs -Q --batch -l test/clj-refactor-bytecomp-warnings.el clj-refactor.el - -;; This assumes that all `clj-refactor' dependencies are already on the package -;; dir (probably from running `cask install'). - -(setq load-prefer-newer t) -(add-to-list 'load-path (expand-file-name "./")) -(require 'package) -(package-generate-autoloads 'clj-refactor default-directory) -(package-initialize) -(load-file "clj-refactor-autoloads.el") -(setq byte-compile-error-on-warn t) -(batch-byte-compile) - -;;; clj-refactor-bytecomp-warnings.el ends here diff --git a/test/test-checks.el b/test/test-checks.el deleted file mode 100644 index 9ea91b5a..00000000 --- a/test/test-checks.el +++ /dev/null @@ -1,31 +0,0 @@ -;; This is a script to be loaded from the root `clj-refactor' directory. It will -;; prepare all requirements and then run `check-declare-directory' on -;; `default-directory'. For example: emacs -Q --batch -l test/test-checkdoc.el - -;; This assumes that all `clj-refactor' dependencies are already on the package -;; dir (probably from running `cask install'). - -(add-to-list 'load-path (expand-file-name "./")) -(require 'package) -(require 'check-declare) -(package-initialize) - -;; disable some annoying (or non-applicable) checkdoc checks -(setq checkdoc-package-keywords-flag nil) -(setq checkdoc-arguments-in-order-flag nil) -(setq checkdoc-verb-check-experimental-flag nil) - -(when (not (getenv "CI")) ;; See https://github.com/clojure-emacs/clj-refactor.el/issues/491 - (let ((files (directory-files default-directory t - "\\`[^.].*\\.el\\'" t))) - - ;; `checkdoc-file' was introduced in Emacs 25 - (when (fboundp 'checkdoc-file) - (dolist (file files) - (checkdoc-file file)) - (when (get-buffer "*Warnings*") - (message "Failing due to checkdoc warnings...") - (kill-emacs 1))) - - (when (apply #'check-declare-files files) - (kill-emacs 1)))) diff --git a/watch-tests.watchr b/watch-tests.watchr deleted file mode 100644 index 823a6aab..00000000 --- a/watch-tests.watchr +++ /dev/null @@ -1,45 +0,0 @@ -ENV["WATCHR"] = "1" -system 'clear' - -def run(cmd) - `#{cmd}` -end - -def run_all_tests - system('clear') - result = run "cask exec ecukes --no-win" - puts result -end - -def run_test(file) - system('clear') - result = run "cask exec ecukes #{file} --no-win --verbose" - puts result -end - -run_all_tests -watch('.*.feature') { |file| run_test file } -watch('.*.el') { run_all_tests } - -# Ctrl-\ -Signal.trap 'QUIT' do - puts " --- Running all tests ---\n\n" - run_all_tests -end - -@interrupted = false - -# Ctrl-C -Signal.trap 'INT' do - if @interrupted then - @wants_to_quit = true - abort("\n") - else - puts "Interrupt a second time to quit" - @interrupted = true - Kernel.sleep 1.5 - # raise Interrupt, nil # let the run loop catch it - run_all_tests - @interrupted = false - end -end