From f750b714e40f37e1acbdca18053d3ed48d481aa1 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Tue, 26 Feb 2019 20:44:00 +0900 Subject: [PATCH] Update `rake yard_for_generate_documentation` task to add metadata This commit updates `rake yard_for_generate_documentation` task to add metadata and adds document regenerated by `rake yard_for_generate_documentation`. --- manual/cops_rails.md | 300 +++++++++++++++++----------------- tasks/cops_documentation.rake | 27 ++- 2 files changed, 172 insertions(+), 155 deletions(-) diff --git a/manual/cops_rails.md b/manual/cops_rails.md index de385c76e0..075a2d5e01 100644 --- a/manual/cops_rails.md +++ b/manual/cops_rails.md @@ -2,9 +2,9 @@ ## Rails/ActionFilter -Enabled by default | Supports autocorrection ---- | --- -Enabled | Yes +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | Yes | 0.19 | - This cop enforces the consistent use of action filter methods. @@ -52,9 +52,9 @@ Include | `app/controllers/**/*.rb` | Array ## Rails/ActiveRecordAliases -Enabled by default | Supports autocorrection ---- | --- -Enabled | Yes +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | Yes | 0.53 | - Checks that ActiveRecord aliases are not used. The direct method names are more clear and easier to read. @@ -71,9 +71,9 @@ Book.update!(author: 'Alice') ## Rails/ActiveSupportAliases -Enabled by default | Supports autocorrection ---- | --- -Enabled | Yes +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | Yes | 0.48 | - This cop checks that ActiveSupport aliases to core ruby methods are not used. @@ -96,9 +96,9 @@ are not used. ## Rails/ApplicationJob -Enabled by default | Supports autocorrection ---- | --- -Enabled | Yes +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | Yes | 0.49 | - This cop checks that jobs subclass ApplicationJob with Rails 5.0. @@ -118,9 +118,9 @@ end ## Rails/ApplicationRecord -Enabled by default | Supports autocorrection ---- | --- -Enabled | Yes +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | Yes | 0.49 | - This cop checks that models subclass ApplicationRecord with Rails 5.0. @@ -140,9 +140,9 @@ end ## Rails/AssertNot -Enabled by default | Supports autocorrection ---- | --- -Enabled | Yes +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | Yes | 0.56 | - Use `assert_not` instead of `assert !`. @@ -164,9 +164,9 @@ Include | `**/test/**/*` | Array ## Rails/BelongsTo -Enabled by default | Supports autocorrection ---- | --- -Enabled | Yes +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | Yes | 0.62 | - This cop looks for belongs_to associations where we control whether the association is required via the deprecated `required` option instead. @@ -218,9 +218,9 @@ end ## Rails/Blank -Enabled by default | Supports autocorrection ---- | --- -Enabled | Yes +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | Yes | 0.48 | - This cop checks for code that can be written with simpler conditionals using `Object#blank?` defined by Active Support. @@ -287,9 +287,9 @@ UnlessPresent | `true` | Boolean ## Rails/BulkChangeTable -Enabled by default | Supports autocorrection ---- | --- -Enabled | No +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | No | 0.57 | - This Cop checks whether alter queries are combinable. If combinable queries are detected, it suggests to you @@ -363,9 +363,9 @@ Include | `db/migrate/*.rb` | Array ## Rails/CreateTableWithTimestamps -Enabled by default | Supports autocorrection ---- | --- -Enabled | No +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | No | 0.52 | - This cop checks the migration for which timestamps are not included when creating a new table. @@ -416,9 +416,9 @@ Include | `db/migrate/*.rb` | Array ## Rails/Date -Enabled by default | Supports autocorrection ---- | --- -Enabled | No +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | No | 0.30 | 0.33 This cop checks for the correct use of Date methods, such as Date.today, Date.current etc. @@ -475,9 +475,9 @@ EnforcedStyle | `flexible` | `strict`, `flexible` ## Rails/Delegate -Enabled by default | Supports autocorrection ---- | --- -Enabled | Yes +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | Yes | 0.21 | 0.50 This cop looks for delegations that could have been created automatically with the `delegate` method. @@ -544,9 +544,9 @@ EnforceForPrefixed | `true` | Boolean ## Rails/DelegateAllowBlank -Enabled by default | Supports autocorrection ---- | --- -Enabled | Yes +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | Yes | 0.44 | - This cop looks for delegations that pass :allow_blank as an option instead of :allow_nil. :allow_blank is not a valid option to pass @@ -564,9 +564,9 @@ delegate :foo, to: :bar, allow_nil: true ## Rails/DynamicFindBy -Enabled by default | Supports autocorrection ---- | --- -Enabled | Yes +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | Yes | 0.44 | - This cop checks dynamic `find_by_*` methods. Use `find_by` instead of dynamic method. @@ -606,9 +606,9 @@ Whitelist | `find_by_sql` | Array ## Rails/EnumUniqueness -Enabled by default | Supports autocorrection ---- | --- -Enabled | No +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | No | 0.46 | - This cop looks for duplicate values in enum declarations. @@ -636,9 +636,9 @@ Include | `app/models/**/*.rb` | Array ## Rails/EnvironmentComparison -Enabled by default | Supports autocorrection ---- | --- -Enabled | Yes +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | Yes | 0.52 | - This cop checks that Rails.env is compared using `.production?`-like methods instead of equality against a string or symbol. @@ -658,9 +658,9 @@ Rails.env.production? ## Rails/Exit -Enabled by default | Supports autocorrection ---- | --- -Enabled | No +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | No | 0.41 | - This cop enforces that `exit` calls are not used within a rails app. Valid options are instead to raise an error, break, return, or some @@ -695,9 +695,9 @@ Exclude | `lib/**/*.rake` | Array ## Rails/FilePath -Enabled by default | Supports autocorrection ---- | --- -Enabled | No +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | No | 0.47 | 0.57 This cop is used to identify usages of file path joining process to use `Rails.root.join` clause. It is used to add uniformity when @@ -736,9 +736,9 @@ EnforcedStyle | `arguments` | `slashes`, `arguments` ## Rails/FindBy -Enabled by default | Supports autocorrection ---- | --- -Enabled | Yes +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | Yes | 0.30 | - This cop is used to identify usages of `where.first` and change them to use `find_by` instead. @@ -766,9 +766,9 @@ Include | `app/models/**/*.rb` | Array ## Rails/FindEach -Enabled by default | Supports autocorrection ---- | --- -Enabled | Yes +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | Yes | 0.30 | - This cop is used to identify usages of `all.each` and change them to use `all.find_each` instead. @@ -795,9 +795,9 @@ Include | `app/models/**/*.rb` | Array ## Rails/HasAndBelongsToMany -Enabled by default | Supports autocorrection ---- | --- -Enabled | No +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | No | 0.12 | - This cop checks for the use of the has_and_belongs_to_many macro. @@ -823,9 +823,9 @@ Include | `app/models/**/*.rb` | Array ## Rails/HasManyOrHasOneDependent -Enabled by default | Supports autocorrection ---- | --- -Enabled | No +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | No | 0.50 | - This cop looks for `has_many` or `has_one` associations that don't specify a `:dependent` option. @@ -860,9 +860,9 @@ Include | `app/models/**/*.rb` | Array ## Rails/HelperInstanceVariable -Enabled by default | Supports autocorrection ---- | --- -Enabled | No +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | No | 2.0 | - This cop checks for use of the helper methods which reference instance variables. @@ -896,9 +896,9 @@ Include | `app/helpers/**/*.rb` | Array ## Rails/HttpPositionalArguments -Enabled by default | Supports autocorrection ---- | --- -Enabled | Yes +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | Yes | 0.44 | - This cop is used to identify usages of http methods like `get`, `post`, `put`, `patch` without the usage of keyword arguments in your tests and @@ -925,9 +925,9 @@ Include | `spec/**/*`, `test/**/*` | Array ## Rails/HttpStatus -Enabled by default | Supports autocorrection ---- | --- -Enabled | Yes +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | Yes | 0.54 | - Enforces use of symbolic or numeric value to define HTTP status. @@ -972,9 +972,9 @@ EnforcedStyle | `symbolic` | `numeric`, `symbolic` ## Rails/IgnoredSkipActionFilterOption -Enabled by default | Supports autocorrection ---- | --- -Enabled | No +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | No | 0.63 | - This cop checks that `if` and `only` (or `except`) are not used together as options of `skip_*` action filter. @@ -1024,9 +1024,9 @@ Include | `app/controllers/**/*.rb` | Array ## Rails/InverseOf -Enabled by default | Supports autocorrection ---- | --- -Enabled | No +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | No | 0.52 | - This cop looks for has_(one|many) and belongs_to associations where Active Record can't automatically determine the inverse association @@ -1162,9 +1162,9 @@ Include | `app/models/**/*.rb` | Array ## Rails/LexicallyScopedActionFilter -Enabled by default | Supports autocorrection ---- | --- -Enabled | No +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | No | 0.52 | - This cop checks that methods specified in the filter's `only` or `except` options are defined within the same class or module. @@ -1235,9 +1235,9 @@ Include | `app/controllers/**/*.rb` | Array ## Rails/LinkToBlank -Enabled by default | Supports autocorrection ---- | --- -Enabled | Yes +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | Yes | 0.62 | - This cop checks for calls to `link_to` that contain a `target: '_blank'` but no `rel: 'noopener'`. This can be a security @@ -1260,9 +1260,9 @@ link_to 'Click here', url, target: '_blank', rel: 'noopener' ## Rails/NotNullColumn -Enabled by default | Supports autocorrection ---- | --- -Enabled | No +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | No | 0.43 | - This cop checks for add_column call with NOT NULL constraint in migration file. @@ -1289,9 +1289,9 @@ Include | `db/migrate/*.rb` | Array ## Rails/Output -Enabled by default | Supports autocorrection ---- | --- -Enabled | No +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | No | 0.15 | 0.19 This cop checks for the use of output calls like puts and print @@ -1315,9 +1315,9 @@ Include | `app/**/*.rb`, `config/**/*.rb`, `db/**/*.rb`, `lib/**/*.rb` | Array ## Rails/OutputSafety -Enabled by default | Supports autocorrection ---- | --- -Enabled | No +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | No | 0.41 | - This cop checks for the use of output safety calls like `html_safe`, `raw`, and `safe_concat`. These methods do not escape content. They @@ -1384,9 +1384,9 @@ safe_join([user_content, " ", content_tag(:span, user_content)]) ## Rails/PluralizationGrammar -Enabled by default | Supports autocorrection ---- | --- -Enabled | Yes +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | Yes | 0.35 | - This cop checks for correct grammar when using ActiveSupport's core extensions to the numeric classes. @@ -1405,9 +1405,9 @@ core extensions to the numeric classes. ## Rails/Presence -Enabled by default | Supports autocorrection ---- | --- -Enabled | Yes +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | Yes | 0.52 | - This cop checks code that can be written more easily using `Object#presence` defined by Active Support. @@ -1449,9 +1449,9 @@ a.presence || b ## Rails/Present -Enabled by default | Supports autocorrection ---- | --- -Enabled | Yes +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | Yes | 0.48 | - This cop checks for code that can be written with simpler conditionals using `Object#present?` defined by Active Support. @@ -1510,9 +1510,9 @@ UnlessBlank | `true` | Boolean ## Rails/ReadWriteAttribute -Enabled by default | Supports autocorrection ---- | --- -Enabled | Yes +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | Yes | 0.20 | 0.29 This cop checks for the use of the `read_attribute` or `write_attribute` methods and recommends square brackets instead. @@ -1549,9 +1549,9 @@ Include | `app/models/**/*.rb` | Array ## Rails/RedundantReceiverInWithOptions -Enabled by default | Supports autocorrection ---- | --- -Enabled | Yes +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | Yes | 0.52 | - This cop checks for redundant receiver in `with_options`. Receiver is implicit from Rails 4.2 or higher. @@ -1610,9 +1610,9 @@ end ## Rails/ReflectionClassName -Enabled by default | Supports autocorrection ---- | --- -Enabled | No +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | No | 0.64 | - This cop checks if the value of the option `class_name`, in the definition of a reflection is a string. @@ -1630,9 +1630,9 @@ has_many :accounts, class_name: 'Account' ## Rails/RefuteMethods -Enabled by default | Supports autocorrection ---- | --- -Enabled | Yes +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | Yes | 0.56 | - Use `assert_not` methods instead of `refute` methods. @@ -1658,9 +1658,9 @@ Include | `**/test/**/*` | Array ## Rails/RelativeDateConstant -Enabled by default | Supports autocorrection ---- | --- -Enabled | Yes +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | Yes | 0.48 | 0.59 This cop checks whether constant value isn't relative date. Because the relative date will be evaluated only once. @@ -1689,9 +1689,9 @@ AutoCorrect | `false` | Boolean ## Rails/RequestReferer -Enabled by default | Supports autocorrection ---- | --- -Enabled | Yes +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | Yes | 0.41 | - This cop checks for consistent uses of `request.referer` or `request.referrer`, depending on the cop's configuration. @@ -1725,9 +1725,9 @@ EnforcedStyle | `referer` | `referer`, `referrer` ## Rails/ReversibleMigration -Enabled by default | Supports autocorrection ---- | --- -Enabled | No +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | No | 0.47 | - This cop checks whether the change method of the migration file is reversible. @@ -1866,9 +1866,9 @@ Include | `db/migrate/*.rb` | Array ## Rails/SafeNavigation -Enabled by default | Supports autocorrection ---- | --- -Enabled | Yes +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | Yes | 0.43 | - This cop converts usages of `try!` to `&.`. It can also be configured to convert `try`. It will convert code to use safe navigation if the @@ -1917,9 +1917,9 @@ ConvertTry | `false` | Boolean ## Rails/SaveBang -Enabled by default | Supports autocorrection ---- | --- -Disabled | Yes +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Disabled | Yes | Yes | 0.42 | 0.59 This cop identifies possible cases where Active Record save! or related should be used instead of save because the model might have failed to @@ -2032,9 +2032,9 @@ AllowedReceivers | `[]` | Array ## Rails/ScopeArgs -Enabled by default | Supports autocorrection ---- | --- -Enabled | No +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | No | 0.19 | - This cop checks for scope calls where it was passed a method (usually a scope) instead of a lambda/proc. @@ -2057,9 +2057,9 @@ Include | `app/models/**/*.rb` | Array ## Rails/SkipsModelValidations -Enabled by default | Supports autocorrection ---- | --- -Enabled | No +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | No | 0.47 | 0.60 This cop checks for the use of methods which skip validations which are listed in @@ -2111,9 +2111,9 @@ Whitelist | `[]` | Array ## Rails/TimeZone -Enabled by default | Supports autocorrection ---- | --- -Enabled | No +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | No | 0.30 | 0.33 This cop checks for the use of Time methods without zone. @@ -2176,9 +2176,9 @@ EnforcedStyle | `flexible` | `strict`, `flexible` ## Rails/UniqBeforePluck -Enabled by default | Supports autocorrection ---- | --- -Enabled | Yes +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | Yes | 0.40 | 0.47 Prefer the use of uniq (or distinct), before pluck instead of after. @@ -2235,9 +2235,9 @@ AutoCorrect | `false` | Boolean ## Rails/UnknownEnv -Enabled by default | Supports autocorrection ---- | --- -Enabled | No +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | No | 0.51 | - This cop checks that environments called with `Rails.env` predicates exist. @@ -2260,9 +2260,9 @@ Environments | `development`, `test`, `production` | Array ## Rails/Validation -Enabled by default | Supports autocorrection ---- | --- -Enabled | Yes +Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged +--- | --- | --- | --- | --- +Enabled | Yes | Yes | 0.9 | 0.41 This cop checks for the use of old-style attribute validation macros. diff --git a/tasks/cops_documentation.rake b/tasks/cops_documentation.rake index b2bbeae5e9..cea92711f6 100644 --- a/tasks/cops_documentation.rake +++ b/tasks/cops_documentation.rake @@ -32,15 +32,29 @@ task generate_cops_documentation: :yard_for_generate_documentation do end end + # rubocop:disable Metrics/MethodLength def properties(config, cop) - header = ['Enabled by default', 'Supports autocorrection'] - enabled_by_default = config.for_cop(cop).fetch('Enabled') + header = [ + 'Enabled by default', 'Safe', 'Supports autocorrection', 'VersionAdded', + 'VersionChanged' + ] + config = config.for_cop(cop) + safe_auto_correct = config.fetch('SafeAutoCorrect', true) + autocorrect = if cop.new.support_autocorrect? + "Yes #{'(Unsafe)' unless safe_auto_correct}" + else + 'No' + end content = [[ - enabled_by_default ? 'Enabled' : 'Disabled', - cop.new.support_autocorrect? ? 'Yes' : 'No' + config.fetch('Enabled') ? 'Enabled' : 'Disabled', + config.fetch('Safe', true) ? 'Yes' : 'No', + autocorrect, + config.fetch('VersionAdded', '-'), + config.fetch('VersionChanged', '-') ]] to_table(header, content) + "\n" end + # rubocop:enable Metrics/MethodLength def h2(title) content = "\n".dup @@ -165,7 +179,10 @@ task generate_cops_documentation: :yard_for_generate_documentation do def print_cop_with_doc(cop, config) t = config.for_cop(cop) - non_display_keys = %w[Description Enabled StyleGuide Reference] + non_display_keys = %w[ + Description Enabled StyleGuide Reference Safe SafeAutoCorrect VersionAdded + VersionChanged + ] pars = t.reject { |k| non_display_keys.include? k } description = 'No documentation' examples_object = []