nicklockwood / SwiftFormat

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

Emit warnings for lintonly rules when running in format mode #1904

Open Cyberbeni opened 1 week ago

Cyberbeni commented 1 week ago

I think when someone runs the format command, they would expect warnings about issues that the formatter can't fix (In our case, lintonly rules), for example ESLint works this way when passing the --fix option. Having a wrapper to run format and then lint can cause unnecessary overhead. I don't think it needs a new option, this should just be the way it works when running in format mode. Generated warnings would result in return code 1 when running in strict mode. Generated warnings would not result in return code 1 when running without lenient mode. What do you think? I can work on this sometime in the near future. The idea would be to start here and then just resolve the compiler errors: format-and-lint.patch

nicklockwood commented 1 week ago

I agree this is a good way for it to work. I intended this originally, but it turned out to be tricky to handle both lint and format in a single pass due to the current architecture. I'll try to revisit the idea

Cyberbeni commented 1 week ago

Other idea is to keep the Options type as is, also set lenient if lint and not strict, and then if we have lintonly rules and not in lint mode then just generate a separate Options for linting that only contains the lintonly rules then run it twice from this point on: https://github.com/nicklockwood/SwiftFormat/blob/ed75a316f2f2868b9181ae8d1c7182bf8d97f269/Sources/CommandLine.swift#L434