Betterment / betterlint

MIT License
41 stars 15 forks source link

Fix false positives from ActiveJobPerformable #9

Closed rzane closed 1 year ago

rzane commented 1 year ago

The following code was incorrectly being recognized as an offense:

class MyBusinessLogic
  class MyJob < ApplicationJob
    def perform
      MyBusinessLogic.call
    end
  end
end

This was happening because Node#descendants returns all of the nodes descendants (recursively), rather than the node's immediate children.

smudge commented 1 year ago

@rzane though you may want to increment the version number if you want a new release out after this merges.

rzane commented 1 year ago

@smudge, not sure what's going on, but I don't see a merge button. I'm guessing I don't have permission?

aburgel commented 1 year ago

@rzane @smudge This change breaks on empty classes:

class MyClass
end
     NoMethodError:
       undefined method `begin_type?' for nil:NilClass
     # ./lib/rubocop/cop/betterment/active_job_performable.rb:39:in `possible_methods_within'
     # ./lib/rubocop/cop/betterment/active_job_performable.rb:35:in `has_perform_method?'
     # ./lib/rubocop/cop/betterment/active_job_performable.rb:27:in `on_class'

nody.body is nil in this case. return [] if node.body.nil? at the beginning of possible_methods_within will fix it.

rzane commented 1 year ago

Ah! Thank you @aburgel! I'll fix this right away!