Module: Mry::AddedCops

Defined in:
lib/mry/added_cops.rb

Defined Under Namespace

Classes: RuboCopVersionMismatchError

Constant Summary collapse

Cops =
{
  Gem::Version.new('0.51.0') => %w[
    Rails/UnknownEnv
    Style/StderrPuts
    Lint/UnneededRequireStatement
    Lint/RedundantWithObject
    Style/CommentedKeyword
    Lint/RegexpAsCondition
    Style/MixinUsage
    Style/DateTime
    Gemspec/OrderedDependencies
  ],
  Gem::Version.new('0.50.0') => %w[
    Style/RedundantConditional
    Naming/HeredocDelimiterNaming
    Lint/ReturnInVoidContext
    Lint/BooleanSymbol
    Rails/HasManyOrHasOneDependent
    Style/Dir
    Naming/HeredocDelimiterCase
    Lint/RescueWithoutErrorClass
    Performance/UnfreezeString
    Style/OrAssignment
    Style/ReturnNil
    Lint/UriEscapeUnescape
    Performance/UriDefaultParser
    Lint/UriRegexp
    Style/MinMax
    Bundler/InsecureProtocolSource
    Lint/RedundantWithIndex
    Lint/InterpolationCheck
  ],
  Gem::Version.new('0.49.0') => %w[
    Rails/ApplicationJob
    Rails/ApplicationRecord
    Performance/Caller
    Style/FormatStringToken
    Lint/ScriptPermission
    Style/YodaCondition
    Style/MultipleComparison
    Lint/RescueType
  ],
  Gem::Version.new('0.48.0') => %w[
    Performance/DoubleStartEndWith
    Style/EmptyLineAfterMagicComment
    Style/MixinGrouping
    Style/EmptyLinesAroundBeginBody
    Style/EmptyLinesAroundExceptionHandlingKeywords
    Rails/RelativeDateConstant
    Style/IndentHeredoc
    Style/InverseMethods
    Rails/ActiveSupportAliases
    Lint/AmbiguousBlockAssociation
    Rails/Blank
    Rails/Present
  ],
  Gem::Version.new('0.47.0') => %w[
    Lint/MultipleCompare
    Lint/SafeNavigationChain
    Security/MarshalLoad
    Security/YAMLLoad
    Performance/RegexpMatch
    Rails/FilePath
    Rails/SkipsModelValidations
    Style/MethodCallWithArgsParentheses
    Rails/ReversibleMigration
  ],
  Gem::Version.new('0.46.0') => %w[
    Bundler/DuplicatedGem
    Style/EmptyMethod
    Rails/EnumUniqueness
    Bundler/OrderedGems
  ],
  Gem::Version.new('0.45.0') => %w[
    Lint/DuplicateCaseCondition
    Lint/EmptyWhen
    Style/MultilineIfModifier
    Style/SpaceInLambdaLiteral
    Lint/EmptyExpression
  ],
  Gem::Version.new('0.44.0') => %w[
    Rails/HttpPositionalArguments
    Metrics/BlockLength
    Rails/DynamicFindBy
    Rails/DelegateAllowBlank
    Style/MultilineMemoization
  ],
  Gem::Version.new('0.43.0') => %w[
    Style/DocumentationMethod
    Rails/SafeNavigation
    Rails/NotNullColumn
    Style/VariableNumber
    Security/JSONLoad
    Style/SafeNavigation
    Performance/SortWithBlock
    Lint/UnifiedInteger
  ],
  Gem::Version.new('0.42.0') => %w[
    Style/TernaryParentheses
    Style/MethodMissing
    Rails/SaveBang
    Style/NumericPredicate
  ],
  Gem::Version.new('0.41.0') => %w[
    Style/SpaceInsidePercentLiteralDelimiters
    Style/SpaceInsideArrayPercentLiteral
    Style/NumericLiteralPrefix
    Style/ImplicitRuntimeError
    Style/EachForSimpleLoop
    Lint/ShadowedException
    Lint/PercentSymbolArray
    Lint/PercentStringArray
    Lint/InheritException
    Performance/PushSplat
    Rails/RequestReferer
    Rails/OutputSafety
    Rails/Exit
  ],
}.freeze

Class Method Summary collapse

Class Method Details

.added_cops(from:, to:) ⇒ Object



157
158
159
160
161
162
# File 'lib/mry/added_cops.rb', line 157

def added_cops(from:, to:)
  range = from..to
  Cops
    .flat_map {|key, cops|  range.cover?(key) && from != key ? cops : [] }
    .map {|cop| update_name(cop: cop, to: to) }
end

.added_cops_yaml(from:, to:) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/mry/added_cops.rb', line 140

def added_cops_yaml(from:, to:)
  begin
    gem 'rubocop', "= #{to}"
    require 'rubocop'
  rescue Gem::MissingSpecVersionError, Gem::LoadError
    raise RuboCopVersionMismatchError.new(expected: to)
  end
  cops = added_cops(from: from, to: to)
  return if cops.empty?

  in_tmpdir do
    stdout do
      RuboCop::CLI.new.run(['--show-cops', cops.join(',')])
    end
  end
end