Skip to content

Commit

Permalink
Merge pull request rubocop#1055 from geniou/rename_todo_file
Browse files Browse the repository at this point in the history
Rename rubocop-todo.yml file to .rubocop_todo.yml
  • Loading branch information
bbatsov committed Apr 30, 2014
2 parents 2a0e713 + 1d9bbc8 commit 8e67b3e
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# This is the configuration used to check the rubocop source code.

inherit_from: rubocop-todo.yml
inherit_from: .rubocop_todo.yml
4 changes: 2 additions & 2 deletions rubocop-todo.yml → .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This configuration was generated by `rubocop --auto-gen-config`
# on 2014-04-29 14:42:33 +0200 using RuboCop version 0.21.0.
# on 2014-04-29 22:57:01 +0200 using RuboCop version 0.21.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -14,7 +14,7 @@ ClassLength:
CyclomaticComplexity:
Max: 10

# Offense count: 115
# Offense count: 114
# Configuration parameters: CountComments.
MethodLength:
Max: 20
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* `NonNilCheck` offense reporting and autocorrect are configurable to include semantic changes. ([@hannestyden][])
* The parameters `AllCops/Excludes` and `AllCops/Includes` with final `s` only give a warning and don't halt `rubocop` execution. ([@jonas054][])
* The `GuardClause` cop is no longer irgnoring a one-line body by default - see configuration. ([@geniou][])
* [#1050](https://github.com/bbatsov/rubocop/issues/1050): Rename `rubocop-todo.yml` file to `.robcop_todo.yml`. ([@geniou][])

### Bugs fixed

Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,13 @@ CyclomaticComplexity:

### Automatically Generated Configuration

If you have a code base with an overwhelming amount of offenses, it can be a
good idea to use `rubocop --auto-gen-config` and add an `inherit_from:
rubocop-todo.yml` in your `.rubocop.yml`. The generated file `rubocop-todo.yml`
contains configuration to disable all cops that currently detect an offense in
the code. Then you can start removing the entries in the generated file one by
one as you work through all the offenses in the code.
If you have a code base with an overwhelming amount of offenses, it can
be a good idea to use `rubocop --auto-gen-config` and add an
`inherit_from: .rubocop_todo.yml` in your `.rubocop.yml`. The generated
file `.rubocop_todo.yml` contains configuration to disable all cops that
currently detect an offense in the code. Then you can start removing the
entries in the generated file one by one as you work through all the
offenses in the code.

## Disabling Cops within Source Code

Expand Down
14 changes: 12 additions & 2 deletions lib/rubocop/config_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ConfigLoader
DOTFILE = '.rubocop.yml'
RUBOCOP_HOME = File.realpath(File.join(File.dirname(__FILE__), '..', '..'))
DEFAULT_FILE = File.join(RUBOCOP_HOME, 'config', 'default.yml')
AUTO_GENERATED_FILE = 'rubocop-todo.yml'
AUTO_GENERATED_FILE = '.rubocop_todo.yml'

class << self
attr_accessor :debug, :auto_gen_config
Expand Down Expand Up @@ -57,7 +57,11 @@ def merge(base_hash, derived_hash)
def base_configs(path, inherit_from)
configs = Array(inherit_from).map do |f|
f = File.join(File.dirname(path), f) unless f.start_with?('/')
next if auto_gen_config? && f.include?(AUTO_GENERATED_FILE)

if auto_gen_config?
next if f.include?(AUTO_GENERATED_FILE)
old_auto_config_file_warning if f.include?('rubocop-todo.yml')
end

print 'Inheriting ' if debug?
load_file(f)
Expand Down Expand Up @@ -123,6 +127,12 @@ def dirs_to_search(target_dir)
end
dirs_to_search << Dir.home
end

def old_auto_config_file_warning
warn 'Attention: rubocop_todo.yml has been renamed to ' \
"#{AUTO_GENERATED_FILE}".color(:red)
exit(1)
end
end
end
end
41 changes: 30 additions & 11 deletions spec/rubocop/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -451,11 +451,11 @@ def abs(path)
'#' * 85,
'y ',
'puts x'])
create_file('rubocop-todo.yml', ['LineLength:',
' Enabled: false'])
create_file('.rubocop.yml', ['inherit_from: rubocop-todo.yml'])
create_file('.rubocop_todo.yml', ['LineLength:',
' Enabled: false'])
create_file('.rubocop.yml', ['inherit_from: .rubocop_todo.yml'])
expect(cli.run(['--auto-gen-config'])).to eq(1)
expect(IO.readlines('rubocop-todo.yml')[7..-1].map(&:chomp))
expect(IO.readlines('.rubocop_todo.yml')[7..-1].map(&:chomp))
.to eq(['# Offense count: 1',
'LineLength:',
' Max: 85',
Expand Down Expand Up @@ -503,9 +503,9 @@ def abs(path)
expect(cli.run(['--auto-gen-config'])).to eq(1)
expect($stderr.string).to eq('')
expect($stdout.string)
.to include(['Created rubocop-todo.yml.',
'Run `rubocop --config rubocop-todo.yml`, or',
'add inherit_from: rubocop-todo.yml in a ' \
.to include(['Created .rubocop_todo.yml.',
'Run `rubocop --config .rubocop_todo.yml`, or',
'add inherit_from: .rubocop_todo.yml in a ' \
'.rubocop.yml file.',
''].join("\n"))
expected =
Expand Down Expand Up @@ -549,7 +549,7 @@ def abs(path)
'# Cop supports --auto-correct.',
'TrailingWhitespace:',
' Enabled: false']
actual = IO.read('rubocop-todo.yml').split($RS)
actual = IO.read('.rubocop_todo.yml').split($RS)
expected.each_with_index do |line, ix|
if line.is_a?(String)
expect(actual[ix]).to eq(line)
Expand Down Expand Up @@ -590,7 +590,7 @@ def abs(path)
'# Offense count: 1',
'Tab:',
' Enabled: false']
actual = IO.read('rubocop-todo.yml').split($RS)
actual = IO.read('.rubocop_todo.yml').split($RS)
expect(actual.length).to eq(expected.length)
expected.each_with_index do |line, ix|
if line.is_a?(String)
Expand Down Expand Up @@ -622,7 +622,7 @@ def abs(path)
'# Offense count: 1',
'RegexpLiteral:',
' MaxSlashes: 0']
actual = IO.read('rubocop-todo.yml').split($RS)
actual = IO.read('.rubocop_todo.yml').split($RS)
expected.each_with_index do |line, ix|
if line.is_a?(String)
expect(actual[ix]).to eq(line)
Expand All @@ -631,7 +631,7 @@ def abs(path)
end
end
$stdout = StringIO.new
result = cli.run(%w(--config rubocop-todo.yml --format emacs))
result = cli.run(%w(--config .rubocop_todo.yml --format emacs))
expect($stdout.string).to eq('')
expect(result).to eq(0)
end
Expand Down Expand Up @@ -1952,5 +1952,24 @@ def interrupt
'Valid severities are refactor, convention, ' \
"warning, error, fatal.\n")
end

context 'when a file inherits from the old auto generated file' do
before do
create_file('rubocop-todo.yml', '')
create_file('.rubocop.yml', ['inherit_from: rubocop-todo.yml'])
end

it 'prints no warning when --auto-gen-config is not set' do
expect { cli.run(%w(-c .rubocop.yml)) }.not_to exit_with_code(1)
end

it 'prints a warning when --auto-gen-config is set' do
expect { cli.run(%w(-c .rubocop.yml --auto-gen-config)) }
.to exit_with_code(1)
expect($stderr.string)
.to eq('Attention: rubocop_todo.yml has been renamed to ' \
".rubocop_todo.yml\n")
end
end
end
end
8 changes: 4 additions & 4 deletions spec/rubocop/formatter/disabled_config_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Formatter
let(:output) do
o = StringIO.new
def o.path
'rubocop-todo.yml'
'.rubocop_todo.yml'
end
o
end
Expand All @@ -38,9 +38,9 @@ def o.path
' Enabled: false',
''].join("\n"))
expect($stdout.string)
.to eq(['Created rubocop-todo.yml.',
'Run `rubocop --config rubocop-todo.yml`, or',
'add inherit_from: rubocop-todo.yml in a .rubocop.yml ' \
.to eq(['Created .rubocop_todo.yml.',
'Run `rubocop --config .rubocop_todo.yml`, or',
'add inherit_from: .rubocop_todo.yml in a .rubocop.yml ' \
'file.',
''].join("\n"))
end
Expand Down

0 comments on commit 8e67b3e

Please sign in to comment.