No release in over 3 years
rubocop-dry-import adds a RuboCop cop (Dry/UnusedImport) that warns when imported dependencies via dry-rb’s Import or AutoInject are not used within the class.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

>= 1.0, < 2.0
 Project Readme

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.