Skip to content

Commit

Permalink
Merge pull request #1726 from rubocop/1720
Browse files Browse the repository at this point in the history
Change to be inline disable for `RSpec/SpecFilePathFormat` like `RSpec/FilePath`
  • Loading branch information
pirj committed Oct 15, 2023
2 parents e609b2a + 4790d14 commit 1c42da1
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 251 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Master (Unreleased)

- Add support single quoted string and percent string and heredoc for `RSpec/Rails/HttpStatus`. ([@ydah])
- Change to be inline disable for `RSpec/SpecFilePathFormat` like `RSpec/FilePath`. ([@ydah])

## 2.24.1 (2023-09-23)

Expand Down
10 changes: 5 additions & 5 deletions lib/rubocop/cop/rspec/spec_file_path_format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class SpecFilePathFormat < Base

# @!method example_group_arguments(node)
def_node_matcher :example_group_arguments, <<~PATTERN
(block (send #rspec? #ExampleGroups.all $_ $...) ...)
(block $(send #rspec? #ExampleGroups.all $_ $...) ...)
PATTERN

# @!method metadata_key_value(node)
Expand All @@ -50,24 +50,24 @@ class SpecFilePathFormat < Base
def on_top_level_example_group(node)
return unless top_level_groups.one?

example_group_arguments(node) do |class_name, arguments|
example_group_arguments(node) do |send_node, class_name, arguments|
next if !class_name.const_type? || ignore_metadata?(arguments)

ensure_correct_file_path(class_name, arguments)
ensure_correct_file_path(send_node, class_name, arguments)
end
end

private

def ensure_correct_file_path(class_name, arguments)
def ensure_correct_file_path(send_node, class_name, arguments)
pattern = correct_path_pattern(class_name, arguments)
return if filename_ends_with?(pattern)

# For the suffix shown in the offense message, modify the regular
# expression pattern to resemble a glob pattern for clearer error
# messages.
suffix = pattern.sub('.*', '*').sub('[^/]*', '*').sub('\.', '.')
add_global_offense(format(MSG, suffix: suffix))
add_offense(send_node, message: format(MSG, suffix: suffix))
end

def ignore_metadata?(arguments)
Expand Down
Loading

0 comments on commit 1c42da1

Please sign in to comment.