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

Add regex filters #589

Merged
merged 7 commits into from
Jun 24, 2017
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: 1 addition & 7 deletions lib/simplecov/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ def self.build_filter(filter_argument)
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😍


def self.class_for_argument(filter_argument)
return filter_argument if filter_argument.is_a?(SimpleCov::Filter)

if filter_argument.is_a?(String)
SimpleCov::StringFilter
elsif filter_argument.is_a?(Regexp)
Expand Down Expand Up @@ -74,11 +72,7 @@ def matches?(source_file)
class ArrayFilter < SimpleCov::Filter
def initialize(filter_argument)
filter_objects = filter_argument.map do |arg|
if arg.is_a?(SimpleCov::Filter)
arg
else
Filter.class_for_argument(arg).new(arg)
end
Filter.build_filter(arg)
end

super(filter_objects)
Expand Down
3 changes: 1 addition & 2 deletions lib/simplecov/source_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ def initialize(filename, coverage)

# The path to this source file relative to the projects directory
def project_filename
project_dir = File.dirname(File.expand_path(File.basename(__FILE__)))
@filename.sub(/^#{project_dir}/, "")
@filename.sub(/^#{SimpleCov.root}/, "")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm not too sure but I think it looks good 👍

In the future though, would be preferred to have unrelated changes for other issues etc. in their own PR so they don't get too big and stay more focussed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, but this change was kind of required for the regex. Without it the regex would be matching the full path, which probably nobody would understand.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, didn't make that connection in my head. Thanks!

end

# The source code for this file. Aliased as :source
Expand Down