| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
 | require_relative "../../rubocops/lines_cop"
describe RuboCop::Cop::FormulaAudit::Lines do
  subject(:cop) { described_class.new }
  it "reports an offense when using depends_on :automake" do
    expect_offense(<<~RUBY)
      class Foo < Formula
        url 'http://example.com/foo-1.0.tgz'
        depends_on :automake
        ^^^^^^^^^^^^^^^^^^^^ :automake is deprecated. Usage should be \"automake\".
      end
    RUBY
  end
  it "reports an offense when using depends_on :autoconf" do
    expect_offense(<<~RUBY)
      class Foo < Formula
        url 'http://example.com/foo-1.0.tgz'
        depends_on :autoconf
        ^^^^^^^^^^^^^^^^^^^^ :autoconf is deprecated. Usage should be \"autoconf\".
      end
    RUBY
  end
  it "reports an offense when using depends_on :libtool" do
    expect_offense(<<~RUBY)
      class Foo < Formula
        url 'http://example.com/foo-1.0.tgz'
        depends_on :libtool
        ^^^^^^^^^^^^^^^^^^^ :libtool is deprecated. Usage should be \"libtool\".
      end
    RUBY
  end
  it "reports an offense when using depends_on :apr" do
    expect_offense(<<~RUBY)
      class Foo < Formula
        url 'http://example.com/foo-1.0.tgz'
        depends_on :apr
        ^^^^^^^^^^^^^^^ :apr is deprecated. Usage should be \"apr-util\".
      end
    RUBY
  end
  it "reports an offense when using depends_on :tex" do
    expect_offense(<<~RUBY)
      class Foo < Formula
        url 'http://example.com/foo-1.0.tgz'
        depends_on :tex
        ^^^^^^^^^^^^^^^ :tex is deprecated.
      end
    RUBY
  end
end
describe RuboCop::Cop::FormulaAudit::ClassInheritance do
  subject(:cop) { described_class.new }
  it "reports an offense when not using spaces for class inheritance" do
    expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
      class Foo<Formula
                ^^^^^^^ Use a space in class inheritance: class Foo < Formula
        desc "foo"
        url 'http://example.com/foo-1.0.tgz'
      end
    RUBY
  end
end
describe RuboCop::Cop::FormulaAudit::Comments do
  subject(:cop) { described_class.new }
  context "When auditing formula" do
    it "commented cmake call" do
      expect_offense(<<~RUBY)
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          # system "cmake", ".", *std_cmake_args
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Please remove default template comments
        end
      RUBY
    end
    it "default template comments" do
      expect_offense(<<~RUBY)
        class Foo < Formula
          # PLEASE REMOVE
          ^^^^^^^^^^^^^^^ Please remove default template comments
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
        end
      RUBY
    end
    it "commented out depends_on" do
      expect_offense(<<~RUBY)
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          # depends_on "foo"
          ^^^^^^^^^^^^^^^^^^ Commented-out dependency "foo"
        end
      RUBY
    end
  end
end
describe RuboCop::Cop::FormulaAudit::AssertStatements do
  subject(:cop) { described_class.new }
  it "assert ...include usage" do
    expect_offense(<<~RUBY)
      class Foo < Formula
        desc "foo"
        url 'http://example.com/foo-1.0.tgz'
        assert File.read("inbox").include?("Sample message 1")
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `assert_match` instead of `assert ...include?`
      end
    RUBY
  end
  it "assert ...exist? without a negation" do
    expect_offense(<<~RUBY)
      class Foo < Formula
        desc "foo"
        url 'http://example.com/foo-1.0.tgz'
        assert File.exist? "default.ini"
               ^^^^^^^^^^^^^^^^^^^^^^^^^ Use `assert_predicate <path_to_file>, :exist?` instead of `assert File.exist? "default.ini"`
      end
    RUBY
  end
  it "assert ...exist? with a negation" do
    expect_offense(<<~RUBY)
      class Foo < Formula
        desc "foo"
        url 'http://example.com/foo-1.0.tgz'
        assert !File.exist?("default.ini")
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `refute_predicate <path_to_file>, :exist?` instead of `assert !File.exist?("default.ini")`
      end
    RUBY
  end
  it "assert ...executable? without a negation" do
    expect_offense(<<~RUBY)
      class Foo < Formula
        desc "foo"
        url 'http://example.com/foo-1.0.tgz'
        assert File.executable? f
               ^^^^^^^^^^^^^^^^^^ Use `assert_predicate <path_to_file>, :executable?` instead of `assert File.executable? f`
      end
    RUBY
  end
end
describe RuboCop::Cop::FormulaAudit::OptionDeclarations do
  subject(:cop) { described_class.new }
  it "unless build.without? conditional" do
    expect_offense(<<~RUBY)
      class Foo < Formula
        desc "foo"
        url 'http://example.com/foo-1.0.tgz'
        def post_install
          return unless build.without? "bar"
                        ^^^^^^^^^^^^^^^^^^^^ Use if build.with? "bar" instead of unless build.without? "bar"
        end
      end
    RUBY
  end
  it "unless build.with? conditional" do
    expect_offense(<<~RUBY)
      class Foo < Formula
        desc "foo"
        url 'http://example.com/foo-1.0.tgz'
        def post_install
          return unless build.with? "bar"
                        ^^^^^^^^^^^^^^^^^ Use if build.without? "bar" instead of unless build.with? "bar"
        end
      end
    RUBY
  end
  it "negated build.with? conditional" do
    expect_offense(<<~RUBY)
      class Foo < Formula
        desc "foo"
        url 'http://example.com/foo-1.0.tgz'
        def post_install
          return if !build.with? "bar"
                    ^^^^^^^^^^^^^^^^^^ Don't negate 'build.with?': use 'build.without?'
        end
      end
    RUBY
  end
  it "negated build.without? conditional" do
    expect_offense(<<~RUBY)
      class Foo < Formula
        desc "foo"
        url 'http://example.com/foo-1.0.tgz'
        def post_install
          return if !build.without? "bar"
                    ^^^^^^^^^^^^^^^^^^^^^ Don't negate 'build.without?': use 'build.with?'
        end
      end
    RUBY
  end
  it "unnecessary build.without? conditional" do
    expect_offense(<<~RUBY)
      class Foo < Formula
        desc "foo"
        url 'http://example.com/foo-1.0.tgz'
        def post_install
          return if build.without? "--without-bar"
                                    ^^^^^^^^^^^^^ Don't duplicate 'without': Use `build.without? \"bar\"` to check for \"--without-bar\"
        end
      end
    RUBY
  end
  it "unnecessary build.with? conditional" do
    expect_offense(<<~RUBY)
      class Foo < Formula
        desc "foo"
        url 'http://example.com/foo-1.0.tgz'
        def post_install
          return if build.with? "--with-bar"
                                 ^^^^^^^^^^ Don't duplicate 'with': Use `build.with? \"bar\"` to check for \"--with-bar\"
        end
      end
    RUBY
  end
  it "build.include? conditional" do
    expect_offense(<<~RUBY)
      class Foo < Formula
        desc "foo"
        url 'http://example.com/foo-1.0.tgz'
        def post_install
          return if build.include? "without-bar"
                                    ^^^^^^^^^^^ Use build.without? \"bar\" instead of build.include? 'without-bar'
        end
      end
    RUBY
  end
  it "build.include? with dashed args conditional" do
    expect_offense(<<~RUBY)
      class Foo < Formula
        desc "foo"
        url 'http://example.com/foo-1.0.tgz'
        def post_install
          return if build.include? "--bar"
                                    ^^^^^ Reference 'bar' without dashes
        end
      end
    RUBY
  end
  it "def options usage" do
    expect_offense(<<~RUBY)
      class Foo < Formula
        desc "foo"
        url 'http://example.com/foo-1.0.tgz'
        def options
        ^^^^^^^^^^^ Use new-style option definitions
          [["--bar", "desc"]]
        end
      end
    RUBY
  end
end
describe RuboCop::Cop::FormulaAudit::Miscellaneous do
  subject(:cop) { described_class.new }
  context "When auditing formula" do
    it "FileUtils usage" do
      expect_offense(<<~RUBY)
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          FileUtils.mv "hello"
          ^^^^^^^^^^^^^^^^^^^^ Don\'t need \'FileUtils.\' before mv
        end
      RUBY
    end
    it "long inreplace block vars" do
      expect_offense(<<~RUBY)
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          inreplace "foo" do |longvar|
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \"inreplace <filenames> do |s|\" is preferred over \"|longvar|\".
            somerandomCall(longvar)
          end
        end
      RUBY
    end
    it "an invalid rebuild statement" do
      expect_offense(<<~RUBY)
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          bottle do
            rebuild 0
            ^^^^^^^^^ 'rebuild 0' should be removed
            sha256 "fe0679b932dd43a87fd415b609a7fbac7a069d117642ae8ebaac46ae1fb9f0b3" => :sierra
          end
        end
      RUBY
    end
    it "OS.linux? check" do
      expect_offense(<<~RUBY, "/homebrew-core/")
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          bottle do
            if OS.linux?
               ^^^^^^^^^ Don\'t use OS.linux?; Homebrew/core only supports macOS
              nil
            end
            sha256 "fe0679b932dd43a87fd415b609a7fbac7a069d117642ae8ebaac46ae1fb9f0b3" => :sierra
          end
        end
      RUBY
    end
    it "fails_with :llvm block" do
      expect_offense(<<~RUBY)
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          bottle do
            sha256 "fe0679b932dd43a87fd415b609a7fbac7a069d117642ae8ebaac46ae1fb9f0b3" => :sierra
          end
          fails_with :llvm do
          ^^^^^^^^^^^^^^^^ 'fails_with :llvm' is now a no-op so should be removed
            build 2335
            cause "foo"
          end
        end
      RUBY
    end
    it "def test's deprecated usage" do
      expect_offense(<<~RUBY)
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          def test
          ^^^^^^^^ Use new-style test definitions (test do)
            assert_equals "1", "1"
          end
        end
      RUBY
    end
    it "with deprecated skip_clean call" do
      expect_offense(<<~RUBY)
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          skip_clean :all
          ^^^^^^^^^^^^^^^ `skip_clean :all` is deprecated; brew no longer strips symbols. Pass explicit paths to prevent Homebrew from removing empty folders.
        end
      RUBY
    end
    it "build.universal? deprecated usage" do
      expect_offense(<<~RUBY)
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          if build.universal?
             ^^^^^^^^^^^^^^^^ macOS has been 64-bit only since 10.6 so build.universal? is deprecated.
             "foo"
          end
        end
      RUBY
    end
    it "build.universal? deprecation exempted formula" do
      expect_no_offenses(<<~RUBY, "/homebrew-core/Formula/wine.rb")
        class Wine < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          if build.universal?
             "foo"
          end
        end
      RUBY
    end
    it "deprecated ENV.universal_binary usage" do
      expect_offense(<<~RUBY)
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          if build?
             ENV.universal_binary
             ^^^^^^^^^^^^^^^^^^^^ macOS has been 64-bit only since 10.6 so ENV.universal_binary is deprecated.
          end
        end
      RUBY
    end
    it "ENV.universal_binary deprecation exempted formula" do
      expect_no_offenses(<<~RUBY, "/homebrew-core/Formula/wine.rb")
        class Wine < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          if build?
            ENV.universal_binary
          end
        end
      RUBY
    end
    it "deprecated ENV.x11 usage" do
      expect_offense(<<~RUBY)
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          if build?
             ENV.x11
             ^^^^^^^ Use "depends_on :x11" instead of "ENV.x11"
          end
        end
      RUBY
    end
    it "install_name_tool usage instead of ruby-macho" do
      expect_offense(<<~RUBY)
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          system "install_name_tool", "-id"
                  ^^^^^^^^^^^^^^^^^ Use ruby-macho instead of calling "install_name_tool"
        end
      RUBY
    end
    it "ruby-macho alternatives audit exempted formula" do
      expect_no_offenses(<<~RUBY, "/homebrew-core/Formula/cctools.rb")
        class Cctools < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          system "install_name_tool", "-id"
        end
      RUBY
    end
    it "npm install without language::Node args" do
      expect_offense(<<~RUBY)
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          system "npm", "install"
          ^^^^^^^^^^^^^^^^^^^^^^^ Use Language::Node for npm install args
        end
      RUBY
    end
    it "npm install without language::Node args in kibana(exempted formula)" do
      expect_no_offenses(<<~RUBY, "/homebrew-core/Formula/kibana@4.4.rb")
        class KibanaAT44 < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          system "npm", "install"
        end
      RUBY
    end
    it "depends_on with an instance as argument" do
      expect_offense(<<~RUBY)
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          depends_on FOO::BAR.new
                     ^^^^^^^^^^^^ `depends_on` can take requirement classes instead of instances
        end
      RUBY
    end
    it "old style OS check" do
      expect_offense(<<~RUBY)
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          depends_on :foo if MacOS.snow_leopard?
                             ^^^^^^^^^^^^^^^^^^^ \"MacOS.snow_leopard?\" is deprecated, use a comparison to MacOS.version instead
        end
      RUBY
    end
    it "non glob DIR usage" do
      expect_offense(<<~RUBY)
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          rm_rf Dir["src/{llvm,test,librustdoc,etc/snapshot.pyc}"]
          rm_rf Dir["src/snapshot.pyc"]
                     ^^^^^^^^^^^^^^^^ Dir(["src/snapshot.pyc"]) is unnecessary; just use "src/snapshot.pyc"
        end
      RUBY
    end
    it "system call to fileUtils Method" do
      expect_offense(<<~RUBY)
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          system "mkdir", "foo"
                  ^^^^^ Use the `mkdir` Ruby method instead of `system "mkdir", "foo"`
        end
      RUBY
    end
    it "top-level function def outside class body" do
      expect_offense(<<~RUBY)
        def test
        ^^^^^^^^ Define method test in the class body, not at the top-level
           nil
        end
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
        end
      RUBY
    end
    it "Using ARGV to check options" do
      expect_no_offenses(<<~RUBY)
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          def install
            verbose = ARGV.verbose?
          end
        end
      RUBY
    end
    it 'man+"man8" usage' do
      expect_offense(<<~RUBY)
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          def install
            man1.install man+"man8" => "faad.1"
                              ^^^^ "man+"man8"" should be "man8"
          end
        end
      RUBY
    end
    it "hardcoded gcc compiler" do
      expect_offense(<<~'RUBY')
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          def install
            system "/usr/bin/gcc", "foo"
                    ^^^^^^^^^^^^ Use "#{ENV.cc}" instead of hard-coding "gcc"
          end
        end
      RUBY
    end
    it "hardcoded g++ compiler" do
      expect_offense(<<~'RUBY')
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          def install
            system "/usr/bin/g++", "-o", "foo", "foo.cc"
                    ^^^^^^^^^^^^ Use "#{ENV.cxx}" instead of hard-coding "g++"
          end
        end
      RUBY
    end
    it "hardcoded llvm-g++ compiler" do
      expect_offense(<<~'RUBY')
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          def install
            ENV["COMPILER_PATH"] = "/usr/bin/llvm-g++"
                                    ^^^^^^^^^^^^^^^^^ Use "#{ENV.cxx}" instead of hard-coding "llvm-g++"
          end
        end
      RUBY
    end
    it "hardcoded gcc compiler" do
      expect_offense(<<~RUBY)
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          def install
            ENV["COMPILER_PATH"] = "/usr/bin/gcc"
                                    ^^^^^^^^^^^^ Use \"\#{ENV.cc}\" instead of hard-coding \"gcc\"
          end
        end
      RUBY
    end
    it "formula path shortcut : man" do
      expect_offense(<<~'RUBY')
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          def install
            mv "#{share}/man", share
                         ^^^^ "#{share}/man" should be "#{man}"
          end
        end
      RUBY
    end
    it "formula path shortcut : libexec" do
      expect_offense(<<~'RUBY')
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          def install
            mv "#{prefix}/libexec", share
                          ^^^^^^^^ "#{prefix}/libexec" should be "#{libexec}"
          end
        end
      RUBY
    end
    it "formula path shortcut : info" do
      expect_offense(<<~'RUBY')
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          def install
            system "./configure", "--INFODIR=#{prefix}/share/info"
                                                       ^^^^^^ "#{prefix}/share" should be "#{share}"
                                                       ^^^^^^^^^^^ "#{prefix}/share/info" should be "#{info}"
          end
        end
      RUBY
    end
    it "formula path shortcut : man8" do
      expect_offense(<<~'RUBY')
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          def install
            system "./configure", "--MANDIR=#{prefix}/share/man/man8"
                                                      ^^^^^^ "#{prefix}/share" should be "#{share}"
                                                      ^^^^^^^^^^^^^^^ "#{prefix}/share/man/man8" should be "#{man8}"
          end
        end
      RUBY
    end
    it "dependecies which have to vendored" do
      expect_offense(<<~RUBY)
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          depends_on "lpeg" => :lua51
                                ^^^^^ lua modules should be vendored rather than use deprecated depends_on \"lpeg\" => :lua51`
        end
      RUBY
    end
    it "manually setting env" do
      expect_offense(<<~RUBY)
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          system "export", "var=value"
                  ^^^^^^ Use ENV instead of invoking 'export' to modify the environment
        end
      RUBY
    end
    it "dependencies with invalid options" do
      expect_offense(<<~RUBY)
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          depends_on "foo" => "with-bar"
                     ^^^^^^^^^^^^^^^^^^^ Dependency foo should not use option with-bar
        end
      RUBY
    end
    it "inspecting version manually" do
      expect_offense(<<~RUBY)
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          if version == "HEAD"
             ^^^^^^^^^^^^^^^^^ Use 'build.head?' instead of inspecting 'version'
            foo()
          end
        end
      RUBY
    end
    it "deprecated ARGV.include? (--HEAD) usage" do
      expect_offense(<<~RUBY)
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          test do
            head = ARGV.include? "--HEAD"
                                  ^^^^^^ Use "if build.head?" instead
                   ^^^^ Use build instead of ARGV to check options
          end
        end
      RUBY
    end
    it "deprecated needs :openmp usage" do
      expect_offense(<<~RUBY)
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          needs :openmp
          ^^^^^^^^^^^^^ 'needs :openmp' should be replaced with 'depends_on \"gcc\"'
        end
      RUBY
    end
    it "deprecated MACOS_VERSION const usage" do
      expect_offense(<<~RUBY)
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          test do
            version = MACOS_VERSION
                      ^^^^^^^^^^^^^ Use MacOS.version instead of MACOS_VERSION
          end
        end
      RUBY
    end
    it "deprecated if build.with? conditional dependency" do
      expect_offense(<<~RUBY)
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          depends_on "foo" if build.with? "foo"
          ^^^^^^^^^^^^^^^^ Replace depends_on "foo" if build.with? "foo" with depends_on "foo" => :optional
        end
      RUBY
    end
    it "unless conditional dependency with build.without?" do
      expect_offense(<<~RUBY)
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          depends_on :foo unless build.without? "foo"
          ^^^^^^^^^^^^^^^ Replace depends_on :foo unless build.without? "foo" with depends_on :foo => :recommended
        end
      RUBY
    end
    it "unless conditional dependency with build.include?" do
      expect_offense(<<~RUBY)
        class Foo < Formula
          desc "foo"
          url 'http://example.com/foo-1.0.tgz'
          depends_on :foo unless build.include? "without-foo"
          ^^^^^^^^^^^^^^^ Replace depends_on :foo unless build.include? "without-foo" with depends_on :foo => :recommended
        end
      RUBY
    end
  end
end
 |