Skip to content

[GH-8922] Add support for only one error per file in Rubyzen - #35

Open
Eric Silverberg (esilverberg) wants to merge 1 commit into
mainfrom
8922-add-support-for-only-one-error-per-file-in-rubyzen
Open

[GH-8922] Add support for only one error per file in Rubyzen#35
Eric Silverberg (esilverberg) wants to merge 1 commit into
mainfrom
8922-add-support-for-only-one-error-per-file-in-rubyzen

Conversation

@esilverberg

Copy link
Copy Markdown
Member

What changed and why

Checklist

  • Tests are added or updated for the changes
  • YARD docs are added or updated for the changes
  • bundle exec rake passes locally (runs both the RSpec and Minitest suites)
[GH-8922] Add support for only one error per file in Rubyzen

We want to support only printing one error per file, so we can more easily create baselines

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds one_per_file support to reduce displayed violations while preserving full evaluation.

Changes:

  • Adds shared per-file filtering.
  • Exposes the option across RSpec matchers and Minitest assertions.
  • Documents the option and adds initial regression coverage.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Summary
spec/matchers/zen_empty_matcher_spec.rb Adds per-file output regression coverage.
README.md Documents one_per_file.
lib/rubyzen/matchers/zen_true_matcher.rb Adds option support to the true matcher.
lib/rubyzen/matchers/zen_false_matcher.rb Adds option support to the false matcher.
lib/rubyzen/matchers/zen_empty_matcher.rb Adds option support to the empty matcher.
lib/rubyzen/expectation_helpers.rb Implements shared classification and per-file filtering.
lib/rubyzen/assertions/assert_zen_true.rb Adds option support to the true assertion.
lib/rubyzen/assertions/assert_zen_false.rb Adds option support to the false assertion.
lib/rubyzen/assertions/assert_zen_empty.rb Adds option support to the empty assertion.
Suppressed comments (1)

lib/rubyzen/expectation_helpers.rb:102

  • one_per_file is now threaded through all six public entry points, but the only added example covers zen_empty in RSpec. Add equivalent coverage for the zen_true/zen_false matcher paths and all three Minitest assertions (ideally with multiple files) so regressions in those new branches cannot leave the suite green.
      raw_violations = Array(grouped_items[:violations])
      violations_to_display = one_per_file ? filter_one_per_file(raw_violations) : raw_violations

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 70 to +71
# @return [Hash{Symbol => Array<String>}] keys: :violations, :baseline, :allowlist,
# :stale_baseline, :stale_allowlist
def classify_items(subject_collection, allowlist: nil, baseline: nil)
# :stale_baseline, :stale_allowlist, :violations_raw
Rubyzen::Collections::ClassesCollection.new(file.classes)
end

it 'displays only the first violation from each file' do
expect(non_empty_collection).not_to zen_empty
end

describe 'with one_per_file' do

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add one test in the Minitest assertions as well?

# end
# end
RSpec::Matchers.define :zen_true do |custom_message=nil, allowlist: nil, baseline: nil|
RSpec::Matchers.define :zen_true do |custom_message=nil, allowlist: nil, baseline: nil, one_per_file: false|

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we print maximum one violation per file, it would be nice to at least show how many we have in total, something like:

Violations
  - element: foo
  - file: a.rb:3 (+2 more in this file)

This can be done in a follow-up PR as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants