rubocop 0.24.1 → 0.25.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rubocop might be problematic. Click here for more details.

Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +12 -8
  3. data/.travis.yml +1 -1
  4. data/CHANGELOG.md +42 -0
  5. data/Gemfile +2 -0
  6. data/README.md +27 -6
  7. data/bin/rubocop +10 -15
  8. data/config/default.yml +72 -25
  9. data/config/enabled.yml +57 -25
  10. data/lib/rubocop.rb +15 -8
  11. data/lib/rubocop/config_loader.rb +11 -7
  12. data/lib/rubocop/cop/cop.rb +16 -16
  13. data/lib/rubocop/cop/ignored_node.rb +11 -4
  14. data/lib/rubocop/cop/lint/block_alignment.rb +29 -4
  15. data/lib/rubocop/cop/lint/debugger.rb +8 -1
  16. data/lib/rubocop/cop/lint/def_end_alignment.rb +5 -1
  17. data/lib/rubocop/cop/lint/end_alignment.rb +5 -5
  18. data/lib/rubocop/cop/lint/end_in_method.rb +2 -2
  19. data/lib/rubocop/cop/lint/useless_setter_call.rb +2 -2
  20. data/lib/rubocop/cop/{style → metrics}/block_nesting.rb +1 -1
  21. data/lib/rubocop/cop/{style → metrics}/class_length.rb +4 -4
  22. data/lib/rubocop/cop/{style → metrics}/cyclomatic_complexity.rb +5 -16
  23. data/lib/rubocop/cop/{style → metrics}/line_length.rb +1 -1
  24. data/lib/rubocop/cop/{style → metrics}/method_length.rb +8 -4
  25. data/lib/rubocop/cop/{style → metrics}/parameter_lists.rb +1 -1
  26. data/lib/rubocop/cop/metrics/perceived_complexity.rb +61 -0
  27. data/lib/rubocop/cop/mixin/autocorrect_unless_changing_ast.rb +10 -2
  28. data/lib/rubocop/cop/mixin/code_length.rb +2 -3
  29. data/lib/rubocop/cop/mixin/configurable_naming.rb +6 -20
  30. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -1
  31. data/lib/rubocop/cop/mixin/if_node.rb +1 -1
  32. data/lib/rubocop/cop/mixin/method_complexity.rb +32 -0
  33. data/lib/rubocop/cop/mixin/negative_conditional.rb +1 -1
  34. data/lib/rubocop/cop/mixin/{check_methods.rb → on_method.rb} +3 -3
  35. data/lib/rubocop/cop/mixin/on_normal_if_unless.rb +24 -0
  36. data/lib/rubocop/cop/mixin/percent_literal.rb +2 -1
  37. data/lib/rubocop/cop/mixin/space_inside.rb +33 -4
  38. data/lib/rubocop/cop/mixin/statement_modifier.rb +14 -14
  39. data/lib/rubocop/cop/mixin/string_help.rb +4 -0
  40. data/lib/rubocop/cop/mixin/surrounding_space.rb +1 -0
  41. data/lib/rubocop/cop/rails/delegate.rb +2 -2
  42. data/lib/rubocop/cop/rails/output.rb +4 -2
  43. data/lib/rubocop/cop/style/accessor_method_name.rb +2 -2
  44. data/lib/rubocop/cop/style/align_hash.rb +9 -1
  45. data/lib/rubocop/cop/style/and_or.rb +37 -3
  46. data/lib/rubocop/cop/style/bare_percent_literals.rb +46 -0
  47. data/lib/rubocop/cop/style/block_end_newline.rb +56 -0
  48. data/lib/rubocop/cop/style/character_literal.rb +1 -1
  49. data/lib/rubocop/cop/style/def_with_parentheses.rb +2 -2
  50. data/lib/rubocop/cop/style/empty_lines_around_access_modifier.rb +31 -3
  51. data/lib/rubocop/cop/style/empty_lines_around_body.rb +6 -2
  52. data/lib/rubocop/cop/style/end_of_line.rb +3 -14
  53. data/lib/rubocop/cop/style/if_unless_modifier.rb +3 -6
  54. data/lib/rubocop/cop/style/if_with_semicolon.rb +6 -7
  55. data/lib/rubocop/cop/style/indentation_width.rb +3 -8
  56. data/lib/rubocop/cop/style/method_def_parentheses.rb +2 -2
  57. data/lib/rubocop/cop/style/method_name.rb +4 -18
  58. data/lib/rubocop/cop/style/multiline_block_layout.rb +73 -0
  59. data/lib/rubocop/cop/style/multiline_if_then.rb +4 -4
  60. data/lib/rubocop/cop/style/negated_if.rb +1 -1
  61. data/lib/rubocop/cop/style/negated_while.rb +2 -2
  62. data/lib/rubocop/cop/style/next.rb +12 -0
  63. data/lib/rubocop/cop/style/one_line_conditional.rb +6 -6
  64. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +22 -8
  65. data/lib/rubocop/cop/style/percent_q_literals.rb +53 -0
  66. data/lib/rubocop/cop/style/predicate_name.rb +2 -2
  67. data/lib/rubocop/cop/style/redundant_begin.rb +2 -2
  68. data/lib/rubocop/cop/style/redundant_return.rb +2 -2
  69. data/lib/rubocop/cop/style/rescue_modifier.rb +7 -3
  70. data/lib/rubocop/cop/style/single_line_methods.rb +2 -2
  71. data/lib/rubocop/cop/style/space_after_method_name.rb +2 -2
  72. data/lib/rubocop/cop/style/space_inside_block_braces.rb +14 -10
  73. data/lib/rubocop/cop/style/space_inside_brackets.rb +5 -1
  74. data/lib/rubocop/cop/style/string_literals.rb +5 -8
  75. data/lib/rubocop/cop/style/trailing_comma.rb +15 -3
  76. data/lib/rubocop/cop/style/trivial_accessors.rb +2 -2
  77. data/lib/rubocop/cop/style/unneeded_capital_w.rb +2 -4
  78. data/lib/rubocop/cop/style/unneeded_percent_q.rb +13 -0
  79. data/lib/rubocop/cop/style/variable_interpolation.rb +14 -2
  80. data/lib/rubocop/cop/style/variable_name.rb +17 -17
  81. data/lib/rubocop/cop/style/while_until_modifier.rb +2 -5
  82. data/lib/rubocop/cop/util.rb +5 -0
  83. data/lib/rubocop/cop/variable_force.rb +7 -6
  84. data/lib/rubocop/formatter/base_formatter.rb +2 -2
  85. data/lib/rubocop/processed_source.rb +5 -22
  86. data/lib/rubocop/version.rb +1 -1
  87. data/relnotes/v0.25.0.md +91 -0
  88. data/rubocop.gemspec +2 -3
  89. data/spec/project_spec.rb +1 -1
  90. data/spec/rubocop/cli_spec.rb +70 -44
  91. data/spec/rubocop/comment_config_spec.rb +6 -6
  92. data/spec/rubocop/config_loader_spec.rb +19 -13
  93. data/spec/rubocop/config_spec.rb +3 -3
  94. data/spec/rubocop/cop/commissioner_spec.rb +1 -1
  95. data/spec/rubocop/cop/cop_spec.rb +3 -3
  96. data/spec/rubocop/cop/lint/block_alignment_spec.rb +113 -6
  97. data/spec/rubocop/cop/lint/debugger_spec.rb +10 -6
  98. data/spec/rubocop/cop/lint/useless_assignment_spec.rb +12 -0
  99. data/spec/rubocop/cop/{style → metrics}/block_nesting_spec.rb +1 -1
  100. data/spec/rubocop/cop/{style → metrics}/class_length_spec.rb +1 -1
  101. data/spec/rubocop/cop/{style → metrics}/cyclomatic_complexity_spec.rb +1 -1
  102. data/spec/rubocop/cop/{style → metrics}/if_unless_modifier_spec.rb +2 -2
  103. data/spec/rubocop/cop/{style → metrics}/line_length_spec.rb +7 -7
  104. data/spec/rubocop/cop/{style → metrics}/method_length_spec.rb +1 -1
  105. data/spec/rubocop/cop/{style → metrics}/parameter_lists_spec.rb +1 -1
  106. data/spec/rubocop/cop/metrics/perceived_complexity_spec.rb +222 -0
  107. data/spec/rubocop/cop/{style → metrics}/while_until_modifier_spec.rb +2 -2
  108. data/spec/rubocop/cop/rails/output_spec.rb +8 -2
  109. data/spec/rubocop/cop/style/align_hash_spec.rb +7 -0
  110. data/spec/rubocop/cop/style/and_or_spec.rb +245 -43
  111. data/spec/rubocop/cop/style/bare_percent_literals_spec.rb +132 -0
  112. data/spec/rubocop/cop/style/block_end_newline_spec.rb +61 -0
  113. data/spec/rubocop/cop/style/empty_lines_around_access_modifier_spec.rb +34 -0
  114. data/spec/rubocop/cop/style/end_of_line_spec.rb +8 -0
  115. data/spec/rubocop/cop/style/guard_clause_spec.rb +1 -1
  116. data/spec/rubocop/cop/style/multiline_block_layout_spec.rb +138 -0
  117. data/spec/rubocop/cop/style/next_spec.rb +32 -3
  118. data/spec/rubocop/cop/style/percent_literal_delimiters_spec.rb +34 -0
  119. data/spec/rubocop/cop/style/percent_q_literals_spec.rb +122 -0
  120. data/spec/rubocop/cop/style/space_inside_block_braces_spec.rb +20 -0
  121. data/spec/rubocop/cop/style/space_inside_brackets_spec.rb +26 -2
  122. data/spec/rubocop/cop/style/trailing_comma_spec.rb +112 -0
  123. data/spec/rubocop/cop/style/unneeded_percent_q_spec.rb +86 -31
  124. data/spec/rubocop/cop/style/variable_interpolation_spec.rb +21 -1
  125. data/spec/rubocop/cop/team_spec.rb +14 -9
  126. data/spec/spec_helper.rb +1 -0
  127. metadata +47 -50
  128. data/lib/rubocop/cop/mixin/if_then_else.rb +0 -23
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.name = 'rubocop'
9
9
  s.version = RuboCop::Version::STRING
10
10
  s.platform = Gem::Platform::RUBY
11
- s.required_ruby_version = '>= 1.9.2'
11
+ s.required_ruby_version = '>= 1.9.3'
12
12
  s.authors = ['Bozhidar Batsov', 'Jonas Arvidsson', 'Yuji Nakayama']
13
13
  s.description = <<-EOF
14
14
  Automatic Ruby code style checking tool.
@@ -27,9 +27,8 @@ Gem::Specification.new do |s|
27
27
  s.summary = 'Automatic Ruby code style checking tool.'
28
28
 
29
29
  s.add_runtime_dependency('rainbow', '>= 1.99.1', '< 3.0')
30
- s.add_runtime_dependency('parser', '>= 2.2.0.pre.3', '< 3.0')
30
+ s.add_runtime_dependency('parser', '>= 2.2.0.pre.4', '< 3.0')
31
31
  s.add_runtime_dependency('powerpack', '~> 0.0.6')
32
- s.add_runtime_dependency('json', '>= 1.7.7', '< 2')
33
32
  s.add_runtime_dependency('ruby-progressbar', '~> 1.4')
34
33
  s.add_development_dependency('rake', '~> 10.1')
35
34
  s.add_development_dependency('rspec', '~> 3.0')
@@ -76,7 +76,7 @@ describe 'RuboCop Project' do
76
76
  it 'has a valid URL' do
77
77
  issues.each do |issue|
78
78
  number = issue[:number].gsub(/\D/, '')
79
- pattern = %r{^https://github\.com/bbatsov/rubocop/(?:issues|pull)/#{number}$} # rubocop:disable Style/LineLength
79
+ pattern = %r{^https://github\.com/bbatsov/rubocop/(?:issues|pull)/#{number}$} # rubocop:disable Metrics/LineLength
80
80
  expect(issue[:url]).to match(pattern)
81
81
  end
82
82
  end
@@ -95,12 +95,12 @@ describe RuboCop::CLI, :isolated_environment do
95
95
  ' class Bar',
96
96
  ' stuff = [',
97
97
  ' {',
98
- " some: 'hash',",
98
+ " some: 'hash'",
99
99
  ' },',
100
100
  ' {',
101
101
  " another: 'hash',",
102
102
  " with: 'more'",
103
- ' },',
103
+ ' }',
104
104
  ' ]',
105
105
  ' end',
106
106
  'end'].join("\n") + "\n")
@@ -197,12 +197,13 @@ describe RuboCop::CLI, :isolated_environment do
197
197
  create_file('example.rb', ['# encoding: utf-8',
198
198
  'class Dsl',
199
199
  'private',
200
- ' A = ["git", "path"]',
200
+ ' A = ["git", "path",]',
201
201
  'end'])
202
202
  expect(cli.run(%w(--auto-correct --format emacs))).to eq(1)
203
203
  expect(IO.read('example.rb')).to eq(['# encoding: utf-8',
204
204
  'class Dsl',
205
205
  ' private',
206
+ '',
206
207
  ' A = %w(git path)',
207
208
  'end'].join("\n") + "\n")
208
209
  e = abs('example.rb')
@@ -211,8 +212,11 @@ describe RuboCop::CLI, :isolated_environment do
211
212
  'comment.',
212
213
  "#{e}:3:1: C: [Corrected] Indent access modifiers like " \
213
214
  '`private`.',
215
+ "#{e}:3:1: C: [Corrected] Keep a blank line before and " \
216
+ 'after `private`.',
214
217
  "#{e}:3:3: W: Useless `private` access modifier.",
215
- "#{e}:3:3: C: Keep a blank line before and after `private`.",
218
+ "#{e}:3:3: C: [Corrected] Keep a blank line before and " \
219
+ 'after `private`.',
216
220
  "#{e}:4:7: C: [Corrected] Use `%w` or `%W` " \
217
221
  'for array of words.',
218
222
  "#{e}:4:8: C: [Corrected] Prefer single-quoted strings " \
@@ -221,6 +225,18 @@ describe RuboCop::CLI, :isolated_environment do
221
225
  "#{e}:4:15: C: [Corrected] Prefer single-quoted strings " \
222
226
  "when you don't need string interpolation or special " \
223
227
  'symbols.',
228
+ "#{e}:4:21: C: [Corrected] Avoid comma after the last item " \
229
+ 'of an array.',
230
+ "#{e}:5:7: C: [Corrected] Use `%w` or `%W` " \
231
+ 'for array of words.',
232
+ "#{e}:5:8: C: [Corrected] Prefer single-quoted strings " \
233
+ "when you don't need string interpolation or special " \
234
+ 'symbols.',
235
+ "#{e}:5:15: C: [Corrected] Prefer single-quoted strings " \
236
+ "when you don't need string interpolation or special " \
237
+ 'symbols.',
238
+ "#{e}:5:21: C: [Corrected] Avoid comma after the last item " \
239
+ 'of an array.',
224
240
  ''].join("\n"))
225
241
  end
226
242
 
@@ -498,19 +514,19 @@ describe RuboCop::CLI, :isolated_environment do
498
514
 
499
515
  it 'does not say [Corrected] if correction was avoided' do
500
516
  create_file('example.rb', ['# encoding: utf-8',
501
- 'func a and b',
517
+ 'a = c and b',
502
518
  'not a && b',
503
519
  'func a do b end'])
504
520
  expect(cli.run(%w(-a -f simple))).to eq(1)
505
521
  expect($stderr.string).to eq('')
506
522
  expect(IO.read('example.rb')).to eq(['# encoding: utf-8',
507
- 'func a and b',
523
+ 'a = c and b',
508
524
  'not a && b',
509
525
  'func a do b end',
510
526
  ''].join("\n"))
511
527
  expect($stdout.string)
512
528
  .to eq(['== example.rb ==',
513
- 'C: 2: 8: Use && instead of and.',
529
+ 'C: 2: 7: Use && instead of and.',
514
530
  'C: 3: 1: Use ! instead of not.',
515
531
  'C: 4: 8: Prefer {...} over do...end for single-line ' \
516
532
  'blocks.',
@@ -528,7 +544,7 @@ describe RuboCop::CLI, :isolated_environment do
528
544
  end
529
545
  expect($stderr.string).to eq('')
530
546
  expect(IO.read('example.rb')).to eq(['# encoding: utf-8',
531
- 'some_method(a,)',
547
+ 'some_method(a)',
532
548
  ''].join("\n"))
533
549
  end
534
550
 
@@ -541,26 +557,31 @@ describe RuboCop::CLI, :isolated_environment do
541
557
  end
542
558
  expect($stderr.string).to eq('')
543
559
  expect(IO.read('example.rb')).to eq(['# encoding: utf-8',
544
- 'puts [1,]',
560
+ 'puts [1]',
545
561
  ''].join("\n"))
546
562
  end
547
563
  end
548
564
 
549
565
  describe '--auto-gen-config' do
566
+ before(:each) do
567
+ RuboCop::Formatter::DisabledConfigFormatter
568
+ .config_to_allow_offenses = {}
569
+ end
570
+
550
571
  it 'overwrites an existing todo file' do
551
572
  create_file('example1.rb', ['# encoding: utf-8',
552
573
  'x= 0 ',
553
574
  '#' * 85,
554
575
  'y ',
555
576
  'puts x'])
556
- create_file('.rubocop_todo.yml', ['Style/LineLength:',
577
+ create_file('.rubocop_todo.yml', ['Metrics/LineLength:',
557
578
  ' Enabled: false'])
558
579
  create_file('.rubocop.yml', ['inherit_from: .rubocop_todo.yml'])
559
580
  expect(cli.run(['--auto-gen-config'])).to eq(1)
560
581
  expect(IO.readlines('.rubocop_todo.yml')[7..-1].map(&:chomp))
561
582
  .to eq(['# Offense count: 1',
562
583
  '# Configuration parameters: AllowURI.',
563
- 'Style/LineLength:',
584
+ 'Metrics/LineLength:',
564
585
  ' Max: 85',
565
586
  '',
566
587
  '# Offense count: 1',
@@ -620,6 +641,11 @@ describe RuboCop::CLI, :isolated_environment do
620
641
  '# versions of RuboCop, may require this file to be generated ' \
621
642
  'again.',
622
643
  '',
644
+ '# Offense count: 2',
645
+ '# Configuration parameters: AllowURI.',
646
+ 'Metrics/LineLength:',
647
+ ' Max: 90',
648
+ '',
623
649
  '# Offense count: 1',
624
650
  '# Cop supports --auto-correct.',
625
651
  'Style/CommentIndentation:',
@@ -635,11 +661,6 @@ describe RuboCop::CLI, :isolated_environment do
635
661
  'Style/IndentationConsistency:',
636
662
  ' Enabled: false',
637
663
  '',
638
- '# Offense count: 2',
639
- '# Configuration parameters: AllowURI.',
640
- 'Style/LineLength:',
641
- ' Max: 90',
642
- '',
643
664
  '# Offense count: 1',
644
665
  '# Cop supports --auto-correct.',
645
666
  'Style/SpaceAroundOperators:',
@@ -706,6 +727,7 @@ describe RuboCop::CLI, :isolated_environment do
706
727
  end
707
728
 
708
729
  it 'generates a todo list that removes the reports' do
730
+ RuboCop::Cop::Style::RegexpLiteral.slash_count = 0
709
731
  create_file('example.rb', ['# encoding: utf-8',
710
732
  'y.gsub!(%r{abc/xyz}, "#{x}")'])
711
733
  expect(cli.run(%w(--format emacs))).to eq(1)
@@ -724,8 +746,9 @@ describe RuboCop::CLI, :isolated_environment do
724
746
  'again.',
725
747
  '',
726
748
  '# Offense count: 1',
749
+ '# Configuration parameters: MaxSlashes.',
727
750
  'Style/RegexpLiteral:',
728
- ' MaxSlashes: 0']
751
+ ' Enabled: false']
729
752
  actual = IO.read('.rubocop_todo.yml').split($RS)
730
753
  expected.each_with_index do |line, ix|
731
754
  if line.is_a?(String)
@@ -978,7 +1001,7 @@ describe RuboCop::CLI, :isolated_environment do
978
1001
  let(:stdout) { $stdout.string }
979
1002
 
980
1003
  before do
981
- create_file('.rubocop.yml', ['Style/LineLength:',
1004
+ create_file('.rubocop.yml', ['Metrics/LineLength:',
982
1005
  ' Max: 110'])
983
1006
  expect { cli.run ['--show-cops'] + cop_list }.to exit_with_code(0)
984
1007
  end
@@ -1051,7 +1074,7 @@ describe RuboCop::CLI, :isolated_environment do
1051
1074
  end
1052
1075
 
1053
1076
  context 'with two cops given' do
1054
- let(:cop_list) { ['Style/Tab,Style/LineLength'] }
1077
+ let(:cop_list) { ['Style/Tab,Metrics/LineLength'] }
1055
1078
  include_examples :prints_config
1056
1079
  end
1057
1080
 
@@ -1446,18 +1469,18 @@ describe RuboCop::CLI, :isolated_environment do
1446
1469
 
1447
1470
  describe 'rubocop:disable comment' do
1448
1471
  it 'can disable all cops in a code section' do
1449
- create_file('example.rb',
1450
- ['# encoding: utf-8',
1451
- '# rubocop:disable all',
1452
- '#' * 90,
1453
- 'x(123456)',
1454
- 'y("123")',
1455
- 'def func',
1456
- ' # rubocop: enable Style/LineLength,Style/StringLiterals',
1457
- ' ' + '#' * 93,
1458
- ' x(123456)',
1459
- ' y("123")',
1460
- 'end'])
1472
+ src = ['# encoding: utf-8',
1473
+ '# rubocop:disable all',
1474
+ '#' * 90,
1475
+ 'x(123456)',
1476
+ 'y("123")',
1477
+ 'def func',
1478
+ ' # rubocop: enable Metrics/LineLength,Style/StringLiterals',
1479
+ ' ' + '#' * 93,
1480
+ ' x(123456)',
1481
+ ' y("123")',
1482
+ 'end']
1483
+ create_file('example.rb', src)
1461
1484
  expect(cli.run(['--format', 'emacs', 'example.rb'])).to eq(1)
1462
1485
  # all cops were disabled, then 2 were enabled again, so we
1463
1486
  # should get 2 offenses reported.
@@ -1478,13 +1501,16 @@ describe RuboCop::CLI, :isolated_environment do
1478
1501
  'x(123456)',
1479
1502
  'y("123")',
1480
1503
  'def func',
1481
- ' # rubocop: enable Style/LineLength, ' \
1504
+ ' # rubocop: enable Metrics/LineLength, ' \
1482
1505
  'Style/StringLiterals',
1483
1506
  ' ' + '#' * 93,
1484
1507
  ' x(123456)',
1485
1508
  ' y("123")',
1486
1509
  'end'])
1487
1510
  expect(cli.run(['--format', 'emacs', 'example.rb'])).to eq(1)
1511
+ expect($stderr.string)
1512
+ .to eq("#{abs('example.rb')}: Style/LineLength has the wrong " \
1513
+ "namespace - should be Metrics\n")
1488
1514
  # 3 cops were disabled, then 2 were enabled again, so we
1489
1515
  # should get 2 offenses reported.
1490
1516
  expect($stdout.string)
@@ -1506,9 +1532,9 @@ describe RuboCop::CLI, :isolated_environment do
1506
1532
  it 'can disable selected cops on a single line' do
1507
1533
  create_file('example.rb',
1508
1534
  ['# encoding: utf-8',
1509
- 'a' * 90 + ' # rubocop:disable Style/LineLength',
1535
+ 'a' * 90 + ' # rubocop:disable Metrics/LineLength',
1510
1536
  '#' * 95,
1511
- 'y("123") # rubocop:disable Style/LineLength,' \
1537
+ 'y("123") # rubocop:disable Metrics/LineLength,' \
1512
1538
  'Style/StringLiterals'
1513
1539
  ])
1514
1540
  expect(cli.run(['--format', 'emacs', 'example.rb'])).to eq(1)
@@ -1890,7 +1916,7 @@ describe RuboCop::CLI, :isolated_environment do
1890
1916
  create_file('rubocop.yml', ['Style/Encoding:',
1891
1917
  ' Enabled: false',
1892
1918
  '',
1893
- 'Style/LineLength:',
1919
+ 'Metrics/LineLength:',
1894
1920
  ' Enabled: false'
1895
1921
  ])
1896
1922
  result = cli.run(['--format', 'simple',
@@ -1928,7 +1954,7 @@ describe RuboCop::CLI, :isolated_environment do
1928
1954
  create_file('example_src/example1.rb', ['# encoding: utf-8',
1929
1955
  '#' * 90
1930
1956
  ])
1931
- create_file('example_src/.rubocop.yml', ['Style/LineLength:',
1957
+ create_file('example_src/.rubocop.yml', ['Metrics/LineLength:',
1932
1958
  ' Enabled: true',
1933
1959
  ' Max: 100'
1934
1960
  ])
@@ -1944,7 +1970,7 @@ describe RuboCop::CLI, :isolated_environment do
1944
1970
  '#' * 90
1945
1971
  ])
1946
1972
  end
1947
- create_file('example/src/.rubocop.yml', ['Style/LineLength:',
1973
+ create_file('example/src/.rubocop.yml', ['Metrics/LineLength:',
1948
1974
  ' Enabled: true',
1949
1975
  ' Max: 100'
1950
1976
  ])
@@ -1961,11 +1987,11 @@ describe RuboCop::CLI, :isolated_environment do
1961
1987
  create_file('example_src/example1.rb', ['# encoding: utf-8',
1962
1988
  '#' * 90
1963
1989
  ])
1964
- create_file('example_src/.rubocop.yml', ['Style/LineLength:',
1990
+ create_file('example_src/.rubocop.yml', ['Metrics/LineLength:',
1965
1991
  ' Enabled: true',
1966
1992
  ' Max: 100'
1967
1993
  ])
1968
- create_file("#{Dir.home}/.rubocop.yml", ['Style/LineLength:',
1994
+ create_file("#{Dir.home}/.rubocop.yml", ['Metrics/LineLength:',
1969
1995
  ' Enabled: true',
1970
1996
  ' Max: 80'
1971
1997
  ])
@@ -2100,14 +2126,14 @@ describe RuboCop::CLI, :isolated_environment do
2100
2126
  create_file('example/example1.rb', ['# encoding: utf-8',
2101
2127
  '#' * 90])
2102
2128
 
2103
- create_file('example/.rubocop.yml', ['Style/LineLength:',
2129
+ create_file('example/.rubocop.yml', ['Metrics/LineLength:',
2104
2130
  ' Enabled: true',
2105
2131
  ' Min: 10'])
2106
2132
 
2107
2133
  expect(cli.run(%w(--format simple example))).to eq(1)
2108
2134
  expect($stderr.string)
2109
- .to eq(['Warning: unrecognized parameter Style/LineLength:Min found ' \
2110
- 'in ' + abs('example/.rubocop.yml'),
2135
+ .to eq(['Warning: unrecognized parameter Metrics/LineLength:Min ' \
2136
+ 'found in ' + abs('example/.rubocop.yml'),
2111
2137
  ''].join("\n"))
2112
2138
  end
2113
2139
 
@@ -2145,7 +2171,7 @@ describe RuboCop::CLI, :isolated_environment do
2145
2171
  create_file('example/example1.rb', ['# encoding: utf-8',
2146
2172
  '#' * 90])
2147
2173
 
2148
- create_file('rubocop.yml', ['Style/LineLength:',
2174
+ create_file('rubocop.yml', ['Metrics/LineLength:',
2149
2175
  ' Severity: error'])
2150
2176
 
2151
2177
  cli.run(%w(--format simple -c rubocop.yml))
@@ -2162,7 +2188,7 @@ describe RuboCop::CLI, :isolated_environment do
2162
2188
  create_file('example/example1.rb', ['# encoding: utf-8',
2163
2189
  '#' * 90])
2164
2190
 
2165
- create_file('rubocop.yml', ['Style/LineLength:',
2191
+ create_file('rubocop.yml', ['Metrics/LineLength:',
2166
2192
  ' Severity: superbad'])
2167
2193
 
2168
2194
  cli.run(%w(--format simple -c rubocop.yml))
@@ -10,11 +10,11 @@ describe RuboCop::CommentConfig do
10
10
  [
11
11
  '# encoding: utf-8',
12
12
  '',
13
- '# rubocop:disable Style/MethodLength',
13
+ '# rubocop:disable Metrics/MethodLength',
14
14
  'def some_method',
15
15
  " puts 'foo'",
16
16
  'end',
17
- '# rubocop:enable Style/MethodLength',
17
+ '# rubocop:enable Metrics/MethodLength',
18
18
  '',
19
19
  '# rubocop:disable all',
20
20
  'some_method',
@@ -26,7 +26,7 @@ describe RuboCop::CommentConfig do
26
26
  '',
27
27
  'def some_method',
28
28
  " puts 'Disabling indented single line' # rubocop:disable " \
29
- 'Style/LineLength',
29
+ 'Metrics/LineLength',
30
30
  'end',
31
31
  '',
32
32
  'string = <<END',
@@ -35,7 +35,7 @@ describe RuboCop::CommentConfig do
35
35
  '',
36
36
  'foo # rubocop:disable Style/MethodCallParentheses',
37
37
  '',
38
- '# rubocop:enable Style/Void',
38
+ '# rubocop:enable Lint/Void',
39
39
  '',
40
40
  '# rubocop:disable Style/For',
41
41
  'foo'
@@ -51,7 +51,7 @@ describe RuboCop::CommentConfig do
51
51
 
52
52
  it 'supports disabling multiple lines with a pair of directive' do
53
53
  method_length_disabled_lines =
54
- disabled_lines_of_cop('Style/MethodLength')
54
+ disabled_lines_of_cop('Metrics/MethodLength')
55
55
  expected_part = (3..6).to_a
56
56
  expect(method_length_disabled_lines & expected_part)
57
57
  .to eq(expected_part)
@@ -77,7 +77,7 @@ describe RuboCop::CommentConfig do
77
77
  end
78
78
 
79
79
  it 'handles indented single line' do
80
- line_length_disabled_lines = disabled_lines_of_cop('Style/LineLength')
80
+ line_length_disabled_lines = disabled_lines_of_cop('Metrics/LineLength')
81
81
  expect(line_length_disabled_lines).to include(18)
82
82
  expect(line_length_disabled_lines).not_to include(19)
83
83
  end
@@ -161,14 +161,14 @@ describe RuboCop::ConfigLoader do
161
161
  create_file('dir/subdir/example.rb', '')
162
162
 
163
163
  create_file('.rubocop.yml',
164
- ['Style/LineLength:',
164
+ ['Metrics/LineLength:',
165
165
  ' Enabled: false',
166
166
  ' Max: 77'])
167
167
 
168
168
  create_file('dir/.rubocop.yml',
169
169
  ['inherit_from: ../.rubocop.yml',
170
170
  '',
171
- 'Style/MethodLength:',
171
+ 'Metrics/MethodLength:',
172
172
  ' Enabled: true',
173
173
  ' CountComments: false',
174
174
  ' Max: 10'
@@ -177,10 +177,10 @@ describe RuboCop::ConfigLoader do
177
177
  create_file(file_path,
178
178
  ['inherit_from: ../.rubocop.yml',
179
179
  '',
180
- 'Style/LineLength:',
180
+ 'Metrics/LineLength:',
181
181
  ' Enabled: true',
182
182
  '',
183
- 'Style/MethodLength:',
183
+ 'Metrics/MethodLength:',
184
184
  ' Max: 5'
185
185
  ])
186
186
  end
@@ -188,16 +188,16 @@ describe RuboCop::ConfigLoader do
188
188
  it 'returns the ancestor configuration plus local overrides' do
189
189
  config =
190
190
  default_config
191
- .merge('Style/LineLength' => {
191
+ .merge('Metrics/LineLength' => {
192
192
  'Description' =>
193
- default_config['Style/LineLength']['Description'],
193
+ default_config['Metrics/LineLength']['Description'],
194
194
  'Enabled' => true,
195
195
  'Max' => 77,
196
196
  'AllowURI' => true
197
197
  },
198
- 'Style/MethodLength' => {
198
+ 'Metrics/MethodLength' => {
199
199
  'Description' =>
200
- default_config['Style/MethodLength']['Description'],
200
+ default_config['Metrics/MethodLength']['Description'],
201
201
  'Enabled' => true,
202
202
  'CountComments' => false,
203
203
  'Max' => 5
@@ -213,13 +213,13 @@ describe RuboCop::ConfigLoader do
213
213
  create_file('example.rb', '')
214
214
 
215
215
  create_file('normal.yml',
216
- ['Style/MethodLength:',
216
+ ['Metrics/MethodLength:',
217
217
  ' Enabled: false',
218
218
  ' CountComments: true',
219
219
  ' Max: 80'])
220
220
 
221
221
  create_file('special.yml',
222
- ['Style/MethodLength:',
222
+ ['Metrics/MethodLength:',
223
223
  ' Enabled: false',
224
224
  ' Max: 200'])
225
225
 
@@ -228,7 +228,7 @@ describe RuboCop::ConfigLoader do
228
228
  ' - normal.yml',
229
229
  ' - special.yml',
230
230
  '',
231
- 'Style/MethodLength:',
231
+ 'Metrics/MethodLength:',
232
232
  ' Enabled: true'
233
233
  ])
234
234
  end
@@ -237,7 +237,7 @@ describe RuboCop::ConfigLoader do
237
237
  expected = { 'Enabled' => true, # overridden in .rubocop.yml
238
238
  'CountComments' => true, # only defined in normal.yml
239
239
  'Max' => 200 } # special.yml takes precedence
240
- expect(configuration_from_file['Style/MethodLength'].to_set)
240
+ expect(configuration_from_file['Metrics/MethodLength'].to_set)
241
241
  .to be_superset(expected.to_set)
242
242
  end
243
243
  end
@@ -260,6 +260,12 @@ describe RuboCop::ConfigLoader do
260
260
  'Enabled' => true
261
261
  )
262
262
  end
263
+
264
+ it 'returns an empty configuration loaded from an empty file' do
265
+ create_file(configuration_path, '')
266
+ configuration = load_file
267
+ expect(configuration).to eq({})
268
+ end
263
269
  end
264
270
 
265
271
  describe '.merge' do
@@ -300,7 +306,7 @@ describe RuboCop::ConfigLoader do
300
306
  context 'when a config file which does not mention SymbolArray exists' do
301
307
  it 'is disabled' do
302
308
  create_file('.rubocop.yml', [
303
- 'Style/LineLength:',
309
+ 'Metrics/LineLength:',
304
310
  ' Max: 80'
305
311
  ])
306
312
  expect(config.cop_enabled?('Style/SymbolArray')).to be_falsey