Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support older prism versions #71

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading