Skip to content

Commit

Permalink
Allow for non-RSpec base cop usage
Browse files Browse the repository at this point in the history
  • Loading branch information
pirj committed Dec 11, 2022
1 parent f8340c0 commit f941a9c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
3 changes: 2 additions & 1 deletion bin/build_config
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ rspec_cop_path = File.join('lib', 'rubocop', 'cop', 'rspec', 'base.rb')
YARD::Tags::Library.define_tag('Cop Safety Information', :safety)
YARD.parse(Dir[glob].prepend(rspec_cop_path), [])

descriptions = RuboCop::RSpec::DescriptionExtractor.new(YARD::Registry.all).to_h
descriptions =
RuboCop::RSpec::DescriptionExtractor.new(YARD::Registry.all(:class)).to_h
current_config = if Psych::VERSION >= '4.0.0' # RUBY_VERSION >= '3.1.0'
YAML.unsafe_load_file('config/default.yml')
else
Expand Down
15 changes: 5 additions & 10 deletions lib/rubocop/rspec/description_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def to_h

# Decorator of a YARD code object for working with documented rspec cops
class CodeObject
COP_CLASS_NAME = 'RuboCop::Cop::RSpec::Base'
RSPEC_COP_CLASS_NAME = 'RuboCop::Cop::RSpec::Base'
RUBOCOP_COP_CLASS_NAME = 'RuboCop::Cop::Base'
RSPEC_NAMESPACE = 'RuboCop::Cop::RSpec'

def initialize(yardoc)
Expand All @@ -32,10 +33,7 @@ def initialize(yardoc)
#
# @return [Boolean]
def rspec_cop?
class_documentation? &&
rspec_cop_namespace? &&
cop_subclass? &&
!abstract?
cop_subclass? && !abstract? && rspec_cop_namespace?
end

# Configuration for the documented cop that would live in default.yml
Expand All @@ -55,10 +53,6 @@ def description
yardoc.docstring.split("\n\n").first.to_s
end

def class_documentation?
yardoc.type.equal?(:class)
end

def rspec_cop_namespace?
documented_constant.start_with?(RSPEC_NAMESPACE)
end
Expand All @@ -68,7 +62,8 @@ def documented_constant
end

def cop_subclass?
yardoc.superclass.path == COP_CLASS_NAME
yardoc.superclass.path == RSPEC_COP_CLASS_NAME ||
yardoc.superclass.path == RUBOCOP_COP_CLASS_NAME
end

def abstract?
Expand Down
2 changes: 1 addition & 1 deletion spec/rubocop/rspec/description_extractor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def bar
end
RUBY

YARD::Registry.all
YARD::Registry.all(:class)
end

let(:temp_class) do
Expand Down

0 comments on commit f941a9c

Please sign in to comment.