lib/rubocop/git/style_guide.rb in rubocop-git-0.0.2 vs lib/rubocop/git/style_guide.rb in rubocop-git-0.0.3

- old
+ new

@@ -1,54 +1,65 @@ module RuboCop::Git -# ref. https://github.com/thoughtbot/hound/blob/be2dd34/app/models/style_guide.rb +# ref. https://github.com/thoughtbot/hound/blob/d2f3933/app/models/style_guide.rb class StyleGuide - def initialize(rubocop_options, config_path, override_config_content = nil) + def initialize(rubocop_options, config_file, override_config_content = nil) @rubocop_options = rubocop_options - @config_path = config_path + @config_file = config_file @override_config_content = override_config_content end def violations(file) if ignored_file?(file) [] else parsed_source = parse_source(file) - team = Rubocop::Cop::Team.new( - Rubocop::Cop::Cop.all, configuration, @rubocop_options) - commissioner = Rubocop::Cop::Commissioner.new(team.cops, []) - commissioner.investigate(parsed_source) + cops = RuboCop::Cop::Cop.all + team = RuboCop::Cop::Team.new(cops, config, rubocop_options) + team.inspect_file(parsed_source) end end private def ignored_file?(file) - !file.ruby? || - file.removed? || - configuration.file_to_exclude?(file.filename) + !file.ruby? || file.removed? || excluded_file?(file) end + def excluded_file?(file) + config.file_to_exclude?(file.filename) + end + def parse_source(file) - Rubocop::SourceParser.parse(file.contents, file.filename) + RuboCop::ProcessedSource.new(file.content) end - def configuration - config = Rubocop::ConfigLoader.configuration_from_file(@config_path) - - if override_config - config = Rubocop::Config.new( - Rubocop::ConfigLoader.merge(config, override_config), - '' - ) - config.make_excludes_absolute + def config + if @config.nil? + config = RuboCop::ConfigLoader.configuration_from_file(@config_file) + combined_config = RuboCop::ConfigLoader.merge(config, override_config) + @config = RuboCop::Config.new(combined_config, "") end - config + @config end + def rubocop_options + if config["ShowCopNames"] + { debug: true } + else + {} + end.merge(@rubocop_options) + end + def override_config if @override_config_content - Rubocop::Config.new(YAML.load(@override_config_content)) + config_content = YAML.load(@override_config_content) + override_config = RuboCop::Config.new(config_content, "") + override_config.add_missing_namespaces + override_config.make_excludes_absolute + override_config + else + {} end end end end