churn_vs_complexity 1.8.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 +95 -0
- data/README.md +46 -23
- data/bin/churn_vs_complexity +6 -1
- data/lib/churn_vs_complexity/analysis_scope.rb +20 -0
- data/lib/churn_vs_complexity/churn.rb +41 -8
- 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 +7 -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 +35 -25
- data/lib/churn_vs_complexity/gate/serializer.rb +9 -2
- data/lib/churn_vs_complexity/git_strategy.rb +29 -10
- 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 +36 -21
- 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 +46 -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 -59
- data/.devcontainer/devcontainer.json +0 -26
- data/.rubocop.yml +0 -25
- data/CLAUDE.md +0 -60
- data/Dockerfile +0 -34
- data/Dockerfile.dev +0 -27
- data/Rakefile +0 -6
- data/TODO +0 -11
- 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/package-lock.json +0 -6
- 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
- data/tmp/test-support/delta/ruby-summary.txt +0 -55
- data/tmp/test-support/delta/ruby.csv +0 -12
- data/tmp/test-support/go/main.go +0 -11
- data/tmp/test-support/go/utils.go +0 -13
- data/tmp/test-support/java/small-example/src/main/java/org/example/Main.java +0 -10
- data/tmp/test-support/java/small-example/src/main/java/org/example/spice/Checker.java +0 -28
- data/tmp/test-support/javascript/complex.js +0 -43
- data/tmp/test-support/javascript/moderate.js +0 -12
- data/tmp/test-support/javascript/simple.js +0 -5
- data/tmp/test-support/javascript/typescript-example.ts +0 -26
- data/tmp/test-support/kotlin/Main.kt +0 -7
- data/tmp/test-support/kotlin/Utils.kt +0 -11
- data/tmp/test-support/python/example.py +0 -6
- data/tmp/test-support/python/utils.py +0 -9
- data/tmp/test-support/rust/main.rs +0 -7
- data/tmp/test-support/rust/utils.rs +0 -20
- data/tmp/test-support/swift/main.swift +0 -7
- data/tmp/test-support/swift/utils.swift +0 -24
- data/tmp/test-support/txt/abc.txt +0 -0
- data/tmp/test-support/txt/d.txt +0 -0
- data/tmp/test-support/txt/ef.txt +0 -0
- data/tmp/test-support/txt/ghij.txt +0 -0
- data/tmp/test-support/txt/klm.txt +0 -0
- data/tmp/test-support/txt/nopq.txt +0 -0
- data/tmp/test-support/txt/r.txt +0 -0
- data/tmp/test-support/txt/st.txt +0 -0
- data/tmp/test-support/txt/uvx.txt +0 -0
- data/tmp/test-support/txt/yz.txt +0 -0
- data/tmp/timetravel/.keep +0 -0
|
@@ -4,45 +4,55 @@ module ChurnVsComplexity
|
|
|
4
4
|
module Gate
|
|
5
5
|
class Config
|
|
6
6
|
DEFAULT_MAX_GAMMA = 25
|
|
7
|
+
SUPPORTED_SERIALIZERS = %i[json].freeze
|
|
7
8
|
|
|
8
|
-
def
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
@language = language
|
|
9
|
+
def self.from_options(options)
|
|
10
|
+
new(
|
|
11
|
+
scope: AnalysisScope.from_options(options),
|
|
12
|
+
serializer: options[:serializer] || :json,
|
|
13
|
+
max_gamma: options[:max_gamma] || DEFAULT_MAX_GAMMA,
|
|
14
|
+
)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def initialize(scope:, serializer: :json, max_gamma: DEFAULT_MAX_GAMMA, validators: ValidatorSet.new)
|
|
18
|
+
@scope = scope
|
|
19
19
|
@serializer = serializer
|
|
20
20
|
@max_gamma = max_gamma
|
|
21
|
-
@
|
|
22
|
-
@excluded = excluded
|
|
23
|
-
@complexity_validator = complexity_validator
|
|
24
|
-
@since_validator = since_validator
|
|
25
|
-
@options = options
|
|
21
|
+
@validators = validators
|
|
26
22
|
end
|
|
27
23
|
|
|
28
24
|
def validate!
|
|
29
|
-
LanguageValidator.validate!(@language)
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
LanguageValidator.validate!(@scope.language)
|
|
26
|
+
validate_serializer!
|
|
27
|
+
validate_period!
|
|
28
|
+
@validators.complexity.validate!(@scope.language)
|
|
29
|
+
validate_max_gamma!
|
|
32
30
|
end
|
|
33
31
|
|
|
34
32
|
def checker
|
|
35
|
-
normal_config = Normal::Config.new(
|
|
36
|
-
language: @language,
|
|
37
|
-
serializer: :none,
|
|
38
|
-
since: @since,
|
|
39
|
-
excluded: @excluded,
|
|
40
|
-
)
|
|
33
|
+
normal_config = Normal::Config.new(scope: @scope, serializer: :none)
|
|
41
34
|
Checker.new(engine: normal_config.checker, serializer: gate_serializer, max_gamma: @max_gamma)
|
|
42
35
|
end
|
|
43
36
|
|
|
44
37
|
private
|
|
45
38
|
|
|
39
|
+
def validate_serializer!
|
|
40
|
+
return if SUPPORTED_SERIALIZERS.include?(@serializer)
|
|
41
|
+
|
|
42
|
+
raise ValidationError, "Unsupported serializer: #{@serializer}"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def validate_period!
|
|
46
|
+
@validators.since.validate!(since: @scope.since, relative_period: @scope.relative_period)
|
|
47
|
+
Normal::RelativePeriodValidator.validate!(relative_period: @scope.relative_period)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def validate_max_gamma!
|
|
51
|
+
return unless @max_gamma.negative?
|
|
52
|
+
|
|
53
|
+
raise ValidationError, "Max gamma must not be negative, got #{@max_gamma}"
|
|
54
|
+
end
|
|
55
|
+
|
|
46
56
|
def gate_serializer
|
|
47
57
|
case @serializer
|
|
48
58
|
when :json then Serializer::Json
|
|
@@ -24,10 +24,17 @@ module ChurnVsComplexity
|
|
|
24
24
|
gamma = GammaScore.calculate(values[0], values[1]).round(2)
|
|
25
25
|
next unless gamma > max_gamma
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
{ file:, gamma_score: gamma, exceeds_by: "#{exceeds_pct}%" }
|
|
27
|
+
{ file:, gamma_score: gamma, exceeds_by: excess(gamma, max_gamma) }
|
|
29
28
|
end
|
|
30
29
|
end
|
|
30
|
+
|
|
31
|
+
# There is no percentage by which a score exceeds zero, so a zero
|
|
32
|
+
# threshold reports the violation without one.
|
|
33
|
+
def excess(gamma, max_gamma)
|
|
34
|
+
return nil if max_gamma.zero?
|
|
35
|
+
|
|
36
|
+
"#{(((gamma - max_gamma) / max_gamma) * 100).round(0)}%"
|
|
37
|
+
end
|
|
31
38
|
end
|
|
32
39
|
end
|
|
33
40
|
end
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'open3'
|
|
4
|
+
|
|
3
5
|
module ChurnVsComplexity
|
|
4
6
|
class GitStrategy
|
|
5
7
|
EMPTY_TREE_SHA = '4b825dc642cb6eb9a060e54bf8d69288fbee4904'
|
|
@@ -12,7 +14,7 @@ module ChurnVsComplexity
|
|
|
12
14
|
def valid_commit?(commit:)
|
|
13
15
|
@repo.object(commit)
|
|
14
16
|
true
|
|
15
|
-
rescue Git::
|
|
17
|
+
rescue Git::Error
|
|
16
18
|
false
|
|
17
19
|
end
|
|
18
20
|
|
|
@@ -22,8 +24,8 @@ module ChurnVsComplexity
|
|
|
22
24
|
|
|
23
25
|
def surrounding(commit:)
|
|
24
26
|
current = object(commit)
|
|
25
|
-
child_sha =
|
|
26
|
-
next_commit = child_sha
|
|
27
|
+
child_sha = next_commit_sha(current.sha)
|
|
28
|
+
next_commit = child_sha.nil? || child_sha.empty? ? nil : child_sha
|
|
27
29
|
[current.parent&.sha, next_commit]
|
|
28
30
|
end
|
|
29
31
|
|
|
@@ -35,12 +37,24 @@ module ChurnVsComplexity
|
|
|
35
37
|
end
|
|
36
38
|
|
|
37
39
|
def checkout_in_worktree(worktree_folder, sha)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
Open3.capture3('git', '-C', worktree_folder, 'checkout', sha)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Both ends are given an explicit time. A bare date is an approximate date
|
|
44
|
+
# to git, resolved against the clock and the timezone, so the window it
|
|
45
|
+
# produces is not the window that was asked for.
|
|
46
|
+
def commits_in(git_period)
|
|
47
|
+
log = @repo.log(1_000_000).until(end_of_day(git_period.end_date))
|
|
48
|
+
log = log.since(start_of_day(git_period.effective_start_date)) if git_period.requested_start_date
|
|
49
|
+
log.execute.to_a
|
|
40
50
|
end
|
|
41
51
|
|
|
52
|
+
def start_of_day(date) = date.strftime('%Y-%m-%dT00:00:00')
|
|
53
|
+
|
|
54
|
+
def end_of_day(date) = date.strftime('%Y-%m-%dT23:59:59')
|
|
55
|
+
|
|
42
56
|
def resolve_commits_with_interval(git_period:, jump_days:)
|
|
43
|
-
candidates =
|
|
57
|
+
candidates = commits_in(git_period)
|
|
44
58
|
|
|
45
59
|
commits_by_date = candidates.filter { |c| c.date.to_date >= git_period.effective_start_date }
|
|
46
60
|
.group_by { |c| c.date.to_date }
|
|
@@ -51,17 +65,22 @@ module ChurnVsComplexity
|
|
|
51
65
|
end
|
|
52
66
|
|
|
53
67
|
def add_worktree(wt_folder)
|
|
54
|
-
|
|
55
|
-
`#{command}`
|
|
68
|
+
Open3.capture3('git', '-C', @folder, 'worktree', 'add', '--detach', '-f', wt_folder)
|
|
56
69
|
end
|
|
57
70
|
|
|
58
71
|
def remove_worktree(worktree_folder)
|
|
59
|
-
|
|
60
|
-
`#{command}`
|
|
72
|
+
Open3.capture3('git', '-C', @folder, 'worktree', 'remove', '-f', worktree_folder)
|
|
61
73
|
end
|
|
62
74
|
|
|
63
75
|
private
|
|
64
76
|
|
|
77
|
+
def next_commit_sha(sha)
|
|
78
|
+
output, = Open3.capture2(
|
|
79
|
+
'git', '-C', @folder, 'log', '--reverse', '--ancestry-path', "#{sha}..HEAD", '--format=%H'
|
|
80
|
+
)
|
|
81
|
+
output.lines.first&.chomp
|
|
82
|
+
end
|
|
83
|
+
|
|
65
84
|
def diff_from_parent(commit_object)
|
|
66
85
|
base = commit_object.parent
|
|
67
86
|
base ? base.diff(commit_object) : @repo.diff(EMPTY_TREE_SHA, commit_object.sha)
|
|
@@ -3,42 +3,46 @@
|
|
|
3
3
|
module ChurnVsComplexity
|
|
4
4
|
module Hotspots
|
|
5
5
|
class Config
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
SUPPORTED_SERIALIZERS = %i[json markdown].freeze
|
|
7
|
+
|
|
8
|
+
def self.from_options(options)
|
|
9
|
+
new(
|
|
10
|
+
scope: AnalysisScope.from_options(options),
|
|
11
|
+
serializer: options[:serializer] || :json,
|
|
12
|
+
)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def initialize(scope:, serializer: :json, validators: ValidatorSet.new)
|
|
16
|
+
@scope = scope
|
|
16
17
|
@serializer = serializer
|
|
17
|
-
@
|
|
18
|
-
@excluded = excluded
|
|
19
|
-
@complexity_validator = complexity_validator
|
|
20
|
-
@since_validator = since_validator
|
|
21
|
-
@options = options
|
|
18
|
+
@validators = validators
|
|
22
19
|
end
|
|
23
20
|
|
|
24
21
|
def validate!
|
|
25
|
-
LanguageValidator.validate!(@language)
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
LanguageValidator.validate!(@scope.language)
|
|
23
|
+
validate_serializer!
|
|
24
|
+
validate_period!
|
|
25
|
+
@validators.complexity.validate!(@scope.language)
|
|
28
26
|
end
|
|
29
27
|
|
|
30
28
|
def checker
|
|
31
|
-
normal_config = Normal::Config.new(
|
|
32
|
-
|
|
33
|
-
serializer: :none,
|
|
34
|
-
since: @since,
|
|
35
|
-
excluded: @excluded,
|
|
36
|
-
)
|
|
37
|
-
Checker.new(engine: normal_config.checker, serializer: hotspots_serializer, language: @language)
|
|
29
|
+
normal_config = Normal::Config.new(scope: @scope, serializer: :none)
|
|
30
|
+
Checker.new(engine: normal_config.checker, serializer: hotspots_serializer, language: @scope.language)
|
|
38
31
|
end
|
|
39
32
|
|
|
40
33
|
private
|
|
41
34
|
|
|
35
|
+
def validate_serializer!
|
|
36
|
+
return if SUPPORTED_SERIALIZERS.include?(@serializer)
|
|
37
|
+
|
|
38
|
+
raise ValidationError, "Unsupported serializer: #{@serializer}"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def validate_period!
|
|
42
|
+
@validators.since.validate!(since: @scope.since, relative_period: @scope.relative_period)
|
|
43
|
+
Normal::RelativePeriodValidator.validate!(relative_period: @scope.relative_period)
|
|
44
|
+
end
|
|
45
|
+
|
|
42
46
|
def hotspots_serializer
|
|
43
47
|
case @serializer
|
|
44
48
|
when :json then Serializer::Json
|
|
@@ -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]
|
|
@@ -11,36 +25,37 @@ module ChurnVsComplexity
|
|
|
11
25
|
|
|
12
26
|
return empty_summary(end_date) if values_by_file.empty?
|
|
13
27
|
|
|
14
|
-
|
|
15
|
-
complexity_values = values_by_file.map { |_, values| values[1].to_f }
|
|
16
|
-
gamma_scores = values_by_file.map { |_, values| GammaScore.calculate(values[0], values[1]) }
|
|
17
|
-
|
|
18
|
-
stats(churn_values).transform_keys { |k| :"#{k}_churn" }
|
|
19
|
-
.merge(stats(complexity_values).transform_keys { |k| :"#{k}_complexity" })
|
|
20
|
-
.merge(stats(gamma_scores).slice(:mean, :median).transform_keys { |k| :"#{k}_gamma_score" })
|
|
21
|
-
.merge(end_date:)
|
|
28
|
+
summarise(values_by_file).merge(end_date:)
|
|
22
29
|
end
|
|
23
30
|
|
|
24
31
|
private
|
|
25
32
|
|
|
33
|
+
def summarise(values_by_file)
|
|
34
|
+
churn_stats(values_by_file)
|
|
35
|
+
.merge(complexity_stats(values_by_file), gamma_stats(values_by_file))
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def churn_stats(values_by_file)
|
|
39
|
+
values = values_by_file.map { |_, pair| pair[0].to_f }
|
|
40
|
+
stats(values).transform_keys { |key| :"#{key}_churn" }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def complexity_stats(values_by_file)
|
|
44
|
+
values = values_by_file.map { |_, pair| pair[1].to_f }
|
|
45
|
+
stats(values).transform_keys { |key| :"#{key}_complexity" }
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def gamma_stats(values_by_file)
|
|
49
|
+
values = values_by_file.map { |_, pair| GammaScore.calculate(pair[0], pair[1]) }
|
|
50
|
+
stats(values).slice(:mean, :median).transform_keys { |key| :"#{key}_gamma_score" }
|
|
51
|
+
end
|
|
52
|
+
|
|
26
53
|
def stats(values)
|
|
27
54
|
{ mean: values.sum / values.size, median: values.sort[values.size / 2], max: values.max, min: values.min }
|
|
28
55
|
end
|
|
29
56
|
|
|
30
57
|
def empty_summary(end_date)
|
|
31
|
-
|
|
32
|
-
mean_churn: 0.0,
|
|
33
|
-
median_churn: 0.0,
|
|
34
|
-
max_churn: 0.0,
|
|
35
|
-
min_churn: 0.0,
|
|
36
|
-
mean_complexity: 0.0,
|
|
37
|
-
median_complexity: 0.0,
|
|
38
|
-
max_complexity: 0.0,
|
|
39
|
-
min_complexity: 0.0,
|
|
40
|
-
mean_gamma_score: 0.0,
|
|
41
|
-
median_gamma_score: 0.0,
|
|
42
|
-
end_date:,
|
|
43
|
-
}
|
|
58
|
+
EMPTY_METRICS.merge(end_date:)
|
|
44
59
|
end
|
|
45
60
|
end
|
|
46
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
|
|