diff --git a/README.md b/README.md index b8d01488ca..72a264c7b3 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,26 @@ RuboCop::RakeTask.new do |task| end ``` +## RuboCop Rails configuration + +The following settings specific to RuboCop Rails can be configured in `.rubocop.yml`. + +### `AllCops: TargetRailsVersion` + +What version of Rails is the inspected code using? If a value is specified +for `TargetRailsVersion` then it is used. Acceptable values are specified +as a float (e.g., 7.2); the patch version of Rails should not be included. + +```yaml +AllCops: + TargetRailsVersion: 7.2 +``` + +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. + ## Rails configuration tip In Rails 6.1+, add the following `config.generators.after_generate` setting to diff --git a/config/default.yml b/config/default.yml index b59db897c5..0e7d183460 100644 --- a/config/default.yml +++ b/config/default.yml @@ -17,12 +17,12 @@ AllCops: # Enable checking Active Support extensions. # See: https://docs.rubocop.org/rubocop/configuration.html#enable-checking-active-support-extensions ActiveSupportExtensionsEnabled: true - # What version of Rails is the inspected code using? If a value is specified - # for TargetRailsVersion then it is used. Acceptable values are specified - # 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 + # What version of Rails is the inspected code using? If a value is specified + # for `TargetRailsVersion` then it is used. Acceptable values are specified + # as a float (e.g., 7.2); 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 + # application. If neither of those files exist, RuboCop will use Rails 5.0 # as the default. TargetRailsVersion: ~ diff --git a/docs/modules/ROOT/pages/usage.adoc b/docs/modules/ROOT/pages/usage.adoc index 97cfe75cec..c4aa17b024 100644 --- a/docs/modules/ROOT/pages/usage.adoc +++ b/docs/modules/ROOT/pages/usage.adoc @@ -31,6 +31,27 @@ RuboCop::RakeTask.new do |task| end ---- +== RuboCop Rails configuration + +The following settings specific to RuboCop Rails can be configured in `.rubocop.yml`. + +=== `AllCops: TargetRailsVersion` + +What version of Rails is the inspected code using? If a value is specified +for `TargetRailsVersion` then it is used. Acceptable values are specified +as a float (e.g., 7.2); the patch version of Rails should not be included. + +[source,yaml] +---- +AllCops: + TargetRailsVersion: 7.2 +---- + +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. + == Rails configuration tip In Rails 6.1+, add the following `config.generators.after_generate` setting to