Skip to content

Commit

Permalink
Fixing the problem when RuboCop::Markdown.config_store was not filled.
Browse files Browse the repository at this point in the history
This problem appeared when "rubocop-md" loaded via .rubocop.yml and used "--formater"

Fixes #22
  • Loading branch information
prog-supdex committed Oct 18, 2023
1 parent e9c468d commit 91c89a7
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lib/rubocop/markdown/rubocop_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
inherit_from:
- "../../.rubocop.yml"

require:
- "rubocop-md"
2 changes: 1 addition & 1 deletion test/fixtures/configs/no_autodetect.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
inherit_from: "../../../.rubocop.yml"
inherit_from: "../.rubocop.yml"

Markdown:
Autodetect: false
3 changes: 2 additions & 1 deletion test/fixtures/configs/no_warn_invalid.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
inherit_from: "../../../.rubocop.yml"
inherit_from: "../.rubocop.yml"

Markdown:
WarnInvalid: false

12 changes: 10 additions & 2 deletions test/integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")

Expand Down

0 comments on commit 91c89a7

Please sign in to comment.