diff --git a/CHANGELOG.md b/CHANGELOG.md index 3266dcfd2740..f8b02c3cdde3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * Fix false positive in `Style/TrailingCommaInArguments` & `Style/TrailingCommaInLiteral` cops with consistent_comma style. ([@meganemura][]) * [#2861](https://github.com/bbatsov/rubocop/pull/2861): Fix false positive in `Style/SpaceAroundKeyword` for `rescue(...`. ([@rrosenblum][]) * [#2832](https://github.com/bbatsov/rubocop/issues/2832): `Style/MultilineOperationIndentation` treats operations inside blocks inside other operations correctly. ([@jonas054][]) +* [#2865](https://github.com/bbatsov/rubocop/issues/2865): Change `require:` in config to be relative to the `.rubocop.yml` file itself. ([@ptarjan][]) ## 0.37.2 (11/02/2016) @@ -2002,3 +2003,4 @@ [@mmcguinn]: https://github.com/mmcguinn [@pocke]: https://github.com/pocke [@prsimp]: https://github.com/prsimp +[@ptarjan]: https://github.com/ptarjan diff --git a/lib/rubocop/config_loader.rb b/lib/rubocop/config_loader.rb index a0fa435bd0a2..f98261b87ee5 100644 --- a/lib/rubocop/config_loader.rb +++ b/lib/rubocop/config_loader.rb @@ -35,7 +35,10 @@ def load_file(path) resolve_inheritance_from_gems(hash, hash.delete('inherit_gem')) resolve_inheritance(path, hash) - Array(hash.delete('require')).each { |r| require(r) } + config_dir = File.dirname(path) + Array(hash.delete('require')).each do |r| + require(File.join(config_dir, r)) + end hash.delete('inherit_from') config = Config.new(hash, path) diff --git a/spec/rubocop/config_loader_spec.rb b/spec/rubocop/config_loader_spec.rb index 5df1beb7bad0..c711d724208f 100644 --- a/spec/rubocop/config_loader_spec.rb +++ b/spec/rubocop/config_loader_spec.rb @@ -505,5 +505,13 @@ described_class.configuration_from_file(config_path) expect(defined?(MyClass)).to be_truthy end + + it 'uses paths relative to the .rubocop.yml, not cwd' do + config_path = described_class.configuration_file_for('.') + Dir.chdir '..' do + described_class.configuration_from_file(config_path) + expect(defined?(MyClass)).to be_truthy + end + end end end