Repository navigation
Conversation
This considers the project root for a gem to be packaged to be determined by the presence of a Gemfile or gems.rb file. It isolates the specs using RuboCop's shared 'isolated environment' context, triggered by the :isolated_environment annotation. This runs the specs in a temporary directory so we can set up the files the cop should look for to determine the (potentially nested) project root. The RuboCop::ConfigFinder.project_root attribute turns out to be little used in RuboCop itself, to the point that it is not reset in the 'isolated environment' spec context. Therefore, we drop its use and simply rely on find_file_upwards to traverse the correct directory hierarchy. This fixes #61.
cd3ed41 to
adf5d0e
Compare
|
@mvz I had AI analyze and compare my forked branch (from the closed PR) which respects nearest gemspec, and this one. Here's what it said: I have a test fixture ensuring my dev harness works on a gem that has a gemspec but no Gemfile. That seems like a valid target for a rubocop project concerned with "packaging", since Ruby packages are most frequently rubygems, and gemspecs are part of the explicit profile of a rubygem. Is the avoidance of detecting gemspecs intentional? And if so, why does that make sense (even for a monorepo with multiple gems and gemspecs - each gemspec represents a gem, which is a package)? |
|
@pboling AI;DR. I'm using Gemfile and gems.rb to match the existing RuboCop behavior of how it finds the project root. In practice, this should have the same result. Since your case is the only existing known case (there will surely be others!), my question remains: Does this give the expected result for your case? |
|
The code block was the AI part, but it seems you skipped what I wrote as well, so I will copy it here: I have a test fixture ensuring my dev harness (about 70 gems and growing) works on a gem that has a gemspec but no Gemfile. That seems like a valid target for a rubocop project concerned with "packaging", since Ruby packages are most frequently rubygems, and gemspecs are part of the explicit profile of a rubygem, while Gemfile/gems.rb is not. Is the avoidance of detecting gemspecs intentional? And if so, why does that make sense (even for a monorepo with multiple gems and gemspecs - each gemspec represents a gem, which is a package)? Gemfile and gems.rb are package boundaries in exactly 0% of packages in Ruby that I have worked with. Is this not rubocop-packaging? I am trying to understand. I'll avoid AI in this repo in the future. |
Great! Two questions:
Packaging here refers to packaging by, e.g., Linux distros, so cops are meant to stimulate behaviors that will make it easier to repackage ruby gems as There are many theoretical edge cases I can think of with Eventually, it makes sense to make the package root configurable somehow. |
|
The fixture I was referring to is here (inline): It's not proving this scenario, rather it proves that my tooling can run on a gem with only a gemspec and no Gemfile, not linting per se. I found another Gemfile-free fixture gem I use for testing with Appraisals: https://github.com/appraisal-rb/appraisal2/tree/main/spec/fixtures/test_gem It also is not specifically testing linting integration. My main claim is this:
And I think that matters, because Gemfile is not a prescribed part of a published gem, neither is it part of the packages this project would recommend. So an unpacked installed gem would not have a Gemfile. This project would be unable to recognize the package shape it recommends as a package, and it would be unable to lint it. Worse, if you have a Gemfile in a parent directory it wouldn't even fail. It would likely succeed with a false positive, report a clean lint, having not linted the package at all. It would look right past it to any random parent dir that has a Gemfile. The gemspec has At the same time - no, I do not intend to build gems without Gemfiles. So this is absolutely a storm in a tea kettle. |
This considers the project root for a gem to be packaged to be determined by the presence of a Gemfile or gems.rb file.
It isolates the specs using RuboCop's shared 'isolated environment' context, triggered by the
:isolated_environmentannotation. This runs the specs in a temporary directory so we can set up the files the cop should look for to determine the (potentially nested) project root.The
RuboCop::ConfigFinder.project_rootattribute turns out to be little used in RuboCop itself, to the point that it is not reset in the 'isolated environment' spec context. Therefore, we drop its use and simply rely onfind_file_upwardsto traverse the correct directory hierarchy.This fixes #61.