Skip to content

[TASK] Use delegation for DeclarationBlock -> RuleSet #1194

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

JakeQZ
Copy link
Collaborator

@JakeQZ JakeQZ commented Mar 19, 2025

... rather than inheritance.

This will allow DeclarationBlock to instead extend CSSBlockList in order to support
CSS nesting.

This is a slightly-breaking change, since now CSSBlockList::getAllRuleSets() will include the RuleSet property of the DeclarationBlock instead of the DeclarationBlock itself.

Part of #1170.

@JakeQZ JakeQZ added cleanup css4 Relating to features introduced in CSS4 labels Mar 19, 2025
@JakeQZ JakeQZ self-assigned this Mar 19, 2025
@JakeQZ JakeQZ marked this pull request as draft March 19, 2025 00:56
@coveralls
Copy link

coveralls commented Mar 19, 2025

Coverage Status

coverage: 58.507% (-1.2%) from 59.751%
when pulling 5448e91 on task/declarationblock-delegate-ruleset
into 8c4a77e on main.

@JakeQZ JakeQZ force-pushed the task/declarationblock-delegate-ruleset branch from 7800603 to 73956e9 Compare March 19, 2025 02:06
@JakeQZ JakeQZ added css3 and removed css4 Relating to features introduced in CSS4 labels Mar 20, 2025
@JakeQZ JakeQZ force-pushed the task/declarationblock-delegate-ruleset branch 5 times, most recently from c1c27a9 to 3a278e0 Compare April 2, 2025 00:31
@JakeQZ JakeQZ force-pushed the task/declarationblock-delegate-ruleset branch 5 times, most recently from c935f2c to 1f908cf Compare April 14, 2025 15:25
@JakeQZ
Copy link
Collaborator Author

JakeQZ commented Apr 15, 2025

Would be good to resolve #1247 before moving on with this.

@JakeQZ JakeQZ force-pushed the task/declarationblock-delegate-ruleset branch from 1f908cf to 1ce18b7 Compare May 6, 2025 17:40
@JakeQZ
Copy link
Collaborator Author

JakeQZ commented May 8, 2025

This is almost ready for review, but some tests need to be added. Before doing so, I'd appreciate a pre-review from you: @sabberworm, @oliverklee.

I'm not keen on the having the various chaining methods in DeclarationBlock, but to avoid breaking changes they are necessary. A trait can be used for testing them in the same way as their counterparts in RuleSet.

For DeclarationBlock to contain nested rules, it needs to extend CSSBlockList. RuleSet cannot be a trait; it needs to be a fully-fledged type for methods like getAllRuleSets().

This is the only realistic way forward I see for now, in an 'Agile' sense, which can deliver what is required now, without wholescale refactoring or breaking changes.

Copy link
Collaborator

@oliverklee oliverklee left a comment

Choose a reason for hiding this comment

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

I like this approach!

@oliverklee
Copy link
Collaborator

Maybe as another spin-off PR (or prepatch), we can introduce the interface and have one class implement it.

@JakeQZ JakeQZ force-pushed the task/declarationblock-delegate-ruleset branch 2 times, most recently from a9790f1 to e123988 Compare June 26, 2025 21:40
JakeQZ added a commit that referenced this pull request Jun 26, 2025
The trait provides tests for classes implementing `RuleContainer`.
The test methods and data providers have been moved verbatim to the trait from
`RuleSetTest`.
Will be needed for #1194.
JakeQZ added a commit that referenced this pull request Jun 26, 2025
The trait provides tests for classes implementing `RuleContainer`.
The test methods and data providers have been moved verbatim to the trait from
`RuleSetTest`.

Will be needed for #1194.
oliverklee pushed a commit that referenced this pull request Jun 27, 2025
The trait provides tests for classes implementing `RuleContainer`.
The test methods and data providers have been moved verbatim to the trait from
`RuleSetTest`.

Will be needed for #1194
@JakeQZ JakeQZ force-pushed the task/declarationblock-delegate-ruleset branch from 61d3317 to 17885d0 Compare June 27, 2025 12:37
@JakeQZ
Copy link
Collaborator Author

JakeQZ commented Jun 27, 2025

I think all pre-PRs that can be separated have been completed now.

@JakeQZ JakeQZ marked this pull request as ready for review June 27, 2025 14:26
@JakeQZ JakeQZ requested review from oliverklee and sabberworm June 27, 2025 14:26
*/
abstract class RuleSet implements CSSElement, CSSListItem, Positionable, RuleContainer
class RuleSet implements CSSElement, CSSListItem, Positionable, RuleContainer
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can move the changes to RuleSet (plus test coverage) to a pre-patch, too.

@JakeQZ JakeQZ force-pushed the task/declarationblock-delegate-ruleset branch from bcf5cbe to 6974745 Compare June 30, 2025 00:47
@oliverklee
Copy link
Collaborator

This PR needs a rebase.

Apart from that, I think we can move de-abstracting the RuleSet class (and creating a dedicated testcase for it by copying some existing tests) into a pre-PR.

@JakeQZ
Copy link
Collaborator Author

JakeQZ commented Jul 17, 2025

This PR needs a rebase.

It is impossible to rebase now, because git does it one commit at a time, and I probably included changes in the wrong commits in a previous rebase. I tried merge. Might be able to fix the resulting errors. Otherwise will have to start over.

Copy link
Collaborator Author

@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.

This needs starting over. It's a mess now.

@JakeQZ JakeQZ marked this pull request as draft July 17, 2025 23:27
@JakeQZ
Copy link
Collaborator Author

JakeQZ commented Jul 17, 2025

I tried undoing lastest merge, but it's still a mess. I can't even get back to where I was now. Will take some time redoing.

@oliverklee
Copy link
Collaborator

I tried undoing lastest merge, but it's still a mess. I can't even get back to where I was now. Will take some time redoing.

In my experience, when I had a PR from which I spun off some pre-PRs, I also sometimes had nasty merge conflicts when rebasing. In those cases, it made things a lot easier if I squashed the existing commits in the PR branch before rebasing.

JakeQZ added a commit that referenced this pull request Jul 18, 2025
... adding internal `render` method.

Precursor to #1194.
@JakeQZ
Copy link
Collaborator Author

JakeQZ commented Jul 18, 2025

I tried undoing lastest merge, but it's still a mess. I can't even get back to where I was now. Will take some time redoing.

In my experience, when I had a PR from which I spun off some pre-PRs, I also sometimes had nasty merge conflicts when rebasing. In those cases, it made things a lot easier if I squashed the existing commits in the PR branch before rebasing.

I think I have somehow managed to rebase without including any changes from main. So now the diffs are showing that all the changes from main are being reverted. I did git rebase --abort when I got in a muddle.

If I could somehow reset the branch to the state it was in immediately after the commit "Reorder construction", then squashing may be possible, but I'm not sure how to do that.

@oliverklee
Copy link
Collaborator

If I could somehow reset the branch to the state it was in immediately after the commit "Reorder construction", then squashing may be possible, but I'm not sure how to do that.

git reflog allows you to list all recent commits and which actions lead to them, including rebases, branch switches etc. So this might be helpful. (It has saved my work a couple of times.)

@JakeQZ JakeQZ force-pushed the task/declarationblock-delegate-ruleset branch 2 times, most recently from 6974745 to 184f865 Compare July 18, 2025 23:48
... rather than inheritance.

This will allow `DeclarationBlock` to instead extend `CSSBlockList` in order
to support
[CSS nesting](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_nesting).

This is a slightly-breaking change, since now `CSSBlockList::getAllRuleSets()`
will include the `RuleSet` property of the `DeclarationBlock` instead of the
`DeclarationBlock` itself.

Part of #1170.
@JakeQZ JakeQZ force-pushed the task/declarationblock-delegate-ruleset branch from 184f865 to 34c8708 Compare July 19, 2025 00:22
@JakeQZ
Copy link
Collaborator Author

JakeQZ commented Jul 19, 2025

If I could somehow reset the branch to the state it was in immediately after the commit "Reorder construction"

git reset -hard {SHA-of-last-commit-before-attempted-rebase}

... undid the failed rebase/merge. I think when I tried merging instead (via GitHub), that moved the 'common ancestor' point, but when I reverted the merge, it was not moved back.

then squashing may be possible, but I'm not sure how to do that.

git reset -soft {SHA-of-first-branch-commit}
git commit --amend

... did the squashing.

In my experience, when I had a PR from which I spun off some pre-PRs, I also sometimes had nasty merge conflicts when rebasing. In those cases, it made things a lot easier if I squashed the existing commits in the PR branch before rebasing.

That helped immensely; thanks. Instead of (presumably) 9 rounds of conflict resolution, including for files with no overall conflict, there was just one round, for the two files that actually had conflicts. (I'm used to Perforce, which does the merge all at once, and also has a visual editor for 3-way merging. Keeping a cool head also helps ;))

Rebase now done !) Thanks <3

@oliverklee
Copy link
Collaborator

I'm used to Perforce, which does the merge all at once, and also has a visual editor for 3-way merging.

I use PhpStorm as my IDE, and IIRC it also have a nice 3-way-merge UI. (Disclaimer: I don't use UIs for git stuff and hence can only report what I hear and see from other people.)

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

Successfully merging this pull request may close these issues.

3 participants