From a4a1edbb8a0b4801dbc706280025e8a34f36e4f2 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Thu, 25 Jun 2026 22:22:30 +0100 Subject: [PATCH 1/2] Fix Diagnostic rule type --- lib/rubydex/diagnostic.rb | 4 ++-- rbi/rubydex.rbi | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/rubydex/diagnostic.rb b/lib/rubydex/diagnostic.rb index b13c599d6..694c5085e 100644 --- a/lib/rubydex/diagnostic.rb +++ b/lib/rubydex/diagnostic.rb @@ -2,7 +2,7 @@ module Rubydex class Diagnostic - #: Symbol + #: String attr_reader :rule #: String @@ -11,7 +11,7 @@ class Diagnostic #: Location attr_reader :location - #: (rule: Symbol, message: String, location: Location) -> void + #: (rule: String, message: String, location: Location) -> void def initialize(rule:, message:, location:) @rule = rule @message = message diff --git a/rbi/rubydex.rbi b/rbi/rubydex.rbi index 8d9787635..ce31e5d68 100644 --- a/rbi/rubydex.rbi +++ b/rbi/rubydex.rbi @@ -213,7 +213,7 @@ class Rubydex::Prepend < Rubydex::Mixin; end class Rubydex::Extend < Rubydex::Mixin; end class Rubydex::Diagnostic - sig { params(rule: Symbol, message: String, location: Rubydex::Location).void } + sig { params(rule: String, message: String, location: Rubydex::Location).void } def initialize(rule:, message:, location:); end sig { returns(Rubydex::Location) } @@ -222,7 +222,7 @@ class Rubydex::Diagnostic sig { returns(String) } def message; end - sig { returns(Symbol) } + sig { returns(String) } def rule; end end From 3e542c98ac1b38174b18b0c70aa13d21e23d2e50 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Fri, 26 Jun 2026 18:23:11 +0100 Subject: [PATCH 2/2] Return diagnostic rules as symbols --- ext/rubydex/graph.c | 2 +- lib/rubydex/diagnostic.rb | 4 ++-- rbi/rubydex.rbi | 4 ++-- test/graph_test.rb | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ext/rubydex/graph.c b/ext/rubydex/graph.c index 15912be63..689a0f28d 100644 --- a/ext/rubydex/graph.c +++ b/ext/rubydex/graph.c @@ -531,7 +531,7 @@ static VALUE rdxr_graph_diagnostics(VALUE self) { for (size_t i = 0; i < array->len; i++) { DiagnosticEntry entry = array->items[i]; VALUE message = entry.message == NULL ? Qnil : rb_utf8_str_new_cstr(entry.message); - VALUE rule = rb_str_new2(entry.rule); + VALUE rule = rb_str_intern(rb_str_new2(entry.rule)); VALUE location = rdxi_build_location_value(entry.location); VALUE kwargs = rb_hash_new(); diff --git a/lib/rubydex/diagnostic.rb b/lib/rubydex/diagnostic.rb index 694c5085e..b13c599d6 100644 --- a/lib/rubydex/diagnostic.rb +++ b/lib/rubydex/diagnostic.rb @@ -2,7 +2,7 @@ module Rubydex class Diagnostic - #: String + #: Symbol attr_reader :rule #: String @@ -11,7 +11,7 @@ class Diagnostic #: Location attr_reader :location - #: (rule: String, message: String, location: Location) -> void + #: (rule: Symbol, message: String, location: Location) -> void def initialize(rule:, message:, location:) @rule = rule @message = message diff --git a/rbi/rubydex.rbi b/rbi/rubydex.rbi index ce31e5d68..8d9787635 100644 --- a/rbi/rubydex.rbi +++ b/rbi/rubydex.rbi @@ -213,7 +213,7 @@ class Rubydex::Prepend < Rubydex::Mixin; end class Rubydex::Extend < Rubydex::Mixin; end class Rubydex::Diagnostic - sig { params(rule: String, message: String, location: Rubydex::Location).void } + sig { params(rule: Symbol, message: String, location: Rubydex::Location).void } def initialize(rule:, message:, location:); end sig { returns(Rubydex::Location) } @@ -222,7 +222,7 @@ class Rubydex::Diagnostic sig { returns(String) } def message; end - sig { returns(String) } + sig { returns(Symbol) } def rule; end end diff --git a/test/graph_test.rb b/test/graph_test.rb index 5a73a5958..dec560bea 100644 --- a/test/graph_test.rb +++ b/test/graph_test.rb @@ -59,8 +59,8 @@ def test_indexing_with_parse_errors assert_diagnostics( [ - { rule: "parse-error", path: "file.rb", message: "expected an `end` to close the `class` statement" }, - { rule: "parse-error", path: "file.rb", message: "unexpected end-of-input, assuming it is closing the parent top level context" }, + { rule: :"parse-error", path: "file.rb", message: "expected an `end` to close the `class` statement" }, + { rule: :"parse-error", path: "file.rb", message: "unexpected end-of-input, assuming it is closing the parent top level context" }, ], graph.diagnostics, )