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

Migrate dead code detection to Prism #527

Merged
merged 11 commits into from Mar 15, 2024
Merged

Migrate dead code detection to Prism #527

merged 11 commits into from Mar 15, 2024

Conversation

Morriar
Copy link
Collaborator

@Morriar Morriar commented Mar 13, 2024

Replace the dependency on SyntaxTree by Prism.

This PR may be easier to read commit by commit as switching the parser deeply impacted the implementation and required a lot of changes. I used the tests as source of truth.

Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
A visitor that always go through `visit` to allow common behavior for all
nodes without having to define all the `visit_*` methods.

Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
@Morriar Morriar added the chore Chore task label Mar 13, 2024
@Morriar Morriar self-assigned this Mar 13, 2024
@Morriar Morriar requested a review from a team as a code owner March 13, 2024 14:13
Comment on lines 45 to 47
message = result.errors.map do |e|
"#{e.message} (at #{e.location.start_line}:#{e.location.start_column})."
end.join(" ")
Copy link
Member

@paracycle paracycle Mar 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like you are trying to display multiple errors in a single line here, and I think the resulting text ends up being confusing.

How about building something like, which is much easier to read IMO:

Encountered error(s) while parsing foo.rb: 
- expected a `)` to close the parameters (at 1:8).
- cannot parse the expression (at 1:8). 
- expected an `end` to close the `def` statement (at 1:8).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is that we do not display the errors straight away, instead we raise and I always been under the impression that exception messages should be single line? wdyt?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if it is a requirement for the message to be a single line. After all, the docs for detailed_message do talk about decorating the first line of the exception message which implies that it might be expecting more than 1 line: https://ruby-doc.org/3.3.0/Exception.html#method-i-detailed_message

It may add the class name of the exception to the end of the first line.

There is another option at your disposal as well, though. You could store the formatted errors in your custom exception, and do the formatting at the site that's doing the handling. You could even encapsulate the formatting in the to_s of the exception class.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you go 35b15d8 👍

By default, `srb` will look for RBIs coming from gems. Since we migrated to
Prism, Sorbet is now picking up the RBI shipped with the gem which results
in a lot of errors.

We can disable this behavior by using Tapioca. See sorbet/sorbet#3332.

Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
@Morriar Morriar merged commit 6374c3b into main Mar 15, 2024
8 checks passed
@Morriar Morriar deleted the at-deadcode-prism branch March 15, 2024 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Chore task
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants