nicklockwood / SwiftFormat

A command-line tool and Xcode Extension for formatting Swift code
MIT License
7.62k stars 623 forks source link

File Header rule fails on CI #1724

Open jesus-mg-ios opened 3 weeks ago

jesus-mg-ios commented 3 weeks ago

Hi I'm comming up with an error on xcode cloud trying to use the new {created.date}.

The rules I'm using are:

--exclude .somefolders/
--wraparguments before-first
--wrapcollections before-first
--disable trailingClosures
--disable wrapMultilineStatementBraces
--disable initCoderUnavailable
--maxwidth 120
--header "\n{file}\nCopyright (c) {created.date} company. All rights reserved.\nCreated by company.\n"

The first step was adding in the script: git fetch --unshallow

After that, the complaining count went down.

Using same version on local and CI, but when you run lint, for only some files swiftformat complains. (after doing git fetch --unshallow less files were affected) :

filePath..... 
-- rules applied: fileHeader

SwiftFormat completed in time's.
Source input did not pass lint check.

Any idea on how to deal with this would be much appreciated.

nicklockwood commented 3 weeks ago

cc @hampustagerud - any idea what the problem is here?

nicklockwood commented 3 weeks ago

@jesus-mg-ios FYI I think {created.date} needs to be {created.year}, although that may not be the cause of your issue

jesus-mg-ios commented 3 weeks ago

@jesus-mg-ios FYI I think {created.date} needs to be {created.year}, although that may not be the cause of your issue

Sorry for the mistake, same result using {created.year}

bcybs commented 2 weeks ago

Same issue - however what I'm experiencing but never noticed before is that when I run swiftformat . on the project with {created.year} in the header template it sets every file to the current year. Perhaps this is the issue - it's now working as expected on CI but from SwiftFormat it's setting the current year not the created year?

nicklockwood commented 2 weeks ago

@bcybs prior to the git integration added in the last release, the created date was derived from the file metadata. For files stored in git, that probably ends up being the checkout date rather than the original creation date.

hampustagerud commented 1 week ago

If the repo is checked out with only one commit (--depth 1) then that will be the commit creating the file, which is most likely why the errors are thrown. I am not sure what the best solution would be but some of them include:

If I were to implement a CI with this I'd try with replacing git clone --depth 1 ... with git clone --filter=blob:none .../git clone --filter=tree:0 ... to avoid cloning everything (for speed) but keeping the entire history 🙂 more info