Class: RuboCop::CLI::Command::InitDotfile Private

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cli/command/init_dotfile.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Generate a .rubocop.yml file in the current directory.

Constant Summary collapse

DOTFILE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

ConfigLoader::DOTFILE

Instance Attribute Summary

Attributes inherited from Base

#env

Instance Method Summary collapse

Methods inherited from Base

by_command_name, inherited, #initialize

Constructor Details

This class inherits a constructor from RuboCop::CLI::Command::Base

Instance Method Details

#runObject

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.


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rubocop/cli/command/init_dotfile.rb', line 13

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://docs.rubocop.org/rubocop/configuration
    DESC

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

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

    STATUS_SUCCESS
  end
end