Skip to content

Expose built-in rules in Ruby - #1008

Merged
vinistock merged 1 commit into
mainfrom
vs_produce_built_in_rules_in_ruby
Aug 17, 2026
Merged

Expose built-in rules in Ruby#1008
vinistock merged 1 commit into
mainfrom
vs_produce_built_in_rules_in_ruby

Conversation

@vinistock

Copy link
Copy Markdown
Member

Fourth step towards #1000

This PR makes sure we automatically create RuleDefinition classes for all built-in diagnostics. This allows us to treat rule definitions consistently between the linter and the graph, since they are all just classes that inherit from RuleDefinition.

The idea is basically to have an all method in Rust that returns all rules and we use the names to create classes like class ParseError < RuleDefinition, which registers the identity of that rule in the Ruby side consistently with linting rules.

@vinistock vinistock self-assigned this Aug 14, 2026
@vinistock
vinistock requested a review from a team as a code owner August 14, 2026 15:50
@vinistock
vinistock force-pushed the vs_extract_rule_definition branch 2 times, most recently from 65d7c1e to fd06555 Compare August 14, 2026 19:53
@vinistock
vinistock force-pushed the vs_produce_built_in_rules_in_ruby branch from 567f063 to bf902d7 Compare August 14, 2026 19:55
Base automatically changed from vs_extract_rule_definition to main August 14, 2026 20:35
@vinistock
vinistock force-pushed the vs_produce_built_in_rules_in_ruby branch from bf902d7 to f3185b1 Compare August 14, 2026 20:36
Comment thread ext/rubydex/diagnostic.c
rb_ary_push(definitions, rule);
}

rdx_rule_definitions_free(definition_array);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we need to add an rb_ensure here to free the array when the above code raises exceptions.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Similar to the other comment, this runs upon requiring Rubydex. If this code raises, then it's a bug we have to fix internally and don't want to swallow. There's no way for a consumer of Rubydex to make this code raise.

@st0012 st0012 Aug 17, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's not to swallow the exception tho. It's so that we can still free the definition_array in that case.
I know it's not likely to happen but I think so far we always make sure free's called properly in all scenarios.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, but in this case, we're not protecting ourselves from external code that might be incorrect. We'd be protecting ourselves against our own code, but we can ensure that is never raising on our side.

Comment thread ext/rubydex/diagnostic.c
@vinistock
vinistock merged commit 18da1c9 into main Aug 17, 2026
36 checks passed
@vinistock
vinistock deleted the vs_produce_built_in_rules_in_ruby branch August 17, 2026 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants