Rails 6 upgrades to rails notes command and introduction of Rails::Command::NotesCommand

rails notes is used to search your code in a Rails application to find comments beginning with specific keywords.

Rails 6 adds Rails::Command::NotesCommand to follow the pattern for Rails::Commands. It also introduces some useful changes to the rails notes API.

The old rake notes usage has been modified to call that newer command under the hood with a deprecation warning when called with the old API.

Before Rails 6

Previously, one had to use environment variable to find comments beginning with custom keywords.

For instance, to find comments starting with frozen_string_literal,

$ rails notes:custom ANNOTATION=frozen_string_literal
app/channels/application_cable/channel.rb:
  * [1] true

app/channels/application_cable/connection.rb:
  * [1] true

Also, we could use certain tags directly. For instance, to find comments starting with TODO,

$ rails notes:todo
app/models/user.rb:
  * [14] Send email after registration

Rails 6

With Rails 6, we can seamlessly use --annotations argument to either search for default tags or pass specific annotation(s).

For instance, to find comments beginning with default tags (FIXME, OPTIMIZE, TODO),

$ rails notes --annotations
app/controllers/admin/users_controller.rb:
  * [ 40] [TODO] move business logic to model
  * [144] [FIXME] needs urgent attention for next deployment

lib/school.rb:
  * [ 18] [OPTIMIZE] refactor to a faster sql query

And to find annotations with custom tags,

$ rails notes --annotations REFACTOR FIXME
app/controllers/products_controller.rb:
  * [ 55] [REFACTOR] need to refactor this controller code

app/controllers/admin/users_controller.rb:
  * [144] [FIXME] needs urgent attention for next deployment

Note that the old rails notes:custom, rails notes:fixme, rails notes:todo, rails notes:optimize have been marked as deprecated.

Calling any notes command with rake instead of rails has also been deprecated.

Need help on your Ruby on Rails or React project?

Join Our Newsletter