fix: attribute PSR compatibility
This partially fixes #2360, in the sense that formatting now matches PSR guidelines. It will still split across multiple lines if need be though.
I’m confused I ran the exact same command on my laptop and everything passes; did I miss something?
Hello, @apollisa The test fails because the AST changed, run AST_COMPARE=1 yarn test you'll see the failure on local.
Oh indeed with AST_COMPARE the tests do fail in local :+1:
Should Prettier keep the AST unchanged? Because here if we want to stick with the PSR rules, we must split attributes that span multiple lines:
#[
IA("interface"),
\\Looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong\\Namespace\\WithStuff\\IB
]
becomes
#[IA("interface")]
#[\\Looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong\\Namespace\\WithStuff\\IB]
I'm not sure if this will be accepted, but if it's expected to produce different AST, you'll need change the old shape to new shape in https://github.com/prettier/plugin-php/blob/main/src/clean.mjs
Well I’m sorry I can’t seem to make it to work :thinking: It would seem that the clean function only gets a single attribute group at a time, so I don’t see how I could split it into multiple ones
Looking at how printAttrs is called, I think you can
if (node.kind === 'arrowfunc' || node.kind === 'parameter' /* || other kinds */) {
// Update newObj.attrGroups
}
clean should also have a third argument to access parent, I believe.