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.59.0 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.58.0 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.57.0 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.56.0 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.55.0 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.54.0 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.53.0 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.52.0 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.51.3 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.51.2 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.51.1 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.51.0 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.50.0 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.49.0 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.48.0 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.47.0 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.46.0 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.45.0 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.44.0 lib/cc/analyzer/issue_validations/relative_path_validation.rb
codeclimate-0.43.1 lib/cc/analyzer/issue_validations/relative_path_validation.rb