Sha256: 1923f1d33ae09b329457ea2158695d1cf776e7711ce6d4e467de889a3c5de85b

Contents?: true

Size: 958 Bytes

Versions: 241

Compression:

Stored size: 958 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  # This class handles collecting the options for regenerating a TODO file.
  # @api private
  class ConfigRegeneration
    AUTO_GENERATED_FILE = RuboCop::CLI::Command::AutoGenerateConfig::AUTO_GENERATED_FILE
    COMMAND_REGEX = /(?<=`rubocop )(.*?)(?=`)/.freeze
    DEFAULT_OPTIONS = { auto_gen_config: true }.freeze

    # Get options from the comment in the TODO file, and parse them as options
    def options
      # If there's no existing TODO file, generate one
      return DEFAULT_OPTIONS unless todo_exists?

      match = generation_command.match(COMMAND_REGEX)
      return DEFAULT_OPTIONS unless match

      options = match[1].split
      Options.new.parse(options).first
    end

    private

    def todo_exists?
      File.exist?(AUTO_GENERATED_FILE) && !File.empty?(AUTO_GENERATED_FILE)
    end

    def generation_command
      File.foreach(AUTO_GENERATED_FILE).take(2).last
    end
  end
end

Version data entries

241 entries across 232 versions & 21 rubygems

Version Path
rubocop-1.68.0 lib/rubocop/config_regeneration.rb
rubocop-1.67.0 lib/rubocop/config_regeneration.rb
rubocop-1.66.1 lib/rubocop/config_regeneration.rb
rubocop-1.66.0 lib/rubocop/config_regeneration.rb
rubocop-1.65.1 lib/rubocop/config_regeneration.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubocop-1.64.1/lib/rubocop/config_regeneration.rb
rubocop-1.65.0 lib/rubocop/config_regeneration.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/config_regeneration.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/config_regeneration.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/config_regeneration.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/rubocop-1.64.1/lib/rubocop/config_regeneration.rb
rubocop-1.64.1 lib/rubocop/config_regeneration.rb
rubocop-1.63.4 lib/rubocop/config_regeneration.rb
rubocop-1.63.3 lib/rubocop/config_regeneration.rb
rubocop-1.63.2 lib/rubocop/config_regeneration.rb
harbr-2.8.1 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/config_regeneration.rb
rubocop-1.63.1 lib/rubocop/config_regeneration.rb
rubocop-1.63.0 lib/rubocop/config_regeneration.rb
bison-0.1.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.62.1/lib/rubocop/config_regeneration.rb
rubocop-1.62.1 lib/rubocop/config_regeneration.rb