Sha256: b1de9724631fcd89401c9dd7438da560e2a3916f692063ef7b229e6d1bc316bc
Contents?: true
Size: 1.82 KB
Versions: 2
Compression:
Stored size: 1.82 KB
Contents
module CC module CLI class Init < Command include CC::Analyzer AUTO_EXCLUDE_PATHS = %w[config db features node_modules script spec test vendor].freeze def run if filesystem.exist?(CODECLIMATE_YAML) say "Config file .codeclimate.yml already present.\nTry running 'validate-config' to check configuration." else create_codeclimate_yaml say "Config file .codeclimate.yml successfully generated.\nEdit and then try running 'validate-config' to check configuration." end end private def create_codeclimate_yaml config = { "engines" => {} } eligible_engines.each do |engine_name, engine_config| config["engines"][engine_name] = { "enabled" => true } config["ratings"] ||= {} config["ratings"]["paths"] ||= [] config["ratings"]["paths"] |= engine_config["default_ratings_paths"] end config["exclude_paths"] = exclude_paths(AUTO_EXCLUDE_PATHS) File.write(filesystem.path_for(CODECLIMATE_YAML), config.to_yaml) end def exclude_paths(paths) expanded_paths = [] paths.each do |dir| if filesystem.exist?(dir) expanded_paths << "#{dir}/**/*" end end expanded_paths end def engine_eligible?(engine) !engine["community"] && engine["enable_regexps"].present? && filesystem.any? do |path| engine["enable_regexps"].any? { |re| Regexp.new(re).match(path) } end end def eligible_engines CC::Analyzer::EngineRegistry.new.list.each_with_object({}) do |(engine_name, config), result| if engine_eligible?(config) result[engine_name] = config end end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
codeclimate-0.0.7 | lib/cc/cli/init.rb |
codeclimate-0.0.6 | lib/cc/cli/init.rb |