Created
May 4, 2023 17:37
-
-
Save jaynetics/e0bc3211a55cb252eb05028e8a226446 to your computer and use it in GitHub Desktop.
find possibly unused modules in a rails app
This file contains hidden or 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
code = Dir['{app,config,lib}/**/*.{rb,slim,erb,rake}'].map { File.read _1 }.join; 1 | |
defs = code.scan(/(?:class|module) \K[A-Z][\w:]+(?=\n)/); 1 | |
refs = code.scan(/(?<!class |module )\b#{Regexp.union(defs + defs.map { |d| d.split('::').last })}\b/); 1 | |
unused = defs.uniq.sort.select { |d| refs.count(d) == 0 && refs.count(d.split('::').last) == 0 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment