Last active
March 2, 2020 03:51
-
-
Save jonatas/c1e580dcb74e20d4f2df4632ceb084ef to your computer and use it in GitHub Desktop.
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
require 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'ffast', | |
git: 'https://github.com/jonatas/fast.git', | |
require: 'fast' | |
end | |
Fast.class_eval do | |
# Captures class and method name when find syntax like: | |
# `allow(...).to receive(...)` that does not end with `.with(...)` | |
pattern_with_captures = <<~FAST | |
(send (send nil allow (const nil $_)) to | |
(send (send nil receive (sym $_)) !with)) | |
FAST | |
pattern = expression(pattern_with_captures.tr('$','')) | |
ruby_files_from('spec').each do |file| | |
results = search_file(pattern, file) || [] rescue next | |
results.each do |n| | |
clazz, method = capture(n, pattern_with_captures) | |
if klazz = Object.const_get(clazz.to_s) rescue nil | |
if klazz.respond_to?(method) | |
params = klazz.method(method).parameters | |
if params.any?{|e|e.first == :req} | |
code = n.loc.expression | |
range = [code.first_line, code.last_line].uniq.join(",") | |
boom_message = "💥 #{clazz}.#{method} does not include the parameters!" | |
puts boom_message, "#{file}:#{range}", code.source | |
end | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/jonatas/bf9387bbc8ba2f0f6f9267cef5751802