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

[Feature Request] Produce a warning for unused methods #243

Open
caspiano opened this issue Sep 13, 2021 · 5 comments
Open

[Feature Request] Produce a warning for unused methods #243

caspiano opened this issue Sep 13, 2021 · 5 comments
Labels

Comments

@caspiano
Copy link
Contributor

Crystal's behaviour of not type-checking unused code paths can lead to some annoying situations.
A lint that checks that every method is called will help reduce dead and broken code in a codebase.

@veelenga
Copy link
Member

This can be applied only to unused private methods. This is a part of the roadmap

@caspiano
Copy link
Contributor Author

I think traversing the shard/app's specs may still be useful for producing a warning if a public method that is exported by the project isn't used (can't be guaranteed that it compiles)

@veelenga
Copy link
Member

What if the shard is some kind of api and public method is designed to be used in a separate dependent shard?

@caspiano
Copy link
Contributor Author

In that case, wouldn't you expect that method to have been spec'd?
I think it could encourage coverage of the library's public surface.

Would it make sense for it to be optional for unused public methods, with private unused method warnings enabled by default?

@veelenga
Copy link
Member

Ok, i see the point now, thanks. Keep in mind, Ameba makes static analysis only and knows nothing about types, so it is quite hard to do this properly. For example:

class MyClass
  def select
    # ...
  end
end

# somewhere in spec...

obj.select { ... } # is this a custom method or the built-in one `Array#select` ?

While detecting unused private methods could be a bit easier, since you can use them only in class, finding unused public methods could be challenging and in my understanding doesn't worth it if we disable that by default.

@Sija Sija added rule and removed feature labels Oct 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants