Skip to content

Commit

Permalink
upgrade RuboCop, configure new rules, and apply necessary code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mojavelinux committed Mar 9, 2024
1 parent fb27ca1 commit 65dbe42
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 18 deletions.
65 changes: 59 additions & 6 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ AllCops:
TargetRubyVersion: 2.7
Capybara:
Enabled: false
FactoryBot:
Enabled: false
Gemspec/DeprecatedAttributeAssignment:
Enabled: true
Gemspec/DevelopmentDependencies:
Expand Down Expand Up @@ -113,10 +115,16 @@ Lint/IdentityComparison:
Enabled: true
Lint/IncompatibleIoSelectWithFiberScheduler:
Enabled: true
Lint/ItWithoutArgumentsInBlock:
Enabled: true
Lint/LambdaWithoutLiteralBlock:
Enabled: true
Lint/LiteralAssignmentInCondition:
Enabled: false # reason: we know what we're doing; sometimes it's necessary to assign a literal value
Lint/MissingSuper:
Enabled: false # FIXME consider enabling
Lint/MixedCaseRange:
Enabled: true
Lint/MixedRegexpCaptureTypes:
Enabled: true
Lint/NoReturnInBeginEndBlocks:
Expand All @@ -135,6 +143,8 @@ Lint/RaiseException:
Enabled: true
Lint/RedundantDirGlobSort:
Enabled: true
Lint/RedundantRegexpQuantifiers:
Enabled: true
Lint/RefinementImportMethods:
Enabled: true
Lint/RequireRangeParentheses:
Expand All @@ -148,7 +158,7 @@ Lint/StructNewOverride:
Lint/SuppressedException:
Enabled: true
Lint/SymbolConversion:
Enabled: true
Enabled: false # reason: requires use of :"static#{variable}" which is not the style we prefer
Lint/ToEnumArguments:
Enabled: true
Lint/TopLevelReturnWithArgument:
Expand Down Expand Up @@ -219,7 +229,7 @@ RSpec/BeEmpty:
RSpec/BeEq:
Enabled: true
RSpec/BeEql:
Enabled: false # NOTE can lead to cryptic error messages when comparing integers
Enabled: false # reason: can lead to cryptic error messages when comparing integers
RSpec/BeNil:
Enabled: true
RSpec/BeforeAfterAll:
Expand All @@ -238,6 +248,10 @@ RSpec/DuplicatedMetadata:
Enabled: true
RSpec/EmptyExampleGroup:
Enabled: true
RSpec/EmptyMetadata:
Enabled: true
RSpec/Eq:
Enabled: true
RSpec/ExampleLength:
Enabled: false
RSpec/ExampleWording:
Expand All @@ -254,8 +268,13 @@ RSpec/IdenticalEqualityAssertion:
Enabled: true
RSpec/IndexedLet:
Enabled: true
RSpec/IsExpectedSpecify:
Enabled: true
RSpec/MatchArray:
Enabled: true
RSpec/MetadataStyle:
Enabled: false # reason: this rule is just confused
EnforcedStyle: symbol
RSpec/MultipleExpectations:
Enabled: true
Max: 25 # FIXME get this down to 15
Expand All @@ -264,17 +283,29 @@ RSpec/NamedSubject:
RSpec/NoExpectationExample:
Enabled: false
RSpec/Pending:
Enabled: true
Enabled: false # reason: incorrectly detects spec as proc as pending
RSpec/PendingWithoutReason:
Enabled: true
RSpec/RedundantAround:
Enabled: true
RSpec/Rails:
Enabled: false
RSpec/ReceiveMessages:
Enabled: true
RSpec/RedundantAround:
Enabled: true
RSpec/RedundantPredicateMatcher:
Enabled: true
RSpec/RemoveConst:
Enabled: false # reason: we need this capability
RSpec/RepeatedSubjectCall:
Enabled: true
RSpec/SkipBlockInsideExample:
Enabled: true
RSpec/SortMetadata:
Enabled: true
RSpec/SpecFilePathFormat:
Enabled: false # reason: we prefer to name spec files the way we want to name them
RSpec/SpecFilePathSuffix:
Enabled: true
RSpec/SubjectDeclaration:
Enabled: true
RSpec/VerifiedDoubleReference:
Expand Down Expand Up @@ -302,7 +333,7 @@ Style/ArrayIntersect:
Style/AsciiComments:
Enabled: false # reason: this is just nitpicky
Style/Attr:
Enabled: true
Enabled: false # reason: gets confused by Asciidoctor's attr method
Style/BisectedAttrAccessor:
Enabled: true
Style/BlockComments:
Expand Down Expand Up @@ -359,6 +390,8 @@ Style/EndlessMethod:
Enabled: true
Style/EnvHome:
Enabled: true
Style/ExactRegexpMatch:
Enabled: true
Style/ExplicitBlockArgument:
Enabled: false # reason: yield is fine
Style/ExponentialNotation:
Expand Down Expand Up @@ -481,12 +514,16 @@ Style/QuotedSymbols:
Enabled: true
Style/RedundantArgument:
Enabled: true
Style/RedundantArrayConstructor:
Enabled: true
Style/RedundantAssignment:
Enabled: true
Style/RedundantBegin:
Enabled: true
Style/RedundantConstantBase:
Enabled: true
Style/RedundantCurrentDirectoryInPath:
Enabled: true
Style/RedundantDoubleSplatHashBraces:
Enabled: true
Style/RedundantEach:
Expand All @@ -495,22 +532,34 @@ Style/RedundantFetchBlock:
Enabled: true
Style/RedundantFileExtensionInRequire:
Enabled: true
Style/RedundantFilterChain:
Enabled: true
Style/RedundantHeredocDelimiterQuotes:
Enabled: false # reason: we know what we are doing
Style/RedundantInitialize:
Enabled: true
Style/RedundantLineContinuation:
Enabled: true
Style/RedundantParentheses:
Enabled: false # reason: sometimes the parentheses just make it clearer; this rule is too aggressive
Style/RedundantPercentQ:
Enabled: true
Style/RedundantRegexpArgument:
Enabled: true
Style/RedundantRegexpCharacterClass:
Enabled: true
Style/RedundantRegexpConstructor:
Enabled: true
Style/RedundantRegexpEscape:
Enabled: true
Style/ReturnNilInPredicateMethodDefinition:
Enabled: true
Style/RedundantSelfAssignment:
Enabled: true
Style/RedundantSelfAssignmentBranch:
Enabled: false
Style/SingleLineDoEndBlock:
Enabled: true
Style/RedundantStringEscape:
Enabled: false # reason: this rule crashes RuboCop
Style/RegexpLiteral:
Expand Down Expand Up @@ -539,6 +588,8 @@ Style/StringChars:
Enabled: true
Style/StringConcatenation:
Enabled: false # reason: string concatenation can be faster
Style/SuperWithArgsParentheses:
Enabled: false # reason: hate it
Style/SwapValues:
Enabled: true
Style/SymbolArray:
Expand All @@ -554,3 +605,5 @@ Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: consistent_comma
Style/WordArray:
Enabled: true
Style/YAMLFileRead:
Enabled: true
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ group :lint do
gem 'rubocop-rake', '~> 0.6.0', require: false
gem 'rubocop-rspec', '~> 2.10.0', require: false
else
gem 'rubocop', '~> 1.50.0', require: false
gem 'rubocop', '~> 1.62.0', require: false
gem 'rubocop-rake', '~> 0.6.0', require: false
gem 'rubocop-rspec', '~> 2.20.0', require: false
gem 'rubocop-rspec', '~> 2.27.0', require: false
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/asciidoctor/pdf/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ def convert_document doc
end

unless page_count < body_start_page_number
ink_running_content :header, doc, num_front_matter_pages, body_start_page_number unless doc.noheader || @theme.header_height.to_f == 0 # rubocop:disable Lint/FloatComparison
ink_running_content :footer, doc, num_front_matter_pages, body_start_page_number unless doc.nofooter || @theme.footer_height.to_f == 0 # rubocop:disable Lint/FloatComparison
ink_running_content :header, doc, num_front_matter_pages, body_start_page_number unless doc.noheader || @theme.header_height.to_f == 0
ink_running_content :footer, doc, num_front_matter_pages, body_start_page_number unless doc.nofooter || @theme.footer_height.to_f == 0
end

add_outline doc, (doc.attr 'outlinelevels', toc_num_levels), toc_page_nums, num_front_matter_pages[1], has_front_cover
Expand Down
4 changes: 2 additions & 2 deletions spec/converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
pdf_doc = doc.convert
tmp_files = (converter = doc.converter).instance_variable_get :@tmp_files
(expect tmp_files).to have_size 1
tmp_files.each {|_, path| converter.send :unlink_tmp_file, path }
tmp_files.each_value {|path| converter.send :unlink_tmp_file, path }
doc.write pdf_doc, (pdf_io = StringIO.new)
pdf = PDF::Reader.new pdf_io
(expect get_images pdf).to have_size 1
Expand Down Expand Up @@ -193,7 +193,7 @@
pdf = PDF::Reader.new pdf_io
(expect get_images pdf).to have_size 1
(expect tmp_files).to have_size 1
tmp_files.each do |_, path|
tmp_files.each_value do |path|
(expect Pathname.new path).to exist
File.unlink path
end
Expand Down
10 changes: 5 additions & 5 deletions spec/list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1145,11 +1145,11 @@
doc.convert
dlist = doc.blocks[0]
term, desc = (item = (items = dlist.items)[0])
(expect dlist).to be == original_dlist
(expect term).to be == original_term
(expect items).to be == original_items
(expect item).to be == original_item
(expect desc).to be == original_desc
(expect dlist).to eq original_dlist
(expect term).to eq original_term
(expect items).to eq original_items
(expect item).to eq original_item
(expect desc).to eq original_desc
end

it 'should arrange horizontal list in two columns' do
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def get_images pdf, page_num = nil
if page_num
(pdf.page page_num).xobjects.select {|_, candidate| candidate.hash[:Subtype] == :Image }.values
else
pdf.pages.each_with_object([]) {|page, accum| page.xobjects.each {|_, candidate| candidate.hash[:Subtype] == :Image ? (accum << candidate) : accum } }
pdf.pages.each_with_object([]) {|page, accum| page.xobjects.each_value {|candidate| candidate.hash[:Subtype] == :Image ? (accum << candidate) : accum } }
end
end

Expand Down

0 comments on commit 65dbe42

Please sign in to comment.