danger-jazzy 1.0.2 → 1.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db4b71747b0acf87ce07d1b553e8a8a22575506c
4
- data.tar.gz: 55ac443df45ae24bf49c03bca9f5aeb210a142c4
3
+ metadata.gz: b99f453de87c08e5609f3fd5d714600d9908dcd2
4
+ data.tar.gz: 43b3498db32cea77056c88bf2e4a2706e64e35b4
5
5
  SHA512:
6
- metadata.gz: 9d0d09d7462955ff4aec1b25d1af88804cdca4beb62b7c3aa0b396485dc5ce94f2af60cd6ebbfd3ec4af29a570946dd34c22176ec54ba6fafd0b25b4636a8e25
7
- data.tar.gz: b62f90b18fb9cffbdb10fc6bd11f6c1c9f838c0bb598253e5cd364089093b17f7a0679bd3cb15d811490f9ca3b4ff386bcfb4a1bcbc343334c277d128989eb3d
6
+ metadata.gz: 1729ec2ee260dfc2bd76ab05d3dd40c319622c55d7319f806b1e269c5047f8dece18394fdad9150ad206d16c10ff39ac81ed4d1e17a1e5bc4c048472ccdc866a
7
+ data.tar.gz: d319abe887ab76084131e7efe97db43ece579ad211866d182f7c4079e43ed3fc7fc8e2ab8ce40cd4c5543fe31c638f2915c827c4195ba6aacdfbae476ba1f741
@@ -22,3 +22,9 @@ Style/SpecialGlobalVars:
22
22
  Metrics/BlockLength:
23
23
  Exclude:
24
24
  - "**/*_spec.rb"
25
+
26
+ Metrics/LineLength:
27
+ Max: 90
28
+
29
+ Metrics/AbcSize:
30
+ Max: 20
data/README.md CHANGED
@@ -20,14 +20,14 @@ jazzy.check fail: :all</pre>
20
20
  jazzy.check warn: :modified</pre>
21
21
  </blockquote>
22
22
 
23
- <blockquote>Write a custom message for undocumented symbols in modified files.
23
+ <blockquote>Write custom handling for undocumented symbols in modified files.
24
24
  <pre>
25
25
  jazzy.undocumented.each do |item|
26
26
  message "You forgot to document this", file:item.file, line:item.line
27
27
  end</pre>
28
28
  </blockquote>
29
29
 
30
- <blockquote>Write a custom message for undocumented symbols in all files.
30
+ <blockquote>Write a custom handling for undocumented symbols in all files.
31
31
  <pre>
32
32
  jazzy.undocumented(:all).each do |item|
33
33
  message "You forgot to document this", file:item.file, line:item.line
@@ -39,6 +39,12 @@ end</pre>
39
39
 
40
40
  `path` - Path to the docs folder, defaults to 'docs/'.
41
41
 
42
+ `ignore` - List of files to ignore, defaults to [].
43
+
44
+ `message` - Message to display, defaults to `Undocumented symbol %<symbol>s in *%<file>s*`.
45
+
46
+ `inline_message` - Message to display inline, defaults to `Undocumented symbol %<symbol>s`.
47
+
42
48
 
43
49
  #### Methods
44
50
 
@@ -1,3 +1,3 @@
1
1
  module Jazzy
2
- VERSION = '1.0.2'.freeze
2
+ VERSION = '1.1.0'.freeze
3
3
  end
@@ -1,5 +1,4 @@
1
1
  module Danger
2
- # rubocop:disable Metrics/LineLength
3
2
  # This is a danger plugin to check for undocumented symbols via Jazzy.
4
3
  #
5
4
  # @example Fail on undocumented symbols in modified files.
@@ -29,14 +28,27 @@ module Danger
29
28
  # @see fwal/danger-jazzy
30
29
  # @tags jazzy, docs, documentation
31
30
  #
32
- # rubocop:enable Metrics/LineLength
33
31
  class DangerJazzy < Plugin
34
- DEFAULT_MESSAGE = 'Undocumented symbol.'.freeze
32
+ DEFAULT_MESSAGE = 'Undocumented symbol `%<symbol>s` in *%<file>s*'.freeze
33
+ DEFAULT_INLINE_MESSAGE = 'Undocumented symbol `%<symbol>s`'.freeze
35
34
 
36
35
  # Path to the docs folder, defaults to 'docs/'.
37
36
  # @return [String]
38
37
  attr_accessor :path
39
38
 
39
+ # List of files to ignore, defaults to [].
40
+ # @return [[String]]
41
+ attr_accessor :ignore
42
+
43
+ # Message to display, defaults to 'Undocumented symbol `%<symbol>s` in *%<file>s*'.
44
+ # @return [String]
45
+ attr_accessor :message
46
+
47
+ # Message to display inline,
48
+ # defaults to 'Undocumented symbol `%<symbol>s`'.
49
+ # @return [String]
50
+ attr_accessor :inline_message
51
+
40
52
  # Checks files for modified symbols.
41
53
  #
42
54
  # Takes a hash with the following keys:
@@ -79,6 +91,18 @@ module Danger
79
91
  @path || 'docs/'
80
92
  end
81
93
 
94
+ def ignored_files
95
+ @ignore || []
96
+ end
97
+
98
+ def message_template
99
+ @message || DEFAULT_MESSAGE
100
+ end
101
+
102
+ def inline_message_template
103
+ @inline_message || DEFAULT_INLINE_MESSAGE
104
+ end
105
+
82
106
  def undocumented_path
83
107
  File.join(docs_path, 'undocumented.json')
84
108
  end
@@ -90,6 +114,8 @@ module Danger
90
114
  def load_undocumented(scope)
91
115
  reader = UndocumentedReader.new(undocumented_path)
92
116
  @undocumented[scope] = reader.undocumented_symbols.select do |item|
117
+ next unless !item.nil? && item.file
118
+ next if ignored_files.include? item.file
93
119
  if scope == :modified
94
120
  files_of_interest.include?(item.file)
95
121
  else
@@ -108,15 +134,23 @@ module Danger
108
134
 
109
135
  def fail_check
110
136
  undocumented(fail_scope).each do |item|
111
- # rubocop:disable Style/SignalException
112
- fail DEFAULT_MESSAGE, file: item.file, line: item.line
113
- # rubocop:enable Style/SignalException
137
+ # rubocop:disable Style/SignalException, Style/GuardClause
138
+ if item.file.nil? || item.line.nil?
139
+ fail message_template % item.to_h
140
+ else
141
+ fail inline_message_template % item.to_h, file: item.file, line: item.line
142
+ end
143
+ # rubocop:enable Style/SignalException, Style/GuardClause
114
144
  end
115
145
  end
116
146
 
117
147
  def warn_check
118
148
  undocumented(warn_scope).each do |item|
119
- warn DEFAULT_MESSAGE, file: item.file, line: item.line
149
+ if item.file.nil? || item.line.nil?
150
+ warn message_template % item.to_h
151
+ else
152
+ warn inline_message_template % item.to_h, file: item.file, line: item.line
153
+ end
120
154
  end
121
155
  end
122
156
  end
@@ -26,7 +26,9 @@ module Danger
26
26
  end
27
27
 
28
28
  def item_file(item)
29
- path = Pathname.new(item['file'])
29
+ file = item['file']
30
+ return unless file
31
+ path = Pathname.new(file)
30
32
  path.relative_path_from(@working_path).to_s
31
33
  end
32
34
 
@@ -13,6 +13,34 @@
13
13
  "symbol": "MyStruct.handleThing()",
14
14
  "symbol_kind": "source.lang.swift.decl.function.method.instance",
15
15
  "warning": "undocumented"
16
+ },
17
+ {
18
+ "file": "/MyOtherFile.swift",
19
+ "line": 12,
20
+ "symbol": "MyStruct.handleThing()",
21
+ "symbol_kind": "source.lang.swift.decl.function.method.instance",
22
+ "warning": "other"
23
+ },
24
+ {
25
+ "file": "/MyExtensionFile.swift",
26
+ "line": null,
27
+ "symbol": "MyClass",
28
+ "symbol_kind": "source.lang.swift.decl.extension",
29
+ "warning": "undocumented"
30
+ },
31
+ {
32
+ "file": "/MyExtensionFile.swift",
33
+ "line": null,
34
+ "symbol": "MyClass",
35
+ "symbol_kind": "source.lang.swift.decl.extension",
36
+ "warning": "undocumented"
37
+ },
38
+ {
39
+ "file": null,
40
+ "line": null,
41
+ "symbol": null,
42
+ "symbol_kind": null,
43
+ "warning": "undocumented"
16
44
  }
17
45
  ],
18
46
  "source_directory": "/"
@@ -15,9 +15,11 @@ module Danger
15
15
  @my_plugin = @dangerfile.jazzy
16
16
  @default_message = 'Undocumented symbol.'
17
17
  @my_plugin.path = 'spec/fixtures'
18
+ @my_plugin.message = @default_message
19
+ @my_plugin.inline_message = @default_message
18
20
  end
19
21
 
20
- context 'changed files contains undocumented symbols' do
22
+ context 'containing changed files with undocumented symbols' do
21
23
  before do
22
24
  modified = Git::Diff::DiffFile.new(
23
25
  'base',
@@ -48,27 +50,27 @@ module Danger
48
50
  end
49
51
 
50
52
  it 'can find undocumented symbols in all files' do
51
- expect(@my_plugin.undocumented(:all).length).to eq(2)
53
+ expect(@my_plugin.undocumented(:all).length).to eq(4)
52
54
  end
53
55
 
54
- it 'fails on undocumented symbols only in modified files by default' do
56
+ it 'fails only in modified files by default' do
55
57
  @my_plugin.check
56
58
  expect(@dangerfile.status_report[:errors]).to eq([@default_message])
57
59
  end
58
60
 
59
- it 'does not warn on undocumented symbols by default' do
61
+ it 'does not warn by default' do
60
62
  @my_plugin.check
61
63
  expect(@dangerfile.status_report[:warnings]).to eq([])
62
64
  end
63
65
 
64
- it 'can fail on undocumented symbols in all files' do
66
+ it 'can fail in all files' do
65
67
  @my_plugin.check fail: :all
66
- expect(@dangerfile.status_report[:errors]).to eq([@default_message, @default_message])
68
+ expect(@dangerfile.status_report[:errors].length).to eq(4)
67
69
  end
68
70
 
69
- it 'can warn on undocumented symbols in all files' do
71
+ it 'can warn in all files' do
70
72
  @my_plugin.check warn: :all
71
- expect(@dangerfile.status_report[:warnings]).to eq([@default_message, @default_message])
73
+ expect(@dangerfile.status_report[:warnings].length).to eq(4)
72
74
  end
73
75
 
74
76
  it 'does not fail if there is no undocumented json' do
@@ -76,6 +78,34 @@ module Danger
76
78
  @my_plugin.check
77
79
  expect(@dangerfile.status_report[:errors]).to eq([])
78
80
  end
81
+
82
+ it 'ignores files listed in ignore' do
83
+ @my_plugin.ignore = ['MyFile.swift']
84
+ @my_plugin.check
85
+ expect(@dangerfile.status_report[:errors]).to eq([])
86
+ end
87
+
88
+ it 'uses templates for violations' do
89
+ @my_plugin.inline_message = '%<symbol>s in %<file>s'
90
+ @my_plugin.check
91
+ expect(@dangerfile.status_report[:errors]).to eq(
92
+ ['MyClass.doStuff() in MyFile.swift']
93
+ )
94
+ end
95
+
96
+ it 'can switch template' do
97
+ @my_plugin.ignore = ['MyFile.swift']
98
+ @my_plugin.message = '%<symbol>s in %<file>s'
99
+ @my_plugin.inline_message = '%<symbol>s'
100
+ @my_plugin.check fail: :all
101
+
102
+ fixture = [
103
+ 'MyStruct.handleThing()',
104
+ 'MyClass in MyExtensionFile.swift',
105
+ 'MyClass in MyExtensionFile.swift'
106
+ ]
107
+ expect(@dangerfile.status_report[:errors]).to eq(fixture)
108
+ end
79
109
  end
80
110
  end
81
111
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-jazzy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frederik Wallner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-11 00:00:00.000000000 Z
11
+ date: 2018-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger-plugin-api
@@ -223,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
223
  version: '0'
224
224
  requirements: []
225
225
  rubyforge_project:
226
- rubygems_version: 2.6.14
226
+ rubygems_version: 2.6.8
227
227
  signing_key:
228
228
  specification_version: 4
229
229
  summary: A danger plugin for validating documentation generated with jazzy