Skip to content

Commit

Permalink
Merge branch 'master' into invalid-fn-name
Browse files Browse the repository at this point in the history
  • Loading branch information
tomdl89 committed Nov 24, 2023
2 parents e41531c + c3366f9 commit e44e734
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ For a list of breaking changes, check [here](#breaking-changes).
## Unreleased

- [#2159](https://github.com/clj-kondo/clj-kondo/issues/2159): New linter, `:invalid-fn-name`
- [#1753](https://github.com/clj-kondo/clj-kondo/issues/1753): new linter `:underscore-in-namespace`
- [#2207](https://github.com/clj-kondo/clj-kondo/issues/2207): New `:condition-always-true` linter, see [docs](doc/linters.md)
- [#2013](https://github.com/clj-kondo/clj-kondo/issues/2013): Fix NPE and similar errors when linting an import with an illegal token

Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,15 @@ pod](https://github.com/babashka/babashka.pods).
;;=> {:error 0, :warning 0, :info 0, :type :summary, :duration 779}
```

## Podcast
## Podcasts

+ [defnpodcast](https://soundcloud.com/defn-771544745)
+ [ClojureScript Podcast](https://clojurescriptpodcast.com/)

## Articles

- [Taking your linting to the next level](https://blog.tvaisanen.com/take-your-linting-game-to-the-next-level?showSharer=true#heading-benefits-of-types-in-the-editor) by Toni Vaisanen

## Thanks to:

- [joker](https://github.com/candid82/joker) for inspiration
Expand Down
2 changes: 1 addition & 1 deletion corpus/no_unused_namespace.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns no_unused-namespace
(ns no-unused-namespace
(:require [clojure.string :as str]))

(let [{score (if (str/starts-with? "foo" "f")
Expand Down
4 changes: 4 additions & 0 deletions doc/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,10 @@ This tells clj-kondo to copy clj-kondo configs from dependencies while linting.

Typically, you will want to check copied configs into version control with your project.

See this
[article](https://blog.tvaisanen.com/take-your-linting-game-to-the-next-level?showSharer=true#heading-benefits-of-types-in-the-editor)
by Toni Vaisanen on how to use library configurations and malli!

## Deprecations

Some configuration keys have been renamed over time. The default configuration
Expand Down
2 changes: 1 addition & 1 deletion doc/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Use `println` or `prn` for debugging and `time` to measure performance.
Hooks must be configured in clj-kondo's `config.edn` under `:hooks`, e.g.:

``` Clojure
{:hooks {:analyze-call {foo.weird-macro hooks.foo/weird-macro}}}
{:hooks {:analyze-call {foo/weird-macro hooks.foo/weird-macro}}}
```

## analyze-call
Expand Down
12 changes: 12 additions & 0 deletions doc/linters.md
Original file line number Diff line number Diff line change
Expand Up @@ -1964,3 +1964,15 @@ namespaces. Defaults to only warning when doing interop.

The value of `:warn-only-on-interop` can be set to `false` to always warn in
Clojure namespaces.

## Underscore in namespace

*Keyword:* `:underscore-in-namespace`

*Description:* warns about the usage of the `_` character in the declaration of namespaces (as opposed to `-`).

*Default level:* `:warning`

*Example trigger:* `(ns special_files)`

*Example message:* `Avoid underscore in namespace name: special_files`
11 changes: 11 additions & 0 deletions src/clj_kondo/impl/analyzer/namespace.clj
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,17 @@
ns-name-expr
:namespace-name-mismatch
(str "Namespace name does not match file name: " ns-name)))))))

_ (when (and (not (identical? :off (-> ctx :config :linters :underscore-in-namespace :level)))
(symbol? ns-name)
(str/includes? (name ns-name) "_"))
(findings/reg-finding!
ctx
(node->line filename
ns-name-expr
:underscore-in-namespace
(str "Avoid underscore in namespace name: " ns-name))))

clauses children
_ (run! #(utils/handle-ignore ctx %) children)
kw+libspecs (for [?require-clause clauses
Expand Down
3 changes: 2 additions & 1 deletion src/clj_kondo/impl/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@
:protocol-method-varargs {:level :error}
:unused-alias {:level :off}
:self-requiring-namespace {:level :off}
:condition-always-true {:level :off}}
:condition-always-true {:level :off}
:underscore-in-namespace {:level :warning}}
;; :hooks {:macroexpand ... :analyze-call ...}
:lint-as {cats.core/->= clojure.core/->
cats.core/->>= clojure.core/->>
Expand Down
13 changes: 13 additions & 0 deletions test/clj_kondo/main_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3449,6 +3449,19 @@ foo/")))
(assert-submaps2 expected (lint! "(import 3.14)"))
(assert-submaps2 expected (lint! "(import -1)"))))

(deftest underscore-in-ns

(let [expected #(list {:file "<stdin>"
:row 1 :col 5
:level :warning
:message (str "Avoid underscore in namespace name: " %)})]

(assert-submaps2 (expected "beep_boop") (lint! "(ns beep_boop)"))
(assert-submaps2 (expected "beep_") (lint! "(ns beep_)"))
(assert-submaps2 (expected "_boop") (lint! "(ns _boop)"))
(assert-submaps2 (expected "never_give.you-up") (lint! "(ns never_give.you-up)"))
(assert-submaps2 (expected "a.large-smelly_dog") (lint! "(ns a.large-smelly_dog)"))))

;;;; Scratch

(comment
Expand Down

0 comments on commit e44e734

Please sign in to comment.