Skip to content

Commit

Permalink
Introduce and fix new cops
Browse files Browse the repository at this point in the history
  • Loading branch information
PragTob committed Aug 9, 2020
1 parent a692880 commit 4b8d017
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 21 deletions.
73 changes: 73 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,52 @@ Lint/AmbiguousRegexpLiteral:
- "spec/**/*_steps.rb"
- "tmp/**/*_steps.rb"

Lint/BinaryOperatorWithIdenticalOperands:
Enabled: true

Lint/DeprecatedOpenSSLConstant:
Description: Don't use algorithm constants for `OpenSSL::Cipher` and `OpenSSL::Digest`.
Enabled: true

Lint/DuplicateElsifCondition:
Enabled: true

Lint/DuplicateRescueException:
Enabled: true

Lint/EmptyConditionalBody:
Enabled: true

Lint/FloatComparison:
Enabled: true

Lint/MissingSuper:
Enabled: true

Lint/MixedRegexpCaptureTypes:
Description: Do not mix named captures and numbered captures in a Regexp literal.
Enabled: true

Lint/OutOfRangeRegexpRef:
Enabled: true

Lint/RaiseException:
Description: Checks for `raise` or `fail` statements which are raising `Exception` class.
Enabled: true

Lint/SelfAssignment:
Enabled: true

Lint/StructNewOverride:
Description: Disallow overriding the `Struct` built-in methods via `Struct.new`.
Enabled: true

Lint/TopLevelReturnWithArgument:
Enabled: true

Lint/UnreachableLoop:
Enabled: true

Metrics/AbcSize:
Description: Checks that the ABC size of methods is not higher than the configured maximum.
Max: 25 # TODO: Lower to 15
Expand Down Expand Up @@ -109,6 +139,18 @@ Naming/FileName:
Exclude:
- "spec/fixtures/utf-8.rb"

Style/AccessorGrouping:
Enabled: true

Style/ArrayCoercion:
Enabled: true

Style/BisectedAttrAccessor:
Enabled: true

Style/CaseLikeIf:
Enabled: true

Style/CollectionMethods:
Description: Enforces the use of consistent method names from the Enumerable module.
PreferredMethods:
Expand All @@ -126,6 +168,10 @@ Style/DoubleNegation:
StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#no-bang-bang
Enabled: false

Style/ExplicitBlockArgument:
# capturing as a proc has a performance hit, so is a case by case choice
Enabled: false

Style/ExponentialNotation:
Description: When using exponential notation, favor a mantissa between 1 (inclusive) and 10 (exclusive).
Enabled: true
Expand All @@ -139,14 +185,23 @@ Style/FrozenStringLiteralComment:
Exclude:
- "spec/fixtures/**/*"

Style/GlobalStdStream:
Enabled: true

Style/GuardClause:
Description: Use a guard clause instead of wrapping the code inside a conditional expression.
Enabled: false

Style/HashAsLastArrayItem:
Enabled: true

Style/HashEachMethods:
Description: Use Hash#each_key and Hash#each_value.
Enabled: true

Style/HashLikeCase:
Enabled: true

Style/HashTransformKeys:
Description: Prefer `transform_keys` over `each_with_object` and `map`.
Enabled: true
Expand All @@ -159,6 +214,18 @@ Style/HashSyntax:
Description: Checks hash literal syntax.
EnforcedStyle: ruby19

Style/OptionalBooleanParameter:
Enabled: true

Style/RedundantAssignment:
Enabled: true

Style/RedundantFetchBlock:
Enabled: true

Style/RedundantFileExtensionInRequire:
Enabled: true

Style/RedundantRegexpCharacterClass:
Description: Checks for unnecessary single-element Regexp character classes.
Enabled: true
Expand All @@ -172,6 +239,9 @@ Style/RegexpLiteral:
StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#percent-r
Enabled: false

Style/SingleArgumentDig:
Enabled: true

Style/SlicingWithRange:
Description: Checks array slicing is done with endless ranges when suitable.
Enabled: true
Expand All @@ -183,6 +253,9 @@ Style/SpecialGlobalVars:
- "spec/return_codes_spec.rb"
- "lib/simplecov/defaults.rb"

Style/StringConcatenation:
Enabled: true

Style/StringLiterals:
Description: Allow double-quoted strings without interpolation.
EnforcedStyle: double_quotes
Expand Down
3 changes: 1 addition & 2 deletions lib/simplecov.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
#
module SimpleCov
class << self
attr_accessor :running
attr_accessor :pid
attr_accessor :running, :pid
attr_reader :exit_exception

# Basically, should we take care of at_exit behavior or something else?
Expand Down
9 changes: 5 additions & 4 deletions lib/simplecov/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ def self.build_filter(filter_argument)
end

def self.class_for_argument(filter_argument)
if filter_argument.is_a?(String)
case filter_argument
when String
SimpleCov::StringFilter
elsif filter_argument.is_a?(Regexp)
when Regexp
SimpleCov::RegexFilter
elsif filter_argument.is_a?(Array)
when Array
SimpleCov::ArrayFilter
elsif filter_argument.is_a?(Proc)
when Proc
SimpleCov::BlockFilter
else
raise ArgumentError, "You have provided an unrecognized filter type"
Expand Down
2 changes: 1 addition & 1 deletion lib/simplecov/formatter/multi_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def self.new(formatters = nil)

def self.[](*args)
warn "#{Kernel.caller.first}: [DEPRECATION] ::[] is deprecated. Use ::new instead."
new(Array([*args]))
new(Array(args))
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/filters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ def a_file(path)
end

it "filters even if the sibling directory has SimpleCov.root as a prefix" do
sibling_dir = SimpleCov.root + "_cache"
expect(SimpleCov.filtered([a_file(sibling_dir + "/foo.rb")]).count).to eq(0)
sibling_dir = "#{SimpleCov.root}_cache"
expect(SimpleCov.filtered([a_file("#{sibling_dir}/foo.rb")]).count).to eq(0)
end
end
end
Expand Down
26 changes: 15 additions & 11 deletions spec/result_merger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,22 +135,26 @@
it "blocks other processes" do
file = Tempfile.new("foo")

other_process = open("|ruby -e " + Shellwords.escape(<<-CODE) + " 2>/dev/null") # rubocop:disable Security/Open
require "simplecov"
SimpleCov.coverage_dir(#{SimpleCov.coverage_dir.inspect})
test_script = <<-CODE
require "simplecov"
SimpleCov.coverage_dir(#{SimpleCov.coverage_dir.inspect})
# ensure the parent process has enough time to get a
# lock before we do
sleep 0.5
# ensure the parent process has enough time to get a
# lock before we do
sleep 0.5
$stdout.sync = true
puts "running" # see `sleep`s in parent process
$stdout.sync = true
puts "running" # see `sleep`s in parent process
SimpleCov::ResultMerger.synchronize_resultset do
File.open(#{file.path.inspect}, "a") { |f| f.write("process 2\n") }
end
SimpleCov::ResultMerger.synchronize_resultset do
File.open(#{file.path.inspect}, "a") { |f| f.write("process 2\n") }
end
CODE

# rubocop:disable Security/Open
other_process = open("|ruby -e #{Shellwords.escape(test_script)} 2>/dev/null")
# rubocop:enable Security/Open

SimpleCov::ResultMerger.synchronize_resultset do
# wait until the child process is going, and then wait some more
# so we can be sure it blocks on the lock we already have.
Expand Down
2 changes: 1 addition & 1 deletion spec/return_codes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
end

context "when print_error_status is disabled" do
let(:command) { "PRINT_ERROR_STATUS=false " + super() }
let(:command) { "PRINT_ERROR_STATUS=false #{super()}" }

it "has a non-zero exit status" do
expect(@status.exitstatus).not_to be_zero
Expand Down

0 comments on commit 4b8d017

Please sign in to comment.