Skip to content

Commit

Permalink
Change requre: in config to be relative to the .rubocop.yml file itself
Browse files Browse the repository at this point in the history
  • Loading branch information
ptarjan committed Feb 22, 2016
1 parent 5a74240 commit 5fdd795
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -2002,3 +2003,4 @@
[@mmcguinn]: https://github.com/mmcguinn
[@pocke]: https://github.com/pocke
[@prsimp]: https://github.com/prsimp
[@ptarjan]: https://github.com/ptarjan
5 changes: 4 additions & 1 deletion lib/rubocop/config_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/config_loader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5fdd795

Please sign in to comment.