Skip to content

Commit

Permalink
Fix #8650 for improved hidden files finder performance
Browse files Browse the repository at this point in the history
  • Loading branch information
tleish committed Sep 25, 2020
1 parent b1e1829 commit bf35216
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,7 @@
### Changes

* [#8785](https://github.com/rubocop-hq/rubocop/pull/8785): Update TargetRubyVersion 2.8 to 3.0 (experimental). ([@em-gazelle][])
* [#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 @@ -4912,3 +4913,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

0 comments on commit bf35216

Please sign in to comment.