Skip to content

Commit

Permalink
Hook into rejecting offenses earlier
Browse files Browse the repository at this point in the history
The runner is pretty high-level, if tests are running without involving the cli offenses aren't being rejected
  • Loading branch information
Earlopain committed Dec 13, 2023
1 parent 6a9db74 commit 061e331
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions lib/rubocop/markdown/rubocop_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,6 @@ def file_offense_cache(file)
super
end

def inspect_file(*args)
super.tap do |(offenses, *)|
# Skip offenses reported for ignored MD source (trailing whitespaces, etc.)
marker_comment = "##{RuboCop::Markdown::Preprocess::MARKER}"
offenses.reject! do |offense|
next if RuboCop::Markdown::MARKDOWN_OFFENSE_COPS.include?(offense.cop_name)

offense.location.source_line.start_with?(marker_comment)
end
end
end

def file_finished(file, offenses)
return super unless RuboCop::Markdown.markdown_file?(file)

Expand All @@ -86,6 +74,20 @@ def file_finished(file, offenses)
end
end)

RuboCop::Cop::Commissioner::InvestigationReport.prepend(Module.new do
# Skip offenses reported for ignored MD source (trailing whitespaces, etc.)
def offenses
@offenses ||= begin
marker_comment = "##{RuboCop::Markdown::Preprocess::MARKER}"
offenses_per_cop.flatten(1).reject do |offense|
next if RuboCop::Markdown::MARKDOWN_OFFENSE_COPS.include?(offense.cop_name)

offense.location.source_line.start_with?(marker_comment)
end
end
end
end)

# Allow Rubocop to analyze markdown files
RuboCop::TargetFinder.prepend(Module.new do
def ruby_file?(file)
Expand Down

0 comments on commit 061e331

Please sign in to comment.