Skip to content

Commit

Permalink
#800 new rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
davvd committed Nov 30, 2023
1 parent 497b352 commit b8c00cb
Show file tree
Hide file tree
Showing 92 changed files with 327 additions and 327 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/rake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ on:
branches:
- master
jobs:
test:
rake:
strategy:
matrix:
os: [ubuntu-20.04, macos-12]
ruby: ['3.0']
os: [ubuntu-22.04, macos-12]
ruby: [3.2]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
Expand Down
12 changes: 7 additions & 5 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ AllCops:
- 'assets/**/*'
DisplayCopNames: true
TargetRubyVersion: 2.5
NewCops: enable
SuggestExtensions: false

Lint/ToJSON:
Enabled: false
Layout/AlignArguments:
Layout/ArgumentAlignment:
Enabled: false
Style/ClassAndModuleChildren:
Enabled: false
Layout/EmptyLineAfterGuardClause:
Enabled: false
Metrics/CyclomaticComplexity:
Max: 33
Max: 45
Metrics/MethodLength:
Enabled: false
Layout/MultilineMethodCallIndentation:
Expand All @@ -31,15 +33,15 @@ Layout/EndOfLine:
EnforcedStyle: lf
Metrics/ParameterLists:
Max: 10
Layout/AlignParameters:
Layout/ParameterAlignment:
Enabled: false
Metrics/PerceivedComplexity:
Max: 36
Max: 45
Metrics/LineLength:
Max: 120
Style/MultilineBlockChain:
Enabled: false
Layout/MultilineOperationIndentation:
Enabled: false
Naming/UncommunicativeMethodParamName:
Naming/MethodParameterName:
MinNameLength: 1
32 changes: 14 additions & 18 deletions .simplecov
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: utf-8
# frozen_string_literal: true

#
# Copyright (c) 2018-2023 Zerocracy
#
Expand All @@ -20,21 +21,16 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

if Gem.win_platform? then
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
SimpleCov::Formatter::HTMLFormatter
]
SimpleCov.start do
add_filter "/test/"
add_filter "/features/"
end
else
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
[SimpleCov::Formatter::HTMLFormatter]
)
SimpleCov.start do
add_filter "/test/"
add_filter "/features/"
# minimum_coverage 30
end
SimpleCov.formatter = if Gem.win_platform?
SimpleCov::Formatter::MultiFormatter[
SimpleCov::Formatter::HTMLFormatter
]
else
SimpleCov::Formatter::MultiFormatter.new(
[SimpleCov::Formatter::HTMLFormatter]
)
end
SimpleCov.start do
add_filter '/test/'
add_filter '/features/'
end
26 changes: 13 additions & 13 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true
# frozen_string_literal: true

# Copyright (c) 2018-2023 Zerocracy
#
Expand All @@ -23,19 +23,19 @@
source 'https://rubygems.org'
gemspec

gem 'cucumber', '3.1.2', require: false
gem 'guard', '2.15.0', require: false
gem 'cucumber', '9.1.0', require: false
gem 'guard', '2.18.1', require: false
gem 'guard-minitest', '2.4.6', require: false
gem 'minitest', '5.11.3', require: false
gem 'minitest', '5.20.0', require: false
gem 'minitest-fail-fast', '0.1.0', require: false
gem 'minitest-hooks', '1.5.0', require: false
gem 'minitest-reporters', '1.3.6', require: false
gem 'rake', '12.3.2', require: false
gem 'random-port', '0.3.1', require: false
gem 'rdoc', '6.1.1', require: false
gem 'rspec-rails', '3.8.2', require: false
gem 'rubocop', '0.69.0', require: false
gem 'rubocop-rspec', '1.33.0', require: false
gem 'minitest-hooks', '1.5.1', require: false
gem 'minitest-reporters', '1.6.1', require: false
gem 'rake', '13.1.0', require: false
gem 'random-port', '0.6.0', require: false
gem 'rdoc', '6.6.0', require: false
gem 'rspec-rails', '6.1.0', require: false
gem 'rubocop', '1.57.2', require: false
gem 'rubocop-rspec', '2.25.0', require: false
gem 'simplecov', '0.22.0', require: false
gem 'webmock', '3.5.1', require: false
gem 'webmock', '3.19.1', require: false
gem 'xcop', '>=0.6', require: false
2 changes: 1 addition & 1 deletion Guardfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Guardfile for Zold
guard :minitest, all_after_pass: false, all_on_start: false do
# with Minitest::Unit
watch(%r{^test/(.*)\/?test_(.*)\.rb$})
watch(%r{^test/(.*)/?test_(.*)\.rb$})
watch(%r{^lib/zold/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
watch(%r{^test/test_helper\.rb$}) { 'test' }
end
8 changes: 4 additions & 4 deletions features/step_definitions/steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
@dir = Dir.mktmpdir('test')
FileUtils.copy('fixtures/id_rsa', @dir)
FileUtils.copy('fixtures/id_rsa.pub', @dir)
FileUtils.mkdir_p(@dir) unless File.exist?(@dir)
FileUtils.mkdir_p(@dir)
Dir.chdir(@dir)
end

After do
Dir.chdir(@cwd)
FileUtils.rm_rf(@dir) if File.exist?(@dir)
FileUtils.rm_rf(@dir)
end

When(%r{^I run ([a-z/-]+) with "([^"]*)"$}) do |cmd, args|
Expand All @@ -47,15 +47,15 @@

When(/^I run bash with:$/) do |text|
FileUtils.copy_entry(@cwd, File.join(@dir, 'zold'))
IO.write('run.sh', text)
File.write('run.sh', text)
@stdout = `/bin/bash run.sh 2>&1`
@exitstatus = $CHILD_STATUS.exitstatus
end

When(/^I have "([^"]*)" file with content:$/) do |file, text|
FileUtils.mkdir_p(File.dirname(file)) unless File.exist?(file)
File.open(file, 'w:ASCII-8BIT') do |f|
f.write(text.gsub(/\\xFF/, 0xFF.chr))
f.write(text.gsub('\\xFF', 0xFF.chr))
end
end

Expand Down
2 changes: 1 addition & 1 deletion fixtures/merge/legacy_negatives_stay/assert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

require_relative 'asserts.rb'
require_relative 'asserts'
wallet = Zold::Wallet.new('0123456789abcdef.z')
assert_equal(Zold::Amount.new(zld: -9.0), wallet.balance)
2 changes: 1 addition & 1 deletion fixtures/merge/missed_wallets/assert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

require_relative 'asserts.rb'
require_relative 'asserts'
wallet = Zold::Wallet.new('0123456789abcdef.z')
assert_equal(Zold::Amount.new(zld: 496.0), wallet.balance)
2 changes: 1 addition & 1 deletion fixtures/merge/negatives_in_between/assert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

require_relative 'asserts.rb'
require_relative 'asserts'
wallet = Zold::Wallet.new('0123456789abcdef.z')
assert_equal(Zold::Amount.new(zld: 512.0 - 16 - 32), wallet.balance)
2 changes: 1 addition & 1 deletion fixtures/merge/random_expenses/assert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

require_relative 'asserts.rb'
require_relative 'asserts'
wallet = Zold::Wallet.new('0123456789abcdef.z')
assert_equal(Zold::Amount.new(zld: 388.0), wallet.balance)
4 changes: 2 additions & 2 deletions lib/zold/amount.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def initialize(zents: nil, zld: nil)
@zents = zents
elsif !zld.nil?
raise "Float is required, while #{zld.class} provided: #{zld}" unless zld.is_a?(Float)
@zents = (zld * 2**FRACTION).to_i
@zents = (zld * (2**FRACTION)).to_i
else
raise 'You can\'t specify both coints and zld'
end
Expand All @@ -60,7 +60,7 @@ def to_i

# Convert to ZLD and return as a float.
def to_f
@zents.to_f / 2**FRACTION
@zents.to_f / (2**FRACTION)
end

# Convert to ZLD and return as a string. If you need float, you should use <tt>to_f()</tt> later.
Expand Down
2 changes: 1 addition & 1 deletion lib/zold/commands/calculate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def calculate(opts)
)
loop do
msg = score.to_s
msg += (score.value.positive? ? ' ' + score.hash : '') unless opts['hide-hash']
msg += (score.value.positive? ? " #{score.hash}" : '') unless opts['hide-hash']
msg += " #{(Time.now - mstart).round(2)}s" unless opts['hide-time']
@log.info(msg)
break if score.value >= opts[:max].to_i
Expand Down
4 changes: 2 additions & 2 deletions lib/zold/commands/diff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ def diff(id, cps, _)
patch.join(Wallet.new(c[:path]))
end
before = @wallets.acq(id) do |wallet|
IO.read(wallet.path)
File.read(wallet.path)
end
after = ''
Tempfile.open(['', Wallet::EXT]) do |f|
patch.save(f.path, overwrite: true)
after = IO.read(f)
after = File.read(f)
end
diff = Diffy::Diff.new(before, after, context: 0).to_s(:color)
@log.info(diff)
Expand Down
4 changes: 2 additions & 2 deletions lib/zold/commands/fetch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def fetch_one(id, r, cps, opts)
if wallet.balance.negative? && !wallet.root?
raise FetchError, "The balance of #{id} is #{wallet.balance} and it's not a root wallet"
end
copy = cps.add(IO.read(f), score.host, score.port, score.value, master: r.master?)
copy = cps.add(File.read(f), score.host, score.port, score.value, master: r.master?)
@log.debug("#{r} returned #{wallet.mnemo} #{Age.new(json['mtime'])}/#{json['copies']}c \
as copy ##{copy}/#{cps.all.count} in #{Age.new(start, limit: 4)}: \
#{Rainbow(score.value).green} (#{json['version']})")
Expand Down Expand Up @@ -204,7 +204,7 @@ def existing_copy_added(id, cps, score, r, json)
cps.all.each do |c|
next unless json['digest'] == OpenSSL::Digest::SHA256.file(c[:path]).hexdigest &&
json['size'] == File.size(c[:path])
copy = cps.add(IO.read(c[:path]), score.host, score.port, score.value, master: r.master?)
copy = cps.add(File.read(c[:path]), score.host, score.port, score.value, master: r.master?)
@log.debug("No need to fetch #{id} from #{r}, it's the same content as copy ##{copy}")
return true
end
Expand Down
6 changes: 3 additions & 3 deletions lib/zold/commands/merge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def merge(id, cps, opts)
end
if modified
@log.info("#{cps.count} copies with the total score of #{score} successfully merged \
into #{@wallets.acq(id, &:mnemo)} in #{Age.new(start, limit: 0.1 + cps.count * 0.01)}")
into #{@wallets.acq(id, &:mnemo)} in #{Age.new(start, limit: 0.1 + (cps.count * 0.01))}")
else
@log.info("Nothing changed in #{id} after merge of #{cps.count} copies")
end
Expand All @@ -157,14 +157,14 @@ def merge_one(opts, patch, wallet, name, baseline: false, master: false)
@log.debug("Adding copy ##{name}#{master ? ' (master)' : ''} to the patch #{wallet.mnemo}...")
if opts['depth'].positive?
patch.join(wallet, ledger: opts['ledger'], baseline: baseline, master: master) do |txn|
trusted = IO.read(opts['trusted']).split(',')
trusted = File.read(opts['trusted']).split(',')
if trusted.include?(txn.bnf.to_s)
@log.debug("Won't PULL #{txn.bnf} since it is already trusted, among #{trusted.count} others")
elsif trusted.count > opts['trusted-max']
@log.debug("Won't PULL #{txn.bnf} since there are too many trusted wallets already: \
#{trusted.count} > #{opts['trusted-max']}")
else
IO.write(opts['trusted'], (trusted + [txn.bnf.to_s]).sort.uniq.join(','))
File.write(opts['trusted'], (trusted + [txn.bnf.to_s]).sort.uniq.join(','))
Pull.new(wallets: @wallets, remotes: @remotes, copies: @copies, log: @log).run(
['pull', txn.bnf.to_s, "--network=#{Shellwords.escape(opts['network'])}", '--quiet-if-absent'] +
["--depth=#{opts['depth'] - 1}"] +
Expand Down
4 changes: 2 additions & 2 deletions lib/zold/commands/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def run(args = [])
the node won\'t connect to the network like that; try to do "zold remote reset" first'
end
pid = nohup(opts)
IO.write(opts['save-pid'], pid) if opts['save-pid']
File.write(opts['save-pid'], pid) if opts['save-pid']
@log.debug("Process ID #{pid} saved into \"#{opts['save-pid']}\"")
@log.info(pid)
return
Expand Down Expand Up @@ -499,7 +499,7 @@ def print(data)
temp = Tempfile.new
total = copy(@file, temp)
unit = File.size(@file) / total
tail = total - @max / (2 * unit)
tail = total - (@max / (2 * unit))
copy(temp, @file, tail)
File.delete(temp)
File.open(@file, 'a') do |f|
Expand Down
2 changes: 1 addition & 1 deletion lib/zold/commands/pay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def pay(from, invoice, amount, details, opts)
the difference is #{(amount - from.balance).to_i} zents"
end
end
pem = IO.read(opts['private-key'])
pem = File.read(opts['private-key'])
unless opts['keygap'].empty?
pem = pem.sub('*' * opts['keygap'].length, opts['keygap'])
@log.debug("Keygap \"#{'*' * opts['keygap'].length}\" injected into the RSA private key")
Expand Down
2 changes: 1 addition & 1 deletion lib/zold/commands/propagate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def propagate(id, _)
end
modified.uniq!
@log.debug("Wallet #{id} propagated successfully, #{total} txns \
in #{Age.new(start, limit: 20 + total * 0.005)}, #{modified.count} wallets affected")
in #{Age.new(start, limit: 20 + (total * 0.005))}, #{modified.count} wallets affected")
modified.each do |w|
@wallets.acq(w, &:refurbish)
end
Expand Down
13 changes: 6 additions & 7 deletions lib/zold/commands/routines/audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ def initialize(opts, wallets, log: Log::NULL)

def exec(_ = 0)
sleep(60) unless @opts['routine-immediately']
@log.info(
'Audit: ' + [
"memory used: #{Zold::Size.new(GetProcessMem.new.bytes.to_i)}",
"threads total: #{Thread.list.count}",
"wallets: #{@wallets.count}"
].join('; ')
)
msg = [
"memory used: #{Zold::Size.new(GetProcessMem.new.bytes.to_i)}",
"threads total: #{Thread.list.count}",
"wallets: #{@wallets.count}"
].join('; ')
@log.info("Audit: #{msg}")
end
end
2 changes: 1 addition & 1 deletion lib/zold/commands/routines/reconcile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def exec(_ = 0)
res = r.http('/wallets').get
r.assert_code(200, res)
missing = res.body.strip.split("\n").compact
.select { |i| /^[a-f0-9]{16}$/.match?(i) }
.grep(/^[a-f0-9]{16}$/)
.reject { |i| @wallets.acq(Zold::Id.new(i), &:exists?) }
missing.each { |i| pull(i) }
if missing.empty?
Expand Down
9 changes: 4 additions & 5 deletions lib/zold/commands/show.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,10 @@ def show(wallet, _)
"Digest: #{wallet.digest}"
].join("\n")
)
@log.info(
"\n" + Copies.new(File.join(@copies, wallet.id)).all.map do |c|
"##{c[:name]}: #{c[:score]} #{Wallet.new(c[:path]).mnemo}"
end.join("\n")
)
msg = Copies.new(File.join(@copies, wallet.id)).all.map do |c|
"##{c[:name]}: #{c[:score]} #{Wallet.new(c[:path]).mnemo}"
end.join("\n")
@log.info("\n#{msg}")
balance
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/zold/commands/taxes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def pay(wallet, opts)
@log.debug("The score has already been taxed: #{best}")
next
end
pem = IO.read(opts['private-key'])
pem = File.read(opts['private-key'])
unless opts['keygap'].empty?
pem = pem.sub('*' * opts['keygap'].length, opts['keygap'])
@log.debug("Keygap \"#{'*' * opts['keygap'].length}\" injected into the RSA private key")
Expand Down
Loading

0 comments on commit b8c00cb

Please sign in to comment.