danger-toc 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 38ae0d61092888976e59f8da7acb132be0cd0284
4
- data.tar.gz: cfd1e2d33f51048d8565908142ffbd35d7fe4803
3
+ metadata.gz: 11cf1615f816fb91537d90ee61bf5e53123e1127
4
+ data.tar.gz: 8391ad24cabe41e7989ab2b8b154d3b6a45a900b
5
5
  SHA512:
6
- metadata.gz: ae85c1148f5440b7fc2bcb4843118ef32944688e38a5391478130bd325a038fdacea55467ddd2bc14218d314a2be042ca6b334e08d92aea64b82f6cd6585f909
7
- data.tar.gz: 38b99caf0a4a221a698e918c513b614a882e2c5268eaa9323d1552c2324468ff85368135cfa870d1cc83c053d19481ea5f9be18a0c372a3920a5a9936480d35d
6
+ metadata.gz: 6331b825f408b1c52a9b70cce3a1532c1df3e8cc469a3048b695edf6b6af973e028abb77af0ed2356202933fe26518c133262e5efc5f32fbbdb8c0c7aedec7cd
7
+ data.tar.gz: 6ff29b16f78ecb185a433c2ddc12f3c22e65d4424d2e7550938024600214c4dd9bf0cd6752156d85a294824ffa69000d5f0ca29c013b9e3d681662b50fa2e3a2
data/.gitignore CHANGED
@@ -3,3 +3,9 @@ pkg
3
3
  .idea/
4
4
  Gemfile.lock
5
5
  .yardoc
6
+
7
+ # ignore the Ruby Version manager
8
+ .rvmrc
9
+ .ruby-version
10
+ .ruby-gemset
11
+ .rbenv
data/.rubocop_todo.yml CHANGED
@@ -1,36 +1,17 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2017-11-05 10:44:59 -0500 using RuboCop version 0.51.0.
3
+ # on 2018-03-23 17:04:14 +0300 using RuboCop version 0.41.2.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 3
10
- # Cop supports --auto-correct.
11
- # Configuration parameters: EnforcedStyle, SupportedStyles.
12
- # SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent
13
- Layout/IndentHeredoc:
14
- Exclude:
15
- - 'lib/toc/plugin.rb'
16
- - 'spec/toc_spec.rb'
17
-
18
- # Offense count: 1
19
- Lint/DuplicateMethods:
20
- Exclude:
21
- - 'lib/toc/config.rb'
22
-
23
9
  # Offense count: 4
24
10
  Metrics/AbcSize:
25
- Max: 18
11
+ Max: 19
26
12
 
27
- # Offense count: 5
28
- # Configuration parameters: CountComments, ExcludedMethods.
29
- Metrics/BlockLength:
30
- Max: 69
31
-
32
- # Offense count: 20
33
- # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
13
+ # Offense count: 24
14
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
34
15
  # URISchemes: http, https
35
16
  Metrics/LineLength:
36
17
  Max: 119
@@ -40,28 +21,6 @@ Metrics/LineLength:
40
21
  Metrics/MethodLength:
41
22
  Max: 21
42
23
 
43
- # Offense count: 4
44
- # Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
45
- # AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
46
- Naming/FileName:
47
- Exclude:
48
- - 'Dangerfile'
49
- - 'Gemfile'
50
- - 'Guardfile'
51
- - 'danger-toc.gemspec'
52
-
53
- # Offense count: 2
54
- # Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist, MethodDefinitionMacros.
55
- # NamePrefix: is_, has_, have_
56
- # NamePrefixBlacklist: is_, has_, have_
57
- # NameWhitelist: is_a?
58
- # MethodDefinitionMacros: define_method, define_singleton_method
59
- Naming/PredicateName:
60
- Exclude:
61
- - 'spec/**/*'
62
- - 'lib/toc/markdown_file.rb'
63
- - 'lib/toc/plugin.rb'
64
-
65
24
  # Offense count: 6
66
25
  Style/Documentation:
67
26
  Exclude:
@@ -78,7 +37,7 @@ Style/DoubleNegation:
78
37
  Exclude:
79
38
  - 'lib/toc/markdown_file.rb'
80
39
 
81
- # Offense count: 2
40
+ # Offense count: 1
82
41
  # Configuration parameters: MinBodyLength.
83
42
  Style/GuardClause:
84
43
  Exclude:
@@ -90,3 +49,14 @@ Style/GuardClause:
90
49
  Style/ModuleFunction:
91
50
  Exclude:
92
51
  - 'lib/toc/config.rb'
52
+
53
+ # Offense count: 2
54
+ # Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist.
55
+ # NamePrefix: is_, has_, have_
56
+ # NamePrefixBlacklist: is_, has_, have_
57
+ # NameWhitelist: is_a?
58
+ Style/PredicateName:
59
+ Exclude:
60
+ - 'spec/**/*'
61
+ - 'lib/toc/markdown_file.rb'
62
+ - 'lib/toc/plugin.rb'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## Changelog
2
2
 
3
+ ### 0.1.1 (2018/03/27)
4
+
5
+ * [#3](https://github.com/dblock/danger-toc/issues/3): Configure "Table of Contents" header with `toc.header` - [@dblock](https://github.com/dblock).
6
+ * [#11](https://github.com/dblock/danger-toc/pull/11): Fix bug "undefined method #filename" in the method #toc_changes? - [@mr-dxdy](https://github.com/mr-dxdy).
7
+
3
8
  ### 0.1.0 (2017/11/5)
4
9
 
5
10
  * Initial public release - [@dblock](https://github.com/dblock).
data/README.md CHANGED
@@ -12,6 +12,7 @@ A plugin for [danger.systems](http://danger.systems) that makes sure your projec
12
12
  - [Configuration](#configuration)
13
13
  - [Methods and Attributes](#methods-and-attributes)
14
14
  - [toc.files](#tocfiles)
15
+ - [toc.header](#tocheader)
15
16
  - [toc.check](#toccheck)
16
17
  - [Contributing](#contributing)
17
18
  - [Copyright](#copyright)
@@ -34,10 +35,10 @@ Add `toc.check` to your Dangerfile. Make a pull request and see this plugin in a
34
35
 
35
36
  The plugin supports following configuration options:
36
37
 
37
- You can configure plugin using following code:
38
38
  ```ruby
39
39
  Danger::Toc.configure do |config|
40
40
  config.files = [ 'README.md' ]
41
+ config.header = 'Table of Contents'
41
42
  end
42
43
  ```
43
44
 
@@ -47,7 +48,11 @@ Methods and attributes from this plugin are available in your `Dangerfile` under
47
48
 
48
49
  #### toc.files
49
50
 
50
- List of files to ensure TOC in.
51
+ List of files to ensure TOC in, default is `README.md`.
52
+
53
+ #### toc.header
54
+
55
+ The Table of Contents header, without `#`, default is `Table of Contents`.
51
56
 
52
57
  #### toc.check
53
58
 
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'rubocop/rake_task'
4
4
 
5
5
  RSpec::Core::RakeTask.new(:specs)
6
6
 
7
- task default: %i[rubocop specs]
7
+ task default: %i(rubocop specs)
8
8
 
9
9
  task :spec do
10
10
  Rake::Task['specs'].invoke
data/danger-toc.gemspec CHANGED
@@ -28,6 +28,6 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency 'pry'
29
29
  spec.add_development_dependency 'rake', '~> 10.0'
30
30
  spec.add_development_dependency 'rspec', '~> 3.4'
31
- spec.add_development_dependency 'rubocop', '~> 0.41'
31
+ spec.add_development_dependency 'rubocop', '~> 0.41.0'
32
32
  spec.add_development_dependency 'yard', '~> 0.8'
33
33
  end
data/lib/toc/config.rb CHANGED
@@ -4,13 +4,21 @@ module Danger
4
4
  extend self
5
5
 
6
6
  attr_accessor :files
7
+ attr_accessor :header
7
8
 
9
+ # Files to process
8
10
  def files=(value)
9
11
  @files = value
10
12
  end
11
13
 
14
+ # Table of Contents Header
15
+ def header=(value)
16
+ @header = value
17
+ end
18
+
12
19
  def reset
13
20
  self.files = ['README.md']
21
+ self.header = 'Table of Contents'
14
22
  end
15
23
 
16
24
  reset
@@ -26,7 +26,7 @@ module Danger
26
26
  has_toc = false
27
27
  headers = []
28
28
  toc.each do |line|
29
- if !has_toc && line[:text] == 'Table of Contents' # TODO: make configurable
29
+ if !has_toc && line[:text] == Danger::Toc.config.header
30
30
  headers = [] # drop any headers prior to TOC
31
31
  has_toc = true
32
32
  else
data/lib/toc/extractor.rb CHANGED
@@ -11,7 +11,7 @@ module Danger
11
11
  end
12
12
 
13
13
  def convert(el)
14
- if el.type == :header && el.options[:raw_text] == 'Table of Contents'
14
+ if el.type == :header && el.options[:raw_text] == Danger::Toc.config.header
15
15
  @in_toc = true
16
16
  @toc_start = el.options[:location]
17
17
  elsif el.type == :header
@@ -1,3 +1,3 @@
1
1
  module Toc
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  end
data/lib/toc/plugin.rb CHANGED
@@ -29,10 +29,10 @@ module Danger
29
29
  is_toc_correct?
30
30
  end
31
31
 
32
- # Has the CHANGELOG file been modified?
32
+ # Has the README file been modified?
33
33
  # @return [boolean]
34
34
  def toc_changes?
35
- (git.modified_files & filename).any? || (git.added_files & filenames).any?
35
+ (git.modified_files & filenames).any? || (git.added_files & filenames).any?
36
36
  end
37
37
 
38
38
  # Is the TOC format correct?
@@ -50,7 +50,7 @@ module Danger
50
50
  Here's the expected TOC for #{filename}:
51
51
 
52
52
  ```markdown
53
- # Table of Contents
53
+ # #{Danger::Toc.config.header}
54
54
 
55
55
  #{toc_file.toc_from_headers.join("\n")}
56
56
  ```
data/spec/config_spec.rb CHANGED
@@ -7,22 +7,40 @@ describe Danger::Toc::Config do
7
7
 
8
8
  describe 'configure' do
9
9
  describe 'files' do
10
- context 'defailt' do
10
+ context 'default' do
11
11
  it 'assumes README.md' do
12
12
  expect(Danger::Toc.config.files).to eq ['README.md']
13
13
  end
14
14
  end
15
- context 'when valid' do
15
+ context 'custom value' do
16
16
  before do
17
17
  Danger::Toc.configure do |config|
18
18
  config.files = ['README.md', 'SOMETHING.md']
19
19
  end
20
20
  end
21
21
 
22
- it 'saves configuration' do
22
+ it 'is set' do
23
23
  expect(Danger::Toc.config.files).to eq ['README.md', 'SOMETHING.md']
24
24
  end
25
25
  end
26
26
  end
27
+ describe 'header' do
28
+ context 'default' do
29
+ it 'assumes Table of Contents' do
30
+ expect(Danger::Toc.config.header).to eq 'Table of Contents'
31
+ end
32
+ end
33
+ context 'custom value' do
34
+ before do
35
+ Danger::Toc.configure do |config|
36
+ config.header = 'Custom TOC'
37
+ end
38
+ end
39
+
40
+ it 'is set' do
41
+ expect(Danger::Toc.config.header).to eq 'Custom TOC'
42
+ end
43
+ end
44
+ end
27
45
  end
28
46
  end
@@ -0,0 +1,11 @@
1
+ # Prelude
2
+
3
+ The quick brown fox jumps over the lazy dog.
4
+
5
+ # Custom TOC
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,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Danger::Toc::MarkdownFile do
4
- describe 'README.md' do
4
+ describe 'danger-toc README' do
5
5
  let(:filename) { File.expand_path('../../../README.md', __FILE__) }
6
6
  subject do
7
7
  Danger::Toc::MarkdownFile.new(filename)
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Danger::Toc::MarkdownFile do
4
- describe 'ONE-SECTION.md' do
5
- let(:filename) { File.expand_path('../../fixtures/markdown_file/ONE-SECTION.md', __FILE__) }
4
+ describe 'with a single section' do
5
+ let(:filename) { File.expand_path('../../fixtures/markdown_file/one_section.md', __FILE__) }
6
6
  subject do
7
7
  Danger::Toc::MarkdownFile.new(filename)
8
8
  end
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Danger::Toc::MarkdownFile do
4
- describe 'ONE-SECTION-WITH-TOC-LEVEL.md' do
5
- let(:filename) { File.expand_path('../../fixtures/markdown_file/ONE-SECTION-WITH-TOC-LEVEL.md', __FILE__) }
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', __FILE__) }
6
6
  subject do
7
7
  Danger::Toc::MarkdownFile.new(filename)
8
8
  end
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Danger::Toc::MarkdownFile do
4
- describe 'ONE-SECTION-WITH-TOC.md' do
5
- let(:filename) { File.expand_path('../../fixtures/markdown_file/ONE-SECTION-WITH-TOC.md', __FILE__) }
4
+ describe 'one section with TOC' do
5
+ let(:filename) { File.expand_path('../../fixtures/markdown_file/one_section_with_toc.md', __FILE__) }
6
6
  subject do
7
7
  Danger::Toc::MarkdownFile.new(filename)
8
8
  end
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Danger::Toc::MarkdownFile do
4
- describe 'WITH-QUOTED-EXAMPLE.md' do
5
- let(:filename) { File.expand_path('../../fixtures/markdown_file/WITH-QUOTED-EXAMPLE.md', __FILE__) }
4
+ describe 'with a code example' do
5
+ let(:filename) { File.expand_path('../../fixtures/markdown_file/with_quoted_example.md', __FILE__) }
6
6
  subject do
7
7
  Danger::Toc::MarkdownFile.new(filename)
8
8
  end
data/spec/toc_spec.rb CHANGED
@@ -10,7 +10,7 @@ describe Danger::Toc do
10
10
  end
11
11
 
12
12
  describe 'with Dangerfile' do
13
- let(:filename) { File.expand_path('../fixtures/markdown_file/ONE-SECTION-WITH-TOC.md', __FILE__) }
13
+ let(:filename) { File.expand_path('../fixtures/markdown_file/one_section_with_toc.md', __FILE__) }
14
14
  let(:dangerfile) { testing_dangerfile }
15
15
  let(:toc) do
16
16
  dangerfile.toc.filenames = [filename]
@@ -18,6 +18,29 @@ describe Danger::Toc do
18
18
  end
19
19
  let(:status_report) { toc.status_report }
20
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
+
21
44
  context 'is_toc_correct?' do
22
45
  subject do
23
46
  toc.is_toc_correct?
@@ -46,7 +69,7 @@ describe Danger::Toc do
46
69
  end
47
70
 
48
71
  context 'with missing TOC' do
49
- let(:filename) { File.expand_path('../fixtures/markdown_file/ONE-SECTION.md', __FILE__) }
72
+ let(:filename) { File.expand_path('../fixtures/markdown_file/one_section.md', __FILE__) }
50
73
  it 'reports errors' do
51
74
  expect(subject).to be false
52
75
  expect(status_report[:errors]).to eq ["The #{filename} file is missing a TOC."]
@@ -65,7 +88,7 @@ MARKDOWN
65
88
  end
66
89
 
67
90
  context 'with invalid TOC' do
68
- let(:filename) { File.expand_path('../fixtures/markdown_file/ONE-SECTION-WITH-INVALID-TOC.md', __FILE__) }
91
+ let(:filename) { File.expand_path('../fixtures/markdown_file/one_section_with_invalid_toc.md', __FILE__) }
69
92
  it 'reports errors' do
70
93
  expect(subject).to be false
71
94
  expect(status_report[:errors]).to eq ["The TOC found in #{filename} doesn't match the sections of the file."]
@@ -82,6 +105,32 @@ MARKDOWN
82
105
  ]
83
106
  end
84
107
  end
108
+
109
+ context 'with a custom toc header' do
110
+ before do
111
+ Danger::Toc.configure do |config|
112
+ config.header = 'Custom TOC'
113
+ end
114
+ end
115
+
116
+ context 'with missing TOC' do
117
+ let(:filename) { File.expand_path('../fixtures/markdown_file/one_section.md', __FILE__) }
118
+ it 'reports errors' do
119
+ expect(subject).to be false
120
+ expect(status_report[:markdowns].first.message).to include "\n# Custom TOC\n"
121
+ end
122
+ end
123
+
124
+ context 'with a custom TOC' do
125
+ let(:filename) { File.expand_path('../fixtures/markdown_file/one_section_with_custom_toc.md', __FILE__) }
126
+ it 'has no complaints' do
127
+ expect(subject).to be true
128
+ expect(status_report[:errors]).to eq []
129
+ expect(status_report[:warnings]).to eq []
130
+ expect(status_report[:markdowns]).to eq []
131
+ end
132
+ end
133
+ end
85
134
  end
86
135
  end
87
136
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-toc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - dblock
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-06 00:00:00.000000000 Z
11
+ date: 2018-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -156,14 +156,14 @@ dependencies:
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: '0.41'
159
+ version: 0.41.0
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: '0.41'
166
+ version: 0.41.0
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: yard
169
169
  requirement: !ruby/object:Gem::Requirement
@@ -210,11 +210,12 @@ files:
210
210
  - lib/toc/markdown_file.rb
211
211
  - lib/toc/plugin.rb
212
212
  - spec/config_spec.rb
213
- - spec/fixtures/markdown_file/ONE-SECTION-WITH-INVALID-TOC.md
214
- - spec/fixtures/markdown_file/ONE-SECTION-WITH-TOC-LEVEL.md
215
- - spec/fixtures/markdown_file/ONE-SECTION-WITH-TOC.md
216
- - spec/fixtures/markdown_file/ONE-SECTION.md
217
- - spec/fixtures/markdown_file/WITH-QUOTED-EXAMPLE.md
213
+ - spec/fixtures/markdown_file/one_section.md
214
+ - spec/fixtures/markdown_file/one_section_with_custom_toc.md
215
+ - spec/fixtures/markdown_file/one_section_with_invalid_toc.md
216
+ - spec/fixtures/markdown_file/one_section_with_toc.md
217
+ - spec/fixtures/markdown_file/one_section_with_toc_level.md
218
+ - spec/fixtures/markdown_file/with_quoted_example.md
218
219
  - spec/markdown_file/danger_toc_readme_spec.rb
219
220
  - spec/markdown_file/one_section_spec.rb
220
221
  - spec/markdown_file/one_section_with_toc_level_spec.rb
@@ -242,17 +243,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
242
243
  version: '0'
243
244
  requirements: []
244
245
  rubyforge_project:
245
- rubygems_version: 2.6.12
246
+ rubygems_version: 2.6.11
246
247
  signing_key:
247
248
  specification_version: 4
248
249
  summary: A danger.systems plugin for your markdown TOC.
249
250
  test_files:
250
251
  - spec/config_spec.rb
251
- - spec/fixtures/markdown_file/ONE-SECTION-WITH-INVALID-TOC.md
252
- - spec/fixtures/markdown_file/ONE-SECTION-WITH-TOC-LEVEL.md
253
- - spec/fixtures/markdown_file/ONE-SECTION-WITH-TOC.md
254
- - spec/fixtures/markdown_file/ONE-SECTION.md
255
- - spec/fixtures/markdown_file/WITH-QUOTED-EXAMPLE.md
252
+ - spec/fixtures/markdown_file/one_section.md
253
+ - spec/fixtures/markdown_file/one_section_with_custom_toc.md
254
+ - spec/fixtures/markdown_file/one_section_with_invalid_toc.md
255
+ - spec/fixtures/markdown_file/one_section_with_toc.md
256
+ - spec/fixtures/markdown_file/one_section_with_toc_level.md
257
+ - spec/fixtures/markdown_file/with_quoted_example.md
256
258
  - spec/markdown_file/danger_toc_readme_spec.rb
257
259
  - spec/markdown_file/one_section_spec.rb
258
260
  - spec/markdown_file/one_section_with_toc_level_spec.rb