Skip to content

Commit

Permalink
fix: preserve syntax errors spanning markdown
Browse files Browse the repository at this point in the history
Fixes #26
  • Loading branch information
palkan committed Dec 1, 2023
1 parent f94a787 commit e7d2bfe
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## master (unreleased)

- Fix analyzing code blocks with backticks.

## 1.2.1 (2023-10-20)

- Fix incompatibility when loading the plugin from YAML and using other RuboCop options.
Expand Down
5 changes: 5 additions & 0 deletions lib/rubocop/markdown/rubocop_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ module Markdown # :nodoc:
.workbook
].freeze

# A list of cops that could produce offenses in commented lines
MARKDOWN_OFFENSE_COPS = %w[Lint/Syntax].freeze

class << self
attr_accessor :config_store

Expand Down Expand Up @@ -61,6 +64,8 @@ def inspect_file(*args)
# 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
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/backticks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```ruby
`method_call
```

```ruby
further_code("", '')
```
7 changes: 7 additions & 0 deletions test/integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ def test_non_code_offenses
assert_match %r{Inspecting 1 file}, res
assert_match %r{no offenses detected}, res
end

def test_backticks_in_code
res = run_rubocop("backticks.md")

assert_match %r{Inspecting 1 file}, res
assert_match %r{1 offense detected}, res
end
end

class RuboCop::Markdown::AutocorrectTest < Minitest::Test
Expand Down

0 comments on commit e7d2bfe

Please sign in to comment.