Skip to content

Commit d85d366

Browse files
authored
Update rubocop / Introduce rubocop-performance, rubocop-minitest (#123)
* Update rubocop * NewCops: enable ``` Please also note that can also opt-in to new cops by default by adding this to your config: AllCops: NewCops: enable ``` * Add rubocop-performance * Fix rubocop-preformance offenses * Introduce rubocop-minitest * Fix rubocop-minitest offenses with `rubocop -a`
1 parent e5d721d commit d85d366

File tree

7 files changed

+29
-23
lines changed

7 files changed

+29
-23
lines changed

.rubocop.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
AllCops:
22
TargetRubyVersion: 2.4
3+
NewCops: enable
34
Exclude:
45
- "*.gemspec"
56
- "gemfiles/*"
67
- "vendor/**/*"
78
- Rakefile
89
- Gemfile
10+
require:
11+
- rubocop-performance
12+
- rubocop-minitest
913

1014
Metrics/MethodLength:
1115
Enabled: false

Gemfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ gem 'minitest-reporters'
77
gem 'minitest'
88
gem 'pry'
99
gem 'rake'
10-
gem 'rubocop', '~> 0.81'
10+
gem 'rubocop-minitest'
11+
gem 'rubocop-performance'
12+
gem 'rubocop'
1113
gem 'simplecov', '~> 0.17.1'

test/parser/test_inject_anchors_filter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ def test_injects_anchors_into_content
1818
def test_does_not_inject_toc
1919
html = @parser.inject_anchors_into_html
2020

21-
assert_nil(/<ul class="section-nav">/ =~ html)
21+
refute_includes(html, %(<ul class="section-nav">))
2222
end
2323
end

test/parser/test_ordered_list.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ class TestOrderedList < Minitest::Test
88
def test_default_configuration
99
configuration = Jekyll::TableOfContents::Configuration.new({})
1010

11-
assert_equal configuration.ordered_list, false
11+
refute(configuration.ordered_list)
1212
end
1313

1414
def test_disabled_ordered_list
1515
configuration = Jekyll::TableOfContents::Configuration.new('ordered_list' => false)
1616

17-
assert_equal configuration.ordered_list, false
17+
refute(configuration.ordered_list)
1818
end
1919

2020
def test_enabled_ordered_list
2121
configuration = Jekyll::TableOfContents::Configuration.new('ordered_list' => true)
2222

23-
assert_equal configuration.ordered_list, true
23+
assert(configuration.ordered_list)
2424
end
2525

2626
def test_basic_ordered_list_top_heading
@@ -57,7 +57,7 @@ def test_ordered_list_subheadings_with_classes_nested_structure
5757

5858
occurrences = html.scan(/<ol class="sublist-class">/).count
5959

60-
assert_equal occurrences, 5
60+
assert_equal(5, occurrences)
6161
end
6262

6363
private

test/parser/test_toc_only_filter.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ def setup
1212
def test_injects_toc_container
1313
html = @parser.build_toc
1414

15-
assert_match(/<ul class="section-nav">/, html)
15+
assert_includes(html, %(<ul class="section-nav">))
1616
end
1717

1818
def test_does_not_return_content
1919
html = @parser.build_toc
2020

21-
assert_nil(%r{<h1>Simple H1</h1>} =~ html)
21+
refute_includes(html, %(<h1>Simple H1</h1>))
2222
end
2323
end

test/test_configuration.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@ class TestConfiguration < Minitest::Test
66
def test_default_configuration
77
configuration = Jekyll::TableOfContents::Configuration.new({})
88

9-
assert_equal configuration.toc_levels, 1..6
10-
assert_equal configuration.ordered_list, false
11-
assert_equal configuration.no_toc_section_class, 'no_toc_section'
12-
assert_equal configuration.list_class, 'section-nav'
13-
assert_equal configuration.sublist_class, ''
14-
assert_equal configuration.item_class, 'toc-entry'
15-
assert_equal configuration.item_prefix, 'toc-'
9+
assert_equal(1..6, configuration.toc_levels)
10+
refute(configuration.ordered_list)
11+
assert_equal('no_toc_section', configuration.no_toc_section_class)
12+
assert_equal('section-nav', configuration.list_class)
13+
assert_equal('', configuration.sublist_class)
14+
assert_equal('toc-entry', configuration.item_class)
15+
assert_equal('toc-', configuration.item_prefix)
1616
end
1717

1818
def test_type_error
1919
configuration = Jekyll::TableOfContents::Configuration.new('TypeError!')
2020

21-
assert_equal configuration.toc_levels, 1..6
22-
assert_equal configuration.ordered_list, false
23-
assert_equal configuration.no_toc_section_class, 'no_toc_section'
24-
assert_equal configuration.list_class, 'section-nav'
25-
assert_equal configuration.sublist_class, ''
26-
assert_equal configuration.item_class, 'toc-entry'
27-
assert_equal configuration.item_prefix, 'toc-'
21+
assert_equal(1..6, configuration.toc_levels)
22+
refute(configuration.ordered_list)
23+
assert_equal('no_toc_section', configuration.no_toc_section_class)
24+
assert_equal('section-nav', configuration.list_class)
25+
assert_equal('', configuration.sublist_class)
26+
assert_equal('toc-entry', configuration.item_class)
27+
assert_equal('toc-', configuration.item_prefix)
2828
end
2929
end

test/test_toc_tag.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def test_toc_tag
1717
site: @stubbed_context1.new({ 'toc' => nil })
1818
)
1919
tag = Jekyll::TocTag.parse('toc_tag', '', Tokenizer.new(''), ParseContext.new)
20-
assert_equal tag.render(context), "<ul class=\"section-nav\">\n<li class=\"toc-entry toc-h1\"><a href=\"#test\">test</a></li>\n</ul>"
20+
assert_equal("<ul class=\"section-nav\">\n<li class=\"toc-entry toc-h1\"><a href=\"#test\">test</a></li>\n</ul>", tag.render(context))
2121
end
2222

2323
def test_toc_tag_returns_empty_string

0 commit comments

Comments
 (0)