Skip to content

Commit

Permalink
Merge pull request #71 from Shopify/other-prisms
Browse files Browse the repository at this point in the history
Support older prism versions
  • Loading branch information
andyw8 authored Dec 8, 2023
2 parents 125ee11 + 2d95e2b commit cf233ef
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PATH
remote: .
specs:
smart_todo (1.7.0)
prism
prism (~> 0.15)

GEM
remote: https://rubygems.org/
Expand Down
32 changes: 26 additions & 6 deletions lib/smart_todo/comment_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion smart_todo.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit cf233ef

Please sign in to comment.