| 1 | if something_wrong? # ruby-move-to-block-skips-heredoc |
| 2 | ActiveSupport::Deprecation.warn(<<-eowarn) |
| 3 | boo hoo |
| 4 | end |
| 5 | eowarn |
| 6 | foo |
| 7 | end |
| 8 | |
| 9 | def foo |
| 10 | %^bar^ |
| 11 | end |
| 12 | |
| 13 | # Percent literals. |
| 14 | b = %Q{This is a "string"} |
| 15 | c = %w!foo |
| 16 | bar |
| 17 | baz! |
| 18 | d = %(hello (nested) world) |
| 19 | |
| 20 | # Don't propertize percent literals inside strings. |
| 21 | "(%s, %s)" % [123, 456] |
| 22 | |
| 23 | "abc/#{def}ghi" |
| 24 | "abc\#{def}ghi" |
| 25 | |
| 26 | # Or inside comments. |
| 27 | x = # "tot %q/to"; = |
| 28 | y = 2 / 3 |
| 29 | |
| 30 | # Regexp after whitelisted method. |
| 31 | "abc".sub /b/, 'd' |
| 32 | |
| 33 | # Don't mis-match "sub" at the end of words. |
| 34 | a = asub / aslb + bsub / bslb; |
| 35 | |
| 36 | # Highlight the regexp after "if". |
| 37 | x = toto / foo if /do bar/ =~ "dobar" |
| 38 | |
| 39 | # Regexp options are highlighted. |
| 40 | |
| 41 | /foo/xi != %r{bar}mo.tee |
| 42 | |
| 43 | bar(class: XXX) do # ruby-indent-keyword-label |
| 44 | foo |
| 45 | end |
| 46 | bar |
| 47 | |
| 48 | foo = [1, # ruby-deep-indent |
| 49 | 2] |
| 50 | |
| 51 | foo = { # ruby-deep-indent-disabled |
| 52 | a: b |
| 53 | } |
| 54 | |
| 55 | foo = { a: b, |
| 56 | a1: b1 |
| 57 | } |
| 58 | |
| 59 | foo({ # bug#16118 |
| 60 | a: b, |
| 61 | c: d |
| 62 | }) |
| 63 | |
| 64 | bar = foo( |
| 65 | a, [ |
| 66 | 1, |
| 67 | ], |
| 68 | :qux => [ |
| 69 | 3 |
| 70 | ]) |
| 71 | |
| 72 | foo( |
| 73 | [ |
| 74 | { |
| 75 | a: b |
| 76 | }, |
| 77 | ], |
| 78 | { |
| 79 | c: d |
| 80 | } |
| 81 | ) |
| 82 | |
| 83 | foo([{ |
| 84 | a: 2 |
| 85 | }, |
| 86 | { |
| 87 | b: 3 |
| 88 | }, |
| 89 | 4 |
| 90 | ]) |
| 91 | |
| 92 | foo = [ # ruby-deep-indent-disabled |
| 93 | 1 |
| 94 | ] |
| 95 | |
| 96 | foo( # ruby-deep-indent-disabled |
| 97 | a |
| 98 | ) |
| 99 | |
| 100 | # Multiline regexp. |
| 101 | /bars |
| 102 | tees # toots |
| 103 | nfoos/ |
| 104 | |
| 105 | def test1(arg) |
| 106 | puts "hello" |
| 107 | end |
| 108 | |
| 109 | def test2 (arg) |
| 110 | a = "apple" |
| 111 | |
| 112 | if a == 2 |
| 113 | puts "hello" |
| 114 | else |
| 115 | puts "there" |
| 116 | end |
| 117 | |
| 118 | if a == 2 then |
| 119 | puts "hello" |
| 120 | elsif a == 3 |
| 121 | puts "hello3" |
| 122 | elsif a == 3 then |
| 123 | puts "hello3" |
| 124 | else |
| 125 | puts "there" |
| 126 | end |
| 127 | |
| 128 | b = case a |
| 129 | when "a" |
| 130 | 6 |
| 131 | # Support for this syntax was removed in Ruby 1.9, so we |
| 132 | # probably don't need to handle it either. |
| 133 | # when "b" : |
| 134 | # 7 |
| 135 | # when "c" : 2 |
| 136 | when "d" then 4 |
| 137 | else 5 |
| 138 | end |
| 139 | end |
| 140 | |
| 141 | # Some Cucumber code: |
| 142 | Given /toto/ do |
| 143 | print "hello" |
| 144 | end |
| 145 | |
| 146 | # Bug#15208 |
| 147 | if something == :== |
| 148 | do_something |
| 149 | |
| 150 | return false unless method == :+ |
| 151 | x = y + z # Bug#16609 |
| 152 | |
| 153 | a = 1 ? 2 :( |
| 154 | 2 + 3 |
| 155 | ) |
| 156 | end |
| 157 | |
| 158 | # Bug#17097 |
| 159 | if x == :!= |
| 160 | something |
| 161 | end |
| 162 | |
| 163 | # Example from http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html |
| 164 | d = 4 + 5 + # no '\' needed |
| 165 | 6 + 7 |
| 166 | |
| 167 | # Example from http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html |
| 168 | e = 8 + 9 \ |
| 169 | + 10 # '\' needed |
| 170 | |
| 171 | foo = obj.bar { |m| tee(m) } + |
| 172 | obj.qux { |m| hum(m) } |
| 173 | |
| 174 | begin |
| 175 | foo |
| 176 | ensure |
| 177 | bar |
| 178 | end |
| 179 | |
| 180 | # Bug#15369 |
| 181 | MSG = 'Separate every 3 digits in the integer portion of a number' \ |
| 182 | 'with underscores(_).' |
| 183 | |
| 184 | class C |
| 185 | def foo |
| 186 | self.end |
| 187 | D.new.class |
| 188 | end |
| 189 | end |
| 190 | |
| 191 | a = foo(j, k) - |
| 192 | bar_tee |
| 193 | |
| 194 | while a < b do # "do" is optional |
| 195 | foo |
| 196 | end |
| 197 | |
| 198 | desc "foo foo" \ |
| 199 | "bar bar" |
| 200 | |
| 201 | foo. |
| 202 | bar |
| 203 | |
| 204 | # https://github.com/rails/rails/blob/17f5d8e062909f1fcae25351834d8e89967b645e/activesupport/lib/active_support/time_with_zone.rb#L206 |
| 205 | foo |
| 206 | .bar |
| 207 | |
| 208 | z = { |
| 209 | foo: { |
| 210 | a: "aaa", |
| 211 | b: "bbb" |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | foo if |
| 216 | bar |
| 217 | |
| 218 | if foo? |
| 219 | bar |
| 220 | end |
| 221 | |
| 222 | method arg1, # bug#15594 |
| 223 | method2 arg2, |
| 224 | arg3 |
| 225 | |
| 226 | method? arg1, |
| 227 | arg2 |
| 228 | |
| 229 | method! arg1, |
| 230 | arg2 |
| 231 | |
| 232 | method !arg1, |
| 233 | arg2 |
| 234 | |
| 235 | method [], |
| 236 | arg2 |
| 237 | |
| 238 | method :foo, |
| 239 | :bar |
| 240 | |
| 241 | method (a + b), |
| 242 | c, :d => :e, |
| 243 | f: g |
| 244 | |
| 245 | desc "abc", |
| 246 | defg |
| 247 | |
| 248 | it "is a method call with block" do |asd| |
| 249 | foo |
| 250 | end |
| 251 | |
| 252 | it("is too!") { |
| 253 | bar |
| 254 | .qux |
| 255 | } |
| 256 | |
| 257 | and_this_one(has) { |block, parameters| |
| 258 | tee |
| 259 | } |
| 260 | |
| 261 | if foo && |
| 262 | bar |
| 263 | end |
| 264 | |
| 265 | foo + |
| 266 | bar |
| 267 | |
| 268 | foo and |
| 269 | bar |
| 270 | |
| 271 | foo > bar && |
| 272 | tee < qux |
| 273 | |
| 274 | zux do |
| 275 | foo == bar and |
| 276 | tee == qux |
| 277 | end |
| 278 | |
| 279 | foo ^ |
| 280 | bar |
| 281 | |
| 282 | foo_bar_tee(1, 2, 3) |
| 283 | .qux.bar |
| 284 | .tee |
| 285 | |
| 286 | foo do |
| 287 | bar |
| 288 | .tee |
| 289 | end |
| 290 | |
| 291 | def bar |
| 292 | foo |
| 293 | .baz |
| 294 | end |
| 295 | |
| 296 | # http://stackoverflow.com/questions/17786563/emacs-ruby-mode-if-expressions-indentation |
| 297 | tee = if foo |
| 298 | bar |
| 299 | else |
| 300 | tee |
| 301 | end |
| 302 | |
| 303 | a = b { |
| 304 | c |
| 305 | } |
| 306 | |
| 307 | aa = bb do |
| 308 | cc |
| 309 | end |
| 310 | |
| 311 | foo :bar do |
| 312 | qux |
| 313 | end |
| 314 | |
| 315 | foo do |*args| |
| 316 | tee |
| 317 | end |
| 318 | |
| 319 | bar do |&block| |
| 320 | tee |
| 321 | end |
| 322 | |
| 323 | foo = [1, 2, 3].map do |i| |
| 324 | i + 1 |
| 325 | end |
| 326 | |
| 327 | bar.foo do |
| 328 | bar |
| 329 | end |
| 330 | |
| 331 | bar.foo(tee) do |
| 332 | bar |
| 333 | end |
| 334 | |
| 335 | bar.foo(tee) { |
| 336 | bar |
| 337 | } |
| 338 | |
| 339 | bar 1 do |
| 340 | foo 2 do |
| 341 | tee |
| 342 | end |
| 343 | end |
| 344 | |
| 345 | foo | |
| 346 | bar |
| 347 | |
| 348 | def qux |
| 349 | foo ||= begin |
| 350 | bar |
| 351 | tee |
| 352 | rescue |
| 353 | oomph |
| 354 | end |
| 355 | end |
| 356 | |
| 357 | private def foo |
| 358 | bar |
| 359 | end |
| 360 | |
| 361 | %^abc^ |
| 362 | ddd |
| 363 | |
| 364 | qux = foo.fee ? |
| 365 | bar : |
| 366 | tee |
| 367 | |
| 368 | zoo.keep.bar!( |
| 369 | {x: y, |
| 370 | z: t}) |
| 371 | |
| 372 | zoo |
| 373 | .lose( |
| 374 | q, p) |
| 375 | |
| 376 | a.records().map(&:b).zip( |
| 377 | foo) |
| 378 | |
| 379 | # FIXME: This is not consistent with the example below it, but this |
| 380 | # offset only happens if the colon is at eol, which wouldn't be often. |
| 381 | # Tokenizing `bar:' as `:bar =>' would be better, but it's hard to |
| 382 | # distinguish from a variable reference inside a ternary operator. |
| 383 | foo(bar: |
| 384 | tee) |
| 385 | |
| 386 | foo(:bar => |
| 387 | tee) |
| 388 | |
| 389 | {'a' => { |
| 390 | 'b' => 'c', |
| 391 | 'd' => %w(e f) |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | # Bug#17050 |
| 396 | |
| 397 | return render json: { |
| 398 | errors: { base: [message] }, |
| 399 | copying: copying |
| 400 | }, |
| 401 | status: 400 |
| 402 | |
| 403 | top test( |
| 404 | some, |
| 405 | top, |
| 406 | test) |
| 407 | |
| 408 | foo bar, { |
| 409 | tee: qux |
| 410 | } |