From ff4f73b9df8d5abc9e1a47b7eda23d5bea2a561f Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Tue, 19 Dec 2023 12:38:56 +0100 Subject: [PATCH] Move config injection to own file --- lib/rubocop/markdown.rb | 1 + lib/rubocop/markdown/inject.rb | 18 ++++++++++++++++++ lib/rubocop/markdown/rubocop_ext.rb | 13 +------------ 3 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 lib/rubocop/markdown/inject.rb diff --git a/lib/rubocop/markdown.rb b/lib/rubocop/markdown.rb index 915bf32..af5da64 100644 --- a/lib/rubocop/markdown.rb +++ b/lib/rubocop/markdown.rb @@ -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 diff --git a/lib/rubocop/markdown/inject.rb b/lib/rubocop/markdown/inject.rb new file mode 100644 index 0000000..3a49d59 --- /dev/null +++ b/lib/rubocop/markdown/inject.rb @@ -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 diff --git a/lib/rubocop/markdown/rubocop_ext.rb b/lib/rubocop/markdown/rubocop_ext.rb index 1283b97..d7fa0ca 100644 --- a/lib/rubocop/markdown/rubocop_ext.rb +++ b/lib/rubocop/markdown/rubocop_ext.rb @@ -26,17 +26,6 @@ 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 @@ -44,7 +33,7 @@ def markdown_file?(file) end end -RuboCop::Markdown.inject! +RuboCop::Markdown::Inject.defaults! RuboCop::Runner.prepend(Module.new do # Set config store for Markdown