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.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +56 -0
  3. data/README.md +46 -23
  4. data/lib/churn_vs_complexity/analysis_scope.rb +20 -0
  5. data/lib/churn_vs_complexity/churn.rb +27 -9
  6. data/lib/churn_vs_complexity/cli/main.rb +58 -19
  7. data/lib/churn_vs_complexity/cli/parser.rb +85 -121
  8. data/lib/churn_vs_complexity/cli.rb +2 -3
  9. data/lib/churn_vs_complexity/complexity/flog_calculator.rb +0 -3
  10. data/lib/churn_vs_complexity/complexity/lizard_calculator.rb +64 -0
  11. data/lib/churn_vs_complexity/complexity.rb +1 -7
  12. data/lib/churn_vs_complexity/complexity_validator.rb +1 -16
  13. data/lib/churn_vs_complexity/concurrent_calculator.rb +20 -23
  14. data/lib/churn_vs_complexity/delta/checker.rb +35 -21
  15. data/lib/churn_vs_complexity/delta/commit_hydrator.rb +1 -1
  16. data/lib/churn_vs_complexity/delta/complexity_annotator.rb +23 -5
  17. data/lib/churn_vs_complexity/delta/config.rb +15 -16
  18. data/lib/churn_vs_complexity/delta/factory.rb +2 -2
  19. data/lib/churn_vs_complexity/delta/multi_checker.rb +24 -25
  20. data/lib/churn_vs_complexity/delta/serializer.rb +6 -4
  21. data/lib/churn_vs_complexity/delta.rb +11 -49
  22. data/lib/churn_vs_complexity/diff/checker.rb +10 -3
  23. data/lib/churn_vs_complexity/diff/config.rb +29 -20
  24. data/lib/churn_vs_complexity/file_selector.rb +63 -114
  25. data/lib/churn_vs_complexity/focus/config.rb +42 -32
  26. data/lib/churn_vs_complexity/focus/serializer.rb +17 -4
  27. data/lib/churn_vs_complexity/gate/config.rb +28 -25
  28. data/lib/churn_vs_complexity/git_strategy.rb +17 -12
  29. data/lib/churn_vs_complexity/hotspots/config.rb +29 -25
  30. data/lib/churn_vs_complexity/language_registry.rb +108 -0
  31. data/lib/churn_vs_complexity/language_validator.rb +1 -3
  32. data/lib/churn_vs_complexity/normal/config.rb +31 -100
  33. data/lib/churn_vs_complexity/normal/serializer/graph.rb +3 -2
  34. data/lib/churn_vs_complexity/normal/serializer/summary.rb +18 -14
  35. data/lib/churn_vs_complexity/normal/serializer/summary_hash.rb +15 -13
  36. data/lib/churn_vs_complexity/normal/serializer.rb +2 -1
  37. data/lib/churn_vs_complexity/normal.rb +17 -13
  38. data/lib/churn_vs_complexity/risk_classifier.rb +3 -19
  39. data/lib/churn_vs_complexity/timetravel/config.rb +34 -47
  40. data/lib/churn_vs_complexity/timetravel/schedule.rb +15 -0
  41. data/lib/churn_vs_complexity/timetravel/serializer/stats_calculator.rb +36 -32
  42. data/lib/churn_vs_complexity/timetravel/serializer.rb +16 -24
  43. data/lib/churn_vs_complexity/timetravel/traveller.rb +44 -15
  44. data/lib/churn_vs_complexity/timetravel.rb +36 -14
  45. data/lib/churn_vs_complexity/triage/checker.rb +24 -28
  46. data/lib/churn_vs_complexity/triage/collaborator_set.rb +11 -0
  47. data/lib/churn_vs_complexity/triage/config.rb +29 -26
  48. data/lib/churn_vs_complexity/triage.rb +1 -0
  49. data/lib/churn_vs_complexity/validator_set.rb +9 -0
  50. data/lib/churn_vs_complexity/version.rb +1 -1
  51. data/lib/churn_vs_complexity.rb +3 -0
  52. metadata +18 -22
  53. data/lib/churn_vs_complexity/complexity/eslint_calculator.rb +0 -40
  54. data/lib/churn_vs_complexity/complexity/go_calculator.rb +0 -48
  55. data/lib/churn_vs_complexity/complexity/kotlin_calculator.rb +0 -54
  56. data/lib/churn_vs_complexity/complexity/pmd/files_calculator.rb +0 -26
  57. data/lib/churn_vs_complexity/complexity/pmd/folder_calculator.rb +0 -20
  58. data/lib/churn_vs_complexity/complexity/pmd.rb +0 -54
  59. data/lib/churn_vs_complexity/complexity/python_calculator.rb +0 -50
  60. data/lib/churn_vs_complexity/complexity/rust_calculator.rb +0 -54
  61. data/lib/churn_vs_complexity/complexity/swift_calculator.rb +0 -54
  62. data/tmp/eslint-support/complexity-calculator.js +0 -51
  63. data/tmp/eslint-support/package.json +0 -11
  64. data/tmp/pmd-support/ruleset.xml +0 -21
@@ -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+,"[^"]*","([^"]*)"/
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
@@ -1,54 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'pmd/folder_calculator'
4
- require_relative 'pmd/files_calculator'
5
-
6
- module ChurnVsComplexity
7
- module Complexity
8
- module PMD
9
- CONCURRENCY = Etc.nprocessors
10
-
11
- class << self
12
- def resolve_ruleset_path
13
- ruleset_path = File.join(gem_root, 'tmp', 'pmd-support', 'ruleset.xml')
14
- raise "ruleset.xml not found in #{ruleset_path}" unless File.exist?(ruleset_path)
15
-
16
- ruleset_path
17
- end
18
-
19
- def resolve_cache_path(*components)
20
- File.join(ChurnVsComplexity.tmp_dir_path(*components), 'pmd', 'pmd-cache')
21
- end
22
-
23
- def check_dependencies!
24
- `pmd --help`
25
- rescue StandardError
26
- raise Error, 'Could not execute PMD using command pmd'
27
- end
28
-
29
- private
30
-
31
- def gem_root = ROOT_PATH
32
- end
33
-
34
- class Parser
35
- def self.empty_result = {}
36
-
37
- def parse(output)
38
- doc = JSON.parse(output)
39
- doc['files'].each_with_object({}) do |file, result|
40
- result[file['filename']] =
41
- file['violations'].sum { |violation| extract_complexity(violation) }
42
- end
43
- end
44
-
45
- private
46
-
47
- def extract_complexity(violation)
48
- # Find text 'total cyclomatic complexity of <number>'
49
- violation['description'].match(/total cyclomatic complexity of (\d+)/)[1].to_i
50
- end
51
- end
52
- end
53
- end
54
- end
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'json'
4
- require 'open3'
5
-
6
- module ChurnVsComplexity
7
- module Complexity
8
- module PythonCalculator
9
- class << self
10
- attr_writer :command_runner
11
-
12
- def folder_based? = false
13
-
14
- def calculate(files:)
15
- json_output = run_radon(files)
16
- parse_radon_output(json_output, files:)
17
- end
18
-
19
- def parse_radon_output(json_output, files:)
20
- data = JSON.parse(json_output)
21
- files.to_h do |file|
22
- blocks = data[file] || []
23
- total = blocks.sum { |b| b['complexity'] }
24
- [file, total]
25
- end
26
- end
27
-
28
- def check_dependencies!
29
- command_runner.call('radon --version 2>&1')
30
- rescue Errno::ENOENT
31
- raise Error, 'Needs radon installed (pip install radon)'
32
- end
33
-
34
- private
35
-
36
- def command_runner
37
- @command_runner || Open3.method(:capture2)
38
- end
39
-
40
- def run_radon(files)
41
- files_arg = files.map { |f| "'#{f}'" }.join(' ')
42
- stdout, status = command_runner.call("radon cc #{files_arg} -j")
43
- raise Error, "radon failed (exit #{status.exitstatus}). Is it installed?" unless status.success?
44
-
45
- stdout
46
- end
47
- end
48
- end
49
- end
50
- end
@@ -1,54 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'open3'
4
-
5
- module ChurnVsComplexity
6
- module Complexity
7
- module RustCalculator
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+,"[^"]*","([^"]*)"/
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,54 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'open3'
4
-
5
- module ChurnVsComplexity
6
- module Complexity
7
- module SwiftCalculator
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+,"[^"]*","([^"]*)"/
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,51 +0,0 @@
1
- import { ESLint } from 'eslint';
2
-
3
- import eslint from '@eslint/js';
4
- import tseslint from 'typescript-eslint';
5
-
6
- async function analyzeComplexity(files) {
7
- const overrideConfig = tseslint.config(
8
- eslint.configs.recommended,
9
- ...tseslint.configs.recommended,
10
- {
11
- rules: {
12
- 'complexity': ['warn', 0],
13
- },
14
-
15
- }
16
- );
17
-
18
- const linter = new ESLint({
19
- overrideConfigFile: true,
20
- overrideConfig,
21
- cwd: '/',
22
- });
23
-
24
- try {
25
- const results = await linter.lintFiles(files);
26
- const complexityResults = results.map(result => {
27
- const messages = result.messages.filter(msg => msg.ruleId === 'complexity');
28
- const complexity = messages.reduce((sum, msg) => {
29
- const complexityValue = parseInt(msg.message.match(/\d+/)[0], 10);
30
- return sum + complexityValue;
31
- }, 0);
32
-
33
- if (complexity === 0) {
34
- console.error("File has no complexity", result);
35
- }
36
-
37
- return {
38
- file: result.filePath,
39
- complexity,
40
- };
41
- });
42
-
43
- console.log(JSON.stringify(complexityResults));
44
- } catch (error) {
45
- console.error('Error during analysis:', error);
46
- process.exit(1);
47
- }
48
- }
49
-
50
- const files = JSON.parse(process.argv[2]);
51
- analyzeComplexity(files);
@@ -1,11 +0,0 @@
1
- {
2
- "type": "module",
3
- "dependencies": {
4
- "eslint-plugin-complexity": "^1.0.2",
5
- "@eslint/js": "^9.11.1",
6
- "@types/eslint__js": "^8.42.3",
7
- "eslint": "^9.11.1",
8
- "typescript": "^5.6.2",
9
- "typescript-eslint": "^8.7.0"
10
- }
11
- }
@@ -1,21 +0,0 @@
1
- <?xml version="1.0"?>
2
-
3
- <ruleset name="Rules for churn vs complexity"
4
- xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
5
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6
- xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
7
-
8
- <description>
9
- Find cyclomatic complexity in java files
10
- </description>
11
-
12
- <rule ref="category/java/design.xml/CyclomaticComplexity">
13
- <properties>
14
- <property name="classReportLevel" value="1"/>
15
- <!-- We only want one report pr class -->
16
- <property name="methodReportLevel" value="1000000"/>
17
- <property name="cycloOptions" value=""/>
18
- </properties>
19
- </rule>
20
-
21
- </ruleset>