-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[FEATURE] Add support to import namespaces for sniffs #25
Conversation
During the development of sniffs for the CMS TYPO3 and the framework FLOW3 we create some own codesniffs. Out folder structure looks like: |-TYPO3 |--Sniffs |-TYPO3v4 |--ruleset.xml |-FLOW3 |--ruleset.xml Folder TYPO3 contains all sniffs. TYPO3v4 and FLOW3 implement only a subset of the sniffs, which are located in FLOW3. At the moment we have to symlink the TYPO3-Folder into the PHP_CodeSniffer standard directory to use this. This is not a nice solution. This commit try to fix this problem. This commit introduces to import sniff namespaces. Imagine you add your rules like <rule ref="TYPO3.Files.OneClassPerFile" /> If there is no symlink in your standard directory for TYPO3 an exception will be thrown. With this commit you have the possibility to import the namespace TYPO3 like <namespace-import name="TYPO3" ref="../TYPO3/" /> Now the TYPO3 standard is known without symlinking :)
I really like this feature, but there are similar features already supported in the ruleset.xml format. You can load a standard by specifying the path, or a directory of sniffs, or a single sniff. The only problem is that it doesn't currently support relative paths. So maybe instead of adding a new namespace tag that has relative path support, I should just change the existing RULE tag to support relative paths. So then you'd include the sniffs you want like:
or for all sniffs in the Files dir
or if it is easier to include the whole TYPO3 standard and just exclude some sniffs:
|
By the way, I'm going to implement the relative path feature anyway because it would be good to have. It's also a pretty easy change given refs can't start with a "." (except if your are using a hidden dir I guess) and so I can assume this is a relative path. If it isn't and realpath() fails, I can just try the fallback code. Commit is here: e329880 |
Hey, first of all thanks for taking care of my "wish" / "issue". It is awesome that you have implemented the relative path feature so quick. Thanks for that.
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="TYPO3v4">
<description>The coding standard for TYPO3 Version 4 / 6. Have a look at http://forge.typo3.org/projects/team-php_codesniffer/wiki</description>
<!-- Arrays -->
<rule ref="Squiz.Arrays.ArrayBracketSpacing" />
<!-- Files -->
<rule ref="../TYPO3/Sniffs/Files/OneClassPerFileSniff.php" />
<rule ref="../TYPO3/Sniffs/Files/LowercasedFilenameSniff.php" />
<rule ref="../TYPO3/Sniffs/Files/EncodingUtf8Sniff.php" />
<rule ref="../TYPO3/Sniffs/Files/OneInterfacePerFileSniff.php" />
<rule ref="Generic.Files.LineEndings" />
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="130"/>
<property name="absoluteLineLimit" value="200"/>
</properties>
</rule>
<rule ref="../TYPO3/Sniffs/Files/IncludingFileSniff.php" />
<!-- Classes -->
<rule ref="../TYPO3/Sniffs/Classes" />
<rule ref="Squiz.Classes.SelfMemberReference" />
</ruleset>
On my machine, the following error occured:
My solution was to change the realpath-line in your commit (e329880) to $realpath = realpath(self::$standardDir.'/'.$sniff); Just remove the "dirname()" call. If you need help to reproduce my error, just drop me a line and i will setup a demo. After fixing this "bug" / "feature" (?) my pull request is obsolete and can be closed, of course. |
Hi Andy, I've updated the code to do an additional check because the Thanks for the great test instructions. Greg On Sat, Apr 28, 2012 at 1:33 AM, Andy Grunwald
Greg Sherwood Squiz Labs Pty. Ltd. Suite 4, 7 Parkes St Parramatta NSW 2150 |
Hey Greg, thx for your work. The new commit (40d804d) works perfect! |
During the development of PHP_CodeSniffer-Sniffs for the CMS TYPO3 and the framework FLOW3 we create some own codesniffs. Our folder structure looks like:
|-TYPO3
|--Sniffs
|-TYPO3v4
|--ruleset.xml
|-FLOW3
|--ruleset.xml
Folder "TYPO3" contains all sniffs (Sniffpool). TYPO3v4 and FLOW3 implement only a subset of the sniffs, which are located in TYPO3. At the moment we have to symlink the TYPO3-Folder into the PHP_CodeSniffer standard directory to use this standard. This is not a nice solution.
This pull request try to fix this problem. This commit introduces the possibility to import sniff namespaces. Imagine you add your rules like
in your ruleset.xml. If there is no symlink in your standard directory for TYPO3 during execution of your ruleset an exception will be thrown. With this commit you have the possibility to import the namespace TYPO3 like
Now the TYPO3 standard is known without symlinking :)
This feature makes it more easier for us and more independent from the standard directory.
What do you think about this? Your feedback is very welcome.