From 91c89a7071e0198547e20028a25d63a2edb016a9 Mon Sep 17 00:00:00 2001 From: prog-supdex Date: Wed, 18 Oct 2023 13:32:33 +0200 Subject: [PATCH] Fixing the problem when RuboCop::Markdown.config_store was not filled. This problem appeared when "rubocop-md" loaded via .rubocop.yml and used "--formater" Fixes #22 --- lib/rubocop/markdown/rubocop_ext.rb | 5 +++-- test/fixtures/.rubocop.yml | 5 +++++ test/fixtures/configs/no_autodetect.yml | 2 +- test/fixtures/configs/no_warn_invalid.yml | 3 ++- test/integration_test.rb | 12 ++++++++++-- 5 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 test/fixtures/.rubocop.yml diff --git a/lib/rubocop/markdown/rubocop_ext.rb b/lib/rubocop/markdown/rubocop_ext.rb index 62fd945..1bfbc56 100644 --- a/lib/rubocop/markdown/rubocop_ext.rb +++ b/lib/rubocop/markdown/rubocop_ext.rb @@ -42,9 +42,10 @@ def markdown_file?(file) RuboCop::Runner.prepend(Module.new do # Set config store for Markdown - def initialize(*args) - super + def get_processed_source(*args) RuboCop::Markdown.config_store = @config_store + + super end # Do not cache markdown files, 'cause cache doesn't know about processing. diff --git a/test/fixtures/.rubocop.yml b/test/fixtures/.rubocop.yml new file mode 100644 index 0000000..a5638d5 --- /dev/null +++ b/test/fixtures/.rubocop.yml @@ -0,0 +1,5 @@ +inherit_from: + - "../../.rubocop.yml" + +require: + - "rubocop-md" diff --git a/test/fixtures/configs/no_autodetect.yml b/test/fixtures/configs/no_autodetect.yml index a6e1f35..82a6a9e 100644 --- a/test/fixtures/configs/no_autodetect.yml +++ b/test/fixtures/configs/no_autodetect.yml @@ -1,4 +1,4 @@ -inherit_from: "../../../.rubocop.yml" +inherit_from: "../.rubocop.yml" Markdown: Autodetect: false diff --git a/test/fixtures/configs/no_warn_invalid.yml b/test/fixtures/configs/no_warn_invalid.yml index 3edd292..f6c7f71 100644 --- a/test/fixtures/configs/no_warn_invalid.yml +++ b/test/fixtures/configs/no_warn_invalid.yml @@ -1,4 +1,5 @@ -inherit_from: "../../../.rubocop.yml" +inherit_from: "../.rubocop.yml" Markdown: WarnInvalid: false + diff --git a/test/integration_test.rb b/test/integration_test.rb index eb19490..366c365 100644 --- a/test/integration_test.rb +++ b/test/integration_test.rb @@ -6,11 +6,11 @@ module RuboCopRunner def run_rubocop(path, options: "") - md_path = File.expand_path("../lib/rubocop-md.rb", __dir__) output, _status = Open3.capture2( - "bundle exec rubocop -r #{md_path} #{options} #{path}", + "bundle exec rubocop #{options} #{path}", chdir: File.join(__dir__, "fixtures") ) + output end end @@ -26,6 +26,14 @@ def test_single_snippet_file assert_match %r{Style/StringLiterals}, res end + def test_file_with_format_options + res = run_rubocop("single_snippet.md", options: "--format progress") + + assert_match %r{Inspecting 1 file}, res + assert_match %r{1 offense detected}, res + assert_match %r{Style/StringLiterals}, res + end + def test_multiple_snippets_file res = run_rubocop("multiple_snippets.markdown")