clojure-emacs / clj-refactor.el

A CIDER extension that provides powerful commands for refactoring Clojure code.
GNU General Public License v3.0
771 stars 111 forks source link

cljr-clean-ns erroneously removes :as-alias in clj namespaces #516

Closed DerGuteMoritz closed 2 years ago

DerGuteMoritz commented 2 years ago

Expected behavior

Using the same scenario as clojure-emacs/refactor-nrepl#378 but on a namespace declared in a clj rather than a cljc file: When invoking cljr-clean-ns on a namespace which contains an unused require as well as a keyword literal referring to a namespace which is only required with :as-alias like so:

(ns some-ns
  (:require [foo :as-alias f]
            [unused :as-alias clean-me-up]))

(def bar ::f/bar)

The unused namespace should be removed.

Actual behavior

The unused namespace is removed (correct) but also, the :as-alias declaration is removed even though a keyword literal still refers to it:

(ns some-ns
  (:require [foo]))

(def bar ::f/bar)

Steps to reproduce the problem

See above.

Environment & Version information

clj-refactor.el version information

clj-refactor 3.4.2, refactor-nrepl 3.4.1

CIDER version information

CIDER 1.3.0 (Ukraine), nREPL 0.9.0 Clojure 1.11.0-rc1, Java 11.0.12

Clojure CLI version

1.10.3.1029

Emacs version

GNU Emacs 27.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.31, cairo version 1.16.0)

Operating system

NixOS on nixpkgs rev 3e644bd62489b516292c816f70bf0052c693b3c7

vemv commented 2 years ago

Thanks for the detailed reports!

Sounds like an issue in refactor-nrepl, I'll take a look