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

Misclassification of java interoperability as function #2

Closed
wardle opened this issue Mar 22, 2023 · 7 comments
Closed

Misclassification of java interoperability as function #2

wardle opened this issue Mar 22, 2023 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@wardle
Copy link

wardle commented Mar 22, 2023

When mapping using an anonymous fn to use java interop, splint says 'No need to wrap function. Clojure supports first-class functions', but you generally cannot unwrap in this case. e.g. (map #(Integer/parseInt %) ["1" "2" "3"])

PS. Thank you very much for this linter - really brilliant at identifying style improvements - particularly those where I can vastly simplify code such as preferring or etc. Thank you!

@wardle
Copy link
Author

wardle commented Mar 22, 2023

The only method I could think of to do this without running code, and only using structure, would be to look either for (. - which is obviously interop, or ([A-Z] ie a call to a static method on a class so will be capitalised.

@NoahTheDuke
Copy link
Owner

NoahTheDuke commented Mar 22, 2023

Thanks for trying it out! I'm glad it's proving helpful.

This is an interesting one, and I think you have the solution right. I would rather be silent for potential matches than warn on valid usage. Clojure can allow for some wacky constructions so it's better to play it safe.

PR is welcome, if you wanna try your hand at tackling it. I haven't written any documentation for how the pattern matching works or how the rules are defined, lol, but that makes it more fun, right?

@NoahTheDuke NoahTheDuke added the bug Something isn't working label Mar 22, 2023
@wardle
Copy link
Author

wardle commented Mar 23, 2023

Thanks @NoahTheDuke - I'll have a look - will be interesting!

@NoahTheDuke
Copy link
Owner

NoahTheDuke commented Mar 31, 2023

I've written a bunch of documentation about how the pattern DSL and rules objects are built, if you're still interested: https://cljdoc.org/d/io.github.noahtheduke/splint/1.1.1/doc/rules

@wardle
Copy link
Author

wardle commented Apr 1, 2023

I'll have a look. Thanks!

@wardle
Copy link
Author

wardle commented Apr 7, 2023

I looked at this but it is tricky. The rough heuristic above with a dot might work for some cases, but it doesn't catch the use of static methods on a Java class.

@NoahTheDuke
Copy link
Owner

Yeah, that's definitely an issue. Without deeper analysis (like clj-kondo does), I suspect there's not much we can do.

Maybe we could use the list of built-in classes that Clojure recognizes and extract the :use symbols and check against those? That would cover the majority of cases I expect. That'll be a lot harder than a simple check against capital letters tho.

@NoahTheDuke NoahTheDuke self-assigned this Apr 22, 2023
NoahTheDuke added a commit that referenced this issue Apr 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants