2013-10-05 14:37:08 -04:00
|
|
|
if something_wrong? # ruby-move-to-block-skips-heredoc
|
|
|
|
ActiveSupport::Deprecation.warn(<<-eowarn)
|
|
|
|
boo hoo
|
|
|
|
end
|
|
|
|
eowarn
|
|
|
|
end
|
|
|
|
|
2012-08-14 08:38:11 -04:00
|
|
|
# Percent literals.
|
2012-04-24 13:06:12 -04:00
|
|
|
b = %Q{This is a "string"}
|
2012-08-14 08:38:11 -04:00
|
|
|
c = %w!foo
|
2012-04-24 13:06:12 -04:00
|
|
|
bar
|
2012-08-14 08:38:11 -04:00
|
|
|
baz!
|
|
|
|
d = %(hello (nested) world)
|
|
|
|
|
|
|
|
# Don't propertize percent literals inside strings.
|
|
|
|
"(%s, %s)" % [123, 456]
|
|
|
|
|
|
|
|
# Or inside comments.
|
|
|
|
x = # "tot %q/to"; =
|
2013-05-08 16:25:57 -04:00
|
|
|
y = 2 / 3
|
2012-08-14 08:38:11 -04:00
|
|
|
|
|
|
|
# Regexp after whitelisted method.
|
|
|
|
"abc".sub /b/, 'd'
|
|
|
|
|
|
|
|
# Don't mis-match "sub" at the end of words.
|
|
|
|
a = asub / aslb + bsub / bslb;
|
2012-04-24 13:06:12 -04:00
|
|
|
|
2012-08-14 08:38:11 -04:00
|
|
|
# Highlight the regexp after "if".
|
|
|
|
x = toto / foo if /do bar/ =~ "dobar"
|
2012-04-24 13:06:12 -04:00
|
|
|
|
2013-10-05 14:37:08 -04:00
|
|
|
bar(class: XXX) do # ruby-indent-keyword-label
|
|
|
|
foo
|
|
|
|
end
|
|
|
|
bar
|
|
|
|
|
|
|
|
foo = [1, # ruby-deep-indent
|
|
|
|
2]
|
|
|
|
|
|
|
|
foo = { # ruby-deep-indent-disabled
|
2013-10-06 03:46:28 +03:00
|
|
|
a: b
|
2013-10-05 14:37:08 -04:00
|
|
|
}
|
|
|
|
|
2013-10-23 13:55:53 -04:00
|
|
|
foo = { a: b
|
|
|
|
a1: b1
|
|
|
|
}
|
|
|
|
|
2013-10-21 07:50:06 +04:00
|
|
|
foo({
|
|
|
|
a: b,
|
|
|
|
c: d
|
|
|
|
})
|
|
|
|
|
2013-10-05 14:37:08 -04:00
|
|
|
foo = [ # ruby-deep-indent-disabled
|
|
|
|
1
|
|
|
|
]
|
|
|
|
|
|
|
|
foo( # ruby-deep-indent-disabled
|
|
|
|
a
|
|
|
|
)
|
|
|
|
|
2013-05-19 10:01:23 +04:00
|
|
|
# Multiline regexp.
|
|
|
|
/bars
|
|
|
|
tees # toots
|
|
|
|
nfoos/
|
|
|
|
|
2013-05-08 16:25:57 -04:00
|
|
|
def test1(arg)
|
|
|
|
puts "hello"
|
|
|
|
end
|
|
|
|
|
|
|
|
def test2 (arg)
|
|
|
|
a = "apple"
|
|
|
|
|
|
|
|
if a == 2
|
|
|
|
puts "hello"
|
|
|
|
else
|
|
|
|
puts "there"
|
|
|
|
end
|
|
|
|
|
|
|
|
if a == 2 then
|
|
|
|
puts "hello"
|
|
|
|
elsif a == 3
|
|
|
|
puts "hello3"
|
|
|
|
elsif a == 3 then
|
|
|
|
puts "hello3"
|
|
|
|
else
|
|
|
|
puts "there"
|
|
|
|
end
|
|
|
|
|
|
|
|
case a
|
|
|
|
when "a"
|
|
|
|
6
|
2013-05-19 10:01:23 +04:00
|
|
|
# Support for this syntax was removed in Ruby 1.9, so we
|
|
|
|
# probably don't need to handle it either.
|
2013-05-08 16:25:57 -04:00
|
|
|
# when "b" :
|
|
|
|
# 7
|
|
|
|
# when "c" : 2
|
|
|
|
when "d" then 4
|
|
|
|
else 5
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-04-24 13:06:12 -04:00
|
|
|
# Some Cucumber code:
|
|
|
|
Given /toto/ do
|
|
|
|
print "hello"
|
|
|
|
end
|
2013-09-03 03:29:10 +03:00
|
|
|
|
|
|
|
# Bug#15208
|
|
|
|
if something == :==
|
|
|
|
do_something
|
|
|
|
end
|
2013-09-16 02:42:26 +03:00
|
|
|
|
2013-10-06 23:38:26 -04:00
|
|
|
# Example from http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html
|
|
|
|
d = 4 + 5 + # no '\' needed
|
|
|
|
6 + 7
|
|
|
|
|
|
|
|
# Example from http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html
|
|
|
|
e = 8 + 9 \
|
|
|
|
+ 10 # '\' needed
|
|
|
|
|
2013-10-06 03:46:28 +03:00
|
|
|
begin
|
|
|
|
foo
|
|
|
|
ensure
|
|
|
|
bar
|
|
|
|
end
|
|
|
|
|
2013-09-16 02:42:26 +03:00
|
|
|
# Bug#15369
|
2013-10-07 16:27:29 +03:00
|
|
|
MSG = 'Separate every 3 digits in the integer portion of a number' \
|
2013-10-05 14:37:08 -04:00
|
|
|
'with underscores(_).'
|
2013-10-06 03:46:28 +03:00
|
|
|
|
2013-10-06 23:38:26 -04:00
|
|
|
class C
|
|
|
|
def foo
|
|
|
|
self.end
|
|
|
|
D.new.class
|
|
|
|
end
|
|
|
|
end
|
2013-10-06 03:46:28 +03:00
|
|
|
|
|
|
|
a = foo(j, k) -
|
2013-10-06 23:38:26 -04:00
|
|
|
bar_tee
|
2013-10-06 03:46:28 +03:00
|
|
|
|
|
|
|
while a < b do # "do" is optional
|
|
|
|
foo
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "foo foo" \
|
2013-10-06 23:38:26 -04:00
|
|
|
"bar bar"
|
2013-10-06 04:21:51 +03:00
|
|
|
|
|
|
|
foo.
|
|
|
|
bar
|
|
|
|
|
2013-10-07 16:27:29 +03:00
|
|
|
# https://github.com/rails/rails/blob/17f5d8e062909f1fcae25351834d8e89967b645e/activesupport/lib/active_support/time_with_zone.rb#L206
|
2013-10-06 04:21:51 +03:00
|
|
|
foo
|
|
|
|
.bar
|
2013-10-07 16:27:29 +03:00
|
|
|
|
|
|
|
z = {
|
|
|
|
foo: {
|
|
|
|
a: "aaa",
|
|
|
|
b: "bbb"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-09 06:18:01 +03:00
|
|
|
foo if
|
|
|
|
bar
|
|
|
|
|
2013-10-11 05:11:37 +03:00
|
|
|
if foo?
|
|
|
|
bar
|
|
|
|
end
|
|
|
|
|
2013-10-14 04:51:20 +03:00
|
|
|
method arg1, # bug#15594
|
|
|
|
method2 arg2,
|
|
|
|
arg3
|
|
|
|
|
|
|
|
method? arg1,
|
|
|
|
arg2
|
|
|
|
|
|
|
|
method! arg1,
|
|
|
|
arg2
|
|
|
|
|
2013-10-21 07:50:06 +04:00
|
|
|
it "is a method call with block" do |asd|
|
|
|
|
foo
|
|
|
|
end
|
|
|
|
|
|
|
|
it("is too!") {
|
|
|
|
bar
|
|
|
|
}
|
|
|
|
|
|
|
|
and_this_one(has) { |block, parameters|
|
|
|
|
tee
|
|
|
|
}
|
|
|
|
|
2013-10-21 10:15:47 +04:00
|
|
|
if foo &&
|
2013-10-21 09:54:18 +04:00
|
|
|
bar
|
|
|
|
end
|
|
|
|
|
2013-10-07 16:27:29 +03:00
|
|
|
foo +
|
|
|
|
bar
|
|
|
|
|
2013-10-22 02:25:59 +04:00
|
|
|
foo_bar_tee(1, 2, 3)
|
|
|
|
.qux
|
|
|
|
.bar
|
|
|
|
|
2013-10-23 00:47:29 +04:00
|
|
|
foo do
|
|
|
|
bar
|
|
|
|
.tee
|
|
|
|
end
|
|
|
|
|
|
|
|
def bar
|
|
|
|
foo
|
|
|
|
.baz
|
|
|
|
end
|
|
|
|
|
2013-10-21 09:34:13 -04:00
|
|
|
# Examples below still fail with `ruby-use-smie' on:
|
|
|
|
|
2013-10-09 06:18:01 +03:00
|
|
|
foo = [1, 2, 3].map do |i|
|
|
|
|
i + 1
|
|
|
|
end
|
2013-10-11 23:45:14 +03:00
|
|
|
|
2013-10-14 04:51:20 +03:00
|
|
|
method !arg1,
|
|
|
|
arg2
|
|
|
|
|
2013-10-15 04:21:22 +03:00
|
|
|
method [],
|
2013-10-14 04:51:20 +03:00
|
|
|
arg2
|
|
|
|
|
|
|
|
method :foo,
|
|
|
|
:bar
|
|
|
|
|
|
|
|
method (a + b),
|
|
|
|
c
|
2013-10-22 02:25:59 +04:00
|
|
|
|
2013-10-23 00:47:29 +04:00
|
|
|
bar.foo do # "." is parent to "do"; it shouldn't be.
|
2013-10-22 02:25:59 +04:00
|
|
|
bar
|
|
|
|
end
|