Skip to content

Commit 70e0939

Browse files
committed
[GR-17457] Add Ruby linter policy for space around = for a method default parameter
PullRequest: truffleruby/3690
2 parents 41d4eb1 + 55e9cb6 commit 70e0939

39 files changed

+176
-171
lines changed

.rubocop.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,4 +384,9 @@ Layout/SpaceBeforeBlockBraces:
384384
Layout/SpaceInsideBlockBraces:
385385
Enabled: true
386386
EnforcedStyle: space
387-
EnforcedStyleForEmptyBraces: space
387+
EnforcedStyleForEmptyBraces: space
388+
389+
# Supports --auto-correct
390+
Layout/SpaceAroundEqualsInParameterDefault:
391+
Description: Checks that the equals signs in parameter default assignments have or don't have surrounding space depending on configuration.
392+
Enabled: true

lib/truffle/digest/bubblebabble.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def self.bubblebabble(message)
2222
digest.bubblebabble
2323
end
2424

25-
def bubblebabble(message=NO_MESSAGE)
25+
def bubblebabble(message = NO_MESSAGE)
2626
Digest.bubblebabble(digest(message))
2727
end
2828

lib/truffle/pathname.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ def prepend_prefix(prefix, relpath)
374374
# entries than absolutely necessary, but without accessing the filesystem,
375375
# this can't be avoided. See #realpath.
376376
#
377-
def cleanpath(consider_symlink=false)
377+
def cleanpath(consider_symlink = false)
378378
if consider_symlink
379379
cleanpath_conservative
380380
else
@@ -478,7 +478,7 @@ def cleanpath_conservative
478478
# All components of the pathname must exist when this method is
479479
# called.
480480
#
481-
def realpath(basedir=nil)
481+
def realpath(basedir = nil)
482482
self.class.new(File.realpath(@path, basedir))
483483
end
484484

@@ -488,7 +488,7 @@ def realpath(basedir=nil)
488488
#
489489
# The last component of the real pathname can be nonexistent.
490490
#
491-
def realdirpath(basedir=nil)
491+
def realdirpath(basedir = nil)
492492
self.class.new(File.realdirpath(@path, basedir))
493493
end
494494

@@ -707,7 +707,7 @@ def join(*args)
707707
#
708708
# This method has existed since 1.8.1.
709709
#
710-
def children(with_directory=true)
710+
def children(with_directory = true)
711711
with_directory = false if @path == '.'
712712
result = []
713713
Dir.foreach(@path) do |e|
@@ -747,7 +747,7 @@ def children(with_directory=true)
747747
# # #<Pathname:src>
748748
# # #<Pathname:man>
749749
#
750-
def each_child(with_directory=true, &b)
750+
def each_child(with_directory = true, &b)
751751
children(with_directory).each(&b)
752752
end
753753

lib/truffle/socket/ip_socket.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def addr(reverse_lookup = nil)
3535
Truffle::Socket.address_info(:getsockname, self, reverse_lookup)
3636
end
3737

38-
def peeraddr(reverse_lookup=nil)
38+
def peeraddr(reverse_lookup = nil)
3939
Truffle::Socket.address_info(:getpeername, self, reverse_lookup)
4040
end
4141

lib/truffle/stringio.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def readbyte
4141
readchar.getbyte(0)
4242
end
4343

44-
def readline(sep=$/, limit=::Undefined, chomp: false)
44+
def readline(sep = $/, limit = ::Undefined, chomp: false)
4545
check_readable
4646
raise EOFError, 'end of file reached' if eof?
4747

@@ -138,7 +138,7 @@ def self.open(*args)
138138

139139
attr_reader :__data__
140140

141-
def initialize(string=nil, mode=nil, **options)
141+
def initialize(string = nil, mode = nil, **options)
142142
if block_given?
143143
warn 'StringIO::new() does not take block; use StringIO::open() instead'
144144
end
@@ -190,7 +190,7 @@ def initialize_copy(from)
190190
raise IOError, 'unable to modify data' if @__data__.string.frozen?
191191
end
192192

193-
def set_encoding(external, internal=nil, options=nil)
193+
def set_encoding(external, internal = nil, options = nil)
194194
encoding = external || Encoding.default_external
195195
d = @__data__
196196
TruffleRuby.synchronized(d) do
@@ -257,7 +257,7 @@ def each_codepoint(&block)
257257
self
258258
end
259259

260-
def each(sep=$/, limit=Undefined, chomp: false)
260+
def each(sep = $/, limit = Undefined, chomp: false)
261261
return to_enum :each, sep, limit, chomp: chomp unless block_given?
262262
check_readable
263263

@@ -385,7 +385,7 @@ def getbyte
385385
end
386386
end
387387

388-
def gets(sep=$/, limit=Undefined, chomp: false)
388+
def gets(sep = $/, limit = Undefined, chomp: false)
389389
check_readable
390390

391391
# Truffle: $_ is thread and frame local, so we use a primitive to
@@ -474,7 +474,7 @@ def read(length = nil, buffer = nil)
474474
end
475475
end
476476

477-
def readlines(sep=$/, limit=Undefined, chomp: false)
477+
def readlines(sep = $/, limit = Undefined, chomp: false)
478478
check_readable
479479

480480
ary = []
@@ -485,7 +485,7 @@ def readlines(sep=$/, limit=Undefined, chomp: false)
485485
ary
486486
end
487487

488-
def reopen(string=nil, mode=Undefined)
488+
def reopen(string = nil, mode = Undefined)
489489
if string and not string.kind_of? String and mode.equal? Undefined
490490
stringio = Truffle::Type.coerce_to(string, StringIO, :to_strio)
491491

@@ -699,7 +699,7 @@ def yaml_initialize(type, val)
699699
d.string.replace('') if (mode & IO::TRUNC) != 0
700700
end
701701

702-
private def getline(arg_error, sep, limit, chomp=false)
702+
private def getline(arg_error, sep, limit, chomp = false)
703703
if limit != Undefined
704704
limit = Primitive.rb_to_int limit if limit
705705
sep = Truffle::Type.coerce_to sep, String, :to_str if sep

lib/truffle/timeout.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def timeout(sec, exception = Error, message = nil)
180180
# Defined for backwards compatibility with earlier versions of timeout.rb, see
181181
# Timeout#timeout.
182182

183-
def timeout(n, e=Timeout::Error, &block) # :nodoc:
183+
def timeout(n, e = Timeout::Error, &block) # :nodoc:
184184
Timeout.timeout(n, e, &block)
185185
end
186186

spec/truffle/arguments_descriptor_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def posn_kws_defaults(a, b: 101, c: 102)
150150
end
151151

152152
it "contain the name of present optional keyword arguments without the optional positional" do
153-
def opt_and_kws(a, b=2, c: nil)
153+
def opt_and_kws(a, b = 2, c: nil)
154154
info([a, b, c], Primitive.arguments_descriptor, Primitive.arguments)
155155
end
156156

src/main/ruby/truffleruby/core/argf.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def default_value
125125
#
126126
# @see #gets.
127127
#
128-
def each_line(sep=$/)
128+
def each_line(sep = $/)
129129
return to_enum :each_line, sep unless block_given?
130130
return nil unless advance!
131131

@@ -283,7 +283,7 @@ def getc
283283
# The mechanism does track the line numbers,
284284
# and updates $. accordingly.
285285
#
286-
def gets(sep=$/)
286+
def gets(sep = $/)
287287
while advance!
288288
line = @stream.gets(sep)
289289

@@ -375,7 +375,7 @@ def readbyte
375375
# is provided, as by default, a String with the data is
376376
# returned instead.
377377
#
378-
def read(bytes=nil, output=nil)
378+
def read(bytes = nil, output = nil)
379379
# The user might try to pass in nil, so we have to check here
380380
if Primitive.nil? output
381381
output = default_value
@@ -454,11 +454,11 @@ def getpartial(bytes, output, is_blocking, exception: true)
454454
end
455455
private :getpartial
456456

457-
def readpartial(bytes, output=nil)
457+
def readpartial(bytes, output = nil)
458458
getpartial(bytes, output, true)
459459
end
460460

461-
def read_nonblock(bytes, output=nil, exception: true)
461+
def read_nonblock(bytes, output = nil, exception: true)
462462
getpartial(bytes, output, false, exception: exception)
463463
end
464464

@@ -470,7 +470,7 @@ def read_nonblock(bytes, output=nil, exception: true)
470470
#
471471
# @see #gets
472472
#
473-
def readline(sep=$/)
473+
def readline(sep = $/)
474474
raise EOFError, 'ARGF at end' unless advance!
475475

476476
if line = gets(sep)
@@ -488,7 +488,7 @@ def readline(sep=$/)
488488
#
489489
# @see #gets
490490
#
491-
def readlines(sep=$/)
491+
def readlines(sep = $/)
492492
return [] unless advance!
493493

494494
lines = []

src/main/ruby/truffleruby/core/array.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ def empty?
399399
size == 0
400400
end
401401

402-
def fetch(idx, default=undefined)
402+
def fetch(idx, default = undefined)
403403
orig = idx
404404
idx = Primitive.rb_num2int idx
405405

@@ -420,7 +420,7 @@ def fetch(idx, default=undefined)
420420
at(idx)
421421
end
422422

423-
private def fill_internal(a=undefined, b=undefined, c=undefined)
423+
private def fill_internal(a = undefined, b = undefined, c = undefined)
424424
Primitive.check_frozen self
425425

426426
if block_given?
@@ -492,7 +492,7 @@ def first(n = undefined)
492492
Array.new self[0, n]
493493
end
494494

495-
def flatten(level=-1)
495+
def flatten(level = -1)
496496
level = Primitive.rb_num2int level
497497
return Array.new(self) if level == 0
498498

@@ -501,7 +501,7 @@ def flatten(level=-1)
501501
out
502502
end
503503

504-
def flatten!(level=-1)
504+
def flatten!(level = -1)
505505
Primitive.check_frozen self
506506

507507
level = Primitive.rb_num2int level
@@ -572,7 +572,7 @@ def hash
572572
end
573573
Truffle::Graal.always_split instance_method(:hash)
574574

575-
def find_index(obj=undefined)
575+
def find_index(obj = undefined)
576576
super
577577
end
578578
alias_method :index, :find_index
@@ -650,7 +650,7 @@ def intersection(*others)
650650
common.keys
651651
end
652652

653-
def join(sep=nil)
653+
def join(sep = nil)
654654
return ''.encode(Encoding::US_ASCII) if size == 0
655655

656656
out = +''
@@ -702,7 +702,7 @@ def keep_if(&block)
702702
self
703703
end
704704

705-
def last(n=undefined)
705+
def last(n = undefined)
706706
if Primitive.undefined?(n)
707707
return at(-1)
708708
elsif size < 1
@@ -718,7 +718,7 @@ def last(n=undefined)
718718
Array.new self[-n..-1]
719719
end
720720

721-
def permutation(num=undefined, &block)
721+
def permutation(num = undefined, &block)
722722
unless block_given?
723723
return to_enum(:permutation, num) do
724724
permutation_size(num)
@@ -756,11 +756,11 @@ def permutation(num=undefined, &block)
756756
self
757757
end
758758

759-
def max(n=undefined)
759+
def max(n = undefined)
760760
super(n)
761761
end
762762

763-
def min(n=undefined)
763+
def min(n = undefined)
764764
super(n)
765765
end
766766

@@ -998,7 +998,7 @@ def reverse_each
998998
self
999999
end
10001000

1001-
def rindex(obj=undefined)
1001+
def rindex(obj = undefined)
10021002
if Primitive.undefined?(obj)
10031003
return to_enum(:rindex, obj) unless block_given?
10041004

@@ -1023,7 +1023,7 @@ def rindex(obj=undefined)
10231023
nil
10241024
end
10251025

1026-
def rotate(n=1)
1026+
def rotate(n = 1)
10271027
n = Primitive.rb_num2int n
10281028

10291029
len = self.length
@@ -1034,7 +1034,7 @@ def rotate(n=1)
10341034
Primitive.array_rotate self, n
10351035
end
10361036

1037-
def rotate!(n=1)
1037+
def rotate!(n = 1)
10381038
n = Primitive.rb_num2int n
10391039
Primitive.check_frozen self
10401040

@@ -1612,7 +1612,7 @@ def reverse!
16121612
self
16131613
end
16141614

1615-
def slice!(start, length=undefined)
1615+
def slice!(start, length = undefined)
16161616
Primitive.check_frozen self
16171617

16181618
if Primitive.undefined? length

src/main/ruby/truffleruby/core/complex.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ def Complex.generic?(other) # :nodoc:
5555
(defined?(Rational) and Primitive.object_kind_of?(other, Rational))
5656
end
5757

58-
def Complex.rect(real, imag=0)
58+
def Complex.rect(real, imag = 0)
5959
raise TypeError, 'not a real' unless Primitive.check_real?(real) && Primitive.check_real?(imag)
6060
new(real, imag)
6161
end
6262
class << self; alias_method :rectangular, :rect end
6363

64-
def Complex.polar(r, theta=0)
64+
def Complex.polar(r, theta = 0)
6565
raise TypeError, 'not a real' unless Primitive.check_real?(r) && Primitive.check_real?(theta)
6666

6767
Complex(r*Math.cos(theta), r*Math.sin(theta))

0 commit comments

Comments
 (0)