Last active
June 13, 2024 12:19
-
-
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
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
#!/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 :) |
so you need to name it .swifttemplate
run sourcery on it, if it sees your source files it should output a lot of lines for the command line grep / xargs pair, when you do so does it generate anything at all?
OMG. Finally, it did work. The problem was indeed in the file type .swifttemplate
. @krzysztofzablocki thanks once again for the explanation, patience and help 🤝
glad it works now :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@krzysztofzablocki , @Nikoloutsos thank you for your feedback. I still don't get the result that I want, but I strongly believe this is a working solution. Sourcery works for me extremely fine when I work with stencil templates especially since it is easy to do in Sourcery Pro, but for some reason, I couldn't achieve the same with this type of template. In the very best situation so far it's generated exactly the same script as the output but doesn't modify files ( I will try again