diff --git a/CHANGELOG.md b/CHANGELOG.md index e603df7f..c863bee3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -105,6 +105,7 @@ Please also have a look at our ### Fixed +- Ensure first rule added with `RuleSet::addRule()` has valid position (#1262) - Don't render `rgb` colors with percentage values using hex notation (#803) ### Documentation diff --git a/src/RuleSet/RuleSet.php b/src/RuleSet/RuleSet.php index 1fc1295e..c0a61f5f 100644 --- a/src/RuleSet/RuleSet.php +++ b/src/RuleSet/RuleSet.php @@ -117,6 +117,8 @@ public function addRule(Rule $ruleToAdd, ?Rule $sibling = null): void if ($rulesCount > 0) { $last = $rules[$rulesCount - 1]; $ruleToAdd->setPosition($last->getLineNo() + 1, 0); + } else { + $ruleToAdd->setPosition(1, 0); } } diff --git a/tests/Unit/RuleSet/RuleSetTest.php b/tests/Unit/RuleSet/RuleSetTest.php index 1fba6a22..100d0bf1 100644 --- a/tests/Unit/RuleSet/RuleSetTest.php +++ b/tests/Unit/RuleSet/RuleSetTest.php @@ -95,10 +95,6 @@ public function addRuleWithoutSiblingAddsRuleAfterInitialRulesAndSetsValidLineAn array $initialPropertyNames, string $propertyNameToAdd ): void { - if ($initialPropertyNames === []) { - self::markTestSkipped('currently broken - first rule added does not have valid line number set'); - } - $ruleToAdd = new Rule($propertyNameToAdd); $this->setRulesFromPropertyNames($initialPropertyNames);