danger-wcc 0.0.3 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +22 -15
  3. data/danger-wcc.gemspec +3 -3
  4. data/lib/version.rb +1 -1
  5. data/lib/wcc/commit_lint.rb +2 -1
  6. data/lib/wcc/commit_lint/commit_check.rb +0 -1
  7. data/lib/wcc/commit_lint/empty_line_check.rb +0 -1
  8. data/lib/wcc/commit_lint/subject_cap_check.rb +0 -1
  9. data/lib/wcc/commit_lint/subject_length_check.rb +0 -1
  10. data/lib/wcc/commit_lint/subject_period_check.rb +0 -1
  11. data/lib/wcc/commit_lint/subject_words_check.rb +0 -1
  12. data/lib/wcc/defaults.reek +8 -8
  13. data/lib/wcc/dependencies.rb +100 -0
  14. data/lib/wcc/jshint.rb +2 -2
  15. data/lib/wcc/plugin.rb +30 -12
  16. data/lib/wcc/reek.rb +2 -2
  17. data/lib/wcc/rubocop_exceptions.rb +13 -8
  18. data/lib/wcc/todos.rb +5 -4
  19. data/lib/wcc/util/yarn_info.rb +84 -0
  20. data/lib/wcc/utils.rb +17 -5
  21. data/lib/wcc/yarn_deduplicate.rb +72 -0
  22. data/spec/fixtures/dependencies/package.json +112 -0
  23. data/spec/fixtures/dependencies/package.json.diff +28 -0
  24. data/spec/fixtures/dependencies/package.json_patch_bumps_minor.diff +13 -0
  25. data/spec/fixtures/dependencies/package.json_patch_bumps_minor.json +112 -0
  26. data/spec/fixtures/dependencies/package.json_second_level_effect.diff +17 -0
  27. data/spec/fixtures/dependencies/package.json_second_level_effect.json +133 -0
  28. data/spec/fixtures/dependencies/yarn.lock +19609 -0
  29. data/spec/fixtures/dependencies/yarn.lock_patch_bumps_minor.lock +19614 -0
  30. data/spec/fixtures/dependencies/yarn.lock_second_level_effect.lock +20022 -0
  31. data/spec/fixtures/dependencies/yarn_list_second_level_effect.txt +1243 -0
  32. data/spec/fixtures/dependencies/yarn_list_second_level_effect.txt.diff +141 -0
  33. data/spec/fixtures/dependencies/yarn_minor_version.diff +33 -0
  34. data/spec/fixtures/dependencies/yarn_minor_version.txt +1151 -0
  35. data/spec/fixtures/dependencies/yarn_old.txt +1152 -0
  36. data/spec/fixtures/dependencies/yarn_patch_bumps_minor.diff +28 -0
  37. data/spec/fixtures/exception_inline_disabled_rule.diff +12 -0
  38. data/spec/fixtures/rubocop_exception.rb +3 -0
  39. data/spec/fixtures/yarn_deduplicate/list.a.txt +293 -0
  40. data/spec/fixtures/yarn_deduplicate/list.b.txt +295 -0
  41. data/spec/fixtures/yarn_deduplicate/list.diff +11 -0
  42. data/spec/fixtures/yarn_deduplicate/yarn.lock +20031 -0
  43. data/spec/fixtures_helper.rb +0 -1
  44. data/spec/spec_helper.rb +1 -1
  45. data/spec/wcc/commit_lint_spec.rb +6 -10
  46. data/spec/wcc/dependencies_spec.rb +129 -0
  47. data/spec/wcc/github_spec.rb +13 -7
  48. data/spec/wcc/jshint_spec.rb +1 -1
  49. data/spec/wcc/plugin_spec.rb +22 -17
  50. data/spec/wcc/reek_spec.rb +1 -1
  51. data/spec/wcc/rubocop_exceptions_spec.rb +34 -15
  52. data/spec/wcc/todos_spec.rb +10 -10
  53. data/spec/wcc/utils_spec.rb +2 -2
  54. data/spec/wcc/yarn_deduplicate_spec.rb +57 -0
  55. data/spec/wcc_spec.rb +1 -1
  56. metadata +71 -10
@@ -1,4 +1,3 @@
1
-
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module FixturesHelper
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'pathname'
4
- ROOT = Pathname.new(File.expand_path('../../', __FILE__))
4
+ ROOT = Pathname.new(File.expand_path('..', __dir__))
5
5
  $LOAD_PATH.unshift((ROOT + 'lib').to_s)
6
6
  $LOAD_PATH.unshift((ROOT + 'spec').to_s)
7
7
 
@@ -4,7 +4,7 @@
4
4
  # https://github.com/jonallured/danger-commit_lint
5
5
  # which is licensed under the MIT License
6
6
 
7
- require File.expand_path('../../spec_helper', __FILE__)
7
+ require File.expand_path('../spec_helper', __dir__)
8
8
 
9
9
  TEST_MESSAGES = {
10
10
  subject_cap: 'this subject needs a capital',
@@ -16,7 +16,7 @@ TEST_MESSAGES = {
16
16
  'separating the subject and the body.",
17
17
  all_errors: "this is a really long subject and it even ends in a period.\n'\
18
18
  'Not to mention the missing empty line!",
19
- valid: "This is a valid message\n\nYou can tell because it meets all the '\
19
+ valid: "This is a valid message\n\nYou can tell because it meets all the '\
20
20
  'criteria and the linter does not complain."
21
21
  }.freeze
22
22
 
@@ -24,8 +24,6 @@ NOOP_MESSAGE = Danger::DangerWCC::CommitLint::NOOP_MESSAGE
24
24
  SUBJECT_LENGTH_CHECK_MESSAGE = 'Please limit commit subject line to 50 '\
25
25
  'characters.'
26
26
 
27
- # rubocop:enable Metrics/LineLength
28
-
29
27
  def report_counts(status_report)
30
28
  status_report.values.flatten.count
31
29
  end
@@ -132,7 +130,7 @@ module Danger
132
130
 
133
131
  checks.each do |check, _|
134
132
  commit = double(:commit,
135
- message: TEST_MESSAGES[check], sha: sha)
133
+ message: TEST_MESSAGES[check], sha: sha)
136
134
  allow(@git).to receive(:commits).and_return([commit])
137
135
 
138
136
  commit_lint disable: [check]
@@ -195,7 +193,7 @@ module Danger
195
193
 
196
194
  checks.each do |check, warning|
197
195
  commit = double(:commit,
198
- message: TEST_MESSAGES[check], sha: sha)
196
+ message: TEST_MESSAGES[check], sha: sha)
199
197
  allow(@git).to receive(:commits).and_return([commit])
200
198
 
201
199
  expect {
@@ -281,7 +279,7 @@ module Danger
281
279
 
282
280
  checks.each do |check, warning|
283
281
  commit = double(:commit,
284
- message: TEST_MESSAGES[check], sha: sha)
282
+ message: TEST_MESSAGES[check], sha: sha)
285
283
  allow(@git).to receive(:commits).and_return([commit])
286
284
 
287
285
  expect {
@@ -369,7 +367,7 @@ module Danger
369
367
 
370
368
  options.each_with_index do |(check, opts), i|
371
369
  commit = double(:commit,
372
- message: TEST_MESSAGES[:valid], sha: sha)
370
+ message: TEST_MESSAGES[:valid], sha: sha)
373
371
  allow(@git).to receive(:commits).and_return([commit])
374
372
 
375
373
  arg = {}
@@ -388,5 +386,3 @@ module Danger
388
386
  end
389
387
  end
390
388
  end
391
-
392
- # rubocop:enable Metrics/ClassLength
@@ -0,0 +1,129 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('../spec_helper', __dir__)
4
+
5
+ module Danger
6
+ describe Danger::DangerWCC do
7
+ before do
8
+ @dangerfile = testing_dangerfile
9
+ @my_plugin = @dangerfile.wcc
10
+ @git = @dangerfile.git
11
+ @github = @dangerfile.github
12
+
13
+ allow(@github).to receive(:html_link) do |text|
14
+ "<a href=\"github_html_link\">#{text}</a>"
15
+ end
16
+
17
+ allow(File).to receive(:exist?).and_call_original
18
+ allow(File).to receive(:read).and_call_original
19
+ allow(File).to receive(:exist?).with('yarn.lock')
20
+ .and_return(true)
21
+ allow(File).to receive(:readlines).with('yarn.lock')
22
+ .and_return(load_fixture('dependencies/yarn.lock').split("\n"))
23
+ allow(File).to receive(:read).with('package.json')
24
+ .and_return(load_fixture('dependencies/package.json'))
25
+ end
26
+
27
+ describe 'yarn dependencies' do
28
+ let(:subject) { Danger::DangerWCC::Dependencies.new(@my_plugin) }
29
+
30
+ it 'Errors when minor version changes' do
31
+ allow(subject).to receive(:run_and_diff)
32
+ .with(/yarn list/)
33
+ .and_return(load_fixture('dependencies/yarn_minor_version.diff'))
34
+ allow(@git).to receive(:diff)
35
+ .and_return([
36
+ load_diff(
37
+ 'spec/fixtures/dependencies/package.json',
38
+ 'dependencies/package.json'
39
+ )
40
+ ])
41
+
42
+ # act
43
+ subject.perform
44
+
45
+ expect(@dangerfile.violation_report[:warnings])
46
+ .to eq([Violation.new(
47
+ 'Dangerous change! react-instantsearch was updated '\
48
+ 'from 5.3.2 to 5.7.0 without a corresponding '\
49
+ 'change to package.json!',
50
+ false,
51
+ 'yarn.lock',
52
+ 15_613,
53
+ type: :error
54
+ )])
55
+ end
56
+
57
+ it 'Errors when patch bump causes minor version changes' do
58
+ allow(File).to receive(:readlines).with('yarn.lock')
59
+ .and_return(
60
+ load_fixture('dependencies/yarn.lock_patch_bumps_minor.lock')
61
+ .split("\n")
62
+ )
63
+
64
+ allow(subject).to receive(:run_and_diff)
65
+ .with(/yarn list/)
66
+ .and_return(load_fixture('dependencies/yarn_patch_bumps_minor.diff'))
67
+ allow(@git).to receive(:diff)
68
+ .and_return(
69
+ [
70
+ load_diff(
71
+ 'spec/fixtures/dependencies/'\
72
+ 'package.json_patch_bumps_minor.json',
73
+ 'dependencies/package.json_patch_bumps_minor'
74
+ )
75
+ ]
76
+ )
77
+
78
+ # act
79
+ subject.perform
80
+
81
+ expect(@dangerfile.violation_report[:warnings])
82
+ .to eq([Violation.new(
83
+ 'Dangerous change! lodash was updated '\
84
+ 'from 4.17.15 to 4.18.1 without a corresponding '\
85
+ 'change to package.json!',
86
+ false,
87
+ 'yarn.lock',
88
+ # make sure we pick out the right lodash! There's 3 of them.
89
+ 12_111,
90
+ type: :error
91
+ )])
92
+ end
93
+
94
+ it 'ignores all changes when top level major version changes' do
95
+ allow(File).to receive(:readlines).with('yarn.lock')
96
+ .and_return(
97
+ load_fixture('dependencies/yarn.lock_second_level_effect.lock')
98
+ .split("\n")
99
+ )
100
+ allow(File).to receive(:read).with('package.json')
101
+ .and_return(
102
+ load_fixture('dependencies/'\
103
+ 'package.json_second_level_effect.json')
104
+ )
105
+
106
+ allow(subject).to receive(:run_and_diff)
107
+ .with(/yarn list/)
108
+ .and_return(load_fixture(
109
+ 'dependencies/yarn_list_second_level_effect.txt.diff'
110
+ ))
111
+ allow(@git).to receive(:diff)
112
+ .and_return(
113
+ [
114
+ load_diff(
115
+ 'package.json',
116
+ 'dependencies/package.json_second_level_effect'
117
+ )
118
+ ]
119
+ )
120
+
121
+ # act
122
+ subject.perform
123
+
124
+ expect(@dangerfile.violation_report[:warnings].map(&:message))
125
+ .to eq([])
126
+ end
127
+ end
128
+ end
129
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require File.expand_path('../../spec_helper', __FILE__)
3
+ require File.expand_path('../spec_helper', __dir__)
4
4
  require 'webmock'
5
5
 
6
6
  module Danger
@@ -37,8 +37,10 @@ module Danger
37
37
  end
38
38
 
39
39
  it '#add_labels adds existing labels to issue' do
40
- stub = stub_request(:post,
41
- API_URL + '/repos/watermarkchurch/danger-wcc/issues/2/labels')
40
+ stub = stub_request(
41
+ :post,
42
+ API_URL + '/repos/watermarkchurch/danger-wcc/issues/2/labels'
43
+ )
42
44
  .with(body: '["backlog","bug","duplicate"]')
43
45
 
44
46
  # act
@@ -49,11 +51,15 @@ module Danger
49
51
  end
50
52
 
51
53
  it '#add_labels creates new labels before adding to issue' do
52
- stub = stub_request(:post,
53
- API_URL + '/repos/watermarkchurch/danger-wcc/labels')
54
+ stub = stub_request(
55
+ :post,
56
+ API_URL + '/repos/watermarkchurch/danger-wcc/labels'
57
+ )
54
58
  .with(body: '{"name":"new_label","color":"ffffff"}')
55
- stub_request(:post,
56
- API_URL + '/repos/watermarkchurch/danger-wcc/issues/2/labels')
59
+ stub_request(
60
+ :post,
61
+ API_URL + '/repos/watermarkchurch/danger-wcc/issues/2/labels'
62
+ )
57
63
  .with(body: '["backlog","new_label"]')
58
64
 
59
65
  # act
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require File.expand_path('../../spec_helper', __FILE__)
3
+ require File.expand_path('../spec_helper', __dir__)
4
4
 
5
5
  module Danger
6
6
  describe Danger::DangerWCC do
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require File.expand_path('../../spec_helper', __FILE__)
3
+ require File.expand_path('../spec_helper', __dir__)
4
4
 
5
5
  module Danger
6
6
  describe Danger::DangerWCC do
@@ -16,18 +16,24 @@ module Danger
16
16
  end
17
17
 
18
18
  describe 'all' do
19
- it 'runs all checks and passes default options' do
20
- Danger::DangerWCC::CHECKS.each do |check|
19
+ it 'runs all default and passes default options' do
20
+ %i[
21
+ rubocop_exceptions todos brakeman
22
+ dependencies yarn_deduplicate
23
+ ].each do |check|
21
24
  expect(@my_plugin).to receive(check)
22
25
  .with({})
23
26
  end
27
+ %i[commit_lint flay reek jshint].each do |check|
28
+ expect(@my_plugin).to_not receive(check)
29
+ end
24
30
 
25
31
  # act
26
32
  @my_plugin.all
27
33
  end
28
34
 
29
35
  it 'errors if all checks disabled' do
30
- disabled = Danger::DangerWCC::CHECKS
36
+ disabled = Danger::DangerWCC::DEFAULT_OPTIONS.keys
31
37
  options = disabled.each_with_object({}) { |v, h| h[v] = false; }
32
38
 
33
39
  # expect
@@ -42,20 +48,19 @@ module Danger
42
48
  end
43
49
 
44
50
  it 'runs only enabled checks' do
45
- enabled = %i[todos commit_lint]
46
- disabled =
47
- Danger::DangerWCC::CHECKS.reject do |check|
48
- enabled.include?(check)
49
- end
50
- options = disabled.each_with_object({}) { |v, h| h[v] = false; }
51
+ options = {
52
+ rubocop_exceptions: false,
53
+ yarn_deduplicate: false,
54
+ todos: false,
55
+ brakeman: false,
56
+ reek: true
57
+ }
51
58
 
52
59
  # expect
53
- enabled.each do |check|
54
- expect(@my_plugin).to receive(check)
55
- end
56
- disabled.each do |check|
57
- expect(@my_plugin).to_not receive(check)
58
- end
60
+ expect(@my_plugin).to receive(:reek)
61
+ expect(@my_plugin).to receive(:dependencies)
62
+ expect(@my_plugin).to_not receive(:rubocop_exceptions)
63
+ expect(@my_plugin).to_not receive(:commit_lint)
59
64
 
60
65
  # act
61
66
  @my_plugin.all options
@@ -63,7 +68,7 @@ module Danger
63
68
 
64
69
  it 'passes options' do
65
70
  options =
66
- Danger::DangerWCC::CHECKS.each_with_object({}) do |v, h|
71
+ Danger::DangerWCC::DEFAULT_OPTIONS.keys.each_with_object({}) do |v, h|
67
72
  h[v] = false
68
73
  end
69
74
  options[:commit_lint] = { test: { options: 1 } }
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require File.expand_path('../../spec_helper', __FILE__)
3
+ require File.expand_path('../spec_helper', __dir__)
4
4
 
5
5
  module Danger
6
6
  describe Danger::DangerWCC do
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require File.expand_path('../../spec_helper', __FILE__)
3
+ require File.expand_path('../spec_helper', __dir__)
4
4
 
5
5
  module Danger
6
6
  describe Danger::DangerWCC do
@@ -30,9 +30,9 @@ module Danger
30
30
  .to eq([Violation.new('Rubocop rule Rails/SomeRule disabled in '\
31
31
  '<a href="github_html_link">spec/fixtures/rubocop_exception.rb</a>'\
32
32
  " \nPlease provide an explanation why this rule was disabled.",
33
- false,
34
- 'spec/fixtures/rubocop_exception.rb',
35
- 5)])
33
+ false,
34
+ 'spec/fixtures/rubocop_exception.rb',
35
+ 5)])
36
36
  end
37
37
 
38
38
  it 'Errors when rubocop exception not reenabled' do
@@ -52,9 +52,28 @@ module Danger
52
52
  "\n\nThe rule was not reenabled!\n"\
53
53
  'Please add a `rubocop:enable` comment so the rule is disabled '\
54
54
  'for the minimal scope.',
55
- false,
55
+ false,
56
+ 'spec/fixtures/rubocop_exception.rb',
57
+ 10)])
58
+ end
59
+
60
+ it 'does not require reenabling for inline comments' do
61
+ allow(@git).to receive(:diff)
62
+ .and_return([load_diff(
56
63
  'spec/fixtures/rubocop_exception.rb',
57
- 10)])
64
+ 'exception_inline_disabled_rule'
65
+ )])
66
+
67
+ # act
68
+ @my_plugin.rubocop_exceptions
69
+
70
+ expect(@dangerfile.violation_report[:warnings])
71
+ .to eq([Violation.new('Rubocop rule Rails/SomeRule disabled in '\
72
+ '<a href="github_html_link">spec/fixtures/rubocop_exception.rb</a>'\
73
+ " \nPlease provide an explanation why this rule was disabled.",
74
+ false,
75
+ 'spec/fixtures/rubocop_exception.rb',
76
+ 40)])
58
77
  end
59
78
 
60
79
  it 'Messages when exception added with context' do
@@ -71,9 +90,9 @@ module Danger
71
90
  .to eq([Violation.new('Rubocop rule Metrics/LineLength disabled in '\
72
91
  '<a href="github_html_link">spec/fixtures/rubocop_exception.rb</a>'\
73
92
  " explanation:\n\t> Disabling because I want to.",
74
- false,
75
- 'spec/fixtures/rubocop_exception.rb',
76
- 15)])
93
+ false,
94
+ 'spec/fixtures/rubocop_exception.rb',
95
+ 15)])
77
96
  end
78
97
 
79
98
  it 'Messages when exception added with multiline context' do
@@ -92,9 +111,9 @@ module Danger
92
111
  ' explanation:'\
93
112
  "\n\t> I want to disable this because.."\
94
113
  "\n\t> I forgot the reasons.",
95
- false,
96
- 'spec/fixtures/rubocop_exception.rb',
97
- 30)])
114
+ false,
115
+ 'spec/fixtures/rubocop_exception.rb',
116
+ 30)])
98
117
  end
99
118
 
100
119
  it 'Messages when exception added in between existing comments' do
@@ -112,9 +131,9 @@ module Danger
112
131
  '<a href="github_html_link">spec/fixtures/rubocop_exception.rb</a>'\
113
132
  ' explanation:'\
114
133
  "\n\t> here is my comment why we are disabling ABC",
115
- false,
116
- 'spec/fixtures/rubocop_exception.rb',
117
- 21)])
134
+ false,
135
+ 'spec/fixtures/rubocop_exception.rb',
136
+ 21)])
118
137
  end
119
138
 
120
139
  it 'Does not message when no exception added' do
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require File.expand_path('../../spec_helper', __FILE__)
3
+ require File.expand_path('../spec_helper', __dir__)
4
4
 
5
5
  module Danger
6
6
  describe Danger::DangerWCC do
@@ -27,9 +27,9 @@ module Danger
27
27
  .to eq([Violation.new('TODO added in '\
28
28
  '<a href="github_html_link">spec/fixtures/todo.rb</a>'\
29
29
  ' - is there a card associated with that?',
30
- false,
31
- 'spec/fixtures/todo.rb',
32
- 9)])
30
+ false,
31
+ 'spec/fixtures/todo.rb',
32
+ 9)])
33
33
  end
34
34
 
35
35
  it 'Does not warn when TODO removed' do
@@ -68,9 +68,9 @@ module Danger
68
68
  '<a href="github_html_link">spec/fixtures/todo.rb</a> '\
69
69
  'referencing [https://zube.io/watermark/asdf1234]'\
70
70
  '(https://zube.io/watermark/asdf1234)',
71
- false,
72
- 'spec/fixtures/todo.rb',
73
- 13)])
71
+ false,
72
+ 'spec/fixtures/todo.rb',
73
+ 13)])
74
74
  end
75
75
 
76
76
  it 'Sends message when todo below link' do
@@ -87,9 +87,9 @@ module Danger
87
87
  '<a href="github_html_link">spec/fixtures/todo.rb</a> '\
88
88
  'referencing [https://www.github.com/watermarkchurch/asdf/1234]'\
89
89
  '(https://www.github.com/watermarkchurch/asdf/1234)',
90
- false,
91
- 'spec/fixtures/todo.rb',
92
- 18)])
90
+ false,
91
+ 'spec/fixtures/todo.rb',
92
+ 18)])
93
93
  end
94
94
  end
95
95
  end