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

Add invalid-fn-name linter #2211

Closed
wants to merge 6 commits into from
Closed

Conversation

tomdl89
Copy link
Contributor

@tomdl89 tomdl89 commented Nov 6, 2023

Fixes #2159 paritially

Please answer the following questions and leave the below in as part of your PR.

This, effectively supersedes #2160, although as noted in the test file, there is still room for a linter which catches bound vars threaded into fn name position.

@tomdl89
Copy link
Contributor Author

tomdl89 commented Nov 7, 2023

I noticed that the % arg needed adding to the bindings, as that isn't done by expand fn. I also noticed that#() in ->> forms needs expanding too, and fn* needed adding to checks, in order to surface unsued-value lints which otherwise don't show. So a bit of scope drift, but all related.

@tomdl89
Copy link
Contributor Author

tomdl89 commented Nov 7, 2023

During this PR, I have spotted this false positive, which is also fixed:
image
n.b. hello is not bound, but doesn't need to be. the warning says it's an unresolved symbol

@tomdl89
Copy link
Contributor Author

tomdl89 commented Nov 24, 2023

Merged master back in so it's easier to see it can be merged. Also updated the error message to be a bit more accurate. I think the only question that needs answering before it can be merged is if it's ok to set the default config for this to be :error or :off? @borkdude lmk if there's anything else you'd like to see before merging. Thanks!

@borkdude
Copy link
Member

Hey @tomdl89 ! I appreciate the effort, but I think the PR fixes more than one issue and partially fixes the main issue it was written for? If this PR is only for checking that the name of a fn should be simple symbol (unqualified), then I think there is a much simpler PR possible.

@tomdl89
Copy link
Contributor Author

tomdl89 commented Dec 15, 2023

Hey @borkdude yes the PR definitely has some scope creep, no doubt. But I'm fairly sure it isn't otherwise over-engineered.

The only bit of code that checks for invalid fns directly is invalid-fn-name? and reg-invalid-fn-name! (and the supporting vector-node? helper fn).

The rest of the code is expanding function reader literals (i.e. #(...) ) before the threading macros are expanded (they weren't before, which means some linting couldn't happen). I can split this out if you would prefer?

That, and tests to support the above work.

Some project prefer separate PRs, but I felt that it was connected enough to warrant one PR. Let me know what you'd like and I'll get on it :)

@borkdude
Copy link
Member

Yes, let's split it up into tinier issues. With the expanding of fn literals, please give a test case that would otherwise fail with the current order.

@borkdude
Copy link
Member

@tomdl89 I quickly bashed together a PR to show how I would have done it:

#2243

Happy to make you co-author of the PR if it gets merged. Feedback welcome.

@tomdl89
Copy link
Contributor Author

tomdl89 commented Dec 15, 2023

Ah, cool. I just extracted mine too. Lemme compare the approaches...

@tomdl89
Copy link
Contributor Author

tomdl89 commented Dec 15, 2023

So, your version is arguably a bit neater, but it does miss things like this:

(fn {:foo :bar} [x] (+ x 42))

which mine catches, because it explicitly says the first arg has to be a symbol, arg vec or fn arity:

({:file "<stdin>",
  :row 1,
  :col 1,
  :level :error,
  :message "First arg of fn should be a symbol, params vector or arity clause"})

otherwise, good catch on needing to lint it for fns and defns. I'll add that.

@tomdl89 tomdl89 marked this pull request as draft December 15, 2023 18:27
@tomdl89
Copy link
Contributor Author

tomdl89 commented Dec 15, 2023

I'll close this to reduce clutter. Can spin out the threading-macro-related functionality in a later PR.

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.

New linter idea: threaded-fn-form
2 participants