A Ruby gem that automatically sorts and organizes your import statements in Ruby files. You can use it on a file or a complete directory at once. Checkout here: https://rubygems.org/gems/isort
gem install isort
isort --file path/to/your/file.rb
or
isort -f path/to/your/file.rb
isort --directory path/to/your/directory
or
isort -d path/to/your/directory
require 'isort'
sorter = Isort::FileSorter.new('path/to/your/file.rb')
sorter.sort_and_format_imports
- Sorts import statements correctly as per the norms
- Groups imports by type (require, require_relative, include, extend)
- Preserves code structure and spacing
- Maintains conditional requires
- Respects nested class and module definitions
Bug reports and pull requests are welcome on GitHub at https://github.com/abhinvv1/isort.
The gem is available as open source under the terms of the MIT License.