Skip to content

Instantly share code, notes, and snippets.

@Bhacaz
Created January 20, 2022 14:09
Show Gist options
  • Save Bhacaz/b3a352e2f91eeb87afe068090735a1f5 to your computer and use it in GitHub Desktop.
Save Bhacaz/b3a352e2f91eeb87afe068090735a1f5 to your computer and use it in GitHub Desktop.
Detect files with methods that may modify string
# frozen_string_literal: true
files_path = `git diff --name-only origin/master..`
files_path = files_path.split("\n").select { |f| f.end_with?('.rb') }
METHODS = %w(
<<
.push
.gsub!
.concat
.tr!
.delete
.clear
.map!
.slice!
).freeze
def detect_method(path)
clean = true
File.read(path).each_line.with_index do |line, number|
METHODS.each do |m|
if line.include?(m)
clean = false
puts "check: #{path}:#{number + 1} - #{line.gsub(m, "** #{m} **")}"
end
end
end
clean
end
clean = []
files_path.each do |path|
clean << path if detect_method(path)
end
puts 'vvvvvv-clean-vvvvvvv'
puts clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment