Skip to content

Commit

Permalink
Merge pull request #45 from toptal/rubocop-config
Browse files Browse the repository at this point in the history
Add rubocop config that can be required project using granite
  • Loading branch information
Michał Młoźniak committed Mar 5, 2020
2 parents 79fceff + 12a4a8b commit 5b8db4b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
3 changes: 3 additions & 0 deletions config/rubocop-default.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Lint/UselessAccessModifier:
ContextCreatingMethods:
- projector
2 changes: 1 addition & 1 deletion lib/granite/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Granite
VERSION = '0.9.4'.freeze
VERSION = '0.9.5'.freeze
end
8 changes: 8 additions & 0 deletions lib/rubocop-granite.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

require 'rubocop'

require_relative 'rubocop/granite'
require_relative 'rubocop/granite/inject'

RuboCop::Granite::Inject.defaults!
9 changes: 9 additions & 0 deletions lib/rubocop/granite.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module RuboCop
module Granite
PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'rubocop-default.yml').freeze
CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze

private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
end
end
20 changes: 20 additions & 0 deletions lib/rubocop/granite/inject.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

# The original code is from https://github.com/rubocop-hq/rubocop-rspec/blob/master/lib/rubocop/rspec/inject.rb
# See https://github.com/rubocop-hq/rubocop-rspec/blob/master/MIT-LICENSE.md
module RuboCop
module Granite
# Because RuboCop doesn't yet support plugins, we have to monkey patch in a
# bit of our configuration.
module Inject
def self.defaults!
path = CONFIG_DEFAULT.to_s
hash = ConfigLoader.load_file(path)
config = Config.new(hash, path).tap(&:make_excludes_absolute)
puts "configuration from #{path}" if ConfigLoader.debug?
config = ConfigLoader.merge_with_default(config, path)
ConfigLoader.instance_variable_set(:@default_configuration, config)
end
end
end
end

0 comments on commit 5b8db4b

Please sign in to comment.