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

Chore: Add witness hint for enum_tuple_variant_field_missing lint #1214

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/lints/enum_tuple_variant_field_missing.ron
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ SemverQuery(
end_line @output
}
}

field @fold @transform(op: "count") @output(name: "field_count")
}
}
}
Expand Down Expand Up @@ -72,4 +74,10 @@ SemverQuery(
},
error_message: "A field of a tuple variant in a pub enum has been removed.",
per_result_error_template: Some("field {{field_name}} of variant {{enum_name}}::{{variant_name}}, previously in file {{span_filename}}:{{span_begin_line}}"),
witness: (
hint_template: r#"match value {
{{ join "::" path }}::{{ variant_name }}({{#repeat field_count }}{{#if (eq (to_string @index) ../field_name) }}witness{{else}}_{{/if}}{{#unless @last}}, {{/unless}}{{/repeat}}) => (),
_ => (),
}"#,
),
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ snapshot_kind: text
"./test_crates/enum_struct_field_hidden_from_public_api/": [
{
"enum_name": String("RemovedHiddenFieldFromVariant"),
"field_count": Uint64(4),
"field_name": String("3"),
"path": List([
String("enum_struct_field_hidden_from_public_api"),
Expand All @@ -21,6 +22,7 @@ snapshot_kind: text
"./test_crates/enum_tuple_variant_field_missing/": [
{
"enum_name": String("PublicEnum"),
"field_count": Uint64(3),
"field_name": String("2"),
"path": List([
String("enum_tuple_variant_field_missing"),
Expand Down
23 changes: 23 additions & 0 deletions test_outputs/witnesses/enum_tuple_variant_field_missing.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
source: src/query.rs
assertion_line: 847
description: "Lint `enum_tuple_variant_field_missing` did not have the expected witness output.\nSee https://github.com/obi1kenobi/cargo-semver-checks/blob/main/CONTRIBUTING.md#testing-witnesses\nfor more information."
expression: "&actual_witnesses"
---
[["./test_crates/enum_struct_field_hidden_from_public_api/"]]
filename = 'src/lib.rs'
begin_line = 38
hint = '''
match value {
enum_struct_field_hidden_from_public_api::RemovedHiddenFieldFromVariant::VisibleTupleVariantBreaking(_, _, _, witness) => (),
_ => (),
}'''

[["./test_crates/enum_tuple_variant_field_missing/"]]
filename = 'src/lib.rs'
begin_line = 5
hint = '''
match value {
enum_tuple_variant_field_missing::PublicEnum::TupleVariantWithMissingField(_, _, witness) => (),
_ => (),
}'''
Loading