churn_vs_complexity 1.9.0 → 2.0.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 +56 -0
- data/README.md +46 -23
- data/lib/churn_vs_complexity/analysis_scope.rb +20 -0
- data/lib/churn_vs_complexity/churn.rb +27 -9
- data/lib/churn_vs_complexity/cli/main.rb +58 -19
- data/lib/churn_vs_complexity/cli/parser.rb +85 -121
- data/lib/churn_vs_complexity/cli.rb +2 -3
- data/lib/churn_vs_complexity/complexity/flog_calculator.rb +0 -3
- data/lib/churn_vs_complexity/complexity/lizard_calculator.rb +64 -0
- data/lib/churn_vs_complexity/complexity.rb +1 -7
- data/lib/churn_vs_complexity/complexity_validator.rb +1 -16
- data/lib/churn_vs_complexity/concurrent_calculator.rb +20 -23
- data/lib/churn_vs_complexity/delta/checker.rb +35 -21
- data/lib/churn_vs_complexity/delta/commit_hydrator.rb +1 -1
- data/lib/churn_vs_complexity/delta/complexity_annotator.rb +23 -5
- data/lib/churn_vs_complexity/delta/config.rb +15 -16
- data/lib/churn_vs_complexity/delta/factory.rb +2 -2
- data/lib/churn_vs_complexity/delta/multi_checker.rb +24 -25
- data/lib/churn_vs_complexity/delta/serializer.rb +6 -4
- data/lib/churn_vs_complexity/delta.rb +11 -49
- data/lib/churn_vs_complexity/diff/checker.rb +10 -3
- data/lib/churn_vs_complexity/diff/config.rb +29 -20
- data/lib/churn_vs_complexity/file_selector.rb +63 -114
- data/lib/churn_vs_complexity/focus/config.rb +42 -32
- data/lib/churn_vs_complexity/focus/serializer.rb +17 -4
- data/lib/churn_vs_complexity/gate/config.rb +28 -25
- data/lib/churn_vs_complexity/git_strategy.rb +17 -12
- data/lib/churn_vs_complexity/hotspots/config.rb +29 -25
- data/lib/churn_vs_complexity/language_registry.rb +108 -0
- data/lib/churn_vs_complexity/language_validator.rb +1 -3
- data/lib/churn_vs_complexity/normal/config.rb +31 -100
- data/lib/churn_vs_complexity/normal/serializer/graph.rb +3 -2
- data/lib/churn_vs_complexity/normal/serializer/summary.rb +18 -14
- data/lib/churn_vs_complexity/normal/serializer/summary_hash.rb +15 -13
- data/lib/churn_vs_complexity/normal/serializer.rb +2 -1
- data/lib/churn_vs_complexity/normal.rb +17 -13
- data/lib/churn_vs_complexity/risk_classifier.rb +3 -19
- data/lib/churn_vs_complexity/timetravel/config.rb +34 -47
- data/lib/churn_vs_complexity/timetravel/schedule.rb +15 -0
- data/lib/churn_vs_complexity/timetravel/serializer/stats_calculator.rb +36 -32
- data/lib/churn_vs_complexity/timetravel/serializer.rb +16 -24
- data/lib/churn_vs_complexity/timetravel/traveller.rb +44 -15
- data/lib/churn_vs_complexity/timetravel.rb +36 -14
- data/lib/churn_vs_complexity/triage/checker.rb +24 -28
- data/lib/churn_vs_complexity/triage/collaborator_set.rb +11 -0
- data/lib/churn_vs_complexity/triage/config.rb +29 -26
- data/lib/churn_vs_complexity/triage.rb +1 -0
- data/lib/churn_vs_complexity/validator_set.rb +9 -0
- data/lib/churn_vs_complexity/version.rb +1 -1
- data/lib/churn_vs_complexity.rb +3 -0
- metadata +18 -22
- data/lib/churn_vs_complexity/complexity/eslint_calculator.rb +0 -40
- data/lib/churn_vs_complexity/complexity/go_calculator.rb +0 -48
- data/lib/churn_vs_complexity/complexity/kotlin_calculator.rb +0 -54
- data/lib/churn_vs_complexity/complexity/pmd/files_calculator.rb +0 -26
- data/lib/churn_vs_complexity/complexity/pmd/folder_calculator.rb +0 -20
- data/lib/churn_vs_complexity/complexity/pmd.rb +0 -54
- data/lib/churn_vs_complexity/complexity/python_calculator.rb +0 -50
- data/lib/churn_vs_complexity/complexity/rust_calculator.rb +0 -54
- data/lib/churn_vs_complexity/complexity/swift_calculator.rb +0 -54
- data/tmp/eslint-support/complexity-calculator.js +0 -51
- data/tmp/eslint-support/package.json +0 -11
- data/tmp/pmd-support/ruleset.xml +0 -21
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ChurnVsComplexity
|
|
4
|
+
module LanguageRegistry
|
|
5
|
+
module NoopValidator
|
|
6
|
+
def self.check_dependencies! = nil
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
JAVASCRIPT_DEFAULT_EXCLUDES = %w[node_modules].freeze
|
|
10
|
+
PYTHON_DEFAULT_EXCLUDES = %w[venv .venv env .env __pycache__ .tox site-packages].freeze
|
|
11
|
+
|
|
12
|
+
Entry = Data.define(
|
|
13
|
+
:key,
|
|
14
|
+
:label,
|
|
15
|
+
:cli_flags,
|
|
16
|
+
:extensions,
|
|
17
|
+
:default_excludes,
|
|
18
|
+
:calculator,
|
|
19
|
+
:validator,
|
|
20
|
+
:cli_description,
|
|
21
|
+
) do
|
|
22
|
+
def file_selector
|
|
23
|
+
FileSelector::Factory.new(
|
|
24
|
+
extensions:,
|
|
25
|
+
default_excludes:,
|
|
26
|
+
)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def description
|
|
30
|
+
cli_description || "Check complexity of #{label.downcase} files"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
class << self
|
|
35
|
+
def all = ENTRIES
|
|
36
|
+
def keys = BY_KEY.keys
|
|
37
|
+
def supported?(key) = BY_KEY.key?(key)
|
|
38
|
+
|
|
39
|
+
def fetch(key)
|
|
40
|
+
BY_KEY.fetch(key) { raise ValidationError, "Unsupported language: #{key}" }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def file_selector_for(key)
|
|
44
|
+
fetch(key).file_selector
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def complexity_for(key)
|
|
48
|
+
fetch(key).calculator
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
|
|
53
|
+
def register(key, label, cli_flags, extensions)
|
|
54
|
+
Entry.new(
|
|
55
|
+
key:,
|
|
56
|
+
label:,
|
|
57
|
+
cli_flags: cli_flags.freeze,
|
|
58
|
+
extensions: extensions.freeze,
|
|
59
|
+
default_excludes: [].freeze,
|
|
60
|
+
calculator: Complexity::LizardCalculator,
|
|
61
|
+
validator: Complexity::LizardCalculator,
|
|
62
|
+
cli_description: nil,
|
|
63
|
+
)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
ENTRIES = [
|
|
68
|
+
register(:java, 'Java', ['--java'], ['.java']).with(
|
|
69
|
+
cli_description: 'Check complexity of java classes',
|
|
70
|
+
),
|
|
71
|
+
register(:ruby, 'Ruby', ['--ruby'], ['.rb']).with(
|
|
72
|
+
calculator: Complexity::FlogCalculator,
|
|
73
|
+
validator: NoopValidator,
|
|
74
|
+
),
|
|
75
|
+
register(:javascript, 'JavaScript and TypeScript',
|
|
76
|
+
%w[--js --ts --javascript --typescript --jsx --tsx],
|
|
77
|
+
%w[.js .cjs .mjs .jsx .ts .tsx]).with(
|
|
78
|
+
default_excludes: JAVASCRIPT_DEFAULT_EXCLUDES,
|
|
79
|
+
),
|
|
80
|
+
register(:python, 'Python', ['--python'], ['.py']).with(
|
|
81
|
+
default_excludes: PYTHON_DEFAULT_EXCLUDES,
|
|
82
|
+
),
|
|
83
|
+
register(:go, 'Go', ['--go'], ['.go']),
|
|
84
|
+
register(:kotlin, 'Kotlin', ['--kotlin'], ['.kt', '.kts']),
|
|
85
|
+
register(:rust, 'Rust', ['--rust'], ['.rs']),
|
|
86
|
+
register(:swift, 'Swift', ['--swift'], ['.swift']),
|
|
87
|
+
register(:cpp, 'C/C++', %w[--cpp --c++ --c], %w[.c .cpp .cc .cxx .h .hpp]),
|
|
88
|
+
register(:csharp, 'C#', %w[--csharp --cs], %w[.cs]),
|
|
89
|
+
register(:objc, 'Objective-C', %w[--objc --objective-c --objectivec], %w[.m .mm]),
|
|
90
|
+
register(:php, 'PHP', %w[--php], %w[.php]),
|
|
91
|
+
register(:scala, 'Scala', %w[--scala], %w[.scala]),
|
|
92
|
+
register(:gdscript, 'GDScript', %w[--gdscript], %w[.gd]),
|
|
93
|
+
register(:lua, 'Lua', %w[--lua], %w[.lua]),
|
|
94
|
+
register(:fortran, 'Fortran', %w[--fortran], %w[.f70 .f90 .f95 .f03 .f08 .f .for .ftn .fpp]),
|
|
95
|
+
register(:solidity, 'Solidity', %w[--solidity], %w[.sol]),
|
|
96
|
+
register(:erlang, 'Erlang', %w[--erlang], %w[.erl .hrl .es .escript]),
|
|
97
|
+
register(:zig, 'Zig', %w[--zig], %w[.zig]),
|
|
98
|
+
register(:vue, 'Vue', %w[--vue --vuejs], %w[.vue]),
|
|
99
|
+
register(:perl, 'Perl', %w[--perl], %w[.pl .pm]),
|
|
100
|
+
register(:ttcn, 'TTCN-3', %w[--ttcn --ttcn3], %w[.ttcn .ttcnpp]),
|
|
101
|
+
register(:st, 'Structured Text', %w[--st --structured-text], %w[.st]),
|
|
102
|
+
register(:r, 'R', %w[--r], %w[.r .R]),
|
|
103
|
+
register(:plsql, 'PL/SQL', %w[--plsql], %w[.sql .pks .pkb .pls .plb .pck]),
|
|
104
|
+
].freeze
|
|
105
|
+
|
|
106
|
+
BY_KEY = ENTRIES.to_h { |entry| [entry.key, entry] }.freeze
|
|
107
|
+
end
|
|
108
|
+
end
|
|
@@ -2,10 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
module ChurnVsComplexity
|
|
4
4
|
module LanguageValidator
|
|
5
|
-
SUPPORTED = %i[java ruby javascript python go kotlin rust swift].freeze
|
|
6
|
-
|
|
7
5
|
def self.validate!(language)
|
|
8
|
-
raise ValidationError, "Unsupported language: #{language}" unless
|
|
6
|
+
raise ValidationError, "Unsupported language: #{language}" unless LanguageRegistry.supported?(language)
|
|
9
7
|
end
|
|
10
8
|
end
|
|
11
9
|
end
|
|
@@ -3,103 +3,40 @@
|
|
|
3
3
|
module ChurnVsComplexity
|
|
4
4
|
module Normal
|
|
5
5
|
class Config
|
|
6
|
-
def
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
@language = language
|
|
6
|
+
def self.from_options(options)
|
|
7
|
+
new(
|
|
8
|
+
scope: AnalysisScope.from_options(options),
|
|
9
|
+
serializer: options[:serializer],
|
|
10
|
+
relative_period: options[:relative_period],
|
|
11
|
+
)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def initialize(scope:, serializer:, relative_period: nil, validators: ValidatorSet.new)
|
|
15
|
+
@scope = scope
|
|
17
16
|
@serializer = serializer
|
|
18
|
-
@
|
|
19
|
-
@
|
|
20
|
-
@relative_period = relative_period
|
|
21
|
-
@complexity_validator = complexity_validator
|
|
22
|
-
@since_validator = since_validator
|
|
23
|
-
@options = options
|
|
17
|
+
@relative_period = relative_period || scope.relative_period
|
|
18
|
+
@validators = validators
|
|
24
19
|
end
|
|
25
20
|
|
|
26
21
|
def validate!
|
|
27
|
-
LanguageValidator.validate!(@language)
|
|
28
|
-
|
|
22
|
+
LanguageValidator.validate!(@scope.language)
|
|
29
23
|
SerializerValidator.validate!(serializer: @serializer)
|
|
30
|
-
|
|
31
|
-
@since_validator.validate!(since: @since, relative_period: @relative_period)
|
|
24
|
+
@validators.since.validate!(since: @scope.since, relative_period: @relative_period)
|
|
32
25
|
RelativePeriodValidator.validate!(relative_period: @relative_period)
|
|
33
|
-
@
|
|
26
|
+
@validators.complexity.validate!(@scope.language)
|
|
34
27
|
end
|
|
35
28
|
|
|
36
29
|
def checker
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
Engine.concurrent(
|
|
48
|
-
complexity: Complexity::FlogCalculator,
|
|
49
|
-
churn:,
|
|
50
|
-
file_selector: FileSelector::Ruby.excluding(@excluded),
|
|
51
|
-
serializer:,
|
|
52
|
-
since: @since || @relative_period,
|
|
53
|
-
)
|
|
54
|
-
when :javascript
|
|
55
|
-
Engine.concurrent(
|
|
56
|
-
complexity: Complexity::ESLintCalculator,
|
|
57
|
-
churn:,
|
|
58
|
-
file_selector: FileSelector::JavaScript.excluding(@excluded),
|
|
59
|
-
serializer:,
|
|
60
|
-
since: @since || @relative_period,
|
|
61
|
-
)
|
|
62
|
-
when :python
|
|
63
|
-
Engine.concurrent(
|
|
64
|
-
complexity: Complexity::PythonCalculator,
|
|
65
|
-
churn:,
|
|
66
|
-
file_selector: FileSelector::Python.excluding(@excluded),
|
|
67
|
-
serializer:,
|
|
68
|
-
since: @since || @relative_period,
|
|
69
|
-
)
|
|
70
|
-
when :go
|
|
71
|
-
Engine.concurrent(
|
|
72
|
-
complexity: Complexity::GoCalculator,
|
|
73
|
-
churn:,
|
|
74
|
-
file_selector: FileSelector::Go.excluding(@excluded),
|
|
75
|
-
serializer:,
|
|
76
|
-
since: @since || @relative_period,
|
|
77
|
-
)
|
|
78
|
-
when :kotlin
|
|
79
|
-
Engine.concurrent(
|
|
80
|
-
complexity: Complexity::KotlinCalculator,
|
|
81
|
-
churn:,
|
|
82
|
-
file_selector: FileSelector::Kotlin.excluding(@excluded),
|
|
83
|
-
serializer:,
|
|
84
|
-
since: @since || @relative_period,
|
|
85
|
-
)
|
|
86
|
-
when :rust
|
|
87
|
-
Engine.concurrent(
|
|
88
|
-
complexity: Complexity::RustCalculator,
|
|
89
|
-
churn:,
|
|
90
|
-
file_selector: FileSelector::Rust.excluding(@excluded),
|
|
91
|
-
serializer:,
|
|
92
|
-
since: @since || @relative_period,
|
|
93
|
-
)
|
|
94
|
-
when :swift
|
|
95
|
-
Engine.concurrent(
|
|
96
|
-
complexity: Complexity::SwiftCalculator,
|
|
97
|
-
churn:,
|
|
98
|
-
file_selector: FileSelector::Swift.excluding(@excluded),
|
|
99
|
-
serializer:,
|
|
100
|
-
since: @since || @relative_period,
|
|
101
|
-
)
|
|
102
|
-
end
|
|
30
|
+
return unless LanguageRegistry.supported?(@scope.language)
|
|
31
|
+
|
|
32
|
+
entry = LanguageRegistry.fetch(@scope.language)
|
|
33
|
+
Engine.concurrent(
|
|
34
|
+
complexity: entry.calculator,
|
|
35
|
+
churn:,
|
|
36
|
+
file_selector: entry.file_selector.excluding(@scope.excluded),
|
|
37
|
+
serializer:,
|
|
38
|
+
since: @scope.since || @relative_period,
|
|
39
|
+
)
|
|
103
40
|
end
|
|
104
41
|
|
|
105
42
|
private
|
|
@@ -108,18 +45,12 @@ module ChurnVsComplexity
|
|
|
108
45
|
|
|
109
46
|
def serializer
|
|
110
47
|
case @serializer
|
|
111
|
-
when :none
|
|
112
|
-
|
|
113
|
-
when :
|
|
114
|
-
|
|
115
|
-
when :
|
|
116
|
-
|
|
117
|
-
when :summary
|
|
118
|
-
Serializer::Summary
|
|
119
|
-
when :pass_through
|
|
120
|
-
Serializer::PassThrough
|
|
121
|
-
when :json
|
|
122
|
-
Serializer::Json
|
|
48
|
+
when :none then Serializer::None
|
|
49
|
+
when :csv then Serializer::CSV
|
|
50
|
+
when :graph then Serializer::Graph.new
|
|
51
|
+
when :summary then Serializer::Summary
|
|
52
|
+
when :pass_through then Serializer::PassThrough
|
|
53
|
+
when :json then Serializer::Json
|
|
123
54
|
end
|
|
124
55
|
end
|
|
125
56
|
end
|
|
@@ -9,9 +9,10 @@ module ChurnVsComplexity
|
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
def serialize(result)
|
|
12
|
-
|
|
12
|
+
entries = result[:values_by_file].map do |file, values|
|
|
13
13
|
"{ file_path: '#{file}', churn: #{values[0]}, complexity: #{values[1]} }"
|
|
14
|
-
end.join(",\n")
|
|
14
|
+
end.join(",\n")
|
|
15
|
+
data = "#{entries}\n"
|
|
15
16
|
title = Serializer.title(result)
|
|
16
17
|
@template.gsub("// INSERT DATA\n", data).gsub('INSERT TITLE', title)
|
|
17
18
|
end
|
|
@@ -4,25 +4,29 @@ module ChurnVsComplexity
|
|
|
4
4
|
module Normal
|
|
5
5
|
module Serializer
|
|
6
6
|
module Summary
|
|
7
|
+
SECTIONS = [
|
|
8
|
+
['Churn', :mean_churn, :median_churn],
|
|
9
|
+
['Complexity', :mean_complexity, :median_complexity],
|
|
10
|
+
['Gamma score', :mean_gamma_score, :median_gamma_score],
|
|
11
|
+
].freeze
|
|
12
|
+
private_constant :SECTIONS
|
|
13
|
+
|
|
7
14
|
def self.serialize(result)
|
|
8
|
-
values_by_file = result[:values_by_file]
|
|
9
15
|
summary = SummaryHash.serialize(result)
|
|
16
|
+
"#{[header(result), *metric_sections(summary)].join("\n\n")}\n"
|
|
17
|
+
end
|
|
10
18
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
Number of observations: #{values_by_file.size}
|
|
15
|
-
|
|
16
|
-
Churn:
|
|
17
|
-
Mean #{summary[:mean_churn]}, Median #{summary[:median_churn]}
|
|
18
|
-
|
|
19
|
-
Complexity:
|
|
20
|
-
Mean #{summary[:mean_complexity]}, Median #{summary[:median_complexity]}
|
|
19
|
+
def self.header(result)
|
|
20
|
+
"#{Serializer.title(result)}\n\nNumber of observations: #{result[:values_by_file].size}"
|
|
21
|
+
end
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
def self.metric_sections(summary)
|
|
24
|
+
SECTIONS.map do |label, mean_key, median_key|
|
|
25
|
+
"#{label}:\nMean #{summary[mean_key]}, Median #{summary[median_key]}"
|
|
26
|
+
end
|
|
25
27
|
end
|
|
28
|
+
|
|
29
|
+
private_class_method :header, :metric_sections
|
|
26
30
|
end
|
|
27
31
|
end
|
|
28
32
|
end
|
|
@@ -4,6 +4,20 @@ module ChurnVsComplexity
|
|
|
4
4
|
module Normal
|
|
5
5
|
module Serializer
|
|
6
6
|
module SummaryHash
|
|
7
|
+
EMPTY_METRICS = {
|
|
8
|
+
mean_churn: 0.0,
|
|
9
|
+
median_churn: 0.0,
|
|
10
|
+
max_churn: 0.0,
|
|
11
|
+
min_churn: 0.0,
|
|
12
|
+
mean_complexity: 0.0,
|
|
13
|
+
median_complexity: 0.0,
|
|
14
|
+
max_complexity: 0.0,
|
|
15
|
+
min_complexity: 0.0,
|
|
16
|
+
mean_gamma_score: 0.0,
|
|
17
|
+
median_gamma_score: 0.0,
|
|
18
|
+
}.freeze
|
|
19
|
+
private_constant :EMPTY_METRICS
|
|
20
|
+
|
|
7
21
|
class << self
|
|
8
22
|
def serialize(result)
|
|
9
23
|
values_by_file = result[:values_by_file]
|
|
@@ -41,19 +55,7 @@ module ChurnVsComplexity
|
|
|
41
55
|
end
|
|
42
56
|
|
|
43
57
|
def empty_summary(end_date)
|
|
44
|
-
|
|
45
|
-
mean_churn: 0.0,
|
|
46
|
-
median_churn: 0.0,
|
|
47
|
-
max_churn: 0.0,
|
|
48
|
-
min_churn: 0.0,
|
|
49
|
-
mean_complexity: 0.0,
|
|
50
|
-
median_complexity: 0.0,
|
|
51
|
-
max_complexity: 0.0,
|
|
52
|
-
min_complexity: 0.0,
|
|
53
|
-
mean_gamma_score: 0.0,
|
|
54
|
-
median_gamma_score: 0.0,
|
|
55
|
-
end_date:,
|
|
56
|
-
}
|
|
58
|
+
EMPTY_METRICS.merge(end_date:)
|
|
57
59
|
end
|
|
58
60
|
end
|
|
59
61
|
end
|
|
@@ -16,7 +16,8 @@ module ChurnVsComplexity
|
|
|
16
16
|
if requested_start_date.nil?
|
|
17
17
|
"Churn until #{end_date.strftime('%Y-%m-%d')} vs complexity"
|
|
18
18
|
else
|
|
19
|
-
"Churn between #{requested_start_date.strftime('%Y-%m-%d')}
|
|
19
|
+
"Churn between #{requested_start_date.strftime('%Y-%m-%d')} " \
|
|
20
|
+
"and #{end_date.strftime('%Y-%m-%d')} vs complexity"
|
|
20
21
|
end
|
|
21
22
|
end
|
|
22
23
|
|
|
@@ -5,7 +5,6 @@ require_relative 'normal/serializer'
|
|
|
5
5
|
|
|
6
6
|
module ChurnVsComplexity
|
|
7
7
|
module Normal
|
|
8
|
-
# TODO: unit test
|
|
9
8
|
module SerializerValidator
|
|
10
9
|
def self.validate!(serializer:)
|
|
11
10
|
raise ValidationError, "Unsupported serializer: #{serializer}" \
|
|
@@ -13,7 +12,6 @@ module ChurnVsComplexity
|
|
|
13
12
|
end
|
|
14
13
|
end
|
|
15
14
|
|
|
16
|
-
# TODO: unit test
|
|
17
15
|
module RelativePeriodValidator
|
|
18
16
|
def self.validate!(relative_period:)
|
|
19
17
|
return if relative_period.nil? || %i[month quarter year].include?(relative_period)
|
|
@@ -24,22 +22,28 @@ module ChurnVsComplexity
|
|
|
24
22
|
|
|
25
23
|
module SinceValidator
|
|
26
24
|
def self.validate!(since:, relative_period:)
|
|
27
|
-
# since can be nil, a date string or a keyword (:month, :quarter, :year)
|
|
28
25
|
return if since.nil?
|
|
29
26
|
|
|
30
|
-
|
|
31
|
-
raise ValidationError,
|
|
32
|
-
'--since and relative period (--month, --quarter, --year) cannot be used together in normal mode'
|
|
33
|
-
end
|
|
34
|
-
|
|
27
|
+
validate_exclusive!(relative_period)
|
|
35
28
|
raise ValidationError, "Invalid since value #{since}" unless since.is_a?(String)
|
|
36
29
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
30
|
+
validate_date_format!(since)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.validate_exclusive!(relative_period)
|
|
34
|
+
return if relative_period.nil?
|
|
35
|
+
|
|
36
|
+
raise ValidationError,
|
|
37
|
+
'--since and relative period (--month, --quarter, --year) cannot be used together'
|
|
42
38
|
end
|
|
39
|
+
|
|
40
|
+
def self.validate_date_format!(since)
|
|
41
|
+
Date.strptime(since, '%Y-%m-%d')
|
|
42
|
+
rescue Date::Error
|
|
43
|
+
raise ValidationError, "Invalid date #{since}, please use correct format, YYYY-MM-DD"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
private_class_method :validate_exclusive!, :validate_date_format!
|
|
43
47
|
end
|
|
44
48
|
end
|
|
45
49
|
end
|
|
@@ -4,31 +4,15 @@ module ChurnVsComplexity
|
|
|
4
4
|
# Classifies files into low/medium/high risk based on gamma score
|
|
5
5
|
# (harmonic mean of churn and complexity).
|
|
6
6
|
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
# Language Tool Metric Trivial Complex (~100 LOC) Real-world range
|
|
12
|
-
# Ruby Flog Code pain (weighted) 0 ~286 0-88
|
|
13
|
-
# JavaScript/TS ESLint Cyclomatic complexity 3 ~62 10-50
|
|
14
|
-
# Python Radon Cyclomatic complexity 1 ~44 5-50
|
|
15
|
-
# Java PMD Cyclomatic complexity 1 ~39 1-40
|
|
16
|
-
# Go gocognit Cognitive complexity 0 ~87 0-50
|
|
17
|
-
# Kotlin lizard Cyclomatic complexity 1 ~40 1-40
|
|
18
|
-
# Rust lizard Cyclomatic complexity 1 ~40 1-40
|
|
19
|
-
# Swift lizard Cyclomatic complexity 1 ~40 1-40
|
|
20
|
-
#
|
|
21
|
-
# The DEFAULT_LOW and DEFAULT_HIGH thresholds below are rough midpoints
|
|
22
|
-
# suitable for Java/Python/JS. They are too aggressive for Ruby (Flog
|
|
23
|
-
# scores 3-7x higher) and Go (cognitive complexity penalises nesting).
|
|
24
|
-
# Use the constructor to pass language-appropriate thresholds.
|
|
7
|
+
# Default thresholds (10 / 25) fit cyclomatic complexity from lizard (used for
|
|
8
|
+
# all non-Ruby languages). Ruby uses Flog whose weighted pain scores run higher,
|
|
9
|
+
# so it overrides the defaults.
|
|
25
10
|
class RiskClassifier
|
|
26
11
|
DEFAULT_LOW = 10
|
|
27
12
|
DEFAULT_HIGH = 25
|
|
28
13
|
|
|
29
14
|
LANGUAGE_DEFAULTS = {
|
|
30
15
|
ruby: { low: 30, high: 70 },
|
|
31
|
-
go: { low: 15, high: 40 },
|
|
32
16
|
}.freeze
|
|
33
17
|
|
|
34
18
|
RECOMMENDATIONS = {
|
|
@@ -3,71 +3,58 @@
|
|
|
3
3
|
module ChurnVsComplexity
|
|
4
4
|
module Timetravel
|
|
5
5
|
class Config
|
|
6
|
-
def
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
)
|
|
17
|
-
@language = language
|
|
6
|
+
def self.from_options(options)
|
|
7
|
+
new(
|
|
8
|
+
scope: AnalysisScope.from_options(options),
|
|
9
|
+
serializer: options[:serializer],
|
|
10
|
+
schedule: Schedule.from_options(options),
|
|
11
|
+
)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def initialize(scope:, serializer:, schedule:, validators: ValidatorSet.new(since: SinceValidator))
|
|
15
|
+
@scope = scope
|
|
18
16
|
@serializer = serializer
|
|
19
|
-
@
|
|
20
|
-
@
|
|
21
|
-
@relative_period = relative_period
|
|
22
|
-
@jump_days = jump_days
|
|
23
|
-
@complexity_validator = complexity_validator
|
|
24
|
-
@since_validator = since_validator
|
|
25
|
-
@factory = factory
|
|
26
|
-
@options = options
|
|
17
|
+
@schedule = schedule
|
|
18
|
+
@validators = validators
|
|
27
19
|
end
|
|
28
20
|
|
|
29
21
|
def validate!
|
|
30
|
-
raise ValidationError, 'Must specify jump days!' if @jump_days.nil?
|
|
31
|
-
|
|
32
|
-
LanguageValidator.validate!(@language)
|
|
22
|
+
raise ValidationError, 'Must specify jump days!' if @schedule.jump_days.nil?
|
|
33
23
|
|
|
24
|
+
LanguageValidator.validate!(@scope.language)
|
|
34
25
|
SerializerValidator.validate!(serializer: @serializer)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
@complexity_validator.validate!(@language)
|
|
26
|
+
@validators.since.validate!(since: @scope.since)
|
|
27
|
+
RelativePeriodValidator.validate!(relative_period: @schedule.relative_period)
|
|
28
|
+
@validators.complexity.validate!(@scope.language)
|
|
39
29
|
end
|
|
40
30
|
|
|
41
|
-
def checker
|
|
42
|
-
|
|
43
|
-
private
|
|
44
|
-
|
|
45
|
-
def traveller(git_period:)
|
|
31
|
+
def checker
|
|
32
|
+
resolved = @schedule.with(git_period: GitDate.git_period(@scope.since, Time.now.to_date))
|
|
46
33
|
Traveller.new(
|
|
47
|
-
|
|
48
|
-
relative_period: @relative_period,
|
|
34
|
+
schedule: resolved,
|
|
49
35
|
engine: engine_config.checker,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
factory: @factory,
|
|
36
|
+
serializer: resolve_serializer(resolved),
|
|
37
|
+
factory: Factory,
|
|
53
38
|
)
|
|
54
39
|
end
|
|
55
40
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
def resolve_serializer(schedule)
|
|
44
|
+
Serializer.resolve(
|
|
45
|
+
serializer: @serializer,
|
|
46
|
+
git_period: schedule.git_period,
|
|
47
|
+
relative_period: schedule.relative_period,
|
|
48
|
+
jump_days: schedule.jump_days,
|
|
49
|
+
)
|
|
59
50
|
end
|
|
60
51
|
|
|
61
52
|
def engine_config
|
|
62
53
|
Normal::Config.new(
|
|
63
|
-
|
|
54
|
+
scope: @scope.with(since: nil),
|
|
64
55
|
serializer: :pass_through,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
relative_period: @relative_period,
|
|
68
|
-
complexity_validator: @complexity_validator,
|
|
69
|
-
since_validator: @since_validator,
|
|
70
|
-
**@options,
|
|
56
|
+
relative_period: @schedule.relative_period,
|
|
57
|
+
validators: ValidatorSet.new(complexity: @validators.complexity),
|
|
71
58
|
)
|
|
72
59
|
end
|
|
73
60
|
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ChurnVsComplexity
|
|
4
|
+
module Timetravel
|
|
5
|
+
Schedule = Data.define(:git_period, :relative_period, :jump_days) do
|
|
6
|
+
def initialize(jump_days:, relative_period: nil, git_period: nil)
|
|
7
|
+
super
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.from_options(options)
|
|
11
|
+
new(jump_days: options[:jump_days], relative_period: options[:relative_period])
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|