Skip to content

Commit

Permalink
Update details_menu_migration linter config (#3139)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamieshark authored Oct 21, 2024
1 parent 683abd2 commit b650344
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/new-nails-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/view-components': patch
---

Adjusts config for DetailsMenuMigration linter to take in an array of strings instead of array of regexp
5 changes: 3 additions & 2 deletions lib/primer/view_components/linters/details_menu_migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DetailsMenuMigration < Linter

# Allow custom pattern matching for ERB nodes
class ConfigSchema < LinterConfig
property :custom_erb_pattern, accepts: array_of?(Regexp),
property :custom_erb_pattern, accepts: array_of?(String),
default: -> { [] }
end
self.config_schema = ConfigSchema
Expand Down Expand Up @@ -51,7 +51,8 @@ def custom_erb_pattern
if @config.custom_erb_pattern.empty?
nil
else
Regexp.new(@config.custom_erb_pattern.join("|"), true)
regexes = @config.custom_erb_pattern.map { |pattern| Regexp.new(pattern, true) }
Regexp.new(regexes.join("|"), true)
end
end

Expand Down
6 changes: 4 additions & 2 deletions test/lib/erblint/details_menu_migration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def test_does_not_warn_if_inline_disable_comment
end

def test_accepts_custom_regex_pattern
@linter.config.custom_erb_pattern = [/render[\s\(]GitHub::MenuComponent/]
@linter.config.custom_erb_pattern = ["render[\s\(]GitHub::MenuComponent"]

@file = <<~HTML
<%= render GitHub::MenuComponent.new do %>
HTML
Expand All @@ -64,7 +65,8 @@ def test_accepts_custom_regex_pattern
end

def test_accepts_multiple_custom_regex_pattern
@linter.config.custom_erb_pattern = [/render[\s\(]GitHub::MenuComponent/, /SomeOtherComponent/]
@linter.config.custom_erb_pattern = ["render[\s\(]GitHub::MenuComponent", "SomeOtherComponent"]

@file = <<~HTML
<%= render GitHub::MenuComponent.new do %>
<% end %>
Expand Down

0 comments on commit b650344

Please sign in to comment.