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

Fix #8650 for improved hidden files finder performance #8784

Merged
merged 2 commits into from Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -12,7 +12,9 @@

### Changes

* [#8785](https://github.com/rubocop-hq/rubocop/pull/8785): Update TargetRubyVersion 2.8 to 3.0 (experimental). ([@em-gazelle][])
* [#8785](https://github.com/rubocop-hq/rubocop/pull/8785): Update TargetRubyVersion 2.8 to 3.0 (experimental). ([@koic][])
* [#8650](https://github.com/rubocop-hq/rubocop/issues/8650): Faster find of hidden files in `TargetFinder` class which improves rubocop initial startup speed. ([@tleish][])

## 0.91.1 (2020-09-23)

Expand Down Expand Up @@ -4916,3 +4918,4 @@
[@fsateler]: https://github.com/fsateler
[@iSarCasm]: https://github.com/iSarCasm
[@em-gazelle]: https://github.com/em-gazelle
[@tleish]: https://github.com/tleish
5 changes: 4 additions & 1 deletion lib/rubocop/target_finder.rb
Expand Up @@ -5,6 +5,8 @@ module RuboCop
# and picking ruby files.
# @api private
class TargetFinder
HIDDEN_PATH_SUBSTRING = "#{File::SEPARATOR}."

def initialize(config_store, options = {})
@config_store = config_store
@options = options
Expand Down Expand Up @@ -55,7 +57,8 @@ def target_files_in_dir(base_dir = Dir.pwd)
# Support Windows: Backslashes from command-line -> forward slashes
base_dir = base_dir.gsub(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
all_files = find_files(base_dir, File::FNM_DOTMATCH)
hidden_files = Set.new(all_files - find_files(base_dir, 0))
# use file.include? for performance optimization
hidden_files = all_files.select { |file| file.include?(HIDDEN_PATH_SUBSTRING) }
base_dir_config = @config_store.for(base_dir)

target_files = all_files.select do |file|
Expand Down