clojure-emacs / clojure-emacs/clj-refactor.el

cljr--find-source-ns-of-test-ns can choose the wrong namespace when there are multiple matches

Open
#407 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Emacs Lisp
Stars
785
Forks
110
PR merge metrics
No merged PRs in 30d

Description

The sut can choose the wrong namespace when there are multiple partial matches. For example, given a source tree with:

```
src/advent/day1.clj
src/advent/day10.clj
```

Creating a new buffer named `test/advent/day10_test.clj` results in:

```
(ns advent.day10-test
(:require [advent.day1 :as sut]
[clojure.test :as t]))
```
When we'd expect:

```
(ns advent.day10-test
(:require [advent.day10 :as sut]
[clojure.test :as t]))
```

I have a partial fix at https://github.com/orb/clj-refactor.el/commit/a8306c2ff0c81d5930e90afa4a304e2a495bed55. I did not submit a PR because I didn't meet all the contribution requirements yet. However, the basic idea was that instead of finding the first matching file, we'd find the longest matching file.

This solution works well when the `sut` class exists. If, in this example, `src/advent/day10.clj` did not exist yet, it would still choose `advent.day1` as the best match. I don't like that, but I'm not sure how to best fix that and still maintain the flexibility the code is apparently trying to achieve.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.