-
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.
Merge pull request #69 from Shopify/speed
Speed up
- Loading branch information
Showing
31 changed files
with
665 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
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,51 @@ | ||
# frozen_string_literal: true | ||
|
||
module SmartTodo | ||
class CommentParser | ||
attr_reader :todos | ||
|
||
def initialize | ||
@todos = [] | ||
end | ||
|
||
def parse(source, filepath = "-e") | ||
parse_comments(Prism.parse_comments(source), filepath) | ||
end | ||
|
||
def parse_file(filepath) | ||
parse_comments(Prism.parse_file_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| | ||
next unless comment.is_a?(Prism::InlineComment) | ||
|
||
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.