Sha256: f6231864663870ae522255952368ebe6e8c7ce22159725ab006ebdef0c32fd97

Contents?: true

Size: 644 Bytes

Versions: 12

Compression:

Stored size: 644 Bytes

Contents

require "pathname"

module CC
  module Analyzer
    class IssueRelativePathValidation < Validation
      def valid?
        path &&
          !path.start_with?("/") &&
          relative_to?(MountedPath.code.container_path)
      end

      def message
        "Path must be relative to the project directory"
      end

      private

      def relative_to?(directory)
        expanded_base = Pathname.new(directory).expand_path.to_s
        expanded_path = Pathname.new(path).expand_path.to_s

        expanded_path.start_with?(expanded_base)
      end

      def path
        object.fetch("location", {})["path"]
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
codeclimate-0.34.1 lib/cc/analyzer/issue_relative_path_validation.rb
codeclimate-0.34.0 lib/cc/analyzer/issue_relative_path_validation.rb
codeclimate-0.33.0 lib/cc/analyzer/issue_relative_path_validation.rb
codeclimate-0.32.1 lib/cc/analyzer/issue_relative_path_validation.rb
codeclimate-0.32.0 lib/cc/analyzer/issue_relative_path_validation.rb
codeclimate-0.32.0.rc1 lib/cc/analyzer/issue_relative_path_validation.rb
codeclimate-0.31.1 lib/cc/analyzer/issue_relative_path_validation.rb
codeclimate-0.31.0 lib/cc/analyzer/issue_relative_path_validation.rb
codeclimate-0.30.1 lib/cc/analyzer/issue_relative_path_validation.rb
codeclimate-0.30.0 lib/cc/analyzer/issue_relative_path_validation.rb
codeclimate-0.29.0 lib/cc/analyzer/issue_relative_path_validation.rb
codeclimate-0.28.0 lib/cc/analyzer/issue_relative_path_validation.rb