Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rubocop: Call super to initialize state of the parent class even when super class doesn't have initialization [closed]

Out of nowhere, Rubocop is complaining about classes that are not calling super.

W: Lint/MissingSuper: Call `super` to initialize state of the parent class.

Example:

# frozen_string_literal: true

class ApplicationService
  class << self
    def call(*args)
      new(*args).call
    end
  end

  def initialize(_args)
    raise NotImplementedError
  end

  def call
    raise NotImplementedError
  end
end
class SampleService < ApplicationService
  def initialize(something)
    @something = something
  end

  def call
   # do something
  end

  private

  # remaining methods
end

I have ApplicationService just as a way to easily call a service with: SampleService.call(arguments).

like image 642
user14288887 Avatar asked Oct 26 '25 03:10

user14288887


1 Answers

For the services you could set in .rubocop.yml:

Lint/MissingSuper:
  Exclude:
    - 'app/services/**/*'

source: Recommend calling super in initialize

like image 74
Juanse Gimenez Avatar answered Oct 28 '25 05:10

Juanse Gimenez