debtective 0.2.3.4 → 0.2.3.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,68 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "debtective/todos/todo"
4
- require "debtective/find_end_of_statement"
5
-
6
- module Debtective
7
- module Todos
8
- # Build a Todo object given the pathname and the comment index
9
- class Build
10
- BEFORE_LINE_TODO_REGEX = /^\s*#\sTODO:\s/
11
- INLINE_TODO_REGEX = /\s*#\sTODO:\s/
12
- COMMENT_REGEX = /^\s*#/
13
-
14
- # @param pathname [Pathname]
15
- # @param index [Integer]
16
- def initialize(pathname:, index:)
17
- @pathname = pathname
18
- @index = index
19
- end
20
-
21
- # @return [Debtective::Todos::Todo]
22
- def call
23
- Debtective::Todos::Todo.new(
24
- pathname: @pathname,
25
- lines: lines,
26
- todo_boundaries: todo_boundaries,
27
- statement_boundaries: statement_boundaries
28
- )
29
- end
30
-
31
- private
32
-
33
- # @return [Array<String>]
34
- def lines
35
- @lines ||= @pathname.readlines
36
- end
37
-
38
- # @return [Range]
39
- def todo_boundaries
40
- @index..([@index, statement_boundaries.min - 1].max)
41
- end
42
-
43
- # range of the concerned code
44
- # @return [Range]
45
- def statement_boundaries
46
- @statement_boundaries ||=
47
- case lines[@index]
48
- when BEFORE_LINE_TODO_REGEX
49
- first_line_index = statement_start
50
- last_line_index = Debtective::FindEndOfStatement.new(lines: lines, first_line_index: first_line_index).call
51
- first_line_index..last_line_index
52
- when INLINE_TODO_REGEX
53
- @index..@index
54
- end
55
- end
56
-
57
- # start index of the concerned code (i.e. below the TODO comment)
58
- # @return [Integer]
59
- def statement_start
60
- lines.index.with_index do |line, i|
61
- i > @index &&
62
- !line.strip.empty? &&
63
- !line.match?(COMMENT_REGEX)
64
- end
65
- end
66
- end
67
- end
68
- end
@@ -1,88 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "debtective/export"
4
- require "debtective/print"
5
- require "debtective/todos/build"
6
- require "debtective/todos/todo"
7
-
8
- module Debtective
9
- module Todos
10
- # Export todos in a JSON file
11
- class Export < Debtective::Export
12
- private
13
-
14
- FILE_PATH = "todos.json"
15
-
16
- TABLE_COLUMNS = [
17
- Debtective::Print::Column.new(
18
- "location",
19
- "%-80.80s",
20
- -> { _1.location }
21
- ),
22
- Debtective::Print::Column.new(
23
- "author",
24
- "%-20.20s",
25
- -> { _1.commit.author.name || "?" }
26
- ),
27
- Debtective::Print::Column.new(
28
- "days",
29
- "%-12.12s",
30
- -> { _1.days || "?" }
31
- ),
32
- Debtective::Print::Column.new(
33
- "size",
34
- "%-12.12s",
35
- -> { _1.size }
36
- )
37
- ].freeze
38
-
39
- # @return [Array<Debtective::Todos::Todo>]
40
- def log_table
41
- Debtective::Print.new(
42
- columns: TABLE_COLUMNS,
43
- track: Debtective::Todos::Todo,
44
- user_name: @user_name
45
- ).call { find_elements }
46
- end
47
-
48
- # @return [Array<Debtective::Todos::Todo>]
49
- def find_elements
50
- pathnames.flat_map do |pathname|
51
- pathname.readlines.filter_map.with_index do |line, index|
52
- next unless line =~ /#\sTODO:/
53
-
54
- Debtective::Todos::Build.new(
55
- pathname: pathname,
56
- index: index
57
- ).call
58
- end
59
- end
60
- end
61
-
62
- # @return [void]
63
- def log_counts
64
- puts "total: #{@elements.count}"
65
- puts "extended lines count: #{extended_count}"
66
- puts "combined lines count: #{combined_count}"
67
- end
68
-
69
- # @return [Integer]
70
- def extended_count
71
- @elements.sum(&:size)
72
- end
73
-
74
- # @return [Integer]
75
- def combined_count
76
- @elements
77
- .group_by(&:pathname)
78
- .values
79
- .sum do |pathname_todos|
80
- pathname_todos
81
- .map { _1.statement_boundaries.to_a }
82
- .reduce(:|)
83
- .length
84
- end
85
- end
86
- end
87
- end
88
- end
@@ -1,68 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "debtective/find_commit"
4
-
5
- module Debtective
6
- module Todos
7
- # Hold todo information
8
- class Todo
9
- attr_accessor :pathname, :todo_boundaries, :statement_boundaries
10
-
11
- # @param pathname [Pathname]
12
- # @param lines [Array<String>]
13
- # @param todo_boundaries [Range]
14
- # @param statement_boundaries [Range]
15
- def initialize(pathname:, lines:, todo_boundaries:, statement_boundaries:)
16
- @pathname = pathname
17
- @lines = lines
18
- @todo_boundaries = todo_boundaries
19
- @statement_boundaries = statement_boundaries
20
- end
21
-
22
- # location in the codebase
23
- # @return [String]
24
- def location
25
- "#{@pathname}:#{@todo_boundaries.min + 1}"
26
- end
27
-
28
- # size of the todo code
29
- # @return [Integer]
30
- def size
31
- @statement_boundaries.size
32
- end
33
-
34
- # return commit that introduced the todo
35
- # @return [Debtective::FindCommit::Commit]
36
- def commit
37
- @commit ||=
38
- Debtective::FindCommit.new(
39
- pathname: @pathname,
40
- code_line: @lines[@todo_boundaries.min]
41
- ).call
42
- end
43
-
44
- # @return [Integer]
45
- def days
46
- return if commit.time.nil?
47
-
48
- ((Time.now - commit.time) / (24 * 60 * 60)).round
49
- end
50
-
51
- # @return [Hash]
52
- def to_h
53
- {
54
- pathname: @pathname,
55
- location: location,
56
- todo_boundaries: todo_boundaries.minmax,
57
- statement_boundaries: statement_boundaries.minmax,
58
- size: size,
59
- commit: {
60
- sha: commit.sha,
61
- author: commit.author.to_h,
62
- time: commit.time
63
- }
64
- }
65
- end
66
- end
67
- end
68
- end