Page MenuHomePhabricator

Add a linter rule for `use` statement namespace prefixes
ClosedPublic

Authored by joshuaspence on Nov 19 2015, 5:46 AM.
Tags
None
Referenced Files
F15198435: D14517.diff
Sun, Feb 23, 2:57 AM
Unknown Object (File)
Sun, Feb 16, 9:34 PM
Unknown Object (File)
Sat, Feb 1, 11:54 AM
Unknown Object (File)
Thu, Jan 30, 12:07 PM
Unknown Object (File)
Wed, Jan 29, 10:32 PM
Unknown Object (File)
Wed, Jan 29, 10:24 AM
Unknown Object (File)
Tue, Jan 28, 12:49 AM
Unknown Object (File)
Jan 23 2025, 8:08 AM
Subscribers

Details

Summary

When importing or aliases a symbol with a use statement, the leading namespace separator is optional and does not modify the behavior. That is, use \X is equivalent to use X. As such, the latter syntax should be preferred because it is more concise.

According to the PHP documentation:

Note that for namespaced names (fully qualified namespace names containing namespace separator, such as Foo\Bar as opposed to global names that do not, such as FooBar), the leading backslash is unnecessary and not recommended, as import names must be fully qualified, and are not processed relative to the current namespace.

Test Plan

Added test cases.

Diff Detail

Repository
rARC Arcanist
Branch
master
Lint
Lint Passed
Unit
Test Failures
Build Status
Buildable 8927
Build 10470: Run Core Tests
Build 10469: arc lint + arc unit

Event Timeline

joshuaspence retitled this revision from to Add a linter rule for `use` statement namespace prefixes.
joshuaspence updated this object.
joshuaspence edited the test plan for this revision. (Show Details)
joshuaspence edited the test plan for this revision. (Show Details)
joshuaspence added a reviewer: epriestley.
epriestley edited edge metadata.
This revision is now accepted and ready to land.Nov 23 2015, 3:28 PM
This revision was automatically updated to reflect the committed changes.