Skip to content

Add support to allow partial use rules per namespace#1856

Open
Toflar wants to merge 7 commits into
slevomat:masterfrom
Toflar:feature/allow-and-force-partial-namespace-uses
Open

Add support to allow partial use rules per namespace#1856
Toflar wants to merge 7 commits into
slevomat:masterfrom
Toflar:feature/allow-and-force-partial-namespace-uses

Conversation

@Toflar

@Toflar Toflar commented Jun 18, 2026

Copy link
Copy Markdown

Implements feature request in #1310

It adds namespace-aware control to SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly partial-use handling.

As already explained in the original issue, the reason why I would like to have this is that some codebases intentionally use partial references for selected packages, especially Doctrine ORM and Symfony Validator.

You can now either just allow them:

<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
	<properties>
		<property name="allowPartialUses" value="false"/>
		<property name="namespacesAllowedToUsePartially" type="array">
			<element value="Doctrine\ORM"/>
			<element value="Symfony\Component\Validator\Constraints as Assert"/>
		</property>
	</properties>
</rule>

or even enforce them:

<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
	<properties>
		<property name="allowPartialUses" value="false"/>
		<property name="namespacesRequiredToUsePartially" type="array">
			<element value="Doctrine\ORM"/>
			<element value="Symfony\Component\Validator\Constraints as Assert"/>
		</property>
	</properties>
</rule>

@Toflar Toflar marked this pull request as draft June 19, 2026 06:48
@Toflar Toflar force-pushed the feature/allow-and-force-partial-namespace-uses branch from 80b7915 to 0e1ab34 Compare June 19, 2026 13:47
@Toflar Toflar marked this pull request as ready for review June 19, 2026 13:51
@Toflar

Toflar commented Jun 19, 2026

Copy link
Copy Markdown
Author

Updated the PR so it now also allows namespace aliases properly supporting the Symfony\Component\Validator\Constraints as Assert as well. Initial PR description updated 😎

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.

1 participant