New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CMR-9776: Resolve linter errors & warnings in common-app-lib; add linting config #2102
Conversation
.clj-kondo/config.edn
Outdated
cmr.common.jobs/def-stateful-job clojure.core/defn | ||
cmr.common.util/are3 clj-kondo.lint-as/def-catch-all} | ||
;; dynamically generated functions/vars | ||
:linters {:unresolved-var {:exclude [digest/md5 digest/sha-1]}}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is much better than the declare statements that I was using.
Can we also add are2 and are? They are deprecated functions, but the test code still uses them and are showing up as such from the linters.
Couple of questions
- When you merge this in does this work when running kondo only from the top level of the project or can kondo be run inside of each project and it will pick up this file? Or do you have to tell it about the file? I am using my own installed cli-kondo executable at the moment.
- After you merge in and I understand the answer to my first question I am assuming that I should remove the declare statements that I put in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Interestingly, I would have thought it would only work from the root level as well, but I just tried it and it does still work in the subprojects. I am using my own clj-kondo executable as well and have not added clj-kondo as a dep to CMR, just this config file since clj-kondo is now our officially supported linter to my knowledge.
I tested this by changing into the common-app-lib directory and running clj-kondo --lint ./src
, which still suppressed all the stuff mentioned here. To make sure I tried deleting the contents of config.edn and running it again and it did come back.
- I think that a lot of those, that you previously added, might be covered by what is here, but possibly not all. Maybe we should coordinate on rules for what to consistently ignore/exclude/include etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And yes, I will add are2 and are3 as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is just are2. are3 you already included and are is a clojure command.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note for Reader: discussed with reviewer here and we decided I will review the aforementioned declares that were already merged in for access-control-app, acl-lib, and es-spatial-plugin, and incorporate into this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reader has noted discussion.
@@ -0,0 +1,5 @@ | |||
{:lint-as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this file do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file was pulled in automatically by following the instructions in clj-kondo's project set up guide, which is here: https://github.com/clj-kondo/clj-kondo?tab=readme-ov-file#project-setup
To my understanding, this file (and the folder it is in) was written by the authors of this package clj-rewrite, which we have as a dependency, and they "exported" it so that projects using their package can import it and thus lint clj-rewrite correctly.
This seems to be the only one that exported a clj-kondo config. The super common ones like compojure are included in clj-kondo by default. The docs recommended adding this to version control. (see link above)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Originally I wanted to incorporate this into the build, but when I saw only 1 dep came out of it, I figured it wasn't worth it.
common-app-lib/src/cmr/common_app/api/request_context_user_augmenter.clj
Outdated
Show resolved
Hide resolved
(if-let [errors (seq (qv/validate query))] | ||
(errors/throw-service-errors :bad-request errors) | ||
query)) | ||
|
||
(defmulti search-results->response | ||
"Converts query search results into a string response." | ||
(fn [context query results] | ||
(fn [_context query _results] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have been converting the defmulti/defmethod functions to a function with a case statement when possible (it is almost always possible since most of the time all of the defmethod functions are in the same namespace), but I will let you decide if you want to do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this particular case, there do exist defmethods in other namespaces. Results handler namespaces to be exact, which account for a lot of the scattered multimethods.
[(:concept-type query) (qm/base-result-format query)])) | ||
|
||
(defmulti single-result->response | ||
"Returns a string representation of a single concept in the format | ||
specified in the query." | ||
(fn [context query results] | ||
(fn [_context query _results] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have been converting the defmulti/defmethod functions to a function with a case statement when possible (it is almost always possible since most of the time all of the defmethod functions are in the same namespace), but I will let you decide if you want to do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this particular case, there do exist defmethods in other namespaces. Results handler namespaces to be exact, which account for a lot of the scattered multimethods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some cases where you can purge a little more code than just use _ in front of a parameter.
Overview
What is the feature/fix?
Fix clj-kondo errors and warnings on common-app-lib.
Also added .clj-kondo to codebase, including config file and imported config from clj-rewrite.
What is the Solution?
See above, followed clj-kondo docs. See comments in config.edn file.
What areas of the application does this impact?
Quality control
Checklist