rubycritic 3.2.3 → 3.3.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/.gitignore +1 -0
- data/.rubocop_todo.yml +3 -3
- data/CHANGELOG.md +10 -1
- data/README.md +1 -1
- data/docs/jenkins-pr-reviews.md +64 -0
- data/features/command_line_interface/minimum_score.feature +5 -5
- data/features/command_line_interface/options.feature +1 -0
- data/features/rake_task.feature +1 -1
- data/features/step_definitions/sample_file_steps.rb +4 -4
- data/features/support/env.rb +2 -2
- data/lib/rubycritic/analysers/complexity.rb +1 -1
- data/lib/rubycritic/cli/options.rb +4 -3
- data/lib/rubycritic/core/analysed_module.rb +6 -2
- data/lib/rubycritic/core/analysed_modules_collection.rb +15 -5
- data/lib/rubycritic/generators/lint_report.rb +30 -0
- data/lib/rubycritic/generators/text/lint.rb +41 -0
- data/lib/rubycritic/generators/text/templates/lint.erb +3 -0
- data/lib/rubycritic/reporter.rb +3 -0
- data/lib/rubycritic/source_control_systems/git.rb +18 -7
- data/lib/rubycritic/source_locator.rb +1 -0
- data/lib/rubycritic/version.rb +1 -1
- data/rubycritic.gemspec +7 -4
- data/test/lib/rubycritic/commands/status_reporter_test.rb +2 -2
- data/test/lib/rubycritic/generators/json_report_test.rb +15 -15
- data/test/lib/rubycritic/generators/lint_report_test.rb +37 -0
- data/test/lib/rubycritic/source_control_systems/perforce_test.rb +6 -6
- data/test/test_helper.rb +17 -1
- metadata +77 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fb8941448d84144db4e15c3cb37731de9c78a9b9
|
|
4
|
+
data.tar.gz: 36cf41f7d42d12668c4abe9f6300e0cbdeec43a5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2174e7c073020b197681db5c4af3501b302f85d64cb858c224e772d93a268eeebd68bf9d530203a20f278918d5bd03370be8a7d5ff988e83e1d1a7792ab05908
|
|
7
|
+
data.tar.gz: fb77e4cc9ce6aafe5cc8239f90d79f6354046568934f6baf37eda7bb47786fe77b256c8fef53fa548e442d7caad8b0e627eda1f9e6beb5c68b0aada9d2e3feaf
|
data/.gitignore
CHANGED
data/.rubocop_todo.yml
CHANGED
|
@@ -17,7 +17,7 @@ Metrics/MethodLength:
|
|
|
17
17
|
- 'lib/rubycritic/platforms/base.rb'
|
|
18
18
|
|
|
19
19
|
# Offense count: 4
|
|
20
|
-
|
|
20
|
+
Naming/AccessorMethodName:
|
|
21
21
|
Exclude:
|
|
22
22
|
- 'lib/rubycritic/analysers/helpers/ast_node.rb'
|
|
23
23
|
- 'lib/rubycritic/generators/html/base.rb'
|
|
@@ -37,9 +37,9 @@ Style/SpecialGlobalVars:
|
|
|
37
37
|
|
|
38
38
|
# Offense count: 1
|
|
39
39
|
Style/MethodMissing:
|
|
40
|
-
Exclude:
|
|
40
|
+
Exclude:
|
|
41
41
|
- 'lib/rubycritic/configuration.rb'
|
|
42
42
|
|
|
43
43
|
# Offense count: 3
|
|
44
|
-
|
|
44
|
+
Layout/IndentHeredoc:
|
|
45
45
|
Enabled: false
|
data/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
# master [(unreleased)](https://github.com/whitesmith/rubycritic/compare/v3.
|
|
1
|
+
# master [(unreleased)](https://github.com/whitesmith/rubycritic/compare/v3.3.0...master)
|
|
2
|
+
|
|
3
|
+
# 3.3.0 / 2017-10-10 [(commits)](https://github.com/whitesmith/rubycritic/compare/v3.2.3...v3.3.0)
|
|
4
|
+
|
|
5
|
+
* [FEATURE] Add lint format similar to Golint (by [@nightscape][])
|
|
6
|
+
* [CHANGE] Update `cucumber` to 3.0 (by [@onumis][])
|
|
7
|
+
* [CHANGE] Update `rake` to 12.0 (by [@onumis][])
|
|
8
|
+
* [CHANGE] Update `rubocop` to 0.50.0 (by [@onumis][])
|
|
9
|
+
* [CHANGE] Accepting floating point values from Flog (by [@onumis][])
|
|
2
10
|
|
|
3
11
|
# 3.2.3 / 2017-05-31 [(commits)](https://github.com/whitesmith/rubycritic/compare/v3.2.2...v3.2.3)
|
|
4
12
|
|
|
@@ -215,3 +223,4 @@
|
|
|
215
223
|
[@georgedrummond]: https://github.com/georgedrummond
|
|
216
224
|
[@yuku-t]: https://github.com/yuku-t
|
|
217
225
|
[@ochagata]: https://github.com/ochagata
|
|
226
|
+
[@nightscape]: https://github.com/nightscape
|
data/README.md
CHANGED
|
@@ -117,7 +117,7 @@ $ rubycritic --help
|
|
|
117
117
|
| `-v` / `--version` | Displays the current version and exits |
|
|
118
118
|
| `-p` / `--path` | Set path where report will be saved (tmp/rubycritic by default) |
|
|
119
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
|
|
120
|
+
| `-s` / `--minimum-score` | Set a minimum score (FLOAT: ex: 96.28) |
|
|
121
121
|
| `--mode-ci` | Use CI mode (faster, but only analyses last commit) |
|
|
122
122
|
| `--deduplicate-symlinks` | De-duplicate symlinks based on their final target |
|
|
123
123
|
| `--suppress-ratings` | Suppress letter ratings |
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Making Jenkins review Pull Requests
|
|
2
|
+
|
|
3
|
+
## Installing Jenkins and setting up RubyCritic
|
|
4
|
+
|
|
5
|
+
There is a step-by-step tutorial on how to set up Jenkins in [`building-own-code-climate.md`](./building-own-code-climate.md).
|
|
6
|
+
|
|
7
|
+
### Installing required plugins
|
|
8
|
+
|
|
9
|
+
Installing a Jenkins Plugin is extremely easy. All you have to do is proceed to `Manage Jenkins`, go to `Manage Plugins`, select the `Available` tab and then check the desired plugin.
|
|
10
|
+
|
|
11
|
+
For creating comments on PRs we are going to use the [Violation Comments to GitHub Jenkins Plugin](https://github.com/jenkinsci/violation-comments-to-github-plugin).
|
|
12
|
+
|
|
13
|
+
## Configuring the project
|
|
14
|
+
|
|
15
|
+
The Violation plugin has parsers for many different formats, and the GoLint one is compatible with the `lint` format created by RubyCritic.
|
|
16
|
+
We're assuming that you use a `Jenkinsfile` for creating a pipeline, but the approach can be adapted to other scenarios.
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
```groovy
|
|
20
|
+
pipeline {
|
|
21
|
+
agent any
|
|
22
|
+
|
|
23
|
+
stages {
|
|
24
|
+
stage('Build') {
|
|
25
|
+
steps {
|
|
26
|
+
// Install gems etc.
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
stage('Test') {
|
|
30
|
+
steps {
|
|
31
|
+
parallel tests: { // We are running tests and code_checks in parallel to shorten build times
|
|
32
|
+
sh 'bundle exec rspec'
|
|
33
|
+
},
|
|
34
|
+
code_checks: {
|
|
35
|
+
sh 'bundle exec rubycritic -f lint'
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
stage('Package / Deploy') {
|
|
40
|
+
steps {
|
|
41
|
+
parallel deploy: {
|
|
42
|
+
// Create Docker image / deploy via Capistrano / ...
|
|
43
|
+
},
|
|
44
|
+
publish_code_review: {
|
|
45
|
+
step([
|
|
46
|
+
$class: 'ViolationsToGitHubRecorder',
|
|
47
|
+
config: [
|
|
48
|
+
repositoryName: 'your_project_name',
|
|
49
|
+
pullRequestId: env.CHANGE_ID, // The CHANGE_ID env variable will be set to the PR ID by Jenkins
|
|
50
|
+
createSingleFileComments: true, // Create one comment per violation
|
|
51
|
+
commentOnlyChangedContent: true, // Only comment on lines that have changed
|
|
52
|
+
keepOldComments: false,
|
|
53
|
+
violationConfigs: [
|
|
54
|
+
[ pattern: '.*/lint\\.txt$', parser: 'GOLINT', reporter: 'RubyCritic' ], // RubyCritic will output a lint.txt file in GoLint compatible format
|
|
55
|
+
]
|
|
56
|
+
]])
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
For further information, check out the documentation of the [Violation Comments to GitHub Jenkins Plugin](https://github.com/jenkinsci/violation-comments-to-github-plugin).
|
|
@@ -3,17 +3,17 @@ Feature: Break if overall score is below minimum
|
|
|
3
3
|
RubyCritic returns the exit status according with the score
|
|
4
4
|
|
|
5
5
|
Scenario: Status indicates a success when not using --minimum-score
|
|
6
|
-
Given the smelly file 'smelly.rb' with a score of 93.
|
|
6
|
+
Given the smelly file 'smelly.rb' with a score of 93.19
|
|
7
7
|
When I run rubycritic smelly.rb
|
|
8
8
|
Then the exit status indicates a success
|
|
9
9
|
|
|
10
10
|
Scenario: Status indicates an error when score below the minimum
|
|
11
|
-
Given the smelly file 'smelly.rb' with a score of 93.
|
|
11
|
+
Given the smelly file 'smelly.rb' with a score of 93.19
|
|
12
12
|
When I run rubycritic --minimum-score 100 smelly.rb
|
|
13
13
|
Then the exit status indicates an error
|
|
14
14
|
|
|
15
15
|
Scenario: Status indicates a success when score is above the minimum
|
|
16
|
-
Given the smelly file 'smelly.rb' with a score of 93.
|
|
16
|
+
Given the smelly file 'smelly.rb' with a score of 93.19
|
|
17
17
|
When I run rubycritic --minimum-score 93 smelly.rb
|
|
18
18
|
Then the exit status indicates a success
|
|
19
19
|
|
|
@@ -23,11 +23,11 @@ Feature: Break if overall score is below minimum
|
|
|
23
23
|
Then the exit status indicates a success
|
|
24
24
|
|
|
25
25
|
Scenario: Prints the score on output
|
|
26
|
-
Given the smelly file 'smelly.rb' with a score of 93.
|
|
26
|
+
Given the smelly file 'smelly.rb' with a score of 93.19
|
|
27
27
|
When I run rubycritic smelly.rb
|
|
28
28
|
Then the output should contain:
|
|
29
29
|
"""
|
|
30
|
-
Score: 93.
|
|
30
|
+
Score: 93.19
|
|
31
31
|
"""
|
|
32
32
|
|
|
33
33
|
Scenario: Prints a message informing the score is below the minimum
|
|
@@ -25,6 +25,7 @@ Feature: RubyCritic can be controlled using command-line options
|
|
|
25
25
|
html (default; will open in a browser)
|
|
26
26
|
json
|
|
27
27
|
console
|
|
28
|
+
lint
|
|
28
29
|
-s, --minimum-score [MIN_SCORE] Set a minimum score
|
|
29
30
|
-m, --mode-ci Use CI mode (faster, but only analyses last commit)
|
|
30
31
|
--deduplicate-symlinks De-duplicate symlinks based on their final target
|
data/features/rake_task.feature
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
Given(/^the smelly file 'smelly.rb'/) do
|
|
4
|
-
contents = <<-
|
|
4
|
+
contents = <<-RUBY.strip_heredoc
|
|
5
5
|
class AllTheMethods
|
|
6
6
|
def method_missing(method, *args, &block)
|
|
7
7
|
message = "I"
|
|
@@ -13,17 +13,17 @@ Given(/^the smelly file 'smelly.rb'/) do
|
|
|
13
13
|
self.send(method)
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
|
-
|
|
16
|
+
RUBY
|
|
17
17
|
write_file('smelly.rb', contents)
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
Given(/^the clean file 'clean.rb'/) do
|
|
21
|
-
contents = <<-
|
|
21
|
+
contents = <<-RUBY.strip_heredoc
|
|
22
22
|
# Explanatory comment
|
|
23
23
|
class Clean
|
|
24
24
|
def foo; end
|
|
25
25
|
end
|
|
26
|
-
|
|
26
|
+
RUBY
|
|
27
27
|
write_file('clean.rb', contents)
|
|
28
28
|
end
|
|
29
29
|
|
data/features/support/env.rb
CHANGED
|
@@ -22,11 +22,11 @@ class RubyCriticWorld
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
def rake(name, task_def)
|
|
25
|
-
header = <<-
|
|
25
|
+
header = <<-RUBY.strip_heredoc
|
|
26
26
|
require 'rubycritic'
|
|
27
27
|
require 'rubycritic/rake_task'
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
RUBY
|
|
30
30
|
write_file 'Rakefile', header + task_def
|
|
31
31
|
run_simple("rake #{name}", false)
|
|
32
32
|
end
|
|
@@ -16,7 +16,7 @@ module RubyCritic
|
|
|
16
16
|
@analysed_modules.each do |analysed_module|
|
|
17
17
|
@flog.reset
|
|
18
18
|
@flog.flog(analysed_module.path)
|
|
19
|
-
analysed_module.complexity = @flog.total_score.round
|
|
19
|
+
analysed_module.complexity = @flog.total_score.round(2)
|
|
20
20
|
print green '.'
|
|
21
21
|
end
|
|
22
22
|
puts ''
|
|
@@ -22,17 +22,18 @@ module RubyCritic
|
|
|
22
22
|
|
|
23
23
|
opts.on(
|
|
24
24
|
'-f', '--format [FORMAT]',
|
|
25
|
-
%i[html json console],
|
|
25
|
+
%i[html json console lint],
|
|
26
26
|
'Report smells in the given format:',
|
|
27
27
|
' html (default; will open in a browser)',
|
|
28
28
|
' json',
|
|
29
|
-
' console'
|
|
29
|
+
' console',
|
|
30
|
+
' lint'
|
|
30
31
|
) do |format|
|
|
31
32
|
self.format = format
|
|
32
33
|
end
|
|
33
34
|
|
|
34
35
|
opts.on('-s', '--minimum-score [MIN_SCORE]', 'Set a minimum score') do |min_score|
|
|
35
|
-
self.minimum_score =
|
|
36
|
+
self.minimum_score = Float(min_score)
|
|
36
37
|
end
|
|
37
38
|
|
|
38
39
|
opts.on('-m', '--mode-ci', 'Use CI mode (faster, but only analyses last commit)') do
|
|
@@ -7,6 +7,9 @@ module RubyCritic
|
|
|
7
7
|
class AnalysedModule
|
|
8
8
|
include Virtus.model
|
|
9
9
|
|
|
10
|
+
# Complexity is reduced by a factor of 25 when calculating cost
|
|
11
|
+
COMPLEXITY_FACTOR = 25.0
|
|
12
|
+
|
|
10
13
|
attribute :name
|
|
11
14
|
attribute :smells_count
|
|
12
15
|
attribute :file_location
|
|
@@ -16,7 +19,7 @@ module RubyCritic
|
|
|
16
19
|
attribute :smells, Array, default: []
|
|
17
20
|
attribute :churn
|
|
18
21
|
attribute :committed_at
|
|
19
|
-
attribute :complexity
|
|
22
|
+
attribute :complexity, Float, default: Float::INFINITY
|
|
20
23
|
attribute :duplication, Integer, default: 0
|
|
21
24
|
attribute :methods_count
|
|
22
25
|
|
|
@@ -37,7 +40,8 @@ module RubyCritic
|
|
|
37
40
|
end
|
|
38
41
|
|
|
39
42
|
def cost
|
|
40
|
-
@cost ||= smells.map(&:cost).inject(0, :+) +
|
|
43
|
+
@cost ||= smells.map(&:cost).inject(0.0, :+) +
|
|
44
|
+
(complexity / COMPLEXITY_FACTOR)
|
|
41
45
|
end
|
|
42
46
|
|
|
43
47
|
def rating
|
|
@@ -32,9 +32,11 @@ module RubyCritic
|
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
def score
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
if @modules.any?
|
|
36
|
+
MAX_SCORE - average_limited_cost * COST_MULTIPLIER
|
|
37
|
+
else
|
|
38
|
+
0.0
|
|
39
|
+
end
|
|
38
40
|
end
|
|
39
41
|
|
|
40
42
|
def summary
|
|
@@ -48,8 +50,16 @@ module RubyCritic
|
|
|
48
50
|
private
|
|
49
51
|
|
|
50
52
|
def average_limited_cost
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
[average_cost, ZERO_SCORE_COST].min
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def average_cost
|
|
57
|
+
num_modules = @modules.size
|
|
58
|
+
if num_modules > 0
|
|
59
|
+
map { |mod| limited_cost_for(mod) }.reduce(:+) / num_modules.to_f
|
|
60
|
+
else
|
|
61
|
+
0.0
|
|
62
|
+
end
|
|
53
63
|
end
|
|
54
64
|
|
|
55
65
|
def limited_cost_for(mod)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rubycritic/generators/text/lint'
|
|
4
|
+
|
|
5
|
+
module RubyCritic
|
|
6
|
+
module Generator
|
|
7
|
+
class LintReport
|
|
8
|
+
def initialize(analysed_modules)
|
|
9
|
+
@analysed_modules = analysed_modules
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def generate_report
|
|
13
|
+
FileUtils.mkdir_p(generator.file_directory)
|
|
14
|
+
File.open(generator.file_pathname, 'w+') do |file|
|
|
15
|
+
file.write(reports.join("\n"))
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def generator
|
|
20
|
+
Text::Lint
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def reports
|
|
24
|
+
@analysed_modules.sort.map do |mod|
|
|
25
|
+
generator.new(mod).render
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'erb'
|
|
4
|
+
module RubyCritic
|
|
5
|
+
module Generator
|
|
6
|
+
module Text
|
|
7
|
+
class Lint
|
|
8
|
+
class << self
|
|
9
|
+
TEMPLATE_PATH = File.expand_path('../templates/lint.erb', __FILE__)
|
|
10
|
+
FILE_NAME = 'lint.txt'.freeze
|
|
11
|
+
|
|
12
|
+
def file_directory
|
|
13
|
+
@file_directory ||= Pathname.new(Config.root)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def file_pathname
|
|
17
|
+
Pathname.new(file_directory).join FILE_NAME
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def erb_template
|
|
21
|
+
@erb_template ||= ERB.new(File.read(TEMPLATE_PATH), nil, '-')
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def initialize(analysed_module)
|
|
26
|
+
@analysed_module = analysed_module
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def render
|
|
30
|
+
erb_template.result(binding)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
|
|
35
|
+
def erb_template
|
|
36
|
+
self.class.erb_template
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
data/lib/rubycritic/reporter.rb
CHANGED
|
@@ -14,6 +14,9 @@ module RubyCritic
|
|
|
14
14
|
when :console
|
|
15
15
|
require 'rubycritic/generators/console_report'
|
|
16
16
|
Generator::ConsoleReport
|
|
17
|
+
when :lint
|
|
18
|
+
require 'rubycritic/generators/lint_report'
|
|
19
|
+
Generator::LintReport
|
|
17
20
|
else
|
|
18
21
|
require 'rubycritic/generators/html_report'
|
|
19
22
|
Generator::HtmlReport
|
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'tty/which'
|
|
4
|
+
|
|
3
5
|
module RubyCritic
|
|
4
6
|
module SourceControlSystem
|
|
5
7
|
class Git < Base
|
|
6
8
|
register_system
|
|
9
|
+
GIT_EXECUTABLE = TTY::Which.which('git')
|
|
10
|
+
|
|
11
|
+
def self.git(arg)
|
|
12
|
+
`#{GIT_EXECUTABLE} #{arg}`
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def git(arg)
|
|
16
|
+
self.class.git(arg)
|
|
17
|
+
end
|
|
7
18
|
|
|
8
19
|
def self.supported?
|
|
9
|
-
|
|
20
|
+
git('branch 2>&1') && $?.success?
|
|
10
21
|
end
|
|
11
22
|
|
|
12
23
|
def self.to_s
|
|
@@ -14,11 +25,11 @@ module RubyCritic
|
|
|
14
25
|
end
|
|
15
26
|
|
|
16
27
|
def revisions_count(path)
|
|
17
|
-
|
|
28
|
+
git("log --follow --format=%h #{path.shellescape}").count("\n")
|
|
18
29
|
end
|
|
19
30
|
|
|
20
31
|
def date_of_last_commit(path)
|
|
21
|
-
|
|
32
|
+
git("log -1 --date=iso --format=%ad #{path.shellescape}").chomp!
|
|
22
33
|
end
|
|
23
34
|
|
|
24
35
|
def revision?
|
|
@@ -26,7 +37,7 @@ module RubyCritic
|
|
|
26
37
|
end
|
|
27
38
|
|
|
28
39
|
def head_reference
|
|
29
|
-
|
|
40
|
+
git('rev-parse --verify HEAD').chomp!
|
|
30
41
|
end
|
|
31
42
|
|
|
32
43
|
def travel_to_head
|
|
@@ -40,17 +51,17 @@ module RubyCritic
|
|
|
40
51
|
|
|
41
52
|
def stash_changes
|
|
42
53
|
stashes_count_before = stashes_count
|
|
43
|
-
|
|
54
|
+
git('stash')
|
|
44
55
|
stashes_count_after = stashes_count
|
|
45
56
|
stashes_count_after > stashes_count_before
|
|
46
57
|
end
|
|
47
58
|
|
|
48
59
|
def stashes_count
|
|
49
|
-
|
|
60
|
+
git('stash list --format=%h').count("\n")
|
|
50
61
|
end
|
|
51
62
|
|
|
52
63
|
def travel_to_original_state
|
|
53
|
-
|
|
64
|
+
git('stash pop')
|
|
54
65
|
end
|
|
55
66
|
end
|
|
56
67
|
end
|
data/lib/rubycritic/version.rb
CHANGED
data/rubycritic.gemspec
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
# coding: utf-8
|
|
2
1
|
# frozen_string_literal: true
|
|
3
2
|
|
|
4
3
|
lib = File.expand_path('../lib', __FILE__)
|
|
@@ -25,6 +24,7 @@ Gem::Specification.new do |spec|
|
|
|
25
24
|
spec.add_runtime_dependency 'flay', '~> 2.8'
|
|
26
25
|
spec.add_runtime_dependency 'flog', '~> 4.4'
|
|
27
26
|
spec.add_runtime_dependency 'launchy', '2.4.3'
|
|
27
|
+
spec.add_runtime_dependency 'tty-which', '~> 0.3.0'
|
|
28
28
|
spec.add_runtime_dependency 'parser', '~> 2.4.0'
|
|
29
29
|
spec.add_runtime_dependency 'rainbow', '~> 2.1'
|
|
30
30
|
spec.add_runtime_dependency 'reek', '~> 4.4'
|
|
@@ -33,10 +33,13 @@ Gem::Specification.new do |spec|
|
|
|
33
33
|
|
|
34
34
|
spec.add_development_dependency 'aruba', '~> 0.12', '>= 0.12.0'
|
|
35
35
|
spec.add_development_dependency 'bundler', '~> 1.3', '>= 1.3.0'
|
|
36
|
-
spec.add_development_dependency 'cucumber', '~>
|
|
36
|
+
spec.add_development_dependency 'cucumber', '~> 3.0', '>= 2.2.0'
|
|
37
37
|
spec.add_development_dependency 'fakefs', '~> 0.10', '>= 0.10.0'
|
|
38
38
|
spec.add_development_dependency 'minitest', '~> 5.3', '>= 5.3.0'
|
|
39
|
+
spec.add_development_dependency 'minitest-around', '~> 0.4.0'
|
|
40
|
+
spec.add_development_dependency 'diff-lcs', '~> 1.3'
|
|
39
41
|
spec.add_development_dependency 'mocha', '~> 1.1', '>= 1.1.0'
|
|
40
|
-
spec.add_development_dependency 'rake', '~>
|
|
41
|
-
spec.add_development_dependency 'rubocop', '~> 0.
|
|
42
|
+
spec.add_development_dependency 'rake', '~> 12.0', '>= 11.0.0'
|
|
43
|
+
spec.add_development_dependency 'rubocop', '~> 0.50.0'
|
|
44
|
+
spec.add_development_dependency 'byebug', '~> 9.0', '>= 8.0'
|
|
42
45
|
end
|
|
@@ -50,13 +50,13 @@ describe RubyCritic::Command::StatusReporter do
|
|
|
50
50
|
it 'should return the correct status' do
|
|
51
51
|
@reporter.score = score
|
|
52
52
|
@reporter.status.must_equal score_below_minimum
|
|
53
|
-
@reporter.status_message.must_equal 'Score (98.0) is below the minimum 99'
|
|
53
|
+
@reporter.status_message.must_equal 'Score (98.0) is below the minimum 99.0'
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
it 'should format the score' do
|
|
57
57
|
@reporter.score = 98.95258620689656
|
|
58
58
|
@reporter.status.must_equal score_below_minimum
|
|
59
|
-
@reporter.status_message.must_equal 'Score (98.95) is below the minimum 99'
|
|
59
|
+
@reporter.status_message.must_equal 'Score (98.95) is below the minimum 99.0'
|
|
60
60
|
end
|
|
61
61
|
end
|
|
62
62
|
|
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'test_helper'
|
|
4
|
-
require 'rubycritic/
|
|
4
|
+
require 'rubycritic/analysers_runner'
|
|
5
5
|
require 'rubycritic/generators/json_report'
|
|
6
6
|
require 'json'
|
|
7
7
|
require 'fakefs/safe'
|
|
8
8
|
|
|
9
9
|
describe RubyCritic::Generator::JsonReport do
|
|
10
10
|
describe '#generate_report' do
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
around do |example|
|
|
12
|
+
capture_output_streams do
|
|
13
|
+
with_cloned_fs(&example)
|
|
14
|
+
end
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
data = File.read('test/samples/report.json')
|
|
25
|
-
assert data != '', 'expected report file not to be empty'
|
|
17
|
+
it 'creates a report file with JSON data inside' do
|
|
18
|
+
sample_files = Dir['test/samples/**/*.rb']
|
|
19
|
+
create_analysed_modules_collection
|
|
20
|
+
generate_report
|
|
21
|
+
data = JSON.parse(File.read('test/samples/report.json'))
|
|
22
|
+
analysed_files = data['analysed_modules'].map { |h| h['path'] }.uniq
|
|
23
|
+
assert_matched_arrays analysed_files, sample_files
|
|
26
24
|
end
|
|
27
25
|
end
|
|
28
26
|
|
|
29
27
|
def create_analysed_modules_collection
|
|
30
|
-
@analysed_modules_collection = RubyCritic::AnalysedModulesCollection.new('test/samples/')
|
|
31
28
|
RubyCritic::Config.root = 'test/samples'
|
|
29
|
+
RubyCritic::Config.source_control_system = RubyCritic::SourceControlSystem::Git.new
|
|
30
|
+
analyser_runner = RubyCritic::AnalysersRunner.new('test/samples/')
|
|
31
|
+
@analysed_modules_collection = analyser_runner.run
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
def generate_report
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'test_helper'
|
|
4
|
+
require 'rubycritic/analysers_runner'
|
|
5
|
+
require 'rubycritic/generators/lint_report'
|
|
6
|
+
require 'fakefs/safe'
|
|
7
|
+
|
|
8
|
+
describe RubyCritic::Generator::LintReport do
|
|
9
|
+
describe '#generate_report' do
|
|
10
|
+
around do |example|
|
|
11
|
+
capture_output_streams do
|
|
12
|
+
with_cloned_fs(&example)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'report file has data inside' do
|
|
17
|
+
sample_files = Dir['test/samples/**/*.rb'].reject { |f| File.zero?(f) }
|
|
18
|
+
create_analysed_modules_collection
|
|
19
|
+
generate_report
|
|
20
|
+
lines = File.readlines('test/samples/lint.txt').map(&:strip).reject(&:empty?)
|
|
21
|
+
analysed_files = lines.map { |line| line.split(':').first }.uniq
|
|
22
|
+
assert_matched_arrays analysed_files, sample_files
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def create_analysed_modules_collection
|
|
27
|
+
RubyCritic::Config.root = 'test/samples'
|
|
28
|
+
RubyCritic::Config.source_control_system = RubyCritic::SourceControlSystem::Git.new
|
|
29
|
+
analyser_runner = RubyCritic::AnalysersRunner.new('test/samples/')
|
|
30
|
+
@analysed_modules_collection = analyser_runner.run
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def generate_report
|
|
34
|
+
report = RubyCritic::Generator::LintReport.new(@analysed_modules_collection)
|
|
35
|
+
report.generate_report
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -66,7 +66,7 @@ describe RubyCritic::SourceControlSystem::Perforce do
|
|
|
66
66
|
describe '::in_client_directory?' do
|
|
67
67
|
context 'current directory is in p4 client' do
|
|
68
68
|
let(:p4_info) do
|
|
69
|
-
<<-
|
|
69
|
+
<<-P4INFO
|
|
70
70
|
User name: unit_test_user
|
|
71
71
|
Client name: UNIT_TEST_CLIENT
|
|
72
72
|
Client host: MACHINE_NAME
|
|
@@ -75,7 +75,7 @@ Current directory: /path/to/client/root/ruby_project/unit_test
|
|
|
75
75
|
Peer address: 127.0.0.1::3000
|
|
76
76
|
Client address: 127.0.0.1
|
|
77
77
|
Server address: the.server.address.com
|
|
78
|
-
|
|
78
|
+
P4INFO
|
|
79
79
|
end
|
|
80
80
|
|
|
81
81
|
it 'calls p4 info and parse the result' do
|
|
@@ -86,7 +86,7 @@ Server address: the.server.address.com
|
|
|
86
86
|
|
|
87
87
|
context 'current directory is not in p4 client' do
|
|
88
88
|
let(:p4_info) do
|
|
89
|
-
<<-
|
|
89
|
+
<<-P4INFO
|
|
90
90
|
User name: unit_test_user
|
|
91
91
|
Client name: UNIT_TEST_CLIENT
|
|
92
92
|
Client host: MACHINE_NAME
|
|
@@ -95,7 +95,7 @@ Current directory: /somewhere/else/ruby_project/unit_test
|
|
|
95
95
|
Peer address: 127.0.0.1::3000
|
|
96
96
|
Client address: 127.0.0.1
|
|
97
97
|
Server address: the.server.address.com
|
|
98
|
-
|
|
98
|
+
P4INFO
|
|
99
99
|
end
|
|
100
100
|
|
|
101
101
|
it 'calls p4 info and parse the result' do
|
|
@@ -107,7 +107,7 @@ Server address: the.server.address.com
|
|
|
107
107
|
|
|
108
108
|
describe 'retrieve informations' do
|
|
109
109
|
let(:p4_stats) do
|
|
110
|
-
<<-
|
|
110
|
+
<<-P4STATS
|
|
111
111
|
... clientFile /path/to/client/a_ruby_file.rb
|
|
112
112
|
... headTime 1473075551
|
|
113
113
|
... headRev 16
|
|
@@ -118,7 +118,7 @@ Server address: the.server.address.com
|
|
|
118
118
|
... action opened
|
|
119
119
|
... headRev 12
|
|
120
120
|
... headChange 2103504
|
|
121
|
-
|
|
121
|
+
P4STATS
|
|
122
122
|
end
|
|
123
123
|
|
|
124
124
|
describe 'build_file_cache' do
|
data/test/test_helper.rb
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'minitest/autorun'
|
|
4
|
+
require 'minitest/around/spec'
|
|
4
5
|
require 'minitest/pride'
|
|
5
6
|
require 'mocha/mini_test'
|
|
6
7
|
require 'ostruct'
|
|
8
|
+
require 'diff/lcs'
|
|
7
9
|
|
|
8
10
|
def context(*args, &block)
|
|
9
11
|
describe(*args, &block)
|
|
@@ -18,6 +20,19 @@ ensure
|
|
|
18
20
|
$stderr = STDERR
|
|
19
21
|
end
|
|
20
22
|
|
|
23
|
+
def with_cloned_fs
|
|
24
|
+
FakeFS do
|
|
25
|
+
begin
|
|
26
|
+
config = File.expand_path('..', __dir__)
|
|
27
|
+
FakeFS::FileSystem.clone(config)
|
|
28
|
+
Dir.chdir(config)
|
|
29
|
+
yield
|
|
30
|
+
ensure
|
|
31
|
+
FakeFS::FileSystem.clear
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
21
36
|
module MiniTest
|
|
22
37
|
module Assertions
|
|
23
38
|
##
|
|
@@ -31,7 +46,8 @@ module MiniTest
|
|
|
31
46
|
assert_kind_of Array, exp_ary
|
|
32
47
|
act_ary = act.to_ary
|
|
33
48
|
assert_kind_of Array, act_ary
|
|
34
|
-
|
|
49
|
+
diffs = Diff::LCS.sdiff(act_ary.sort, exp_ary.sort).reject(&:unchanged?)
|
|
50
|
+
assert diffs.empty?, "There are diffs between expected and actual values:\n#{diffs.map(&:inspect).join("\n")}"
|
|
35
51
|
end
|
|
36
52
|
end
|
|
37
53
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubycritic
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Guilherme Simoes
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-
|
|
11
|
+
date: 2017-10-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: flay
|
|
@@ -52,6 +52,20 @@ dependencies:
|
|
|
52
52
|
- - '='
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: 2.4.3
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: tty-which
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 0.3.0
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 0.3.0
|
|
55
69
|
- !ruby/object:Gem::Dependency
|
|
56
70
|
name: parser
|
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -168,7 +182,7 @@ dependencies:
|
|
|
168
182
|
requirements:
|
|
169
183
|
- - "~>"
|
|
170
184
|
- !ruby/object:Gem::Version
|
|
171
|
-
version: '
|
|
185
|
+
version: '3.0'
|
|
172
186
|
- - ">="
|
|
173
187
|
- !ruby/object:Gem::Version
|
|
174
188
|
version: 2.2.0
|
|
@@ -178,7 +192,7 @@ dependencies:
|
|
|
178
192
|
requirements:
|
|
179
193
|
- - "~>"
|
|
180
194
|
- !ruby/object:Gem::Version
|
|
181
|
-
version: '
|
|
195
|
+
version: '3.0'
|
|
182
196
|
- - ">="
|
|
183
197
|
- !ruby/object:Gem::Version
|
|
184
198
|
version: 2.2.0
|
|
@@ -222,6 +236,34 @@ dependencies:
|
|
|
222
236
|
- - ">="
|
|
223
237
|
- !ruby/object:Gem::Version
|
|
224
238
|
version: 5.3.0
|
|
239
|
+
- !ruby/object:Gem::Dependency
|
|
240
|
+
name: minitest-around
|
|
241
|
+
requirement: !ruby/object:Gem::Requirement
|
|
242
|
+
requirements:
|
|
243
|
+
- - "~>"
|
|
244
|
+
- !ruby/object:Gem::Version
|
|
245
|
+
version: 0.4.0
|
|
246
|
+
type: :development
|
|
247
|
+
prerelease: false
|
|
248
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
249
|
+
requirements:
|
|
250
|
+
- - "~>"
|
|
251
|
+
- !ruby/object:Gem::Version
|
|
252
|
+
version: 0.4.0
|
|
253
|
+
- !ruby/object:Gem::Dependency
|
|
254
|
+
name: diff-lcs
|
|
255
|
+
requirement: !ruby/object:Gem::Requirement
|
|
256
|
+
requirements:
|
|
257
|
+
- - "~>"
|
|
258
|
+
- !ruby/object:Gem::Version
|
|
259
|
+
version: '1.3'
|
|
260
|
+
type: :development
|
|
261
|
+
prerelease: false
|
|
262
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
263
|
+
requirements:
|
|
264
|
+
- - "~>"
|
|
265
|
+
- !ruby/object:Gem::Version
|
|
266
|
+
version: '1.3'
|
|
225
267
|
- !ruby/object:Gem::Dependency
|
|
226
268
|
name: mocha
|
|
227
269
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -248,7 +290,7 @@ dependencies:
|
|
|
248
290
|
requirements:
|
|
249
291
|
- - "~>"
|
|
250
292
|
- !ruby/object:Gem::Version
|
|
251
|
-
version: '
|
|
293
|
+
version: '12.0'
|
|
252
294
|
- - ">="
|
|
253
295
|
- !ruby/object:Gem::Version
|
|
254
296
|
version: 11.0.0
|
|
@@ -258,7 +300,7 @@ dependencies:
|
|
|
258
300
|
requirements:
|
|
259
301
|
- - "~>"
|
|
260
302
|
- !ruby/object:Gem::Version
|
|
261
|
-
version: '
|
|
303
|
+
version: '12.0'
|
|
262
304
|
- - ">="
|
|
263
305
|
- !ruby/object:Gem::Version
|
|
264
306
|
version: 11.0.0
|
|
@@ -268,14 +310,34 @@ dependencies:
|
|
|
268
310
|
requirements:
|
|
269
311
|
- - "~>"
|
|
270
312
|
- !ruby/object:Gem::Version
|
|
271
|
-
version: 0.
|
|
313
|
+
version: 0.50.0
|
|
272
314
|
type: :development
|
|
273
315
|
prerelease: false
|
|
274
316
|
version_requirements: !ruby/object:Gem::Requirement
|
|
275
317
|
requirements:
|
|
276
318
|
- - "~>"
|
|
277
319
|
- !ruby/object:Gem::Version
|
|
278
|
-
version: 0.
|
|
320
|
+
version: 0.50.0
|
|
321
|
+
- !ruby/object:Gem::Dependency
|
|
322
|
+
name: byebug
|
|
323
|
+
requirement: !ruby/object:Gem::Requirement
|
|
324
|
+
requirements:
|
|
325
|
+
- - "~>"
|
|
326
|
+
- !ruby/object:Gem::Version
|
|
327
|
+
version: '9.0'
|
|
328
|
+
- - ">="
|
|
329
|
+
- !ruby/object:Gem::Version
|
|
330
|
+
version: '8.0'
|
|
331
|
+
type: :development
|
|
332
|
+
prerelease: false
|
|
333
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
334
|
+
requirements:
|
|
335
|
+
- - "~>"
|
|
336
|
+
- !ruby/object:Gem::Version
|
|
337
|
+
version: '9.0'
|
|
338
|
+
- - ">="
|
|
339
|
+
- !ruby/object:Gem::Version
|
|
340
|
+
version: '8.0'
|
|
279
341
|
description: RubyCritic is a tool that wraps around various static analysis gems to
|
|
280
342
|
provide a quality report of your Ruby code.
|
|
281
343
|
email:
|
|
@@ -301,6 +363,7 @@ files:
|
|
|
301
363
|
- bin/rubycritic
|
|
302
364
|
- docs/building-own-code-climate.md
|
|
303
365
|
- docs/core-metrics.md
|
|
366
|
+
- docs/jenkins-pr-reviews.md
|
|
304
367
|
- features/command_line_interface/minimum_score.feature
|
|
305
368
|
- features/command_line_interface/options.feature
|
|
306
369
|
- features/rake_task.feature
|
|
@@ -398,7 +461,10 @@ files:
|
|
|
398
461
|
- lib/rubycritic/generators/html_report.rb
|
|
399
462
|
- lib/rubycritic/generators/json/simple.rb
|
|
400
463
|
- lib/rubycritic/generators/json_report.rb
|
|
464
|
+
- lib/rubycritic/generators/lint_report.rb
|
|
465
|
+
- lib/rubycritic/generators/text/lint.rb
|
|
401
466
|
- lib/rubycritic/generators/text/list.rb
|
|
467
|
+
- lib/rubycritic/generators/text/templates/lint.erb
|
|
402
468
|
- lib/rubycritic/generators/text/templates/list.erb
|
|
403
469
|
- lib/rubycritic/rake_task.rb
|
|
404
470
|
- lib/rubycritic/reporter.rb
|
|
@@ -432,6 +498,7 @@ files:
|
|
|
432
498
|
- test/lib/rubycritic/core/smells_array_test.rb
|
|
433
499
|
- test/lib/rubycritic/generators/console_report_test.rb
|
|
434
500
|
- test/lib/rubycritic/generators/json_report_test.rb
|
|
501
|
+
- test/lib/rubycritic/generators/lint_report_test.rb
|
|
435
502
|
- test/lib/rubycritic/generators/turbulence_test.rb
|
|
436
503
|
- test/lib/rubycritic/generators/view_helpers_test.rb
|
|
437
504
|
- test/lib/rubycritic/revision_comparator_test.rb
|
|
@@ -482,7 +549,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
482
549
|
version: '0'
|
|
483
550
|
requirements: []
|
|
484
551
|
rubyforge_project:
|
|
485
|
-
rubygems_version: 2.6.
|
|
552
|
+
rubygems_version: 2.6.13
|
|
486
553
|
signing_key:
|
|
487
554
|
specification_version: 4
|
|
488
555
|
summary: RubyCritic is a Ruby code quality reporter
|
|
@@ -506,6 +573,7 @@ test_files:
|
|
|
506
573
|
- test/lib/rubycritic/core/smells_array_test.rb
|
|
507
574
|
- test/lib/rubycritic/generators/console_report_test.rb
|
|
508
575
|
- test/lib/rubycritic/generators/json_report_test.rb
|
|
576
|
+
- test/lib/rubycritic/generators/lint_report_test.rb
|
|
509
577
|
- test/lib/rubycritic/generators/turbulence_test.rb
|
|
510
578
|
- test/lib/rubycritic/generators/view_helpers_test.rb
|
|
511
579
|
- test/lib/rubycritic/revision_comparator_test.rb
|