Skip to content

Commit

Permalink
Update Rubocop and other gems + fix errors (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Kirch authored Sep 14, 2021
1 parent 3584ea9 commit 369af7f
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 49 deletions.
10 changes: 9 additions & 1 deletion ruby/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
AllCops:
TargetRubyVersion: 2.7
SuggestExtensions: false
NewCops: enable

Style/Encoding:
Enabled: false

Layout/EndOfLine:
EnforcedStyle: lf

Metrics/LineLength:
Layout/LineLength:
Max: 180

Metrics/ClassLength:
Expand All @@ -24,3 +29,6 @@ Metrics/AbcSize:

Metrics/ParameterLists:
Max: 7

Gemspec/RequiredRubyVersion:
Enabled: false
2 changes: 1 addition & 1 deletion ruby/.ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.6.5
2.7.2
59 changes: 32 additions & 27 deletions ruby/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,50 @@ GEM
remote: https://rubygems.org/
specs:
asciidoctor (2.0.11)
ast (2.4.1)
diff-lcs (1.3)
jaro_winkler (1.5.4)
parallel (1.19.1)
parser (2.7.1.3)
ast (~> 2.4.0)
ast (2.4.2)
diff-lcs (1.4.4)
parallel (1.21.0)
parser (3.0.2.0)
ast (~> 2.4.1)
rainbow (3.0.0)
rake (12.3.3)
rspec (3.8.0)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
rspec-mocks (~> 3.8.0)
rspec-core (3.8.2)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.6)
rake (13.0.6)
regexp_parser (2.1.1)
rexml (3.2.5)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
rspec-mocks (~> 3.10.0)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-mocks (3.8.2)
rspec-support (~> 3.10.0)
rspec-mocks (3.10.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.3)
rubocop (0.74.0)
jaro_winkler (~> 1.5.1)
rspec-support (~> 3.10.0)
rspec-support (3.10.2)
rubocop (1.21.0)
parallel (~> 1.10)
parser (>= 2.6)
parser (>= 3.0.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.9.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 1.7)
ruby-progressbar (1.10.1)
unicode-display_width (1.6.1)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.11.0)
parser (>= 3.0.1.1)
ruby-progressbar (1.11.0)
unicode-display_width (2.0.0)

PLATFORMS
ruby

DEPENDENCIES
asciidoctor-kroki!
rake (~> 12.3.2)
rspec (~> 3.8.0)
rubocop (~> 0.74.0)
rake (~> 13.0.6)
rspec (~> 3.10.0)
rubocop (~> 1.21)

BUNDLED WITH
2.2.17
6 changes: 3 additions & 3 deletions ruby/asciidoctor-kroki.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |s|

s.add_runtime_dependency 'asciidoctor', '~> 2.0'

s.add_development_dependency 'rake', '~> 12.3.2'
s.add_development_dependency 'rspec', '~> 3.8.0'
s.add_development_dependency 'rubocop', '~> 0.74.0'
s.add_development_dependency 'rake', '~> 13.0.6'
s.add_development_dependency 'rspec', '~> 3.10.0'
s.add_development_dependency 'rubocop', '~> 1.21'
end
29 changes: 13 additions & 16 deletions ruby/lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def process(parent, target, attrs)

begin
diagram_text = read(path)
rescue => e # rubocop:disable RescueStandardError
rescue => e # rubocop:disable Style/RescueStandardError
logger.error "Failed to read #{diagram_type} file: #{path}. #{e}."
return create_block(parent, 'paragraph', unresolved_block_macro_message(diagram_type, path), {})
end
Expand All @@ -89,7 +89,7 @@ def read_allowed?(_target)
def read(target)
if target.start_with?('http://') || target.start_with?('https://')
require 'open-uri'
URI.open(target, &:read)
::OpenURI.open_uri(target, &:read)
else
File.open(target, &:read)
end
Expand Down Expand Up @@ -135,6 +135,7 @@ class KrokiProcessor
TEXT_FORMATS = %w[txt atxt utxt].freeze

class << self
# rubocop:disable Metrics/AbcSize
def process(processor, parent, attrs, diagram_type, diagram_text, logger)
doc = parent.document
diagram_text = prepend_plantuml_config(diagram_text, diagram_type, doc, logger)
Expand Down Expand Up @@ -164,6 +165,7 @@ def process(processor, parent, attrs, diagram_type, diagram_text, logger)
block.assign_caption(caption, 'figure')
block
end
# rubocop:enable Metrics/AbcSize

private

Expand All @@ -174,7 +176,7 @@ def prepend_plantuml_config(diagram_text, diagram_type, doc, logger)
plantuml_include_path = doc.normalize_system_path(doc.attr('kroki-plantuml-include'))
if ::File.readable? plantuml_include_path
config = File.read(plantuml_include_path)
diagram_text = config + "\n" + diagram_text
diagram_text = "#{config}\n#{diagram_text}"
else
logger.warn "Unable to read plantuml-include. File not found or not readable: #{plantuml_include_path}."
end
Expand Down Expand Up @@ -258,9 +260,7 @@ class KrokiDiagram
require 'zlib'
require 'digest'

attr_reader :type
attr_reader :text
attr_reader :format
attr_reader :type, :text, :format

def initialize(type, format, text)
@text = text
Expand All @@ -280,11 +280,10 @@ def save(output_dir_path, kroki_client)
diagram_url = get_diagram_uri(kroki_client.server_url)
diagram_name = "diag-#{Digest::SHA256.hexdigest diagram_url}.#{@format}"
file_path = File.join(output_dir_path, diagram_name)
encoding = if @format == 'txt' || @format == 'atxt' || @format == 'utxt'
encoding = case @format
when 'txt', 'atxt', 'utxt'
'utf8'
elsif @format == 'svg'
'binary'
else
when 'svg', 'binary'
'binary'
end
# file is either (already) on the file system or we should read it from Kroki
Expand All @@ -303,12 +302,12 @@ def save(output_dir_path, kroki_client)
def _join_uri_segments(base, *uris)
segments = []
# remove trailing slashes
segments.push(base.gsub(%r{[/]+$}, ''))
segments.push(base.gsub(%r{/+$}, ''))
segments.concat(uris.map do |uri|
# remove leading and trailing slashes
uri.to_s
.gsub(%r{^[/]+}, '')
.gsub(%r{[/]+$}, '')
.gsub(%r{^/+}, '')
.gsub(%r{/+$}, '')
end)
segments.join('/')
end
Expand All @@ -317,9 +316,7 @@ def _join_uri_segments(base, *uris)
# Kroki client
#
class KrokiClient
attr_reader :server_url
attr_reader :method
attr_reader :max_uri_length
attr_reader :server_url, :method, :max_uri_length

SUPPORTED_HTTP_METHODS = %w[get post adaptive].freeze

Expand Down
2 changes: 2 additions & 0 deletions ruby/spec/asciidoctor_kroki_block_macro_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# rubocop:disable Lint/ConstantDefinitionInBlock
# frozen_string_literal: true

require 'rspec_helper'
Expand Down Expand Up @@ -126,3 +127,4 @@ def unresolved_block_macro_message(name, target)
end
end
end
# rubocop:enable Lint/ConstantDefinitionInBlock
2 changes: 1 addition & 1 deletion ruby/spec/asciidoctor_kroki_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
it 'should instantiate block processor without warning' do
original_stderr = $stderr
$stderr = StringIO.new
::AsciidoctorExtensions::KrokiBlockProcessor.new 'plantuml'.to_sym, {}
::AsciidoctorExtensions::KrokiBlockProcessor.new :plantuml, {}
output = $stderr.string
(expect output).to eql ''
ensure
Expand Down

0 comments on commit 369af7f

Please sign in to comment.