todofind 1.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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +18 -0
- data/bin/todofind +78 -0
- data/config.json +6 -0
- data/lib/todofind/config.rb +38 -0
- data/lib/todofind/finder.rb +94 -0
- data/lib/todofind/formatter.rb +0 -0
- data/lib/todofind/formatters/default_formatter.rb +28 -0
- data/lib/todofind/formatters/json_formatter.rb +10 -0
- data/lib/todofind.rb +13 -0
- data/lib/version.rb +4 -0
- data/test/default_testing_dir/testfile +1 -0
- data/test/todofind_test.rb +20 -0
- data/todofind.gemspec +19 -0
- metadata +82 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Mark Szymanski
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# todofind
|
2
|
+
|
3
|
+
A gem for finding TODO/FIXME/etc. comments in files.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'todofind'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install todofind
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
See `todofind -h`
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
require 'cane/rake_task'
|
4
|
+
require 'rake/testtask'
|
5
|
+
|
6
|
+
desc "Run cane quality tests"
|
7
|
+
Cane::RakeTask.new(:quality)
|
8
|
+
|
9
|
+
desc "Run tests"
|
10
|
+
task :test do
|
11
|
+
Rake::TestTask.new do |t|
|
12
|
+
t.libs << "test"
|
13
|
+
t.test_files = FileList['test/*_test.rb']
|
14
|
+
t.verbose = false
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
task :default => [:quality, :test]
|
data/bin/todofind
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$: << File.expand_path("../../lib/.", __FILE__)
|
4
|
+
|
5
|
+
require 'todofind'
|
6
|
+
require 'optparse'
|
7
|
+
|
8
|
+
options = {}
|
9
|
+
|
10
|
+
parser = OptionParser.new do |opts|
|
11
|
+
opts.banner = "Usage: #{$0} [options] [path]"
|
12
|
+
|
13
|
+
opts.on "-c FILE", "--config FILE", "Use FILE as the configuration file.", "Must be a JSON file." do |config_file|
|
14
|
+
if !config_file.match /(.+)\.json/
|
15
|
+
puts "Error: Configuration file isn't a json file."
|
16
|
+
exit 1
|
17
|
+
end
|
18
|
+
options[:config_file] = config_file
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on "-f FORMATTER", "--formatter",
|
22
|
+
"Use FORMATTER as the formatter." do |formatter|
|
23
|
+
options[:formatter] = formatter
|
24
|
+
end
|
25
|
+
|
26
|
+
opts.on_tail "-h", "--help", "Display this message." do
|
27
|
+
puts opts
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
|
31
|
+
opts.on_tail "-l", "--list-formatters",
|
32
|
+
"List the available output formatters." do
|
33
|
+
TodoFind::FORMATTERS.keys.each{|f| puts f }
|
34
|
+
exit
|
35
|
+
end
|
36
|
+
|
37
|
+
opts.on_tail "-v", "--version", "Display the version number." do
|
38
|
+
puts VERSION
|
39
|
+
exit
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
parser.parse! ARGV
|
44
|
+
|
45
|
+
if ARGV.size > 1
|
46
|
+
puts "Too many arguments."
|
47
|
+
exit 1
|
48
|
+
end
|
49
|
+
|
50
|
+
path = ARGV[0] || "."
|
51
|
+
|
52
|
+
formatter_name = (options[:formatter] || "default").to_sym
|
53
|
+
|
54
|
+
if options[:config_file]
|
55
|
+
begin
|
56
|
+
config_data = File.read options[:config_file]
|
57
|
+
config_data = JSON.parse config_data
|
58
|
+
if config_data["formatter"]
|
59
|
+
formatter_name = config_data["formatter"].to_sym
|
60
|
+
end
|
61
|
+
rescue Errno::ENOENT
|
62
|
+
puts "Config file doesn't exist."
|
63
|
+
exit 1
|
64
|
+
end
|
65
|
+
else
|
66
|
+
config_data = {}
|
67
|
+
end
|
68
|
+
|
69
|
+
finder = TodoFind::Finder.new config_data, path
|
70
|
+
out = finder.find
|
71
|
+
|
72
|
+
if TodoFind::FORMATTERS.include? formatter_name
|
73
|
+
formatter = TodoFind::FORMATTERS[formatter_name].new
|
74
|
+
else
|
75
|
+
formatter = TodoFind::DefaultFormatter.new
|
76
|
+
end
|
77
|
+
|
78
|
+
puts formatter.render out
|
data/config.json
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
module TodoFind
|
2
|
+
# Internal: A model for the configuration data.
|
3
|
+
class Config
|
4
|
+
attr_reader :exclude_dirs, :exclude_files, :labels
|
5
|
+
# Public: Create a new instance of Config
|
6
|
+
#
|
7
|
+
# data - A hash of the data to be used
|
8
|
+
# :labels - A list of labels to search for. Defaults are TODO and
|
9
|
+
# FIXME
|
10
|
+
# :exclude_dirs - A list of directories to exclude from the search.
|
11
|
+
# :exclude_files - A list of files to exclude from the search.
|
12
|
+
#
|
13
|
+
# Examples:
|
14
|
+
#
|
15
|
+
# config = TodoFind::Config.new({ :labels => ["TODO, "FIXME", "OHAI"]})
|
16
|
+
def initialize(data)
|
17
|
+
new_data = {}
|
18
|
+
data.each do |k, v|
|
19
|
+
new_data[k.to_sym] = v
|
20
|
+
end
|
21
|
+
|
22
|
+
@labels = new_data[:labels] || %w{TODO FIXME}
|
23
|
+
if !@labels.is_a? Array
|
24
|
+
@labels = []
|
25
|
+
end
|
26
|
+
|
27
|
+
@exclude_dirs = new_data[:exclude_dirs] || []
|
28
|
+
if !@exclude_dirs.is_a? Array
|
29
|
+
@exclude_dirs = []
|
30
|
+
end
|
31
|
+
|
32
|
+
@exclude_files = new_data[:exclude_files] || []
|
33
|
+
if !@exclude_files.is_a? Array
|
34
|
+
@exclude_files = []
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module TodoFind
|
2
|
+
# Public: The comment finder. It finds all files in the current directory
|
3
|
+
# containing the comments specified in the config data, or the
|
4
|
+
# defaults: TODO and FIXME.
|
5
|
+
#
|
6
|
+
# Examples:
|
7
|
+
#
|
8
|
+
# finder = Finder.new(config_data, '.')
|
9
|
+
# finder.find
|
10
|
+
# # => [{:filename => "my_file.rb", :comments =>
|
11
|
+
# [{:line => 3,
|
12
|
+
# :label => "TODO",
|
13
|
+
# :comment => "A todo comment"}]}]
|
14
|
+
class Finder
|
15
|
+
# Public: Create a new Finder object with specified config data and a path.
|
16
|
+
#
|
17
|
+
# config - A hash of the configuration data. Allowed options are:
|
18
|
+
# :labels - An array of labels to find (Defaults are TODO and
|
19
|
+
# FIXME)
|
20
|
+
# :exclude_files - An array of files to exclude from the search.
|
21
|
+
# :exclude_dirs - An array of directories to exclude from the
|
22
|
+
# search.
|
23
|
+
#
|
24
|
+
# path - The path to start the search at. The search will recurse down from
|
25
|
+
# here but never above this directory.
|
26
|
+
def initialize(config, path)
|
27
|
+
@config = TodoFind::Config.new config
|
28
|
+
@path = path
|
29
|
+
end
|
30
|
+
|
31
|
+
# Public: Start recursing through directories under the Finder object's
|
32
|
+
# path and look for comments with the specified labels.
|
33
|
+
#
|
34
|
+
# Examples:
|
35
|
+
#
|
36
|
+
# finder.find
|
37
|
+
#
|
38
|
+
# # => [{:filename => "my_file.rb",
|
39
|
+
# :comments => [{:line => 3,
|
40
|
+
# :label => "TODO",
|
41
|
+
# :comment => "Do something"}]}]
|
42
|
+
#
|
43
|
+
# Returns a Hash of the comment data.
|
44
|
+
def find
|
45
|
+
file_list = get_file_list
|
46
|
+
regex = /(#{@config.labels.join "|"}): (.+)/
|
47
|
+
data = []
|
48
|
+
|
49
|
+
file_list.each do |file|
|
50
|
+
did_output_filename = false
|
51
|
+
|
52
|
+
file_data = { :filename => file, :comments => [] }
|
53
|
+
|
54
|
+
contents = File.read file
|
55
|
+
lines = contents.split "\n"
|
56
|
+
lines.each_with_index do |line, line_num|
|
57
|
+
line.match regex do |match|
|
58
|
+
label = match[1]
|
59
|
+
comment = match[2]
|
60
|
+
file_data[:comments] << { :line => line_num + 1,
|
61
|
+
:label => label,
|
62
|
+
:comment => comment }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
if !file_data[:comments].empty?
|
66
|
+
data << file_data
|
67
|
+
end
|
68
|
+
end
|
69
|
+
return data
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
# Internal: Get the list of files underneath the current one. Recursively.
|
74
|
+
#
|
75
|
+
# Examples:
|
76
|
+
#
|
77
|
+
# finder = TodoFind::Finder.new(config_data, ".")
|
78
|
+
# finder.get_file_list
|
79
|
+
# # => [ "file", "dir", "dir/file" ]
|
80
|
+
#
|
81
|
+
# Returns an Array containing the entries from the recursive file search.
|
82
|
+
def get_file_list
|
83
|
+
file_list = Dir.glob "#{@path}/**/*"
|
84
|
+
file_list.reject! do |f|
|
85
|
+
File.directory?(f) ||
|
86
|
+
@config.exclude_files.include?(File.path f) ||
|
87
|
+
(!@config.exclude_dirs.empty? && @config.exclude_dirs.map do |dir|
|
88
|
+
File.path(f)[dir]
|
89
|
+
end.any?)
|
90
|
+
end
|
91
|
+
return file_list
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
File without changes
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# TODO: Allow using any sort of formatter from any file as the formatter.
|
2
|
+
|
3
|
+
module TodoFind
|
4
|
+
# Public: The default output formatter to use when printing the search data.
|
5
|
+
class DefaultFormatter
|
6
|
+
# Public: Render the given data.
|
7
|
+
#
|
8
|
+
# data - The search data to render. (ex: Data returned from
|
9
|
+
# TodoFind::Finder#find
|
10
|
+
#
|
11
|
+
# Returns a String of the rendered data.
|
12
|
+
def render(data)
|
13
|
+
output = ""
|
14
|
+
data.each do |file|
|
15
|
+
filename = file[:filename]
|
16
|
+
|
17
|
+
output << "#{filename.green}:\n"
|
18
|
+
|
19
|
+
file[:comments].each do |comment|
|
20
|
+
output <<
|
21
|
+
"#{comment[:line]}: [#{comment[:label].red}] #{comment[:comment]}\n"
|
22
|
+
end
|
23
|
+
output << "\n"
|
24
|
+
end
|
25
|
+
output
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/todofind.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'colored'
|
2
|
+
require 'json'
|
3
|
+
require 'todofind/config'
|
4
|
+
require 'todofind/finder'
|
5
|
+
require 'todofind/formatters/default_formatter'
|
6
|
+
require 'todofind/formatters/json_formatter'
|
7
|
+
require 'todofind/formatter'
|
8
|
+
|
9
|
+
module TodoFind
|
10
|
+
# Public: The output formatters
|
11
|
+
FORMATTERS = { :default => TodoFind::DefaultFormatter,
|
12
|
+
:json => TodoFind::JSONFormatter }
|
13
|
+
end
|
data/lib/version.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
TODO: A TODO comment
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# TODO: Write the unit tests.
|
2
|
+
|
3
|
+
$: << File.expand_path("../../lib/.", __FILE__)
|
4
|
+
require 'riot'
|
5
|
+
require 'todofind'
|
6
|
+
|
7
|
+
context "Searching without config" do
|
8
|
+
setup { TodoFind::Finder.new({}, "test/default_testing_dir") }
|
9
|
+
asserts(:find).equals([{:filename=>"test/default_testing_dir/testfile", :comments=>[{:line=>1, :label=>"TODO", :comment=>"A TODO comment"}]}])
|
10
|
+
end
|
11
|
+
|
12
|
+
context "Ignoring files" do
|
13
|
+
setup { TodoFind::Finder.new({ :exclude_files => ["test/default_testing_dir/testfile"] }, "test/default_testing_dir") }
|
14
|
+
asserts(:find).equals([])
|
15
|
+
end
|
16
|
+
|
17
|
+
context "Ignoring directories" do
|
18
|
+
setup { TodoFind::Finder.new({ :exclude_dirs => ["test/default_testing_dir"] }, "test/default_testing_dir") }
|
19
|
+
asserts(:find).equals []
|
20
|
+
end
|
data/todofind.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/./version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Mark Szymanski"]
|
6
|
+
gem.email = ["mdszy@me.com"]
|
7
|
+
gem.description = %q{Find comments in files that contain certain labels}
|
8
|
+
gem.summary = %q{Find comments with labels}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "todofind"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = TodoFind::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency "tomdoc"
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: todofind
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mark Szymanski
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: tomdoc
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: Find comments in files that contain certain labels
|
31
|
+
email:
|
32
|
+
- mdszy@me.com
|
33
|
+
executables:
|
34
|
+
- todofind
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- .gitignore
|
39
|
+
- Gemfile
|
40
|
+
- LICENSE
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- bin/todofind
|
44
|
+
- config.json
|
45
|
+
- lib/todofind.rb
|
46
|
+
- lib/todofind/config.rb
|
47
|
+
- lib/todofind/finder.rb
|
48
|
+
- lib/todofind/formatter.rb
|
49
|
+
- lib/todofind/formatters/default_formatter.rb
|
50
|
+
- lib/todofind/formatters/json_formatter.rb
|
51
|
+
- lib/version.rb
|
52
|
+
- test/default_testing_dir/testfile
|
53
|
+
- test/todofind_test.rb
|
54
|
+
- todofind.gemspec
|
55
|
+
homepage: ''
|
56
|
+
licenses: []
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.8.23
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: Find comments with labels
|
79
|
+
test_files:
|
80
|
+
- test/default_testing_dir/testfile
|
81
|
+
- test/todofind_test.rb
|
82
|
+
has_rdoc:
|