Skip to content

[TASK] Deprecate sSpaceAfterListArgumentSeparator being an array #876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

oliverklee
Copy link
Collaborator

No description provided.

@oliverklee oliverklee added this to the 8.8.0 milestone Feb 3, 2025
@oliverklee oliverklee self-assigned this Feb 3, 2025
Copy link
Collaborator

@JakeQZ JakeQZ left a comment

Choose a reason for hiding this comment

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

Wow. I couldn't think of a way of achieving the seemingly impossible (well, not impossible but it looked like a lot of work). But you just have. Very clever. (Do you play chess?)

But there's a premature change here, I think.

* @var string
* #866 `array` is deprecated in version V8.8.0, will be changed to `string` only in V9.0.0.
*
* @var string|array<string, string>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Too soon. We need to still allow array until 9.0.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oops, was looking at the diff the wrong way round. But...

Can we use @deprecated in the DocBlock here for partial deprecation?

@JakeQZ
Copy link
Collaborator

JakeQZ commented Feb 4, 2025

But there's a premature change here, I think.

I was mistaken about that, but wonder if it's possible to use @deprecated in the DocBlock for a partial deprecation...

@oliverklee
Copy link
Collaborator Author

I was mistaken about that, but wonder if it's possible to use @deprecated in the DocBlock for a partial deprecation...

As far as I know, that's not possible. @deprecated annotations always refer to one "thing" in its entirety, be it class, method, property or parameter.

@oliverklee
Copy link
Collaborator Author

Wow. I couldn't think of a way of achieving the seemingly impossible (well, not impossible but it looked like a lot of work). But you just have. Very clever. (Do you play chess?)

Working within the limits of written communication, I'm not completely sure whether you meant this as genuine appreciation, or whether you were being sarcastic.

Assuming it was the former: Why, thanks! ❤️ (I used to play some chess as a child, but gave up on it quite soon. Nowadays, I really enjoy escape rooms and also logic puzzles. What, you wanted to get some real work done today instead? 😉)

Copy link
Collaborator

@JakeQZ JakeQZ left a comment

Choose a reason for hiding this comment

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

Thinking about this a bit more, I'm not convinced we can deprecate/drop support for the array arguments for list separator spacing.

Consider

color: rgba(0, 85, 0, 0.5); /* "legacy" syntax */
color: rgba(0 85 0 / 0.5); /* "modern syntax */

These examples use the typical human-readable format which is also used in MDN and W3C examples.

Both / and , are list separators. But if we stop allowing a distinction between them for output spacing, the above output would not be possible. The choice would be between

color: rgba(0 , 85 , 0 , 0.5); /* "legacy" syntax */
color: rgba(0 85 0 / 0.5); /* "modern syntax */

and

color: rgba(0, 85, 0, 0.5); /* "legacy" syntax */
color: rgba(0 85 0/ 0.5); /* "modern syntax */

both of which are ugly and not as humanly-readable.

I was mistaken about that, but wonder if it's possible to use @deprecated in the DocBlock for a partial deprecation...

As far as I know, that's not possible. @deprecated annotations always refer to one "thing" in its entirety, be it class, method, property or parameter.

Indeed that seems so. Moreover,

Structural Elements tagged with the @deprecated tag will be listed in the Deprecated elements report and their name will be shown as strike through,

So bending the rules won't work. And the tag does not have an inline option (e.g. {@deprecated} within a parameter description).

Wow. I couldn't think of a way of achieving the seemingly impossible...

Working within the limits of written communication, I'm not completely sure whether you meant this as genuine appreciation, or whether you were being sarcastic.

The former. See #866 (comment). I didn't think of simply deprecating the test method referred to in the documentation along with adding a deprecation note to the property.

(I used to play some chess as a child, but gave up on it quite soon. Nowadays, I really enjoy escape rooms and also logic puzzles. What, you wanted to get some real work done today instead? 😉)

(I wondered, because chess often involves seeing a cunning yet simple way through - and we could do with more participants in our online chess tourneys. Thanks for the puzzles link. Some are the same type that appear in daily newspapers along with the crossword. I occasionally try them. My Mum loves them, so I'll pass on the link.)

@JakeQZ
Copy link
Collaborator

JakeQZ commented Feb 5, 2025

Thinking about this a bit more, I'm not convinced we can deprecate/drop support for the array arguments for list separator spacing.

Maybe we can for 'after' (though not 'before'), but I'm not 100% convinced we may not have missed a case where the variation for different separators is actually needed to render human-readable CSS.

@sabberworm
Copy link
Collaborator

I didn’t follow any of the discussions leading up to this so I’m curious: what’s the rationale for this change?

@oliverklee
Copy link
Collaborator Author

what’s the rationale for this change?

I'm generally working on these things:
a) covering the existing code with tests,
b) replacing magic methods with explicit existing methods, and
c) making type declarations as correct and specific as possible (including native types where possible) so we can make use the interpreter's type checks and PHPStan's checks.

In the process, I added tests for the (hitherto) magic getters and setters of OutputFormat in #847, #862 and #867. Then I replaced the magic getters and setters with explicit methods with native type declarations in #871.

This lead me to discover that at least the test deprecated here relied on OutputFormat.sSpaceAfterListArgumentSeparator allowing arrays in addition to strings (which meant that the current type annotation string was either incorrect/incomplete, or the code using it was incorrect). So currently this test is blocking the explicit accessor methods with native type declarations.

I prefer to have types that are as narrow is possible, and to use native type declarations as much as possible.

So that's the rationale. :-)

@sabberworm Maybe you can shed some light on this: Does it make sense to enforce this property being string only in 9.0? Or is allowing arrays as well important, and we need to allow that in the getter and setter as well?

@sabberworm
Copy link
Collaborator

I suppose it’s sensible to allow customizing the whitespace for specific separators but I agree it should not clash with type annotations. IMO we could change setSpaceAfterListArgumentSeparator to only allow strings but allow overrides being registered with a separate method, e.g. setSpaceAfterListArgumentSeparatorOfType($type, $space).

@oliverklee
Copy link
Collaborator Author

Thanks! I propose we add a new typesafe property and method when we need it.

@JakeQZ
Copy link
Collaborator

JakeQZ commented Feb 5, 2025

Thanks! I propose we add a new typesafe property and method when we need it.

We'd need to add this before deprecating the possibility of the property being an array, wouldn't we? So the deprecation message can become

array is deprecated in version V8.8.0, will be changed to string only in V9.0.0. To set the spacing for specific separators, use sSpaceAfterListArgumentSeparatorOfType instead.

@oliverklee
Copy link
Collaborator Author

I propose we drop the functionality of setting this to an array without replacement altogether for the time being, and re-add it (with the corresponding method) when and if we need this.

@JakeQZ
Copy link
Collaborator

JakeQZ commented Feb 6, 2025

I propose we drop the functionality of setting this to an array without replacement altogether for the time being, and re-add it (with the corresponding method) when and if we need this.

For the reasons I mentioned in #876 (review), I think we need this, at least for the counterpart sSpaceBeforeListArgumentSeparator. And if we have it for one, we may as well for the other, as it's hardly any extra effort (just a case of 'rinse and repeat').

I think the ability to unminify CSS and/or render it in a human-readable format is an important feature of the library. Removing the option of different-spacing-according-to-separator breaks that feature.

Also, that feature is almost zero-cost in terms of maintenance. (By far the biggest maintenance cost is changes to the CSS spec for parsing, dictated by the GAFAMs, who are beyond reproach.)

I'd be more than happy to create a PR to add the ...SeparatorOfType alternative suggested by @sabberworm, whilst retaining the original array option (to be deprecated), and still using the magic methods (so it can easily be backported). Might take a couple of days. Once that's done, this PR can proceed. @oliverklee, have I persuaded you?

@oliverklee
Copy link
Collaborator Author

Yes, let's do this. 🙏 Please go ahead!

@oliverklee
Copy link
Collaborator Author

I‘d prefer the new method to be specific to passing an array, though (both in naming as well as the parameter type), instead of adding a general method that allows passing the type of the other parameter.

JakeQZ added a commit that referenced this pull request Feb 6, 2025
`SpaceBeforeListArgumentSeparators` and `SpaceAfterListArgumentSeparators`
are added to allow for different spacing for different separators.

`SpaceBeforeListArgumentSeparator` and `SpaceAfterListArgumentSeparator`
will specify the default spacing.  Setting these as an array is deprecated.

Resolves #866, #876, #878.
oliverklee pushed a commit that referenced this pull request Feb 6, 2025
`SpaceBeforeListArgumentSeparators` and `SpaceAfterListArgumentSeparators`
are added to allow for different spacing for different separators.

`SpaceBeforeListArgumentSeparator` and `SpaceAfterListArgumentSeparator`
will specify the default spacing.  Setting these as an array is deprecated.

Resolves #866, #876, #878.
@oliverklee oliverklee closed this Feb 6, 2025
@oliverklee oliverklee deleted the task/deprecate-array branch February 6, 2025 16:20
@sabberworm
Copy link
Collaborator

sabberworm commented Feb 6, 2025

I‘d prefer the new method to be specific to passing an array, though (both in naming as well as the parameter type), instead of adding a general method that allows passing the type of the other parameter.

Sorry for the confusion. The method I suggested would take two strings. The $type name of the parameter was referring to the type of the list separator.

@JakeQZ
Copy link
Collaborator

JakeQZ commented Feb 6, 2025

I‘d prefer the new method to be specific to passing an array, though (both in naming as well as the parameter type), instead of adding a general method that allows passing the type of the other parameter.

Sorry for the confusion. The method I suggested would take two strings. The $type name of the parameter was referring to the type of the list separator.

In #880, I added an additional separate method accepting an array (only), whose values would override the default string set by the original method. This was simpler to implement than having methods to set the values in the array individually, which would have also needed a means to unset elements.

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.

3 participants