-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
671 additions
and
896 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,5 @@ gemspec | |
group :rubocop do | ||
gem "rubocop-shopify", require: false | ||
end | ||
|
||
gem "prism", github: "ruby/prism" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require "bundler/setup" | ||
require "smart_todo" | ||
|
||
class NullDispatcher < SmartTodo::Dispatchers::Base | ||
class << self | ||
def validate_options!(_); end | ||
end | ||
def dispatch | ||
end | ||
end | ||
exit SmartTodo::CLI.new(NullDispatcher).run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
module SmartTodo | ||
class CommentParser | ||
attr_reader :todos | ||
|
||
def initialize | ||
@todos = [] | ||
end | ||
|
||
def parse(source, filepath = "-e") | ||
parse_comments(Prism.parse_inline_comments(source, filepath), filepath) | ||
end | ||
|
||
def parse_file(filepath) | ||
parse_comments(Prism.parse_file_inline_comments(filepath), filepath) | ||
end | ||
|
||
class << self | ||
def parse(source) | ||
parser = new | ||
parser.parse(source) | ||
parser.todos | ||
end | ||
end | ||
|
||
private | ||
|
||
def parse_comments(comments, filepath) | ||
current_todo = nil | ||
|
||
comments.each do |comment| | ||
source = comment.location.slice | ||
|
||
if source.match?(/^#\sTODO\(/) | ||
todos << current_todo if current_todo | ||
current_todo = Todo.new(source, filepath) | ||
elsif current_todo && (indent = source[/^#(\s*)/, 1].length) && (indent - current_todo.indent == 2) | ||
current_todo << "#{source[(indent + 1)..]}\n" | ||
else | ||
todos << current_todo if current_todo | ||
current_todo = nil | ||
end | ||
end | ||
|
||
todos << current_todo if current_todo | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.