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

Detect redundant calls to str #2323

Closed
borkdude opened this issue May 15, 2024 · 4 comments
Closed

Detect redundant calls to str #2323

borkdude opened this issue May 15, 2024 · 4 comments
Projects

Comments

@borkdude
Copy link
Member

  • (str "foo")
  • (str (format "foo"))

See branch redundant-call-string

@borkdude borkdude added this to Needs triage in clj-kondo via automation May 15, 2024
@borkdude borkdude moved this from Needs triage to High priority (next release) in clj-kondo May 15, 2024
clj-kondo automation moved this from High priority (next release) to Done May 16, 2024
@borkdude borkdude reopened this May 16, 2024
clj-kondo automation moved this from Done to Needs triage May 16, 2024
@borkdude borkdude moved this from Needs triage to High priority (next release) in clj-kondo May 16, 2024
@borkdude
Copy link
Member Author

borkdude commented May 16, 2024

One false positive:

(are [x y] (= x (str y))
  "foo" "bar"
  "foo" 1)

borkdude added a commit that referenced this issue May 16, 2024
@borkdude borkdude moved this from High priority (next release) to In progress in clj-kondo May 17, 2024
clj-kondo automation moved this from In progress to Done May 17, 2024
@NoahTheDuke
Copy link
Contributor

Dang, nice that you can reuse the "return type" of functions to check when str is redundant. I did this in splint but had to hardcode a couple built-in functions.

@borkdude
Copy link
Member Author

borkdude commented May 17, 2024

I like that you split it into a separate linter called :redundant-str-call, I might do that too and enable it by default (perhaps in a later release as to not cause trouble for people with a new linter that might not be perfect yet) since it might be a bit too hard to enable it now as part of redundant-call. Where did you have to hardcode it?

@NoahTheDuke
Copy link
Contributor

https://github.com/NoahTheDuke/splint/blob/0dd94d487b9ea9426d3b624aa294c6ee3fa7a1f9/src/noahtheduke/splint/rules/lint/redundant_str_call.clj#L16-L18

I'm checking (str (FUNC ...)) where FUNC is str or format. I don't know if it's worth checking lots more, I'm still determining where the line is for this kind of check. Once I get to 3+ functions, makes me feel like I should invest in tracking var definitions/locals, which is an incredible amount of work (as seen by clj-kondo).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
clj-kondo
  
Done
Development

No branches or pull requests

2 participants