{"id":13483510,"url":"https://github.com/rubocop/rubocop-rails","last_synced_at":"2026-01-12T00:53:55.558Z","repository":{"id":36994373,"uuid":"136781582","full_name":"rubocop/rubocop-rails","owner":"rubocop","description":"A RuboCop extension focused on enforcing Rails best practices and coding conventions.","archived":false,"fork":false,"pushed_at":"2025-05-09T15:26:04.000Z","size":29562,"stargazers_count":840,"open_issues_count":170,"forks_count":272,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-05-11T05:47:48.828Z","etag":null,"topics":["code-formatter","hacktoberfest","linter","rails","rubocop","ruby","static-code-analysis"],"latest_commit_sha":null,"homepage":"https://docs.rubocop.org/rubocop-rails","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rubocop.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"bbatsov","patreon":"bbatsov","open_collective":"rubocop","tidelift":"rubygems/rubocop","custom":"https://www.paypal.me/bbatsov"}},"created_at":"2018-06-10T05:22:00.000Z","updated_at":"2025-05-09T15:26:09.000Z","dependencies_parsed_at":"2023-09-28T18:21:40.181Z","dependency_job_id":"53024866-228e-46c7-8be9-ce98f2476ee3","html_url":"https://github.com/rubocop/rubocop-rails","commit_stats":{"total_commits":1587,"total_committers":260,"mean_commits":"6.1038461538461535","dds":0.516698172652804,"last_synced_commit":"11261639e22c85ce6236e5a618a1aaccc66438f5"},"previous_names":["rubocop-hq/rubocop-rails"],"tags_count":198,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubocop%2Frubocop-rails","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubocop%2Frubocop-rails/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubocop%2Frubocop-rails/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubocop%2Frubocop-rails/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rubocop","download_url":"https://codeload.github.com/rubocop/rubocop-rails/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253523733,"owners_count":21921818,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-formatter","hacktoberfest","linter","rails","rubocop","ruby","static-code-analysis"],"created_at":"2024-07-31T17:01:12.193Z","updated_at":"2026-01-12T00:53:55.506Z","avatar_url":"https://github.com/rubocop.png","language":"Ruby","funding_links":["https://github.com/sponsors/bbatsov","https://patreon.com/bbatsov","https://opencollective.com/rubocop","https://tidelift.com/funding/github/rubygems/rubocop","https://www.paypal.me/bbatsov"],"categories":["Code Formatting","Ruby","Gems","Code quality"],"sub_categories":["Articles"],"readme":"# RuboCop Rails\n\n[![Gem Version](https://badge.fury.io/rb/rubocop-rails.svg)](https://badge.fury.io/rb/rubocop-rails)\n[![CI](https://github.com/rubocop/rubocop-rails/actions/workflows/test.yml/badge.svg)](https://github.com/rubocop/rubocop-rails/actions/workflows/test.yml)\n\nA [RuboCop](https://github.com/rubocop/rubocop) extension focused on enforcing Rails best practices and coding conventions.\n\n\u003e [!IMPORTANT]\n\u003e This repository manages rubocop-rails gem (\u003e= 2.0.0). rubocop-rails gem (\u003c= 1.5.0) has been renamed to [rubocop-rails_config](https://rubygems.org/gems/rubocop-rails_config) gem.\n\n## Installation\n\nJust install the `rubocop-rails` gem\n\n```sh\n$ gem install rubocop-rails\n```\n\nor if you use bundler put this in your `Gemfile`\n\n```ruby\ngem 'rubocop-rails', require: false\n```\n\n## Usage\n\nYou need to tell RuboCop to load the Rails extension. There are three\nways to do this:\n\n### RuboCop configuration file\n\nPut this into your `.rubocop.yml`.\n\n```yaml\nplugins: rubocop-rails\n```\n\nAlternatively, use the following array notation when specifying multiple extensions.\n\n```yaml\nplugins:\n  - rubocop-other-extension\n  - rubocop-rails\n```\n\nNow you can run `rubocop` and it will automatically load the RuboCop Rails\ncops together with the standard cops.\n\n\u003e [!NOTE]\n\u003e The plugin system is supported in RuboCop 1.72+. In earlier versions, use `require` instead of `plugins`.\n\n### Command line\n\n```sh\n$ rubocop --plugin rubocop-rails\n```\n\n### Rake task\n\n```ruby\nrequire 'rubocop/rake_task'\n\nRuboCop::RakeTask.new do |task|\n  task.plugins \u003c\u003c 'rubocop-rails'\nend\n```\n\n## RuboCop Rails configuration\n\nThe following settings specific to RuboCop Rails can be configured in `.rubocop.yml`.\n\n### `AllCops: TargetRailsVersion`\n\nWhat version of Rails is the inspected code using? If a value is specified\nfor `TargetRailsVersion` then it is used. Acceptable values are specified\nas a float (e.g., 7.2); the patch version of Rails should not be included.\n\n```yaml\nAllCops:\n  TargetRailsVersion: 7.2\n```\n\nIf `TargetRailsVersion` is not set, RuboCop will parse the Gemfile.lock or\ngems.locked file to find the version of Rails that has been bound to the\napplication. If neither of those files exist, RuboCop will use Rails 5.0\nas the default.\n\n### `AllCops: MigratedSchemaVersion`\n\nBy specifying the `MigratedSchemaVersion` option, migration files that have already been run can be ignored.\nWhen `MigratedSchemaVersion: '20241225000000'` is set, migration files lower than or equal to '20241225000000' will be ignored.\nFor example, to ignore db/migrate/20241225000000_create_articles.rb and earlier migrations you would configure it the following way:\n\n```yaml\nAllCops:\n  MigratedSchemaVersion: '20241225000000'\n```\n\nThis prevents inspecting schema settings for already applied migration files.\nChanging already applied migrations should be avoided because it can lead to the schema getting out of sync\nbetween your local copy and what it actually is in production, depending on when `bin/rails db:migrate` was executed.\nIf you want to modify your schema to comply with the cops, you should instead create new migrations.\n\n## Rails configuration tip\n\nIn Rails 6.1+, add the following `config.generators.after_generate` setting to\nyour `config/environments/development.rb` to apply RuboCop autocorrection to code generated by `bin/rails g`.\n\n```ruby\n# config/environments/development.rb\nRails.application.configure do\n  config.generators.after_generate do |files|\n    parsable_files = files.filter { |file| file.end_with?('.rb') }\n    unless parsable_files.empty?\n      system(\"bundle exec rubocop -A --fail-level=E #{parsable_files.shelljoin}\", exception: true)\n    end\n  end\nend\n```\n\nIt uses `rubocop -A` to apply `Style/FrozenStringLiteralComment` and other unsafe autocorrection cops.\n`rubocop -A` is unsafe autocorrection, but code generated by default is simple and less likely to\nbe incompatible with `rubocop -A`. If you have problems you can replace it with `rubocop -a` instead.\n\nIn Rails 7.2+, it is recommended to use `config.generators.apply_rubocop_autocorrect_after_generate!` instead of the above setting:\n\n```diff\n # config/environments/development.rb\n Rails.application.configure do\n   (snip)\n   # Apply autocorrection by RuboCop to files generated by `bin/rails generate`.\n-  # config.generators.apply_rubocop_autocorrect_after_generate!\n+  config.generators.apply_rubocop_autocorrect_after_generate!\n end\n```\n\nYou only need to uncomment.\n\n## The Cops\n\nAll cops are located under\n[`lib/rubocop/cop/rails`](lib/rubocop/cop/rails), and contain\nexamples/documentation.\n\nIn your `.rubocop.yml`, you may treat the Rails cops just like any other\ncop. For example:\n\n```yaml\nRails/FindBy:\n  Exclude:\n    - lib/example.rb\n```\n\n## Documentation\n\nYou can read a lot more about RuboCop Rails in its [official docs](https://docs.rubocop.org/rubocop-rails/).\n\n## Compatibility\n\nRails cops support the following versions:\n\n- Rails 4.2+\n\n## Readme Badge\n\nIf you use RuboCop Rails in your project, you can include one of these badges in your readme to let people know that your code is written following the community Rails Style Guide.\n\n[![Rails Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop/rubocop-rails)\n\n[![Rails Style Guide](https://img.shields.io/badge/code_style-community-brightgreen.svg)](https://rails.rubystyle.guide)\n\nHere are the Markdown snippets for the two badges:\n\n``` markdown\n[![Rails Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop/rubocop-rails)\n\n[![Rails Style Guide](https://img.shields.io/badge/code_style-community-brightgreen.svg)](https://rails.rubystyle.guide)\n```\n\n## Contributing\n\nCheckout the [contribution guidelines](CONTRIBUTING.md).\n\n## License\n\n`rubocop-rails` is MIT licensed. [See the accompanying file](LICENSE.txt) for\nthe full text.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubocop%2Frubocop-rails","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frubocop%2Frubocop-rails","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubocop%2Frubocop-rails/lists"}