Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Upgrade rubocop, motivated by CVE. #338

Merged
merged 3 commits into from
Jan 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
inherit_from: .rubocop_rspec_base.yml
inherit_from:
- .rubocop_rspec_base.yml

Metrics/AbcSize:
Max: 28

Metrics/BlockLength:
Max: 86

Metrics/PerceivedComplexity:
Max: 10

Security/MarshalLoad:
Exclude:
- 'lib/rspec/support/spec/in_sub_process.rb'

Style/EvalWithLocation:
Exclude:
# eval is only used here to check syntax
- 'lib/rspec/support/ruby_features.rb'

Lint/AssignmentInCondition:
Exclude:
# The pattern makes sense here
- 'lib/rspec/support/mutex.rb'
201 changes: 189 additions & 12 deletions .rubocop_rspec_base.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# This file was generated on 2017-12-30T17:04:25-08:00 from the rspec-dev repo.
# DO NOT modify it by hand as your changes will get lost the next time it is generated.

# This file contains defaults for RSpec projects. Individual projects
# can customize by inheriting this file and overriding particular settings.

AccessModifierIndentation:
EnforcedStyle: outdent
Enabled: false

# "Use alias_method instead of alias"
# We're fine with `alias`.
Expand Down Expand Up @@ -50,9 +47,6 @@ DoubleNegation:
EachWithObject:
Enabled: false

Encoding:
EnforcedStyle: when_needed

FormatString:
EnforcedStyle: percent

Expand All @@ -73,7 +67,7 @@ MethodLength:
Max: 15

# Who cares what we call the argument for binary operator methods?
OpMethod:
BinaryOperatorParameterName:
Enabled: false

PercentLiteralDelimiters:
Expand All @@ -98,9 +92,6 @@ PredicateName:
Proc:
Enabled: false

RedundantReturn:
AllowMultipleReturnValues: true

# Exceptions should be rescued with `Support::AllExceptionsExceptOnesWeMustNotRescue`
RescueException:
Enabled: true
Expand All @@ -121,10 +112,196 @@ StringLiterals:
Style/SpecialGlobalVars:
Enabled: false

Style/TrailingComma:
Style/TrailingCommaInLiteral:
Enabled: false

Style/TrailingCommaInArguments:
Enabled: false

TrivialAccessors:
AllowDSLWriters: true
AllowPredicates: true
ExactNameMatch: true

Style/ParallelAssignment:
Enabled: false

Layout/EmptyLineBetweenDefs:
Enabled: false

Layout/FirstParameterIndentation:
Enabled: false

Naming/ConstantName:
Enabled: false

Style/ClassCheck:
Enabled: false

Style/ConditionalAssignment:
Enabled: false

Style/EmptyMethod:
Enabled: false

Style/FormatStringToken:
Enabled: false

Style/GuardClause:
Enabled: false

Style/IdenticalConditionalBranches:
Enabled: false

Style/IfUnlessModifier:
Enabled: false

Style/IfUnlessModifierOfIfUnless:
Enabled: false

Style/MethodMissing:
Enabled: false

Style/MixinUsage:
Enabled: false

Style/MultipleComparison:
Enabled: false

Style/MutableConstant:
Enabled: false

Style/NestedModifier:
Enabled: false

Style/NestedParenthesizedCalls:
Enabled: false

Style/NumericPredicate:
Enabled: false

Style/RedundantParentheses:
Enabled: false

Style/StringLiteralsInInterpolation:
Enabled: false

Style/SymbolArray:
Enabled: false

Style/SymbolProc:
Enabled: false

Style/YodaCondition:
Enabled: false

Style/ZeroLengthPredicate:
Enabled: false

Layout/ClosingParenthesisIndentation:
Enabled: false

Layout/ExtraSpacing:
Enabled: false

Layout/MultilineMethodCallBraceLayout:
Enabled: false

Layout/MultilineMethodCallIndentation:
Enabled: false

Layout/MultilineOperationIndentation:
Enabled: false

Layout/SpaceAroundBlockParameters:
Enabled: false

Layout/SpaceAroundOperators:
Enabled: false

Layout/SpaceBeforeComma:
Enabled: false

Style/BlockDelimiters:
Enabled: false

Style/EmptyCaseCondition:
Enabled: false

Style/MultilineIfModifier:
Enabled: false

Style/RescueStandardError:
Enabled: false

Style/StderrPuts:
Enabled: false

Style/TernaryParentheses:
Enabled: false

# This could likely be enabled, but it had a false positive on rspec-mocks
# (suggested change was not behaviour preserving) so I don't trust it.
Performance/HashEachMethods:
Enabled: false

Naming/HeredocDelimiterNaming:
Enabled: false

Layout/EmptyLineAfterMagicComment:
Enabled: false

Layout/IndentArray:
Enabled: false

Layout/IndentAssignment:
Enabled: false

Layout/IndentHeredoc:
Enabled: false

Layout/SpaceInsidePercentLiteralDelimiters:
Enabled: false

Style/EmptyElse:
Enabled: false

Style/IfInsideElse:
Enabled: false

Style/RedundantReturn:
Enabled: false

Style/StructInheritance:
Enabled: false

Naming/VariableNumber:
Enabled: false

Layout/SpaceInsideStringInterpolation:
Enabled: false

Style/DateTime:
Enabled: false

Style/ParenthesesAroundCondition:
Enabled: false

Layout/EmptyLinesAroundBlockBody:
Enabled: false

Lint/ImplicitStringConcatenation:
Enabled: false

Lint/NestedMethodDefinition:
Enabled: false

Style/RegexpLiteral:
Enabled: false

Style/TrailingUnderscoreVariable:
Enabled: false

Layout/EmptyLinesAroundAccessModifier:
Enabled: false

5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ if RUBY_VERSION < '2.0.0' && !!(RbConfig::CONFIG['host_os'] =~ /cygwin|mswin|min
gem 'ffi', '< 1.9.15' # allow ffi to be installed on older rubies on windows
end

if RUBY_VERSION >= '2.0' && RUBY_VERSION <= '2.1'
gem 'rubocop', "~> 0.23.0"
# No need to run rubocop on earlier versions
if RUBY_VERSION >= '2.4' && RUBY_ENGINE == 'ruby'
gem "rubocop", "~> 0.52.1"
end

eval File.read('Gemfile-custom') if File.exist?('Gemfile-custom')
8 changes: 4 additions & 4 deletions lib/rspec/support/object_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Support
# Provide additional output details beyond what `inspect` provides when
# printing Time, DateTime, or BigDecimal
# @api private
class ObjectFormatter # rubocop:disable Style/ClassLength
class ObjectFormatter # rubocop:disable Metrics/ClassLength
ELLIPSIS = "..."

attr_accessor :max_formatted_output_length
Expand All @@ -31,15 +31,15 @@ def initialize(max_formatted_output_length=200)

def format(object)
if max_formatted_output_length.nil?
return prepare_for_inspection(object).inspect
prepare_for_inspection(object).inspect
else
formatted_object = prepare_for_inspection(object).inspect
if formatted_object.length < max_formatted_output_length
return formatted_object
formatted_object
else
beginning = truncate_string formatted_object, 0, max_formatted_output_length / 2
ending = truncate_string formatted_object, -max_formatted_output_length / 2, -1
return beginning + ELLIPSIS + ending
beginning + ELLIPSIS + ending
end
end
end
Expand Down
2 changes: 0 additions & 2 deletions lib/rspec/support/ruby_features.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ def supports_rebinding_module_methods?
end
else
# RBX / JRuby et al support is unknown for keyword arguments
# rubocop:disable Lint/Eval
begin
eval("o = Object.new; def o.m(a: 1); end;"\
" raise SyntaxError unless o.method(:m).parameters.include?([:key, :a])")
Expand Down Expand Up @@ -147,7 +146,6 @@ def supports_rebinding_module_methods?
false
end
end
# rubocop:enable Lint/Eval
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does rubocop no longer support this way of disabling checks? Or do you just prefer putting the exception in the config file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does, but it was redundant here

end

def module_refinement_supported?
Expand Down
2 changes: 1 addition & 1 deletion script/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function check_documentation_coverage {

function check_style_and_lint {
echo "bin/rubocop lib"
bin/rubocop lib
eval "(unset RUBYOPT; exec bin/rubocop lib)"
}

function run_all_spec_suites {
Expand Down