This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-04
Channels
- # admin-announcements (1)
- # adventofcode (98)
- # announcements (5)
- # asami (3)
- # babashka (24)
- # beginners (51)
- # bitcoin (3)
- # calva (24)
- # clj-kondo (73)
- # cljdoc (5)
- # cljs-dev (2)
- # clojure (15)
- # clojure-czech (3)
- # clojure-dev (27)
- # clojure-europe (7)
- # clojure-gamedev (1)
- # clojure-italy (2)
- # clojure-uk (1)
- # conjure (4)
- # cursive (18)
- # datahike (4)
- # datomic (3)
- # deps-new (7)
- # emacs (1)
- # events (10)
- # fulcro (5)
- # honeysql (4)
- # jackdaw (2)
- # java (13)
- # lsp (85)
- # meander (9)
- # membrane (1)
- # minecraft (1)
- # off-topic (45)
- # re-frame (16)
- # sql (17)
- # tools-deps (10)
- # vscode (9)
- # xtdb (8)
I am thinking of a lint rule. Warn when there are unused inputs in some code paths of a function. Consider this function
(defn scan
[price display input]
(if-let [product-id (parse-product-id input)]
(if-let [product-price (price product-id)]
(display product-price)
(display "Not found!"))
(display "Invalid code!")))
If the parse function returns nil, the code execution moves to calling display with "Invalid code". In this code path, the price input remains unused. Is this something possible with a lint rule?I am not very familiar with cljkondo. If there is a way to store lint rules in another library and pass them to cljkondo via config, I would very much love to build/use such a lint rule.
Is such a rule even possible with current capabilities of clj-kondo?
From an initial skim of the document, it sounds like I have to register my custom code for every function I wish it to be executed against. In my scenario scan
was one function where the issue was demonstrated. I would ideally like to lint/check every (as many as needed) function.
@U0A5B1LJU In your case, I recommend to make a fork of clj-kondo to experiment and see how useful your linting rule becomes.
And then you could raise an issue and explain in more detail why you would want to contribute that back
In the case of your linting rule, I expect this would be "too much" for most people, it is very common to not use all arguments in all branches
I noticed this section https://github.com/clj-kondo/clj-kondo/tree/master/analysis#analysis-data-and-tools ... is that a viable option? or forking is more viable?
but you cannot see if they are in the left or right side of an if for example (I think)
> I expect this would be "too much" for most people, it is very common to not use all arguments in all branches True. Even I am not sure how useful it will be. It is an experiment for me.
I think what you can do with the analysis: You know the scope of each local You know the locations of each usage of the local You know the scope of each var usage (function call)
Then you can decide if there are function calls within the scope of a local that have no local usages
Would supporting the kind of linter we are theorizing , be a valid reason to augment the analysis data 🙏
it's a chicken and egg problem: you don't know if it's worth adding until you know that what you added it for is useful enough
Thanks a lot. This is helpful. It will take me a while to understand the code enough to build this. It will be interesting for me to do though 🙂 Will ping in the channel when I need help. Thanks again.
I moved on to working on tech.ml.dataset and I reduced the linting issues down to just a few things that are difficult to reduce further.
(graal-native/when-not-defined-graal-native
(require '[clojure.pprint :as pprint])
(defmethod pprint/simple-dispatch
tech.v3.dataset.impl.dataset.Dataset [f] (pr f)))
I use that to keep pprint out of graal native. That simple-dispatch is required for some editors to correctly print a dataset. It produces the warning:
src/tech/v3/dataset/impl/dataset.clj:452:13: warning: Unresolved namespace pprint. Are you missing a require?
Next -
(definterface PParser
(addValue [^long idx value])
(finalize [^long rowcount]))
This produces a warning -
src/tech/v3/dataset/io/column_parsers.clj:132:20: warning: unused binding rowcount
Next I have a file with a complex macro system so I can efficiently bind the many and varied arrow https://github.com/techascent/tech.ml.dataset/blob/master/src/tech/v3/libs/arrow/datatype.clj. I would like to exclude this file entirely from processing.@chris441 I think this would work:
{:lint-as {graal-native/when-not-defined-graal-native clojure.core/comment}}
https://github.com/techascent/tech.ml.dataset/ - master branch - scripts/clj-kondo
I added a config to turn comments off. This combined with the graal-macro-as-comment pathway worked for two of them.
Again, I would be interested in being able to exclude files either in config.edn or in a bit of namespace metadata from linting altogether. I don't think supporting complex macro systems that are used purely to compress implementation is worth it.
(base) chrisn@chrisn-lt3:~/dev/tech.all/tech.ml.dataset$ gpush To http://github.com:techascent/tech.ml.dataset b6f9f4e..e3fca12 master -> master (base) chrisn@chrisn-lt3:~/dev/tech.all/tech.ml.dataset$ scripts/clj-kondo src/tech/v3/dataset/io/column_parsers.clj:132:20: warning: unused binding rowcount src/tech/v3/libs/arrow/datatype.clj:15:13: warning: Unused import TimeStampMilliTZVector linting took 969ms, errors: 0, warnings: 2
Also I recommend checking in the config for cneurber/dtype-next into the .clj-kondo dir
btw- I am super happy with where this ended up. I get a bit more robustness, linting, and discoverability across every clojure editor as a result of the whole process. Thanks for the help so far - will definitely shout it out.
That would be one. The second is being able to skip linting for a particular file via config.