rubycritic 3.4.0 → 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -2
  3. data/README.md +12 -10
  4. data/lib/rubycritic/cli/options.rb +25 -3
  5. data/lib/rubycritic/command_factory.rb +3 -0
  6. data/lib/rubycritic/commands/ci.rb +2 -8
  7. data/lib/rubycritic/commands/compare.rb +105 -0
  8. data/lib/rubycritic/commands/utils/build_number_file.rb +35 -0
  9. data/lib/rubycritic/configuration.rb +18 -1
  10. data/lib/rubycritic/core/analysed_modules_collection.rb +23 -3
  11. data/lib/rubycritic/generators/html/assets/stylesheets/application.css +20 -0
  12. data/lib/rubycritic/generators/html/base.rb +1 -1
  13. data/lib/rubycritic/generators/html/code_file.rb +11 -0
  14. data/lib/rubycritic/generators/html/code_index.rb +7 -0
  15. data/lib/rubycritic/generators/html/overview.rb +7 -0
  16. data/lib/rubycritic/generators/html/smells_index.rb +7 -0
  17. data/lib/rubycritic/generators/html/templates/code_index.html.erb +10 -0
  18. data/lib/rubycritic/generators/html/templates/layouts/application.html.erb +7 -0
  19. data/lib/rubycritic/generators/html/view_helpers.rb +10 -1
  20. data/lib/rubycritic/source_control_systems/git.rb +27 -1
  21. data/lib/rubycritic/version.rb +1 -1
  22. metadata +7 -131
  23. data/.gitignore +0 -23
  24. data/.rubocop.yml +0 -37
  25. data/.rubocop_todo.yml +0 -45
  26. data/.todo.reek +0 -142
  27. data/.travis.yml +0 -29
  28. data/.yardopts +0 -5
  29. data/docs/building-own-code-climate.md +0 -156
  30. data/docs/core-metrics.md +0 -72
  31. data/docs/jenkins-pr-reviews.md +0 -64
  32. data/features/command_line_interface/minimum_score.feature +0 -39
  33. data/features/command_line_interface/options.feature +0 -37
  34. data/features/rake_task.feature +0 -65
  35. data/features/step_definitions/rake_task_steps.rb +0 -5
  36. data/features/step_definitions/rubycritic_steps.rb +0 -33
  37. data/features/step_definitions/sample_file_steps.rb +0 -32
  38. data/features/support/env.rb +0 -43
  39. data/images/churn-vs-complexity.png +0 -0
  40. data/images/code.png +0 -0
  41. data/images/logo.png +0 -0
  42. data/images/overview.png +0 -0
  43. data/images/rating.png +0 -0
  44. data/images/reek.png +0 -0
  45. data/images/smell-details.png +0 -0
  46. data/images/smells.png +0 -0
  47. data/images/whitesmith.png +0 -0
  48. data/rubycritic.gemspec +0 -45
  49. data/test/analysers_test_helper.rb +0 -12
  50. data/test/lib/rubycritic/analysers/churn_test.rb +0 -35
  51. data/test/lib/rubycritic/analysers/complexity_test.rb +0 -18
  52. data/test/lib/rubycritic/analysers/helpers/methods_counter_test.rb +0 -31
  53. data/test/lib/rubycritic/analysers/helpers/modules_locator_test.rb +0 -55
  54. data/test/lib/rubycritic/analysers/smells/flay_test.rb +0 -41
  55. data/test/lib/rubycritic/analysers/smells/flog_test.rb +0 -28
  56. data/test/lib/rubycritic/analysers/smells/reek_test.rb +0 -32
  57. data/test/lib/rubycritic/analysis_summary_test.rb +0 -30
  58. data/test/lib/rubycritic/browser_test.rb +0 -18
  59. data/test/lib/rubycritic/commands/status_reporter_test.rb +0 -81
  60. data/test/lib/rubycritic/configuration_test.rb +0 -31
  61. data/test/lib/rubycritic/core/analysed_module_test.rb +0 -90
  62. data/test/lib/rubycritic/core/analysed_modules_collection_test.rb +0 -111
  63. data/test/lib/rubycritic/core/location_test.rb +0 -39
  64. data/test/lib/rubycritic/core/smell_test.rb +0 -105
  65. data/test/lib/rubycritic/core/smells_array_test.rb +0 -30
  66. data/test/lib/rubycritic/generators/console_report_test.rb +0 -83
  67. data/test/lib/rubycritic/generators/json_report_test.rb +0 -38
  68. data/test/lib/rubycritic/generators/lint_report_test.rb +0 -37
  69. data/test/lib/rubycritic/generators/turbulence_test.rb +0 -19
  70. data/test/lib/rubycritic/generators/view_helpers_test.rb +0 -85
  71. data/test/lib/rubycritic/revision_comparator_test.rb +0 -66
  72. data/test/lib/rubycritic/smells_status_setter_test.rb +0 -24
  73. data/test/lib/rubycritic/source_control_systems/base_test.rb +0 -31
  74. data/test/lib/rubycritic/source_control_systems/double_test.rb +0 -13
  75. data/test/lib/rubycritic/source_control_systems/git_test.rb +0 -15
  76. data/test/lib/rubycritic/source_control_systems/interfaces/basic.rb +0 -9
  77. data/test/lib/rubycritic/source_control_systems/interfaces/time_travel.rb +0 -9
  78. data/test/lib/rubycritic/source_control_systems/mercurial_test.rb +0 -13
  79. data/test/lib/rubycritic/source_control_systems/perforce_test.rb +0 -176
  80. data/test/lib/rubycritic/source_locator_test.rb +0 -80
  81. data/test/lib/rubycritic/version_test.rb +0 -10
  82. data/test/samples/empty.rb +0 -0
  83. data/test/samples/flay/smelly.rb +0 -8
  84. data/test/samples/flay/smelly2.rb +0 -8
  85. data/test/samples/flog/complex.rb +0 -11
  86. data/test/samples/flog/smelly.rb +0 -11
  87. data/test/samples/location/dir1/file1.rb +0 -0
  88. data/test/samples/location/file0.rb +0 -0
  89. data/test/samples/location/file0_symlink.rb +0 -1
  90. data/test/samples/location/file_with_different_extension.py +0 -0
  91. data/test/samples/location/file_with_no_extension +0 -0
  92. data/test/samples/methods_count.rb +0 -7
  93. data/test/samples/module_names.rb +0 -18
  94. data/test/samples/no_methods.rb +0 -4
  95. data/test/samples/reek/not_smelly.rb +0 -35
  96. data/test/samples/reek/smelly.rb +0 -17
  97. data/test/samples/unparsable.rb +0 -1
  98. data/test/test_helper.rb +0 -64
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
- require 'rubycritic/core/smell'
5
- require 'rubycritic/smells_status_setter'
6
-
7
- describe RubyCritic::SmellsStatusSetter do
8
- describe '::smells' do
9
- before do
10
- @smell = RubyCritic::Smell.new(context: '#bar')
11
- @smells = [@smell]
12
- end
13
-
14
- it 'marks old smells' do
15
- RubyCritic::SmellsStatusSetter.set(@smells, @smells)
16
- @smell.status.must_equal :old
17
- end
18
-
19
- it 'marks new smells' do
20
- RubyCritic::SmellsStatusSetter.set([], @smells)
21
- @smell.status.must_equal :new
22
- end
23
- end
24
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
- require 'rubycritic/source_control_systems/base'
5
-
6
- describe RubyCritic::SourceControlSystem::Base do
7
- before do
8
- RubyCritic::SourceControlSystem::Base.systems.each do |system|
9
- system.stubs(:supported?).returns(false)
10
- end
11
- end
12
-
13
- describe '::create' do
14
- context 'when a source control system is found' do
15
- it 'creates an instance of that source control system' do
16
- RubyCritic::SourceControlSystem::Git.stubs(:supported?).returns(true)
17
- system = RubyCritic::SourceControlSystem::Base.create
18
- system.must_be_instance_of RubyCritic::SourceControlSystem::Git
19
- end
20
- end
21
-
22
- context 'when no source control system is found' do
23
- it 'creates a source control system double' do
24
- capture_output_streams do
25
- system = RubyCritic::SourceControlSystem::Base.create
26
- system.must_be_instance_of RubyCritic::SourceControlSystem::Double
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
- require 'rubycritic/source_control_systems/base'
5
- require_relative 'interfaces/basic'
6
-
7
- class DoubleTest < Minitest::Test
8
- include BasicInterface
9
-
10
- def setup
11
- @system = RubyCritic::SourceControlSystem::Double.new
12
- end
13
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
- require 'rubycritic/source_control_systems/base'
5
- require_relative 'interfaces/basic'
6
- require_relative 'interfaces/time_travel'
7
-
8
- class GitTest < Minitest::Test
9
- include BasicInterface
10
- include TimeTravelInterface
11
-
12
- def setup
13
- @system = RubyCritic::SourceControlSystem::Git.new
14
- end
15
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module BasicInterface
4
- def test_implements_basic_interface
5
- assert_respond_to @system, :revisions_count
6
- assert_respond_to @system, :date_of_last_commit
7
- assert_respond_to @system, :revision?
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # This interface is only used if `@system.revision?` returns `true`.
4
- module TimeTravelInterface
5
- def test_implements_time_travel_interface
6
- assert_respond_to @system, :head_reference
7
- assert_respond_to @system, :travel_to_head
8
- end
9
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
- require 'rubycritic/source_control_systems/base'
5
- require_relative 'interfaces/basic'
6
-
7
- class MercurialTest < Minitest::Test
8
- include BasicInterface
9
-
10
- def setup
11
- @system = RubyCritic::SourceControlSystem::Mercurial.new
12
- end
13
- end
@@ -1,176 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
- require 'rubycritic/source_control_systems/base'
5
-
6
- describe RubyCritic::SourceControlSystem::Perforce do
7
- before do
8
- @system = RubyCritic::SourceControlSystem::Perforce.new
9
- end
10
-
11
- describe RubyCritic::SourceControlSystem::Perforce do
12
- describe '::supported?' do
13
- let(:path) do
14
- ['/some/path', File::PATH_SEPARATOR, '/perforce/path/p4', File::PATH_SEPARATOR + '/other/useless_path'].join
15
- end
16
- let(:p4_client) { 'UNIT_TEST_CLIENT' }
17
-
18
- context 'directory is under p4 client' do
19
- it 'detects if Perforce is the source control used' do
20
- ENV['PATH'] = path
21
- ENV['P4CLIENT'] = p4_client
22
- Gem.stubs(:win_platform?).returns(false)
23
- File.stubs(:executable?).with('/some/path/p4').returns(false)
24
- File.stubs(:executable?).with('/perforce/path/p4/p4').returns(true)
25
- RubyCritic::SourceControlSystem::Perforce.stubs(:in_client_directory?).returns(true)
26
-
27
- RubyCritic::SourceControlSystem::Perforce.supported?.must_equal true
28
- end
29
- end
30
-
31
- context 'directory is not under p4 client' do
32
- it 'returns false if no p4 executables are found' do
33
- ENV['PATH'] = path
34
- ENV['P4CLIENT'] = nil
35
- Gem.stubs(:win_platform?).returns(false)
36
- File.stubs(:executable?).with('/some/path/p4').returns(false)
37
- File.stubs(:executable?).with('/perforce/path/p4/p4').returns(false)
38
- File.stubs(:executable?).with('/other/useless_path/p4').returns(false)
39
-
40
- RubyCritic::SourceControlSystem::Perforce.supported?.must_equal false
41
- end
42
-
43
- it 'returns false if no p4 client is set in environment variables' do
44
- ENV['PATH'] = path
45
- ENV['P4CLIENT'] = nil
46
- Gem.stubs(:win_platform?).returns(false)
47
- File.stubs(:executable?).with('/some/path/p4').returns(false)
48
- File.stubs(:executable?).with('/perforce/path/p4/p4').returns(true)
49
-
50
- RubyCritic::SourceControlSystem::Perforce.supported?.must_equal false
51
- end
52
-
53
- it 'returns false if the current directory is not under p4 client' do
54
- ENV['PATH'] = path
55
- ENV['P4CLIENT'] = p4_client
56
- Gem.stubs(:win_platform?).returns(false)
57
- File.stubs(:executable?).with('/some/path/p4').returns(false)
58
- File.stubs(:executable?).with('/perforce/path/p4/p4').returns(true)
59
- RubyCritic::SourceControlSystem::Perforce.stubs(:in_client_directory?).returns(false)
60
-
61
- RubyCritic::SourceControlSystem::Perforce.supported?.must_equal false
62
- end
63
- end
64
- end
65
-
66
- describe '::in_client_directory?' do
67
- context 'current directory is in p4 client' do
68
- let(:p4_info) do
69
- <<-P4INFO
70
- User name: unit_test_user
71
- Client name: UNIT_TEST_CLIENT
72
- Client host: MACHINE_NAME
73
- Client root: /path/to/client/root
74
- Current directory: /path/to/client/root/ruby_project/unit_test
75
- Peer address: 127.0.0.1::3000
76
- Client address: 127.0.0.1
77
- Server address: the.server.address.com
78
- P4INFO
79
- end
80
-
81
- it 'calls p4 info and parse the result' do
82
- RubyCritic::SourceControlSystem::Perforce.stubs(:`).with('p4 info').returns(p4_info)
83
- RubyCritic::SourceControlSystem::Perforce.in_client_directory?.must_equal true
84
- end
85
- end
86
-
87
- context 'current directory is not in p4 client' do
88
- let(:p4_info) do
89
- <<-P4INFO
90
- User name: unit_test_user
91
- Client name: UNIT_TEST_CLIENT
92
- Client host: MACHINE_NAME
93
- Client root: /path/to/client/root
94
- Current directory: /somewhere/else/ruby_project/unit_test
95
- Peer address: 127.0.0.1::3000
96
- Client address: 127.0.0.1
97
- Server address: the.server.address.com
98
- P4INFO
99
- end
100
-
101
- it 'calls p4 info and parse the result' do
102
- RubyCritic::SourceControlSystem::Perforce.stubs(:`).with('p4 info').returns(p4_info)
103
- RubyCritic::SourceControlSystem::Perforce.in_client_directory?.must_equal false
104
- end
105
- end
106
- end
107
-
108
- describe 'retrieve informations' do
109
- let(:p4_stats) do
110
- <<-P4STATS
111
- ... clientFile /path/to/client/a_ruby_file.rb
112
- ... headTime 1473075551
113
- ... headRev 16
114
- ... headChange 2103503
115
-
116
- ... clientFile /path/to/client/second_ruby_file.rb
117
- ... headTime 1464601668
118
- ... action opened
119
- ... headRev 12
120
- ... headChange 2103504
121
- P4STATS
122
- end
123
-
124
- describe 'build_file_cache' do
125
- it 'builds the perforce file cache' do
126
- RubyCritic::SourceControlSystem::Perforce.stubs(:`).returns(p4_stats)
127
- file_cache = @system.send(:perforce_files)
128
- file_cache.size.must_equal 2
129
-
130
- first_file = file_cache['/path/to/client/a_ruby_file.rb']
131
- first_file.filename.must_equal '/path/to/client/a_ruby_file.rb'
132
- first_file.revision.must_equal '16'
133
- first_file.last_commit.must_equal '1473075551'
134
- first_file.head.must_equal '2103503'
135
- first_file.opened?.must_equal false
136
-
137
- second_file = file_cache['/path/to/client/second_ruby_file.rb']
138
- second_file.filename.must_equal '/path/to/client/second_ruby_file.rb'
139
- second_file.revision.must_equal '12'
140
- second_file.last_commit.must_equal '1464601668'
141
- second_file.head.must_equal '2103504'
142
- second_file.opened?.must_equal true
143
- end
144
- end
145
-
146
- it 'retrieves the number revisions of the ruby files' do
147
- Dir.stubs(:getwd).returns('/path/to/client')
148
- RubyCritic::SourceControlSystem::Perforce.stubs(:`).once.returns(p4_stats)
149
- @system.revisions_count('a_ruby_file.rb').must_equal 16
150
- @system.revisions_count('second_ruby_file.rb').must_equal 12
151
- end
152
-
153
- it 'retrieves the date of the last commit of the ruby files' do
154
- oldtz = ENV['TZ']
155
- ENV['TZ'] = 'utc'
156
- Dir.stubs(:getwd).returns('/path/to/client')
157
- RubyCritic::SourceControlSystem::Perforce.stubs(:`).once.returns(p4_stats)
158
- @system.date_of_last_commit('a_ruby_file.rb').must_equal '2016-09-05 11:39:11 +0000'
159
- @system.date_of_last_commit('second_ruby_file.rb').must_equal '2016-05-30 09:47:48 +0000'
160
- ENV['TZ'] = oldtz
161
- end
162
-
163
- it 'retrieves the information if the ruby file is opened (in the changelist and ready to commit)' do
164
- Dir.stubs(:getwd).returns('/path/to/client')
165
- RubyCritic::SourceControlSystem::Perforce.stubs(:`).once.returns(p4_stats)
166
- @system.revision?.must_equal true
167
- end
168
-
169
- it 'retrieves the head reference of the repository' do
170
- Dir.stubs(:getwd).returns('/path/to/client')
171
- RubyCritic::SourceControlSystem::Perforce.stubs(:`).once.returns(p4_stats)
172
- @system.head_reference.must_equal '2103504'
173
- end
174
- end
175
- end
176
- end
@@ -1,80 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
- require 'rubycritic/source_locator'
5
-
6
- describe RubyCritic::SourceLocator do
7
- before do
8
- @original_dir = Dir.getwd
9
- Dir.chdir('test/samples/location')
10
- end
11
-
12
- describe '#paths' do
13
- it 'finds a single file' do
14
- paths = ['file0.rb']
15
- RubyCritic::SourceLocator.new(paths).paths.must_equal paths
16
- end
17
-
18
- it 'finds all the files inside a given directory' do
19
- initial_paths = ['dir1']
20
- final_paths = ['dir1/file1.rb']
21
- RubyCritic::SourceLocator.new(initial_paths).paths.must_equal final_paths
22
- end
23
-
24
- it 'finds files through multiple paths' do
25
- paths = ['dir1/file1.rb', 'file0.rb']
26
- RubyCritic::SourceLocator.new(paths).paths.must_match_array paths
27
- end
28
-
29
- it 'finds all the files' do
30
- initial_paths = ['.']
31
- final_paths = ['dir1/file1.rb', 'file0.rb', 'file0_symlink.rb']
32
- RubyCritic::SourceLocator.new(initial_paths).paths.must_match_array final_paths
33
- end
34
-
35
- context 'when configured to deduplicate symlinks' do
36
- it 'favors a file over a symlink if they both point to the same target' do
37
- RubyCritic::Config.stubs(:deduplicate_symlinks).returns(true)
38
- initial_paths = ['file0.rb', 'file0_symlink.rb']
39
- final_paths = ['file0.rb']
40
- RubyCritic::SourceLocator.new(initial_paths).paths.must_match_array final_paths
41
- end
42
- end
43
-
44
- it 'cleans paths of consecutive slashes and useless dots' do
45
- initial_paths = ['.//file0.rb']
46
- final_paths = ['file0.rb']
47
- RubyCritic::SourceLocator.new(initial_paths).paths.must_equal final_paths
48
- end
49
-
50
- it 'ignores paths to non-existent files' do
51
- initial_paths = ['non_existent_dir1/non_existent_file1.rb', 'non_existent_file0.rb']
52
- final_paths = []
53
- RubyCritic::SourceLocator.new(initial_paths).paths.must_equal final_paths
54
- end
55
-
56
- it 'ignores paths to files that do not match the Ruby extension' do
57
- initial_paths = ['file_with_no_extension', 'file_with_different_extension.py']
58
- final_paths = []
59
- RubyCritic::SourceLocator.new(initial_paths).paths.must_equal final_paths
60
- end
61
-
62
- it 'can deal with nil paths' do
63
- paths = nil
64
- final_paths = []
65
- RubyCritic::SourceLocator.new(paths).paths.must_equal final_paths
66
- end
67
- end
68
-
69
- describe '#pathnames' do
70
- it 'finds a single file' do
71
- initial_paths = ['file0.rb']
72
- final_pathnames = [Pathname.new('file0.rb')]
73
- RubyCritic::SourceLocator.new(initial_paths).pathnames.must_equal final_pathnames
74
- end
75
- end
76
-
77
- after do
78
- Dir.chdir(@original_dir)
79
- end
80
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
- require 'rubycritic/version'
5
-
6
- describe 'RubyCritic version' do
7
- it 'is defined' do
8
- RubyCritic::VERSION.wont_be_nil
9
- end
10
- end
File without changes
@@ -1,8 +0,0 @@
1
- class Ramsay
2
- def flay(parts)
3
- parts -= 1
4
- parts -= 2
5
- parts -= 3
6
- parts -= 4
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- class Roose
2
- def flay(parts)
3
- parts -= 1
4
- parts -= 2
5
- parts -= 3
6
- parts -= 4
7
- end
8
- end
@@ -1,11 +0,0 @@
1
- class AllTheMethods
2
- def method_missing(method, *args, &block)
3
- message = "I"
4
- eval "message = ' did not'"
5
- eval "message << ' exist,'"
6
- eval "message << ' but now'"
7
- eval "message << ' I do.'"
8
- self.class.send(:define_method, method) { "I did not exist, but now I do." }
9
- self.send(method)
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- class AllTheMethods
2
- def method_missing(method, *args, &block)
3
- message = "I"
4
- eval "message = ' did not'"
5
- eval "message << ' exist,'"
6
- eval "message << ' but now'"
7
- eval "message << ' I do.'"
8
- self.class.send(:define_method, method) { "I did not exist, but now I do." }
9
- self.send(method)
10
- end
11
- end
File without changes
File without changes
@@ -1 +0,0 @@
1
- test/samples/location/file0.rb