Class: Rubydex::Linter::Runner
- Inherits:
-
Object
- Object
- Rubydex::Linter::Runner
- Defined in:
- lib/rubydex/linter/runner.rb
Instance Attribute Summary collapse
-
#custom_rules ⇒ Object
readonly
: Array.
-
#graph ⇒ Object
readonly
: Graph.
Instance Method Summary collapse
-
#initialize(graph, custom_rules:, config:) ⇒ Runner
constructor
: (Graph, custom_rules: Array, config: LinterConfig) -> void.
-
#run ⇒ Object
: () -> Array.
Constructor Details
#initialize(graph, custom_rules:, config:) ⇒ Runner
: (Graph, custom_rules: Array, config: LinterConfig) -> void
15 16 17 18 19 20 |
# File 'lib/rubydex/linter/runner.rb', line 15 def initialize(graph, custom_rules:, config:) @graph = graph @config = config @custom_rules = custom_rules.select { |rule| config.rule_enabled?(rule) }.sort_by(&:rule_name) @dependency_patterns = Gem.path.map { |path| "#{path}/**/*" } #: Array[String] end |
Instance Attribute Details
#custom_rules ⇒ Object (readonly)
: Array
12 13 14 |
# File 'lib/rubydex/linter/runner.rb', line 12 def custom_rules @custom_rules end |
#graph ⇒ Object (readonly)
: Graph
9 10 11 |
# File 'lib/rubydex/linter/runner.rb', line 9 def graph @graph end |
Instance Method Details
#run ⇒ Object
: () -> Array
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rubydex/linter/runner.rb', line 23 def run diagnostics = @graph.diagnostics @custom_rules.each do |rule_class| rule = rule_class.new(@graph, config: @config) rule.lint diagnostics.concat(rule.diagnostics) end # Make sure we have the forward/back slash at the end to avoid accidentally matching sibling directories that # share a prefix. workspace_path = File.join(@graph.workspace_path, "") # Filter out diagnostics that are excluded, inside dependencies or otherwise not a part of the workspace. diagnostics.select! do |diagnostic| rule = diagnostic.rule next false unless @config.rule_enabled?(rule) excluded_patterns = @config.excludes_for(rule).map { |pattern| "#{workspace_path}#{pattern}" } excluded_patterns.concat(@dependency_patterns) path = diagnostic.location.to_file_path path.start_with?(workspace_path) && excluded_patterns.none? { |p| File.fnmatch?(p, path, Helpers::PathHelpers::EXCLUDE_FNMATCH_FLAGS) } rescue Location::NotFileUriError true end diagnostics end |