module Rubydex::Linter::Helpers::PathHelpers
@requires_ancestor: Rubydex::Linter::Rule
Constants
- RUBOCOP_EXCLUDE_FNMATCH_FLAGS
- TEST_PATHS
Public Class Methods
(Location, workspace: String) → String
Source
# File lib/rubydex/linter/helpers/path_helpers.rb, line 29 def display_path(location, workspace:) path = location.to_file_path return path unless path == workspace || path.start_with?("#{workspace}/") Pathname.new(path).relative_path_from(workspace).to_s rescue Location::NotFileUriError URI(location.uri).opaque || location.uri end
Returns the path to show users for a location: relative to the workspace for files inside it, the absolute path for files outside it (dependencies, for example) and the URI opaque for non file URIs, so that untitled:Untitled-1 displays as Untitled-1.
(String, Array[String], workspace: String, ?flags: Integer) → bool
Source
# File lib/rubydex/linter/helpers/path_helpers.rb, line 17 def path_matches_patterns?(path, patterns, workspace:, flags: 0) return false unless path == workspace || path.start_with?("#{workspace}/") relative_path = path.delete_prefix("#{workspace}/") patterns.any? { |pattern| File.fnmatch?(pattern, relative_path, flags) } end
Public Instance Methods
(Enumerable[Rubydex::Definition], Array[String]) → Array[Rubydex::Definition]
Source
# File lib/rubydex/linter/helpers/path_helpers.rb, line 40 def reject_definitions_in_paths(definitions, excluded_patterns) workspace = graph.workspace_path definitions.reject do |definition| path = path_for_definition(definition) path.nil? || (path != workspace && !path.start_with?("#{workspace}/")) || path_matches_patterns?(path, excluded_patterns) end end
(Enumerable[Rubydex::Definition], Array[String]) → Array[Rubydex::Definition]
Source
# File lib/rubydex/linter/helpers/path_helpers.rb, line 51 def select_definitions_in_paths(definitions, patterns) definitions.select do |definition| path = path_for_definition(definition) path && path_matches_patterns?(path, patterns) end end