Skip to content

Commit

Permalink
Merge pull request #504 from ydah/organize-standard
Browse files Browse the repository at this point in the history
Organize standardrb setting and bump standard from 0.2.5 to 1.34.0
  • Loading branch information
danmayer committed Feb 17, 2024
2 parents 031608f + 2cc622a commit 3136085
Show file tree
Hide file tree
Showing 31 changed files with 97 additions and 114 deletions.
2 changes: 1 addition & 1 deletion .standard.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ruby_version: 2.3
ruby_version: 2.7
fix: false # default: false
parallel: true # default: false
format: progress # default: Standard::Formatter
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RuboCop::RakeTask.new

task default: %i[test]

task 'test:all': %i[rubocop test forked_tests benchmarks:memory benchmarks]
task "test:all": %i[rubocop test forked_tests benchmarks:memory benchmarks]

task :test
require "rake/testtask"
Expand Down
3 changes: 1 addition & 2 deletions coverband.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Gem::Specification.new do |spec|

spec.files = `git ls-files`.split("\n").reject { |f| f.start_with?("docs") }
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = %w[lib]

spec.required_ruby_version = ">= 2.3"
Expand All @@ -44,7 +43,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rack-test"
spec.add_development_dependency "rake"
spec.add_development_dependency "resque"
spec.add_development_dependency "standard", "= 0.2.5"
spec.add_development_dependency "standard", "~> 1.34.0"
spec.add_development_dependency "standardrb"

spec.add_development_dependency "coveralls"
Expand Down
6 changes: 3 additions & 3 deletions lib/coverband.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ def self.start
end

def self.tasks_to_ignore?
(defined?(Rake) &&
Rake.respond_to?(:application) &&
(Rake&.application&.top_level_tasks || []).any? { |task| Coverband::Configuration::IGNORE_TASKS.include?(task) })
defined?(Rake) &&
Rake.respond_to?(:application) &&
(Rake&.application&.top_level_tasks || []).any? { |task| Coverband::Configuration::IGNORE_TASKS.include?(task) }
end

def self.eager_loading_coverage!
Expand Down
8 changes: 4 additions & 4 deletions lib/coverband/adapters/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def file_hash(file)
def expand_report(report)
expanded = {}
report_time = Time.now.to_i
updated_time = type == Coverband::EAGER_TYPE ? nil : report_time
updated_time = (type == Coverband::EAGER_TYPE) ? nil : report_time
report.each_pair do |key, line_data|
extended_data = {
FIRST_UPDATED_KEY => report_time,
Expand Down Expand Up @@ -145,11 +145,11 @@ def merge_expanded_data(new_expanded, old_expanded)
# TODO: This should only be 2 cases get our dup / not dups aligned
def array_add(latest, original)
if Coverband.configuration.use_oneshot_lines_coverage
latest.map!.with_index { |v, i| (v + original[i] >= 1 ? 1 : 0) if v && original[i] }
latest.map!.with_index { |v, i| ((v + original[i] >= 1) ? 1 : 0) if v && original[i] }
elsif Coverband.configuration.simulate_oneshot_lines_coverage
latest.map.with_index { |v, i| (v + original[i] >= 1 ? 1 : 0) if v && original[i] }
latest.map.with_index { |v, i| ((v + original[i] >= 1) ? 1 : 0) if v && original[i] }
else
latest.map.with_index { |v, i| v && original[i] ? v + original[i] : nil }
latest.map.with_index { |v, i| (v && original[i]) ? v + original[i] : nil }
end
end
end
Expand Down
16 changes: 7 additions & 9 deletions lib/coverband/adapters/hash_redis_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@ def fetch(local_type)
else
if lock!(local_type)
Thread.new do
begin
result = yield(deferred_time)
set(local_type, JSON.generate(result))
ensure
unlock!(local_type)
end
result = yield(deferred_time)
set(local_type, JSON.generate(result))
ensure
unlock!(local_type)
end
end
JSON.parse(cached_result)
Expand Down Expand Up @@ -147,7 +145,7 @@ def clear_file!(file)

def save_report(report)
report_time = Time.now.to_i
updated_time = type == Coverband::EAGER_TYPE ? nil : report_time
updated_time = (type == Coverband::EAGER_TYPE) ? nil : report_time
keys = []
report.each_slice(@save_report_batch_size) do |slice|
files_data = slice.map { |(file, data)|
Expand Down Expand Up @@ -215,15 +213,15 @@ def add_coverage_for_file(data_from_redis, hash)

data = coverage_data_from_redis(data_from_redis)
hash[file] = data_from_redis.select { |meta_data_key, _value| META_DATA_KEYS.include?(meta_data_key) }.merge!("data" => data)
hash[file][LAST_UPDATED_KEY] = hash[file][LAST_UPDATED_KEY].nil? || hash[file][LAST_UPDATED_KEY] == "" ? nil : hash[file][LAST_UPDATED_KEY].to_i
hash[file][LAST_UPDATED_KEY] = (hash[file][LAST_UPDATED_KEY].nil? || hash[file][LAST_UPDATED_KEY] == "") ? nil : hash[file][LAST_UPDATED_KEY].to_i
hash[file].merge!(LAST_UPDATED_KEY => hash[file][LAST_UPDATED_KEY], FIRST_UPDATED_KEY => hash[file][FIRST_UPDATED_KEY].to_i)
end

def coverage_data_from_redis(data_from_redis)
max = data_from_redis[FILE_LENGTH_KEY].to_i - 1
Array.new(max + 1) do |index|
line_coverage = data_from_redis[index.to_s]
line_coverage.nil? ? nil : line_coverage.to_i
line_coverage&.to_i
end
end

Expand Down
10 changes: 4 additions & 6 deletions lib/coverband/adapters/web_service_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,10 @@ def raw_store
def retry_failed_reports
retries = []
@failed_coverage_reports.any? do
begin
report_body = @failed_coverage_reports.pop
send_report_body(report_body)
rescue
retries << report_body
end
report_body = @failed_coverage_reports.pop
send_report_body(report_body)
rescue
retries << report_body
end
retries.each do |report_body|
add_retry_message(report_body)
Expand Down
2 changes: 1 addition & 1 deletion lib/coverband/collectors/translation_tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def flatten_hash(hash)
hash.each_with_object({}) do |(k, v), h|
if v.is_a? Hash
flatten_hash(v).map do |h_k, h_v|
h["#{k}.#{h_k}".to_sym] = h_v
h[:"#{k}.#{h_k}"] = h_v
end
else
h[k] = v
Expand Down
2 changes: 1 addition & 1 deletion lib/coverband/collectors/view_tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def all_keys
end

def unused_keys(used_views = nil)
recently_used_views = (used_keys || used_keys).keys
recently_used_views = used_keys.keys
unused_views = all_keys - recently_used_views
# since layouts don't include format we count them used if they match with ANY formats
unused_views.reject { |view| view.match(/\/layouts\//) && recently_used_views.any? { |used_view| view.include?(used_view) } }
Expand Down
8 changes: 4 additions & 4 deletions lib/coverband/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def password
def background_reporting_sleep_seconds
@background_reporting_sleep_seconds ||= if service?
# default to 10m for service
Coverband.configuration.coverband_env == "production" ? 600 : 60
(Coverband.configuration.coverband_env == "production") ? 600 : 60
elsif store.is_a?(Coverband::Adapters::HashRedisStore)
# Default to 5 minutes if using the hash redis store
300
Expand All @@ -180,7 +180,7 @@ def store
def store=(store)
raise "Pass in an instance of Coverband::Adapters" unless store.is_a?(Coverband::Adapters::Base)
raise "invalid configuration: only coverband service expects an API Key" if api_key && store.class.to_s != "Coverband::Adapters::WebServiceStore"
raise "invalid configuration: coverband service shouldn't have redis url set" if ENV["COVERBAND_REDIS_URL"] && store.class.to_s == "Coverband::Adapters::WebServiceStore"
raise "invalid configuration: coverband service shouldn't have redis url set" if ENV["COVERBAND_REDIS_URL"] && store.instance_of?(::Coverband::Adapters::WebServiceStore)

@store = store
end
Expand Down Expand Up @@ -262,11 +262,11 @@ def service_url
end

def coverband_env
ENV["RACK_ENV"] || ENV["RAILS_ENV"] || (defined?(Rails) && Rails.respond_to?(:env) ? Rails.env : "unknown")
ENV["RACK_ENV"] || ENV["RAILS_ENV"] || ((defined?(Rails) && Rails.respond_to?(:env)) ? Rails.env : "unknown")
end

def coverband_timeout
@coverband_timeout ||= coverband_env == "development" ? 5 : 2
@coverband_timeout ||= (coverband_env == "development") ? 5 : 2
end

def service_dev_mode
Expand Down
4 changes: 1 addition & 3 deletions lib/coverband/integrations/rack_server_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ def rack_server?

def rails_server?
@stack.any? do |location|
(
location.path.include?("rails/commands/commands_tasks.rb") && location.label == "server" ||
location.path.include?("rails/commands/commands_tasks.rb") && location.label == "server" ||
location.path.include?("rails/commands/server/server_command.rb") && location.label == "perform"
)
end
end
end
Expand Down
5 changes: 2 additions & 3 deletions lib/coverband/reporters/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ class << self

def report(store, _options = {})
all_roots = Coverband.configuration.all_root_paths
scov_style_report = get_current_scov_data_imp(store, all_roots)
get_current_scov_data_imp(store, all_roots)

# These are extremelhy verbose but useful during coverband development, not generally for users
# Only available by uncommenting this mode is never released
# if Coverband.configuration.verbose
# # msg = "report:\n #{scov_style_report.inspect}"
# # Coverband.configuration.logger.debug msg
# end
scov_style_report
end

###
Expand Down Expand Up @@ -71,7 +70,7 @@ def fix_file_names(report_hash, roots)
# > [nil,0,0,1,0,1]
def merge_arrays(first, second)
merged = []
longest = first.length > second.length ? first : second
longest = (first.length > second.length) ? first : second

longest.each_with_index do |_line, index|
merged[index] = if first[index] || second[index]
Expand Down
4 changes: 2 additions & 2 deletions lib/coverband/reporters/web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def call(env)

return [401, {"www-authenticate" => 'Basic realm=""'}, [""]] unless check_auth

request_path_info = request.path_info == "" ? "/" : request.path_info
request_path_info = (request.path_info == "") ? "/" : request.path_info
tracker_route = false
Coverband.configuration.trackers.each do |tracker|
if request_path_info.match(tracker.class::REPORT_ROUTE)
Expand Down Expand Up @@ -219,7 +219,7 @@ def coverband_headers(content_type: "text/html")
# %r{\/.*\/}.match?(request.path) ? request.path.match("\/.*\/")[0] : "/"
# ^^ the above is NOT valid Ruby 2.3/2.4 even though rubocop / standard think it is
def base_path
request.path =~ %r{\/.*\/} ? request.path.match("/.*/")[0] : "/"
(request.path =~ %r{\/.*\/}) ? request.path.match("/.*/")[0] : "/"
end
end
end
Expand Down
38 changes: 19 additions & 19 deletions lib/coverband/utils/absolute_file_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,25 @@ def self.convert(relative_path)

def convert(relative_path)
@cache[relative_path] ||= begin
relative_filename = relative_path
local_filename = relative_filename
@roots.each do |root|
relative_filename = relative_filename.sub(/^#{root}/, "./")
# once we have a relative path break out of the loop
break if relative_filename.start_with? "./"
end
# the filename for our reports is expected to be a full path.
# roots.last should be roots << current_root}/
# a fully expanded path of config.root
# filename = filename.gsub('./', roots.last)
# above only works for app files
# we need to rethink some of this logic
# gems aren't at project root and can have multiple locations
local_root = @roots.find { |root|
File.exist?(relative_filename.gsub("./", root))
}
local_root ? relative_filename.gsub("./", local_root) : local_filename
end
relative_filename = relative_path
local_filename = relative_filename
@roots.each do |root|
relative_filename = relative_filename.sub(/^#{root}/, "./")
# once we have a relative path break out of the loop
break if relative_filename.start_with? "./"
end
# the filename for our reports is expected to be a full path.
# roots.last should be roots << current_root}/
# a fully expanded path of config.root
# filename = filename.gsub('./', roots.last)
# above only works for app files
# we need to rethink some of this logic
# gems aren't at project root and can have multiple locations
local_root = @roots.find { |root|
File.exist?(relative_filename.gsub("./", root))
}
local_root ? relative_filename.gsub("./", local_root) : local_filename
end
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/coverband/utils/file_hasher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ class FileHasher

def self.hash_file(file, path_converter: AbsoluteFileConverter.instance)
@cache[file] ||= begin
file = path_converter.convert(file)
Digest::MD5.file(file).hexdigest if File.exist?(file)
end
file = path_converter.convert(file)
Digest::MD5.file(file).hexdigest if File.exist?(file)
end
end
end
end
Expand Down
5 changes: 2 additions & 3 deletions lib/coverband/utils/html_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,10 @@ def formatted_source_file_loader(result, source_file)
# Returns a table containing the given source files
def formatted_file_list(title, result, source_files, options = {})
title_id = title.gsub(/^[^a-zA-Z]+/, "").gsub(/[^a-zA-Z0-9\-\_]/, "")
# Silence a warning by using the following variable to assign to itself:
# Silence a warning by using the following variable to assign to `_`:
# "warning: possibly useless use of a variable in void context"
# The variable is used by ERB via binding.
title_id = title_id
options = options
_ = title_id, options

template("file_list").result(binding)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/coverband/utils/method_definition_scanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def body
def scan_node(node, class_name)
definitions = []
return definitions unless node.is_a?(RubyVM::AbstractSyntaxTree::Node)
current_class = node.type == :CLASS ? node.children.first.children.last : class_name
current_class = (node.type == :CLASS) ? node.children.first.children.last : class_name
if node.type == :DEFN
definitions <<
MethodDefinition.new(
Expand Down
10 changes: 4 additions & 6 deletions lib/coverband/utils/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ def eager_load!

class Railtie < Rails::Railtie
initializer "coverband.configure" do |app|
begin
app.middleware.use Coverband::BackgroundMiddleware
rescue Redis::CannotConnectError => error
Coverband.configuration.logger.info "Redis is not available (#{error}), Coverband not configured"
Coverband.configuration.logger.info "If this is a setup task like assets:precompile feel free to ignore"
end
app.middleware.use Coverband::BackgroundMiddleware
rescue Redis::CannotConnectError => error
Coverband.configuration.logger.info "Redis is not available (#{error}), Coverband not configured"
Coverband.configuration.logger.info "If this is a setup task like assets:precompile feel free to ignore"
end

config.after_initialize do
Expand Down
14 changes: 7 additions & 7 deletions lib/coverband/utils/relative_file_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ def initialize(roots)

def convert(file)
@cache[file] ||= begin
relative_file = file
@roots.each do |root|
relative_file = file.gsub(/^#{root}/, ".")
break relative_file if relative_file.start_with?(".")
end
relative_file
end
relative_file = file
@roots.each do |root|
relative_file = file.gsub(/^#{root}/, ".")
break relative_file if relative_file.start_with?(".")
end
relative_file
end
end

private
Expand Down
6 changes: 1 addition & 5 deletions lib/coverband/utils/results.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@ def method_missing(method, *args)
end

def respond_to_missing?(method)
if get_results(type).respond_to?(method)
true
else
false
end
get_results(type).respond_to?(method)
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/coverband/utils/source_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def status
return "skipped" if skipped?
return "never" if never?
return "missed" if missed?
return "covered" if covered?
"covered" if covered?
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/coverband/utils/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
Coverband.configuration.store.merge_mode = true
end
Rack::Server.start app: Coverband::Reporters::Web.new,
Port: ENV.fetch("COVERBAND_COVERAGE_PORT", 9022).to_i
Port: ENV.fetch("COVERBAND_COVERAGE_PORT", 9022).to_i
end

###
Expand Down
Loading

0 comments on commit 3136085

Please sign in to comment.