WPTT / WPThemeReview

PHP_CodeSniffer rules (sniffs) to enforce WordPress theme review coding conventions
MIT License
209 stars 37 forks source link

Not able to put WPCS in Config #75

Closed shahbaz-dev1 closed 8 years ago

shahbaz-dev1 commented 8 years ago

I have xampp installed on my system. It already comes with PHPCS and whenever I try to put WPCS into the config, it gives me error that no config file exists. Please guide me what to do :(

jrfnl commented 8 years ago

First off: this is not the repository to ask these kind of questions. For questions about WPCS, ask them at WPCS, for questions about PHPCS, ask them at PHPCS. Please do read the available documentation first though as you might not get much of a response if you don't.

All the same, I'll try and help you as an exception.

whenever I try to put WPCS into the config

Into which config are you trying to add WPCS and how ? Please provide more detail.

shahbaz-dev1 commented 8 years ago

I am sorry posting at the wrong place.

phpcs --config-set installed_paths /path/to/wpcs

When I run this command gettign the following error. Warning: file_put_contents(C:\php\pear\data/PHP_CodeSniffer/CodeSniffer.conf): failed to open stream: No such file or directory in D:\xampp\php\pear\PHP\CodeSniffer.php on line 1939

I have the phpsc and phpcs.bat file in d:\xampp\php directory

Thanks for your help

jrfnl commented 8 years ago

phpcs --config-set installed_paths /path/to/wpcs

Did you adjust the /path/to/wpcs part to the folder in which you have WPCS installed ? If not, that is part of your problem.

I have the phpsc and phpcs.bat file in d:\xampp\php directory

Is the phpcs command available globally, i.e. from every directory on your computer or not ? If not, make sure you actually run the command from a directory where it is available.

shahbaz-dev1 commented 8 years ago

Yes, I have adjust the path to where wpcs is placed. Also I have access to phpcs globally. It is added into Environment Variables.

jrfnl commented 8 years ago

Ok - next, as it says in the error message, check in the C:\php\pear\data/PHP_CodeSniffer/ directory whether you have a file there called CodeSniffer.conf. You probably don't. So, you can either create an empty file called CodeSniffer.conf or copy the CodeSniffer.conf.dist file which most likely is there and rename the copy to CodeSniffer.conf.

shahbaz-dev1 commented 8 years ago

Yes, now it works but whenever I run the check command phpcs -i It says

The installed coding standards are MySource, PEAR, PHPCS, Squiz and Zend

Not WordPress :(

jrfnl commented 8 years ago

Ok, can you open up the CodeSniffer.conf file and copy & paste what it says in there here for me to have a look ?

shahbaz-dev1 commented 8 years ago

Here is what I can see

<?php
 $phpCodeSnifferConfig = array (
  'default_standard' => 'PSR2',
  'report_format' => 'summary',
  'show_warnings' => '0',
  'show_progress' => '1',
  'report_width' => '120',
  'installed_paths' => 'd:/xampp/htdocs/phpcs/wpcs',
)
?>
jrfnl commented 8 years ago

Ok, you can remove everything in the array but the installed_paths bit (just to make sure none of the other settings is interfering), so the file would look like:

<?php
 $phpCodeSnifferConfig = array (
  'installed_paths' => 'd:/xampp/htdocs/phpcs/wpcs',
);
?>

And can you confirm that d:/xampp/htdocs/phpcs/wpcs is the directory in which WPCS is installed ? and that it is the root directory of the WPCS project, i.e. the directory should have the following sub-directories (and possibly more if it's a fork/copy of this fork, not of the WPCS main project):

d:/xampp/htdocs/phpcs/wpcs
    - WordPress
    - WordPress-Core
    - WordPress-Docs
    - WordPress-Extra
    - WordPress-VIP
shahbaz-dev1 commented 8 years ago

Yes, its confirmed, the path correct and I have the following directories

d:/xampp/htdocs/phpcs/wpcs

- WordPress

- WordPress-Core

- WordPress-Docs

- WordPress-Extra

- WordPress-VIP`

But still no luck :(

It seems that it is reading config from somewhere else. Please see the attached CodeSniffer file. CodeSniffer.zip

jrfnl commented 8 years ago

It seems that it is reading config from somewhere else.

That must be the case. However the attached file does not help with that.

Questions which should help determine from where are:

shahbaz-dev1 commented 8 years ago

For Environment Variable paths please see the attachment untitled

Thanks for your help

jrfnl commented 8 years ago

Ok, just looking at your screenshot, I can already see that you have a second copy of PHPCS installed in D:\xampp\htdocs\phpcs\, so more than likely the phpcs.bat file in that directory is being used instead of the one in the PEAR directory, which also means that PHPCS will be looking for the .conf file in D:\xampp\htdocs\phpcs\ not in the PEAR data directory.

Secondly, you say your CodeSniffer.conf is located at file is d:\xampp\php\pear\PHP\CodeSniffer.conf not in the C:\php\pear\data/PHP_CodeSniffer/ directory.

Both are wrong and cause your problems

The simple solution is to copy the d:\xampp\php\pear\PHP\CodeSniffer.conf file to the correct location for both installs:

After that, remove the file from the original (wrong) location d:\xampp\php\pear\PHP\CodeSniffer.conf

Then, keep your fingers crossed and run phpcs -i again :sunglasses:

shahbaz-dev1 commented 8 years ago

Actually C:\php\pear\data/PHP_CodeSniffer/ path is totally not exist. CodeSniffer.php first looks for config in the same directory where CodeSniffer.php is itself and it is placed in d:\xampp\php\pear\PHP\CodeSniffer.php

Is it possible that I search for something specific in the whole directory to find out from where it is reading the configurations.

shahbaz-dev1 commented 8 years ago

Is there a way I disable phpcs comes with Xampp and install it as per phpcs and wpcs way?

jrfnl commented 8 years ago

Actually C:\php\pear\data/PHP_CodeSniffer/ path is totally not exist.

So create it. That will prevent your file from being overwritten when you update the PEAR install of PHPCS.

Is there a way I disable phpcs comes with Xampp and install it as per phpcs and wpcs way?

Yes, uninstall it from your PEAR install. Install composer and run it to install PHPCS and WPCS.

shahbaz-dev1 commented 8 years ago

I did the first step but no luck.

I try to uninstall phpcs and then re-install it.

Thanks a lot for your help :+1:

shahbaz-dev1 commented 8 years ago

I have disabled the pear phpcs installation and re-install PHPCS to a new location/directory by following the instructions at https://github.com/squizlabs/PHP_CodeSniffer and this time successful. Everything now works fine. Thanks @jrfnl

jrfnl commented 8 years ago

Glad to hear it. Enjoy!