Created
January 20, 2022 14:09
-
-
Save Bhacaz/b3a352e2f91eeb87afe068090735a1f5 to your computer and use it in GitHub Desktop.
Detect files with methods that may modify string
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
# 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