From 3af946467a518919f28773e41a8e5d22d74e2a85 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Fri, 18 Oct 2024 23:06:14 +0400 Subject: [PATCH] Fix RuboCop offenses --- .rubocop.yml | 6 ++ .rubocop_todo.yml | 71 ++--------------------- Rakefile | 4 +- lib/repubmark/elems/annotation.rb | 2 +- lib/repubmark/elems/article.rb | 2 +- lib/repubmark/elems/blockquote.rb | 2 +- lib/repubmark/elems/canvas.rb | 10 ++-- lib/repubmark/elems/caption.rb | 2 +- lib/repubmark/elems/figures.rb | 2 +- lib/repubmark/elems/footnote.rb | 12 ++-- lib/repubmark/elems/footnotes_category.rb | 8 +-- lib/repubmark/elems/joint.rb | 4 +- lib/repubmark/elems/link.rb | 4 +- lib/repubmark/elems/paragraph.rb | 2 +- 14 files changed, 37 insertions(+), 94 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 2639587..c7c5fae 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -21,6 +21,9 @@ Lint/AmbiguousOperatorPrecedence: Lint/ReturnInVoidContext: Enabled: false +Metrics/ClassLength: + Max: 200 + Style/AndOr: EnforcedStyle: conditionals @@ -33,6 +36,9 @@ Style/HashAsLastArrayItem: Style/PerlBackrefs: Enabled: false +Style/SuperWithArgsParentheses: + Enabled: false + Style/TrailingCommaInArguments: EnforcedStyleForMultiline: comma diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 47477d5..986620e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2024-10-18 14:41:13 UTC using RuboCop version 1.67.0. +# on 2024-10-18 19:44:25 UTC using RuboCop version 1.67.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -22,23 +22,10 @@ Layout/LineLength: Exclude: - 'lib/repubmark/elems/footnote.rb' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowedMethods. -# AllowedMethods: present?, blank?, presence, try, try!, in? -Lint/SafeNavigationChain: - Exclude: - - 'lib/repubmark/elems/article.rb' - -# Offense count: 1 +# Offense count: 2 # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. Metrics/AbcSize: - Max: 35 - -# Offense count: 1 -# Configuration parameters: CountComments, CountAsOne. -Metrics/ClassLength: - Max: 104 + Max: 36 # Offense count: 1 # Configuration parameters: AllowedMethods, AllowedPatterns. @@ -48,32 +35,14 @@ Metrics/CyclomaticComplexity: # Offense count: 5 # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. Metrics/MethodLength: - Max: 33 + Max: 31 # Offense count: 1 # Configuration parameters: AllowedMethods, AllowedPatterns. Metrics/PerceivedComplexity: Max: 11 -# Offense count: 2 -Performance/MapMethodChain: - Exclude: - - 'lib/repubmark/elems/footnotes_category.rb' - -# Offense count: 14 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowOnlyRestArgument, UseAnonymousForwarding, RedundantRestArgumentNames, RedundantKeywordRestArgumentNames, RedundantBlockArgumentNames. -# RedundantRestArgumentNames: args, arguments -# RedundantKeywordRestArgumentNames: kwargs, options, opts -# RedundantBlockArgumentNames: blk, block, proc -Style/ArgumentsForwarding: - Exclude: - - 'lib/repubmark/elems/canvas.rb' - - 'lib/repubmark/elems/footnotes_category.rb' - - 'lib/repubmark/elems/joint.rb' - - 'lib/repubmark/elems/link.rb' - -# Offense count: 34 +# Offense count: 36 # Configuration parameters: AllowedConstants. Style/Documentation: Enabled: false @@ -97,33 +66,3 @@ Style/RedundantFreeze: Exclude: - 'lib/repubmark/elems/fraction.rb' - 'lib/repubmark/elems/power.rb' - -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantStringEscape: - Exclude: - - 'lib/repubmark/elems/footnote.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowModifier. -Style/SoleNestedConditional: - Exclude: - - 'lib/repubmark/elems/footnote.rb' - -# Offense count: 7 -# This cop supports safe autocorrection (--autocorrect). -Style/SuperArguments: - Exclude: - - 'lib/repubmark/elems/annotation.rb' - - 'lib/repubmark/elems/blockquote.rb' - - 'lib/repubmark/elems/canvas.rb' - - 'lib/repubmark/elems/caption.rb' - - 'lib/repubmark/elems/figures.rb' - - 'lib/repubmark/elems/joint.rb' - - 'lib/repubmark/elems/paragraph.rb' - -# Offense count: 24 -# This cop supports safe autocorrection (--autocorrect). -Style/SuperWithArgsParentheses: - Enabled: false diff --git a/Rakefile b/Rakefile index a1fe1d3..628f9d2 100644 --- a/Rakefile +++ b/Rakefile @@ -27,8 +27,8 @@ task test: :tests desc 'Run code analysis tools' task lint: %i[rubocop yard:cov] -desc 'Fix code style (rubocop --auto-correct)' -task fix: 'rubocop:auto_correct' +desc 'Fix code style (rubocop --autocorrect)' +task fix: 'rubocop:autocorrect' Rake::Task['release'].prereqs.unshift 'default' Rake::Task['release:rubygem_push'].clear diff --git a/lib/repubmark/elems/annotation.rb b/lib/repubmark/elems/annotation.rb index 74f0b3f..dd43ee8 100644 --- a/lib/repubmark/elems/annotation.rb +++ b/lib/repubmark/elems/annotation.rb @@ -6,7 +6,7 @@ module Repubmark parents :Article def initialize(parent) - super parent + super @canvas = Canvas.new self end diff --git a/lib/repubmark/elems/article.rb b/lib/repubmark/elems/article.rb index bec8aa3..adc0e21 100644 --- a/lib/repubmark/elems/article.rb +++ b/lib/repubmark/elems/article.rb @@ -45,7 +45,7 @@ module Repubmark ].compact.join("\n\n\n").freeze end - def chapters = @chapter&.chapters[:chapters] || [].freeze + def chapters = (@chapter&.chapters || {})[:chapters] || [].freeze ################### # Builder methods # diff --git a/lib/repubmark/elems/blockquote.rb b/lib/repubmark/elems/blockquote.rb index c019e50..bc36789 100644 --- a/lib/repubmark/elems/blockquote.rb +++ b/lib/repubmark/elems/blockquote.rb @@ -6,7 +6,7 @@ module Repubmark parents :Canvas def initialize(parent) - super parent + super @canvas = Canvas.new self @caption = nil diff --git a/lib/repubmark/elems/canvas.rb b/lib/repubmark/elems/canvas.rb index 43762e8..9af10aa 100644 --- a/lib/repubmark/elems/canvas.rb +++ b/lib/repubmark/elems/canvas.rb @@ -6,7 +6,7 @@ module Repubmark parents :Annotation, :Blockquote, :Chapter def initialize(parent) - super parent + super @items = [] end @@ -41,14 +41,14 @@ module Repubmark nil end - def code_block(*args, **kwargs) - code_block = CodeBlock.new self, *args, **kwargs + def code_block(*, **) + code_block = CodeBlock.new(self, *, **) @items << code_block nil end - def iframe(*args, **kwargs) - iframe = Iframe.new self, *args, **kwargs + def iframe(*, **) + iframe = Iframe.new(self, *, **) @items << iframe nil end diff --git a/lib/repubmark/elems/caption.rb b/lib/repubmark/elems/caption.rb index b3b5264..96eff05 100644 --- a/lib/repubmark/elems/caption.rb +++ b/lib/repubmark/elems/caption.rb @@ -8,7 +8,7 @@ module Repubmark parents :Blockquote, :Figure, :Footnote, :ListItem, :Paragraph def initialize(parent) - super parent + super @items = [] end diff --git a/lib/repubmark/elems/figures.rb b/lib/repubmark/elems/figures.rb index b109e18..817132a 100644 --- a/lib/repubmark/elems/figures.rb +++ b/lib/repubmark/elems/figures.rb @@ -6,7 +6,7 @@ module Repubmark parents :Canvas def initialize(parent) - super parent + super @figures = [] end diff --git a/lib/repubmark/elems/footnote.rb b/lib/repubmark/elems/footnote.rb index 167d1b6..d376ceb 100644 --- a/lib/repubmark/elems/footnote.rb +++ b/lib/repubmark/elems/footnote.rb @@ -30,12 +30,10 @@ module Repubmark end if url scheme = Addressable::URI.parse(url).scheme&.downcase - if scheme - unless %w[http https].include? scheme - result += %(\n) - result += %(#{scheme}://\n) - result += "\n" - end + if scheme && !%w[http https].include?(scheme) + result += %(\n) + result += %(#{scheme}://\n) + result += "\n" end result += %(#{link_text}\n) else @@ -45,7 +43,7 @@ module Repubmark if alt_urls&.any? result += %[(#{ alt_urls.map do |alt_url| - %(#{alt_url[:name]}) + %(#{alt_url[:name]}) end.join ', ' })\n] end diff --git a/lib/repubmark/elems/footnotes_category.rb b/lib/repubmark/elems/footnotes_category.rb index cc1985c..6a3a320 100644 --- a/lib/repubmark/elems/footnotes_category.rb +++ b/lib/repubmark/elems/footnotes_category.rb @@ -20,7 +20,7 @@ module Repubmark

#@title

    - #{@footnotes.map(&:to_html).map(&:strip).join("\n")} + #{@footnotes.map { |footnote| footnote.to_html.strip }.join("\n")}
HTML end @@ -29,7 +29,7 @@ module Repubmark <<~GEMTEXT ## #@title - #{@footnotes.map(&:to_gemtext).map(&:strip).join("\n")} + #{@footnotes.map { |footnote| footnote.to_gemtext.strip }.join("\n")} GEMTEXT end @@ -37,8 +37,8 @@ module Repubmark # Builder methods # ################### - def footnote(**kwargs) - footnote = Footnote.new(self, **kwargs) + def footnote(**) + footnote = Footnote.new(self, **) @footnotes << footnote yield footnote if block_given? nil diff --git a/lib/repubmark/elems/joint.rb b/lib/repubmark/elems/joint.rb index b48b463..3988f97 100644 --- a/lib/repubmark/elems/joint.rb +++ b/lib/repubmark/elems/joint.rb @@ -6,7 +6,7 @@ module Repubmark parents :Caption, :Quote def initialize(parent) - super parent + super @raw1 = nil @base = nil @@ -92,7 +92,7 @@ module Repubmark base quote end - def section(*args) = base Section.new self, *args + def section(*) = base Section.new(self, *) def text(str) = base Text.new self, str diff --git a/lib/repubmark/elems/link.rb b/lib/repubmark/elems/link.rb index df306d2..6e326f5 100644 --- a/lib/repubmark/elems/link.rb +++ b/lib/repubmark/elems/link.rb @@ -7,8 +7,8 @@ module Repubmark SCHEMES = %w[http https].freeze - def initialize(parent, str, uri, **kwargs) - super parent, str, **kwargs + def initialize(parent, str, uri, **) + super(parent, str, **) self.uri = uri validate_uri! diff --git a/lib/repubmark/elems/paragraph.rb b/lib/repubmark/elems/paragraph.rb index 979e8e4..5568362 100644 --- a/lib/repubmark/elems/paragraph.rb +++ b/lib/repubmark/elems/paragraph.rb @@ -6,7 +6,7 @@ module Repubmark parents :Canvas def initialize(parent) - super parent + super @caption = Caption.new self end