Skip to content

Add clj-kondo macro metadata build option #106

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

Merged
merged 4 commits into from
Sep 9, 2024

Conversation

radovanne
Copy link
Contributor

Issue

  • While applying clj-kondo linter metadata on tablecloth/let-dataset macro in this PR, I noticed that write-api! doesn't build macro metadata at all.

Reason

  • I think that clj-kondo is very good linter but It doesn't recognise custom macros which are common in Clojure code afaik.
    Usually developers write their own set of rules regarding how clj-kondo is going to behave but I believe that should be the case only for macros that are internally used.
    I was thinking that it would be beneficial if we could provide build option for linting metadata when macro is built using write-api!.

Solution

  • With helper function we check for all keys inside macro metadata and return only ones that have clj-kondo namespace part.
  • Meta string is being built from those filtered clj-kondo metadata key-pairs.
  • Check if meta string is not empty and if macro is being built.
  • Feed meta string to writer.
  • If macro is not being built or string is empty, step is going to be skipped.

Why I chose this approach

  • I wanted to do this with least invasive approach for the project which would be to force developers to respect certain rules if they want to add metadata that is going to be built.
  1. Metadata key must contain "clj-kondo"
  2. Metadata can only be built on macros.
  • By following unrecognized-macros docs I saw that there is shorter syntax for adding certain rules but I didn't think that as good approach in this case so I didn't include it in the rules. This way we are certain that only clj-kondo metadata will be added.

  • If there is an issue with this PR or an idea how to make it better I would like to hear it!
    My goal is to learn and contribute to open source as much as possible.

Created a helper function that is going to detect if macro contains
clj-kondo metadata.
If clj-kondo metadata map exists and macro is being built then add
metadata map to the built macro with coresponding clj-kondo metadata.
@radovanne
Copy link
Contributor Author

Hey @cnuernber ,
Do you think that this change would be valuable to the project?

@cnuernber
Copy link
Owner

Definitely - Thanks - it will take me a bit to review this but it looks good to me at first glance.

@radovanne radovanne marked this pull request as ready for review August 22, 2024 07:27
@cnuernber cnuernber merged commit 711367a into cnuernber:master Sep 9, 2024
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.

2 participants