require: - rubocop-rails inherit_mode: merge: - Exclude AllCops: Exclude: - 'node_modules/**/*' - 'vendor/**/*' - '.git/**/*' - 'bin/**/*' - 'tmp/**/*' - 'public/system/**/*' - 'db/schema.rb' # What version of Rails is the inspected code using? If a value is specified # for TargetRailsVersion then it is used. Acceptable values are specificed # as a float (i.e. 5.1); the patch version of Rails should not be included. # If TargetRailsVersion is not set, RuboCop will parse the Gemfile.lock or # gems.locked file to find the version of Rails that has been bound to the # application. If neither of those files exist, RuboCop will use Rails 5.0 # as the default. TargetRailsVersion: ~ Rails/ActionFilter: Description: 'Enforces consistent use of action filter methods.' Enabled: true VersionAdded: '0.19' EnforcedStyle: action SupportedStyles: - action - filter Include: - app/controllers/**/*.rb Rails/ActiveRecordAliases: Description: >- Avoid Active Record aliases: Use `update` instead of `update_attributes`. Use `update!` instead of `update_attributes!`. Enabled: true VersionAdded: '0.53' SafeAutoCorrect: false Rails/ActiveRecordCallbacksOrder: Description: 'Order callback declarations in the order in which they will be executed.' StyleGuide: 'https://rails.rubystyle.guide/#callbacks-order' Enabled: true VersionAdded: '2.7' Include: - app/models/**/*.rb Rails/ActiveRecordOverride: Description: >- Check for overriding Active Record methods instead of using callbacks. Enabled: true VersionAdded: '0.67' Include: - app/models/**/*.rb Rails/ActiveSupportAliases: Description: >- Avoid ActiveSupport aliases of standard ruby methods: `String#starts_with?`, `String#ends_with?`, `Array#append`, `Array#prepend`. Enabled: false VersionAdded: '0.48' Rails/AfterCommitOverride: Description: >- This cop enforces that there is only one call to `after_commit` (and its aliases - `after_create_commit`, `after_update_commit`, and `after_destroy_commit`) with the same callback name per model. Enabled: true VersionAdded: '2.8' Rails/ApplicationController: Description: 'Check that controllers subclass ApplicationController.' Enabled: false # We have Controllers like `/jasmine` which do not inherit from ApplicationController SafeAutoCorrect: false VersionAdded: '2.4' VersionChanged: '2.5' Rails/ApplicationJob: Description: 'Check that jobs subclass ApplicationJob.' Enabled: true SafeAutoCorrect: false VersionAdded: '0.49' VersionChanged: '2.5' Rails/ApplicationMailer: Description: 'Check that mailers subclass ApplicationMailer.' Enabled: true SafeAutoCorrect: false VersionAdded: '2.4' VersionChanged: '2.5' Rails/ApplicationRecord: Description: 'Check that models subclass ApplicationRecord.' Enabled: false # Because not all models are necessarily domain models (e.g. migration models for legacy databases) SafeAutoCorrect: false VersionAdded: '0.49' VersionChanged: '2.5' Rails/ArelStar: Description: 'Enforces `Arel.star` instead of `"*"` for expanded columns.' Enabled: true SafeAutoCorrect: false VersionAdded: '2.9' Rails/AssertNot: Description: 'Use `assert_not` instead of `assert !`.' Enabled: true VersionAdded: '0.56' Include: - '**/test/**/*' Rails/AttributeDefaultBlockValue: Description: 'Pass method call in block for attribute option `default`.' Enabled: true VersionAdded: '2.9' Include: - 'models/**/*' Rails/BelongsTo: Description: >- Use `optional: true` instead of `required: false` for `belongs_to` relations. Enabled: true VersionAdded: '0.62' Rails/Blank: Description: 'Enforces use of `blank?`.' Enabled: true VersionAdded: '0.48' VersionChanged: '0.67' # Convert usages of `nil? || empty?` to `blank?` NilOrEmpty: true # Convert usages of `!present?` to `blank?` NotPresent: true # Convert usages of `unless present?` to `if blank?` UnlessPresent: true Rails/BulkChangeTable: Description: 'Check whether alter queries are combinable.' Enabled: false # We'll maybe enable this later. VersionAdded: '0.57' Database: null SupportedDatabases: - mysql - postgresql Include: - db/migrate/*.rb Rails/ContentTag: Description: 'Use `tag` instead of `content_tag`.' Reference: - 'https://github.com/rails/rails/issues/25195' - 'https://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-content_tag' Enabled: false # The Github page returned an 500 so I was not able to evaluate this cop VersionAdded: '2.6' Rails/CreateTableWithTimestamps: Description: >- Checks the migration for which timestamps are not included when creating a new table. Enabled: true VersionAdded: '0.52' Include: - db/migrate/*.rb Rails/Date: Description: >- Checks the correct usage of date aware methods, such as Date.today, Date.current etc. Enabled: false # It's not that simple. Really. VersionAdded: '0.30' VersionChanged: '0.33' # The value `strict` disallows usage of `Date.today`, `Date.current`, # `Date#to_time` etc. # The value `flexible` allows usage of `Date.current`, `Date.yesterday`, etc # (but not `Date.today`) which are overridden by ActiveSupport to handle current # time zone. EnforcedStyle: flexible SupportedStyles: - strict - flexible Rails/DefaultScope: Description: 'Avoid use of `default_scope`.' StyleGuide: 'https://rails.rubystyle.guide#avoid-default-scope' Enabled: false VersionAdded: '2.7' Rails/Delegate: Description: 'Prefer delegate method for delegations.' Enabled: false VersionAdded: '0.21' VersionChanged: '0.50' # When set to true, using the target object as a prefix of the # method name without using the `delegate` method will be a # violation. When set to false, this case is legal. EnforceForPrefixed: true Rails/DelegateAllowBlank: Description: 'Do not use allow_blank as an option to delegate.' Enabled: true VersionAdded: '0.44' Rails/DynamicFindBy: Description: 'Use `find_by` instead of dynamic `find_by_*`.' StyleGuide: 'https://rails.rubystyle.guide#find_by' Enabled: false # We occasionally define custom find_by_* methods (e.g. `find_by_anything`) which don't work like ActiveRecord's methods. VersionAdded: '0.44' VersionChanged: '2.6' # The `Whitelist` has been deprecated, Please use `AllowedMethods` instead. Whitelist: - find_by_sql AllowedMethods: - find_by_sql AllowedReceivers: - Gem::Specification Rails/EnumHash: Description: 'Prefer hash syntax over array syntax when defining enums.' StyleGuide: 'https://rails.rubystyle.guide#enums' Enabled: true VersionAdded: '2.3' Include: - app/models/**/*.rb Rails/EnumUniqueness: Description: 'Avoid duplicate integers in hash-syntax `enum` declaration.' Enabled: true VersionAdded: '0.46' Include: - app/models/**/*.rb Rails/EnvironmentComparison: Description: "Favor `Rails.env.production?` over `Rails.env == 'production'`." Enabled: true VersionAdded: '0.52' Rails/Exit: Description: >- Favor `fail`, `break`, `return`, etc. over `exit` in application or library code outside of Rake files to avoid exits during unit testing or running in production. Enabled: true VersionAdded: '0.41' Include: - app/**/*.rb - config/**/*.rb - lib/**/*.rb Exclude: - lib/**/*.rake Rails/FilePath: Description: 'Use `Rails.root.join` for file path joining.' Enabled: false VersionAdded: '0.47' VersionChanged: '2.4' EnforcedStyle: slashes SupportedStyles: - slashes - arguments Rails/FindBy: Description: 'Prefer find_by over where.first.' StyleGuide: 'https://rails.rubystyle.guide#find_by' Enabled: false VersionAdded: '0.30' Include: - app/models/**/*.rb Rails/FindById: Description: >- Favor the use of `find` over `where.take!`, `find_by!`, and `find_by_id!` when you need to retrieve a single record by primary key when you expect it to be found. StyleGuide: 'https://rails.rubystyle.guide/#find' Enabled: true VersionAdded: '2.7' Rails/FindEach: Description: 'Prefer all.find_each over all.find.' StyleGuide: 'https://rails.rubystyle.guide#find-each' Enabled: true VersionAdded: '0.30' VersionChanged: '2.9' Include: - app/models/**/*.rb IgnoredMethods: # Methods that don't work well with `find_each`. - order - limit - select - lock Rails/HasAndBelongsToMany: Description: 'Prefer has_many :through to has_and_belongs_to_many.' StyleGuide: 'https://rails.rubystyle.guide#has-many-through' Enabled: true VersionAdded: '0.12' Include: - app/models/**/*.rb Rails/HasManyOrHasOneDependent: Description: 'Define the dependent option to the has_many and has_one associations.' StyleGuide: 'https://rails.rubystyle.guide#has_many-has_one-dependent-option' Enabled: false # https://github.com/makandra/makandra-rubocop/issues/13 VersionAdded: '0.50' Include: - app/models/**/*.rb Rails/HelperInstanceVariable: Description: 'Do not use instance variables in helpers.' Enabled: false # https://github.com/makandra/makandra-rubocop/issues/12 VersionAdded: '2.0' Include: - app/helpers/**/*.rb Rails/HttpPositionalArguments: Description: 'Use keyword arguments instead of positional arguments in http method calls.' Enabled: true VersionAdded: '0.44' Include: - 'spec/**/*' - 'test/**/*' Rails/HttpStatus: Description: 'Enforces use of symbolic or numeric value to define HTTP status.' Enabled: false VersionAdded: '0.54' EnforcedStyle: symbolic SupportedStyles: - numeric - symbolic Rails/IgnoredSkipActionFilterOption: Description: 'Checks that `if` and `only` (or `except`) are not used together as options of `skip_*` action filter.' Reference: 'https://api.rubyonrails.org/classes/AbstractController/Callbacks/ClassMethods.html#method-i-_normalize_callback_options' Enabled: true VersionAdded: '0.63' Include: - app/controllers/**/*.rb Rails/IndexBy: Description: 'Prefer `index_by` over `each_with_object`, `to_h`, or `map`.' Enabled: true VersionAdded: '2.5' VersionChanged: '2.8' Rails/IndexWith: Description: 'Prefer `index_with` over `each_with_object`, `to_h`, or `map`.' Enabled: true VersionAdded: '2.5' VersionChanged: '2.8' Rails/Inquiry: Description: "Prefer Ruby's comparison operators over Active Support's `Array#inquiry` and `String#inquiry`." StyleGuide: 'https://rails.rubystyle.guide/#inquiry' Enabled: false # Not clear why we want this VersionAdded: '2.7' Rails/InverseOf: Description: 'Checks for associations where the inverse cannot be determined automatically.' Enabled: true VersionAdded: '0.52' Include: - app/models/**/*.rb Rails/LexicallyScopedActionFilter: Description: "Checks that methods specified in the filter's `only` or `except` options are explicitly defined in the controller." StyleGuide: 'https://rails.rubystyle.guide#lexically-scoped-action-filter' Enabled: true Safe: false VersionAdded: '0.52' Include: - app/controllers/**/*.rb Rails/LinkToBlank: Description: 'Checks that `link_to` with a `target: "_blank"` have a `rel: "noopener"` option passed to them.' Reference: - https://mathiasbynens.github.io/rel-noopener/ - https://html.spec.whatwg.org/multipage/links.html#link-type-noopener - https://html.spec.whatwg.org/multipage/links.html#link-type-noreferrer Enabled: true VersionAdded: '0.62' Rails/MailerName: Description: 'Mailer should end with `Mailer` suffix.' StyleGuide: 'https://rails.rubystyle.guide/#mailer-name' Enabled: true SafeAutoCorrect: false VersionAdded: '2.7' Include: - app/mailers/**/*.rb Rails/MatchRoute: Description: >- Don't use `match` to define any routes unless there is a need to map multiple request types among [:get, :post, :patch, :put, :delete] to a single action using the `:via` option. StyleGuide: 'https://rails.rubystyle.guide/#no-match-routes' Enabled: false # No need why we want to have a cop for this VersionAdded: '2.7' Include: - config/routes.rb - config/routes/**/*.rb Rails/NegateInclude: Description: 'Prefer `collection.exclude?(obj)` over `!collection.include?(obj)`.' StyleGuide: 'https://rails.rubystyle.guide#exclude' Enabled: true Safe: false VersionAdded: '2.7' VersionChanged: '2.9' Rails/NotNullColumn: Description: 'Do not add a NOT NULL column without a default value.' Enabled: true VersionAdded: '0.43' Include: - db/migrate/*.rb Rails/OrderById: Description: >- Do not use the `id` column for ordering. Use a timestamp column to order chronologically. StyleGuide: 'https://rails.rubystyle.guide/#order-by-id' Enabled: false VersionAdded: '2.8' Rails/Output: Description: 'Checks for calls to puts, print, etc.' Enabled: false VersionAdded: '0.15' VersionChanged: '0.19' Include: - app/**/*.rb - config/**/*.rb - db/**/*.rb - lib/**/*.rb Rails/OutputSafety: Description: 'The use of `html_safe` or `raw` may be a security risk.' Enabled: true # We may need to review this. Unsure if the cop can always know which `html_safe` call is valid and which one is not. VersionAdded: '0.41' Rails/Pick: Description: 'Prefer `pick` over `pluck(...).first`.' StyleGuide: 'https://rails.rubystyle.guide#pick' Enabled: true Safe: false VersionAdded: '2.6' Rails/Pluck: Description: 'Prefer `pluck` over `map { ... }`.' StyleGuide: 'https://rails.rubystyle.guide#pluck' Enabled: true VersionAdded: '2.7' Rails/PluckId: Description: 'Use `ids` instead of `pluck(:id)` or `pluck(primary_key)`.' StyleGuide: 'https://rails.rubystyle.guide/#ids' Enabled: true Safe: false VersionAdded: '2.7' Rails/PluckInWhere: Description: 'Use `select` instead of `pluck` in `where` query methods.' Enabled: false Safe: false VersionAdded: '2.7' VersionChanged: '2.8' EnforcedStyle: conservative SupportedStyles: - conservative - aggressive Rails/PluralizationGrammar: Description: 'Checks for incorrect grammar when using methods like `3.day.ago`.' Enabled: true VersionAdded: '0.35' Rails/Presence: Description: 'Checks code that can be written more easily using `Object#presence` defined by Active Support.' Enabled: true VersionAdded: '0.52' Rails/Present: Description: 'Enforces use of `present?`.' Enabled: true VersionAdded: '0.48' VersionChanged: '0.67' # Convert usages of `!nil? && !empty?` to `present?` NotNilAndNotEmpty: true # Convert usages of `!blank?` to `present?` NotBlank: true # Convert usages of `unless blank?` to `if present?` UnlessBlank: true Rails/RakeEnvironment: Description: 'Include `:environment` as a dependency for all Rake tasks.' Enabled: false Safe: false VersionAdded: '2.4' VersionChanged: '2.6' Include: - '**/Rakefile' - '**/*.rake' Exclude: - 'lib/capistrano/tasks/**/*.rake' Rails/ReadWriteAttribute: Description: >- Checks for read_attribute(:attr) and write_attribute(:attr, val). StyleGuide: 'https://rails.rubystyle.guide#read-attribute' Enabled: true VersionAdded: '0.20' VersionChanged: '0.29' Include: - app/models/**/*.rb Rails/RedundantAllowNil: Description: >- Finds redundant use of `allow_nil` when `allow_blank` is set to certain values in model validations. Enabled: true VersionAdded: '0.67' Include: - app/models/**/*.rb Rails/RedundantForeignKey: Description: 'Checks for associations where the `:foreign_key` option is redundant.' Enabled: true VersionAdded: '2.6' Rails/RedundantReceiverInWithOptions: Description: 'Checks for redundant receiver in `with_options`.' Enabled: true VersionAdded: '0.52' Rails/ReflectionClassName: Description: 'Use a string for `class_name` option value in the definition of a reflection.' Enabled: true VersionAdded: '0.64' Rails/RefuteMethods: Description: 'Use `assert_not` methods instead of `refute` methods.' Enabled: true VersionAdded: '0.56' EnforcedStyle: assert_not SupportedStyles: - assert_not - refute Include: - '**/test/**/*' Rails/RelativeDateConstant: Description: 'Do not assign relative date to constants.' Enabled: true VersionAdded: '0.48' VersionChanged: '0.59' AutoCorrect: false Rails/RenderInline: Description: 'Prefer using a template over inline rendering.' StyleGuide: 'https://rails.rubystyle.guide/#inline-rendering' Enabled: false VersionAdded: '2.7' Rails/RenderPlainText: Description: 'Prefer `render plain:` over `render text:`.' StyleGuide: 'https://rails.rubystyle.guide/#plain-text-rendering' Enabled: true VersionAdded: '2.7' # Convert only when `content_type` is explicitly set to `text/plain`. ContentTypeCompatibility: true Rails/RequestReferer: Description: 'Use consistent syntax for request.referer.' Enabled: true VersionAdded: '0.41' EnforcedStyle: referer SupportedStyles: - referer - referrer Rails/ReversibleMigration: Description: 'Checks whether the change method of the migration file is reversible.' StyleGuide: 'https://rails.rubystyle.guide#reversible-migration' Reference: 'https://api.rubyonrails.org/classes/ActiveRecord/Migration/CommandRecorder.html' Enabled: true VersionAdded: '0.47' Include: - db/migrate/*.rb Rails/SafeNavigation: Description: "Use Ruby's safe navigation operator (`&.`) instead of `try!`." Enabled: false VersionAdded: '0.43' # This will convert usages of `try` to use safe navigation as well as `try!`. # `try` and `try!` work slightly differently. `try!` and safe navigation will # both raise a `NoMethodError` if the receiver of the method call does not # implement the intended method. `try` will not raise an exception for this. ConvertTry: false Rails/SafeNavigationWithBlank: Description: 'Avoid `foo&.blank?` in conditionals.' Enabled: true VersionAdded: '2.4' # While the safe navigation operator is generally a good idea, when # checking `foo&.blank?` in a conditional, `foo` being `nil` will actually # do the opposite of what the author intends. # # foo&.blank? #=> nil # foo.blank? #=> true SafeAutoCorrect: false Rails/SaveBang: Description: 'Identifies possible cases where Active Record save! or related should be used.' StyleGuide: 'https://rails.rubystyle.guide#save-bang' Enabled: false VersionAdded: '0.42' VersionChanged: '0.59' AllowImplicitReturn: true AllowedReceivers: [] SafeAutoCorrect: false Rails/ScopeArgs: Description: 'Checks the arguments of ActiveRecord scopes.' Enabled: true VersionAdded: '0.19' Include: - app/models/**/*.rb Rails/ShortI18n: Description: 'Use the short form of the I18n methods: `t` instead of `translate` and `l` instead of `localize`.' StyleGuide: 'https://rails.rubystyle.guide/#short-i18n' Enabled: true VersionAdded: '2.7' EnforcedStyle: conservative SupportedStyles: - conservative - aggressive Rails/SkipsModelValidations: Description: >- Use methods that skips model validations with caution. See reference for more information. Reference: 'https://guides.rubyonrails.org/active_record_validations.html#skipping-validations' Enabled: false VersionAdded: '0.47' VersionChanged: '2.7' ForbiddenMethods: - decrement! - decrement_counter - increment! - increment_counter - insert - insert! - insert_all - insert_all! - toggle! - touch - touch_all - update_all - update_attribute - update_column - update_columns - update_counters - upsert - upsert_all AllowedMethods: [] Rails/SquishedSQLHeredocs: Description: 'Checks SQL heredocs to use `.squish`.' StyleGuide: 'https://rails.rubystyle.guide/#squished-heredocs' Enabled: true VersionAdded: '2.8' VersionChanged: '2.9' # Some SQL syntax (e.g. PostgreSQL comments and functions) requires newlines # to be preserved in order to work, thus auto-correction is not safe. SafeAutoCorrect: false Rails/TimeZone: Description: 'Checks the correct usage of time zone aware methods.' StyleGuide: 'https://rails.rubystyle.guide#time' Reference: 'http://danilenko.org/2012/7/6/rails_timezones' Enabled: false Safe: false VersionAdded: '0.30' VersionChanged: '0.68' # The value `strict` means that `Time` should be used with `zone`. # The value `flexible` allows usage of `in_time_zone` instead of `zone`. EnforcedStyle: flexible SupportedStyles: - strict - flexible Rails/UniqBeforePluck: Description: 'Prefer the use of uniq or distinct before pluck.' Enabled: true VersionAdded: '0.40' VersionChanged: '2.8' EnforcedStyle: conservative SupportedStyles: - conservative - aggressive SafeAutoCorrect: false AutoCorrect: false Rails/UniqueValidationWithoutIndex: Description: 'Uniqueness validation should be with a unique index.' Enabled: true VersionAdded: '2.5' Include: - app/models/**/*.rb Rails/UnknownEnv: Description: 'Use correct environment name.' Enabled: false # https://github.com/makandra/makandra-rubocop/issues/11 VersionAdded: '0.51' Environments: - development - test - production Rails/Validation: Description: 'Use validates :attribute, hash of validations.' Enabled: true VersionAdded: '0.9' VersionChanged: '0.41' Include: - app/models/**/*.rb Rails/WhereEquals: Description: 'Pass conditions to `where` as a hash instead of manually constructing SQL.' StyleGuide: 'https://rails.rubystyle.guide/#hash-conditions' Enabled: true VersionAdded: '2.9' Rails/WhereExists: Description: 'Prefer `exists?(...)` over `where(...).exists?`.' Enabled: true EnforcedStyle: exists SupportedStyles: - exists - where VersionAdded: '2.7' VersionChanged: '2.8' Rails/WhereNot: Description: 'Use `where.not(...)` instead of manually constructing negated SQL in `where`.' StyleGuide: 'https://rails.rubystyle.guide/#hash-conditions' Enabled: true VersionAdded: '2.8' # Accept `redirect_to(...) and return` and similar cases. Style/AndOr: EnforcedStyle: conditionals