-
Notifications
You must be signed in to change notification settings - Fork 38
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
Expand ameba's functionality with semantic information #513
Comments
Other rule ideas possible with top level semantic (not saying these should be done, but that they could be):
|
This will just need to be left up to an LSP using ameba, and not something we should worry about.
Any issues found in a file that's excluded should be ignored, like how it is currently (except for For another rule idea, I run into this issue a lot: class MessageHandler
def on_request(msg)
# generic message handling
end
def on_request(msg : SpecificRequestType)
# specific message handling
end
end If I accidentally mistype One of the biggest issues I see with Crystal currently is that no semantic analysis is done to code that isn't used. This means when developing library code, unless you write good specs (and know you have to write good specs), you can have semantic issues in your code and have no idea until someone else goes to use it. It would be useful to have some level of semantic analysis for methods, such that explicitly typed things can be checked to make sure their methods actually exist. For example: def hello(a : String)
a.method_doesnt_exist
# ^^^^^^^^^^^^^^^^^^^ error: `String` doesn't have method `method_doesnt_exist`
end If the rule runs into a method that isn't typed, we don't do anything beyond that. The only types this should infer is from literals or methods whose return types are specified. It should be fast, not exhaustive. |
I've started messing around with integrating ameba into larimar (https://github.com/nobodywasishere/larimar), a language server that I've been working on since last June. This allows for not only running lints while typing (via the language server protocol in an editor-independent way), but also for re-using functionality ameba has developed over time. For example, I re-used the This can be made better (provide actual type resolved to instead of just As more time is spent investigating / experimenting with semantic analysis, I think it would be useful for larimar and ameba to share the same / similar visitors and mechanisms. As mentioned above, the visitor / rule that checks for unknown methods could be the same visitor that larimar uses for providing autocomplete. |
Here's a general approach I think may work:
One basic example I wrote up quickly for ![]() Some notes:
Thoughts? cc @Sija @veelenga @straight-shoota @devnote-dev |
I figured out the path issues I was running into - needed to pass in environment variables from the current Crystal installation. With some work implementing the above, I have a basic Branch here: |
@nobodywasishere looks promising. Could you please draft a PR, so we can move from there. |
Sure thing! It won't be perfect, and the approach I'm taking may not be the best, but it's at least a starting point. |
crystal-lang/crystal#14613 (comment) Another rule that could be implemented is |
Currently ameba uses only the stdlib parser in order to provide an AST for the rules to operate over. This is useful, but limits the kinds of things that ameba can be used for. This is an issue to discuss if semantic information to ameba, what that would look like, and what are the downsides / tradeoffs to different approaches. For instance, if we added a top level semantic pass:
Excluded
in.ameba.yml
?Typing/{Instance,Class}VarTypeRestriction
- currently running into potential issues where an instance var could be typed somewhere, but just not in the current file, leading to a failureLint/UnusedVariable
and othersThe text was updated successfully, but these errors were encountered: