rouge-ruby / rouge

A pure Ruby code highlighter that is compatible with Pygments
https://rouge.jneen.net/
Other
3.35k stars 739 forks source link

JSON5 lexer may fail to load in Ruby < 3.0 #2083

Closed t-kinoshita closed 1 week ago

t-kinoshita commented 1 week ago

Please note: This is for non-lexer bugs.

Describe the bug failed in loading Rouge::Lexers::JSON5

TypeError: superclass must be a Class (Module given)
 /usr/local/bundle/gems/rouge-4.5.0/lib/rouge/lexers/json5.rb:8:in `<module:Lexers>'
 /usr/local/bundle/gems/rouge-4.5.0/lib/rouge/lexers/json5.rb:5:in `<module:Rouge>'
/usr/local/bundle/gems/rouge-4.5.0/lib/rouge/lexers/json5.rb:4:in `<main>'
/usr/local/bundle/gems/rouge-4.5.0/lib/rouge/lexer.rb:532:in `load'
/usr/local/bundle/gems/rouge-4.5.0/lib/rouge/lexer.rb:532:in `load_lexer'
/usr/local/bundle/gems/rouge-4.5.0/lib/rouge.rb:52:in `block in load_lexers'
/usr/local/bundle/gems/rouge-4.5.0/lib/rouge.rb:51:in `each'
/usr/local/bundle/gems/rouge-4.5.0/lib/rouge.rb:51:in `load_lexers'
/usr/local/bundle/gems/rouge-4.5.0/lib/rouge.rb:67:in `<main>'

It seems ::JSON is loaded instead of Rouge::Lexers::JSON.

Expected behavior Successfully loaded without error

System (please complete the following information):

Additional context Pathname.glob (seen in Rouge.load_lexers) returns unordered list in Ruby < 3.0, so Rouge::Lexers::JSON may not loaded before Rouge::Lexers::JSON5 in such environments.

tancnle commented 1 week ago

Thank you for reporting this bug @t-kinoshita 🙇🏼‍♂️ I have raised a PR to address it, will merge and push a patch in the next 24 hours.