Sha256: b55b1a1415cf260e28283aabaffc2354f6459874bca74fad11c486134f4b4151
Contents?: true
Size: 1.47 KB
Versions: 1
Compression:
Stored size: 1.47 KB
Contents
module RubocopAutoCorrector class CopFinder attr_reader :cop_name # @param cop_name [String] e.g. Metrics/AbcSize def initialize(cop_name) @cop_name = cop_name end # Whether this cop is auto correctable # @return [Boolean] def auto_correctable? Object.new.instance_eval <<-RUBY begin require '#{gem_name}' rescue LoadError end #{cop_class_name}.new.respond_to?(:autocorrect) RUBY rescue NameError false end # @return [String] def gem_name gem_name, = rubocop_cop_info gem_name end # @return [String] def cop_class_name _, cop_class = rubocop_cop_info cop_class end private def rubocop_cop_info cop_class_suffix = cop_name.gsub('/', '::') case cop_name when %r{^RSpec/} ['rubocop-rspec', "::RuboCop::Cop::#{cop_class_suffix}"] when %r{^(FactoryBot|Capybara)/}, 'Rails/HttpStatus' ['rubocop-rspec', "::RuboCop::Cop::RSpec::#{cop_class_suffix}"] when %r{^(Layout|Lint|Metrics|Naming|Rails|Security|Style|Bundler|Gemspec)/} # Official cops ['rubocop', "::RuboCop::Cop::#{cop_class_suffix}"] else # Unknown cops department_camel = cop_name.split('/').first department_snake = department_camel.gsub(/(?<=.)([A-Z])/) { |s| "_#{s}" }.downcase ["rubocop-#{department_snake}", "::RuboCop::Cop::#{cop_class_suffix}"] end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rubocop_auto_corrector-0.2.0 | lib/rubocop_auto_corrector/cop_finder.rb |