Skip to content
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

Merged
merged 4 commits into from May 3, 2024

Conversation

zimzoom
Copy link
Contributor

@zimzoom zimzoom commented Apr 24, 2024

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

  • [x ] I have updated/added unit and integration tests that prove my fix is effective or that my feature works
  • [x ] New and existing unit and int tests pass locally and remotely with my changes
  • [x ] I have removed unnecessary/dead code and imports in files I have changed
  • [x ] I have performed a self-review of my own code
  • [x ] I have commented my code, particularly in hard-to-understand areas
  • [x ] I have made corresponding changes to the documentation
  • [x ] My changes generate no new warnings

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]}}}
Copy link
Contributor

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

  1. 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.
  2. 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 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.

  1. 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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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
Copy link
Contributor

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?

Copy link
Contributor Author

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)

Copy link
Contributor Author

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.

(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]
Copy link
Contributor

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.

Copy link
Contributor Author

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]
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@eereiter eereiter left a 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.

@codecov-commenter
Copy link

codecov-commenter commented Apr 24, 2024

Codecov Report

Attention: Patch coverage is 57.14286% with 21 lines in your changes are missing coverage. Please review.

Project coverage is 57.80%. Comparing base (289c472) to head (3621d47).

Files Patch % Lines
common-app-lib/src/cmr/common_app/api/routes.clj 0.00% 8 Missing ⚠️
...-control-app/src/cmr/access_control/api/routes.clj 0.00% 3 Missing ⚠️
.../common_app/api/request_context_user_augmenter.clj 0.00% 3 Missing ⚠️
acl-lib/src/cmr/acl/acl_fetcher.clj 50.00% 1 Missing ⚠️
common-app-lib/src/cmr/common_app/api/health.clj 0.00% 1 Missing ⚠️
.../collections_for_gran_acls_by_concept_id_cache.clj 0.00% 1 Missing ⚠️
.../src/cmr/common_app/data/humanizer_alias_cache.clj 0.00% 1 Missing ⚠️
common-app-lib/src/cmr/common_app/humanizer.clj 91.66% 0 Missing and 1 partial ⚠️
...c/cmr/elastic_utils/search/es_index_name_cache.clj 0.00% 1 Missing ⚠️
...-lib/src/cmr/umm_spec/umm_to_xml_mappings/dif9.clj 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2102      +/-   ##
==========================================
- Coverage   57.81%   57.80%   -0.01%     
==========================================
  Files        1044     1044              
  Lines       70318    70311       -7     
  Branches     1966     1964       -2     
==========================================
- Hits        40653    40645       -8     
  Misses      27808    27808              
- Partials     1857     1858       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@zimzoom zimzoom merged commit ab2e261 into master May 3, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants