diff --git a/.rubocop.yml b/.rubocop.yml index f9dc215c9890..052d8c00e89e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -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 diff --git a/rubocop-todo.yml b/.rubocop_todo.yml similarity index 86% rename from rubocop-todo.yml rename to .rubocop_todo.yml index e9c957d8acf8..a71de6275fff 100644 --- a/rubocop-todo.yml +++ b/.rubocop_todo.yml @@ -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 @@ -14,7 +14,7 @@ ClassLength: CyclomaticComplexity: Max: 10 -# Offense count: 115 +# Offense count: 114 # Configuration parameters: CountComments. MethodLength: Max: 20 diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f9d6077cb1e..a46c5870c584 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 28358a3a8168..0fedba00f7f1 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/rubocop/config_loader.rb b/lib/rubocop/config_loader.rb index 7d1b7f343621..11cb739bce52 100644 --- a/lib/rubocop/config_loader.rb +++ b/lib/rubocop/config_loader.rb @@ -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 @@ -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) @@ -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 diff --git a/spec/rubocop/cli_spec.rb b/spec/rubocop/cli_spec.rb index 7e3e22cfbed9..3138740cdabb 100644 --- a/spec/rubocop/cli_spec.rb +++ b/spec/rubocop/cli_spec.rb @@ -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', @@ -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 = @@ -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) @@ -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) @@ -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) @@ -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 @@ -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 diff --git a/spec/rubocop/formatter/disabled_config_formatter_spec.rb b/spec/rubocop/formatter/disabled_config_formatter_spec.rb index 8aac58cba052..8b339625727f 100644 --- a/spec/rubocop/formatter/disabled_config_formatter_spec.rb +++ b/spec/rubocop/formatter/disabled_config_formatter_spec.rb @@ -11,7 +11,7 @@ module Formatter let(:output) do o = StringIO.new def o.path - 'rubocop-todo.yml' + '.rubocop_todo.yml' end o end @@ -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