-
Notifications
You must be signed in to change notification settings - Fork 623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
File header rule improvement #1716
Comments
This functionality is already landed in the develop branch, it will be included in the next release |
Fantastic! |
@jesus-mg-ios I realize now that this only partly addresses your request. What is the use case for the custom variables you mention? Couldn't you just hard-code the values in your header template? |
For example, if you want to create a check method to review files periodically, you could add the date the file was modified (from git) and/or reviewed. Or maybe you want to add a variable Module name, eg, imagine that you have 2 modules with different files, in each module you have the file header with the module name on the top (that matches with one of the parent folders), when you change one file from one module to the other, the file header must be updated reflecting the correct module. |
@jesus-mg-ios you can do all that now by generating your header template using a script and setting it via the command line though, right? Is there any difference between doing the variable substitution yourself vs having SwiftFormat do it for you? |
Yes, you could even add the header format that Swift format already does using a script, isn't it? So the aim is to remove duplicity. |
@jesus-mg-ios right, but the idea with the built-in variables is that it's easier than figuring out how to get those values yourself. If you already have to write the code to extract the modified date from git or whatever then it doesn't seem to add much benefit. I could add the modified date as a built-in variable if that's something you want? Getting the module name would be trickier as I'm not sure how you'd infer that without parsing the project file or something |
Okey, the modified date as built-in is a nice improvement, so for my side go ahead with it. The other one I could try to manage it using another script. |
We can improve it, by adding a way to insert variables and, using the created {created.year} optionally not from the file, but from the git.
If someone could instruct me on how to add the functionality (Where I can see this) I would try to add it.
(
SwiftFormat/Sources/Rules.swift
Line 4331 in 4bf4751
Proposal:
Variables passed from the command line and added in .swiftformat as ${{variableName}}, the others can be {created.date.git} and {created.date.git.year} {modified.date.git} {modified.date.git.year}
The text was updated successfully, but these errors were encountered: