Skip to content

Yaml fixer - #18

Open
ninsuo wants to merge 4 commits into
umpirsky:masterfrom
blablacar:yaml-fixer
Open

Yaml fixer#18
ninsuo wants to merge 4 commits into
umpirsky:masterfrom
blablacar:yaml-fixer

Conversation

@ninsuo

@ninsuo ninsuo commented Dec 9, 2015

Copy link
Copy Markdown

I am not really satisfied by the result:

  • drops comments
  • dump's current formatting is quite not friendly (especially for hashes) (fixed)

Anyway this is a first draw, I'm open to suggestions :)

Comment thread src/Symfony/Upgrade/Fixer/YamlFixer.php Outdated

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return Yaml::dump($array);

@umpirsky

umpirsky commented Dec 9, 2015

Copy link
Copy Markdown
Owner

@ninsuo Awesome work man. 👍

I agree, comments and formatting are the issue, must think about possible solutions, if you have ideas feel free to share them.

@akovalyov

Copy link
Copy Markdown
Contributor

@ninsuo I think, current impl can handle also transforming Foo\Bar to 'Foo\\Bar' with help of https://github.com/symfony/yaml/blob/master/Escaper.php. Not sure about comments, Yaml parser seems to remove it aggressively. The only way I see is to parse comments manually and add it to the result file. However, I can be blind.

@ninsuo

ninsuo commented Dec 11, 2015

Copy link
Copy Markdown
Author

@akovalyov we don't need to escape \ on unquoted/single-quoted strings.

@umpirsky

Copy link
Copy Markdown
Owner

@ninsuo I like last indention changes. 👍

@Nyholm

Nyholm commented Dec 13, 2015

Copy link
Copy Markdown

I believe @akovalyov is correct.

We know we do not edit any keys. Can we check where the comments are relative a key, store them, run Yaml parser and dump and then re-add the comments?

@ninsuo

ninsuo commented Dec 13, 2015

Copy link
Copy Markdown
Author

Yep. This may be the solution. Will try it soon 👍

@weaverryan

Copy link
Copy Markdown

There's interest about this in the Symfony core and someone asked about this on Twitter yesterday: symfony/symfony#18079. @ninsuo are you still interested in this?

Thanks!

@ninsuo

ninsuo commented Mar 10, 2016

Copy link
Copy Markdown
Author

Hello @weaverryan,

I'm quite busy those last days, if somebody from the core want to tackle this, go ahead 👍

Thank you !

A

@weaverryan

Copy link
Copy Markdown

Or some other community member ;). Thanks @ninsuo for starting this and for the quick reply - now we know this issue is open for someone else!

@umpirsky

Copy link
Copy Markdown
Owner

@ninsuo So, comments is the issue we need to solve?

@weaverryan What do you think about the formatting? Is it acceptable?

@ninsuo

ninsuo commented Mar 10, 2016

Copy link
Copy Markdown
Author

Yes, my solution is quite naive and runs Yaml parser / dumper to clean your config files up.

But using this way, you drop all comments. Bad...

I'm guessing there will be no choice but develop a Yaml fixer that will keep formatting and comments, based on regular expressions or maybe more sophisticated...

@weaverryan

Copy link
Copy Markdown

I agree with @ninsuo - this solution won't do it. But the good news is that:

  1. @ninsuo made an awesome test for this PR. If someone were able to get that test to pass with a different method, that would prove it's good.

  2. We don't have to catch all the cases. Symfony will explode if there are any parse errors, so they're easy to find by a user. It's the sheer magnitude that exist in some projects that is a problem. If this fixed 90% of use-cases, that would be just fine.

Cheers!

@umpirsky

Copy link
Copy Markdown
Owner

Just want to add that we can think bigger then this. If we can do it using some third party tool, or e.g. ruby library, I would merge that as well.

We just need yaml parser/dumper that keeps comments.

I would try to avoid using regex magic, but if someone is good with that, why not.

The point is, this is just a tool that gets he job done, it does not necessarily need to be fancy, nor perfect as @weaverryan said.

I will try to look deeper if there is something out there that we can use to easily do this.

Thank you all for the effort. 👍

@xabbuh

xabbuh commented Mar 15, 2016

Copy link
Copy Markdown

You could think about forking the Symfony YAML component. What you would need to do then is to modify it such that comments were not stripped (probably you would have to mark them somehow to be able to dump them properly again). The advantage is that the Symfony parser already knows all the deprecated features and it's easy to handle them, most of them will probably be handled implicitly (I suggest to take the one from the upcoming 3.1 release as there are some more deprecations).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants