Skip to content
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

Open
jesus-mg-ios opened this issue Jun 4, 2024 · 9 comments
Open

File header rule improvement #1716

jesus-mg-ios opened this issue Jun 4, 2024 · 9 comments

Comments

@jesus-mg-ios
Copy link

jesus-mg-ios commented Jun 4, 2024

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.

(

case var .replace(string):
)

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}

@nicklockwood
Copy link
Owner

This functionality is already landed in the develop branch, it will be included in the next release

@nicklockwood nicklockwood added enhancement fixed in develop bug/feature resolved in the develop branch labels Jun 4, 2024
@jesus-mg-ios
Copy link
Author

Fantastic!
@nicklockwood Could you let me know which was the PR?

@nicklockwood
Copy link
Owner

@jesus-mg-ios #1507

@nicklockwood
Copy link
Owner

@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?

@jesus-mg-ios
Copy link
Author

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.

@nicklockwood
Copy link
Owner

@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?

@jesus-mg-ios
Copy link
Author

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.

@nicklockwood
Copy link
Owner

@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

@jesus-mg-ios
Copy link
Author

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.

@nicklockwood nicklockwood removed the fixed in develop bug/feature resolved in the develop branch label Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants