RuboCop Dry Import
A custom RuboCop extension that detects unused Import dependencies in classes using dry-rb’s dependency injection.
Installation
Add this line to your application's Gemfile:
gem 'rubocop-dry-import', require: falseUsage
Add the extension to your .rubocop.yml:
require:
- rubocop_dry_import
Dry/UnusedImport:
Enabled: true
ImportName: 'Import' # Optional, defaults to "Import"Run RuboCop as usual:
bundle exec rubocopExample
class FooService
include Import['service_a', 'service_b']
def call
service_b.call
end
endOffense:
Include Import['service_a', 'service_b']
^^^^^^^^^^^ Imported dependency `service_a` is not used in the class.
Autocorrect: Not available (yet).
Development
Clone and setup:
git clone https://github.com/seriousdev-gh/rubocop-dry-import
cd rubocop-dry-import
bundle installRun tests:
bundle exec rspecRun RuboCop locally:
bundle exec rubocop --require rubocop-dry-import path/to/file.rbContributing
- Fork the project.
- Create your feature branch (
git checkout -b feature/new-cop). - Commit your changes (
git commit -am 'Add new cop'). - Push to the branch (
git push origin feature/new-cop). - Open a Pull Request.
License
This project is licensed under the MIT License.