todoloo 0.0.2 → 0.0.4

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: 3e10a05abef8c425b5e2e9347d1bccc9e592f5e7a03a5608f84aa5495cfdf45e
4
- data.tar.gz: 3e0febaa61ee4a872d045d8df00f9b49e17716ae3384b52a1aad8e0efbd4ec68
3
+ metadata.gz: 30e603e6f88a2ac0a52654b71d81714936db242648786c9bd1b0ac602cff03e6
4
+ data.tar.gz: 609ee891b2a8d01817c63725a4a4b4197c63e86cabeb5f44b32a8b4a470c224a
5
5
  SHA512:
6
- metadata.gz: aefc739a86f6120a9383f3edec5b84433498cdcfe747fa40fd72654fc61ab4925137be92402c2303e37db9ead9b632837171a58d9c1142fdc80fa664deb43387
7
- data.tar.gz: b0862355aa8fdb6bbfc4c405f8b0f83fd84a489f930c9aca3728bbae1b9888481bde8f34c1d3ed9632934068c685d84302e3f9df995dfea209b3573ddcef3033
6
+ metadata.gz: e6f09e526d68283bc2ce77bdf9a2439f4d4a03bcb6b9dc199cdcd41356625fd7968eba57e6f2dade51a61aee5b280041e0e9ec82a2db99a093ce279006135ffd
7
+ data.tar.gz: 7e37cf807c222e8320e0af0eebaab9bd390beb2bb523c6174237a5f40d6a699e8d905e239a0c2b6e0ba917468885fd685d718526bb485fffa29d96cba867f5b5
data/CHANGELOG CHANGED
@@ -1,3 +1,17 @@
1
+ Unreleased
2
+
3
+ 0.0.4 - 13 August 2024
4
+ - Add more extensive CLI tests to catch some corner cases
5
+ - Fix `--exclude` flag not being repeatable
6
+ - Add `--pattern` flag for repeatable file matching pattern specification
7
+ - Add `--verbose` switch to opt-in for printing out scanned files
8
+ - Add `--output [FILENAME]` flag for specifying where to write the todos/tasks
9
+ - Fix remove file repeatitions when using `--pattern` that matches repeatedly
10
+
11
+ 0.0.3 - 8 August 2024
12
+ - Add sorting support to `TaskList` and now sort CLI output by default
13
+ - Fix parsing for multiple tags, as in `TODO(a,b,c)`
14
+
1
15
  0.0.2 - 19 July 2024
2
16
  - Add regression for `Todoloo::TaskList` on writing tasks with blank topics
3
17
 
data/Rakefile CHANGED
@@ -6,3 +6,7 @@ require "minitest/test_task"
6
6
  Minitest::TestTask.create
7
7
 
8
8
  task default: :test
9
+
10
+ task "test:watch" do
11
+ system("rerun bundle exec rake")
12
+ end
data/lib/todoloo/cli.rb CHANGED
@@ -3,13 +3,28 @@ require "thor"
3
3
  class Todoloo::CLI < Thor
4
4
  package_name "Todoloo"
5
5
 
6
+ DEFAULT_PATTERN = [
7
+ "**/*.rb",
8
+ "*.rb"
9
+ ].freeze
10
+
6
11
  desc "scan", "Scans all files that match the given globs and outputs a tasks.yml"
7
- method_option :exclude, type: :array, aliases: "-e", desc: "List of path globs to exclude"
12
+ method_option :pattern, type: :string, repeatable: true, aliases: "-p", desc: "Path globs to match; can be repeated"
13
+ method_option :exclude, type: :string, repeatable: true, aliases: "-e", desc: "List of path globs to exclude"
14
+ method_option :output, type: :string, aliases: "-o", default: "tasks.yml", desc: "Name of the output file"
15
+ method_option :verbose, type: :boolean, default: false
8
16
  def scan
17
+ patterns = options.fetch(:pattern, DEFAULT_PATTERN)
18
+
9
19
  Todoloo::FileScanner
10
- .new("**/*.rb", excludes: options[:exclude] || [], trace: true)
20
+ .new(
21
+ patterns,
22
+ excludes: options.fetch(:exclude, []),
23
+ trace: options.fetch(:verbose)
24
+ )
11
25
  .scan
12
- .write("tasks.yml")
26
+ .sort
27
+ .write(options.fetch(:output))
13
28
  end
14
29
 
15
30
  desc "io", "Reads input from stdio and writes to stdout"
@@ -18,7 +33,7 @@ class Todoloo::CLI < Thor
18
33
  Todoloo::Parser
19
34
  .new
20
35
  .parse_and_transform($stdin.read)
21
- ).write($stdout)
36
+ ).sort.write($stdout)
22
37
  end
23
38
 
24
39
  def self.exit_on_failure?
@@ -6,7 +6,9 @@ module Todoloo
6
6
  # TODO We need to optimize how we traverse the file-system so that we can short-circuit the excludes instead
7
7
  # of only filtering after finding them.
8
8
  #
9
- # @pattern [String]
9
+ # TODO Optimize the seen_path handling
10
+ #
11
+ # @pattern [String, Array<String>]
10
12
  # The file paths to glob
11
13
  #
12
14
  # @excludes [Array<String>]
@@ -14,9 +16,15 @@ module Todoloo
14
16
  #
15
17
  # @return [Enumerator<String>]
16
18
  def glob_paths(pattern, excludes: [])
19
+ seen_paths = Set.new
20
+
17
21
  Enumerator.new do |y|
18
- Dir[pattern].lazy.each do |path|
19
- y << path unless excludes.any? { |e| File.fnmatch(e, path) }
22
+ Dir[*Array(pattern)].lazy.each do |path|
23
+ if !(seen_paths.include?(path) || excludes.any? { |e| File.fnmatch(e, path) })
24
+ y << path
25
+ end
26
+
27
+ seen_paths << path
20
28
  end
21
29
  end
22
30
  end
@@ -148,7 +148,7 @@ module Todoloo
148
148
 
149
149
  rule(:topic) { match(/[^),]/).repeat(1).as(:topic) }
150
150
 
151
- rule(:topic_rest) { (str(",") >> spacing.maybe >> topic).repeat(0, 1) }
151
+ rule(:topic_rest) { (str(",") >> spacing.maybe >> topic).repeat(0) }
152
152
 
153
153
  # (topic1, topic2)
154
154
  rule(:topics) { lparen >> topic >> topic_rest >> rparen }
data/lib/todoloo/task.rb CHANGED
@@ -10,5 +10,9 @@ module Todoloo
10
10
  hash.fetch(:column)
11
11
  )
12
12
  end
13
+
14
+ def location
15
+ "#{path}:#{line}:#{column}"
16
+ end
13
17
  end
14
18
  end
@@ -2,6 +2,20 @@ require "yaml"
2
2
 
3
3
  module Todoloo
4
4
  class TaskList
5
+ include Enumerable
6
+
7
+ # Lower means higher priority
8
+ SEVERITY_INDEX = {
9
+ "FIXME" => 100,
10
+ "HACK" => 200,
11
+ "TODO" => 300,
12
+ "XXX" => 400,
13
+ "NOTE" => 500,
14
+ "HBD" => 600
15
+ }.freeze
16
+
17
+ UNKNOWN_INDEX = 1_000_000
18
+
5
19
  def initialize
6
20
  @tasks = []
7
21
  end
@@ -17,6 +31,20 @@ module Todoloo
17
31
  self
18
32
  end
19
33
 
34
+ def each
35
+ to_enum(:each) unless block_given?
36
+
37
+ @tasks.each { |task| yield task }
38
+ end
39
+
40
+ def sort
41
+ @tasks.sort_by! do |t|
42
+ [t.topics, task_severity(t), t.path, t.line, t.column]
43
+ end
44
+
45
+ self
46
+ end
47
+
20
48
  # Structure:
21
49
  # TOPIC:
22
50
  # TYPE:
@@ -38,6 +66,10 @@ module Todoloo
38
66
 
39
67
  private
40
68
 
69
+ def task_severity(task)
70
+ SEVERITY_INDEX.fetch(task.type, UNKNOWN_INDEX)
71
+ end
72
+
41
73
  def topics_for_task(task)
42
74
  if task.topics.empty?
43
75
  [""]
@@ -19,7 +19,7 @@ module Todoloo
19
19
  {type: type, topics: topics, description: description.empty? ? "" : (raise "must be empty")}
20
20
  end
21
21
 
22
- rule(topic: simple(:x)) { x }
22
+ rule(topic: simple(:x)) { x.to_s }
23
23
 
24
24
  rule(task: subtree(:task)) { task }
25
25
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Todoloo
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.4"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: todoloo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Coetzee
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-19 00:00:00.000000000 Z
11
+ date: 2024-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby