Rubocop: Call super to initialize state of the parent class even when super class doesn't have initi

Publish date: 2024-06-15

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).

2

1 Answer

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

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

source: Recommend calling super in initialize

1

ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJobW5vYmWGeHyOq6ybp5OkvW6vwKWjZqulpbKzedOoZKKmmam2orjIs5xmq6SWwaZ5zp9kraCVYr2ivsSnq2abnJbAtHnEr5ynZaedsq950q6nnqpdmLmivw%3D%3D