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.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +95 -0
  3. data/README.md +46 -23
  4. data/bin/churn_vs_complexity +6 -1
  5. data/lib/churn_vs_complexity/analysis_scope.rb +20 -0
  6. data/lib/churn_vs_complexity/churn.rb +41 -8
  7. data/lib/churn_vs_complexity/cli/main.rb +58 -19
  8. data/lib/churn_vs_complexity/cli/parser.rb +85 -121
  9. data/lib/churn_vs_complexity/cli.rb +2 -3
  10. data/lib/churn_vs_complexity/complexity/flog_calculator.rb +0 -3
  11. data/lib/churn_vs_complexity/complexity/lizard_calculator.rb +64 -0
  12. data/lib/churn_vs_complexity/complexity.rb +1 -7
  13. data/lib/churn_vs_complexity/complexity_validator.rb +1 -16
  14. data/lib/churn_vs_complexity/concurrent_calculator.rb +20 -23
  15. data/lib/churn_vs_complexity/delta/checker.rb +35 -21
  16. data/lib/churn_vs_complexity/delta/commit_hydrator.rb +1 -1
  17. data/lib/churn_vs_complexity/delta/complexity_annotator.rb +23 -5
  18. data/lib/churn_vs_complexity/delta/config.rb +15 -16
  19. data/lib/churn_vs_complexity/delta/factory.rb +2 -2
  20. data/lib/churn_vs_complexity/delta/multi_checker.rb +24 -25
  21. data/lib/churn_vs_complexity/delta/serializer.rb +7 -4
  22. data/lib/churn_vs_complexity/delta.rb +11 -49
  23. data/lib/churn_vs_complexity/diff/checker.rb +10 -3
  24. data/lib/churn_vs_complexity/diff/config.rb +29 -20
  25. data/lib/churn_vs_complexity/file_selector.rb +63 -114
  26. data/lib/churn_vs_complexity/focus/config.rb +42 -32
  27. data/lib/churn_vs_complexity/focus/serializer.rb +17 -4
  28. data/lib/churn_vs_complexity/gate/config.rb +35 -25
  29. data/lib/churn_vs_complexity/gate/serializer.rb +9 -2
  30. data/lib/churn_vs_complexity/git_strategy.rb +29 -10
  31. data/lib/churn_vs_complexity/hotspots/config.rb +29 -25
  32. data/lib/churn_vs_complexity/language_registry.rb +108 -0
  33. data/lib/churn_vs_complexity/language_validator.rb +1 -3
  34. data/lib/churn_vs_complexity/normal/config.rb +31 -100
  35. data/lib/churn_vs_complexity/normal/serializer/graph.rb +3 -2
  36. data/lib/churn_vs_complexity/normal/serializer/summary.rb +18 -14
  37. data/lib/churn_vs_complexity/normal/serializer/summary_hash.rb +36 -21
  38. data/lib/churn_vs_complexity/normal/serializer.rb +2 -1
  39. data/lib/churn_vs_complexity/normal.rb +17 -13
  40. data/lib/churn_vs_complexity/risk_classifier.rb +3 -19
  41. data/lib/churn_vs_complexity/timetravel/config.rb +34 -47
  42. data/lib/churn_vs_complexity/timetravel/schedule.rb +15 -0
  43. data/lib/churn_vs_complexity/timetravel/serializer/stats_calculator.rb +36 -32
  44. data/lib/churn_vs_complexity/timetravel/serializer.rb +16 -24
  45. data/lib/churn_vs_complexity/timetravel/traveller.rb +46 -15
  46. data/lib/churn_vs_complexity/timetravel.rb +36 -14
  47. data/lib/churn_vs_complexity/triage/checker.rb +24 -28
  48. data/lib/churn_vs_complexity/triage/collaborator_set.rb +11 -0
  49. data/lib/churn_vs_complexity/triage/config.rb +29 -26
  50. data/lib/churn_vs_complexity/triage.rb +1 -0
  51. data/lib/churn_vs_complexity/validator_set.rb +9 -0
  52. data/lib/churn_vs_complexity/version.rb +1 -1
  53. data/lib/churn_vs_complexity.rb +3 -0
  54. metadata +18 -59
  55. data/.devcontainer/devcontainer.json +0 -26
  56. data/.rubocop.yml +0 -25
  57. data/CLAUDE.md +0 -60
  58. data/Dockerfile +0 -34
  59. data/Dockerfile.dev +0 -27
  60. data/Rakefile +0 -6
  61. data/TODO +0 -11
  62. data/lib/churn_vs_complexity/complexity/eslint_calculator.rb +0 -40
  63. data/lib/churn_vs_complexity/complexity/go_calculator.rb +0 -48
  64. data/lib/churn_vs_complexity/complexity/kotlin_calculator.rb +0 -54
  65. data/lib/churn_vs_complexity/complexity/pmd/files_calculator.rb +0 -26
  66. data/lib/churn_vs_complexity/complexity/pmd/folder_calculator.rb +0 -20
  67. data/lib/churn_vs_complexity/complexity/pmd.rb +0 -54
  68. data/lib/churn_vs_complexity/complexity/python_calculator.rb +0 -50
  69. data/lib/churn_vs_complexity/complexity/rust_calculator.rb +0 -54
  70. data/lib/churn_vs_complexity/complexity/swift_calculator.rb +0 -54
  71. data/package-lock.json +0 -6
  72. data/tmp/eslint-support/complexity-calculator.js +0 -51
  73. data/tmp/eslint-support/package.json +0 -11
  74. data/tmp/pmd-support/ruleset.xml +0 -21
  75. data/tmp/test-support/delta/ruby-summary.txt +0 -55
  76. data/tmp/test-support/delta/ruby.csv +0 -12
  77. data/tmp/test-support/go/main.go +0 -11
  78. data/tmp/test-support/go/utils.go +0 -13
  79. data/tmp/test-support/java/small-example/src/main/java/org/example/Main.java +0 -10
  80. data/tmp/test-support/java/small-example/src/main/java/org/example/spice/Checker.java +0 -28
  81. data/tmp/test-support/javascript/complex.js +0 -43
  82. data/tmp/test-support/javascript/moderate.js +0 -12
  83. data/tmp/test-support/javascript/simple.js +0 -5
  84. data/tmp/test-support/javascript/typescript-example.ts +0 -26
  85. data/tmp/test-support/kotlin/Main.kt +0 -7
  86. data/tmp/test-support/kotlin/Utils.kt +0 -11
  87. data/tmp/test-support/python/example.py +0 -6
  88. data/tmp/test-support/python/utils.py +0 -9
  89. data/tmp/test-support/rust/main.rs +0 -7
  90. data/tmp/test-support/rust/utils.rs +0 -20
  91. data/tmp/test-support/swift/main.swift +0 -7
  92. data/tmp/test-support/swift/utils.swift +0 -24
  93. data/tmp/test-support/txt/abc.txt +0 -0
  94. data/tmp/test-support/txt/d.txt +0 -0
  95. data/tmp/test-support/txt/ef.txt +0 -0
  96. data/tmp/test-support/txt/ghij.txt +0 -0
  97. data/tmp/test-support/txt/klm.txt +0 -0
  98. data/tmp/test-support/txt/nopq.txt +0 -0
  99. data/tmp/test-support/txt/r.txt +0 -0
  100. data/tmp/test-support/txt/st.txt +0 -0
  101. data/tmp/test-support/txt/uvx.txt +0 -0
  102. data/tmp/test-support/txt/yz.txt +0 -0
  103. data/tmp/timetravel/.keep +0 -0
@@ -3,44 +3,47 @@
3
3
  module ChurnVsComplexity
4
4
  module Triage
5
5
  class Config
6
- def initialize(
7
- language:,
8
- serializer: :json,
9
- targets: [],
10
- since: nil,
11
- excluded: [],
12
- complexity_validator: ComplexityValidator,
13
- since_validator: Normal::SinceValidator,
14
- **options
15
- )
16
- @language = language
6
+ SUPPORTED_SERIALIZERS = %i[json].freeze
7
+
8
+ def self.from_options(options)
9
+ new(
10
+ scope: AnalysisScope.from_options(options),
11
+ serializer: options[:serializer] || :json,
12
+ targets: options.fetch(:targets, []),
13
+ )
14
+ end
15
+
16
+ def initialize(scope:, serializer: :json, targets: [], validators: ValidatorSet.new)
17
+ @scope = scope
17
18
  @serializer = serializer
18
19
  @targets = targets
19
- @since = since
20
- @excluded = excluded
21
- @complexity_validator = complexity_validator
22
- @since_validator = since_validator
23
- @options = options
20
+ @validators = validators
24
21
  end
25
22
 
26
23
  def validate!
27
- LanguageValidator.validate!(@language)
28
- @since_validator.validate!(since: @since, relative_period: nil)
29
- @complexity_validator.validate!(@language)
24
+ LanguageValidator.validate!(@scope.language)
25
+ validate_serializer!
26
+ validate_period!
27
+ @validators.complexity.validate!(@scope.language)
30
28
  end
31
29
 
32
30
  def checker
33
- Checker.new(
34
- language: @language,
35
- serializer: triage_serializer,
36
- targets: @targets,
37
- since: @since,
38
- excluded: @excluded,
39
- )
31
+ Checker.new(scope: @scope, serializer: triage_serializer, targets: @targets)
40
32
  end
41
33
 
42
34
  private
43
35
 
36
+ def validate_serializer!
37
+ return if SUPPORTED_SERIALIZERS.include?(@serializer)
38
+
39
+ raise ValidationError, "Unsupported serializer: #{@serializer}"
40
+ end
41
+
42
+ def validate_period!
43
+ @validators.since.validate!(since: @scope.since, relative_period: @scope.relative_period)
44
+ Normal::RelativePeriodValidator.validate!(relative_period: @scope.relative_period)
45
+ end
46
+
44
47
  def triage_serializer
45
48
  case @serializer
46
49
  when :json
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'triage/serializer'
4
+ require_relative 'triage/collaborator_set'
4
5
  require_relative 'triage/config'
5
6
  require_relative 'triage/checker'
6
7
 
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ChurnVsComplexity
4
+ ValidatorSet = Data.define(:complexity, :since) do
5
+ def initialize(complexity: ComplexityValidator, since: Normal::SinceValidator)
6
+ super
7
+ end
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ChurnVsComplexity
4
- VERSION = '1.8.0'
4
+ VERSION = '2.0.0'
5
5
  end
@@ -26,11 +26,14 @@ require_relative 'churn_vs_complexity/engine'
26
26
  require_relative 'churn_vs_complexity/concurrent_calculator'
27
27
  require_relative 'churn_vs_complexity/file_selector'
28
28
  require_relative 'churn_vs_complexity/complexity'
29
+ require_relative 'churn_vs_complexity/language_registry'
29
30
  require_relative 'churn_vs_complexity/churn'
30
31
  require_relative 'churn_vs_complexity/cli'
31
32
  require_relative 'churn_vs_complexity/git_date'
32
33
  require_relative 'churn_vs_complexity/complexity_validator'
33
34
  require_relative 'churn_vs_complexity/language_validator'
35
+ require_relative 'churn_vs_complexity/analysis_scope'
36
+ require_relative 'churn_vs_complexity/validator_set'
34
37
  require_relative 'churn_vs_complexity/git_strategy'
35
38
  require_relative 'churn_vs_complexity/gamma_score'
36
39
  require_relative 'churn_vs_complexity/risk_classifier'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: churn_vs_complexity
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik T. Madsen
@@ -15,33 +15,35 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: '4.8'
18
+ version: '4.10'
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: '4.8'
25
+ version: '4.10'
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: git
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: '2.1'
32
+ version: '6.0'
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '2.1'
39
+ version: '6.0'
40
40
  description: Correlates file churn (how often files change) with complexity scores
41
- to identify refactoring hotspots. Supports Ruby, JavaScript/TypeScript, Java, Python,
42
- Go, Kotlin, Rust, and Swift. Modes include hotspots ranking, triage assessment,
43
- CI quality gate, diff comparison, focus sessions, and timetravel history. Inspired
44
- by Michael Feathers' article "Getting Empirical about Refactoring".
41
+ to identify refactoring hotspots across 25 languages (Ruby via Flog plus 24 languages
42
+ via Lizard, including Java, JavaScript/TypeScript, Python, Go, Kotlin, Rust, Swift,
43
+ C/C++, C#, Objective-C, PHP, and Scala). Modes include hotspots ranking, triage
44
+ assessment, CI quality gate, diff comparison, focus sessions, delta analysis, and
45
+ timetravel history. Inspired by Michael Feathers' article "Getting Empirical about
46
+ Refactoring".
45
47
  email:
46
48
  - beatmadsen@gmail.com
47
49
  executables:
@@ -49,33 +51,19 @@ executables:
49
51
  extensions: []
50
52
  extra_rdoc_files: []
51
53
  files:
52
- - ".devcontainer/devcontainer.json"
53
- - ".rubocop.yml"
54
54
  - CHANGELOG.md
55
- - CLAUDE.md
56
- - Dockerfile
57
- - Dockerfile.dev
58
55
  - LICENSE.txt
59
56
  - README.md
60
- - Rakefile
61
- - TODO
62
57
  - bin/churn_vs_complexity
63
58
  - lib/churn_vs_complexity.rb
59
+ - lib/churn_vs_complexity/analysis_scope.rb
64
60
  - lib/churn_vs_complexity/churn.rb
65
61
  - lib/churn_vs_complexity/cli.rb
66
62
  - lib/churn_vs_complexity/cli/main.rb
67
63
  - lib/churn_vs_complexity/cli/parser.rb
68
64
  - lib/churn_vs_complexity/complexity.rb
69
- - lib/churn_vs_complexity/complexity/eslint_calculator.rb
70
65
  - lib/churn_vs_complexity/complexity/flog_calculator.rb
71
- - lib/churn_vs_complexity/complexity/go_calculator.rb
72
- - lib/churn_vs_complexity/complexity/kotlin_calculator.rb
73
- - lib/churn_vs_complexity/complexity/pmd.rb
74
- - lib/churn_vs_complexity/complexity/pmd/files_calculator.rb
75
- - lib/churn_vs_complexity/complexity/pmd/folder_calculator.rb
76
- - lib/churn_vs_complexity/complexity/python_calculator.rb
77
- - lib/churn_vs_complexity/complexity/rust_calculator.rb
78
- - lib/churn_vs_complexity/complexity/swift_calculator.rb
66
+ - lib/churn_vs_complexity/complexity/lizard_calculator.rb
79
67
  - lib/churn_vs_complexity/complexity_validator.rb
80
68
  - lib/churn_vs_complexity/concurrent_calculator.rb
81
69
  - lib/churn_vs_complexity/delta.rb
@@ -107,6 +95,7 @@ files:
107
95
  - lib/churn_vs_complexity/hotspots/checker.rb
108
96
  - lib/churn_vs_complexity/hotspots/config.rb
109
97
  - lib/churn_vs_complexity/hotspots/serializer.rb
98
+ - lib/churn_vs_complexity/language_registry.rb
110
99
  - lib/churn_vs_complexity/language_validator.rb
111
100
  - lib/churn_vs_complexity/normal.rb
112
101
  - lib/churn_vs_complexity/normal/config.rb
@@ -122,6 +111,7 @@ files:
122
111
  - lib/churn_vs_complexity/timetravel.rb
123
112
  - lib/churn_vs_complexity/timetravel/config.rb
124
113
  - lib/churn_vs_complexity/timetravel/factory.rb
114
+ - lib/churn_vs_complexity/timetravel/schedule.rb
125
115
  - lib/churn_vs_complexity/timetravel/serializer.rb
126
116
  - lib/churn_vs_complexity/timetravel/serializer/quality_calculator.rb
127
117
  - lib/churn_vs_complexity/timetravel/serializer/stats_calculator.rb
@@ -129,44 +119,13 @@ files:
129
119
  - lib/churn_vs_complexity/timetravel/worktree.rb
130
120
  - lib/churn_vs_complexity/triage.rb
131
121
  - lib/churn_vs_complexity/triage/checker.rb
122
+ - lib/churn_vs_complexity/triage/collaborator_set.rb
132
123
  - lib/churn_vs_complexity/triage/config.rb
133
124
  - lib/churn_vs_complexity/triage/serializer.rb
125
+ - lib/churn_vs_complexity/validator_set.rb
134
126
  - lib/churn_vs_complexity/version.rb
135
- - package-lock.json
136
- - tmp/eslint-support/complexity-calculator.js
137
- - tmp/eslint-support/package.json
138
- - tmp/pmd-support/ruleset.xml
139
127
  - tmp/template/graph.html
140
128
  - tmp/template/timetravel_graph.html
141
- - tmp/test-support/delta/ruby-summary.txt
142
- - tmp/test-support/delta/ruby.csv
143
- - tmp/test-support/go/main.go
144
- - tmp/test-support/go/utils.go
145
- - tmp/test-support/java/small-example/src/main/java/org/example/Main.java
146
- - tmp/test-support/java/small-example/src/main/java/org/example/spice/Checker.java
147
- - tmp/test-support/javascript/complex.js
148
- - tmp/test-support/javascript/moderate.js
149
- - tmp/test-support/javascript/simple.js
150
- - tmp/test-support/javascript/typescript-example.ts
151
- - tmp/test-support/kotlin/Main.kt
152
- - tmp/test-support/kotlin/Utils.kt
153
- - tmp/test-support/python/example.py
154
- - tmp/test-support/python/utils.py
155
- - tmp/test-support/rust/main.rs
156
- - tmp/test-support/rust/utils.rs
157
- - tmp/test-support/swift/main.swift
158
- - tmp/test-support/swift/utils.swift
159
- - tmp/test-support/txt/abc.txt
160
- - tmp/test-support/txt/d.txt
161
- - tmp/test-support/txt/ef.txt
162
- - tmp/test-support/txt/ghij.txt
163
- - tmp/test-support/txt/klm.txt
164
- - tmp/test-support/txt/nopq.txt
165
- - tmp/test-support/txt/r.txt
166
- - tmp/test-support/txt/st.txt
167
- - tmp/test-support/txt/uvx.txt
168
- - tmp/test-support/txt/yz.txt
169
- - tmp/timetravel/.keep
170
129
  homepage: https://github.com/beatmadsen/churn_vs_complexity
171
130
  licenses:
172
131
  - MIT
@@ -188,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
147
  - !ruby/object:Gem::Version
189
148
  version: '0'
190
149
  requirements: []
191
- rubygems_version: 4.0.6
150
+ rubygems_version: 4.0.20
192
151
  specification_version: 4
193
152
  summary: Analyse churn vs complexity to find refactoring hotspots, gate CI quality,
194
153
  triage risky files, and track codebase health over time.
@@ -1,26 +0,0 @@
1
- // For format details, see https://aka.ms/devcontainer.json. For config options, see the
2
- // README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile
3
- {
4
- "name": "Existing Dockerfile",
5
- "build": {
6
- // Sets the run context to one level up instead of the .devcontainer folder.
7
- "context": "..",
8
- // Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
9
- "dockerfile": "../Dockerfile.dev"
10
- }
11
-
12
- // Features to add to the dev container. More info: https://containers.dev/features.
13
- // "features": {},
14
-
15
- // Use 'forwardPorts' to make a list of ports inside the container available locally.
16
- // "forwardPorts": [],
17
-
18
- // Uncomment the next line to run commands after the container is created.
19
- // "postCreateCommand": "cat /etc/os-release",
20
-
21
- // Configure tool-specific properties.
22
- // "customizations": {},
23
-
24
- // Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root.
25
- // "remoteUser": "devcontainer"
26
- }
data/.rubocop.yml DELETED
@@ -1,25 +0,0 @@
1
- AllCops:
2
- TargetRubyVersion: 3.3
3
- NewCops: enable
4
-
5
- Layout/LineLength:
6
- Max: 120
7
-
8
-
9
- Style/Documentation:
10
- Enabled: false
11
-
12
- Style/ModuleFunction:
13
- Enabled: false
14
-
15
- Style/TrailingCommaInArrayLiteral:
16
- Enabled: true
17
- EnforcedStyleForMultiline: consistent_comma
18
-
19
- Style/TrailingCommaInHashLiteral:
20
- Enabled: true
21
- EnforcedStyleForMultiline: consistent_comma
22
-
23
- Style/TrailingCommaInArguments:
24
- Enabled: true
25
- EnforcedStyleForMultiline: consistent_comma
data/CLAUDE.md DELETED
@@ -1,60 +0,0 @@
1
- # CLAUDE.md
2
-
3
- This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
-
5
- ## Project Overview
6
-
7
- `churn_vs_complexity` is a Ruby gem that analyzes code quality by correlating file churn (how often files change) with complexity scores. It supports Ruby (via Flog), JavaScript/TypeScript (via ESLint), Java (via PMD), Python (via Radon), Go (via gocognit), Kotlin (via lizard), Rust (via lizard), and Swift (via lizard). Requires Ruby >= 3.3.
8
-
9
- ## Commands
10
-
11
- ```bash
12
- # Run tests (TLDR framework)
13
- bundle exec rake # default task runs tldr
14
- bundle exec tldr # direct
15
-
16
- # Run a single test file
17
- bundle exec tldr test/churn_vs_complexity/engine_test.rb
18
-
19
- # Run a single test by name
20
- bundle exec tldr --name test_something test/path/to_test.rb
21
-
22
- # Lint
23
- bundle exec rubocop
24
- bundle exec rubocop -a # auto-fix safe offenses
25
-
26
- # Build/install gem
27
- bundle exec rake build
28
- bundle exec rake install
29
- ```
30
-
31
- ## Architecture
32
-
33
- Three operating modes, each with its own Config/Checker/Serializer pipeline:
34
-
35
- - **Normal** (`Normal::Config` → `Engine` → `ConcurrentCalculator`): Analyzes a folder, computing churn + complexity per file. Outputs CSV, HTML graph, or text summary.
36
- - **Timetravel** (`Timetravel::Config` → `Traveller`): Samples quality scores across historical commits at N-day intervals. Uses forked processes with git worktrees for isolation.
37
- - **Delta** (`Delta::Config` → `MultiChecker` → `Checker`): Analyzes complexity of files changed in specific commits. Uses threads with git worktrees.
38
-
39
- Entry point: `CLI::run!` → `CLI::Parser` → `CLI::Main.run!` → mode-specific Config → checker.
40
-
41
- ### Key interfaces
42
-
43
- - **Complexity calculators**: `folder_based?`, `calculate(folder:)` or `calculate(files:)`
44
- - **Churn calculators**: `calculate(folder:, file:, since:)`, `date_of_latest_commit(folder:)`
45
- - **Serializers**: `serialize(result)`
46
- - **File selectors**: `select_files(folder)` → `{ included: [...], explicitly_excluded: [...] }`
47
-
48
- ### Concurrency model
49
-
50
- - Normal: threads (nprocessors) for per-file churn calculation
51
- - Timetravel: forked child processes with IO.pipe for IPC
52
- - Delta: threads (2x nprocessors) for concurrent commit analysis
53
-
54
- ## Code Style
55
-
56
- RuboCop config (`.rubocop.yml`):
57
- - Max line length: 120
58
- - Trailing commas enforced on multiline (arrays, hashes, arguments)
59
- - `NewCops: enable`
60
- - No class/module documentation required (`Style::Documentation` disabled)
data/Dockerfile DELETED
@@ -1,34 +0,0 @@
1
- # Create a build image with wget and unzip
2
- FROM ubuntu:latest as pmd_builder
3
- # Install wget and unzip
4
- RUN apt-get update && \
5
- apt-get install -y --no-install-recommends \
6
- wget unzip
7
-
8
- RUN wget https://github.com/pmd/pmd/releases/download/pmd_releases%2F7.0.0/pmd-dist-7.0.0-bin.zip --no-check-certificate
9
- RUN unzip pmd-dist-7.0.0-bin.zip
10
-
11
- FROM ruby:3.3-bullseye
12
- # Install git and java JDK
13
-
14
- RUN apt-get update; \
15
- apt-get install -y --no-install-recommends \
16
- git openjdk-17-jdk
17
-
18
- # copy PMD from build image
19
- COPY --from=pmd_builder /pmd-bin-7.0.0 /usr/local/bin/pmd-bin-7.0.0
20
- # make pmd available in the PATH
21
- RUN ln -s /usr/local/bin/pmd-bin-7.0.0/bin/pmd /usr/local/bin/pmd
22
-
23
- COPY *.gemspec Gemfile* /app/
24
- COPY lib /app/lib
25
-
26
- WORKDIR /app
27
-
28
- RUN bundle install
29
-
30
- COPY bin /app/bin
31
- COPY tmp/pmd-support /app/tmp/pmd-support
32
- COPY tmp/template /app/tmp/template
33
-
34
- CMD ["/bin/sh", "-c", "echo 'It works!'"]
data/Dockerfile.dev DELETED
@@ -1,27 +0,0 @@
1
- # Create a build image with wget and unzip
2
- FROM ubuntu:latest as pmd_builder
3
- # Install wget and unzip
4
- RUN apt-get update && \
5
- apt-get install -y --no-install-recommends \
6
- wget unzip
7
-
8
- RUN wget https://github.com/pmd/pmd/releases/download/pmd_releases%2F7.0.0/pmd-dist-7.0.0-bin.zip --no-check-certificate
9
- RUN unzip pmd-dist-7.0.0-bin.zip
10
-
11
- FROM ruby:3.3-bullseye
12
- # Install git and java JDK
13
-
14
- RUN apt-get update; \
15
- apt-get install -y --no-install-recommends \
16
- git openjdk-17-jdk
17
-
18
- # copy PMD from build image
19
- COPY --from=pmd_builder /pmd-bin-7.0.0 /usr/local/bin/pmd-bin-7.0.0
20
- # make pmd available in the PATH
21
- RUN ln -s /usr/local/bin/pmd-bin-7.0.0/bin/pmd /usr/local/bin/pmd
22
-
23
- COPY *.gemspec Gemfile* ./
24
- COPY lib/churn_vs_complexity/version.rb lib/churn_vs_complexity/version.rb
25
- RUN bundle install
26
-
27
- CMD ["/bin/sh", "-c", "echo 'It works!'"]
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler/gem_tasks'
4
- require 'tldr/rake'
5
-
6
- task default: :tldr
data/TODO DELETED
@@ -1,11 +0,0 @@
1
- TODO:
2
-
3
- - Move Timetravel calculations away from serializer
4
-
5
- - Database, where we can prepopulate the state of every file and every commit
6
- - Populate incrementally from each commit in log.
7
- - Only need to care about deltas between commits, and copy everything else from previous commit.
8
- - processed_commit table with sha and version of processing logic
9
- - Unit tests for simpler new classes
10
- - Integration test for Timetravel
11
- - Candlebars on mean dots in graph
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ChurnVsComplexity
4
- module Complexity
5
- module ESLintCalculator
6
- class << self
7
- def folder_based? = false
8
-
9
- def calculate(files:)
10
- dir_path = File.join(gem_root, 'tmp', 'eslint-support')
11
- script_path = File.join(dir_path, 'complexity-calculator.js')
12
- install_command = "npm install --prefix '#{dir_path}'"
13
- `#{install_command}`
14
-
15
- command = "node #{script_path} '#{files.to_json}'"
16
- complexity = `#{command}`
17
-
18
- raise Error, 'Failed to calculate complexity' if complexity.empty?
19
-
20
- all = JSON.parse(complexity)
21
- all.to_h do |abc|
22
- [abc['file'], abc['complexity']]
23
- end
24
- end
25
-
26
- def check_dependencies!
27
- `npm --version`
28
- rescue Errno::ENOENT
29
- raise Error, 'Needs node and npm installed'
30
- end
31
-
32
- private
33
-
34
- def gem_root
35
- File.expand_path('../../..', __dir__)
36
- end
37
- end
38
- end
39
- end
40
- end
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'json'
4
- require 'open3'
5
-
6
- module ChurnVsComplexity
7
- module Complexity
8
- module GoCalculator
9
- class << self
10
- attr_writer :command_runner
11
-
12
- def folder_based? = false
13
-
14
- def calculate(files:)
15
- json_output = run_gocognit(files)
16
- parse_gocognit_output(json_output, files:)
17
- end
18
-
19
- def parse_gocognit_output(json_output, files:)
20
- stats = JSON.parse(json_output) || []
21
- scores = stats.group_by { |s| s.dig('Pos', 'Filename') }
22
- .transform_values { |funcs| funcs.sum { |f| f['Complexity'] } }
23
- files.to_h { |file| [file, scores[file] || 0] }
24
- end
25
-
26
- def check_dependencies!
27
- command_runner.call('gocognit --help 2>&1')
28
- rescue Errno::ENOENT
29
- raise Error, 'Needs gocognit installed (go install github.com/uudashr/gocognit/cmd/gocognit@latest)'
30
- end
31
-
32
- private
33
-
34
- def command_runner
35
- @command_runner || Open3.method(:capture2)
36
- end
37
-
38
- def run_gocognit(files)
39
- files_arg = files.map { |f| "'#{f}'" }.join(' ')
40
- stdout, status = command_runner.call("gocognit -json #{files_arg}")
41
- raise Error, "gocognit failed (exit #{status.exitstatus}). Is it installed?" unless status.success?
42
-
43
- stdout
44
- end
45
- end
46
- end
47
- end
48
- end
@@ -1,54 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'open3'
4
-
5
- module ChurnVsComplexity
6
- module Complexity
7
- module KotlinCalculator
8
- class << self
9
- attr_writer :command_runner
10
-
11
- def folder_based? = false
12
-
13
- def calculate(files:)
14
- csv_output = run_lizard(files)
15
- parse_lizard_output(csv_output, files:)
16
- end
17
-
18
- # Lizard CSV format: NLOC,CCN,tokens,params,length,"loc","file","func","long_func",start,end
19
- LIZARD_LINE_PATTERN = /^\d+,(\d+),\d+,\d+,\d+,"[^"]*","([^"]*)"/.freeze
20
-
21
- def parse_lizard_output(csv_output, files:)
22
- scores = Hash.new(0)
23
- csv_output.each_line do |line|
24
- match = line.match(LIZARD_LINE_PATTERN)
25
- next unless match
26
-
27
- scores[match[2]] += match[1].to_i
28
- end
29
- files.to_h { |file| [file, scores[file] || 0] }
30
- end
31
-
32
- def check_dependencies!
33
- command_runner.call('lizard --version 2>&1')
34
- rescue Errno::ENOENT
35
- raise Error, 'Needs lizard installed (pip install lizard)'
36
- end
37
-
38
- private
39
-
40
- def command_runner
41
- @command_runner || Open3.method(:capture2)
42
- end
43
-
44
- def run_lizard(files)
45
- files_arg = files.map { |f| "'#{f}'" }.join(' ')
46
- stdout, status = command_runner.call("lizard --csv #{files_arg}")
47
- raise Error, "lizard failed (exit #{status.exitstatus}). Is it installed?" unless status.success?
48
-
49
- stdout
50
- end
51
- end
52
- end
53
- end
54
- end
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ChurnVsComplexity
4
- module Complexity
5
- module PMD
6
- class FilesCalculator
7
- def initialize(cache_components:)
8
- @cache_components = cache_components
9
- end
10
-
11
- def folder_based? = false
12
-
13
- def calculate(files:)
14
- return Parser.empty_result if files.empty?
15
-
16
- cache_path = PMD.resolve_cache_path(*@cache_components)
17
- files_arg = files.map { |file| "-d #{file}" }.join(' ')
18
- command = "pmd check #{files_arg} -R #{PMD.resolve_ruleset_path} -f json -t #{CONCURRENCY} --cache #{cache_path} 2>/dev/null"
19
- output = `#{command}`
20
-
21
- Parser.new.parse(output)
22
- end
23
- end
24
- end
25
- end
26
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ChurnVsComplexity
4
- module Complexity
5
- module PMD
6
- module FolderCalculator
7
- class << self
8
- def folder_based? = true
9
-
10
- def calculate(folder:)
11
- cache_path = PMD.resolve_cache_path(folder)
12
- output = `pmd check -d #{folder} -R #{PMD.resolve_ruleset_path} -f json -t #{CONCURRENCY} --cache #{cache_path} 2>/dev/null`
13
-
14
- Parser.new.parse(output)
15
- end
16
- end
17
- end
18
- end
19
- end
20
- end