Skip to content
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

Allow CLI args specified in ruleset.xml files to be relative to the ruleset file location #847

Closed
johnmaguire opened this issue Jan 4, 2016 · 6 comments

Comments

@johnmaguire
Copy link
Contributor

Hi, I'm the implementer of the bootstrap file functionality. I discussed a little bit in #793 how we wanted to use it to be able to set some options prior to our running of the sniffs (for example, setting the $allowedTypes class member.) Unfortunately, we ran into an issue given the fact that there's no relative way to set the bootstrap file.

We ship our CodeSniffer configuration in its own repository: https://github.com/barracudanetworks/Cuda-PHP-Code-Standards/

We have dozens of repositories that use it (we include it as a submodule, or you can just clone it once and setup your editor to look at the main repository.) The issue is that we need a way to be able to define the bootstrap file in the ruleset.xml, but we have no way of knowing the user's system layout (Do you keep your repos in /home/jmaguire/repos? /Users/jmaguire/repos? /Users/jmaguire/Repositories? What did you name the Cuda-PHP-Code-Standards clone?)

It'd be great to get support for this.

@gsherwood gsherwood changed the title Allow relative paths to bootstrap file Allow CLI args specified in ruleset.xml files to be relative to the ruleset file location Jan 14, 2016
@gsherwood
Copy link
Member

I'm going to use chdir() to make all relative paths inside ruleset CLI args be relative to the ruleset, but I want to release a 2.5.1 bugfix before I make a change like this.

If you'd like to test it out beforehand, you can apply this diff to CodeSniffer.php:

diff --git a/CodeSniffer.php b/CodeSniffer.php
index 19ea3e6..66927d8 100644
--- a/CodeSniffer.php
+++ b/CodeSniffer.php
@@ -831,7 +831,13 @@ class PHP_CodeSniffer
         }

         if (empty($cliArgs) === false) {
+            // Change the directory so all relative paths are worked
+            // out based on the location of the ruleset instead of
+            // the location of the user.
+            $currentDir = getcwd();
+            chdir($rulesetDir);
             $this->cli->setCommandLineValues($cliArgs);
+            chdir($currentDir);
         }

         // Process custom sniff config settings.

@aik099
Copy link
Contributor

aik099 commented Jan 14, 2016

Support for T_SPACESHIP operator seems like a feature, not a bugfix. This way it should be 2.6.0 release.

@gsherwood
Copy link
Member

Support for T_SPACESHIP operator seems like a feature, not a bugfix. This way it should be 2.6.0 release.

It's a bug because it wasn't set as an operator and PHPCS didn't properly support PHP7. There is no BC break either. The next release will be 2.5.1, hopefully next week.

@aik099
Copy link
Contributor

aik099 commented Jan 14, 2016

Ok.

gsherwood added a commit that referenced this issue Jan 19, 2016
@gsherwood
Copy link
Member

Change has been pushed now that 2.5.1 is out.

@johnmaguire
Copy link
Contributor Author

👍 Thank you! Sorry, I was hoping to test this out but didn't get a chance. It looks like this will work great though! Really appreciate this.

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

No branches or pull requests

3 participants