Method: CopsDocumentationGenerator#initialize
- Defined in:
- lib/rubocop/cops_documentation_generator.rb
#initialize(departments: [], extra_info: {}, base_dir: Dir.pwd, plugin_name: nil) ⇒ CopsDocumentationGenerator
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This class will only generate documentation for cops that belong to one of the departments given in the departments array. E.g. if we only wanted documentation for Lint cops:
CopsDocumentationGenerator.new(departments: ['Lint']).call
For plugin extensions, specify :plugin_name keyword as follows:
CopsDocumentationGenerator.new(
departments: ['Performance'], plugin_name: 'rubocop-performance'
).call
You can append additional information:
callback = ->(data) { required_rails_version(data.cop) }
CopsDocumentationGenerator.new(extra_info: { ruby_version: callback }).call
This will insert the string returned from the lambda after the section from RuboCop itself. See CopsDocumentationGenerator::STRUCTURE for available sections.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rubocop/cops_documentation_generator.rb', line 46 def initialize(departments: [], extra_info: {}, base_dir: Dir.pwd, plugin_name: nil) @departments = departments.map(&:to_sym).sort! @extra_info = extra_info @cops = RuboCop::Cop::Registry.global @config = RuboCop::ConfigLoader.default_configuration # NOTE: For example, this prevents excessive plugin loading before another task executes, # in cases where plugins are already loaded by `internal_investigation`. if plugin_name && @config.loaded_plugins.none? { |plugin| plugin.about.name == plugin_name } RuboCop::Plugin.integrate_plugins(RuboCop::Config.new, [plugin_name]) end @base_dir = base_dir @docs_path = "#{base_dir}/docs/modules/ROOT" FileUtils.mkdir_p("#{@docs_path}/pages") end |