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,39 +0,0 @@
1
- Feature: Break if overall score is below minimum
2
- In order to break the Continuous Integration builds based on a score threshold
3
- RubyCritic returns the exit status according with the score
4
-
5
- Scenario: Status indicates a success when not using --minimum-score
6
- Given the smelly file 'smelly.rb' with a score of 93.19
7
- When I run rubycritic smelly.rb
8
- Then the exit status indicates a success
9
-
10
- Scenario: Status indicates an error when score below the minimum
11
- Given the smelly file 'smelly.rb' with a score of 93.19
12
- When I run rubycritic --minimum-score 100 smelly.rb
13
- Then the exit status indicates an error
14
-
15
- Scenario: Status indicates a success when score is above the minimum
16
- Given the smelly file 'smelly.rb' with a score of 93.19
17
- When I run rubycritic --minimum-score 93 smelly.rb
18
- Then the exit status indicates a success
19
-
20
- Scenario: Status indicates a success when score is equal the minimum
21
- Given the clean file 'clean.rb' with a score of 100
22
- When I run rubycritic --minimum-score 100 clean.rb
23
- Then the exit status indicates a success
24
-
25
- Scenario: Prints the score on output
26
- Given the smelly file 'smelly.rb' with a score of 93.19
27
- When I run rubycritic smelly.rb
28
- Then the output should contain:
29
- """
30
- Score: 93.19
31
- """
32
-
33
- Scenario: Prints a message informing the score is below the minimum
34
- Given the empty file 'empty.rb' with a score of 0
35
- When I run rubycritic --minimum-score 100 empty.rb
36
- Then the output should contain:
37
- """
38
- Score (0.0) is below the minimum 100
39
- """
@@ -1,37 +0,0 @@
1
- Feature: RubyCritic can be controlled using command-line options
2
- In order to change RubyCritic's default behaviour
3
- As a developer
4
- I want to supply options on the command line
5
-
6
- Scenario: return non-zero status on bad option
7
- When I run rubycritic --no-such-option
8
- Then the exit status indicates an error
9
- And it reports the error "Error: invalid option: --no-such-option"
10
- And there is no output on stdout
11
-
12
- Scenario: display the current version number
13
- When I run rubycritic --version
14
- Then it succeeds
15
- And it reports the current version
16
-
17
- Scenario: display the help information
18
- When I run rubycritic --help
19
- Then it succeeds
20
- And it reports:
21
- """
22
- Usage: rubycritic [options] [paths]
23
- -p, --path [PATH] Set path where report will be saved (tmp/rubycritic by default)
24
- -f, --format [FORMAT] Report smells in the given format:
25
- html (default; will open in a browser)
26
- json
27
- console
28
- lint
29
- -s, --minimum-score [MIN_SCORE] Set a minimum score
30
- -m, --mode-ci Use CI mode (faster, but only analyses last commit)
31
- --deduplicate-symlinks De-duplicate symlinks based on their final target
32
- --suppress-ratings Suppress letter ratings
33
- --no-browser Do not open html report with browser
34
- -v, --version Show gem's version
35
- -h, --help Show this message
36
-
37
- """
@@ -1,65 +0,0 @@
1
- Feature: RubyCritic can be run via Rake task
2
- In order to allow for a better CI usage
3
- As a developer
4
- I want to use RubyCritic as a Rake task
5
-
6
- Scenario: ‘paths' attribute is respected
7
- Given the smelly file 'smelly.rb'
8
- When I run rake rubycritic with:
9
- """
10
- RubyCritic::RakeTask.new do |t|
11
- t.paths = FileList['smelly.*']
12
- t.options = '--no-browser -f console'
13
- end
14
- """
15
- Then the output should contain:
16
- """
17
- (HighComplexity) AllTheMethods#method_missing has a flog score of 27
18
- """
19
- And the exit status indicates a success
20
-
21
- Scenario: 'name' option changes the task name
22
- Given the smelly file 'smelly.rb'
23
- When I run rake silky with:
24
- """
25
- RubyCritic::RakeTask.new('silky') do |t|
26
- t.paths = FileList['smelly.*']
27
- t.verbose = true
28
- t.options = '--no-browser'
29
- end
30
- """
31
- Then the output should contain:
32
- """
33
- Running `silky` rake command
34
- """
35
-
36
- Scenario: 'verbose' prints details about the execution
37
- Given the smelly file 'smelly.rb'
38
- When I run rake rubycritic with:
39
- """
40
- RubyCritic::RakeTask.new do |t|
41
- t.paths = FileList['smelly.*']
42
- t.verbose = true
43
- t.options = '--no-browser'
44
- end
45
- """
46
- Then the output should contain:
47
- """
48
- !!! Running `rubycritic` rake command
49
- !!! Inspecting smelly.rb with options --no-browser
50
- """
51
-
52
- Scenario: respect --minimum-score
53
- Given the smelly file 'smelly.rb'
54
- When I run rake rubycritic with:
55
- """
56
- RubyCritic::RakeTask.new do |t|
57
- t.paths = FileList['smelly.*']
58
- t.verbose = true
59
- t.options = '--no-browser -f console --minimum-score 95'
60
- end
61
- """
62
- Then the output should contain:
63
- """
64
- Score (93.19) is below the minimum 95
65
- """
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- When(/^I run rake (\w*) with:$/) do |name, task_def|
4
- rake(name, task_def)
5
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- When(/^I run rubycritic (.*)$/) do |args|
4
- rubycritic(args)
5
- end
6
-
7
- Then(/^the exit status indicates an error$/) do
8
- expect(last_command_started).to have_exit_status(RubyCritic::Command::StatusReporter::SCORE_BELOW_MINIMUM)
9
- end
10
-
11
- Then(/^the exit status indicates a success$/) do
12
- expect(last_command_started).to have_exit_status(RubyCritic::Command::StatusReporter::SUCCESS)
13
- end
14
-
15
- Then(/^it reports:$/) do |report|
16
- expect(last_command_started).to have_output_on_stdout(report.gsub('\n', "\n"))
17
- end
18
-
19
- Then(/^there is no output on stdout$/) do
20
- expect(last_command_started).to have_output_on_stdout('')
21
- end
22
-
23
- Then(/^it reports the current version$/) do
24
- expect(last_command_started).to have_output("RubyCritic #{RubyCritic::VERSION}\n")
25
- end
26
-
27
- Then(/^it reports the error ['"](.*)['"]$/) do |string|
28
- expect(last_command_started).to have_output_on_stderr(/#{Regexp.escape(string)}/)
29
- end
30
-
31
- Then(/^it succeeds$/) do
32
- expect(last_command_started).to have_exit_status(RubyCritic::Command::StatusReporter::SUCCESS)
33
- end
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- Given(/^the smelly file 'smelly.rb'/) do
4
- contents = <<-RUBY.strip_heredoc
5
- class AllTheMethods
6
- def method_missing(method, *args, &block)
7
- message = "I"
8
- eval "message = ' did not'"
9
- eval "message << ' exist,'"
10
- eval "message << ' but now'"
11
- eval "message << ' I do.'"
12
- self.class.send(:define_method, method) { "I did not exist, but now I do." }
13
- self.send(method)
14
- end
15
- end
16
- RUBY
17
- write_file('smelly.rb', contents)
18
- end
19
-
20
- Given(/^the clean file 'clean.rb'/) do
21
- contents = <<-RUBY.strip_heredoc
22
- # Explanatory comment
23
- class Clean
24
- def foo; end
25
- end
26
- RUBY
27
- write_file('clean.rb', contents)
28
- end
29
-
30
- Given(/^the empty file 'empty.rb'/) do
31
- write_file('clean.rb', '')
32
- end
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../../lib/rubycritic'
4
- require_relative '../../lib/rubycritic/cli/application'
5
- require_relative '../../lib/rubycritic/commands/status_reporter'
6
- require 'aruba/cucumber'
7
- require 'minitest/spec'
8
-
9
- #
10
- # Provides runner methods used in the cucumber steps.
11
- #
12
- class RubyCriticWorld
13
- extend MiniTest::Assertions
14
- attr_accessor :assertions
15
-
16
- def initialize
17
- self.assertions = 0
18
- end
19
-
20
- def rubycritic(args)
21
- run_simple("rubycritic #{args} --no-browser", false)
22
- end
23
-
24
- def rake(name, task_def)
25
- header = <<-RUBY.strip_heredoc
26
- require 'rubycritic'
27
- require 'rubycritic/rake_task'
28
-
29
- RUBY
30
- write_file 'Rakefile', header + task_def
31
- run_simple("rake #{name}", false)
32
- end
33
- end
34
-
35
- World do
36
- RubyCriticWorld.new
37
- end
38
-
39
- Before do
40
- Aruba.configure do |config|
41
- config.exit_timeout = 30
42
- end
43
- end
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- lib = File.expand_path('lib', __dir__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'rubycritic/version'
6
-
7
- Gem::Specification.new do |spec|
8
- spec.name = 'rubycritic'
9
- spec.version = RubyCritic::VERSION
10
- spec.authors = ['Guilherme Simoes']
11
- spec.email = ['guilherme.rdems@gmail.com']
12
- spec.description = 'RubyCritic is a tool that wraps around various static analysis gems '\
13
- 'to provide a quality report of your Ruby code.'
14
- spec.summary = 'RubyCritic is a Ruby code quality reporter'
15
- spec.homepage = 'https://github.com/whitesmith/rubycritic'
16
- spec.license = 'MIT'
17
- spec.required_ruby_version = '>= 2.1.0'
18
-
19
- spec.files = `git ls-files`.split("\n")
20
- spec.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
21
- spec.test_files = `git ls-files -- test/*`.split("\n")
22
- spec.require_path = 'lib'
23
-
24
- spec.add_runtime_dependency 'flay', '~> 2.8'
25
- spec.add_runtime_dependency 'flog', '~> 4.4'
26
- spec.add_runtime_dependency 'launchy', '2.4.3'
27
- spec.add_runtime_dependency 'parser', '~> 2.5.0'
28
- spec.add_runtime_dependency 'rainbow', '~> 3.0'
29
- spec.add_runtime_dependency 'reek', '~> 4.4'
30
- spec.add_runtime_dependency 'ruby_parser', '~> 3.8'
31
- spec.add_runtime_dependency 'tty-which', '~> 0.3.0'
32
- spec.add_runtime_dependency 'virtus', '~> 1.0'
33
-
34
- spec.add_development_dependency 'aruba', '~> 0.12', '>= 0.12.0'
35
- spec.add_development_dependency 'bundler', '~> 1.3', '>= 1.3.0'
36
- spec.add_development_dependency 'byebug', '~> 9.0', '>= 8.0'
37
- spec.add_development_dependency 'cucumber', '~> 3.0', '>= 2.2.0'
38
- spec.add_development_dependency 'diff-lcs', '~> 1.3'
39
- spec.add_development_dependency 'fakefs', '~> 0.10', '>= 0.10.0'
40
- spec.add_development_dependency 'minitest', '~> 5.3', '>= 5.3.0'
41
- spec.add_development_dependency 'minitest-around', '~> 0.4.0'
42
- spec.add_development_dependency 'mocha', '~> 1.1', '>= 1.1.0'
43
- spec.add_development_dependency 'rake', '~> 12.0', '>= 11.0.0'
44
- spec.add_development_dependency 'rubocop', '~> 0.53'
45
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class AnalysedModuleDouble < OpenStruct; end
6
-
7
- require_relative '../lib/rubycritic/core/analysed_modules_collection'
8
- class AnalysedModulesCollectionDouble < RubyCritic::AnalysedModulesCollection
9
- def initialize(module_doubles)
10
- @modules = module_doubles
11
- end
12
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'analysers_test_helper'
4
- require 'rubycritic/analysers/churn'
5
- require 'rubycritic/source_control_systems/base'
6
-
7
- describe RubyCritic::Analyser::Churn do
8
- context 'when analysing a file' do
9
- before do
10
- @analysed_module = AnalysedModuleDouble.new(path: 'path_to_some_file.rb')
11
- analysed_modules = [@analysed_module]
12
- analyser = RubyCritic::Analyser::Churn.new(analysed_modules)
13
- analyser.source_control_system = SourceControlSystemDouble.new
14
- analyser.run
15
- end
16
-
17
- it 'calculates its churn' do
18
- @analysed_module.churn.must_equal 1
19
- end
20
-
21
- it 'determines the date of its last commit' do
22
- @analysed_module.committed_at.must_equal '2013-10-09 12:52:49 +0100'
23
- end
24
- end
25
- end
26
-
27
- class SourceControlSystemDouble < RubyCritic::SourceControlSystem::Base
28
- def revisions_count(_path)
29
- 1 # churn
30
- end
31
-
32
- def date_of_last_commit(_path)
33
- '2013-10-09 12:52:49 +0100'
34
- end
35
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'analysers_test_helper'
4
- require 'rubycritic/analysers/complexity'
5
-
6
- describe RubyCritic::Analyser::Complexity do
7
- context 'when analysing a file' do
8
- before do
9
- @analysed_module = AnalysedModuleDouble.new(path: 'test/samples/flog/complex.rb', smells: [])
10
- analysed_modules = [@analysed_module]
11
- RubyCritic::Analyser::Complexity.new(analysed_modules).run
12
- end
13
-
14
- it 'calculates its complexity' do
15
- @analysed_module.complexity.must_be :>, 0
16
- end
17
- end
18
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'analysers_test_helper'
4
- require 'rubycritic/analysers/helpers/methods_counter'
5
-
6
- describe RubyCritic::MethodsCounter do
7
- describe '#count' do
8
- context 'when a file contains Ruby code' do
9
- it 'calculates the number of methods' do
10
- analysed_module = AnalysedModuleDouble.new(path: 'test/samples/methods_count.rb')
11
- RubyCritic::MethodsCounter.new(analysed_module).count.must_equal 2
12
- end
13
- end
14
-
15
- context 'when a file is empty' do
16
- it 'returns 0 as the number of methods' do
17
- analysed_module = AnalysedModuleDouble.new(path: 'test/samples/empty.rb')
18
- RubyCritic::MethodsCounter.new(analysed_module).count.must_equal 0
19
- end
20
- end
21
-
22
- context 'when a file is unparsable' do
23
- it 'does not blow up and returns 0 as the number of methods' do
24
- analysed_module = AnalysedModuleDouble.new(path: 'test/samples/unparsable.rb')
25
- capture_output_streams do
26
- RubyCritic::MethodsCounter.new(analysed_module).count.must_equal 0
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
- require 'rubycritic/analysers/helpers/modules_locator'
5
- require 'rubycritic/core/analysed_module'
6
- require 'pathname'
7
-
8
- describe RubyCritic::ModulesLocator do
9
- describe '#names' do
10
- context 'when a file contains Ruby code' do
11
- it 'returns the names of all the classes and modules inside the file' do
12
- analysed_module = RubyCritic::AnalysedModule.new(
13
- pathname: Pathname.new('test/samples/module_names.rb'),
14
- methods_count: 1
15
- )
16
- RubyCritic::ModulesLocator.new(analysed_module).names
17
- .must_equal ['Foo', 'Foo::Bar', 'Foo::Baz', 'Foo::Qux', 'Foo::Quux::Corge']
18
- end
19
- end
20
-
21
- context 'when a file is empty' do
22
- it 'returns the name of the file titleized' do
23
- analysed_module = RubyCritic::AnalysedModule.new(
24
- pathname: Pathname.new('test/samples/empty.rb'),
25
- methods_count: 1
26
- )
27
- RubyCritic::ModulesLocator.new(analysed_module).names.must_equal ['Empty']
28
- end
29
- end
30
-
31
- context 'when a file is unparsable' do
32
- it 'does not blow up and returns the name of the file titleized' do
33
- analysed_module = RubyCritic::AnalysedModule.new(
34
- pathname: Pathname.new('test/samples/unparsable.rb'),
35
- methods_count: 1
36
- )
37
- capture_output_streams do
38
- RubyCritic::ModulesLocator.new(analysed_module).names.must_equal ['Unparsable']
39
- end
40
- end
41
- end
42
-
43
- context 'when a file has no methods' do
44
- it 'returns the names of all the classes and modules inside the file' do
45
- analysed_module = RubyCritic::AnalysedModule.new(
46
- pathname: Pathname.new('test/samples/no_methods.rb'),
47
- methods_count: 0
48
- )
49
- capture_output_streams do
50
- RubyCritic::ModulesLocator.new(analysed_module).names.must_equal ['Foo::NoMethods']
51
- end
52
- end
53
- end
54
- end
55
- end