churn_vs_complexity 1.6.1 → 1.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6dfa844a5bcd2fe116001652410d39f802c64623be5ec588afcc6ed331b9aac9
4
- data.tar.gz: 42c5d56c7b4c6640bd4040f7f5d8b35ea6acac0aae9285be4c6cb1aaf860f0fb
3
+ metadata.gz: dbfecd03ad25cb8f79ae5b52564f591b122eab2b8ee13e3fe80d1d33883e2747
4
+ data.tar.gz: 4ba6ffb8794bb11c9e87103f26b481b9b6bb29230eb1c55fa7fff7c46aaa0687
5
5
  SHA512:
6
- metadata.gz: 0ad833af0897a784aa0499d277884e011e9be71142d343c441ef0a12b1185c27f18c09b0b7780a3f8493e3ef0399faff5f97b252f51fb4713f3dd98d11b666a7
7
- data.tar.gz: 19cf09a9777aa06a4772fae21fee5a4043ba034efde9d2af13618461b20a602270879438c4aa626463c3ea14054bf1dc8a7b9a25cde09c9636439d9d567a30f3
6
+ metadata.gz: c7463ac718037f9f8d13ba08d1c39b775557246f85bd3e29852ee573b1af55625026e792d239e3d38df118923f80b68d75243508f5dd98b6739bd1b80408fe20
7
+ data.tar.gz: 35358bac1704bc9bca9cb9204d053c3484d9aa5e4d1e378b0feb48e2236f014354494b8ddcd36d12d127865361add543f511e514bfa412d01f7b34f038fb1042
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## [1.7.0] - 2026-04-05
2
+
3
+ ### Added
4
+ - Kotlin support for complexity calculation (via [lizard](https://github.com/terryyin/lizard), install with `pip install lizard`)
5
+
6
+ ## [1.6.2] - 2026-02-19
7
+
8
+ ### Changed
9
+ - Risk classification in triage, hotspots, and focus modes is now language-aware
10
+ - Ruby thresholds raised to low=30/high=70 (Flog scores 3-7x higher than cyclomatic tools)
11
+ - Go thresholds raised to low=15/high=40 (cognitive complexity penalises nesting)
12
+ - Java, Python, and JavaScript/TypeScript thresholds unchanged (low=10/high=25)
13
+
1
14
  ## [1.6.1] - 2026-02-19
2
15
 
3
16
  ### Changed
data/CLAUDE.md CHANGED
@@ -4,7 +4,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
4
4
 
5
5
  ## Project Overview
6
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), and Java (via PMD). Requires Ruby >= 3.3.
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), and Kotlin (via lizard). Requires Ruby >= 3.3.
8
8
 
9
9
  ## Commands
10
10
 
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # ChurnVsComplexity
4
4
 
5
- Correlates file churn (how often files change) with complexity scores to identify refactoring hotspots and track codebase health over time. Supports Ruby, JavaScript/TypeScript, Java, Python, and Go.
5
+ Correlates file churn (how often files change) with complexity scores to identify refactoring hotspots and track codebase health over time. Supports Ruby, JavaScript/TypeScript, Java, Python, Go, and Kotlin.
6
6
 
7
7
  Modes include hotspots ranking, triage assessment, CI quality gate, diff comparison, focus sessions, and timetravel history.
8
8
 
@@ -33,6 +33,7 @@ External tool dependencies per language:
33
33
  - **JavaScript/TypeScript**: Requires [Node.js](https://nodejs.org) (uses ESLint internally).
34
34
  - **Python**: Requires [Radon](https://radon.readthedocs.io) on the search path as `radon`. Install with `pip install radon`.
35
35
  - **Go**: Requires [gocyclo](https://github.com/fzipp/gocyclo) on the search path. Install with `go install github.com/fzipp/gocyclo/cmd/gocyclo@latest`.
36
+ - **Kotlin**: Requires [lizard](https://github.com/terryyin/lizard) on the search path. Install with `pip install lizard`.
36
37
 
37
38
  ## Usage
38
39
 
@@ -48,6 +49,7 @@ Languages:
48
49
  Check complexity of javascript and typescript files
49
50
  --python Check complexity of python files
50
51
  --go Check complexity of go files
52
+ --kotlin Check complexity of kotlin files
51
53
 
52
54
  Modes (mutually exclusive):
53
55
  --timetravel N Calculate summary for all commits at intervals of N days throughout project history or from the date specified with --since
@@ -121,6 +123,9 @@ churn_vs_complexity --java -m --since 2019-03-01 --timetravel 30 --graph my_java
121
123
 
122
124
  # Analyse complexity of specific commits
123
125
  churn_vs_complexity --js --delta HEAD --summary my_js_project
126
+
127
+ # Kotlin project hotspots
128
+ churn_vs_complexity --kotlin --hotspots my_kotlin_project
124
129
  ```
125
130
 
126
131
  ## Development
@@ -34,6 +34,10 @@ module ChurnVsComplexity
34
34
  options[:language] = :go
35
35
  end
36
36
 
37
+ opts.on('--kotlin', 'Check complexity of kotlin files') do
38
+ options[:language] = :kotlin
39
+ end
40
+
37
41
  opts.separator ''
38
42
  opts.separator 'Modes (mutually exclusive):'
39
43
 
@@ -0,0 +1,54 @@
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
@@ -5,6 +5,7 @@ require_relative 'complexity/flog_calculator'
5
5
  require_relative 'complexity/eslint_calculator'
6
6
  require_relative 'complexity/python_calculator'
7
7
  require_relative 'complexity/go_calculator'
8
+ require_relative 'complexity/kotlin_calculator'
8
9
 
9
10
  module ChurnVsComplexity
10
11
  module Complexity
@@ -12,6 +12,8 @@ module ChurnVsComplexity
12
12
  Complexity::PythonCalculator.check_dependencies!
13
13
  when :go
14
14
  Complexity::GoCalculator.check_dependencies!
15
+ when :kotlin
16
+ Complexity::KotlinCalculator.check_dependencies!
15
17
  end
16
18
  end
17
19
  end
@@ -38,6 +38,8 @@ module ChurnVsComplexity
38
38
  FileSelector::Python.predefined(included:, excluded:)
39
39
  when :go
40
40
  FileSelector::Go.predefined(included:, excluded:)
41
+ when :kotlin
42
+ FileSelector::Kotlin.predefined(included:, excluded:)
41
43
  end
42
44
  end
43
45
 
@@ -53,6 +55,8 @@ module ChurnVsComplexity
53
55
  Complexity::PythonCalculator
54
56
  when :go
55
57
  Complexity::GoCalculator
58
+ when :kotlin
59
+ Complexity::KotlinCalculator
56
60
  end
57
61
  end
58
62
  end
@@ -14,6 +14,8 @@ module ChurnVsComplexity
14
14
  ['.py']
15
15
  when :go
16
16
  ['.go']
17
+ when :kotlin
18
+ ['.kt', '.kts']
17
19
  else
18
20
  raise Error, "Unsupported language: #{language}"
19
21
  end
@@ -130,5 +132,15 @@ module ChurnVsComplexity
130
132
  Predefined.new(included:, extensions: FileSelector.extensions(:go), excluded:)
131
133
  end
132
134
  end
135
+
136
+ module Kotlin
137
+ def self.excluding(excluded)
138
+ Excluding.new(FileSelector.extensions(:kotlin), excluded)
139
+ end
140
+
141
+ def self.predefined(included:, excluded:)
142
+ Predefined.new(included:, extensions: FileSelector.extensions(:kotlin), excluded:)
143
+ end
144
+ end
133
145
  end
134
146
  end
@@ -5,11 +5,12 @@ require 'json'
5
5
  module ChurnVsComplexity
6
6
  module Focus
7
7
  class Checker
8
- def initialize(engine:, subcommand:, serializer:, baseline_path:)
8
+ def initialize(engine:, subcommand:, serializer:, baseline_path:, language: nil)
9
9
  @engine = engine
10
10
  @subcommand = subcommand
11
11
  @serializer = serializer
12
12
  @baseline_path = baseline_path
13
+ @language = language
13
14
  end
14
15
 
15
16
  def check(folder:)
@@ -24,7 +25,7 @@ module ChurnVsComplexity
24
25
 
25
26
  def run_start(folder, baseline_path)
26
27
  raw_result = @engine.check(folder:)
27
- entries = RiskAnnotator.annotate(raw_result[:values_by_file])
28
+ entries = RiskAnnotator.annotate(raw_result[:values_by_file], language: @language)
28
29
 
29
30
  baseline = {
30
31
  timestamp: Time.now.utc.iso8601,
@@ -37,7 +38,7 @@ module ChurnVsComplexity
37
38
 
38
39
  def run_end(folder, baseline_path)
39
40
  raw_result = @engine.check(folder:)
40
- current_entries = RiskAnnotator.annotate(raw_result[:values_by_file])
41
+ current_entries = RiskAnnotator.annotate(raw_result[:values_by_file], language: @language)
41
42
 
42
43
  baseline = load_baseline(baseline_path)
43
44
  @serializer.serialize(baseline:, current: current_entries)
@@ -40,6 +40,7 @@ module ChurnVsComplexity
40
40
  subcommand: @subcommand,
41
41
  serializer: focus_serializer,
42
42
  baseline_path: @baseline_path,
43
+ language: @language,
43
44
  )
44
45
  end
45
46
 
@@ -3,14 +3,15 @@
3
3
  module ChurnVsComplexity
4
4
  module Hotspots
5
5
  class Checker
6
- def initialize(engine:, serializer:)
6
+ def initialize(engine:, serializer:, language: nil)
7
7
  @engine = engine
8
8
  @serializer = serializer
9
+ @language = language
9
10
  end
10
11
 
11
12
  def check(folder:)
12
13
  raw_result = @engine.check(folder:)
13
- @serializer.serialize(raw_result)
14
+ @serializer.serialize(raw_result.merge(language: @language))
14
15
  end
15
16
  end
16
17
  end
@@ -34,7 +34,7 @@ module ChurnVsComplexity
34
34
  since: @since,
35
35
  excluded: @excluded,
36
36
  )
37
- Checker.new(engine: normal_config.checker, serializer: hotspots_serializer)
37
+ Checker.new(engine: normal_config.checker, serializer: hotspots_serializer, language: @language)
38
38
  end
39
39
 
40
40
  private
@@ -7,7 +7,7 @@ module ChurnVsComplexity
7
7
  module Serializer
8
8
  module Json
9
9
  def self.serialize(result)
10
- entries = RiskAnnotator.annotate(result[:values_by_file])
10
+ entries = RiskAnnotator.annotate(result[:values_by_file], language: result[:language])
11
11
  entries.sort_by! { |e| -e[:gamma_score] }
12
12
 
13
13
  JSON.generate({ generated: Time.now.utc.iso8601, files: entries,
@@ -23,7 +23,7 @@ module ChurnVsComplexity
23
23
  }.freeze
24
24
 
25
25
  def self.serialize(result)
26
- entries = RiskAnnotator.annotate(result[:values_by_file])
26
+ entries = RiskAnnotator.annotate(result[:values_by_file], language: result[:language])
27
27
  entries.sort_by! { |e| -e[:gamma_score] }
28
28
  grouped = entries.group_by { |e| e[:risk] }
29
29
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module ChurnVsComplexity
4
4
  module LanguageValidator
5
- SUPPORTED = %i[java ruby javascript python go].freeze
5
+ SUPPORTED = %i[java ruby javascript python go kotlin].freeze
6
6
 
7
7
  def self.validate!(language)
8
8
  raise ValidationError, "Unsupported language: #{language}" unless SUPPORTED.include?(language)
@@ -75,6 +75,14 @@ module ChurnVsComplexity
75
75
  serializer:,
76
76
  since: @since || @relative_period,
77
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
+ )
78
86
  end
79
87
  end
80
88
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module ChurnVsComplexity
4
4
  module RiskAnnotator
5
- def self.annotate(values_by_file, classifier: RiskClassifier.new)
5
+ def self.annotate(values_by_file, language: nil, classifier: RiskClassifier.new(language: language))
6
6
  values_by_file.map { |file, values| build_entry(file, values, classifier) }
7
7
  end
8
8
 
@@ -1,19 +1,44 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ChurnVsComplexity
4
+ # Classifies files into low/medium/high risk based on gamma score
5
+ # (harmonic mean of churn and complexity).
6
+ #
7
+ # IMPORTANT: Complexity scores are NOT comparable across languages.
8
+ # Each language uses a different tool with a different numeric scale.
9
+ # All tools sum per-function scores across the file, but the magnitude differs:
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
+ #
19
+ # The DEFAULT_LOW and DEFAULT_HIGH thresholds below are rough midpoints
20
+ # suitable for Java/Python/JS. They are too aggressive for Ruby (Flog
21
+ # scores 3-7x higher) and Go (cognitive complexity penalises nesting).
22
+ # Use the constructor to pass language-appropriate thresholds.
4
23
  class RiskClassifier
5
24
  DEFAULT_LOW = 10
6
25
  DEFAULT_HIGH = 25
7
26
 
27
+ LANGUAGE_DEFAULTS = {
28
+ ruby: { low: 30, high: 70 },
29
+ go: { low: 15, high: 40 },
30
+ }.freeze
31
+
8
32
  RECOMMENDATIONS = {
9
33
  'low' => 'Safe for quick changes.',
10
34
  'medium' => 'Exercise judgement; consider tests for non-trivial changes.',
11
35
  'high' => 'Write tests before modifying. Consider multi-agent review.',
12
36
  }.freeze
13
37
 
14
- def initialize(low: DEFAULT_LOW, high: DEFAULT_HIGH)
15
- @low = low
16
- @high = high
38
+ def initialize(low: DEFAULT_LOW, high: DEFAULT_HIGH, language: nil)
39
+ defaults = LANGUAGE_DEFAULTS.fetch(language, {})
40
+ @low = defaults.fetch(:low, low)
41
+ @high = defaults.fetch(:high, high)
17
42
  end
18
43
 
19
44
  def classify(gamma_score:)
@@ -16,7 +16,7 @@ module ChurnVsComplexity
16
16
  folder = folder || dirs.first || '.'
17
17
  engine = build_engine(files, folder)
18
18
  raw_result = engine.check(folder:)
19
- @serializer.serialize(raw_result)
19
+ @serializer.serialize(raw_result.merge(language: @language))
20
20
  end
21
21
 
22
22
  private
@@ -7,7 +7,7 @@ module ChurnVsComplexity
7
7
  module Serializer
8
8
  module Json
9
9
  def self.serialize(result)
10
- entries = RiskAnnotator.annotate(result[:values_by_file])
10
+ entries = RiskAnnotator.annotate(result[:values_by_file], language: result[:language])
11
11
  JSON.generate({ files: entries, summary: RiskAnnotator.risk_summary(entries) })
12
12
  end
13
13
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ChurnVsComplexity
4
- VERSION = '1.6.1'
4
+ VERSION = '1.7.0'
5
5
  end
@@ -0,0 +1,7 @@
1
+ fun main() {
2
+ println("Hello, world!")
3
+ }
4
+
5
+ fun add(a: Int, b: Int): Int {
6
+ return a + b
7
+ }
@@ -0,0 +1,11 @@
1
+ fun calculateSum(numbers: List<Int>): Int {
2
+ var total = 0
3
+ for (n in numbers) {
4
+ total += n
5
+ }
6
+ return total
7
+ }
8
+
9
+ fun isEven(n: Int): Boolean {
10
+ return n % 2 == 0
11
+ }
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.6.1
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik T. Madsen
@@ -39,8 +39,8 @@ dependencies:
39
39
  version: '2.1'
40
40
  description: Correlates file churn (how often files change) with complexity scores
41
41
  to identify refactoring hotspots. Supports Ruby, JavaScript/TypeScript, Java, Python,
42
- and Go. Modes include hotspots ranking, triage assessment, CI quality gate, diff
43
- comparison, focus sessions, and timetravel history. Inspired by Michael Feathers'
42
+ Go, and Kotlin. Modes include hotspots ranking, triage assessment, CI quality gate,
43
+ diff comparison, focus sessions, and timetravel history. Inspired by Michael Feathers'
44
44
  article "Getting Empirical about Refactoring".
45
45
  email:
46
46
  - beatmadsen@gmail.com
@@ -69,6 +69,7 @@ files:
69
69
  - lib/churn_vs_complexity/complexity/eslint_calculator.rb
70
70
  - lib/churn_vs_complexity/complexity/flog_calculator.rb
71
71
  - lib/churn_vs_complexity/complexity/go_calculator.rb
72
+ - lib/churn_vs_complexity/complexity/kotlin_calculator.rb
72
73
  - lib/churn_vs_complexity/complexity/pmd.rb
73
74
  - lib/churn_vs_complexity/complexity/pmd/files_calculator.rb
74
75
  - lib/churn_vs_complexity/complexity/pmd/folder_calculator.rb
@@ -145,6 +146,8 @@ files:
145
146
  - tmp/test-support/javascript/moderate.js
146
147
  - tmp/test-support/javascript/simple.js
147
148
  - tmp/test-support/javascript/typescript-example.ts
149
+ - tmp/test-support/kotlin/Main.kt
150
+ - tmp/test-support/kotlin/Utils.kt
148
151
  - tmp/test-support/python/example.py
149
152
  - tmp/test-support/python/utils.py
150
153
  - tmp/test-support/txt/abc.txt
@@ -179,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
182
  - !ruby/object:Gem::Version
180
183
  version: '0'
181
184
  requirements: []
182
- rubygems_version: 3.6.7
185
+ rubygems_version: 4.0.6
183
186
  specification_version: 4
184
187
  summary: Analyse churn vs complexity to find refactoring hotspots, gate CI quality,
185
188
  triage risky files, and track codebase health over time.