nicklockwood / SwiftFormat

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

How to disable swiftformat inside a dir? #1148

Open Lakr233 opened 2 years ago

Lakr233 commented 2 years ago

I always mis-execute this command at ~ that will then f*** me up.

1 Is it possible to disable swiftformat at a dir completely? 2 Is is possible to put a check(y/n) before executing the command line when detecting ~?

nicklockwood commented 2 years ago

@Lakr233 this is actually harder than it ought to be. You could put a .swiftformat file in your home directory with:

--rules void
--disable void

This enables only the void rule, then disables that too, so that all rules are disabled. Then you can re-enable the rules you want in another .swiftformat file in your project.

nicklockwood commented 2 years ago

@Lakr233 oh wait, there is a slightly easier way: You can put this in the file instead:

--exclude *
--unexclude path/to/project

Note that the --unexclude must go in the same .swiftformat file as the --exclude * otherwise nothing in any child of that directory will be formatted, even if you format it directly (this is arguably a bad design).

nicklockwood commented 2 years ago

@Lakr233 I've slightly improved this in 0.49.5. You can now use

--disable all

Instead of

--rules void
--disable void

which is a bit less awkward.