smart_todo 1.6.0 → 1.8.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.
@@ -1,124 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "ripper"
4
-
5
- module SmartTodo
6
- module Parser
7
- # A MethodNode represent an event associated to a TODO.
8
- class MethodNode
9
- attr_reader :method_name, :arguments
10
-
11
- # @param method_name [Symbol]
12
- # @param arguments [Array<String>]
13
- def initialize(method_name, arguments)
14
- @arguments = arguments
15
- @method_name = method_name
16
- end
17
- end
18
-
19
- # This class is used to parse the ruby TODO() comment.
20
- class MetadataParser < Ripper
21
- class << self
22
- # @param source [String] the actual Ruby code
23
- def parse(source)
24
- sexp = new(source).parse
25
- Visitor.new.tap { |v| v.process(sexp) }
26
- end
27
- end
28
-
29
- # @return [Array] an Array of Array
30
- # the first element from each inner array is a token
31
- def on_stmts_add(_, data)
32
- data
33
- end
34
-
35
- # @param method [String] the name of the method
36
- # when the parser hits one.
37
- # @param args [Array]
38
- # @return [Array, MethodNode]
39
- def on_method_add_arg(method, args)
40
- if method.start_with?(/TODO\W?/)
41
- args
42
- else
43
- MethodNode.new(method, args)
44
- end
45
- end
46
-
47
- # @param list [nil, Array]
48
- # @param arg [String]
49
- # @return [Array]
50
- def on_args_add(list, arg)
51
- Array(list) << arg
52
- end
53
-
54
- # @param string_content [String]
55
- # @return [String]
56
- def on_string_add(_, string_content)
57
- string_content
58
- end
59
-
60
- # @param key [String]
61
- # @param value [String, Integer, MethodNode]
62
- def on_assoc_new(key, value)
63
- key.tr!(":", "")
64
-
65
- case key
66
- when "on"
67
- [:on_todo_event, value]
68
- when "to"
69
- [:on_todo_assignee, value]
70
- else
71
- [:unknown, value]
72
- end
73
- end
74
-
75
- # @param data [Hash]
76
- # @return [Hash]
77
- def on_bare_assoc_hash(data)
78
- data
79
- end
80
- end
81
-
82
- class Visitor
83
- attr_reader :events, :assignees, :errors
84
-
85
- def initialize
86
- @events = []
87
- @assignees = []
88
- @errors = []
89
- end
90
-
91
- # Iterate over each tokens returned from the parser and call
92
- # the corresponding method
93
- #
94
- # @param sexp [Array]
95
- # @return [void]
96
- def process(sexp)
97
- return unless sexp
98
-
99
- if sexp[0].is_a?(Array)
100
- sexp.each { |node| process(node) }
101
- else
102
- method, *args = sexp
103
- send(method, *args) if method.is_a?(Symbol) && respond_to?(method)
104
- end
105
- end
106
-
107
- # @param method_node [MethodNode]
108
- # @return [void]
109
- def on_todo_event(method_node)
110
- if method_node.is_a?(MethodNode)
111
- events << method_node
112
- else
113
- errors << "Incorrect `:on` event format: #{method_node}"
114
- end
115
- end
116
-
117
- # @param assignee [String]
118
- # @return [void]
119
- def on_todo_assignee(assignee)
120
- @assignees << assignee
121
- end
122
- end
123
- end
124
- end
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SmartTodo
4
- module Parser
5
- # Represents a SmartTodo which includes the associated events
6
- # as well as the assignee.
7
- class TodoNode
8
- DEFAULT_RUBY_INDENTATION = 2
9
-
10
- attr_reader :metadata
11
-
12
- # @param todo [String] the actual Ruby comment
13
- def initialize(todo)
14
- @metadata = MetadataParser.parse(todo.gsub(/^#/, ""))
15
- @comments = []
16
- @start = todo.match(/^#(\s+)/)[1].size
17
- end
18
-
19
- # Return the associated comment for this TODO
20
- #
21
- # @return [String]
22
- def comment
23
- @comments.join
24
- end
25
-
26
- # @param comment [String]
27
- # @return [void]
28
- def <<(comment)
29
- @comments << comment.gsub(/^#(\s+)/, "")
30
- end
31
-
32
- # Check if the +comment+ is indented two spaces below the
33
- # TODO declaration. If yes the comment is considered to be part
34
- # of the TODO itself. Otherwise it's just a regular comment.
35
- #
36
- # @param comment [String]
37
- # @return [true, false]
38
- def indented_comment?(comment)
39
- comment.match(/^#(\s*)/)[1].size - @start == DEFAULT_RUBY_INDENTATION
40
- end
41
- end
42
- end
43
- end