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

How to update ruleset when a new version is released? #1821

Closed
cagross opened this issue Oct 28, 2019 · 22 comments · Fixed by #2367
Closed

How to update ruleset when a new version is released? #1821

cagross opened this issue Oct 28, 2019 · 22 comments · Fixed by #2367
Assignees
Milestone

Comments

@cagross
Copy link

cagross commented Oct 28, 2019

I have a couple questions about keeping this ruleset up to date on my system:

  1. How can I check the current version installed on my system?
  2. If a new version is released, what is the proper way to update the version on my system?

FYI my system is a Windows machine. To install the ruleset I used these instructions (in the 3. Installing The WordPress Coding Standards Rules section).

@dingo-d
Copy link
Member

dingo-d commented Oct 28, 2019

The best way is to use Composer and follow the installation guide.

With Composer you can easily track what version of WPCS you have installed for your project.

Also, it's better not to install phpcs globally, this can just cause you headaches later on.

@cagross
Copy link
Author

cagross commented Oct 29, 2019

@dingo-d OK thanks for that. I'm new to Composer, so let me just confirm what I think you've said. I should be able to use Composer to both check my currently installed version of WPCS and update to the latest version of WPCS. Is that correct?

Also, it's better not to install phpcs globally, this can just cause you headaches later on.

OK thanks for that. I'm slowly learning that, and will look into installing things by project--thanks.

@dingo-d
Copy link
Member

dingo-d commented Oct 29, 2019

I should be able to use Composer to both check my currently installed version of WPCS and update to the latest version of WPCS. Is that correct?

I'm not sure how exactly you installed your current phpcs. My guess is that you have it set up globally.
In that case you'd need to find where you installed the WPCS and check the changelog to see the latest version.

If you'd have installed the phpcs using composer, you'd just type composer info and just see the version in the list 🙂

@cagross
Copy link
Author

cagross commented Oct 30, 2019

OK thanks. I located the WPCS folder, and inside, I ran composer info to get the installed version (3.4.2). In the future, if an update is available, how would I then update my version? With composer update?

@dingo-d
Copy link
Member

dingo-d commented Oct 30, 2019

It's hard to say without knowing your setup. You'll need to add more information, like file structure, how you installed it in the first place etc. 🙂

@cagross
Copy link
Author

cagross commented Oct 31, 2019

OK got it. Problem: I don't exactly remember how I installed wpcs or phpcs :-/ Geesh. I was even trying to write everything down during the installation process. But, well, here we are :-)

From the wpcs instructions, I used either the Composer method, or the Standalone method. Is there any way I can check?

I can say this:

  • In my Windows user directory, is a folder named wpcs.
  • In the wpcs folder is contained all the expected wpcs files/folders.
  • In that wpcs folder is also another folder, vendor. Inside that is a folder squizlabs and inside that is a folder php_codesniffer, which contains all the expected phpcs files.

So somehow phpcs is installed inside wpcs. Is that expected during any of the installation procedures? It sounds a bit odd to me. But at the same time, the wpcs 'Composer' installation instructions indicate that it will automatically install PHP_CodeSniffer. So maybe that's how things are done?

@dingo-d
Copy link
Member

dingo-d commented Oct 31, 2019

That sounds like the composer installation method. So you should be able to update it using composer 🙂

@cagross
Copy link
Author

cagross commented Nov 4, 2019

OK thanks for confirming. If an update becomes available, I'll try to use composer update.

I have a related question. You say that judging from my folder structure, it looks like I used the Composer installation method. And that is the method I believe I used. With that method, is it expected that the php_codesniffer folder is nested inside the wpcs folder? That seems a bit non-standard, or at least, unexpected by me; when I saw it, I thought I might have done something incorrectly (although I can confirm everything works as expected). Other similar extensions I've used have not shared a similar nested folder structure--each has resided in a separate folder. In those cases though, I can say that the extensions were Node-based.

@dingo-d
Copy link
Member

dingo-d commented Nov 4, 2019

Yeah, that doesn't seem right.

The vendor folder should contain the wp-coding-standards folder like this:

Screenshot 2019-11-04 at 13 26 52

The php_codesniffer should be in the squizlabs folder, also inside the vendor folder.

@jrfnl
Copy link
Member

jrfnl commented Nov 4, 2019

Let's take away some confusion:

The current Composer installation instructions in the readme suggest installing WPCS as a stand-alone project which can then be used system-wide.

With an install like that, your directory layout will be like:

wpcs
    /WordPress
    /WordPress-Core
    /...
    /vendor/squizlabs/php_codesniffer/

For a project-based install, the directory layout will be like:

project
    /...
    /vendor/wp-coding-standards/wpcs
    /vendor/squizlabs/php_codesniffer

If your directory looks like the first, throw away the whole wpcs directory and run the original command again to update.

If your directory looks like the second, from within your project root, run composer update wp-coding-standards/wpcs to update.

As a side-note: IMO, we should remove the advise to use create-project and update the install instructions to primarily advise a project based install and as an alternative a composer global install.
Both are easy to update via composer and that kind of usage is more common.

@jrfnl
Copy link
Member

jrfnl commented Nov 4, 2019

Related: #481

@cagross
Copy link
Author

cagross commented Nov 6, 2019

@jrfnl

OK thanks for the info, and confirming the directory structures.

If your directory looks like the first, throw away the whole wpcs directory and run the original command again to update.

Well let's talk about this for a second. My directory does indeed look like the first. But is it absolutely required to throw that away and start over? I ask because this setup is already working as expected and as desired for me. In light of that, I would have no issue leaving it in-place for a bit. If that would be OK, my only questions would be:

  • How to update WPCS?
  • How to update PHP CodeSniffer?

If I navigate by command line to the wpcs folder, then execute composer update, it sounds like that will update wpcs--correct? If so, will it also update PHP CodeSniffer, since it lies in a sub-directory? Or will I have to navigate to that directory and re-run composer update? Or would I have to use some other means? Or are you perhaps suggesting I start over, precisely because there would be update issues with this current setup?

@jrfnl
Copy link
Member

jrfnl commented Nov 6, 2019

But is it absolutely required to throw that away and start over?

With a setup like the first: Yes.

And that shouldn't be an issue as - as an end-user - you won't have made any changes to anything in that directory. If you have, that's another issue, but that raises numerous red flags for me.

If I navigate by command line to the wpcs folder, then execute composer update, it sounds like that will update wpcs--correct?

No, it will not.
It will only update the dependencies of WPCS, i.e. PHP_CodeSniffer. It will not update WPCS itself.
This is inherit in the way the project was installed and why I think the readme install instructions should be changed.

@cagross
Copy link
Author

cagross commented Nov 10, 2019

But is it absolutely required to throw that away and start over?
With a setup like the first: Yes.

OK. So I understand though--why do you say that? Is it because with my current setup, I will not be able to update WPCS in the future? I'm not trying to argue or say you're wrong--I just want to be sure I'm understanding everything properly :-)

@jrfnl
Copy link
Member

jrfnl commented Nov 10, 2019

OK. So I understand though--why do you say that? Is it because with my current setup, I will not be able to update WPCS in the future?

With the first setup you will not be able to update WPCS at all. Not now and not in the future. That's why.

@cagross
Copy link
Author

cagross commented Nov 10, 2019

OK got it, thanks for confirming.

So I now want to throw away and start over. To do so, its clear that I should delete my existing wpcs folder. That will remove both WPCS and PHPCS from my system. In-turn, I should carry out a project-based install. But how exactly do I carry out a project-based install? Would I follow the Standalone instructions to do so?

@jrfnl
Copy link
Member

jrfnl commented Nov 10, 2019

But how exactly do I carry out a project-based install? Would I follow the Standalone instructions to do so?

I would recommend staying with Composer.

Now you have a choice:

  • either install globally - which would make WPCS (and PHPCS) available everywhere on your system.
  • or install specifically for one project.

For a global install:

  1. Run the below command from anywhere on your system:
composer global require wp-coding-standards/wpcs dealerdirect/phpcodesniffer-composer-installer
  1. Make sure the Composer "home" vendor/bin directory is in your system path.
    To find out what the Composer "home" directory is, run composer config --list --global and see what's listed under home.
    Take that directory, add /vendor/bin to it and make sure it's in your system $PATH variable.

You can now call the phpcs and phpcbf commands from anywhere on your system.

To update your install, you can run composer global update.

For a project based install:

  1. Go to the project's root directory.
  2. Run the below command:
composer require wp-coding-standards/wpcs dealerdirect/phpcodesniffer-composer-installer

Now you can call vendor/bin/phpcs and vendor/bin/phpcbf from the root of your project directory.

To update your project based install, you can run composer update from the project's root directory.


Is that clear enough ?

@cagross
Copy link
Author

cagross commented Nov 11, 2019

OK thanks very much for that. Both sets of instructions are reasonably clear, as are the differences between each, and the update instructions. I'm leaning towards the project based install, since it seems slightly less complex (and perhaps more advantageous), but have one additional question before proceeding. In the instructions you mentioned,

Now you can call vendor/bin/phpcs and vendor/bin/phpcbf from the root of your project directory.

Is this to say that at this point, I will also be able to open VSCode, and use the PHP CodeSniffer for Visual Studio Code extension to run my PHP code through PHPCS, while applying the WPCS rules? That is the setup that is currently in-place on my system (screenshot), and my desired functionality.

To give you more information on my installation of PHP CodeSniffer for Visual Studio Code, I'm not 100% sure if it has been installed globally or not. I can say that I installed it via VSCode. VSCode indicates, "This extension is enabled globally" (screenshot). But, the files for this extension definitely reside in my specific Windows user directory: C:\Users\snarl\.vscode\extensions.

@jrfnl
Copy link
Member

jrfnl commented Nov 11, 2019

I don't work with VSCode myself, so I honestly can't advise you on that.

I imagine though that a global install might work better for that, but to be sure, you'd need to check the implementation details of the extension you are using.

@cagross
Copy link
Author

cagross commented Nov 13, 2019

OK no worries--I'll work on VSCode integration separately.

I carried out the For a project based install: steps you listed. When I executed the composer command, everything seemed to install without issue (see output here). At this point, if I execute phpcs -i, should I expect to see WordPress in the installed coding standards? I ask because for me, the output is:

The installed coding standards are MySource, PEAR, PSR1, PSR12, PSR2, Squiz and Zend

@jrfnl
Copy link
Member

jrfnl commented Nov 13, 2019

@cagross as per above instructions for project based install:

Now you can call vendor/bin/phpcs and vendor/bin/phpcbf from the root of your project directory.

The vendor/bin/... commands will look to the project based install.
If you use the phpcs command, you are using a globally installed version of PHPCS.

@cagross
Copy link
Author

cagross commented Nov 15, 2019

The vendor/bin/... commands will look to the project based install.
If you use the phpcs command, you are using a globally installed version of PHPCS.

OK got it. Executing the command vendor/bin/phpcs -i does indeed return:

The installed coding standards are MySource, PEAR, PSR1, PSR12, PSR2, Squiz, Zend, WordPress, WordPress-Core, WordPress-Docs and WordPress-Extra

So, it looks like I now have two installations of PHPCS: one a global install and one a by-project install. Would you agree with that assessment? Also, if I open a PHP file in VSCode, it displays an error message:

phpcs: The "WordPress" coding standard is not installed. Please review your configuration an try again.

So I guess we can assume PHPCS for VSCode is pointing to the global install of PHPCS, rather than the project-based install--sound reasonable? That error occurs regardless of what directory houses the PHP file in-question.

In light of all that, what would you suggest I do now? As I see it, I have two options:

  1. Try to uninstall both versions of PHPCS, and re-carry out your project based installation.

  2. Try to uninstall the project based PHPCS installation, and then try to get your global installation instructions to work.

Would you agree those are my two options right now, or is there perhaps a third I'm overlooking? Of those two options, do you see any benefit of one or the other? Actually, now that I think about it, I think option 2 might be more beneficial to me. I say that because it seems like PHPCS for VSCode is looking at my global PHPCS installation. So option 2 seems like it would have a better chance of getting PHPCS for VSCode to work properly with WPCS (which is my ultimate goal). I personally wouldn't mind a global installation. For the time being, I don't foresee needing different versions of PHPCS or WPCS for different projects. Would you see any issues with attempting option 2?

Thanks for your patience so far! :-)

@jrfnl jrfnl added this to the 3.0.0 milestone Apr 1, 2020
@jrfnl jrfnl self-assigned this Apr 11, 2020
jrfnl added a commit that referenced this issue Aug 20, 2023
This commit updates the README guide to be in line with WordPressCS 3.0.0.

This commit:
* Removes the "Last commit to stable" and "Nr of contributors" badges.
* Updates the "Tested on PHP..." badges.
* Updates the table of contents to match the new content of the file.
* Removes the "Project history" section (has been moved to the wiki).
* Makes the pre-requisites for the package more explicit and puts them in a separate section.
* Updates the installation instructions and adds update instructions.
    - Removes the instructions related to stand-alone installs and using `composer create-project`.
    - The new installation instructions take the changes in Composer 2.2 (permission required for plugins to run) into account.
    - The new installation instructions include a link to the end user/ruleset maintainer upgrade guide for WPCS 3.0.0 as the initial upgrade may need extra work.
* Updates references to the Composer PHPCS plugin to make sure these reference the new name and link to the correct GH repo (as the repo has moved).
* Removes the reference to the VIP ruleset which was removed in WPCS 2.0.0 from the "Rulesets" section.
* Adds links to the "customizable properties" section for where to find customizable properties for PHPCS native sniffs and sniffs from PHPCSExtra.
* Adds the `VariableAnalysis` standard and the `VIP Coding Standards` to the list of optional additional rulesets to use.
* Updates the command and output for the example run.
* Removes the links to IDE related tutorials in favour of a link to the wiki (to save us having to maintain this list in multiple places).
* Ensures the text consistently uses `WordPressCS` instead of `WPCS`.

Closes #481
Closes #1821
Closes #1901
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants