lib/cc/cli/config_generator.rb in codeclimate-0.17.0 vs lib/cc/cli/config_generator.rb in codeclimate-0.18.0

- old
+ new

@@ -1,5 +1,7 @@ +require "shellwords" + module CC module CLI class ConfigGenerator CODECLIMATE_YAML = Command::CODECLIMATE_YAML AUTO_EXCLUDE_PATHS = %w(config/ db/ dist/ features/ node_modules/ script/ spec/ test/ tests/ vendor/).freeze @@ -35,11 +37,11 @@ def errors [] end def exclude_paths - AUTO_EXCLUDE_PATHS.select { |path| filesystem.exist?(path) } + @exclude_paths ||= AUTO_EXCLUDE_PATHS.select { |path| filesystem.exist?(path) } end def post_generation_verb "generated" end @@ -57,11 +59,33 @@ def engine_eligible?(engine) !engine["community"] && engine["enable_regexps"].present? && files_exist?(engine) end def files_exist?(engine) - filesystem.any? do |path| + workspace_files.any? do |path| engine["enable_regexps"].any? { |re| Regexp.new(re).match(path) } + end + end + + def non_excluded_paths + @non_excluded_paths ||= begin + excludes = exclude_paths.map { |path| path.chomp("/") } + filesystem.ls.reject do |path| + path.starts_with?(".") || excludes.include?(path) + end + end + end + + def workspace_files + @workspace_files ||= Dir.chdir(filesystem.root) do + if non_excluded_paths.empty? + [] + else + find_cmd = "find #{non_excluded_paths.map(&:shellescape).join(' ')} -type f -print0" + `#{find_cmd}`.strip.split("\0").map do |path| + path.sub(%r{^\.\/}, "") + end + end end end end end end