diff --git a/.rubocop.yml b/.rubocop.yml index 1412e64328..7e1540bf96 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -126,12 +126,18 @@ Layout/LineContinuationSpacing: Enabled: true Layout/LineEndStringConcatenationIndentation: Enabled: true +Lint/AmbiguousOperatorPrecedence: + Enabled: true +Lint/NonAtomicFileOperation: + Enabled: true Style/EmptyHeredoc: Enabled: true Style/RedundantHeredocDelimiterQuotes: Enabled: true Style/RedundantStringEscape: Enabled: true +Style/ReturnNilInPredicateMethodDefinition: + Enabled: true # Enable our own pending cops. diff --git a/lib/rubocop/cop/rspec/described_class.rb b/lib/rubocop/cop/rspec/described_class.rb index 1e4efaac7d..70743a44c3 100644 --- a/lib/rubocop/cop/rspec/described_class.rb +++ b/lib/rubocop/cop/rspec/described_class.rb @@ -148,15 +148,15 @@ def offensive?(node) end def offensive_described_class?(node) - return unless node.const_type? + return false unless node.const_type? # E.g. `described_class::CONSTANT` - return if contains_described_class?(node) + return false if contains_described_class?(node) nearest_described_class, = node.each_ancestor(:block) .map { |ancestor| described_constant(ancestor) }.find(&:itself) - return if nearest_described_class.equal?(node) + return false if nearest_described_class.equal?(node) full_const_name(nearest_described_class) == full_const_name(node) end diff --git a/lib/rubocop/cop/rspec/empty_example_group.rb b/lib/rubocop/cop/rspec/empty_example_group.rb index 57358bb58e..44293a2c65 100644 --- a/lib/rubocop/cop/rspec/empty_example_group.rb +++ b/lib/rubocop/cop/rspec/empty_example_group.rb @@ -162,7 +162,7 @@ def offensive?(body) end def conditionals_with_examples?(body) - return unless body.begin_type? || body.case_type? + return false unless body.begin_type? || body.case_type? body.each_descendant(:if, :case).any? do |condition_node| examples_in_branches?(condition_node) @@ -170,7 +170,7 @@ def conditionals_with_examples?(body) end def examples_in_branches?(condition_node) - return if !condition_node.if_type? && !condition_node.case_type? + return false if !condition_node.if_type? && !condition_node.case_type? condition_node.branches.any? { |branch| examples?(branch) } end diff --git a/lib/rubocop/cop/rspec/empty_line_after_example.rb b/lib/rubocop/cop/rspec/empty_line_after_example.rb index caf4a5eee4..5603f14638 100644 --- a/lib/rubocop/cop/rspec/empty_line_after_example.rb +++ b/lib/rubocop/cop/rspec/empty_line_after_example.rb @@ -71,8 +71,8 @@ def consecutive_one_liner?(node) def next_one_line_example?(node) next_sibling = node.right_sibling - return unless next_sibling - return unless example?(next_sibling) + return false unless next_sibling + return false unless example?(next_sibling) next_sibling.single_line? end diff --git a/lib/rubocop/cop/rspec/pending.rb b/lib/rubocop/cop/rspec/pending.rb index bb9c230363..af47a118dc 100644 --- a/lib/rubocop/cop/rspec/pending.rb +++ b/lib/rubocop/cop/rspec/pending.rb @@ -67,7 +67,7 @@ def on_send(node) private def skipped?(node) - skippable?(node) && skipped_in_metadata?(node) || + (skippable?(node) && skipped_in_metadata?(node)) || skipped_regular_example_without_body?(node) end diff --git a/lib/rubocop/cop/rspec/predicate_matcher.rb b/lib/rubocop/cop/rspec/predicate_matcher.rb index d27ddc338f..003e9a5874 100644 --- a/lib/rubocop/cop/rspec/predicate_matcher.rb +++ b/lib/rubocop/cop/rspec/predicate_matcher.rb @@ -202,7 +202,7 @@ def predicate_matcher_name?(name) return false if allowed_explicit_matchers.include?(name) - name.start_with?('be_', 'have_') && !name.end_with?('?') || + (name.start_with?('be_', 'have_') && !name.end_with?('?')) || %w[include respond_to].include?(name) end diff --git a/lib/rubocop/cop/rspec/receive_messages.rb b/lib/rubocop/cop/rspec/receive_messages.rb index a8aacc0ebf..d476604e5f 100644 --- a/lib/rubocop/cop/rspec/receive_messages.rb +++ b/lib/rubocop/cop/rspec/receive_messages.rb @@ -148,7 +148,7 @@ def item_range_by_whole_lines(item) end def heredoc_or_splat?(node) - (node.str_type? || node.dstr_type?) && node.heredoc? || + ((node.str_type? || node.dstr_type?) && node.heredoc?) || node.splat_type? end diff --git a/lib/rubocop/cop/rspec/unspecified_exception.rb b/lib/rubocop/cop/rspec/unspecified_exception.rb index b247766aa8..c1dc01a9c6 100644 --- a/lib/rubocop/cop/rspec/unspecified_exception.rb +++ b/lib/rubocop/cop/rspec/unspecified_exception.rb @@ -57,7 +57,7 @@ def empty_exception_matcher?(node) end def block_with_args?(node) - return unless node&.block_type? + return false unless node&.block_type? node.arguments? end diff --git a/lib/rubocop/cop/rspec/variable_definition.rb b/lib/rubocop/cop/rspec/variable_definition.rb index 8012167cea..cb09b5ebdf 100644 --- a/lib/rubocop/cop/rspec/variable_definition.rb +++ b/lib/rubocop/cop/rspec/variable_definition.rb @@ -60,8 +60,8 @@ def correct_variable(variable) end def style_offense?(variable) - style == :symbols && string?(variable) || - style == :strings && symbol?(variable) + (style == :symbols && string?(variable)) || + (style == :strings && symbol?(variable)) end def string?(node) diff --git a/spec/support/file_helper.rb b/spec/support/file_helper.rb index 4ec7c8311a..976b3c38be 100644 --- a/spec/support/file_helper.rb +++ b/spec/support/file_helper.rb @@ -19,6 +19,6 @@ def create_file(file_path, content) def create_dir(file_path) dir_path = File.dirname(file_path) - FileUtils.makedirs dir_path unless File.exist?(dir_path) + FileUtils.makedirs dir_path end end