CPCS doesn't work? Or how the hell is it suppose to be used?

In the spirit of finally doing something useful for ClassicPress and contribute to the repository I figured I finally learn what CPCS is and how it works.

I’m not a terminal wizard, don’t care for it either. Nor do I understand the manual very well as it expects me to know how any of this works… I don’t - I know how basic terminal works, how to run commands and the basics. But if it doesn’t work as explained I have no idea what’s going on or how to fix it.

After 30 frustrating minutes (of my own making for not being a terminal nerd while doing new stuff) I’ve managed to install codesniffer and wpcs - Both work.
I can scan files, folders and I understand the output. Good (ish).

But then - Happy with that result the fun stops.
Why is running cpcs different than wpcs? Why doesn’t it work as the manual says?

Expected usage (even though thats not in the manual):

% php bin/phpcs --standard=ClassicPress ~/Sites/localhost/classicpress/wp-content/plugins/adrotate

But no - That’s too easy:

ERROR: the "ClassicPress" coding standard is not installed. The installed coding standards are MySource, PEAR, PSR1, PSR2, PSR12, Squiz, Zend, WordPress, WordPress-Core, WordPress-Docs and WordPress-Extra

Adding the installed path (or whatever) in a similar fashion as you’d do for wpcs doesn’t work.

I then went back to what your manual says and tried to run:

 % CPCS_TEXTDOMAIN=adrotate cpcs/bin/cpcs ~/Sites/localhost/classicpress/wp-content/plugins/adrotate

(also the reverse, from the plugin directory and a variant with php in front)

It does nothing, no error, no log. It just shows a new prompt as if something happened, except it didn’t.

What is CPCS_TEXTDOMAIN? Why is that not explained anywhere? Is it the plugin slug? WHy not call it ‘slug’ then?
Why doesn’t cpcs give me any response other than a stupid usage indicator that teaches me the above command which doesn’t work?

All I get if I try variants is something like this:

% cpcs/bin/cpcs ~/Sites/localhost/classicpress/wp-content/plugins/adrotate    
Usage: CPCS_TEXTDOMAIN=plugin-textdomain cpcs/bin/cpcs plugin-directory-name [other-wpcs-args]
(to check the current directory, use . for plugin-directory-name)

But that doesn’t work as mentioned above…

So, :face_with_symbols_over_mouth:

How do I run CPCS? WHat command should I run? Or better yet, where is the UI with a input-selection-field, a GO button and a text-log-window-thingy for the result. You know, something modern and not user unfriendly.

Make sure you use the updated CPCS. We have our own repo now and updated some rules. We haven’t announced them yet as it will be part of the new directory.

Thanks for the reply.

That’s the one I got yes - I just renamed the folder to cscp to sort of match wpcs.

Renaming the folder might be the problem (the text domain is same as folder name, correct me if I am wrong).
Try using the original name for the folder.

Hmm good idea.
Just tried it and it made no difference.

I’m thinking I either installed cpcs in the wrong spot following the install manual (perhaps because it’s unclear/doesn’t specify anything beyond “clone the git thing”)
OR cpcs is missing some argument in the command I’m running.

But since there is no error… :man_shrugging:

Seems you are missing something installed.
You should have a folder structured this way if you followed the installation instruction steps 1 to 4:

  • cp-plugin-review
    • ClassicPress-Coding-Standards
    • adrotate
    • cpcs

If you are inside adrotate folder the command should be something like:
CPCS_TEXTDOMAIN=adrotate ../cpcs/bin/cpcs .

Renaming the folder might be the problem (the text domain is same as folder name, correct me if I am wrong).

The text domain usually is the main plugin folder name, but it’s not mandatory as it is just to check text domains in things like esc_html_e( 'Hello!', 'my-text-domain' );

1 Like

You can also try
php bin/phpcs --runtime-set text_domain "adrotate" --standard="path/to/cpcs/phpcs.xml" -s ~/Sites/localhost/classicpress/wp-content/plugins/adrotate

Make sure you update CPCS. We’ve removed additional styling rules. You should see fewer issues.

1 Like

Finally tried Simones idea. Also didn’t work. Just got a blank new prompt as if I hit enter without a command.
Got tired or trying so I deleted the whole lot.

I also tried to get phpcs working in Nova (editor) which works with one click, but then the wpcs/cpcs stuff doesn’t get applied. Just the default rules. Not sure what to do with that either.

So no coding standards checks for now…