CLI design
aanand opened this issue · 7 comments
High-level thoughts, based on a quick skim over gofmt, pep8/flake8/autopep8, eslint and a few language interpreters:
gofmt
fixes by default and prints to stdout. It has a-w
option to fix in place, and a-d
option to print a diff instead of the fixed output.eslint
complains by default and fixes with--fix
.pep8
andflake8
have no fixing functionality;autopep8
seems to be the canonical fixer. Not much help.
I'm leaning towards fixing as the default behaviour and checking as a flag (ruby
and node
have -c|--check
).
Additionally, I think checking should by default print nothing to stdout.
Should we accept directories as arguments and recursively scan them for *.{yml,yaml}
files? Every linter mentioned above does, so I think the answer is yes.
yapf may also be worth a look, it's a python autoformatter in the vein of gofmt.
+1 on recursively scanning directories btw, while you can do this with find it seems like it would be a common use case.
yapf looks cool - we should run it on our own code.
I'm leaning towards fixing as the default behaviour and checking as a flag (ruby and node have -c|--check).
I think it should be called fixyaml
then, not safeyaml
:-)
The problem with 'fix by default' is that we're not doing something unambiguous, and it could easily screw up your files
Additionally, I think checking should by default print nothing to stdout.
OTOH: this seems good, and we can add a --foo
option or something to echo it
The problem with 'fix by default' is that we're not doing something unambiguous, and it could easily screw up your files
This is fair - gofmt can guarantee that, if you've written valid Go, it'll output valid Go that conforms to its style rules. We can't make the same guarantee, because too much stuff is too difficult to repair.
Still: I believe there's enough low-hanging fruit to make repairing worth the effort, especially when it comes to text editor/pre-commit integration.
I believe there's enough low-hanging fruit to make repairing worth the effort, especially when it comes to text editor/pre-commit integration.
I also very much want this, especially if there’s (eventually) an option that lets my editor highlight my broken lines right away.
I believe there's enough low-hanging fruit to make repairing worth the effort
The fixes we've done so far are semantically meaningful though. The easiest changes to make safely automatically are ones of whitespace and formatting, removing comments, etc.
There are some things we could fix automatically that are semantic, quoting barewords. However, unless we work on the full yaml spec as input, we can't guarantee that these barewords would parse the same as strings.
The only safe option is --force-commas
so far. Even --force-strings
means that on: off
becomes "on": "off"
.
--fix-nodent
could be turned on b default, but that's the same as changing the safe yaml spec to allow lists to be indented to same level as containing map.
Which is my other problem with 'fix by default', it effectively changes safeyaml to mean 'safeyaml +whatever we can correct' and that latter part needs to be interactive, or user driven.