danger-wcc 0.0.2
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 +7 -0
- data/.circleci/config.yml +46 -0
- data/.gitignore +6 -0
- data/.rubocop.yml +219 -0
- data/.ruby-version +1 -0
- data/.travis.yml +12 -0
- data/Dangerfile +5 -0
- data/Gemfile +6 -0
- data/Guardfile +35 -0
- data/LICENSE +201 -0
- data/README.md +2 -0
- data/Rakefile +25 -0
- data/danger-wcc.gemspec +58 -0
- data/lib/danger_plugin.rb +3 -0
- data/lib/version.rb +5 -0
- data/lib/wcc/commit_lint.rb +158 -0
- data/lib/wcc/commit_lint/README.md +3 -0
- data/lib/wcc/commit_lint/commit_check.rb +19 -0
- data/lib/wcc/commit_lint/empty_line_check.rb +22 -0
- data/lib/wcc/commit_lint/subject_cap_check.rb +22 -0
- data/lib/wcc/commit_lint/subject_length_check.rb +28 -0
- data/lib/wcc/commit_lint/subject_period_check.rb +22 -0
- data/lib/wcc/commit_lint/subject_words_check.rb +22 -0
- data/lib/wcc/default.jshintrc +5 -0
- data/lib/wcc/defaults.reek +131 -0
- data/lib/wcc/github.rb +24 -0
- data/lib/wcc/jshint.rb +63 -0
- data/lib/wcc/plugin.rb +128 -0
- data/lib/wcc/reek.rb +56 -0
- data/lib/wcc/rubocop_exceptions.rb +99 -0
- data/lib/wcc/todos.rb +78 -0
- data/lib/wcc/utils.rb +136 -0
- data/spec/fixtures/brakeman/a.tmp +13 -0
- data/spec/fixtures/brakeman/b.tmp +14 -0
- data/spec/fixtures/brakeman/brakeman.diff +20 -0
- data/spec/fixtures/brakeman/brakeman.out +14 -0
- data/spec/fixtures/exception_context.diff +15 -0
- data/spec/fixtures/exception_insert_context.diff +14 -0
- data/spec/fixtures/exception_misspelled.diff +14 -0
- data/spec/fixtures/exception_multiline_context.diff +20 -0
- data/spec/fixtures/exception_reenabled.diff +13 -0
- data/spec/fixtures/find_in_diff.rb +21 -0
- data/spec/fixtures/find_in_diff_2_chunks.diff +24 -0
- data/spec/fixtures/flay.diff +17 -0
- data/spec/fixtures/flay.txt +18 -0
- data/spec/fixtures/github/labels.json +72 -0
- data/spec/fixtures/github_pr.json +325 -0
- data/spec/fixtures/jshint/a.tmp +5 -0
- data/spec/fixtures/jshint/b.tmp +7 -0
- data/spec/fixtures/jshint/jshint.diff +13 -0
- data/spec/fixtures/jshint/out.jshint +7 -0
- data/spec/fixtures/no_exception.diff +10 -0
- data/spec/fixtures/no_todo.diff +13 -0
- data/spec/fixtures/reek/line_numbers.reek +121 -0
- data/spec/fixtures/reek/reek.diff +50 -0
- data/spec/fixtures/rubocop_exception.rb +39 -0
- data/spec/fixtures/todo.rb +21 -0
- data/spec/fixtures/todo_link_next_line.diff +14 -0
- data/spec/fixtures/todo_link_same_line.diff +13 -0
- data/spec/fixtures/todo_no_link.diff +13 -0
- data/spec/fixtures/todo_removed.diff +13 -0
- data/spec/fixtures_helper.rb +19 -0
- data/spec/spec_helper.rb +73 -0
- data/spec/wcc/commit_lint_spec.rb +392 -0
- data/spec/wcc/github_spec.rb +67 -0
- data/spec/wcc/jshint_spec.rb +68 -0
- data/spec/wcc/plugin_spec.rb +134 -0
- data/spec/wcc/reek_spec.rb +71 -0
- data/spec/wcc/rubocop_exceptions_spec.rb +136 -0
- data/spec/wcc/todos_spec.rb +96 -0
- data/spec/wcc/utils_spec.rb +134 -0
- data/spec/wcc_spec.rb +21 -0
- metadata +393 -0
@@ -0,0 +1,50 @@
|
|
1
|
+
diff --git a/initial.tmp b/final.tmp
|
2
|
+
index feafe47..97e1eb3 100644
|
3
|
+
--- a/initial.tmp
|
4
|
+
+++ b/final.tmp
|
5
|
+
@@ -23,6 +23,10 @@ lib/wcc/github.rb -- 3 warnings:
|
6
|
+
DuplicateMethodCall: Github#add_labels calls 'github.api' 2 times [https://github.com/troessner/reek/blob/master/docs/Duplicate-Method-Call.md]
|
7
|
+
IrresponsibleModule: Github has no descriptive comment [https://github.com/troessner/reek/blob/master/docs/Irresponsible-Module.md]
|
8
|
+
UncommunicativeVariableName: Github#add_labels has the variable name 'l' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Variable-Name.md]
|
9
|
+
+lib/wcc/plugin.rb -- 3 warnings:
|
10
|
+
+ TooManyStatements: Danger::DangerWCC#reek has approx 7 statements [https://github.com/troessner/reek/blob/master/docs/Too-Many-Statements.md]
|
11
|
+
+ UncommunicativeVariableName: Danger::DangerWCC#reek has the variable name 'l' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Variable-Name.md]
|
12
|
+
+ UncommunicativeVariableName: Danger::DangerWCC#reek has the variable name 'm' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Variable-Name.md]
|
13
|
+
lib/wcc/rubocop_exceptions.rb -- 25 warnings:
|
14
|
+
DuplicateMethodCall: Danger::DangerWCC::RubocopExceptions#build_message calls 'e[:context_lines]' 2 times [https://github.com/troessner/reek/blob/master/docs/Duplicate-Method-Call.md]
|
15
|
+
DuplicateMethodCall: Danger::DangerWCC::RubocopExceptions#find_context calls 'l.content' 2 times [https://github.com/troessner/reek/blob/master/docs/Duplicate-Method-Call.md]
|
16
|
+
@@ -68,7 +72,7 @@ lib/wcc/todos.rb -- 18 warnings:
|
17
|
+
UncommunicativeVariableName: Danger::DangerWCC::Todos#find_link_in_context has the variable name 'l' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Variable-Name.md]
|
18
|
+
UncommunicativeVariableName: Danger::DangerWCC::Todos#find_link_in_context has the variable name 'm' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Variable-Name.md]
|
19
|
+
UtilityFunction: Danger::DangerWCC::Todos#max doesn't depend on instance state (maybe move it to another class?) [https://github.com/troessner/reek/blob/master/docs/Utility-Function.md]
|
20
|
+
-lib/wcc/utils.rb -- 15 warnings:
|
21
|
+
+lib/wcc/utils.rb -- 17 warnings:
|
22
|
+
ControlParameter: Utils#issue is controlled by argument 'severity' [https://github.com/troessner/reek/blob/master/docs/Control-Parameter.md]
|
23
|
+
DuplicateMethodCall: Utils#find_in_diff calls 'l.content' 2 times [https://github.com/troessner/reek/blob/master/docs/Duplicate-Method-Call.md]
|
24
|
+
FeatureEnvy: Utils#find_in_diff refers to 'l' more than self (maybe move it to another class?) [https://github.com/troessner/reek/blob/master/docs/Feature-Envy.md]
|
25
|
+
@@ -79,8 +83,10 @@ lib/wcc/utils.rb -- 15 warnings:
|
26
|
+
NestedIterators: Utils#each_addition_in_diff contains iterators nested 3 deep [https://github.com/troessner/reek/blob/master/docs/Nested-Iterators.md]
|
27
|
+
NestedIterators: Utils#each_file_in_diff contains iterators nested 2 deep [https://github.com/troessner/reek/blob/master/docs/Nested-Iterators.md]
|
28
|
+
NestedIterators: Utils#find_in_diff contains iterators nested 3 deep [https://github.com/troessner/reek/blob/master/docs/Nested-Iterators.md]
|
29
|
+
+ NilCheck: Utils#run_and_diff performs a nil-check [https://github.com/troessner/reek/blob/master/docs/Nil-Check.md]
|
30
|
+
TooManyStatements: Utils#each_addition_in_diff has approx 6 statements [https://github.com/troessner/reek/blob/master/docs/Too-Many-Statements.md]
|
31
|
+
TooManyStatements: Utils#find_in_diff has approx 7 statements [https://github.com/troessner/reek/blob/master/docs/Too-Many-Statements.md]
|
32
|
+
+ TooManyStatements: Utils#run_and_diff has approx 18 statements [https://github.com/troessner/reek/blob/master/docs/Too-Many-Statements.md]
|
33
|
+
UncommunicativeVariableName: Utils#each_addition_in_diff has the variable name 'l' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Variable-Name.md]
|
34
|
+
UncommunicativeVariableName: Utils#find_in_diff has the variable name 'l' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Variable-Name.md]
|
35
|
+
UncommunicativeVariableName: Utils#parsed_diffs has the variable name 'd' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Variable-Name.md]
|
36
|
+
@@ -101,6 +107,8 @@ spec/wcc/commit_lint_spec.rb -- 3 warnings:
|
37
|
+
UtilityFunction: report_counts doesn't depend on instance state (maybe move it to another class?) [https://github.com/troessner/reek/blob/master/docs/Utility-Function.md]
|
38
|
+
spec/wcc/github_spec.rb -- 1 warning:
|
39
|
+
IrresponsibleModule: Danger has no descriptive comment [https://github.com/troessner/reek/blob/master/docs/Irresponsible-Module.md]
|
40
|
+
+spec/wcc/plugin_spec.rb -- 1 warning:
|
41
|
+
+ IrresponsibleModule: Danger has no descriptive comment [https://github.com/troessner/reek/blob/master/docs/Irresponsible-Module.md]
|
42
|
+
spec/wcc/rubocop_exceptions_spec.rb -- 1 warning:
|
43
|
+
IrresponsibleModule: Danger has no descriptive comment [https://github.com/troessner/reek/blob/master/docs/Irresponsible-Module.md]
|
44
|
+
spec/wcc/todos_spec.rb -- 1 warning:
|
45
|
+
@@ -110,4 +118,4 @@ spec/wcc/utils_spec.rb -- 2 warnings:
|
46
|
+
UncommunicativeVariableName: Danger has the variable name 'l' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Variable-Name.md]
|
47
|
+
spec/wcc_spec.rb -- 1 warning:
|
48
|
+
IrresponsibleModule: Danger has no descriptive comment [https://github.com/troessner/reek/blob/master/docs/Irresponsible-Module.md]
|
49
|
+
-91 total warnings
|
50
|
+
+97 total warnings
|
@@ -0,0 +1,39 @@
|
|
1
|
+
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module RubocopException
|
5
|
+
# rubocop:disable Rails/SomeRule
|
6
|
+
def some_method_with_disabled_rule
|
7
|
+
end
|
8
|
+
# rubocop:enable Rails/SomeRule
|
9
|
+
|
10
|
+
# rubocop:disable Lint/SomeLint
|
11
|
+
def some_method_misspelled_reenable
|
12
|
+
end
|
13
|
+
# rubocop:enable Lint/SomLint
|
14
|
+
|
15
|
+
# rubocop:disable Metrics/LineLength
|
16
|
+
# Disabling because I want to.
|
17
|
+
def some_method_with_context
|
18
|
+
end
|
19
|
+
# rubocop:enable Metrics/LineLength
|
20
|
+
|
21
|
+
# rubocop:disable Metrics/ABC
|
22
|
+
# here is my comment why we are disabling ABC
|
23
|
+
# Some existing comments
|
24
|
+
# Made by another person
|
25
|
+
def some_method_with_existing_comments
|
26
|
+
end
|
27
|
+
# rubocop:enable Metrics/ABC
|
28
|
+
|
29
|
+
def some_method_with_multiline_context
|
30
|
+
# rubocop:disable Layout/AlignHash
|
31
|
+
# I want to disable this because..
|
32
|
+
# I forgot the reasons.
|
33
|
+
{
|
34
|
+
a: 'a',
|
35
|
+
b: 'b'
|
36
|
+
}
|
37
|
+
# rubocop:enable Layout/AlignHash
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
module Todo
|
6
|
+
def this_should_not_trigger_todo
|
7
|
+
end
|
8
|
+
|
9
|
+
# TODO: fix this later
|
10
|
+
def todo_without_comment
|
11
|
+
end
|
12
|
+
|
13
|
+
# TODO: https://zube.io/watermark/asdf1234
|
14
|
+
def todo_with_link_same_line
|
15
|
+
end
|
16
|
+
|
17
|
+
# TODO: fix this when things are right
|
18
|
+
# https://www.github.com/watermarkchurch/asdf/1234
|
19
|
+
def todo_with_link_below
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
diff --git a/spec/fixtures/todo.rb b/spec/fixtures/todo.rb
|
2
|
+
index 08d4e15..16dc3b5 100644
|
3
|
+
--- a/spec/fixtures/todo.rb
|
4
|
+
+++ b/spec/fixtures/todo.rb
|
5
|
+
@@ -13,4 +13,9 @@ module Todo
|
6
|
+
# TODO: https://zube.io/watermark/asdf1234
|
7
|
+
def todo_with_link_same_line
|
8
|
+
end
|
9
|
+
+
|
10
|
+
+ # TODO: fix this when things are right
|
11
|
+
+ # https://www.github.com/watermarkchurch/asdf/1234
|
12
|
+
+ def todo_with_link_below
|
13
|
+
+ end
|
14
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
diff --git a/spec/fixtures/todo.rb b/spec/fixtures/todo.rb
|
2
|
+
index f141004..08d4e15 100644
|
3
|
+
--- a/spec/fixtures/todo.rb
|
4
|
+
+++ b/spec/fixtures/todo.rb
|
5
|
+
@@ -9,4 +9,8 @@ module Todo
|
6
|
+
# TODO: fix this later
|
7
|
+
def todo_without_comment
|
8
|
+
end
|
9
|
+
+
|
10
|
+
+ # TODO: https://zube.io/watermark/asdf1234
|
11
|
+
+ def todo_with_link_same_line
|
12
|
+
+ end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
diff --git a/spec/fixtures/todo.rb b/spec/fixtures/todo.rb
|
2
|
+
index 22ca05f..f141004 100644
|
3
|
+
--- a/spec/fixtures/todo.rb
|
4
|
+
+++ b/spec/fixtures/todo.rb
|
5
|
+
@@ -5,4 +5,8 @@
|
6
|
+
module Todo
|
7
|
+
def this_should_not_trigger_todo
|
8
|
+
end
|
9
|
+
+
|
10
|
+
+ # TODO: fix this later
|
11
|
+
+ def todo_without_comment
|
12
|
+
+ end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
diff --git a/spec/fixtures/todo.rb b/spec/fixtures/todo.rb
|
2
|
+
index 16dc3b5..e4fada3 100644
|
3
|
+
--- a/spec/fixtures/todo.rb
|
4
|
+
+++ b/spec/fixtures/todo.rb
|
5
|
+
@@ -14,8 +14,6 @@ module Todo
|
6
|
+
def todo_with_link_same_line
|
7
|
+
end
|
8
|
+
|
9
|
+
- # TODO: fix this when things are right
|
10
|
+
- # https://www.github.com/watermarkchurch/asdf/1234
|
11
|
+
def todo_with_link_below
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module FixturesHelper
|
5
|
+
def load_diff(file_path, fixture_name)
|
6
|
+
raw_diff = load_fixture(fixture_name + '.diff')
|
7
|
+
return unless raw_diff
|
8
|
+
|
9
|
+
double(
|
10
|
+
patch: raw_diff,
|
11
|
+
path: file_path
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
def load_fixture(file_name)
|
16
|
+
file = "#{File.dirname(__FILE__)}/fixtures/#{file_name}"
|
17
|
+
return File.read(file) if File.exist?(file)
|
18
|
+
end
|
19
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
ROOT = Pathname.new(File.expand_path('../../', __FILE__))
|
5
|
+
$LOAD_PATH.unshift((ROOT + 'lib').to_s)
|
6
|
+
$LOAD_PATH.unshift((ROOT + 'spec').to_s)
|
7
|
+
|
8
|
+
require 'bundler/setup'
|
9
|
+
require 'pry'
|
10
|
+
|
11
|
+
require 'rspec'
|
12
|
+
require 'danger'
|
13
|
+
require 'webmock/rspec'
|
14
|
+
|
15
|
+
if `git remote -v` == ''
|
16
|
+
puts 'You cannot run tests without setting a local git remote on this repo'
|
17
|
+
puts "It's a weird side-effect of Danger's internals."
|
18
|
+
exit(0)
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'fixtures_helper'
|
22
|
+
|
23
|
+
# Use coloured output, it's the best.
|
24
|
+
RSpec.configure do |config|
|
25
|
+
config.filter_gems_from_backtrace 'bundler'
|
26
|
+
config.color = true
|
27
|
+
config.tty = true
|
28
|
+
config.include FixturesHelper
|
29
|
+
end
|
30
|
+
|
31
|
+
require 'danger_plugin'
|
32
|
+
|
33
|
+
# These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
|
34
|
+
# If you are expanding these files, see if it's already been done ^.
|
35
|
+
|
36
|
+
# A silent version of the user interface,
|
37
|
+
# it comes with an extra function `.string` which will
|
38
|
+
# strip all ANSI colours from the string.
|
39
|
+
|
40
|
+
# rubocop:disable Lint/NestedMethodDefinition
|
41
|
+
def testing_ui
|
42
|
+
@output = StringIO.new
|
43
|
+
def @output.winsize
|
44
|
+
[20, 9999]
|
45
|
+
end
|
46
|
+
|
47
|
+
cork = Cork::Board.new(out: @output)
|
48
|
+
def cork.string
|
49
|
+
out.string.gsub(/\e\[([;\d]+)?m/, '')
|
50
|
+
end
|
51
|
+
cork
|
52
|
+
end
|
53
|
+
# rubocop:enable Lint/NestedMethodDefinition
|
54
|
+
|
55
|
+
# Example environment (ENV) that would come from
|
56
|
+
# running a PR on TravisCI
|
57
|
+
def testing_env
|
58
|
+
{
|
59
|
+
'HAS_JOSH_K_SEAL_OF_APPROVAL' => 'true',
|
60
|
+
'TRAVIS_PULL_REQUEST' => '800',
|
61
|
+
'TRAVIS_REPO_SLUG' => 'artsy/eigen',
|
62
|
+
'TRAVIS_COMMIT_RANGE' => '759adcbd0d8f...13c4dc8bb61d',
|
63
|
+
'DANGER_GITHUB_API_TOKEN' => '123sbdq54erfsd3422gdfio'
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
# A stubbed out Dangerfile for use in tests
|
68
|
+
def testing_dangerfile
|
69
|
+
env = Danger::EnvironmentManager.new(testing_env)
|
70
|
+
Danger::Dangerfile.new(env, testing_ui)
|
71
|
+
end
|
72
|
+
|
73
|
+
WebMock.disable_net_connect!(allow_localhost: true)
|
@@ -0,0 +1,392 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copied and modified from
|
4
|
+
# https://github.com/jonallured/danger-commit_lint
|
5
|
+
# which is licensed under the MIT License
|
6
|
+
|
7
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
8
|
+
|
9
|
+
TEST_MESSAGES = {
|
10
|
+
subject_cap: 'this subject needs a capital',
|
11
|
+
subject_words: 'Fixed',
|
12
|
+
subject_length: 'This is a really long subject line and should result in an'\
|
13
|
+
' error',
|
14
|
+
subject_period: 'This subject line ends in a period.',
|
15
|
+
empty_line: "This subject line is fine\nBut then I forgot the empty line '\
|
16
|
+
'separating the subject and the body.",
|
17
|
+
all_errors: "this is a really long subject and it even ends in a period.\n'\
|
18
|
+
'Not to mention the missing empty line!",
|
19
|
+
valid: "This is a valid message\n\nYou can tell because it meets all the '\
|
20
|
+
'criteria and the linter does not complain."
|
21
|
+
}.freeze
|
22
|
+
|
23
|
+
NOOP_MESSAGE = Danger::DangerWCC::CommitLint::NOOP_MESSAGE
|
24
|
+
SUBJECT_LENGTH_CHECK_MESSAGE = 'Please limit commit subject line to 50 '\
|
25
|
+
'characters.'
|
26
|
+
|
27
|
+
# rubocop:enable Metrics/LineLength
|
28
|
+
|
29
|
+
def report_counts(status_report)
|
30
|
+
status_report.values.flatten.count
|
31
|
+
end
|
32
|
+
|
33
|
+
module Danger
|
34
|
+
describe Danger::DangerWCC do
|
35
|
+
before do
|
36
|
+
@dangerfile = testing_dangerfile
|
37
|
+
@my_plugin = @dangerfile.wcc
|
38
|
+
@git = @dangerfile.git
|
39
|
+
end
|
40
|
+
|
41
|
+
def message_with_sha(message)
|
42
|
+
[message, sha].join "\n"
|
43
|
+
end
|
44
|
+
|
45
|
+
def commit_lint(options = {})
|
46
|
+
Danger::DangerWCC::CommitLint.new(@my_plugin, options).perform
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'commit lint' do
|
50
|
+
describe 'check without configuration' do
|
51
|
+
let(:sha) { '1234567' }
|
52
|
+
let(:commit) { double(:commit, message: message, sha: sha) }
|
53
|
+
|
54
|
+
context 'with invalid messages' do
|
55
|
+
it 'fails those checks' do
|
56
|
+
checks = {
|
57
|
+
subject_cap: SubjectCapCheck::MESSAGE,
|
58
|
+
subject_words: SubjectWordsCheck::MESSAGE,
|
59
|
+
subject_length: SUBJECT_LENGTH_CHECK_MESSAGE,
|
60
|
+
subject_period: SubjectPeriodCheck::MESSAGE,
|
61
|
+
empty_line: EmptyLineCheck::MESSAGE
|
62
|
+
}
|
63
|
+
|
64
|
+
checks.each do |check, warning|
|
65
|
+
commit = double(:commit, message: TEST_MESSAGES[check], sha: sha)
|
66
|
+
allow(@git).to receive(:commits).and_return([commit])
|
67
|
+
|
68
|
+
expect {
|
69
|
+
commit_lint
|
70
|
+
}.to change { @my_plugin.status_report[:errors].count }.by(1)
|
71
|
+
|
72
|
+
status_report = @my_plugin.status_report
|
73
|
+
expect(status_report[:errors].last)
|
74
|
+
.to eq(message_with_sha(warning))
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'with all errors' do
|
80
|
+
let(:message) { TEST_MESSAGES[:all_errors] }
|
81
|
+
|
82
|
+
it 'fails every check' do
|
83
|
+
allow(@git).to receive(:commits).and_return([commit])
|
84
|
+
|
85
|
+
commit_lint
|
86
|
+
|
87
|
+
status_report = @my_plugin.status_report
|
88
|
+
expect(report_counts(status_report)).to eq 4
|
89
|
+
expect(status_report[:errors]).to eq [
|
90
|
+
message_with_sha(SubjectCapCheck::MESSAGE),
|
91
|
+
message_with_sha(SUBJECT_LENGTH_CHECK_MESSAGE),
|
92
|
+
message_with_sha(SubjectPeriodCheck::MESSAGE),
|
93
|
+
message_with_sha(EmptyLineCheck::MESSAGE)
|
94
|
+
]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'with valid messages' do
|
99
|
+
let(:message) { TEST_MESSAGES[:valid] }
|
100
|
+
|
101
|
+
it 'does nothing' do
|
102
|
+
checks = {
|
103
|
+
subject_length: SUBJECT_LENGTH_CHECK_MESSAGE,
|
104
|
+
subject_period: SubjectPeriodCheck::MESSAGE,
|
105
|
+
empty_line: EmptyLineCheck::MESSAGE
|
106
|
+
}
|
107
|
+
|
108
|
+
checks.each do
|
109
|
+
allow(@git).to receive(:commits).and_return([commit])
|
110
|
+
|
111
|
+
commit_lint
|
112
|
+
|
113
|
+
status_report = @my_plugin.status_report
|
114
|
+
expect(report_counts(status_report)).to eq 0
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe 'disable configuration' do
|
121
|
+
let(:sha) { '1234567' }
|
122
|
+
let(:commit) { double(:commit, message: message, sha: sha) }
|
123
|
+
|
124
|
+
context 'with individual checks' do
|
125
|
+
context 'with invalid messages' do
|
126
|
+
it 'does nothing' do
|
127
|
+
checks = {
|
128
|
+
subject_length: SUBJECT_LENGTH_CHECK_MESSAGE,
|
129
|
+
subject_period: SubjectPeriodCheck::MESSAGE,
|
130
|
+
empty_line: EmptyLineCheck::MESSAGE
|
131
|
+
}
|
132
|
+
|
133
|
+
checks.each do |check, _|
|
134
|
+
commit = double(:commit,
|
135
|
+
message: TEST_MESSAGES[check], sha: sha)
|
136
|
+
allow(@git).to receive(:commits).and_return([commit])
|
137
|
+
|
138
|
+
commit_lint disable: [check]
|
139
|
+
|
140
|
+
status_report = @my_plugin.status_report
|
141
|
+
expect(report_counts(status_report)).to eq 0
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context 'with all checks, implicitly' do
|
148
|
+
let(:message) { TEST_MESSAGES[:all_errors] }
|
149
|
+
|
150
|
+
it 'warns that nothing was checked' do
|
151
|
+
allow(@git).to receive(:commits).and_return([commit])
|
152
|
+
|
153
|
+
all_checks = %i[
|
154
|
+
subject_cap
|
155
|
+
subject_words
|
156
|
+
subject_length
|
157
|
+
subject_period
|
158
|
+
empty_line
|
159
|
+
]
|
160
|
+
commit_lint disable: all_checks
|
161
|
+
|
162
|
+
status_report = @my_plugin.status_report
|
163
|
+
expect(report_counts(status_report)).to eq 1
|
164
|
+
expect(status_report[:warnings]).to eq [NOOP_MESSAGE]
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
context 'with all checks, explicitly' do
|
169
|
+
let(:message) { TEST_MESSAGES[:all_errors] }
|
170
|
+
|
171
|
+
it 'warns that nothing was checked' do
|
172
|
+
allow(@git).to receive(:commits).and_return([commit])
|
173
|
+
|
174
|
+
commit_lint disable: :all
|
175
|
+
|
176
|
+
status_report = @my_plugin.status_report
|
177
|
+
expect(report_counts(status_report)).to eq 1
|
178
|
+
expect(status_report[:warnings]).to eq [NOOP_MESSAGE]
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
describe 'warn configuration' do
|
184
|
+
let(:sha) { '1234567' }
|
185
|
+
let(:commit) { double(:commit, message: message, sha: sha) }
|
186
|
+
|
187
|
+
context 'with individual checks' do
|
188
|
+
context 'with invalid messages' do
|
189
|
+
it 'warns instead of failing' do
|
190
|
+
checks = {
|
191
|
+
subject_length: SUBJECT_LENGTH_CHECK_MESSAGE,
|
192
|
+
subject_period: SubjectPeriodCheck::MESSAGE,
|
193
|
+
empty_line: EmptyLineCheck::MESSAGE
|
194
|
+
}
|
195
|
+
|
196
|
+
checks.each do |check, warning|
|
197
|
+
commit = double(:commit,
|
198
|
+
message: TEST_MESSAGES[check], sha: sha)
|
199
|
+
allow(@git).to receive(:commits).and_return([commit])
|
200
|
+
|
201
|
+
expect {
|
202
|
+
commit_lint warn: [check]
|
203
|
+
}.to change { @my_plugin.status_report[:warnings].count }.by(1)
|
204
|
+
|
205
|
+
status_report = @my_plugin.status_report
|
206
|
+
expect(status_report[:warnings].last)
|
207
|
+
.to eq(message_with_sha(warning))
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
context 'with valid messages' do
|
213
|
+
let(:message) { TEST_MESSAGES[:valid] }
|
214
|
+
|
215
|
+
it 'does nothing' do
|
216
|
+
checks = {
|
217
|
+
subject_length: SUBJECT_LENGTH_CHECK_MESSAGE,
|
218
|
+
subject_period: SubjectPeriodCheck::MESSAGE,
|
219
|
+
empty_line: EmptyLineCheck::MESSAGE
|
220
|
+
}
|
221
|
+
|
222
|
+
checks.each do |check, _|
|
223
|
+
allow(@git).to receive(:commits).and_return([commit])
|
224
|
+
|
225
|
+
commit_lint warn: [check]
|
226
|
+
|
227
|
+
status_report = @my_plugin.status_report
|
228
|
+
expect(report_counts(status_report)).to eq 0
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
context 'with all checks' do
|
235
|
+
context 'with all errors' do
|
236
|
+
let(:message) { TEST_MESSAGES[:all_errors] }
|
237
|
+
|
238
|
+
it 'warns instead of failing' do
|
239
|
+
allow(@git).to receive(:commits).and_return([commit])
|
240
|
+
|
241
|
+
commit_lint warn: :all
|
242
|
+
|
243
|
+
status_report = @my_plugin.status_report
|
244
|
+
expect(report_counts(status_report)).to eq 4
|
245
|
+
expect(status_report[:warnings]).to eq [
|
246
|
+
message_with_sha(SubjectCapCheck::MESSAGE),
|
247
|
+
message_with_sha(SUBJECT_LENGTH_CHECK_MESSAGE),
|
248
|
+
message_with_sha(SubjectPeriodCheck::MESSAGE),
|
249
|
+
message_with_sha(EmptyLineCheck::MESSAGE)
|
250
|
+
]
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
context 'with a valid message' do
|
255
|
+
let(:message) { TEST_MESSAGES[:valid] }
|
256
|
+
|
257
|
+
it 'does nothing' do
|
258
|
+
allow(@git).to receive(:commits).and_return([commit])
|
259
|
+
|
260
|
+
commit_lint warn: :all
|
261
|
+
|
262
|
+
status_report = @my_plugin.status_report
|
263
|
+
expect(report_counts(status_report)).to eq 0
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
describe 'fail configuration' do
|
270
|
+
let(:sha) { '1234567' }
|
271
|
+
let(:commit) { double(:commit, message: message, sha: sha) }
|
272
|
+
|
273
|
+
context 'with individual checks' do
|
274
|
+
context 'with invalid messages' do
|
275
|
+
it 'fails those checks' do
|
276
|
+
checks = {
|
277
|
+
subject_length: SUBJECT_LENGTH_CHECK_MESSAGE,
|
278
|
+
subject_period: SubjectPeriodCheck::MESSAGE,
|
279
|
+
empty_line: EmptyLineCheck::MESSAGE
|
280
|
+
}
|
281
|
+
|
282
|
+
checks.each do |check, warning|
|
283
|
+
commit = double(:commit,
|
284
|
+
message: TEST_MESSAGES[check], sha: sha)
|
285
|
+
allow(@git).to receive(:commits).and_return([commit])
|
286
|
+
|
287
|
+
expect {
|
288
|
+
commit_lint fail: [check]
|
289
|
+
}.to change { @my_plugin.status_report[:errors].count }.by(1)
|
290
|
+
|
291
|
+
status_report = @my_plugin.status_report
|
292
|
+
|
293
|
+
expect(status_report[:errors].last)
|
294
|
+
.to eq(message_with_sha(warning))
|
295
|
+
end
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
context 'with valid messages' do
|
300
|
+
let(:message) { TEST_MESSAGES[:valid] }
|
301
|
+
|
302
|
+
it 'does nothing' do
|
303
|
+
checks = {
|
304
|
+
subject_length: SUBJECT_LENGTH_CHECK_MESSAGE,
|
305
|
+
subject_period: SubjectPeriodCheck::MESSAGE,
|
306
|
+
empty_line: EmptyLineCheck::MESSAGE
|
307
|
+
}
|
308
|
+
|
309
|
+
checks.each do |check, _|
|
310
|
+
allow(@git).to receive(:commits).and_return([commit])
|
311
|
+
|
312
|
+
commit_lint fail: [check]
|
313
|
+
|
314
|
+
status_report = @my_plugin.status_report
|
315
|
+
expect(report_counts(status_report)).to eq 0
|
316
|
+
end
|
317
|
+
end
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
context 'with all checks' do
|
322
|
+
context 'with all errors' do
|
323
|
+
let(:message) { TEST_MESSAGES[:all_errors] }
|
324
|
+
|
325
|
+
it 'fails those checks' do
|
326
|
+
allow(@git).to receive(:commits).and_return([commit])
|
327
|
+
|
328
|
+
commit_lint fail: :all
|
329
|
+
|
330
|
+
status_report = @my_plugin.status_report
|
331
|
+
expect(report_counts(status_report)).to eq 4
|
332
|
+
expect(status_report[:errors]).to eq [
|
333
|
+
message_with_sha(SubjectCapCheck::MESSAGE),
|
334
|
+
message_with_sha(SUBJECT_LENGTH_CHECK_MESSAGE),
|
335
|
+
message_with_sha(SubjectPeriodCheck::MESSAGE),
|
336
|
+
message_with_sha(EmptyLineCheck::MESSAGE)
|
337
|
+
]
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
341
|
+
context 'with a valid message' do
|
342
|
+
let(:message) { TEST_MESSAGES[:valid] }
|
343
|
+
|
344
|
+
it 'does nothing' do
|
345
|
+
allow(@git).to receive(:commits).and_return([commit])
|
346
|
+
|
347
|
+
commit_lint fail: :all
|
348
|
+
|
349
|
+
status_report = @my_plugin.status_report
|
350
|
+
expect(report_counts(status_report)).to eq 0
|
351
|
+
end
|
352
|
+
end
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
356
|
+
describe 'individual check options' do
|
357
|
+
let(:sha) { '1234567' }
|
358
|
+
|
359
|
+
context 'with invalid messages for given options' do
|
360
|
+
it 'fails those checks' do
|
361
|
+
options = [
|
362
|
+
[:subject_length, { max: 10 }],
|
363
|
+
[:subject_length, { min: 100, max: 110 }]
|
364
|
+
]
|
365
|
+
messages = [
|
366
|
+
'Please limit commit subject line to 10 characters.',
|
367
|
+
'Please write a commit subject line of at least 100 characters.'
|
368
|
+
]
|
369
|
+
|
370
|
+
options.each_with_index do |(check, opts), i|
|
371
|
+
commit = double(:commit,
|
372
|
+
message: TEST_MESSAGES[:valid], sha: sha)
|
373
|
+
allow(@git).to receive(:commits).and_return([commit])
|
374
|
+
|
375
|
+
arg = {}
|
376
|
+
arg[check] = opts
|
377
|
+
expect {
|
378
|
+
commit_lint arg
|
379
|
+
}.to change { @my_plugin.status_report[:errors].count }.by(1)
|
380
|
+
|
381
|
+
status_report = @my_plugin.status_report
|
382
|
+
expect(status_report[:errors].last)
|
383
|
+
.to eq(message_with_sha(messages[i]))
|
384
|
+
end
|
385
|
+
end
|
386
|
+
end
|
387
|
+
end
|
388
|
+
end
|
389
|
+
end
|
390
|
+
end
|
391
|
+
|
392
|
+
# rubocop:enable Metrics/ClassLength
|