Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autofix Rubocop Layout rules - Batch 4 #321

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions .github/workflows/rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ on:
- ".rubocop*.yml"
- ".github/workflows/rubocop.yml"
- "**/*.rb"
- "**/*.gemspec"
- "**/*.gemfile"
- "Gemfile"
pull_request:
paths:
- ".rubocop*.yml"
- ".github/workflows/rubocop.yml"
- "**/*.rb"
- "**/*.gemspec"
- "**/*.gemfile"
- "Gemfile"

jobs:
formatting-check:
Expand All @@ -28,12 +34,10 @@ jobs:
uses: ruby/setup-ruby@v1
with:
ruby-version: "2.7"

- name: Install rubocop
run: gem install rubocop --no-doc
bundler-cache: true

- name: Set-up RuboCop Problem Matcher
uses: r7kamura/rubocop-problem-matchers-action@v1

- name: Run rubocop
run: rubocop
run: bundle exec rubocop
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ AllCops:
TargetRubyVersion: 2.7
NewCops: enable

Layout/SpaceAroundEqualsInParameterDefault:
EnforcedStyle: no_space

Naming/MethodName:
EnforcedStyle: snake_case
Exclude:
Expand Down
80 changes: 0 additions & 80 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,86 +16,6 @@ Layout/MultilineHashBraceLayout:
- 'test/sample/file.rb'
- 'test/tests.rb'

# Offense count: 26
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: space, no_space
Layout/SpaceAroundEqualsInParameterDefault:
Exclude:
- 'lib/ox/bag.rb'
- 'lib/ox/document.rb'
- 'lib/ox/element.rb'
- 'test/ox/change.rb'
- 'test/ox/doc.rb'
- 'test/ox/oval.rb'
- 'test/ox/rect.rb'
- 'test/ox/shape.rb'
- 'test/ox/text.rb'
- 'test/perf_mars.rb'
- 'test/sample.rb'
- 'test/sample/change.rb'
- 'test/sample/doc.rb'
- 'test/sample/oval.rb'
- 'test/sample/rect.rb'
- 'test/sample/shape.rb'
- 'test/sample/text.rb'
- 'test/tests.rb'

# Offense count: 10
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator.
# SupportedStylesForExponentOperator: space, no_space
Layout/SpaceAroundOperators:
Exclude:
- 'contrib/xbuilder_test.rb'
- 'lib/ox/element.rb'
- 'test/perf_mars.rb'
- 'test/sax/sax_test.rb'
- 'test/tests.rb'

# Offense count: 4
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
# SupportedStyles: space, no_space
# SupportedStylesForEmptyBraces: space, no_space
Layout/SpaceInsideBlockBraces:
Exclude:
- 'contrib/xbuilder.rb'
- 'test/perf.rb'
- 'test/sax/smart_test.rb'
- 'test/tests.rb'

# Offense count: 106
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
# SupportedStyles: space, no_space, compact
# SupportedStylesForEmptyBraces: space, no_space
Layout/SpaceInsideHashLiteralBraces:
Exclude:
- 'contrib/xbuilder_test.rb'
- 'examples/obj.rb'
- 'lib/ox/bag.rb'
- 'lib/ox/document.rb'
- 'lib/ox/hasattrs.rb'
- 'test/ox/doc.rb'
- 'test/ox/hasprops.rb'
- 'test/perf_gen.rb'
- 'test/perf_mars.rb'
- 'test/sample/doc.rb'
- 'test/sample/file.rb'
- 'test/sample/hasprops.rb'
- 'test/sax/sax_test.rb'
- 'test/sax/smart_test.rb'
- 'test/tests.rb'

# Offense count: 12
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: space, compact, no_space
Layout/SpaceInsideParens:
Exclude:
- 'test/tests.rb'

# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowSafeAssignment.
Expand Down
2 changes: 1 addition & 1 deletion contrib/sax_benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def end_element(key)
end
end

def start_element(key, attrs = [])
def start_element(key, attrs=[])
@stack << @node = {}
attrs.each do |attr|
key, val = *attr
Expand Down
2 changes: 1 addition & 1 deletion contrib/xbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def x(name, *args)
when Hash
arg.each { |k, v| n[k.to_s] = v }
when Array
arg.each { |c| n << c if c}
arg.each { |c| n << c if c }
else
n << arg if arg
end
Expand Down
14 changes: 7 additions & 7 deletions contrib/xbuilder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ def test_build
x_if(false, 'child5')
]

n=x('parent',
x('child1', {'atr1'=>'atr1_value', :atr2 => 'atr2_value'},
x('subchild1', 'some text'),
x('subchild2', {'atr3' => 'default_value'}, {'atr3' => 'atr3_value'},
x('sometag'),
x_if(false, 'never'))),
children)
n = x('parent',
x('child1', { 'atr1' => 'atr1_value', :atr2 => 'atr2_value' },
x('subchild1', 'some text'),
x('subchild2', { 'atr3' => 'default_value' }, { 'atr3' => 'atr3_value' },
x('sometag'),
x_if(false, 'never'))),
children)

assert_equal(Ox.dump(n), Ox.dump(Ox.parse(xml)))
end
Expand Down
2 changes: 1 addition & 1 deletion examples/obj.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def to_s
end
end

obj = Classy.new(23, ['abc', {x: true}])
obj = Classy.new(23, ['abc', { x: true }])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect example of a mix of spaces after brackets and no space. I prefer consistent behaviour between [] and {}. Happy to go with either but not a mix.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe tight, no spaces after [ or { or before ] or } is best if there is no overriding consensus.


doc = Ox.dump(obj, mode: :object)

Expand Down
2 changes: 1 addition & 1 deletion examples/sax_ractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Saxtor < Ox::Sax
# 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 = [], description = nil)
def initialize(ietf=nil, globs=[], description=nil)
super(ietf, globs, description)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/ox/bag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Bag
#
# Ox::Bag.new(:@x => 42, :@y => 57)
#
def initialize(args={ })
def initialize(args={})
args.each do |k, v|
instance_variable_set(k, v)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ox/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Document < Element
# - _:standalone_ [String] indicates the document is standalone
def initialize(prolog={})
super(nil)
@attributes = { }
@attributes = {}
@attributes[:version] = prolog[:version] unless prolog[:version].nil?
@attributes[:encoding] = prolog[:encoding] unless prolog[:encoding].nil?
@attributes[:standalone] = prolog[:standalone] unless prolog[:standalone].nil?
Expand Down
4 changes: 2 additions & 2 deletions lib/ox/element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def alocate(path, found)
name = step
qual = nil
else
name = step[0..i-1]
name = step[0..i - 1]
raise InvalidPath.new(path) unless step.end_with?(']')

i += 1
Expand Down Expand Up @@ -350,7 +350,7 @@ def del_locate(path)
name = step
qual = nil
else
name = step[0..i-1]
name = step[0..i - 1]
raise InvalidPath.new(path) unless step.end_with?(']')

i += 1
Expand Down
4 changes: 2 additions & 2 deletions lib/ox/hasattrs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module HasAttrs
# Returns all the attributes of the Instruct as a Hash.
# *return* [Hash] all attributes and attribute values.
def attributes
@attributes = { } if !instance_variable_defined?(:@attributes) or @attributes.nil?
@attributes = {} if !instance_variable_defined?(:@attributes) or @attributes.nil?
@attributes
end

Expand All @@ -26,7 +26,7 @@ def [](attr)
def []=(attr, value)
raise 'argument to [] must be a Symbol or a String.' unless attr.is_a?(Symbol) or attr.is_a?(String)

@attributes = { } if !instance_variable_defined?(:@attributes) or @attributes.nil?
@attributes = {} if !instance_variable_defined?(:@attributes) or @attributes.nil?
a_str = attr.to_s
a_sym = attr.to_sym
if @attributes.has_key?(a_str)
Expand Down
2 changes: 1 addition & 1 deletion test/ox/doc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def initialize(title)
@title = title
@user = ENV['USER']
@create_time = Time.now
@layers = { }
@layers = {}
@change_history = []
end

Expand Down
4 changes: 2 additions & 2 deletions test/ox/hasprops.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ module Test
module Ox
module HasProps
def add_prop(key, value)
@props = { } unless instance_variable_defined?(:@props)
@props = {} unless instance_variable_defined?(:@props)
@props[key] = value
end

def props
@props = { } unless instance_variable_defined?(:@props)
@props = {} unless instance_variable_defined?(:@props)
@props
end
end # HashProps
Expand Down
2 changes: 1 addition & 1 deletion test/perf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def before(title, &blk)
end

def run(iter)
base = Item.new(nil, nil) { }
base = Item.new(nil, nil) {}
base.run(iter, 0.0)
@items.each do |i|
i.run(iter, base.duration)
Expand Down
2 changes: 1 addition & 1 deletion test/perf_gen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
opts.on('-h', '--help', 'Show this display') { puts opts; Process.exit!(0) }
files = opts.parse(ARGV)

Ox.default_options = {mode: :generic}
Ox.default_options = { mode: :generic }

data = []

Expand Down
4 changes: 2 additions & 2 deletions test/perf_mars.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ def initialize(v=[])
data[:Symbol].values << "Symbol#{i}".to_sym
data[:Time].values << (Time.now + i)
data[:Array].values << []
data[:Hash].values << { }
data[:Hash].values << {}
data[:Range].values << (0..7)
data[:Regexp].values << /^[0-9]/
data[:Bignum].values << (7 ** 55)
data[:Bignum].values << (7**55)
data[:Complex].values << Complex(1, 2)
data[:Rational].values << Rational(1, 3)
data[:Struct].values << s.new(1, 3, 5)
Expand Down
2 changes: 1 addition & 1 deletion test/perf_sax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def warning(message);
end

class NoAllSax < NoSax
def start_element(name, attrs = []); end
def start_element(name, attrs=[]); end
def characters(text); end
def cdata_block(string); end
def comment(string); end
Expand Down
2 changes: 1 addition & 1 deletion test/sample/doc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def initialize(title)
@title = title
@user = ENV['USER']
@create_time = Time.now
@layers = { }
@layers = {}
@change_history = []
end

Expand Down
6 changes: 3 additions & 3 deletions test/sample/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ def initialize(filename)
'user' => {
'read' => (0 != (stat.mode & 0x0100)),
'write' => (0 != (stat.mode & 0x0080)),
'execute' => (0 != (stat.mode & 0x0040))},
'execute' => (0 != (stat.mode & 0x0040)) },
'group' => {
'read' => (0 != (stat.mode & 0x0020)),
'write' => (0 != (stat.mode & 0x0010)),
'execute' => (0 != (stat.mode & 0x0008))},
'execute' => (0 != (stat.mode & 0x0008)) },
'other' => {
'read' => (0 != (stat.mode & 0x0004)),
'write' => (0 != (stat.mode & 0x0002)),
'execute' => (0 != (stat.mode & 0x0001))}
'execute' => (0 != (stat.mode & 0x0001)) }
}
else
@permissions = {
Expand Down
4 changes: 2 additions & 2 deletions test/sample/hasprops.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module Sample
module HasProps
def add_prop(key, value)
@props = { } unless instance_variable_defined?(:@props)
@props = {} unless instance_variable_defined?(:@props)
@props[key] = value
end

def props
@props = { } unless instance_variable_defined?(:@props)
@props = {} unless instance_variable_defined?(:@props)
@props
end
end # HasProps
Expand Down
2 changes: 1 addition & 1 deletion test/sax/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module SaxTestHelpers
# [:end_element, :top]
# ], AllSax, :convert_special => true, :smart => true)
#
def parse_compare(xml, expected, handler_class = AllSax, opts = {}, handler_attr = :calls)
def parse_compare(xml, expected, handler_class=AllSax, opts={}, handler_attr=:calls)
handler = handler_class.new
input = StringIO.new(xml)
options = {
Expand Down
2 changes: 1 addition & 1 deletion test/sax/sax_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,7 @@ def test_sax_html_inactive
Ox.default_options = $ox_sax_options
handler = AllSax.new

Ox.sax_html(handler, '<html><h1>title</h1><hr/><p>Hello</p></html>', :overlay => {'hr'=>:inactive})
Ox.sax_html(handler, '<html><h1>title</h1><hr/><p>Hello</p></html>', :overlay => { 'hr' => :inactive })
assert_equal([
[:start_element, :html],
[:start_element, :h1],
Expand Down
Loading