diff --git a/Gemfile.lock b/Gemfile.lock index 1fcbb37..0155660 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,7 +2,7 @@ PATH remote: . specs: smart_todo (1.7.0) - prism + prism (~> 0.15) GEM remote: https://rubygems.org/ diff --git a/lib/smart_todo/comment_parser.rb b/lib/smart_todo/comment_parser.rb index 4a804a1..2c44232 100644 --- a/lib/smart_todo/comment_parser.rb +++ b/lib/smart_todo/comment_parser.rb @@ -8,12 +8,22 @@ def initialize @todos = [] end - def parse(source, filepath = "-e") - parse_comments(Prism.parse_comments(source), filepath) - end + if Prism.respond_to?(:parse_comments) + 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 + else + def parse(source, filepath = "-e") + parse_comments(Prism.parse(source, filepath).comments, filepath) + end - def parse_file(filepath) - parse_comments(Prism.parse_file_comments(filepath), filepath) + def parse_file(filepath) + parse_comments(Prism.parse_file(filepath).comments, filepath) + end end class << self @@ -26,11 +36,21 @@ def parse(source) private + if defined?(Prism::InlineComment) + def inline?(comment) + comment.is_a?(Prism::InlineComment) + end + else + def inline?(comment) + comment.type == :inline + end + end + def parse_comments(comments, filepath) current_todo = nil comments.each do |comment| - next unless comment.is_a?(Prism::InlineComment) + next unless inline?(comment) source = comment.location.slice diff --git a/smart_todo.gemspec b/smart_todo.gemspec index 5ebc21c..77814d3 100644 --- a/smart_todo.gemspec +++ b/smart_todo.gemspec @@ -33,7 +33,7 @@ Gem::Specification.new do |spec| spec.executables = ["smart_todo"] spec.require_paths = ["lib"] - spec.add_runtime_dependency("prism") + spec.add_runtime_dependency("prism", "~> 0.15") spec.add_development_dependency("bundler", ">= 1.17") spec.add_development_dependency("minitest", "~> 5.0") spec.add_development_dependency("rake", ">= 10.0")