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: false
Usage
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 rubocop
Example
class FooService
include Import['service_a', 'service_b']
def call
service_b.call
end
end
Offense:
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 install
Run tests:
bundle exec rspec
Run RuboCop locally:
bundle exec rubocop --require rubocop-dry-import path/to/file.rb
Contributing
- 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.