SwiftLint icon indicating copy to clipboard operation
SwiftLint copied to clipboard

Ignore .build folders by default

Open a7ex opened this issue 1 year ago • 1 comments

New Issue Checklist

New rule request

Since compiling with swift by default compiles into the hidden folder ".build" and there are checkouts of swift packages contained in the .build folder, wouldn't it be a good idea, if SwiftLint skips sich a .build folder by default?

We had a case, where an unexperienced user must have called swift build at some point in the - otherwise - Xcode project folder. It contained local swift packages and he wondered, why the build was failing with errors, when others could compile just fine. It turned out the errors were generated in the .build folders. Of course we found the issue and it was easily resolved, but it brought up the question to me: Should swiftlint really descend into these folders? 1.) They are most of the times "gitignored" and such can lead to different behaviour on different machines. 2.) There is no point really into descending into those "DerivedData" folders with their checkout Swift Packages, is it?

Therefore I think that rule should be opt-out.

a7ex avatar May 25 '24 11:05 a7ex

While .build would be a good candidate to be ignored by default, I'm actually not inclined to hard-code certain folders into SwiftLint and maintain them. Other build tools have other working folders SwiftLint could ignore as well. On the other hand, users might use these folders as part of their projects not knowing (and not caring) that some build tools conventionally use them.

That said, it's very easy to specify explicit includes and excludes in the configuration. That would be the recommended way,

SimplyDanny avatar Jun 10 '24 21:06 SimplyDanny

I've encountered the same issue. Interestingly, on some machines, the .build folder gets linted, while on others it doesn't. To ensure consistency and avoid unnecessary linting, we've decided to exclude the .build folder. As @a7ex mentioned, there's no benefit in linting the files in the .build directory.

sadaf-behbahani avatar Jul 24 '24 12:07 sadaf-behbahani

While .build would be a good candidate to be ignored by default, I'm actually not inclined to hard-code certain folders into SwiftLint and maintain them. Other build tools have other working folders SwiftLint could ignore as well. On the other hand, users might use these folders as part of their projects not knowing (and not caring) that some build tools conventionally use them.

That said, it's very easy to specify explicit includes and excludes in the configuration. That would be the recommended way,

Fair enough. I was just pointing out, that it could easily happen by accident and then would leave an unexperienced user with a not building project, because the hidden default folder of swift build causes it. I would rather have the user opt-out of excluding ".build" than requiring the user to opt-in to explicitly exclude ".build". But of course that is just my personal opinion and I was just trying to point out, that it is a pitfall, where the unexperienced user feel in and wasn't able to resolve. Such a tool should make our lives better and not more dangerous. But again, it is not up to me to decide. It was just a suggestion upon personal experience.

Feel free to close the issue, if you like.

a7ex avatar Jul 24 '24 13:07 a7ex

The logic to include and/or exclude files is already pretty complicated and a critical area with respect to performance issues. Sorry, but I really don't want to make things worse by supporting something like "default excludes" that can somehow be included again.

I'm definitely not saying, your proposal doesn't make any sense. I just don't think it's worth the effort to avoid a potential and harmless mistake an inexpert user makes once and then remembers forever.

SimplyDanny avatar Jul 26 '24 20:07 SimplyDanny

Thanks for clarifying, Danny. Very much appreciated. Of course, as I said before, it is up to the maintainers to weight the pros and the cons. But I am even asking myself whether a hidden folder should be considered worth recursing into at all. Hidden folders are hidden for a reason and I suspect that swiftlint doesn't recurse into the hidden .git folders as well. Granted it won't find .swift files there anyway, therefore recursing into .git folders is a waste of cpu cycles anyway. Nobody will ever put anything worth linting into a hidden folder. But in contrary to .git/ .build/ can indeed contain loads .swift files, which nobody really should want to waste cpu to lint.

But yes, I understand your reason to keep things simple, which from a maintainable point of view makes perfect sense.

Thank you very much for even taking the time to explain and consider.

a7ex avatar Jul 27 '24 07:07 a7ex