Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better integration tests #31

Merged
merged 4 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/rubocop/markdown/preprocess.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,15 @@ class << self
# using preproccessed source buffer.
#
# We have to restore it.
def restore!(file)
def restore_and_save!(file)
contents = File.read(file)
contents.gsub!(/^##{MARKER}/m, "")
restore!(contents)
File.write(file, contents)
end

def restore!(src)
src.gsub!(/^##{MARKER}/m, "")
end
end

attr_reader :config
Expand Down
28 changes: 15 additions & 13 deletions lib/rubocop/markdown/rubocop_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,30 +62,32 @@ 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)

# Run Preprocess.restore if file has been autocorrected
if @options[:auto_correct] || @options[:autocorrect]
RuboCop::Markdown::Preprocess.restore!(file)
RuboCop::Markdown::Preprocess.restore_and_save!(file)
end

super(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
3 changes: 0 additions & 3 deletions test/fixtures/NON_CODE_OFFENSES.md

This file was deleted.

7 changes: 0 additions & 7 deletions test/fixtures/backticks.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
inherit_from: "../../../.rubocop.yml"

Markdown:
Autodetect: false
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,3 @@ inherit_from: "../../../.rubocop.yml"

require:
- "rubocop-md"

Markdown:
Autodetect: false
5 changes: 0 additions & 5 deletions test/fixtures/configs/no_warn_invalid.yml

This file was deleted.

8 changes: 0 additions & 8 deletions test/fixtures/configs/no_warn_invalid_with_require.yml

This file was deleted.

3 changes: 0 additions & 3 deletions test/fixtures/in_flight_parse.rb

This file was deleted.

25 changes: 0 additions & 25 deletions test/fixtures/multiple_invalid_snippets.md

This file was deleted.

20 changes: 0 additions & 20 deletions test/fixtures/multiple_invalid_snippets_unknown.md

This file was deleted.

52 changes: 0 additions & 52 deletions test/fixtures/multiple_snippets.markdown

This file was deleted.

Loading