Skip to content

Commit

Permalink
Merge pull request #31 from Earlopain/better-integration-tests
Browse files Browse the repository at this point in the history
Better integration tests
  • Loading branch information
palkan authored Dec 18, 2023
2 parents 330cd43 + ef62838 commit 0ca0d0d
Show file tree
Hide file tree
Showing 19 changed files with 654 additions and 444 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
rubocop_version: [""]
include:
- ruby: "2.6"
rubocop_version: "'1.0.0'"
rubocop_version: "'1.45.0'"
- ruby: "3.2"
rubocop_version: "github: 'rubocop/rubocop'"
steps:
Expand Down
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
2 changes: 1 addition & 1 deletion rubocop-md.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Gem::Specification.new do |spec|

spec.require_paths = ["lib"]

spec.add_runtime_dependency "rubocop", ">= 1.0"
spec.add_runtime_dependency "rubocop", ">= 1.45"

spec.add_development_dependency "bundler", ">= 1.15"
spec.add_development_dependency "rake", ">= 13.0"
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

0 comments on commit 0ca0d0d

Please sign in to comment.