Sha256: 43a18167fb6e14165341b7003f282a85be2c2f323c8704d1faeb17ad84503a68

Contents?: true

Size: 761 Bytes

Versions: 97

Compression:

Stored size: 761 Bytes

Contents

require "pathname"

module CC
  module Analyzer
    module IssueValidations
      class RelativePathValidation < Validation
        BUILDER_CODE_PATH = "/tmp/workspace/code".freeze

        def valid?
          path &&
            !path.start_with?("/") && (
              relative_to?(MountedPath.code.container_path) ||
              relative_to?(BUILDER_CODE_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

97 entries across 97 versions & 2 rubygems

Version Path
codeclimate-0.85.27 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.85.26 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.85.25 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.85.24 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-fede-0.85.54 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-fede-0.85.53 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-fede-0.85.52 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-fede-0.85.51 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-fede-0.85.50 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-fede-0.85.49 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-fede-0.85.48 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-fede-0.85.47 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-fede-0.85.46 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-fede-0.85.45 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-fede-0.85.44 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-fede-0.85.43 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-fede-0.85.42 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-fede-0.85.41 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-fede-0.85.40 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-fede-0.85.39 lib/cc/analyzer/issue_validations/relative_path_validation.rb