Skip to content

Commit

Permalink
fix(rubocop): Fix Style, Layout, Lint and other offenses [ci skip]
Browse files Browse the repository at this point in the history
Updated Layout/LineLength cop to Max 120 lenght and ignore everything 
inside specs/**/*

Added rules for below cops in .rubocop.yml
Lint/AmbiguousBlockAssociation
Naming/HeredocDelimiterNaming
Rails/SkipsModelValidations
Style/FormatStringToken


Fixed below mentioned cops:
- Layout/CaseIndentation
- Layout/DotPosition
- Layout/ElseAlignment
- Layout/IndentationWidth
- Layout/LineLength
- Layout/MultilineBlockLayout
- Layout/MultilineOperationIndentation
- Lint/AmbiguousBlockAssociation
- Lint/MissingCopEnableDirective
- Lint/NestedMethodDefinition
- Lint/RedundantCopDisableDirective
- Lint/RedundantRequireStatement
- Lint/UnusedBlockArgument
- Lint/UnusedMethodArgument
- Metrics/ModuleLength
- Naming/RescuedExceptionsVariableName
- Rails/Output
- Rails/Presence
- Security/Eval
- Security/Open
- Style/ClassCheck
- Style/CollectionMethods
- Style/ConditionalAssignment
- Style/EvalWithLocation
- Style/FormatStringToken
- Style/InverseMethods
- Style/MutableConstant
- Style/ParallelAssignment
- Style/RedundantBegin
- Style/RedundantCondition
- Style/RedundantInterpolation
- Style/RedundantSelf
- Style/RedundantSort
- Style/RescueStandardError
- Style/SafeNavigation
- Style/StringLiteralsInInterpolation
- Style/SymbolProc
  • Loading branch information
KapilSachdev committed Sep 6, 2020
1 parent 25f69ab commit 4bc53c5
Show file tree
Hide file tree
Showing 88 changed files with 338 additions and 384 deletions.
28 changes: 20 additions & 8 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ Layout/EmptyLineBetweenDefs:
Layout/HeredocIndentation:
Enabled: false
Layout/LineLength:
Exclude:
- spec/**/*
IgnoredPatterns:
- "^[ ]*#.+$"
- "^[ ]*describe.+$"
- "^[ ]*context.+$"
- "^[ ]*shared_context.+$"
- "^[ ]*shared_examples_for.+$"
- "^[ ]*it.+$"
- "^[ ]*'.+?' => '.+?',?$"
- "^[ ]*\".+?\" => \".+?\",?$"
- '^[ ]*#.+$'
- '^[ ]*''.+?'' => ''.+?'',?$'
- '^[ ]*".+?" => ".+?",?$'
Max: 120
Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented
Layout/ParameterAlignment:
Expand All @@ -32,6 +30,9 @@ Layout/SpaceInLambdaLiteral:
EnforcedStyle: require_space
Layout/SpaceInsideBlockBraces:
Enabled: false
Lint/AmbiguousBlockAssociation:
Exclude:
- spec/**/*
Lint/AmbiguousOperator:
Enabled: false
Lint/AmbiguousRegexpLiteral:
Expand Down Expand Up @@ -68,6 +69,10 @@ Metrics/ClassLength:
Enabled: false
Metrics/MethodLength:
Max: 30
Metrics/ModuleLength:
Enabled: true
Exclude:
- spec/**/*
Metrics/ParameterLists:
CountKeywordArgs: false
Metrics/PerceivedComplexity:
Expand All @@ -80,6 +85,8 @@ Naming/BinaryOperatorParameterName:
Enabled: false
Naming/FileName:
Enabled: false
Naming/HeredocDelimiterNaming:
Enabled: false
Naming/MemoizedInstanceVariableName:
EnforcedStyleForLeadingUnderscores: required
Naming/PredicateName:
Expand All @@ -90,6 +97,9 @@ Rails/Delegate:
Enabled: false
Rails/HttpPositionalArguments:
Enabled: false
Rails/SkipsModelValidations:
Exclude:
- spec/**/*
Rails/TimeZone:
Enabled: false
Style/Alias:
Expand Down Expand Up @@ -137,6 +147,8 @@ Style/EvenOdd:
Enabled: false
Style/FormatString:
Enabled: false
Style/FormatStringToken:
EnforcedStyle: template
Style/FrozenStringLiteralComment:
Enabled: false
Style/GlobalVars:
Expand Down
4 changes: 2 additions & 2 deletions custom_plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def best_available
end

require_relative 'spec/support/unit/load_environment'
rescue Gem::LoadError => error
raise CouldNotBootZeusError.create(underlying_error: error)
rescue Gem::LoadError => e
raise CouldNotBootZeusError.create(underlying_error: e)
end

def after_fork; end
Expand Down
13 changes: 7 additions & 6 deletions doc_config/yard/templates/default/layout/html/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ def javascripts
def diskfile
@file.attributes[:markup] ||= markup_for_file('', @file.filename)

if @file.filename == 'README.md'
contents = preprocess_index(@file.contents)
else
contents = @file.contents
end
contents = if @file.filename == 'README.md'
preprocess_index(@file.contents)
else
@file.contents
end

data = htmlify(contents, @file.attributes[:markup])
"<div id='filecontents'>" + data + '</div>'
Expand All @@ -24,7 +24,8 @@ def preprocess_index(contents)
regex = /\[ (\w+) \] \( lib \/ ([^()]+) \.rb (?:\#L\d+)? \)/x

contents.gsub(regex) do
method_name, file_path = $1, $2
method_name = $1
file_path = $2

module_name = file_path.split('/')[0..2].
map do |value|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def initialize(key)
@key = key
end

def matches?(controller)
def matches?(_controller)
filters_key?
end

Expand Down
14 changes: 7 additions & 7 deletions lib/shoulda/matchers/action_controller/permit_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,11 @@ def format_parameter_names(parameter_names)

def actual_permitted_parameter_names
@_actual_permitted_parameter_names ||= begin
if subparameter_name
options = { for: subparameter_name }
else
options = {}
end
options = if subparameter_name
{ for: subparameter_name }
else
{}
end

parameters_double_registry.permitted_parameter_names(options)
end
Expand All @@ -329,8 +329,8 @@ def ensure_action_and_verb_present!

def default_verb
case action
when :create then :post
when :update then RailsShim.verb_for_update
when :create then :post
when :update then RailsShim.verb_for_update
end
end

Expand Down
14 changes: 6 additions & 8 deletions lib/shoulda/matchers/action_controller/redirect_to_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,12 @@ def description
private

def redirects_to_url?
begin
@context.__send__(:assert_redirected_to, url)
@failure_message_when_negated = "Didn't expect to redirect to #{url}"
true
rescue Shoulda::Matchers.assertion_exception_class => error
@failure_message = error.message
false
end
@context.__send__(:assert_redirected_to, url)
@failure_message_when_negated = "Didn't expect to redirect to #{url}"
true
rescue Shoulda::Matchers.assertion_exception_class => e
@failure_message = e.message
false
end

def url
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,12 @@ def in_context(context)
private

def renders_template?
begin
@context.__send__(:assert_template, @options, @message)
@failure_message_when_negated = "Didn't expect to render #{@template}"
true
rescue Shoulda::Matchers.assertion_exception_class => error
@failure_message = error.message
false
end
@context.__send__(:assert_template, @options, @message)
@failure_message_when_negated = "Didn't expect to render #{@template}"
true
rescue Shoulda::Matchers.assertion_exception_class => e
@failure_message = e.message
false
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ def render_with_layout(expected_layout = nil)
# @private
class RenderWithLayoutMatcher
def initialize(expected_layout)
if expected_layout
@expected_layout = expected_layout.to_s
else
@expected_layout = nil
end
@expected_layout = if expected_layout
expected_layout.to_s
else
nil
end

@controller = nil
end
Expand All @@ -95,11 +95,11 @@ def failure_message_when_negated

def description
description = 'render with '
if @expected_layout.nil?
description << 'a layout'
else
description << "the #{@expected_layout.inspect} layout"
end
description << if @expected_layout.nil?
'a layout'
else
"the #{@expected_layout.inspect} layout"
end
description
end

Expand Down
8 changes: 4 additions & 4 deletions lib/shoulda/matchers/action_controller/route_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,11 @@ def route_recognized?
params,
)
true
rescue ::ActionController::RoutingError => error
@failure_message = error.message
rescue ::ActionController::RoutingError => e
@failure_message = e.message
false
rescue Shoulda::Matchers.assertion_exception_class => error
@failure_message = error.message
rescue Shoulda::Matchers.assertion_exception_class => e
@failure_message = e.message
false
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/shoulda/matchers/action_controller/route_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Matchers
module ActionController
# @private
class RouteParams
PARAMS_TO_SYMBOLIZE = %i{format}
PARAMS_TO_SYMBOLIZE = %i{format}.freeze

def initialize(args)
@args = args
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def [](key)
def to(expected_value = nil, &block)
if block
unless context_set?
message = "When specifying a value as a block, a context must be specified beforehand, e.g., #{store.name}.in_context(context).to { ... }"
message = "When specifying a value as a block, a context must be specified beforehand,
e.g., #{store.name}.in_context(context).to { ... }"
raise ArgumentError, message
end

Expand Down Expand Up @@ -81,18 +82,18 @@ def expected_value_matches?
def expectation_description
string = 'set'

if key_set?
string << " #{store.name}[#{key.inspect}]"
else
string << " any key in #{store.name}"
end
string << if key_set?
" #{store.name}[#{key.inspect}]"
else
" any key in #{store.name}"
end

if expected_value_set?
if expected_value.is_a?(Regexp)
string << " to a value matching #{expected_value.inspect}"
else
string << " to #{expected_value.inspect}"
end
string << if expected_value.is_a?(Regexp)
" to a value matching #{expected_value.inspect}"
else
" to #{expected_value.inspect}"
end
end

string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ def matches?(subject)
end
true
else
if whitelisting?
@failure_message = "Expected #{@attribute} to be accessible"
else
@failure_message = "Did not expect #{@attribute} to be protected"
end
@failure_message = if whitelisting?
"Expected #{@attribute} to be accessible"
else
"Did not expect #{@attribute} to be protected"
end
false
end
end
Expand Down Expand Up @@ -137,7 +137,7 @@ def accessible_attributes
end

def whitelisting?
authorizer.kind_of?(::ActiveModel::MassAssignmentSecurity::WhiteList)
authorizer.is_a?(::ActiveModel::MassAssignmentSecurity::WhiteList)
end

def attr_mass_assignable?
Expand Down
10 changes: 5 additions & 5 deletions lib/shoulda/matchers/active_model/allow_value_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -447,11 +447,11 @@ def failure_message_when_negated
else
message << ' produce'

if expected_message.is_a?(Regexp)
message << ' a'
else
message << ' the'
end
message << if expected_message.is_a?(Regexp)
' a'
else
' the'
end

message << ' validation error'
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ def have_secure_password
class HaveSecurePasswordMatcher
attr_reader :failure_message

CORRECT_PASSWORD = 'aBcDe12345'
INCORRECT_PASSWORD = 'password'
CORRECT_PASSWORD = 'aBcDe12345'.freeze
INCORRECT_PASSWORD = 'password'.freeze

EXPECTED_METHODS = [
:authenticate,
:password=,
:password_confirmation=,
:password_digest,
:password_digest=,
]
].freeze

MESSAGES = {
authenticated_incorrect_password: 'expected %{subject} to not authenticate an incorrect password',
did_not_authenticate_correct_password: 'expected %{subject} to authenticate the correct password',
method_not_found: 'expected %{subject} to respond to %{methods}',
}
}.freeze

def description
'have a secure password'
Expand All @@ -71,7 +71,7 @@ def matches?(subject)
attr_reader :subject

def validate
missing_methods = EXPECTED_METHODS.select {|m| !subject.respond_to?(m) }
missing_methods = EXPECTED_METHODS.reject {|m| subject.respond_to?(m) }

if missing_methods.present?
[:method_not_found, { methods: missing_methods.to_sentence }]
Expand Down
Loading

0 comments on commit 4bc53c5

Please sign in to comment.