Skip to content

Commit

Permalink
Move config injection to own file
Browse files Browse the repository at this point in the history
  • Loading branch information
Earlopain committed Dec 19, 2023
1 parent 0ca0d0d commit ff4f73b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
1 change: 1 addition & 0 deletions lib/rubocop/markdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Markdown
PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
CONFIG_DEFAULT = PROJECT_ROOT.join("config", "default.yml").freeze

require_relative "markdown/inject"
require_relative "markdown/preprocess"
require_relative "markdown/rubocop_ext" if defined?(::RuboCop::ProcessedSource)
end
Expand Down
18 changes: 18 additions & 0 deletions lib/rubocop/markdown/inject.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

module RuboCop
module Markdown
# Merge markdown config into default configuration
# See https://github.com/rubocop/rubocop-rspec/blob/master/lib/rubocop/rspec/inject.rb
module Inject # :nodoc:
def self.defaults!
path = CONFIG_DEFAULT.to_s
hash = ConfigLoader.send(:load_yaml_configuration, path)
config = RuboCop::Config.new(hash, path)
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
13 changes: 1 addition & 12 deletions lib/rubocop/markdown/rubocop_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,14 @@ module Markdown # :nodoc:
class << self
attr_accessor :config_store

# Merge markdown config into default configuration
# See https://github.com/backus/rubocop-rspec/blob/master/lib/rubocop/rspec/inject.rb
def inject!
path = CONFIG_DEFAULT.to_s
hash = ConfigLoader.send(:load_yaml_configuration, path)
config = Config.new(hash, path)
puts "configuration from #{path}" if ConfigLoader.debug?
config = ConfigLoader.merge_with_default(config, path)
ConfigLoader.instance_variable_set(:@default_configuration, config)
end

def markdown_file?(file)
MARKDOWN_EXTENSIONS.include?(File.extname(file))
end
end
end
end

RuboCop::Markdown.inject!
RuboCop::Markdown::Inject.defaults!

RuboCop::Runner.prepend(Module.new do
# Set config store for Markdown
Expand Down

0 comments on commit ff4f73b

Please sign in to comment.