Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ jobs:
- name: Run Ruby tests
run: bundle exec rake test

- name: Run Rubydex linter
if: matrix.os == 'ubuntu-latest' && matrix.ruby == '4.0'
run: bundle exec rdx lint .

- name: Save Rust compile cache
id: rust-compile-cache-save
uses: actions/cache/save@v6
Expand Down
5 changes: 4 additions & 1 deletion lib/rubydex/cli/command/lint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ def run
warn_unknown_rules(config.linter, rules)

graph = build_graph($stderr, workspace_path:, config:, fail_on_index_errors: true)
result = Rubydex::Linter::Runner.new(graph, rules:, config: config.linter).run
runner = Rubydex::Linter::Runner.new(graph, rules:, config: config.linter)
rule_count = runner.rules.size
$stderr.puts("Running #{rule_count} #{pluralize("rule", rule_count)}...")
result = runner.run
if result.diagnostics.empty?
print_summary(graph.documents.count, result.diagnostics)
return
Expand Down
3 changes: 2 additions & 1 deletion lib/rubydex/graph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def add_workspace_dependency_paths(paths)
# descending them
next if File.absolute_path?(path)

paths << File.join(spec.full_gem_path, path)
require_path = File.join(spec.full_gem_path, path)
paths << require_path if File.directory?(require_path)
end
rescue Gem::MissingSpecError
nil
Expand Down
13 changes: 7 additions & 6 deletions lib/rubydex/linter/rule_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,26 @@ module Linter
# Loads project and bundled-gem rules using the Rubydex linter path convention.
class RuleLoader
RULE_GLOB = "rubydex_linter/rules/**/*.rb" #: String
BUILT_IN_RULE_GLOB = File.expand_path("../../rubydex_linter/rules/**/*.rb", __dir__) #: String

class << self
#: (String workspace_path) -> Array[singleton(Rule)]
def load(workspace_path)
existing_rules = Rule.subclasses
rule_files = Dir.glob(RULE_GLOB, base: workspace_path).map do |rule_file|
rule_files = Dir.glob(BUILT_IN_RULE_GLOB)
rule_files.concat(Dir.glob(RULE_GLOB, base: workspace_path).map do |rule_file|
File.expand_path(rule_file, workspace_path)
end
if ENV["BUNDLE_GEMFILE"]
rule_files.concat(Gem.find_latest_files(RULE_GLOB))
end
end)
rule_files.concat(Gem.find_latest_files(RULE_GLOB)) if ENV["BUNDLE_GEMFILE"]

rule_files.each do |rule_file|
require rule_file
rescue LoadError, SyntaxError => error
raise RuleLoadError, "Unable to load linter rules from #{rule_file}: #{error.message}", cause: error
end

Rule.subclasses - existing_rules
built_in_rules = [Rules::RuleStructure] #: Array[singleton(Rule)]
built_in_rules | (Rule.subclasses - existing_rules)
end
end
end
Expand Down
Loading
Loading