danger-toc 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/README.md +101 -15
  4. data/lib/toc/config.rb +57 -32
  5. data/lib/toc/constructors/kramdown_constructor.rb +5 -6
  6. data/lib/toc/constructors.rb +0 -4
  7. data/lib/toc/extractor.rb +2 -1
  8. data/lib/toc/gem_version.rb +1 -1
  9. data/lib/toc/markdown_file.rb +62 -22
  10. data/lib/toc/plugin.rb +53 -33
  11. metadata +43 -61
  12. data/.gitignore +0 -11
  13. data/.rspec +0 -2
  14. data/.rubocop.yml +0 -14
  15. data/.rubocop_todo.yml +0 -81
  16. data/.travis.yml +0 -14
  17. data/CONTRIBUTING.md +0 -125
  18. data/Dangerfile +0 -4
  19. data/Gemfile +0 -16
  20. data/Guardfile +0 -19
  21. data/RELEASING.md +0 -67
  22. data/Rakefile +0 -23
  23. data/danger-toc.gemspec +0 -23
  24. data/images/toc-missing.png +0 -0
  25. data/spec/config_spec.rb +0 -60
  26. data/spec/constructors_spec.rb +0 -23
  27. data/spec/fixtures/markdown_file/one_section.md +0 -5
  28. data/spec/fixtures/markdown_file/one_section_with_custom_toc.md +0 -11
  29. data/spec/fixtures/markdown_file/one_section_with_invalid_toc.md +0 -11
  30. data/spec/fixtures/markdown_file/one_section_with_toc.md +0 -11
  31. data/spec/fixtures/markdown_file/one_section_with_toc_level.md +0 -11
  32. data/spec/fixtures/markdown_file/one_section_with_underscore_in_name.md +0 -11
  33. data/spec/fixtures/markdown_file/with_quoted_example.md +0 -26
  34. data/spec/markdown_file/danger_toc_readme_spec.rb +0 -19
  35. data/spec/markdown_file/one_section_spec.rb +0 -28
  36. data/spec/markdown_file/one_section_with_toc_level_spec.rb +0 -28
  37. data/spec/markdown_file/one_section_with_toc_spec.rb +0 -28
  38. data/spec/markdown_file/with_quoted_example_spec.rb +0 -33
  39. data/spec/markdown_file/with_underscore_in_section_name_spec.rb +0 -32
  40. data/spec/spec_helper.rb +0 -38
  41. data/spec/toc_spec.rb +0 -134
@@ -1,11 +0,0 @@
1
- # Prelude
2
-
3
- The quick brown fox jumps over the lazy dog.
4
-
5
- # Table of Contents
6
-
7
- - [What is That?](#what-is-that)
8
-
9
- # What is This?
10
-
11
- The quick brown fox jumps over the lazy dog.
@@ -1,11 +0,0 @@
1
- # Prelude
2
-
3
- The quick brown fox jumps over the lazy dog.
4
-
5
- # Table of Contents
6
-
7
- - [What is This?](#what-is-this)
8
-
9
- # What is This?
10
-
11
- The quick brown fox jumps over the lazy dog.
@@ -1,11 +0,0 @@
1
- # Prelude
2
-
3
- The quick brown fox jumps over the lazy dog.
4
-
5
- ## Table of Contents
6
-
7
- - [What is This?](#what-is-this)
8
-
9
- ## What is This?
10
-
11
- The quick brown fox jumps over the lazy dog.
@@ -1,11 +0,0 @@
1
- # Prelude
2
-
3
- The quick brown fox jumps over the lazy dog.
4
-
5
- ## Table of Contents
6
-
7
- - [What_is_this?](#what_is_this)
8
-
9
- ## What_is_this?
10
-
11
- The quick brown fox jumps over the lazy dog.
@@ -1,26 +0,0 @@
1
- # Prelude
2
-
3
- The quick brown fox jumps over the lazy dog.
4
-
5
- # Table of Contents
6
-
7
- - [Example](#example)
8
- - [Conclusion](#conclusion)
9
-
10
- # Example
11
-
12
- The quick brown fox jumps over the lazy dog.
13
-
14
- ```ruby
15
- # one
16
-
17
- require 'danger-toc'
18
-
19
- # two
20
-
21
- require 'danger-toc'
22
- ```
23
-
24
- # Conclusion
25
-
26
- The quick brown fox jumps over the lazy dog.
@@ -1,19 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Danger::Toc::MarkdownFile do
4
- describe 'danger-toc README' do
5
- let(:filename) { File.expand_path('../../README.md', __dir__) }
6
- subject do
7
- Danger::Toc::MarkdownFile.new(filename)
8
- end
9
- it 'exists?' do
10
- expect(subject.exists?).to be true
11
- end
12
- it 'has_toc?' do
13
- expect(subject.has_toc?).to be true
14
- end
15
- it 'good?' do
16
- expect(subject.good?).to be true
17
- end
18
- end
19
- end
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Danger::Toc::MarkdownFile do
4
- describe 'with a single section' do
5
- let(:filename) { File.expand_path('../fixtures/markdown_file/one_section.md', __dir__) }
6
- subject do
7
- Danger::Toc::MarkdownFile.new(filename)
8
- end
9
- it 'exists?' do
10
- expect(subject.exists?).to be true
11
- end
12
- it 'has_toc?' do
13
- expect(subject.has_toc?).to be false
14
- end
15
- it 'toc' do
16
- expect(subject.toc).to be nil
17
- end
18
- it 'headers' do
19
- expect(subject.headers).to eq([{ depth: 0, id: 'what-is-this', text: 'What is This?' }])
20
- end
21
- it 'good?' do
22
- expect(subject.good?).to be false
23
- end
24
- it 'bad?' do
25
- expect(subject.bad?).to be true
26
- end
27
- end
28
- end
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Danger::Toc::MarkdownFile do
4
- describe 'one section that is not at the root level' do
5
- let(:filename) { File.expand_path('../fixtures/markdown_file/one_section_with_toc_level.md', __dir__) }
6
- subject do
7
- Danger::Toc::MarkdownFile.new(filename)
8
- end
9
- it 'exists?' do
10
- expect(subject.exists?).to be true
11
- end
12
- it 'has_toc?' do
13
- expect(subject.has_toc?).to be true
14
- end
15
- it 'toc' do
16
- expect(subject.toc).to eq(['- [What is This?](#what-is-this)'])
17
- end
18
- it 'headers' do
19
- expect(subject.headers).to eq([{ depth: 0, id: 'what-is-this', text: 'What is This?' }])
20
- end
21
- it 'good?' do
22
- expect(subject.good?).to be true
23
- end
24
- it 'bad?' do
25
- expect(subject.bad?).to be false
26
- end
27
- end
28
- end
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Danger::Toc::MarkdownFile do
4
- describe 'one section with TOC' do
5
- let(:filename) { File.expand_path('../fixtures/markdown_file/one_section_with_toc.md', __dir__) }
6
- subject do
7
- Danger::Toc::MarkdownFile.new(filename)
8
- end
9
- it 'exists?' do
10
- expect(subject.exists?).to be true
11
- end
12
- it 'has_toc?' do
13
- expect(subject.has_toc?).to be true
14
- end
15
- it 'toc' do
16
- expect(subject.toc).to eq(['- [What is This?](#what-is-this)'])
17
- end
18
- it 'headers' do
19
- expect(subject.headers).to eq([{ depth: 0, id: 'what-is-this', text: 'What is This?' }])
20
- end
21
- it 'good?' do
22
- expect(subject.good?).to be true
23
- end
24
- it 'bad?' do
25
- expect(subject.bad?).to be false
26
- end
27
- end
28
- end
@@ -1,33 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Danger::Toc::MarkdownFile do
4
- describe 'with a code example' do
5
- let(:filename) { File.expand_path('../fixtures/markdown_file/with_quoted_example.md', __dir__) }
6
- subject do
7
- Danger::Toc::MarkdownFile.new(filename)
8
- end
9
- it 'exists?' do
10
- expect(subject.exists?).to be true
11
- end
12
- it 'has_toc?' do
13
- expect(subject.has_toc?).to be true
14
- end
15
- it 'toc' do
16
- expect(subject.toc).to eq(['- [Example](#example)', '- [Conclusion](#conclusion)'])
17
- end
18
- it 'headers' do
19
- expect(subject.headers).to eq(
20
- [
21
- { depth: 0, id: 'example', text: 'Example' },
22
- { depth: 0, id: 'conclusion', text: 'Conclusion' }
23
- ]
24
- )
25
- end
26
- it 'good?' do
27
- expect(subject.good?).to be true
28
- end
29
- it 'bad?' do
30
- expect(subject.bad?).to be false
31
- end
32
- end
33
- end
@@ -1,32 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Danger::Toc::MarkdownFile do
4
- describe 'with a underscore in section name' do
5
- let(:filename) do
6
- File.expand_path('../fixtures/markdown_file/one_section_with_underscore_in_name.md', __dir__)
7
- end
8
-
9
- subject do
10
- Danger::Toc::MarkdownFile.new(filename)
11
- end
12
-
13
- it 'exists?' do
14
- expect(subject.exists?).to be true
15
- end
16
- it 'has_toc?' do
17
- expect(subject.has_toc?).to be true
18
- end
19
- it 'toc' do
20
- expect(subject.toc).to eq(['- [What_is_this?](#what_is_this)'])
21
- end
22
- it 'headers' do
23
- expect(subject.headers).to eq([{ depth: 0, id: 'what_is_this', text: 'What_is_this?' }])
24
- end
25
- it 'good?' do
26
- expect(subject.good?).to be true
27
- end
28
- it 'bad?' do
29
- expect(subject.bad?).to be false
30
- end
31
- end
32
- end
data/spec/spec_helper.rb DELETED
@@ -1,38 +0,0 @@
1
- require 'pathname'
2
- ROOT = Pathname.new(File.expand_path('..', __dir__))
3
- $LOAD_PATH.unshift((ROOT + 'lib').to_s)
4
- $LOAD_PATH.unshift((ROOT + 'spec').to_s)
5
-
6
- require 'bundler/setup'
7
- require 'pry'
8
-
9
- require 'rspec'
10
- require 'danger'
11
-
12
- RSpec.configure do |config|
13
- config.filter_gems_from_backtrace 'bundler'
14
- config.color = true
15
- config.tty = true
16
- end
17
-
18
- require 'danger_plugin'
19
-
20
- def testing_ui
21
- Cork::Board.new(silent: true)
22
- end
23
-
24
- def testing_env
25
- {
26
- 'HAS_JOSH_K_SEAL_OF_APPROVAL' => 'true',
27
- 'TRAVIS_PULL_REQUEST' => '800',
28
- 'TRAVIS_REPO_SLUG' => 'dblock/danger-toc',
29
- 'TRAVIS_COMMIT_RANGE' => '759adcbd0d8f...13c4dc8bb61d',
30
- 'DANGER_GITHUB_API_TOKEN' => '123sbdq54erfsd3422gdfio'
31
- }
32
- end
33
-
34
- # A stubbed out Dangerfile for use in tests
35
- def testing_dangerfile
36
- env = Danger::EnvironmentManager.new(testing_env)
37
- Danger::Dangerfile.new(env, testing_ui)
38
- end
data/spec/toc_spec.rb DELETED
@@ -1,134 +0,0 @@
1
- require File.expand_path('spec_helper', __dir__)
2
-
3
- describe Danger::Toc do
4
- after(:each) do
5
- Danger::Toc::Config.reset
6
- end
7
-
8
- it 'is a Danger plugin' do
9
- expect(Danger::DangerToc.new(nil)).to be_a Danger::Plugin
10
- end
11
-
12
- describe 'with Dangerfile' do
13
- let(:filename) { File.expand_path('fixtures/markdown_file/one_section_with_toc.md', __dir__) }
14
- let(:dangerfile) { testing_dangerfile }
15
- let(:toc) do
16
- dangerfile.toc.files = [filename]
17
- dangerfile.toc
18
- end
19
- let(:status_report) { toc.status_report }
20
-
21
- context 'toc_changes?' do
22
- it 'should find modified files' do
23
- allow(toc.git).to receive(:modified_files).and_return([filename])
24
- allow(toc.git).to receive(:added_files).and_return([])
25
-
26
- expect(toc).to be_toc_changes
27
- end
28
-
29
- it 'should find added files' do
30
- allow(toc.git).to receive(:modified_files).and_return([])
31
- allow(toc.git).to receive(:added_files).and_return([filename])
32
-
33
- expect(toc).to be_toc_changes
34
- end
35
-
36
- it 'should not found changed files' do
37
- allow(toc.git).to receive(:modified_files).and_return([])
38
- allow(toc.git).to receive(:added_files).and_return([])
39
-
40
- expect(toc).not_to be_toc_changes
41
- end
42
- end
43
-
44
- context 'is_toc_correct?' do
45
- subject do
46
- toc.is_toc_correct?
47
- end
48
-
49
- context 'without a file' do
50
- let(:filename) { 'does-not-exist' }
51
- it 'complains' do
52
- expect(subject).to be false
53
- expect(status_report[:errors]).to eq ['The does-not-exist file does not exist.']
54
- end
55
- end
56
-
57
- context 'with changes' do
58
- before do
59
- allow(toc.git).to receive(:modified_files).and_return([filename])
60
- allow(toc.git).to receive(:added_files).and_return([])
61
- end
62
-
63
- it 'has no complaints' do
64
- expect(subject).to be true
65
- expect(status_report[:errors]).to eq []
66
- expect(status_report[:warnings]).to eq []
67
- expect(status_report[:markdowns]).to eq []
68
- end
69
- end
70
-
71
- context 'with missing TOC' do
72
- let(:filename) { File.expand_path('fixtures/markdown_file/one_section.md', __dir__) }
73
- it 'reports errors' do
74
- expect(subject).to be false
75
- expect(status_report[:errors]).to eq ["The #{filename} file is missing a TOC."]
76
- expect(status_report[:warnings]).to eq []
77
- expect(status_report[:markdowns].map(&:message)).to eq [<<-MARKDOWN
78
- Here's the expected TOC for #{filename}:
79
-
80
- ```markdown
81
- # Table of Contents
82
-
83
- - [What is This?](#what-is-this)
84
- ```
85
- MARKDOWN
86
- ]
87
- end
88
- end
89
-
90
- context 'with invalid TOC' do
91
- let(:filename) { File.expand_path('fixtures/markdown_file/one_section_with_invalid_toc.md', __dir__) }
92
- it 'reports errors' do
93
- expect(subject).to be false
94
- expect(status_report[:errors]).to eq ["The TOC found in #{filename} doesn't match the sections of the file."]
95
- expect(status_report[:warnings]).to eq []
96
- expect(status_report[:markdowns].map(&:message)).to eq [<<-MARKDOWN
97
- Here's the expected TOC for #{filename}:
98
-
99
- ```markdown
100
- # Table of Contents
101
-
102
- - [What is This?](#what-is-this)
103
- ```
104
- MARKDOWN
105
- ]
106
- end
107
- end
108
-
109
- context 'with a custom toc header' do
110
- before do
111
- Danger::Toc.config.header = 'Custom TOC'
112
- end
113
-
114
- context 'with missing TOC' do
115
- let(:filename) { File.expand_path('fixtures/markdown_file/one_section.md', __dir__) }
116
- it 'reports errors' do
117
- expect(subject).to be false
118
- expect(status_report[:markdowns].first.message).to include "\n# Custom TOC\n"
119
- end
120
- end
121
-
122
- context 'with a custom TOC' do
123
- let(:filename) { File.expand_path('fixtures/markdown_file/one_section_with_custom_toc.md', __dir__) }
124
- it 'has no complaints' do
125
- expect(subject).to be true
126
- expect(status_report[:errors]).to eq []
127
- expect(status_report[:warnings]).to eq []
128
- expect(status_report[:markdowns]).to eq []
129
- end
130
- end
131
- end
132
- end
133
- end
134
- end