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.69.0 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.68.0 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.67.0 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.66.0 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.65.0 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.64.0 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.63.7 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.63.6 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.63.5 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.63.4 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.63.3 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.63.2 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.63.1 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.63.0 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.62.0 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.61.1 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.61.0 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.60.1 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.60.0 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.59.1 lib/cc/analyzer/issue_validations/relative_path_validation.rb