todo_lint 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -3
- data/lib/todo_lint.rb +2 -0
- data/lib/todo_lint/cli.rb +39 -12
- data/lib/todo_lint/config_file.rb +55 -0
- data/lib/todo_lint/file_finder.rb +21 -1
- data/lib/todo_lint/options.rb +68 -0
- data/lib/todo_lint/todo.rb +1 -1
- data/lib/todo_lint/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1af0ecc125399a8f4a1b92b139973fb0c394ed1a
|
4
|
+
data.tar.gz: 5895d4d1df63439f25794c72e81dc2799d14f6d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1da62b05fe0a35245fdc065bdee21bbec5e200e289ec0318db16af647de574219887f9da8325ef5fd65bf4aab1e2df7c4f8ecc54fbc42acac24cf824abe23abe
|
7
|
+
data.tar.gz: f1a5b2983d648d46ccde43155b417734ee0fdee5641d2a002dcbf4268e29c90b5c10f1329fc7313b425859bd934010da8b9f564d79aadb527840b0dc4ee56ecf
|
data/README.md
CHANGED
@@ -29,9 +29,7 @@ Or install it yourself as:
|
|
29
29
|
Add this to your continuous integration list of commands in your `.travis.yml`
|
30
30
|
or `circle.yml`:
|
31
31
|
|
32
|
-
bundle exec todo_lint
|
33
|
-
|
34
|
-
(Put whichever file extensions you want it to check; note the leading dot.)
|
32
|
+
bundle exec todo_lint
|
35
33
|
|
36
34
|
If you have a bunch of TODO comments in your code, your next build will fail.
|
37
35
|
|
@@ -49,6 +47,31 @@ to:
|
|
49
47
|
|
50
48
|
Now your build will pass. Until November, 2043.
|
51
49
|
|
50
|
+
## Configuration
|
51
|
+
|
52
|
+
Create a .todo_lint.yml file in your main repo
|
53
|
+
|
54
|
+
Exclude Files:
|
55
|
+
- vendor/**
|
56
|
+
|
57
|
+
Options include "Include Files:", "Exclude Files:", and "Extensions:"
|
58
|
+
|
59
|
+
If no extensions are specified, todo_lint will check all .rb files by default.
|
60
|
+
|
61
|
+
If you include files, todo_lint will only read those files.
|
62
|
+
|
63
|
+
The config file will exclude/include files starting from the directory where the config file is located
|
64
|
+
|
65
|
+
You may also configure your use of todo_lint from the command line:
|
66
|
+
|
67
|
+
$ todo_lint -i .rb,.coffee,.js
|
68
|
+
|
69
|
+
Command flag | Description
|
70
|
+
--------------------------|--------------------------------------------
|
71
|
+
`-c/--config [FILE]` | Load the specified config file
|
72
|
+
`-e/--exclude [FILES]` | Exclude the specified files
|
73
|
+
`-i/--include [EXTS]` | Only look at specified extensions
|
74
|
+
|
52
75
|
## Development
|
53
76
|
|
54
77
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
data/lib/todo_lint.rb
CHANGED
@@ -7,6 +7,8 @@ require "todo_lint/todo"
|
|
7
7
|
require "todo_lint/reporter"
|
8
8
|
require "todo_lint/judge"
|
9
9
|
require "todo_lint/cli"
|
10
|
+
require "todo_lint/options"
|
11
|
+
require "todo_lint/config_file"
|
10
12
|
|
11
13
|
# here we establish the module which will namespace all of the code for this gem
|
12
14
|
module TodoLint
|
data/lib/todo_lint/cli.rb
CHANGED
@@ -1,24 +1,31 @@
|
|
1
|
+
require "todo_lint/options"
|
2
|
+
|
1
3
|
module TodoLint
|
2
4
|
# Here we bring together all the pieces and see if it comes together
|
3
|
-
# TODO: test this class somehow
|
4
5
|
class Cli
|
5
6
|
# Startup the thing that actually checks the files for todos!
|
6
7
|
# @example
|
7
|
-
# Cli.new(["
|
8
|
+
# Cli.new(["-i", ".rb,.js"])
|
8
9
|
# @api public
|
9
|
-
def initialize(
|
10
|
+
def initialize(args) # rubocop:disable Metrics/AbcSize
|
11
|
+
@options = Options.new.parse(args)
|
12
|
+
if @options[:config_file]
|
13
|
+
@options.merge!(ConfigFile.new.read_config_file(@options[:config_file]))
|
14
|
+
elsif File.exist?("./.todo_lint.yml")
|
15
|
+
@options.merge!(ConfigFile.new.read_config_file("./.todo_lint.yml"))
|
16
|
+
end
|
10
17
|
@path = File.expand_path(".")
|
11
|
-
@
|
18
|
+
add_default_extensions unless @options.fetch(:files, []).any?
|
12
19
|
end
|
13
20
|
|
14
21
|
# @example
|
15
|
-
# Cli.new([".rb"]).run!
|
22
|
+
# Cli.new(["-i", ".rb"]).run!
|
16
23
|
# @return exit code 0 for success, 1 for failure
|
17
24
|
# @api public
|
18
25
|
# rubocop:disable Metrics/AbcSize
|
19
26
|
def run! # rubocop:disable Metrics/MethodLength
|
20
|
-
finder = FileFinder.new(
|
21
|
-
files = finder
|
27
|
+
finder = FileFinder.new(path, options)
|
28
|
+
files = load_files(finder)
|
22
29
|
files_count = files.count
|
23
30
|
reports = files.map do |file|
|
24
31
|
Todo.within(File.open(file)).map do |todo|
|
@@ -44,18 +51,30 @@ module TodoLint
|
|
44
51
|
end
|
45
52
|
end
|
46
53
|
|
47
|
-
|
48
|
-
|
49
|
-
# Which file extensions are we checking?
|
54
|
+
# Loads the files to be read
|
50
55
|
# @return [Array<String>]
|
51
|
-
# @
|
52
|
-
|
56
|
+
# @example cli.load_files(file_finder)
|
57
|
+
# @api public
|
58
|
+
def load_files(file_finder)
|
59
|
+
if file_finder.options.fetch(:files).empty?
|
60
|
+
file_finder.list(*options[:extensions])
|
61
|
+
else
|
62
|
+
file_finder.options.fetch(:files, [])
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
53
67
|
|
54
68
|
# Where are we looking for files?
|
55
69
|
# @return [String]
|
56
70
|
# @api private
|
57
71
|
attr_reader :path
|
58
72
|
|
73
|
+
# Options hash for all configurations
|
74
|
+
# @return [Hash]
|
75
|
+
# @api private
|
76
|
+
attr_reader :options
|
77
|
+
|
59
78
|
# Pluralize a word based on the count
|
60
79
|
# @return [String]
|
61
80
|
# @api private
|
@@ -63,5 +82,13 @@ module TodoLint
|
|
63
82
|
s = count == 1 ? "" : "s"
|
64
83
|
"#{count} #{word + s}"
|
65
84
|
end
|
85
|
+
|
86
|
+
# Set default extensions if none given
|
87
|
+
# @api private
|
88
|
+
# @return [Array<String>]
|
89
|
+
def add_default_extensions
|
90
|
+
return if options[:extensions]
|
91
|
+
options[:extensions] = [".rb"]
|
92
|
+
end
|
66
93
|
end
|
67
94
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require "yaml"
|
2
|
+
|
3
|
+
module TodoLint
|
4
|
+
# Loads the config file (.todo-lint.yml)
|
5
|
+
class ConfigFile
|
6
|
+
# Parses the config file and loads the options
|
7
|
+
# @api public
|
8
|
+
# @example ConfigFile.new.parse('.todo-lint.yml')
|
9
|
+
# @return [Hash] parsed file-options
|
10
|
+
def read_config_file(file)
|
11
|
+
@config_hash = YAML.load_file(file)
|
12
|
+
@starting_path = File.expand_path(File.split(file).first)
|
13
|
+
@config_options = {}
|
14
|
+
load_file_exclusions
|
15
|
+
load_extension_inclusions
|
16
|
+
config_options
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
# Hashed form of the config file .todo-lint.yml
|
22
|
+
# @return [Hash]
|
23
|
+
# @api private
|
24
|
+
attr_reader :config_hash
|
25
|
+
|
26
|
+
# Options hash for all configurations specified by yaml file
|
27
|
+
# @return [Hash]
|
28
|
+
# @api private
|
29
|
+
attr_reader :config_options
|
30
|
+
|
31
|
+
# Starting path for all files specified in config
|
32
|
+
# @return [String]
|
33
|
+
# @api private
|
34
|
+
attr_reader :starting_path
|
35
|
+
|
36
|
+
# Adds the exclude file options to the config_options hash
|
37
|
+
# @api private
|
38
|
+
# @return [Hash]
|
39
|
+
def load_file_exclusions
|
40
|
+
return unless config_hash["Exclude Files"]
|
41
|
+
config_options[:excluded_files] = []
|
42
|
+
config_hash["Exclude Files"].each do |short_file|
|
43
|
+
config_options[:excluded_files] << File.join(starting_path, short_file)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Adds the desired extensions to the config_options hash
|
48
|
+
# @api private
|
49
|
+
# @return [Hash]
|
50
|
+
def load_extension_inclusions
|
51
|
+
return unless config_hash["Extensions"]
|
52
|
+
config_options[:extensions] = config_hash["Extensions"]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -7,9 +7,11 @@ module TodoLint
|
|
7
7
|
# @example
|
8
8
|
# FileFinder.new("/Users/max/src/layabout")
|
9
9
|
# @api public
|
10
|
-
def initialize(path)
|
10
|
+
def initialize(path, options)
|
11
11
|
@path = path
|
12
|
+
@options = options
|
12
13
|
@all_files = Dir.glob(Pathname.new(path).join("**", "*"))
|
14
|
+
@excluded = options[:excluded_files]
|
13
15
|
end
|
14
16
|
|
15
17
|
# Absolute paths to all the files with the provided extensions
|
@@ -21,8 +23,16 @@ module TodoLint
|
|
21
23
|
all_files.keep_if do |filename|
|
22
24
|
extensions.include?(Pathname.new(filename).extname)
|
23
25
|
end
|
26
|
+
all_files.reject! { |file| excluded_file?(file) }
|
27
|
+
all_files
|
24
28
|
end
|
25
29
|
|
30
|
+
# Options hash for all configurations
|
31
|
+
# @return [Hash]
|
32
|
+
# @example FileFinder.new(path, options).options
|
33
|
+
# @api public
|
34
|
+
attr_reader :options
|
35
|
+
|
26
36
|
private
|
27
37
|
|
28
38
|
# Which folder to look within for files
|
@@ -34,5 +44,15 @@ module TodoLint
|
|
34
44
|
# @return [Array<String>]
|
35
45
|
# @api private
|
36
46
|
attr_reader :all_files
|
47
|
+
|
48
|
+
# Check if this file has been excluded
|
49
|
+
# @api private
|
50
|
+
# @return [Boolean]
|
51
|
+
def excluded_file?(file)
|
52
|
+
full_path = File.expand_path(file)
|
53
|
+
options.fetch(:excluded_files, []).any? do |file_to_exclude|
|
54
|
+
File.fnmatch(file_to_exclude, full_path)
|
55
|
+
end
|
56
|
+
end
|
37
57
|
end
|
38
58
|
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require "optparse"
|
2
|
+
|
3
|
+
module TodoLint
|
4
|
+
# Handles option parsing for the command line application.
|
5
|
+
class Options
|
6
|
+
# Parses command line options into an options hash
|
7
|
+
# @api public
|
8
|
+
# @example Options.new.parse("todo_lint -c app.rb")
|
9
|
+
# @param args [Array<String>] arguments passed via the command line
|
10
|
+
# @return [Hash] parsed options
|
11
|
+
def parse(args)
|
12
|
+
@options = {}
|
13
|
+
|
14
|
+
OptionParser.new do |parser|
|
15
|
+
parser.banner = "Usage: todo_lint [options] [files]"
|
16
|
+
add_config_options parser
|
17
|
+
exclude_file_options parser
|
18
|
+
include_extension_options parser
|
19
|
+
end.parse!(args)
|
20
|
+
|
21
|
+
# Any remaining arguments are assumed to be files
|
22
|
+
options[:files] = args
|
23
|
+
|
24
|
+
options
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
# Adds the file options to the @options hash
|
30
|
+
# @api private
|
31
|
+
# @return [Hash]
|
32
|
+
def add_config_options(parser)
|
33
|
+
parser.on("-c", "--config config-file", String,
|
34
|
+
"Specify the path to the config file you want
|
35
|
+
to use, from the main repo") do |conf_file|
|
36
|
+
options[:config_file] = conf_file
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Adds the excluded file options to the options hash
|
41
|
+
# @api private
|
42
|
+
# @return [Hash]
|
43
|
+
def exclude_file_options(parser)
|
44
|
+
parser.on("-e", "--exclude file1,...", Array,
|
45
|
+
"List of file names to exclude") do |files_list|
|
46
|
+
options[:excluded_files] = []
|
47
|
+
files_list.each do |short_file|
|
48
|
+
options[:excluded_files] << File.expand_path(short_file)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Adds the include extension options to the @options hash
|
54
|
+
# @api private
|
55
|
+
# @return [Hash]
|
56
|
+
def include_extension_options(parser)
|
57
|
+
parser.on("-i", "--include ext1,...", Array,
|
58
|
+
"List of extensions to include") do |ext_list|
|
59
|
+
options[:extensions] = ext_list
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Options hash for all configurations
|
64
|
+
# @return [Hash]
|
65
|
+
# @api private
|
66
|
+
attr_reader :options
|
67
|
+
end
|
68
|
+
end
|
data/lib/todo_lint/todo.rb
CHANGED
@@ -69,7 +69,7 @@ module TodoLint
|
|
69
69
|
# When this todo is due
|
70
70
|
# @example
|
71
71
|
# due_todo.line #=> "# TODO(2015-05-24): go to the beach"
|
72
|
-
#
|
72
|
+
# due_todo.due_date.to_date #=> #<Date: 2015-05-24>
|
73
73
|
# not_due_todo.line #=> "# TODO: become a fish"
|
74
74
|
# not_due_todo.due_date #=> nil
|
75
75
|
# @return [DueDate] if there is a due date
|
data/lib/todo_lint/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: todo_lint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Jacobson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: required_arg
|
@@ -161,9 +161,11 @@ files:
|
|
161
161
|
- exe/todo_lint
|
162
162
|
- lib/todo_lint.rb
|
163
163
|
- lib/todo_lint/cli.rb
|
164
|
+
- lib/todo_lint/config_file.rb
|
164
165
|
- lib/todo_lint/due_date.rb
|
165
166
|
- lib/todo_lint/file_finder.rb
|
166
167
|
- lib/todo_lint/judge.rb
|
168
|
+
- lib/todo_lint/options.rb
|
167
169
|
- lib/todo_lint/reporter.rb
|
168
170
|
- lib/todo_lint/todo.rb
|
169
171
|
- lib/todo_lint/version.rb
|