Rubocop:调用 super 来初始化父级 class 的状态,即使 super class 没有初始化
Rubocop: Call super to initialize state of the parent class even when super class doesn't have initialization
不知何故,Rubocop 抱怨 类 没有调用 super。
W: Lint/MissingSuper: Call `super` to initialize state of the parent class.
示例:
# 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
我有 ApplicationService
作为一种轻松调用服务的方法:SampleService.call(arguments)
。
对于您可以在中设置的服务。rubocop.yml:
Lint/MissingSuper:
Exclude:
- 'app/services/**/*'
不知何故,Rubocop 抱怨 类 没有调用 super。
W: Lint/MissingSuper: Call `super` to initialize state of the parent class.
示例:
# 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
我有 ApplicationService
作为一种轻松调用服务的方法:SampleService.call(arguments)
。
对于您可以在中设置的服务。rubocop.yml:
Lint/MissingSuper:
Exclude:
- 'app/services/**/*'