otwarchive-symphonyarchive/rubocop/cop
2026-03-11 22:22:11 +00:00
..
cucumber first 2026-03-11 22:22:11 +00:00
i18n first 2026-03-11 22:22:11 +00:00
migration first 2026-03-11 22:22:11 +00:00
README.md first 2026-03-11 22:22:11 +00:00

Custom Cops

This folder contains custom RuboCop rules (cops) we've writen to enforce in-house conventions. To add a new rule, create a Ruby file within the directory that matches the department (category in RuboCop speak). Custom cops also need tests in spec/rubocop.

cucumber

regex_step_name

Checks that Cucumber step definitions use Cucumber expressions instead of Regex. Note: this may not always be possible, and this cop is not smart enough to detect those cases.

Avoid

Given /foobar/ do
  ...
end
When /baz/ do
  ...
end
Then /oops(\w+)/ do |it|
  ...
end

Prefer

Given "foobar(s)" do
  ...
end
When "baz" do
  ...
end
Then "oops{str}" do |it|
  ...
end

# Exception: sometimes we still need regex
When /^I do the (\d+)(?:st|nd|rd|th) thing$/ do |ordinal| # rubocop:disable Cucumber/RegexStepName
  ...
end

i18n

default_translation

Checks for uses of the default keyword argument within Rails translation helpers.

Avoid

t(".translation_key", default: "English text")

Prefer

# assuming the translation is in a view, the key must be defined in config/locales/views/en.yml
t(".translation_key")

deprecated_helper

Checks for uses of the deprecated helper function, ts. Strings passed to it cannot be translated, and all calls will need to be replaced with t to enable UI translations in the future.

Avoid

ts("This will only be in English :(")
ts("Hello %{name}", name: "world")

Prefer

t(".relative.path.to.translation")
t(".greeting", name: "world")

deprecated_translation_key

Checks for uses of translation keys that have been superseded by others or different methods of translation.

Avoid

Category.human_attribute_name("name_with_colon", count: 1)
t(".relative.path.name_with_colon", count: 2)

Prefer

Category.human_attribute_name("name", count: 1) + t("mailer.general.metadata_label_indicator")
metadata_property(t(".relative.path.name", count: 2)) # views only

Deprecated translation keys

migration

large_table_schema_update

Checks that migrations updating the schema of large tables, as defined in the configuration, do so safely. As of writing, this involves utilizing the uses_departure! helper.

Avoid

class ExampleMigration < ActiveRecord::Migration[6.1]
  add_column :users, :new_field, :integer, nullable: true
end

Prefer

class ExampleMigration < ActiveRecord::Migration[6.1]
  uses_departure! if Rails.env.staging? || Rails.env.production?

  add_column :users, :new_field, :integer, nullable: true
end

Tables that require Departure