Data-Liberation-Front / csvlint.rb

The gem behind http://csvlint.io
MIT License
286 stars 87 forks source link

Regression: #229 on Ruby 3.3 #296

Closed Floppy closed 1 week ago

Floppy commented 1 week ago

Originally posted by @jalada in https://github.com/Data-Liberation-Front/csvlint.rb/issues/291#issuecomment-2428833319

Hey folks, this seems to have caused a regression whereby https://github.com/Data-Liberation-Front/csvlint.rb/issues/229 resurfaces when using the gem standalone on Ruby 3.3. I hotfixed it by adding require 'active_support/all', but I don't know how good a fix that is.

D-system commented 1 week ago

I reproduced the issue and the mentioned fix works. Let me see if I can add a test to catch that error.

It does works on older Ruby versions.

Ruby 3.3.5

❯ irb
irb(main):001> require "csvlint"
=> true
irb(main):002> validator = Csvlint::Validator.new( StringIO.new( "a1,b2\n34,abc" ) )
/Users/thomas/.local/share/mise/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/csvlint-1.4.0/lib/csvlint/validate.rb:576:in `line_limit_reached?': undefined method `present?' for nil (NoMethodError)

      @limit_lines.present? && @current_line > @limit_lines
                  ^^^^^^^^^
        from /Users/thomas/.local/share/mise/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/csvlint-1.4.0/lib/csvlint/validate.rb:111:in `block in validate_stream'
        from /Users/thomas/.local/share/mise/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/csvlint-1.4.0/lib/csvlint/validate.rb:110:in `each_line'
        from /Users/thomas/.local/share/mise/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/csvlint-1.4.0/lib/csvlint/validate.rb:110:in `validate_stream'
        from /Users/thomas/.local/share/mise/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/csvlint-1.4.0/lib/csvlint/validate.rb:103:in `validate'
        from /Users/thomas/.local/share/mise/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/csvlint-1.4.0/lib/csvlint/validate.rb:88:in `initialize'
        from (irb):2:in `new'
        from (irb):2:in `<main>'
        from <internal:kernel>:187:in `loop'
        from /Users/thomas/.local/share/mise/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/irb-1.14.1/exe/irb:9:in `<top (required)>'
        from /Users/thomas/.local/share/mise/installs/ruby/3.3.5/bin/irb:25:in `load'
        from /Users/thomas/.local/share/mise/installs/ruby/3.3.5/bin/irb:25:in `<main>'
irb(main):003> require "active_support"
=> false
irb(main):004> require "active_support/all"
=> true
irb(main):005> validator = Csvlint::Validator.new( StringIO.new( "a1,b2\n34,abc" ) )
=> 
#<Csvlint::Validator:0x0000000133a7dd50

Ruby 2.7.6

❯ irb                
irb(main):001:0> require "csvlint"
=> true
irb(main):002:0> validator = Csvlint::Validator.new( StringIO.new( "a1,b2\n34,abc" ) )
=> #<Csvlint::Validator:0x0000000129a1c258 @errors=[], @warnings=[], @info_messages=[#<Csvlint::ErrorMessage:0x0000000129a165b0 @type=:assumed_header, @category=:structure, @row=nil, @column=nil, @con...