From 7f1e2ec112e04f70a22f3ad23497c20763bb65c5 Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Mon, 27 Feb 2023 21:12:15 -0500 Subject: [PATCH] Autofix sax_ractor Layout Rubocops --- .rubocop_todo.yml | 34 --------------------------------- examples/sax_ractor.rb | 43 ++++++++++++++++++++---------------------- 2 files changed, 20 insertions(+), 57 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d5695322..9554d667 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,40 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EmptyLineBetweenMethodDefs, EmptyLineBetweenClassDefs, EmptyLineBetweenModuleDefs, AllowAdjacentOneLineDefs, NumberOfEmptyLines. -Layout/EmptyLineBetweenDefs: - Exclude: - - 'examples/sax_ractor.rb' - -# Offense count: 3 -# This cop supports safe autocorrection (--autocorrect). -Layout/EmptyLines: - Exclude: - - 'examples/sax_ractor.rb' - -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only -Layout/EmptyLinesAroundClassBody: - Exclude: - - 'examples/sax_ractor.rb' - -# Offense count: 5 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment. -Layout/ExtraSpacing: - Exclude: - - 'examples/sax_ractor.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Layout/HeredocIndentation: - Exclude: - - 'examples/sax_ractor.rb' - # Offense count: 23 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. diff --git a/examples/sax_ractor.rb b/examples/sax_ractor.rb index 8f5a1ceb..ca28a29f 100755 --- a/examples/sax_ractor.rb +++ b/examples/sax_ractor.rb @@ -11,23 +11,23 @@ # In the Real World™ we probably wouldn't create a single-use `Ractor` for # every argument, but this is primarily a test of `rb_ext_ractor_safe` for Ox. - # Miniature example Ractor-based `shared-mime-info` Ox handler à la `CHECKING::YOU::OUT`: # https://github.com/okeeblow/DistorteD/tree/NEW-SENSATION/CHECKING-YOU-OUT class Saxtor < Ox::Sax - # We will fill this `Struct` as we parse, # yield it if its `ietf` matches our `needle`, # and throw it away otherwise. CYO = Struct.new(:ietf, :globs, :description) do - def initialize(ietf = nil, globs = Array.new, description = nil) + def initialize(ietf=nil, globs=Array.new, description=nil) super(ietf, globs, description) end - def to_s # Pretty print + + def to_s # Pretty print "#{self[:description]} (#{self[:ietf]}) [#{ self[:globs]&.map(&File.method(:extname)).join(?,) }]" end + def inspect; "#"; end end @@ -48,7 +48,7 @@ def cyo def start_element(name) @parse_stack.push(name) case @parse_stack.last - when :"mime-type" then @cyo = nil # Clear out leftovers between types. + when :"mime-type" then @cyo = nil # Clear out leftovers between types. end end @@ -103,34 +103,33 @@ def awen(needle, **kwargs) smart: false, # [boolean] Toggle Ox's built-in hints for HTML parsing: https://github.com/ohler55/ox/blob/master/ext/ox/sax_hint.c strip_namespace: true, # [nil|String|true|false] (from Element names) Strip no namespaces, all namespaces, or a specific namespace. symbolize: true, # [boolean] Fill callback method `name` arguments with Symbols instead of with Strings. - intern_string_values: true, # [boolean] Intern (freeze and deduplicate) String return values. + intern_string_values: true, # [boolean] Intern (freeze and deduplicate) String return values. }.update(kwargs), ) # Let our parent `#take` our needle-equivalent `CYO`, or `nil`. Ractor.yield(@out) - end # def awen - -end # class Saxtor + end # def awen +end # class Saxtor # Fancy "usage" help `String` fragment to concat with specific error messages. -usage = <<-PLZ +usage = <<~PLZ -Usage: `sax_ractor.rb [SHARED-MIME-INFO_XML_PATH] [IETF_MEDIA_TYPES]…` + Usage: `sax_ractor.rb [SHARED-MIME-INFO_XML_PATH] [IETF_MEDIA_TYPES]…` -Common file paths: + Common file paths: -- FreeBSD: - `${LOCALBASE}/share/mime/packages/freedesktop.org.xml` (probably `/usr/local`) - https://www.freshports.org/misc/shared-mime-info/ + - FreeBSD: + `${LOCALBASE}/share/mime/packages/freedesktop.org.xml` (probably `/usr/local`) + https://www.freshports.org/misc/shared-mime-info/ -- Linux: - `/usr/share/mime/packages/freedesktop.org.xml` + - Linux: + `/usr/share/mime/packages/freedesktop.org.xml` -- macOS: - `/opt/homebrew/share/mime/packages/freedesktop.org.xml` (Homebrew) - `/opt/local/share/mime/packages/freedesktop.org.xml` (MacPorts) - https://formulae.brew.sh/formula/shared-mime-info + - macOS: + `/opt/homebrew/share/mime/packages/freedesktop.org.xml` (Homebrew) + `/opt/local/share/mime/packages/freedesktop.org.xml` (MacPorts) + https://formulae.brew.sh/formula/shared-mime-info PLZ # Bail out if we were given a nonexistant file. @@ -148,7 +147,6 @@ def awen(needle, **kwargs) haystack = haystack.realpath.freeze needles = ARGV[1...] - # Hamburger Style. puts "Parallel Ractors" # Create one `Ractor` for every given media-type argument @@ -179,7 +177,6 @@ def awen(needle, **kwargs) "#{_1.name} gave us #{_2 || 'nothing'}" } - # Hotdog Style. puts puts "Serial Ractor"