Sha256: 2c1cee9032d9f5ab71b3871f44da55e2a11555a2f6c1f945b56914b7d1ea535e

Contents?: true

Size: 1.37 KB

Versions: 16

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

module RuboCop
  class CLI
    module Command
      # Generate a .rubocop.yml file in the current directory.
      class InitDotfile < Base
        DOTFILE = ConfigLoader::DOTFILE

        self.command_name = :init

        def run
          path = File.expand_path(DOTFILE)

          if File.exist?(DOTFILE)
            warn Rainbow("#{DOTFILE} already exists at #{path}").red

            STATUS_ERROR
          else
            description = <<~DESC
              # The behavior of RuboCop can be controlled via the .rubocop.yml
              # configuration file. It makes it possible to enable/disable
              # certain cops (checks) and to alter their behavior if they accept
              # any parameters. The file can be placed either in your home
              # directory or in some project directory.
              #
              # RuboCop will start looking for the configuration file in the directory
              # where the inspected file is and continue its way up to the root directory.
              #
              # See https://github.com/rubocop-hq/rubocop/blob/master/manual/configuration.md
            DESC

            File.open(DOTFILE, 'w') do |f|
              f.write(description)
            end

            puts "Writing new #{DOTFILE} to #{path}"

            STATUS_SUCCESS
          end
        end
      end
    end
  end
end

Version data entries

16 entries across 15 versions & 4 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cli/command/init_dotfile.rb
files.com-1.0.1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.85.1/lib/rubocop/cli/command/init_dotfile.rb
rubocop-0.85.1 lib/rubocop/cli/command/init_dotfile.rb
rubocop-0.85.0 lib/rubocop/cli/command/init_dotfile.rb
rubocop-0.84.0 lib/rubocop/cli/command/init_dotfile.rb
rubocop-0.83.0 lib/rubocop/cli/command/init_dotfile.rb
rubocop-0.82.0 lib/rubocop/cli/command/init_dotfile.rb
rubocop-0.81.0 lib/rubocop/cli/command/init_dotfile.rb
rubocop-0.80.1 lib/rubocop/cli/command/init_dotfile.rb
rubocop-0.80.0 lib/rubocop/cli/command/init_dotfile.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/rubocop-0.79.0/lib/rubocop/cli/command/init_dotfile.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cli/command/init_dotfile.rb
rubocop-0.79.0 lib/rubocop/cli/command/init_dotfile.rb
rubocop-0.78.0 lib/rubocop/cli/command/init_dotfile.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.77.0/lib/rubocop/cli/command/init_dotfile.rb
rubocop-0.77.0 lib/rubocop/cli/command/init_dotfile.rb