Sha256: 3ed2b24bcae3b1119034968621fa4a45aca7cf56583c00a356fd84b02e1c5ce3

Contents?: true

Size: 1.56 KB

Versions: 27

Compression:

Stored size: 1.56 KB

Contents

require "cc/yaml"

module CC
  module CLI
    class ValidateConfig < Command
      include CC::Analyzer
      include CC::Yaml

      def run
        require_codeclimate_yml
        verify_yaml
      end

      private

      def verify_yaml
        if any_issues?
          display_issues
        else
          puts colorize("No errors or warnings found in .codeclimate.yml file.", :green)
        end
      end

      def any_issues?
        parsed_yaml.errors? || parsed_yaml.nested_warnings.any? || parsed_yaml.warnings?
      end

      def yaml_content
        filesystem.read_path(CODECLIMATE_YAML).freeze
      end

      def parsed_yaml
        @parsed_yaml ||= CC::Yaml.parse(yaml_content)
      end

      def warnings
        @warnings ||= parsed_yaml.warnings
      end

      def nested_warnings
        @nested_warnings ||= parsed_yaml.nested_warnings
      end

      def errors
        @errors ||= parsed_yaml.errors
      end

      def display_issues
        display_errors
        display_warnings
        display_nested_warnings
      end

      def display_errors
        errors.each do |error|
          puts colorize("ERROR: " + error, :red)
        end
      end

      def display_nested_warnings
        nested_warnings.each do |nested_warning|
          if nested_warning[0][0]
            puts colorize("WARNING in " + nested_warning[0][0] + ": " + nested_warning[1], :red)
          end
        end
      end

      def display_warnings
        warnings.each do |warning|
          puts colorize("WARNING: " + warning, :red)
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
codeclimate-0.2.4 lib/cc/cli/validate_config.rb
codeclimate-0.2.2 lib/cc/cli/validate_config.rb
codeclimate-0.2.1 lib/cc/cli/validate_config.rb
codeclimate-0.2 lib/cc/cli/validate_config.rb
codeclimate-0.1.5 lib/cc/cli/validate_config.rb
codeclimate-0.1.4 lib/cc/cli/validate_config.rb
codeclimate-0.1.3 lib/cc/cli/validate_config.rb
codeclimate-0.1.2 lib/cc/cli/validate_config.rb
codeclimate-0.1.0 lib/cc/cli/validate_config.rb
codeclimate-0.0.25 lib/cc/cli/validate_config.rb
codeclimate-0.0.24 lib/cc/cli/validate_config.rb
codeclimate-0.0.23 lib/cc/cli/validate_config.rb
codeclimate-0.0.22 lib/cc/cli/validate_config.rb
codeclimate-0.0.21 lib/cc/cli/validate_config.rb
codeclimate-0.0.18 lib/cc/cli/validate_config.rb
codeclimate-0.0.17 lib/cc/cli/validate_config.rb
codeclimate-0.0.16 lib/cc/cli/validate_config.rb
codeclimate-0.0.15 lib/cc/cli/validate_config.rb
codeclimate-0.0.14 lib/cc/cli/validate_config.rb
codeclimate-0.0.13 lib/cc/cli/validate_config.rb