rubycritic 2.9.2 → 2.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop_todo.yml +6 -0
- data/.todo.reek +111 -108
- data/CHANGELOG.md +5 -0
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/bin/rubycritic +1 -1
- data/features/command_line_interface/minimum_score.feature +1 -1
- data/features/command_line_interface/options.feature +2 -2
- data/features/rake_task.feature +5 -5
- data/features/step_definitions/rubycritic_steps.rb +4 -4
- data/features/support/env.rb +2 -2
- data/lib/rubycritic/analysers/attributes.rb +1 -1
- data/lib/rubycritic/analysers/churn.rb +1 -1
- data/lib/rubycritic/analysers/complexity.rb +1 -1
- data/lib/rubycritic/analysers/helpers/ast_node.rb +1 -1
- data/lib/rubycritic/analysers/helpers/flay.rb +1 -1
- data/lib/rubycritic/analysers/helpers/flog.rb +1 -1
- data/lib/rubycritic/analysers/helpers/methods_counter.rb +1 -1
- data/lib/rubycritic/analysers/helpers/modules_locator.rb +1 -1
- data/lib/rubycritic/analysers/helpers/parser.rb +1 -1
- data/lib/rubycritic/analysers/helpers/reek.rb +1 -1
- data/lib/rubycritic/analysers/smells/flay.rb +1 -1
- data/lib/rubycritic/analysers/smells/flog.rb +1 -1
- data/lib/rubycritic/analysers/smells/reek.rb +1 -1
- data/lib/rubycritic/analysers_runner.rb +1 -1
- data/lib/rubycritic/browser.rb +1 -1
- data/lib/rubycritic/cli/application.rb +2 -2
- data/lib/rubycritic/cli/options.rb +1 -1
- data/lib/rubycritic/colorize.rb +1 -1
- data/lib/rubycritic/command_factory.rb +1 -1
- data/lib/rubycritic/commands/base.rb +2 -2
- data/lib/rubycritic/commands/ci.rb +1 -1
- data/lib/rubycritic/commands/default.rb +1 -1
- data/lib/rubycritic/commands/help.rb +1 -1
- data/lib/rubycritic/commands/status_reporter.rb +1 -1
- data/lib/rubycritic/commands/version.rb +1 -1
- data/lib/rubycritic/configuration.rb +5 -1
- data/lib/rubycritic/core/analysed_module.rb +2 -2
- data/lib/rubycritic/core/analysed_modules_collection.rb +1 -1
- data/lib/rubycritic/core/location.rb +1 -1
- data/lib/rubycritic/core/rating.rb +1 -1
- data/lib/rubycritic/core/smell.rb +1 -1
- data/lib/rubycritic/generators/console_report.rb +1 -1
- data/lib/rubycritic/generators/html/assets/javascripts/jquery-2.1.0.js +1 -1
- data/lib/rubycritic/generators/html/base.rb +1 -1
- data/lib/rubycritic/generators/html/code_file.rb +1 -1
- data/lib/rubycritic/generators/html/code_index.rb +1 -1
- data/lib/rubycritic/generators/html/line.rb +1 -1
- data/lib/rubycritic/generators/html/overview.rb +1 -1
- data/lib/rubycritic/generators/html/smells_index.rb +1 -1
- data/lib/rubycritic/generators/html/turbulence.rb +1 -1
- data/lib/rubycritic/generators/html/view_helpers.rb +1 -1
- data/lib/rubycritic/generators/html_report.rb +2 -2
- data/lib/rubycritic/generators/json/simple.rb +13 -2
- data/lib/rubycritic/generators/json_report.rb +5 -2
- data/lib/rubycritic/generators/text/list.rb +1 -1
- data/lib/rubycritic/rake_task.rb +2 -2
- data/lib/rubycritic/reporter.rb +1 -1
- data/lib/rubycritic/revision_comparator.rb +1 -1
- data/lib/rubycritic/serializer.rb +1 -1
- data/lib/rubycritic/smells_status_setter.rb +1 -1
- data/lib/rubycritic/source_control_systems/base.rb +1 -1
- data/lib/rubycritic/source_control_systems/double.rb +1 -1
- data/lib/rubycritic/source_control_systems/git.rb +1 -1
- data/lib/rubycritic/source_control_systems/mercurial.rb +1 -1
- data/lib/rubycritic/source_locator.rb +1 -1
- data/lib/rubycritic/version.rb +2 -2
- data/lib/rubycritic.rb +1 -1
- data/rubycritic.gemspec +2 -1
- data/test/lib/rubycritic/analysers/churn_test.rb +3 -3
- data/test/lib/rubycritic/analysers/complexity_test.rb +2 -2
- data/test/lib/rubycritic/analysers/helpers/methods_counter_test.rb +4 -4
- data/test/lib/rubycritic/analysers/helpers/modules_locator_test.rb +9 -9
- data/test/lib/rubycritic/analysers/smells/flay_test.rb +4 -4
- data/test/lib/rubycritic/analysers/smells/flog_test.rb +2 -2
- data/test/lib/rubycritic/analysers/smells/reek_test.rb +2 -2
- data/test/lib/rubycritic/browser_test.rb +2 -2
- data/test/lib/rubycritic/commands/status_reporter_test.rb +7 -7
- data/test/lib/rubycritic/configuration_test.rb +9 -9
- data/test/lib/rubycritic/core/analysed_module_test.rb +9 -9
- data/test/lib/rubycritic/core/analysed_modules_collection_test.rb +3 -3
- data/test/lib/rubycritic/core/location_test.rb +7 -7
- data/test/lib/rubycritic/core/smell_test.rb +15 -15
- data/test/lib/rubycritic/core/smells_array_test.rb +12 -12
- data/test/lib/rubycritic/generators/console_report_test.rb +5 -5
- data/test/lib/rubycritic/generators/json_report_test.rb +36 -0
- data/test/lib/rubycritic/generators/turbulence_test.rb +2 -2
- data/test/lib/rubycritic/generators/view_helpers_test.rb +2 -2
- data/test/lib/rubycritic/revision_comparator_test.rb +10 -10
- data/test/lib/rubycritic/smells_status_setter_test.rb +4 -4
- data/test/lib/rubycritic/source_control_systems/base_test.rb +7 -7
- data/test/lib/rubycritic/source_control_systems/double_test.rb +1 -1
- data/test/lib/rubycritic/source_control_systems/git_test.rb +1 -1
- data/test/lib/rubycritic/source_control_systems/mercurial_test.rb +1 -1
- data/test/lib/rubycritic/source_locator_test.rb +12 -12
- data/test/lib/rubycritic/version_test.rb +2 -2
- metadata +18 -2
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module RubyCritic
|
2
2
|
class Configuration
|
3
3
|
attr_reader :root
|
4
4
|
attr_accessor :source_control_system, :mode, :format, :deduplicate_symlinks,
|
@@ -31,5 +31,9 @@ module Rubycritic
|
|
31
31
|
def self.method_missing(method, *args, &block)
|
32
32
|
configuration.public_send(method, *args, &block)
|
33
33
|
end
|
34
|
+
|
35
|
+
def self.respond_to_missing?(symbol, include_all = false)
|
36
|
+
configuration.respond_to_missing?(symbol) || super
|
37
|
+
end
|
34
38
|
end
|
35
39
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'virtus'
|
2
2
|
require 'rubycritic/core/rating'
|
3
3
|
|
4
|
-
module
|
4
|
+
module RubyCritic
|
5
5
|
class AnalysedModule
|
6
6
|
include Virtus.model
|
7
7
|
|
@@ -27,7 +27,7 @@ module Rubycritic
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def complexity_per_method
|
30
|
-
if methods_count
|
30
|
+
if methods_count.zero?
|
31
31
|
'N/A'
|
32
32
|
else
|
33
33
|
complexity.fdiv(methods_count).round(1)
|
@@ -5,7 +5,7 @@ require 'rubycritic/generators/html/smells_index'
|
|
5
5
|
require 'rubycritic/generators/html/code_index'
|
6
6
|
require 'rubycritic/generators/html/code_file'
|
7
7
|
|
8
|
-
module
|
8
|
+
module RubyCritic
|
9
9
|
module Generator
|
10
10
|
class HtmlReport
|
11
11
|
ASSETS_DIR = File.expand_path('../html/assets', __FILE__)
|
@@ -22,7 +22,7 @@ module Rubycritic
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def browser
|
25
|
-
@browser ||=
|
25
|
+
@browser ||= RubyCritic::Browser.new(report_location)
|
26
26
|
end
|
27
27
|
|
28
28
|
private
|
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'rubycritic/version'
|
3
|
+
require 'pathname'
|
3
4
|
|
4
|
-
module
|
5
|
+
module RubyCritic
|
5
6
|
module Generator
|
6
7
|
module Json
|
7
8
|
class Simple
|
@@ -9,6 +10,8 @@ module Rubycritic
|
|
9
10
|
@analysed_modules = analysed_modules
|
10
11
|
end
|
11
12
|
|
13
|
+
FILE_NAME = 'report.json'.freeze
|
14
|
+
|
12
15
|
def render
|
13
16
|
JSON.dump(data)
|
14
17
|
end
|
@@ -17,13 +20,21 @@ module Rubycritic
|
|
17
20
|
{
|
18
21
|
metadata: {
|
19
22
|
rubycritic: {
|
20
|
-
version:
|
23
|
+
version: RubyCritic::VERSION
|
21
24
|
}
|
22
25
|
},
|
23
26
|
analysed_modules: @analysed_modules,
|
24
27
|
score: @analysed_modules.score
|
25
28
|
}
|
26
29
|
end
|
30
|
+
|
31
|
+
def file_directory
|
32
|
+
@file_directory ||= Pathname.new(Config.root)
|
33
|
+
end
|
34
|
+
|
35
|
+
def file_pathname
|
36
|
+
Pathname.new(file_directory).join FILE_NAME
|
37
|
+
end
|
27
38
|
end
|
28
39
|
end
|
29
40
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'rubycritic/generators/json/simple'
|
2
2
|
|
3
|
-
module
|
3
|
+
module RubyCritic
|
4
4
|
module Generator
|
5
5
|
class JsonReport
|
6
6
|
def initialize(analysed_modules)
|
@@ -8,7 +8,10 @@ module Rubycritic
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def generate_report
|
11
|
-
|
11
|
+
FileUtils.mkdir_p(generator.file_directory)
|
12
|
+
File.open(generator.file_pathname, 'w+') do |file|
|
13
|
+
file.write(generator.render)
|
14
|
+
end
|
12
15
|
end
|
13
16
|
|
14
17
|
private
|
data/lib/rubycritic/rake_task.rb
CHANGED
@@ -3,7 +3,7 @@ require 'rake/tasklib'
|
|
3
3
|
require 'English'
|
4
4
|
require 'rubycritic/cli/application'
|
5
5
|
|
6
|
-
module
|
6
|
+
module RubyCritic
|
7
7
|
#
|
8
8
|
# A rake task that runs RubyCritic on a set of source files.
|
9
9
|
#
|
@@ -58,7 +58,7 @@ module Rubycritic
|
|
58
58
|
puts "\n\n!!! Running `#{name}` rake command\n"
|
59
59
|
puts "!!! Inspecting #{paths} #{options.empty? ? '' : "with options #{options}"}\n\n"
|
60
60
|
end
|
61
|
-
application =
|
61
|
+
application = RubyCritic::Cli::Application.new(options_as_arguments + paths)
|
62
62
|
application.execute
|
63
63
|
end
|
64
64
|
|
data/lib/rubycritic/reporter.rb
CHANGED
data/lib/rubycritic/version.rb
CHANGED
data/lib/rubycritic.rb
CHANGED
data/rubycritic.gemspec
CHANGED
@@ -5,7 +5,7 @@ require 'rubycritic/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'rubycritic'
|
8
|
-
spec.version =
|
8
|
+
spec.version = RubyCritic::VERSION
|
9
9
|
spec.authors = ['Guilherme Simoes']
|
10
10
|
spec.email = ['guilherme.rdems@gmail.com']
|
11
11
|
spec.description = 'RubyCritic is a tool that wraps around various static analysis gems '\
|
@@ -32,6 +32,7 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.add_development_dependency 'aruba'
|
33
33
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
34
34
|
spec.add_development_dependency 'cucumber'
|
35
|
+
spec.add_development_dependency 'fakefs'
|
35
36
|
spec.add_development_dependency 'rake'
|
36
37
|
spec.add_development_dependency 'minitest', '~> 5.3'
|
37
38
|
spec.add_development_dependency 'mocha', '~> 1.1'
|
@@ -2,12 +2,12 @@ require 'analysers_test_helper'
|
|
2
2
|
require 'rubycritic/analysers/churn'
|
3
3
|
require 'rubycritic/source_control_systems/base'
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe RubyCritic::Analyser::Churn do
|
6
6
|
context 'when analysing a file' do
|
7
7
|
before do
|
8
8
|
@analysed_module = AnalysedModuleDouble.new(path: 'path_to_some_file.rb')
|
9
9
|
analysed_modules = [@analysed_module]
|
10
|
-
analyser =
|
10
|
+
analyser = RubyCritic::Analyser::Churn.new(analysed_modules)
|
11
11
|
analyser.source_control_system = SourceControlSystemDouble.new
|
12
12
|
analyser.run
|
13
13
|
end
|
@@ -22,7 +22,7 @@ describe Rubycritic::Analyser::Churn do
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
class SourceControlSystemDouble <
|
25
|
+
class SourceControlSystemDouble < RubyCritic::SourceControlSystem::Base
|
26
26
|
def revisions_count(_path)
|
27
27
|
1 # churn
|
28
28
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'analysers_test_helper'
|
2
2
|
require 'rubycritic/analysers/complexity'
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe RubyCritic::Analyser::Complexity do
|
5
5
|
context 'when analysing a file' do
|
6
6
|
before do
|
7
7
|
@analysed_module = AnalysedModuleDouble.new(path: 'test/samples/flog/complex.rb', smells: [])
|
8
8
|
analysed_modules = [@analysed_module]
|
9
|
-
|
9
|
+
RubyCritic::Analyser::Complexity.new(analysed_modules).run
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'calculates its complexity' do
|
@@ -1,19 +1,19 @@
|
|
1
1
|
require 'analysers_test_helper'
|
2
2
|
require 'rubycritic/analysers/helpers/methods_counter'
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe RubyCritic::MethodsCounter do
|
5
5
|
describe '#count' do
|
6
6
|
context 'when a file contains Ruby code' do
|
7
7
|
it 'calculates the number of methods' do
|
8
8
|
analysed_module = AnalysedModuleDouble.new(path: 'test/samples/methods_count.rb')
|
9
|
-
|
9
|
+
RubyCritic::MethodsCounter.new(analysed_module).count.must_equal 2
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
context 'when a file is empty' do
|
14
14
|
it 'returns 0 as the number of methods' do
|
15
15
|
analysed_module = AnalysedModuleDouble.new(path: 'test/samples/empty.rb')
|
16
|
-
|
16
|
+
RubyCritic::MethodsCounter.new(analysed_module).count.must_equal 0
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -21,7 +21,7 @@ describe Rubycritic::MethodsCounter do
|
|
21
21
|
it 'does not blow up and returns 0 as the number of methods' do
|
22
22
|
analysed_module = AnalysedModuleDouble.new(path: 'test/samples/unparsable.rb')
|
23
23
|
capture_output_streams do
|
24
|
-
|
24
|
+
RubyCritic::MethodsCounter.new(analysed_module).count.must_equal 0
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -3,49 +3,49 @@ require 'rubycritic/analysers/helpers/modules_locator'
|
|
3
3
|
require 'rubycritic/core/analysed_module'
|
4
4
|
require 'pathname'
|
5
5
|
|
6
|
-
describe
|
6
|
+
describe RubyCritic::ModulesLocator do
|
7
7
|
describe '#names' do
|
8
8
|
context 'when a file contains Ruby code' do
|
9
9
|
it 'returns the names of all the classes and modules inside the file' do
|
10
|
-
analysed_module =
|
10
|
+
analysed_module = RubyCritic::AnalysedModule.new(
|
11
11
|
pathname: Pathname.new('test/samples/module_names.rb'),
|
12
12
|
methods_count: 1
|
13
13
|
)
|
14
|
-
|
14
|
+
RubyCritic::ModulesLocator.new(analysed_module).names
|
15
15
|
.must_equal ['Foo', 'Foo::Bar', 'Foo::Baz', 'Foo::Qux', 'Foo::Quux::Corge']
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
context 'when a file is empty' do
|
20
20
|
it 'returns the name of the file titleized' do
|
21
|
-
analysed_module =
|
21
|
+
analysed_module = RubyCritic::AnalysedModule.new(
|
22
22
|
pathname: Pathname.new('test/samples/empty.rb'),
|
23
23
|
methods_count: 1
|
24
24
|
)
|
25
|
-
|
25
|
+
RubyCritic::ModulesLocator.new(analysed_module).names.must_equal ['Empty']
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
context 'when a file is unparsable' do
|
30
30
|
it 'does not blow up and returns the name of the file titleized' do
|
31
|
-
analysed_module =
|
31
|
+
analysed_module = RubyCritic::AnalysedModule.new(
|
32
32
|
pathname: Pathname.new('test/samples/unparsable.rb'),
|
33
33
|
methods_count: 1
|
34
34
|
)
|
35
35
|
capture_output_streams do
|
36
|
-
|
36
|
+
RubyCritic::ModulesLocator.new(analysed_module).names.must_equal ['Unparsable']
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
context 'when a file has no methods' do
|
42
42
|
it 'returns the names of all the classes and modules inside the file' do
|
43
|
-
analysed_module =
|
43
|
+
analysed_module = RubyCritic::AnalysedModule.new(
|
44
44
|
pathname: Pathname.new('test/samples/no_methods.rb'),
|
45
45
|
methods_count: 0
|
46
46
|
)
|
47
47
|
capture_output_streams do
|
48
|
-
|
48
|
+
RubyCritic::ModulesLocator.new(analysed_module).names.must_equal ['Foo::NoMethods']
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
@@ -3,14 +3,14 @@ require 'rubycritic/analysers/smells/flay'
|
|
3
3
|
require 'rubycritic/core/analysed_module'
|
4
4
|
require 'pathname'
|
5
5
|
|
6
|
-
describe
|
6
|
+
describe RubyCritic::Analyser::FlaySmells do
|
7
7
|
context 'when analysing a bunch of files with duplicate code' do
|
8
8
|
before do
|
9
9
|
@analysed_modules = [
|
10
|
-
|
11
|
-
|
10
|
+
RubyCritic::AnalysedModule.new(pathname: Pathname.new('test/samples/flay/smelly.rb')),
|
11
|
+
RubyCritic::AnalysedModule.new(pathname: Pathname.new('test/samples/flay/smelly2.rb'))
|
12
12
|
]
|
13
|
-
|
13
|
+
RubyCritic::Analyser::FlaySmells.new(@analysed_modules).run
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'detects its smells' do
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'analysers_test_helper'
|
2
2
|
require 'rubycritic/analysers/smells/flog'
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe RubyCritic::Analyser::FlogSmells do
|
5
5
|
context 'when analysing a complex file' do
|
6
6
|
before do
|
7
7
|
@analysed_module = AnalysedModuleDouble.new(path: 'test/samples/flog/smelly.rb', smells: [])
|
8
8
|
analysed_modules = [@analysed_module]
|
9
|
-
|
9
|
+
RubyCritic::Analyser::FlogSmells.new(analysed_modules).run
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'detects its smells' do
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'analysers_test_helper'
|
2
2
|
require 'rubycritic/analysers/smells/reek'
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe RubyCritic::Analyser::ReekSmells do
|
5
5
|
context 'when analysing a smelly file' do
|
6
6
|
before do
|
7
7
|
pathname = Pathname.new('test/samples/reek/smelly.rb')
|
8
8
|
@analysed_module = AnalysedModuleDouble.new(pathname: pathname, smells: [])
|
9
9
|
analysed_modules = [@analysed_module]
|
10
|
-
|
10
|
+
RubyCritic::Analyser::ReekSmells.new(analysed_modules).run
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'detects its smells' do
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
require 'rubycritic/browser'
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe RubyCritic::Browser do
|
5
5
|
before do
|
6
6
|
@report_path = 'tmp/rubycritic/overview.html'
|
7
|
-
@browser =
|
7
|
+
@browser = RubyCritic::Browser.new @report_path
|
8
8
|
end
|
9
9
|
|
10
10
|
describe '#open' do
|
@@ -2,15 +2,15 @@ require 'test_helper'
|
|
2
2
|
require 'rubycritic/commands/status_reporter'
|
3
3
|
require 'rubycritic/cli/options'
|
4
4
|
|
5
|
-
describe
|
6
|
-
let(:success_status) {
|
7
|
-
let(:score_below_minimum) {
|
5
|
+
describe RubyCritic::Command::StatusReporter do
|
6
|
+
let(:success_status) { RubyCritic::Command::StatusReporter::SUCCESS }
|
7
|
+
let(:score_below_minimum) { RubyCritic::Command::StatusReporter::SCORE_BELOW_MINIMUM }
|
8
8
|
|
9
9
|
describe 'with default options' do
|
10
10
|
before do
|
11
|
-
@options =
|
11
|
+
@options = RubyCritic::Cli::Options.new([])
|
12
12
|
@options.parse
|
13
|
-
@reporter =
|
13
|
+
@reporter = RubyCritic::Command::StatusReporter.new(@options.to_h)
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'has a default' do
|
@@ -33,9 +33,9 @@ describe Rubycritic::Command::StatusReporter do
|
|
33
33
|
|
34
34
|
describe 'with minimum-score option' do
|
35
35
|
before do
|
36
|
-
@options =
|
36
|
+
@options = RubyCritic::Cli::Options.new(['-s', '99'])
|
37
37
|
@options.parse
|
38
|
-
@reporter =
|
38
|
+
@reporter = RubyCritic::Command::StatusReporter.new(@options.to_h)
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'has a default' do
|