Skip to content

Commit 5e819b6

Browse files
committed
Fixes for lint/misplaced-type-hint and naming/record-name
1 parent d1bc374 commit 5e819b6

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ This changelog is loose. Versions are not semantic, they are incremental. Splint
2323

2424
- Disable `lint/thread-macro-one-arg` by default. It harms readability in a lot of cases and has limited usefulness.
2525
- `:import` parsing now includes both the base class name as well as the fully qualified class name in the returned map, which improves all interop scenarios.
26+
- Include the misplaced type hint in the `Form` output of `lint/misplaced-type-hint`.
2627

2728
### Fixed
2829

2930
- Correctly resolve auto-resolving keywords in the current namespace: `(ns foo) ::bar` will be parsed as `:foo/bar` instead of `:splint-auto-current/bar`.
3031
- `naming/lisp-case` now only looks at symbols.
32+
- `naming/record-name` doesn't crash when analyzing `` `(defrecord ~@body)``.
3133

3234
## 1.20.0 - 2025-03-28
3335

src/noahtheduke/splint/rules/lint/misplaced_type_hint.clj

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@
4141
(when-let [defn-form (:splint/defn-form (meta form))]
4242
(when-let [tag (:tag defn-form)]
4343
(let [arities (:arities defn-form)
44+
tag (symbol (str "^" tag))
4445
arities (if (= 1 (count (:arities defn-form)))
45-
(cons (symbol (str "^" tag)) (first arities))
46-
(map #(cons (symbol (str "^" tag)) %) arities))
47-
replace-form (->list (list* ?defn (:splint/name defn-form) arities))]
48-
(->diagnostic ctx rule form {:replace-form replace-form})))))})
46+
(cons tag (first arities))
47+
(map #(cons tag %) arities))
48+
replace-form (->list (list* ?defn (:splint/name defn-form) arities))
49+
original-form (with-meta (->list (list* ?defn tag (next form)))
50+
(meta form))]
51+
(->diagnostic ctx rule original-form {:replace-form replace-form})))))})

src/noahtheduke/splint/rules/naming/record_name.clj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
(set! *warn-on-reflection* true)
1212

1313
(defn bad-name? [sexp]
14-
(let [record-name (str sexp)]
15-
(not= record-name (csk/->PascalCase record-name))))
14+
(when (symbol? sexp)
15+
(let [record-name (str sexp)]
16+
(not= record-name (csk/->PascalCase record-name)))))
1617

1718
(defrule naming/record-name
1819
"Records should use PascalCase. (Replacement is generated with [camel-snake-kebab](https://github.com/clj-commons/camel-snake-kebab).)

test/noahtheduke/splint/rules/lint/misplaced_type_hint_test.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
(it "handles single arities"
2020
(expect-match
2121
[{:rule-name rule-name
22-
:form '(defn make-str [] "abc")
22+
:form (list 'defn (symbol "^String") 'make-str [] "abc")
2323
:alt (list 'defn 'make-str (symbol "^String") [] "abc")}]
2424
"(defn ^String make-str [] \"abc\")"
2525
(config)))
2626
(it "handles multi-arities"
2727
(expect-match
2828
[{:rule-name rule-name
29-
:form '(defn make-str ([] "abc") ([a] (str a "abc")))
29+
:form (list 'defn (symbol "^String") 'make-str '([] "abc") '([a] (str a "abc")))
3030
:alt (list 'defn 'make-str (list (symbol "^String") [] "abc")
3131
(list (symbol "^String") '[a] '(str a "abc")))}]
3232
"(defn ^String make-str ([] \"abc\") ([a] (str a \"abc\")))"

test/noahtheduke/splint/rules/naming/record_name_test.clj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,10 @@
3636
:form '(defrecord Foo-bar [a b c])
3737
:alt '(defrecord FooBar [a b c])}]
3838
"(defrecord Foo-bar [a b c])"
39+
(single-rule-config rule-name)))
40+
(it "doesn't crash in a macro"
41+
{:focus true}
42+
(expect-match
43+
nil
44+
"`(defrecord ~@body)"
3945
(single-rule-config rule-name))))

0 commit comments

Comments
 (0)