rubycritic 3.4.0 → 3.5.0
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 +4 -4
- data/CHANGELOG.md +10 -2
- data/README.md +12 -10
- data/lib/rubycritic/cli/options.rb +25 -3
- data/lib/rubycritic/command_factory.rb +3 -0
- data/lib/rubycritic/commands/ci.rb +2 -8
- data/lib/rubycritic/commands/compare.rb +105 -0
- data/lib/rubycritic/commands/utils/build_number_file.rb +35 -0
- data/lib/rubycritic/configuration.rb +18 -1
- data/lib/rubycritic/core/analysed_modules_collection.rb +23 -3
- data/lib/rubycritic/generators/html/assets/stylesheets/application.css +20 -0
- data/lib/rubycritic/generators/html/base.rb +1 -1
- data/lib/rubycritic/generators/html/code_file.rb +11 -0
- data/lib/rubycritic/generators/html/code_index.rb +7 -0
- data/lib/rubycritic/generators/html/overview.rb +7 -0
- data/lib/rubycritic/generators/html/smells_index.rb +7 -0
- data/lib/rubycritic/generators/html/templates/code_index.html.erb +10 -0
- data/lib/rubycritic/generators/html/templates/layouts/application.html.erb +7 -0
- data/lib/rubycritic/generators/html/view_helpers.rb +10 -1
- data/lib/rubycritic/source_control_systems/git.rb +27 -1
- data/lib/rubycritic/version.rb +1 -1
- metadata +7 -131
- data/.gitignore +0 -23
- data/.rubocop.yml +0 -37
- data/.rubocop_todo.yml +0 -45
- data/.todo.reek +0 -142
- data/.travis.yml +0 -29
- data/.yardopts +0 -5
- data/docs/building-own-code-climate.md +0 -156
- data/docs/core-metrics.md +0 -72
- data/docs/jenkins-pr-reviews.md +0 -64
- data/features/command_line_interface/minimum_score.feature +0 -39
- data/features/command_line_interface/options.feature +0 -37
- data/features/rake_task.feature +0 -65
- data/features/step_definitions/rake_task_steps.rb +0 -5
- data/features/step_definitions/rubycritic_steps.rb +0 -33
- data/features/step_definitions/sample_file_steps.rb +0 -32
- data/features/support/env.rb +0 -43
- data/images/churn-vs-complexity.png +0 -0
- data/images/code.png +0 -0
- data/images/logo.png +0 -0
- data/images/overview.png +0 -0
- data/images/rating.png +0 -0
- data/images/reek.png +0 -0
- data/images/smell-details.png +0 -0
- data/images/smells.png +0 -0
- data/images/whitesmith.png +0 -0
- data/rubycritic.gemspec +0 -45
- data/test/analysers_test_helper.rb +0 -12
- data/test/lib/rubycritic/analysers/churn_test.rb +0 -35
- data/test/lib/rubycritic/analysers/complexity_test.rb +0 -18
- data/test/lib/rubycritic/analysers/helpers/methods_counter_test.rb +0 -31
- data/test/lib/rubycritic/analysers/helpers/modules_locator_test.rb +0 -55
- data/test/lib/rubycritic/analysers/smells/flay_test.rb +0 -41
- data/test/lib/rubycritic/analysers/smells/flog_test.rb +0 -28
- data/test/lib/rubycritic/analysers/smells/reek_test.rb +0 -32
- data/test/lib/rubycritic/analysis_summary_test.rb +0 -30
- data/test/lib/rubycritic/browser_test.rb +0 -18
- data/test/lib/rubycritic/commands/status_reporter_test.rb +0 -81
- data/test/lib/rubycritic/configuration_test.rb +0 -31
- data/test/lib/rubycritic/core/analysed_module_test.rb +0 -90
- data/test/lib/rubycritic/core/analysed_modules_collection_test.rb +0 -111
- data/test/lib/rubycritic/core/location_test.rb +0 -39
- data/test/lib/rubycritic/core/smell_test.rb +0 -105
- data/test/lib/rubycritic/core/smells_array_test.rb +0 -30
- data/test/lib/rubycritic/generators/console_report_test.rb +0 -83
- data/test/lib/rubycritic/generators/json_report_test.rb +0 -38
- data/test/lib/rubycritic/generators/lint_report_test.rb +0 -37
- data/test/lib/rubycritic/generators/turbulence_test.rb +0 -19
- data/test/lib/rubycritic/generators/view_helpers_test.rb +0 -85
- data/test/lib/rubycritic/revision_comparator_test.rb +0 -66
- data/test/lib/rubycritic/smells_status_setter_test.rb +0 -24
- data/test/lib/rubycritic/source_control_systems/base_test.rb +0 -31
- data/test/lib/rubycritic/source_control_systems/double_test.rb +0 -13
- data/test/lib/rubycritic/source_control_systems/git_test.rb +0 -15
- data/test/lib/rubycritic/source_control_systems/interfaces/basic.rb +0 -9
- data/test/lib/rubycritic/source_control_systems/interfaces/time_travel.rb +0 -9
- data/test/lib/rubycritic/source_control_systems/mercurial_test.rb +0 -13
- data/test/lib/rubycritic/source_control_systems/perforce_test.rb +0 -176
- data/test/lib/rubycritic/source_locator_test.rb +0 -80
- data/test/lib/rubycritic/version_test.rb +0 -10
- data/test/samples/empty.rb +0 -0
- data/test/samples/flay/smelly.rb +0 -8
- data/test/samples/flay/smelly2.rb +0 -8
- data/test/samples/flog/complex.rb +0 -11
- data/test/samples/flog/smelly.rb +0 -11
- data/test/samples/location/dir1/file1.rb +0 -0
- data/test/samples/location/file0.rb +0 -0
- data/test/samples/location/file0_symlink.rb +0 -1
- data/test/samples/location/file_with_different_extension.py +0 -0
- data/test/samples/location/file_with_no_extension +0 -0
- data/test/samples/methods_count.rb +0 -7
- data/test/samples/module_names.rb +0 -18
- data/test/samples/no_methods.rb +0 -4
- data/test/samples/reek/not_smelly.rb +0 -35
- data/test/samples/reek/smelly.rb +0 -17
- data/test/samples/unparsable.rb +0 -1
- data/test/test_helper.rb +0 -64
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6299ec37fabeb3fb630a70326b39377eee3aa4c4
|
|
4
|
+
data.tar.gz: c82518cf3a9c6120e109399fb967ede60a38b7bf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e9df974efb0abbf35414284b494b4295a8b927d8c5d7c7a688dcb22666dfb7b2d2b183fa0621f1b50a70fe82f5e9376f7d5c5b3022305ce850fdfbd100b5d730
|
|
7
|
+
data.tar.gz: e57225932ea86556058a25b9f06fe6068457edd1d127abdbdbda126d040dc62a8964eb4bc6abcda4f4b39ba43aa7626078ba81d8cd6e7ff966e4ec10be72a8cc
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
# master [(unreleased)](https://github.com/whitesmith/rubycritic/compare/v3.
|
|
1
|
+
# master [(unreleased)](https://github.com/whitesmith/rubycritic/compare/v3.5.0...master)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# 3.5.0 / 2018-09-03 [(commits)](https://github.com/whitesmith/rubycritic/compare/v3.4.0...v3.5.0)
|
|
4
|
+
|
|
5
|
+
* [CHANGE] Add ability to compare only the modified files between two branches. Refactored option `--mode-ci`, added `--branch` and `--maximum-decrease` (by [@HemanthMudalaiah][])
|
|
6
|
+
* [CHANGE] Optimized all images (by [@SuperSandro2000][])
|
|
7
|
+
* [BUGFIX] Fixed opening report in chrome on windows (by [@SuperSandro2000][])
|
|
8
|
+
* [BUGFIX] Fixed churn on windows (by [@SuperSandro2000][])
|
|
9
|
+
* [BUGFIX] Fixed gem not installing under restricted windows environments (by [@onumis][])
|
|
4
10
|
|
|
5
11
|
# 3.4.0 / 2018-03-22 [(commits)](https://github.com/whitesmith/rubycritic/compare/v3.3.0...v3.4.0)
|
|
6
12
|
|
|
@@ -236,3 +242,5 @@
|
|
|
236
242
|
[@nightscape]: https://github.com/nightscape
|
|
237
243
|
[@nbekirov]: https://github.com/nbekirov
|
|
238
244
|
[@joshrpowell]: https://github.com/joshrpowell
|
|
245
|
+
[@HemanthMudalaiah]: https://github.com/HemanthMudalaiah
|
|
246
|
+
[@SuperSandro2000]: https://github.com/SuperSandro2000
|
data/README.md
CHANGED
|
@@ -112,16 +112,18 @@ For a full list of the command-line options run:
|
|
|
112
112
|
$ rubycritic --help
|
|
113
113
|
```
|
|
114
114
|
|
|
115
|
-
| Command flag
|
|
116
|
-
|
|
117
|
-
| `-v` / `--version`
|
|
118
|
-
| `-p` / `--path`
|
|
119
|
-
| `-f` / `--format`
|
|
120
|
-
| `-s` / `--minimum-score`
|
|
121
|
-
| `--mode-ci`
|
|
122
|
-
| `--
|
|
123
|
-
| `--
|
|
124
|
-
| `--
|
|
115
|
+
| Command flag | Description |
|
|
116
|
+
|-----------------------------|------------------------------------------------------------------------------------------------|
|
|
117
|
+
| `-v` / `--version` | Displays the current version and exits |
|
|
118
|
+
| `-p` / `--path` | Set path where report will be saved (tmp/rubycritic by default) |
|
|
119
|
+
| `-f` / `--format` | Report smells in the given format: `html` (default; will open in a browser), `json`, `console` |
|
|
120
|
+
| `-s` / `--minimum-score` | Set a minimum score (FLOAT: ex: 96.28), default: 0 |
|
|
121
|
+
| `-m` / `--mode-ci` | Use CI mode. Faster, analyses diffs w.r.t base_branch (default: master), see -b |
|
|
122
|
+
| `-b` / `--branch` | Set branch to compare |
|
|
123
|
+
| `-t` / `--maximum-decrease` | Set a threshold for score difference between two branches (works only with -b), default: 0 |
|
|
124
|
+
| `--deduplicate-symlinks` | De-duplicate symlinks based on their final target |
|
|
125
|
+
| `--suppress-ratings` | Suppress letter ratings |
|
|
126
|
+
| `--no-browser` | Do not open html report with browser |
|
|
125
127
|
|
|
126
128
|
|
|
127
129
|
### Analyzer Configuration
|
|
@@ -20,6 +20,17 @@ module RubyCritic
|
|
|
20
20
|
@root = path
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
+
opts.on('-b', '--branch BRANCH', 'Set branch to compare') do |branch|
|
|
24
|
+
self.base_branch = String(branch)
|
|
25
|
+
set_current_branch
|
|
26
|
+
self.mode = :compare_branches
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
opts.on('-t', '--maximum-decrease [MAX_DECREASE]',
|
|
30
|
+
'Set a threshold for score difference between two branches (works only with -b)') do |threshold_score|
|
|
31
|
+
self.threshold_score = Integer(threshold_score)
|
|
32
|
+
end
|
|
33
|
+
|
|
23
34
|
opts.on(
|
|
24
35
|
'-f', '--format [FORMAT]',
|
|
25
36
|
%i[html json console lint],
|
|
@@ -36,7 +47,10 @@ module RubyCritic
|
|
|
36
47
|
self.minimum_score = Float(min_score)
|
|
37
48
|
end
|
|
38
49
|
|
|
39
|
-
opts.on('-m', '--mode-ci
|
|
50
|
+
opts.on('-m', '--mode-ci [BASE_BRANCH]',
|
|
51
|
+
'Use CI mode (faster, analyses diffs w.r.t base_branch (default: master))') do |branch|
|
|
52
|
+
self.base_branch = branch || 'master'
|
|
53
|
+
set_current_branch
|
|
40
54
|
self.mode = :ci
|
|
41
55
|
end
|
|
42
56
|
|
|
@@ -73,7 +87,10 @@ module RubyCritic
|
|
|
73
87
|
suppress_ratings: suppress_ratings,
|
|
74
88
|
help_text: parser.help,
|
|
75
89
|
minimum_score: minimum_score || 0,
|
|
76
|
-
no_browser: no_browser
|
|
90
|
+
no_browser: no_browser,
|
|
91
|
+
base_branch: base_branch,
|
|
92
|
+
feature_branch: feature_branch,
|
|
93
|
+
threshold_score: threshold_score || 0
|
|
77
94
|
}
|
|
78
95
|
end
|
|
79
96
|
# rubocop:enable Metrics/MethodLength
|
|
@@ -81,7 +98,8 @@ module RubyCritic
|
|
|
81
98
|
private
|
|
82
99
|
|
|
83
100
|
attr_accessor :mode, :root, :format, :deduplicate_symlinks,
|
|
84
|
-
:suppress_ratings, :minimum_score, :no_browser,
|
|
101
|
+
:suppress_ratings, :minimum_score, :no_browser,
|
|
102
|
+
:parser, :base_branch, :feature_branch, :threshold_score
|
|
85
103
|
def paths
|
|
86
104
|
if @argv.empty?
|
|
87
105
|
['.']
|
|
@@ -89,6 +107,10 @@ module RubyCritic
|
|
|
89
107
|
@argv
|
|
90
108
|
end
|
|
91
109
|
end
|
|
110
|
+
|
|
111
|
+
def set_current_branch
|
|
112
|
+
self.feature_branch = SourceControlSystem::Git.current_branch
|
|
113
|
+
end
|
|
92
114
|
end
|
|
93
115
|
end
|
|
94
116
|
end
|
|
@@ -4,17 +4,11 @@ require 'rubycritic/source_control_systems/base'
|
|
|
4
4
|
require 'rubycritic/analysers_runner'
|
|
5
5
|
require 'rubycritic/reporter'
|
|
6
6
|
require 'rubycritic/commands/default'
|
|
7
|
+
require 'rubycritic/commands/compare'
|
|
7
8
|
|
|
8
9
|
module RubyCritic
|
|
9
10
|
module Command
|
|
10
|
-
class Ci <
|
|
11
|
-
def critique
|
|
12
|
-
AnalysersRunner.new(paths).run
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
private
|
|
16
|
-
|
|
17
|
-
attr_reader :paths
|
|
11
|
+
class Ci < Compare
|
|
18
12
|
end
|
|
19
13
|
end
|
|
20
14
|
end
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rubycritic/source_control_systems/base'
|
|
4
|
+
require 'rubycritic/analysers_runner'
|
|
5
|
+
require 'rubycritic/revision_comparator'
|
|
6
|
+
require 'rubycritic/reporter'
|
|
7
|
+
require 'rubycritic/commands/base'
|
|
8
|
+
require 'rubycritic/commands/default'
|
|
9
|
+
require 'rubycritic/commands/utils/build_number_file'
|
|
10
|
+
|
|
11
|
+
module RubyCritic
|
|
12
|
+
module Command
|
|
13
|
+
class Compare < Default
|
|
14
|
+
def initialize(options)
|
|
15
|
+
super
|
|
16
|
+
@build_number = 0
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def execute
|
|
20
|
+
compare_branches
|
|
21
|
+
status_reporter.score = Config.feature_branch_score
|
|
22
|
+
status_reporter
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
attr_reader :paths, :status_reporter
|
|
28
|
+
|
|
29
|
+
def compare_branches
|
|
30
|
+
@build_number = Utils::BuildNumberFile.new.update_build_number
|
|
31
|
+
set_root_paths
|
|
32
|
+
original_no_browser_config = Config.no_browser
|
|
33
|
+
Config.no_browser = true
|
|
34
|
+
analyse_branch(:base_branch)
|
|
35
|
+
analyse_branch(:feature_branch)
|
|
36
|
+
Config.no_browser = original_no_browser_config
|
|
37
|
+
analyse_modified_files
|
|
38
|
+
compare_code_quality
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def set_root_paths
|
|
42
|
+
Config.base_root_directory = Pathname.new(branch_directory(:base_branch))
|
|
43
|
+
Config.feature_root_directory = Pathname.new(branch_directory(:feature_branch))
|
|
44
|
+
Config.compare_root_directory = Pathname.new("#{Config.root}/compare")
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# switch branch and analyse files
|
|
48
|
+
def analyse_branch(branch)
|
|
49
|
+
SourceControlSystem::Git.switch_branch(Config.send(branch))
|
|
50
|
+
critic = critique(branch)
|
|
51
|
+
Config.send(:"#{branch}_score=", critic.score)
|
|
52
|
+
Config.root = branch_directory(branch)
|
|
53
|
+
report(critic)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# generate report only for modified files
|
|
57
|
+
def analyse_modified_files
|
|
58
|
+
modified_files = Config.feature_branch_collection.where(SourceControlSystem::Git.modified_files)
|
|
59
|
+
analysed_modules = AnalysedModulesCollection.new(modified_files.map(&:path), modified_files)
|
|
60
|
+
Config.root = "#{Config.root}/compare"
|
|
61
|
+
report(analysed_modules)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def compare_code_quality
|
|
65
|
+
build_details
|
|
66
|
+
compare_threshold
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# mark build as failed if the diff b/w the score of
|
|
70
|
+
# two branches is greater than threshold value
|
|
71
|
+
def compare_threshold
|
|
72
|
+
return unless mark_build_fail?
|
|
73
|
+
print("Threshold: #{Config.threshold_score}\n")
|
|
74
|
+
print("Difference: #{(Config.base_branch_score - Config.feature_branch_score).abs}\n")
|
|
75
|
+
abort('The score difference between the two branches is over the threshold.')
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def mark_build_fail?
|
|
79
|
+
Config.threshold_score > 0 && threshold_reached?
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def threshold_reached?
|
|
83
|
+
(Config.base_branch_score - Config.feature_branch_score) > Config.threshold_score
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def branch_directory(branch)
|
|
87
|
+
"#{Config.root}/compare/#{Config.send(branch)}"
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# create a txt file with the branch score details
|
|
91
|
+
def build_details
|
|
92
|
+
details = "Base branch (#{Config.base_branch}) score: #{Config.base_branch_score} \n"\
|
|
93
|
+
"Feature branch (#{Config.feature_branch}) score: #{Config.feature_branch_score} \n"
|
|
94
|
+
File.open("#{Config.compare_root_directory}/build_details.txt", 'w') { |file| file.write(details) }
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# store the analysed moduled collection based on the branch
|
|
98
|
+
def critique(branch)
|
|
99
|
+
module_collection = AnalysersRunner.new(paths).run
|
|
100
|
+
Config.send(:"#{branch}_collection=", module_collection)
|
|
101
|
+
RevisionComparator.new(paths).set_statuses(module_collection)
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module RubyCritic
|
|
2
|
+
module Command
|
|
3
|
+
module Utils
|
|
4
|
+
class BuildNumberFile
|
|
5
|
+
attr_reader :file, :build_number
|
|
6
|
+
|
|
7
|
+
def initialize
|
|
8
|
+
open_build_number_file
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# keep track of the number of builds and
|
|
12
|
+
# use this build number to create separate directory for each build
|
|
13
|
+
def update_build_number
|
|
14
|
+
@build_number = file.read.to_i + 1
|
|
15
|
+
write_build_number
|
|
16
|
+
build_number
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def write_build_number
|
|
20
|
+
file.rewind
|
|
21
|
+
file.write(build_number)
|
|
22
|
+
file.close
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def open_build_number_file
|
|
26
|
+
root = Config.root
|
|
27
|
+
FileUtils.mkdir_p(root) unless File.directory?(root)
|
|
28
|
+
location = "#{root}/build_number.txt"
|
|
29
|
+
File.new(location, 'a') unless File.exist?(location)
|
|
30
|
+
@file = File.open(location, 'r+')
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -6,7 +6,11 @@ module RubyCritic
|
|
|
6
6
|
class Configuration
|
|
7
7
|
attr_reader :root
|
|
8
8
|
attr_accessor :source_control_system, :mode, :format, :deduplicate_symlinks,
|
|
9
|
-
:suppress_ratings, :open_with, :no_browser
|
|
9
|
+
:suppress_ratings, :open_with, :no_browser, :base_branch,
|
|
10
|
+
:feature_branch, :base_branch_score, :feature_branch_score,
|
|
11
|
+
:base_root_directory, :feature_root_directory,
|
|
12
|
+
:compare_root_directory, :threshold_score, :base_branch_collection,
|
|
13
|
+
:feature_branch_collection
|
|
10
14
|
|
|
11
15
|
def set(options)
|
|
12
16
|
self.mode = options[:mode] || :default
|
|
@@ -16,6 +20,9 @@ module RubyCritic
|
|
|
16
20
|
self.suppress_ratings = options[:suppress_ratings] || false
|
|
17
21
|
self.open_with = options[:open_with]
|
|
18
22
|
self.no_browser = options[:no_browser]
|
|
23
|
+
self.base_branch = options[:base_branch]
|
|
24
|
+
self.feature_branch = options[:feature_branch]
|
|
25
|
+
self.threshold_score = options[:threshold_score]
|
|
19
26
|
end
|
|
20
27
|
|
|
21
28
|
def root=(path)
|
|
@@ -37,6 +44,16 @@ module RubyCritic
|
|
|
37
44
|
configuration.set(options)
|
|
38
45
|
end
|
|
39
46
|
|
|
47
|
+
def self.compare_branches_mode?
|
|
48
|
+
mode = Config.mode
|
|
49
|
+
mode == :compare_branches || mode == :ci
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def self.build_mode?
|
|
53
|
+
mode = Config.mode
|
|
54
|
+
(mode == :compare_branches || mode == :ci) && !Config.no_browser
|
|
55
|
+
end
|
|
56
|
+
|
|
40
57
|
def self.method_missing(method, *args, &block)
|
|
41
58
|
configuration.public_send(method, *args, &block)
|
|
42
59
|
end
|
|
@@ -17,9 +17,14 @@ module RubyCritic
|
|
|
17
17
|
ZERO_SCORE_COST = 16.0
|
|
18
18
|
COST_MULTIPLIER = MAX_SCORE / ZERO_SCORE_COST
|
|
19
19
|
|
|
20
|
-
def initialize(paths)
|
|
20
|
+
def initialize(paths, modules = nil)
|
|
21
21
|
@modules = SourceLocator.new(paths).pathnames.map do |pathname|
|
|
22
|
-
|
|
22
|
+
if modules
|
|
23
|
+
analysed_module = modules.find { |mod| mod.pathname == pathname }
|
|
24
|
+
build_analysed_module(analysed_module)
|
|
25
|
+
else
|
|
26
|
+
AnalysedModule.new(pathname: pathname)
|
|
27
|
+
end
|
|
23
28
|
end
|
|
24
29
|
end
|
|
25
30
|
|
|
@@ -27,13 +32,21 @@ module RubyCritic
|
|
|
27
32
|
@modules.each(&block)
|
|
28
33
|
end
|
|
29
34
|
|
|
35
|
+
def where(module_paths)
|
|
36
|
+
@modules.find_all { |mod| module_paths.include? mod.path }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def find(module_path)
|
|
40
|
+
@modules.find { |mod| mod.pathname == module_path }
|
|
41
|
+
end
|
|
42
|
+
|
|
30
43
|
def to_json(*options)
|
|
31
44
|
@modules.to_json(*options)
|
|
32
45
|
end
|
|
33
46
|
|
|
34
47
|
def score
|
|
35
48
|
if @modules.any?
|
|
36
|
-
MAX_SCORE - average_limited_cost * COST_MULTIPLIER
|
|
49
|
+
(MAX_SCORE - average_limited_cost * COST_MULTIPLIER).round(2)
|
|
37
50
|
else
|
|
38
51
|
0.0
|
|
39
52
|
end
|
|
@@ -65,5 +78,12 @@ module RubyCritic
|
|
|
65
78
|
def limited_cost_for(mod)
|
|
66
79
|
[mod.cost, COST_LIMIT].min
|
|
67
80
|
end
|
|
81
|
+
|
|
82
|
+
def build_analysed_module(analysed_module)
|
|
83
|
+
AnalysedModule.new(pathname: analysed_module.pathname, name: analysed_module.name,
|
|
84
|
+
smells: analysed_module.smells, churn: analysed_module.churn,
|
|
85
|
+
committed_at: analysed_module.committed_at, complexity: analysed_module.complexity,
|
|
86
|
+
duplication: analysed_module.duplication, methods_count: analysed_module.methods_count)
|
|
87
|
+
end
|
|
68
88
|
end
|
|
69
89
|
end
|
|
@@ -531,6 +531,7 @@ span.metric {
|
|
|
531
531
|
margin-left: 20px;
|
|
532
532
|
}
|
|
533
533
|
|
|
534
|
+
|
|
534
535
|
.filter-table {
|
|
535
536
|
text-align: right;
|
|
536
537
|
}
|
|
@@ -548,3 +549,22 @@ span.metric {
|
|
|
548
549
|
border: 1px solid #ccc;
|
|
549
550
|
border-radius: 4px;
|
|
550
551
|
}
|
|
552
|
+
|
|
553
|
+
.branch{
|
|
554
|
+
font-size: 15px;
|
|
555
|
+
color: #9b111d;
|
|
556
|
+
font-weight: bold;
|
|
557
|
+
display: inline-block;
|
|
558
|
+
padding: 13px;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
.green-color {
|
|
562
|
+
color: #00A900;
|
|
563
|
+
}
|
|
564
|
+
.red-color {
|
|
565
|
+
color: #ED0000;
|
|
566
|
+
}
|
|
567
|
+
.empty-span{
|
|
568
|
+
height: 17px;
|
|
569
|
+
width: 17px;
|
|
570
|
+
}
|
|
@@ -13,6 +13,13 @@ module RubyCritic
|
|
|
13
13
|
def initialize(analysed_module)
|
|
14
14
|
@analysed_module = analysed_module
|
|
15
15
|
@pathname = @analysed_module.pathname
|
|
16
|
+
set_header_links if Config.compare_branches_mode?
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def set_header_links
|
|
20
|
+
@base_path = code_index_path(Config.base_root_directory, file_location)
|
|
21
|
+
@feature_path = code_index_path(Config.feature_root_directory, file_location)
|
|
22
|
+
@build_path = code_index_path(Config.compare_root_directory, file_location)
|
|
16
23
|
end
|
|
17
24
|
|
|
18
25
|
def file_directory
|
|
@@ -23,6 +30,10 @@ module RubyCritic
|
|
|
23
30
|
@pathname.basename.sub_ext('.html')
|
|
24
31
|
end
|
|
25
32
|
|
|
33
|
+
def file_location
|
|
34
|
+
@pathname.sub_ext('.html')
|
|
35
|
+
end
|
|
36
|
+
|
|
26
37
|
def render
|
|
27
38
|
file_code = []
|
|
28
39
|
File.readlines(@pathname).each.with_index(LINE_NUMBER_OFFSET) do |line_text, line_number|
|