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

Check generated RBI files for correctness #842

Merged
merged 3 commits into from Mar 29, 2022
Merged

Conversation

Morriar
Copy link
Collaborator

@Morriar Morriar commented Mar 4, 2022

Motivation

Catches parse errors in generated RBI files and display a helpful error message:

image

Closes #759.

Implementation

Since we already run sorbet on generated files to catch redefinition errors and change the strictness of generated files, I decided to hook on this process to check if we find parse errors (code < 4000) as well.

Tests

See automated tests.

@Morriar Morriar added the enhancement New feature or request label Mar 4, 2022
@Morriar Morriar added this to the Tapioca 1.0 milestone Mar 4, 2022
@Morriar Morriar requested a review from a team March 4, 2022 16:29
@Morriar Morriar self-assigned this Mar 4, 2022
update_gem_rbis_strictnesses([], gem_dir: @gem_dir, dsl_dir: @outpath.to_s)
say("")
validate_rbi_files(
command: default_command(:dsl, @requested_constants.join(" ")),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It would be better to use the real Thor command here but I believe it would require a lot of refactoring

Copy link
Member

Choose a reason for hiding this comment

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

I think this is good enough.

@Morriar Morriar force-pushed the at-check-parse-errors branch 2 times, most recently from 229791c to 8446ab7 Compare March 4, 2022 16:37
Copy link
Member

@paracycle paracycle left a comment

Choose a reason for hiding this comment

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

Nice! Just a couple of comments.

lib/tapioca/helpers/rbi_helper.rb Outdated Show resolved Hide resolved
lib/tapioca/commands/dsl.rb Outdated Show resolved Hide resolved
update_gem_rbis_strictnesses([], gem_dir: @gem_dir, dsl_dir: @outpath.to_s)
say("")
validate_rbi_files(
command: default_command(:dsl, @requested_constants.join(" ")),
Copy link
Member

Choose a reason for hiding this comment

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

I think this is good enough.

@@ -48,10 +107,8 @@ def update_gem_rbis_strictnesses(gem_names, gem_dir: DEFAULT_GEM_DIR, dsl_dir: D
files
.uniq
.sort
.select do |file|
name = gem_name_from_rbi_path(file)
file.start_with?(gem_dir) && (gem_names.empty? || gem_names.include?(name))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Before the auto fix of the typed-override was only applied on requested gems but it doesn't make sense as a newly generated RBI can produce conflicts in old RBIs so I removed the feature.

@@ -1356,30 +1356,6 @@ def quux(x); end
assert_success_status(result)
end

it "must turn the strictness of files with error to false only in asked gems" do
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Relative to the feature removed as explained in https://github.com/Shopify/tapioca/pull/842/files#r835335074.

Copy link
Member

@paracycle paracycle left a comment

Choose a reason for hiding this comment

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

Just a small note about No errors instead of No error, otherwise, LGTM.

lib/tapioca/helpers/rbi_helper.rb Outdated Show resolved Hide resolved
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 merged commit 4256b3d into main Mar 29, 2022
@Morriar Morriar deleted the at-check-parse-errors branch March 29, 2022 18:28
@shopify-shipit shopify-shipit bot temporarily deployed to production May 13, 2022 23:08 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Catch invalid RBIs during the generation
3 participants