Skip to content

Instantly share code, notes, and snippets.

@krzysztofzablocki
Last active September 23, 2022 04:57
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krzysztofzablocki/338eddf527a351de825bd62cf2a1de28 to your computer and use it in GitHub Desktop.
Save krzysztofzablocki/338eddf527a351de825bd62cf2a1de28 to your computer and use it in GitHub Desktop.
Use Sourcery to Generate bash script that will rewrite your source code to add final to all classes that have no inheritance
#!/usr/bin/env bash
<% for type in types.classes { -%>
<%_ if type.modifiers.map{ $0.name }.contains("final") || type.modifiers.map{ $0.name }.contains("open") || types.based[type.name].isEmpty == false { continue } -%>
<%_ _%>git grep -lz 'class <%= type.name %>' | xargs -0 perl -i'' -pE "s/class <%= type.name %>(?=\s|:)/final class <%= type.name %>/g"
<% } %>
// Run with Sourcery on your codebase and then execute generated code via bash :)
@Nikoloutsos
Copy link

Nice one 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment