Sha256: 4ea91a8302dd45fbdb54e86f3788f9909fd3bc4335ef31c5a985d603147ff64d

Contents?: true

Size: 636 Bytes

Versions: 52

Compression:

Stored size: 636 Bytes

Contents

require "pathname"

module CC
  module Analyzer
    module IssueValidations
      class RelativePathValidation < 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
      end
    end
  end
end

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
codeclimate-0.43.0 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.42.1 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.42.0 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.41.0 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.40.3 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.40.2 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.40.1 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.40.0 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.39.0 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.38.1 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.38.0 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.37.0 lib/cc/analyzer/issue_validations/relative_path_validation.rb