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

  1. Fork the project.
  2. Create your feature branch (git checkout -b feature/new-cop).
  3. Commit your changes (git commit -am 'Add new cop').
  4. Push to the branch (git push origin feature/new-cop).
  5. Open a Pull Request.

License

This project is licensed under the MIT License.