glebm / i18n-tasks

Manage translation and localization with static analysis, for Ruby i18n
http://glebm.github.io/i18n-tasks
MIT License
2.08k stars 265 forks source link

Error scanning app/models/application_record.rb: undefined method `type' for nil:NilClass #489

Closed hobbypunk90 closed 1 week ago

hobbypunk90 commented 1 year ago

Heyho,

i have a problem with the rails model matcher. At first i need to require it in my config - weird, but okay :grin:

<% require 'i18n/tasks/scanners/ast_matchers/rails_model_matcher' %>
<% I18n::Tasks.add_ast_matcher('I18n::Tasks::Scanners::AstMatchers::RailsModelMatcher') %>

When i run it now, i get this error:

#<Thread:0x00007f2d4ee278e0 /home/marcel/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/i18n-tasks-1.0.12/lib/i18n/tasks/scanners/scanner_multiplexer.rb:33 run> terminated with exception (report_on_exception is true):
/home/marcel/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/i18n-tasks-1.0.12/lib/i18n/tasks/scanners/ast_matchers/rails_model_matcher.rb:19:in `human_attribute_name_to_key_occurences': Error scanning app/models/application_record.rb: undefined method `type' for nil:NilClass (I18n::Tasks::CommandError)

      return unless method_name == :human_attribute_name && receiver.type == :const
                                                                    ^^^^^
        from /home/marcel/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/i18n-tasks-1.0.12/lib/i18n/tasks/scanners/ast_matchers/rails_model_matcher.rb:8:in `convert_to_key_occurrences'
        from /home/marcel/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/i18n-tasks-1.0.12/lib/i18n/tasks/scanners/ruby_ast_scanner.rb:106:in `block (2 levels) in ast_to_occurences'
        from /home/marcel/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/i18n-tasks-1.0.12/lib/i18n/tasks/scanners/ruby_ast_scanner.rb:105:in `each'
        from /home/marcel/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/i18n-tasks-1.0.12/lib/i18n/tasks/scanners/ruby_ast_scanner.rb:105:in `block in ast_to_occurences'
        from /home/marcel/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/i18n-tasks-1.0.12/lib/i18n/tasks/scanners/ruby_ast_scanner.rb:104:in `each'
        from /home/marcel/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/i18n-tasks-1.0.12/lib/i18n/tasks/scanners/ruby_ast_scanner.rb:104:in `ast_to_occurences'
        from /home/marcel/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/i18n-tasks-1.0.12/lib/i18n/tasks/scanners/ruby_ast_scanner.rb:32:in `scan_file'
        from /home/marcel/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/i18n-tasks-1.0.12/lib/i18n/tasks/scanners/file_scanner.rb:27:in `block in keys'
        from /home/marcel/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/i18n-tasks-1.0.12/lib/i18n/tasks/scanners/files/file_finder.rb:30:in `map'
        from /home/marcel/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/i18n-tasks-1.0.12/lib/i18n/tasks/scanners/files/file_finder.rb:30:in `traverse_files'
        from /home/marcel/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/i18n-tasks-1.0.12/lib/i18n/tasks/scanners/file_scanner.rb:57:in `traverse_files'
        from /home/marcel/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/i18n-tasks-1.0.12/lib/i18n/tasks/scanners/file_scanner.rb:26:in `keys'
        from /home/marcel/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/i18n-tasks-1.0.12/lib/i18n/tasks/scanners/scanner_multiplexer.rb:34:in `block (3 levels) in collect_results'
/home/marcel/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/i18n-tasks-1.0.12/lib/i18n/tasks/scanners/ast_matchers/rails_model_matcher.rb:19:in `human_attribute_name_to_key_occurences': undefined method `type' for nil:NilClass (NoMethodError)

      return unless method_name == :human_attribute_name && receiver.type == :const
                                                                    ^^^^^
        from /home/marcel/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/i18n-tasks-1.0.12/lib/i18n/tasks/scanners/ast_matchers/rails_model_matcher.rb:8:in `convert_to_key_occurrences'
        from /home/marcel/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/i18n-tasks-1.0.12/lib/i18n/tasks/scanners/ruby_ast_scanner.rb:106:in `block (2 levels) in ast_to_occurences'
        from /home/marcel/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/i18n-tasks-1.0.12/lib/i18n/tasks/scanners/ruby_ast_scanner.rb:105:in `each'
        from /home/marcel/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/i18n-tasks-1.0.12/lib/i18n/tasks/scanners/ruby_ast_scanner.rb:105:in `block in ast_to_occurences'
        from /home/marcel/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/i18n-tasks-1.0.12/lib/i18n/tasks/scanners/ruby_ast_scanner.rb:104:in `each'
        from /home/marcel/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/i18n-tasks-1.0.12/lib/i18n/tasks/scanners/ruby_ast_scanner.rb:104:in `ast_to_occurences'
        from /home/marcel/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/i18n-tasks-1.0.12/lib/i18n/tasks/scanners/ruby_ast_scanner.rb:32:in `scan_file'
        from /home/marcel/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/i18n-tasks-1.0.12/lib/i18n/tasks/scanners/file_scanner.rb:27:in `block in keys'
        from /home/marcel/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/i18n-tasks-1.0.12/lib/i18n/tasks/scanners/files/file_finder.rb:30:in `map'
        from /home/marcel/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/i18n-tasks-1.0.12/lib/i18n/tasks/scanners/files/file_finder.rb:30:in `traverse_files'
        from /home/marcel/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/i18n-tasks-1.0.12/lib/i18n/tasks/scanners/file_scanner.rb:57:in `traverse_files'
        from /home/marcel/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/i18n-tasks-1.0.12/lib/i18n/tasks/scanners/file_scanner.rb:26:in `keys'
        from /home/marcel/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/i18n-tasks-1.0.12/lib/i18n/tasks/scanners/scanner_multiplexer.rb:34:in `block (3 levels) in collect_results'
i18n-tasks: Error scanning app/models/application_record.rb: undefined method `type' for nil:NilClass

      return unless method_name == :human_attribute_name && receiver.type == :const

Greets Marcel

brad-ellert commented 1 year ago

Not sure about this error, but you no longer need to require it like that after #512.

davidwessman commented 1 week ago

Sorry I never had the capacity to look at this, fix available in #603