standardrb / standard-ruby-action

MIT License
11 stars 12 forks source link

Run standardrb on a subdirectory #21

Open wjessop opened 2 days ago

wjessop commented 2 days ago

A client has their Rails app contained in a subdirectory of a monorepo and not the root:

root/
├── terraform/
├── cats/
│   └─── gifs/
└── rails_apps/
    ├── widgets_app/
    │   ├── .github/
    │   │   ├── standardrb.yml
etc.

would an option to run standardrb in a subdirectory be possible?

searls commented 2 days ago

How does RuboCop handle it? I think the right answer is probably to mirror them

wjessop commented 1 day ago

Rubocop takes a list of files:

% rubocop -h          
Usage: rubocop [options] [file1, file2, ...]

Basic Options:
…

It seems that Rubocop will take a directory too and run on all files contained within it and it's subdirectories:

% pwd
root/
% rubocop rails_apps/widgets_app
<robocop runs on all files in all subdirs of rails_apps/widgets_app>

However, it seems I've got Rubocop in my $PATH as it's not possible to bundle exec (the Gemfile is in rails_apps/widgets_app and not in the root of the repo which means that bundle exec standardrb --fix will not work there either:

% bundle exec rubocop rails_apps/widgets_app
Could not locate Gemfile or .bundle/ directory

The alternative would be to do something like reviewdog/action-rubocop and to allow specifying a workdir in the action that we could either cd to before running bundle exec …, or pushd/popd around to maintain the working directory.

searls commented 1 day ago

Yeah, I'd shop around to look at a few other linter actions on github and see if there's a consensus name for this, but it sounds like a working directory config option is the best bet