Class: RuboCop::ConfigObsoletion Private

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/config_obsoletion.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

This class handles obsolete configuration.

Constant Summary collapse

RENAMED_COPS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{
  'Layout/AlignArguments' => 'Layout/ArgumentAlignment',
  'Layout/AlignArray' => 'Layout/ArrayAlignment',
  'Layout/AlignHash' => 'Layout/HashAlignment',
  'Layout/AlignParameters' => 'Layout/ParameterAlignment',
  'Layout/IndentArray' => 'Layout/FirstArrayElementIndentation',
  'Layout/IndentAssignment' => 'Layout/AssignmentIndentation',
  'Layout/IndentFirstArgument' => 'Layout/FirstArgumentIndentation',
  'Layout/IndentFirstArrayElement' => 'Layout/FirstArrayElementIndentation',
  'Layout/IndentFirstHashElement' => 'Layout/FirstHashElementIndentation',
  'Layout/IndentFirstParameter' => 'Layout/FirstParameterIndentation',
  'Layout/IndentHash' => 'Layout/FirstHashElementIndentation',
  'Layout/IndentHeredoc' => 'Layout/HeredocIndentation',
  'Layout/LeadingBlankLines' => 'Layout/LeadingEmptyLines',
  'Layout/Tab' => 'Layout/IndentationStyle',
  'Layout/TrailingBlankLines' => 'Layout/TrailingEmptyLines',
  'Lint/DuplicatedKey' => 'Lint/DuplicateHashKey',
  'Lint/EndInMethod' => 'Style/EndBlock',
  'Lint/HandleExceptions' => 'Lint/SuppressedException',
  'Lint/MultipleCompare' => 'Lint/MultipleComparison',
  'Lint/StringConversionInInterpolation' => 'Lint/RedundantStringCoercion',
  'Lint/UnneededCopDisableDirective' => 'Lint/RedundantCopDisableDirective',
  'Lint/UnneededCopEnableDirective' => 'Lint/RedundantCopEnableDirective',
  'Lint/UnneededRequireStatement' => 'Lint/RedundantRequireStatement',
  'Lint/UnneededSplatExpansion' => 'Lint/RedundantSplatExpansion',
  'Naming/UncommunicativeBlockParamName' => 'Naming/BlockParameterName',
  'Naming/UncommunicativeMethodParamName' => 'Naming/MethodParameterName',
  'Style/DeprecatedHashMethods' => 'Style/PreferredHashMethods',
  'Style/MethodCallParentheses' => 'Style/MethodCallWithoutArgsParentheses',
  'Style/OpMethod' => 'Naming/BinaryOperatorParameterName',
  'Style/SingleSpaceBeforeFirstArg' => 'Layout/SpaceBeforeFirstArg',
  'Style/UnneededCapitalW' => 'Style/RedundantCapitalW',
  'Style/UnneededCondition' => 'Style/RedundantCondition',
  'Style/UnneededInterpolation' => 'Style/RedundantInterpolation',
  'Style/UnneededPercentQ' => 'Style/RedundantPercentQ',
  'Style/UnneededSort' => 'Style/RedundantSort'
}.map do |old_name, new_name|
  [old_name, "The `#{old_name}` cop has been renamed to `#{new_name}`."]
end
MOVED_COPS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{
  'Security' => 'Lint/Eval',
  'Naming' => %w[Style/ClassAndModuleCamelCase Style/ConstantName
                 Style/FileName Style/MethodName Style/PredicateName
                 Style/VariableName Style/VariableNumber
                 Style/AccessorMethodName Style/AsciiIdentifiers],
  'Layout' => %w[Lint/BlockAlignment Lint/EndAlignment
                 Lint/DefEndAlignment Metrics/LineLength],
  'Lint' => 'Style/FlipFlop'
}.map do |new_department, old_names|
  Array(old_names).map do |old_name|
    [old_name, "The `#{old_name}` cop has been moved to " \
               "`#{new_department}/#{old_name.split('/').last}`."]
  end
end
REMOVED_COPS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{
  'Layout/SpaceAfterControlKeyword' => 'Layout/SpaceAroundKeyword',
  'Layout/SpaceBeforeModifierKeyword' => 'Layout/SpaceAroundKeyword',
  'Lint/RescueWithoutErrorClass' => 'Style/RescueStandardError',
  'Style/SpaceAfterControlKeyword' => 'Layout/SpaceAroundKeyword',
  'Style/SpaceBeforeModifierKeyword' => 'Layout/SpaceAroundKeyword',
  'Style/TrailingComma' => 'Style/TrailingCommaInArguments, ' \
                           'Style/TrailingCommaInArrayLiteral, and/or ' \
                           'Style/TrailingCommaInHashLiteral',
  'Style/TrailingCommaInLiteral' => 'Style/TrailingCommaInArrayLiteral ' \
                                    'and/or ' \
                                    'Style/TrailingCommaInHashLiteral',
  'Style/BracesAroundHashParameters' => nil
}.map do |old_name, other_cops|
  if other_cops
    more = ". Please use #{other_cops} instead".gsub(%r{[A-Z]\w+/\w+},
                                                     '`\&`')
  end
  [old_name, "The `#{old_name}` cop has been removed#{more}."]
end
REMOVED_COPS_WITH_REASON =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{
  'Lint/InvalidCharacterLiteral' => 'it was never being actually triggered',
  'Lint/SpaceBeforeFirstArg' =>
    'it was a duplicate of `Layout/SpaceBeforeFirstArg`. Please use ' \
    '`Layout/SpaceBeforeFirstArg` instead',
  'Style/MethodMissingSuper' => 'it has been superseded by `Lint/MissingSuper`. Please use ' \
    '`Lint/MissingSuper` instead',
  'Lint/UselessComparison' => 'it has been superseded by '\
    '`Lint/BinaryOperatorWithIdenticalOperands`. Please use '\
    '`Lint/BinaryOperatorWithIdenticalOperands` instead'
}.map do |cop_name, reason|
  [cop_name, "The `#{cop_name}` cop has been removed since #{reason}."]
end
SPLIT_COPS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{
  'Style/MethodMissing' =>
    'The `Style/MethodMissing` cop has been split into ' \
    '`Style/MethodMissingSuper` and `Style/MissingRespondToMissing`.'
}.to_a
OBSOLETE_COPS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

OBSOLETE_PARAMETERS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Parameters can be deprecated but not disabled by setting ‘severity: :warning`

{
    cops: %w[Layout/SpaceAroundOperators Style/SpaceAroundOperators],
    parameters: 'MultiSpaceAllowedForOperators',
    alternative: 'If your intention was to allow extra spaces for ' \
                 'alignment, please use AllowForAlignment: true instead.'
  },
  {
    cops: 'Style/Encoding',
    parameters: %w[EnforcedStyle SupportedStyles
                   AutoCorrectEncodingComment],
    alternative: 'Style/Encoding no longer supports styles. ' \
                 'The "never" behavior is always assumed.'
  },
  {
    cops: 'Style/IfUnlessModifier',
    parameters: 'MaxLineLength',
    alternative: '`Style/IfUnlessModifier: MaxLineLength` has been ' \
                 'removed. Use `Layout/LineLength: Max` instead'
  },
  {
    cops: 'Style/WhileUntilModifier',
    parameters: 'MaxLineLength',
    alternative: '`Style/WhileUntilModifier: MaxLineLength` has been ' \
                 'removed. Use `Layout/LineLength: Max` instead'
  },
  {
    cops: 'AllCops',
    parameters: 'RunRailsCops',
    alternative: "Use the following configuration instead:\n" \
                 "Rails:\n  Enabled: true"
  },
  {
    cops: 'Layout/CaseIndentation',
    parameters: 'IndentWhenRelativeTo',
    alternative: '`IndentWhenRelativeTo` has been renamed to ' \
                 '`EnforcedStyle`'
  },
  {
    cops: %w[Lint/BlockAlignment Layout/BlockAlignment Lint/EndAlignment
             Layout/EndAlignment Lint/DefEndAlignment
             Layout/DefEndAlignment],
    parameters: 'AlignWith',
    alternative: '`AlignWith` has been renamed to `EnforcedStyleAlignWith`'
  },
  {
    cops: 'Rails/UniqBeforePluck',
    parameters: 'EnforcedMode',
    alternative: '`EnforcedMode` has been renamed to `EnforcedStyle`'
  },
  {
    cops: 'Style/MethodCallWithArgsParentheses',
    parameters: 'IgnoredMethodPatterns',
    alternative: '`IgnoredMethodPatterns` has been renamed to ' \
                 '`IgnoredPatterns`'
  },
  {
    cops: %w[Performance/Count Performance/Detect],
    parameters: 'SafeMode',
    alternative: '`SafeMode` has been removed. ' \
                 'Use `SafeAutoCorrect` instead.'
  },
  {
    cops: 'Bundler/GemComment',
    parameters: 'Whitelist',
    alternative: '`Whitelist` has been renamed to `IgnoredGems`.'
  },
  {
    cops: %w[
      Lint/SafeNavigationChain Lint/SafeNavigationConsistency
      Style/NestedParenthesizedCalls Style/SafeNavigation
      Style/TrivialAccessors
    ],
    parameters: 'Whitelist',
    alternative: '`Whitelist` has been renamed to `AllowedMethods`.'
  },
  {
    cops: 'Style/IpAddresses',
    parameters: 'Whitelist',
    alternative: '`Whitelist` has been renamed to `AllowedAddresses`.'
  },
  {
    cops: 'Naming/HeredocDelimiterNaming',
    parameters: 'Blacklist',
    alternative: '`Blacklist` has been renamed to `ForbiddenDelimiters`.'
  },
  {
    cops: 'Naming/PredicateName',
    parameters: 'NamePrefixBlacklist',
    alternative: '`NamePrefixBlacklist` has been renamed to ' \
                 '`ForbiddenPrefixes`.'
  },
  {
    cops: 'Naming/PredicateName',
    parameters: 'NameWhitelist',
    alternative: '`NameWhitelist` has been renamed to ' \
                 '`AllowedMethods`.'
  },
  {
    cops: %w[Metrics/BlockLength Metrics/MethodLength],
    parameters: 'ExcludedMethods',
    alternative: '`ExcludedMethods` has been renamed to `IgnoredMethods`.',
    severity: :warning
  }
].freeze
OBSOLETE_ENFORCED_STYLES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

[
  {
    cop: 'Layout/IndentationConsistency',
    parameter: 'EnforcedStyle',
    enforced_style: 'rails',
    alternative: '`EnforcedStyle: rails` has been renamed to ' \
                 '`EnforcedStyle: indented_internal_methods`'
  }
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ ConfigObsoletion

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ConfigObsoletion.



226
227
228
229
# File 'lib/rubocop/config_obsoletion.rb', line 226

def initialize(config)
  @config = config
  @warnings = []
end

Instance Attribute Details

#warningsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



224
225
226
# File 'lib/rubocop/config_obsoletion.rb', line 224

def warnings
  @warnings
end

Instance Method Details

#reject_obsolete_cops_and_parametersObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:



231
232
233
234
235
236
237
# File 'lib/rubocop/config_obsoletion.rb', line 231

def reject_obsolete_cops_and_parameters
  messages = [obsolete_cops, obsolete_parameters,
              obsolete_enforced_style].flatten.compact
  return if messages.empty?

  raise ValidationError, messages.join("\n")
end