From 061e33165654c03a746d48c39f1e336abfaf7972 Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Wed, 13 Dec 2023 18:48:42 +0100 Subject: [PATCH] Hook into rejecting offenses earlier The runner is pretty high-level, if tests are running without involving the cli offenses aren't being rejected --- lib/rubocop/markdown/rubocop_ext.rb | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/rubocop/markdown/rubocop_ext.rb b/lib/rubocop/markdown/rubocop_ext.rb index ed918e1..17a950c 100644 --- a/lib/rubocop/markdown/rubocop_ext.rb +++ b/lib/rubocop/markdown/rubocop_ext.rb @@ -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) @@ -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)