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

Support phpcodesniffer-composer-installer for easy integrate code style #855

Merged
merged 2 commits into from
Jun 30, 2017

Conversation

alexander-akait
Copy link
Contributor

@JDGrimes
Copy link
Contributor

Related: #546

\cc @schlessera

@jrfnl
Copy link
Member

jrfnl commented Feb 28, 2017

@Rarst Would you have an opinion on this ?

@Rarst
Copy link
Contributor

Rarst commented Mar 6, 2017

Oops, sorry my notifier was broken for some days and I missed bunch of notifications.

I am not sure what the installer does in this case. I remember seeing one that copied stuff around and I don't like that approach. In my opinion Composer packages should never be nested and specific case of standards should be handled with configuration rather than location.

@alexander-akait
Copy link
Contributor Author

alexander-akait commented Mar 6, 2017

@Rarst this only set installed_paths config variable right

@Rarst
Copy link
Contributor

Rarst commented Mar 6, 2017

Ah, good to hear. :) I will try to have a proper look at it and play with later then.

@alexander-akait
Copy link
Contributor Author

/cc @Rarst

@Potherca
Copy link

As this litterally only adds "type" : "phpcodesniffer-standard", to the composer.json, could this PR be looked at?

(There is further documentation outlining the rational behind this change if that helps...)

@JDGrimes
Copy link
Contributor

I think this makes sense, I can see no downside. I do want to confirm that this will work properly though, since WPCS is actually a bundle of several standards (WordPress, WordPress-Core, etc.) ??

#546 could then be closed, as I'd expect that if PHPCS ever does add native support for something like this (which seems unlikely at this point), it would follow the same conventions already being employed by existing plugins.

@Rarst
Copy link
Contributor

Rarst commented Apr 24, 2017

I am getting to looking at it properly this week, will report. :)

@Rarst
Copy link
Contributor

Rarst commented Apr 30, 2017

Ok, finally got to it.

So given this test composer.json

{
	"require" : {
		"squizlabs/php_codesniffer" : "^2.0",
		"dealerdirect/phpcodesniffer-composer-installer" : "0.3.2",
		"wp-coding-standards/wpcs":"dev-patch-1"
	},
	"repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/evilebottnawi/WordPress-Coding-Standards"
        }
    ]
}

Running composer install --no-dev will net us following vendor/squizlabs/php-codesniffer/CodeSniffer.conf

<?php
 $phpCodeSnifferConfig = array (
  'installed_paths' => 'C:\\server\\phpcs-installer-test\\vendor/wp-coding-standards/wpcs',
)
?>

I like this approach:

  • just works (no scripting in composer.json needed)
  • doesn't move standards files around
  • produces reliable absolute path to standards in config

One note on the PR itself — it sets type, but doesn't require installer plugin itself. So it would need either for plugin to be otherwise required or installed globally. If we want to go with this then we should probably require plugin ourselves as well.

Notably this will not work on checkout of this repository itself (as opposed to be pulled in as dependency) since installer doesn't seem to currently handle the case (see PHPCSStandards/composer-installer#20 ) so we would have to keep scripts setup in composer.json we already have.

Copy link
Contributor

@Rarst Rarst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Should require or suggest the installer plugin.
  2. Should remove scripts set up if require is used.
  3. Could update documentation if suggest is used.

@Potherca
Copy link

Potherca commented May 2, 2017

@Rarst Should we fix PHPCSStandards/composer-installer#20 before this PR (possibly including the require) gets merged?

@Rarst
Copy link
Contributor

Rarst commented May 2, 2017

That would be cleaner overall, but I don't think it's critical since we currently already handle root case ourselves with composer.json script instructions https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/blob/5dbac380f4c0b8c61640b42825cc91034ce2a77b/composer.json#L21-L22

@jrfnl
Copy link
Member

jrfnl commented May 3, 2017

Possibly superfluous, but this issue provides some more information about the cases the DealerDirect composer plugin handles: PHPCSStandards/composer-installer#24

@frenck
Copy link

frenck commented May 11, 2017

@Rarst PHPCSStandards/composer-installer#20 has been closed and a new release is out.

The plugin is now able to handle the root case.

Copy link
Member

@GaryJones GaryJones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In terms of the single-line change here, I've got no objection to it being added - it's be up to the external packages to make use of it correctly. On it's own, it's just a line in composer.json that hopefully won't cause any issues to packages that read type, but don't understand phpcodesniffer-standard.

@Potherca
Copy link

@GaryJones As mentioned in the rational linked in my earlier comment: The type should not cause any problems as the specified behaviour for custom-installers is to ignore any type that composer (or any composer plugin) does not recognize and default to "library".

@JDGrimes
Copy link
Contributor

So the PR should now be updated, as @Rarst requested, to:

  • require dealerdirect/phpcodesniffer-composer-installer.
  • Remove the scripts section as it is then no longer needed at all.

My only question is:

I was under the impression that there are several different installers for PHPCS standards. This one seems to be well maintained, so I'm fine with using/depending on it. But I would just like to be clear about what affects, if any, this might have on somebody who uses a different installer. I have a feeling if somebody installed WPCS with a different installer, us requiring this installer might cause issues/conflicts—am I correct?

@Rarst
Copy link
Contributor

Rarst commented May 11, 2017

I have a feeling if somebody installed WPCS with a different installer, us requiring this installer might cause issues/conflicts—am I correct?

Given that there is no official way (I think) for installers to claim type for themselves, two installers trying to target same type will likely conflict to some degree.

We could not add the specific plugin to require, more compatible less convenient.

@frenck
Copy link

frenck commented May 11, 2017

@Rarst Correct, there is no official way to claim it.

My suggestion in that case (when going for the more 'safe' route) would be:

  • Do not require the installer, for compatibility sake.
  • Add plugin package suggestion in the composer.json
  • Keep old script instructions (should not be a problem if the plugin is used).
  • Update documentation

You can still decide (over time), what to do.

@JDGrimes
Copy link
Contributor

We could not add the specific plugin to require, more compatible less convenient.

I think being more convenient makes sense here, but I just wanted to be clear that it would potentially have compatibility issues for some people at some point. If it ever were to become a significant issue, we could revisit it.

@Rarst
Copy link
Contributor

Rarst commented May 11, 2017

From quick search of GH the common practice seems to be declare phpcodesniffer-standard type, but not require specific plugin. I would guess some of those might not even intend for plugin to be used, might just be filling in the type for information.

@JDGrimes
Copy link
Contributor

Posted my last comment at the same time as @frenck. On second thought I'd say he is probably correct, and we might want to just suggest the use of the plugin in the README for now, to ease installation.

So this PR would be merged as-is, and then the install instructions would be updated to mention this option.

@Rarst
Copy link
Contributor

Rarst commented May 11, 2017

So this PR would be merged as-is

I'd like to see suggest added, since other plugin I've seen is way more messy IMO than this one. Won't hurt to include docs in PR as well.

PS oh dear, we just keep picking on this. :) if @evilebottnawi sick of it I can finish this up [next week].

@Potherca
Copy link

I would also suggest not adding a require just yet. The type (and possibly a suggest) should be fine.

A require can always be added later. That would also give us time to look at the "conflicting installers" scenario and ways of dealing with it in the plugin, as that is bound to show up anyway...

jrfnl
jrfnl previously requested changes May 14, 2017
Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To summarize the current status:

This PR needs to be updated as per @frenck's comment:

  • Add suggest section to the composer.json suggesting the dealerdirect/phpcodesniffer-composer-installer plugin.
  • Adjust the readme install instructions for Composer to allow the user to make their own choice from the different Composer plugins available which all use this same type.

@jrfnl
Copy link
Member

jrfnl commented Jun 30, 2017

I've rebased & updated the PR. @Rarst @GaryJones Would you mind having another look ?

@jrfnl jrfnl dismissed their stale review June 30, 2017 00:30

Superseded by new commit

@jrfnl
Copy link
Member

jrfnl commented Jun 30, 2017

Closes #546

@@ -13,12 +13,16 @@
"require" : {
"squizlabs/php_codesniffer": "^2.9.0"
},
"suggest" : {
"dealerdirect/phpcodesniffer-composer-installer": "*"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth suggesting the alternative as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't that create the risk of people blindly installing everything that's suggested and then having two plugins doing the same thing (and possibly conflicting with each other) ?

That was the reason for me to just suggest one anyway.

@alexander-akait
Copy link
Contributor Author

Guys, sorry, i don't have time to this now, feel free to close this PR and create new if something wrong

@jrfnl
Copy link
Member

jrfnl commented Jun 30, 2017

@evilebottnawi No worries, we appreciate you taking the initiative for this and getting the discussion going. I've updated your PR (so you'll get whuffies for your work) and hope to get this merged soon.


There are two actively maintained Composer plugins which can handle the registration of standards with PHP_CodeSniffer for you:
* [composer-phpcodesniffer-standards-plugin](https://github.com/higidi/composer-phpcodesniffer-standards-plugin)
* [phpcodesniffer-composer-installer](https://github.com/DealerDirect/phpcodesniffer-composer-installer)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these two both work in roughly the same way? How would someone choose between the two?

Worth WPCS picking one as the recommendation, and leaving the other as a link for an alternative, instead of presenting both equally (in this doc)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these two both work in roughly the same way?

AFAIK yes, they do.

How would someone choose between the two?

Probably the same way as when choosing between two different WP plugins to use:

  • See if it's still actively maintained, issues are being responded to, has good reviews, how many users it has on packagist.
  • Install each, test it, see if you like it and it does what you want.

Worth WPCS picking one as the recommendation, and leaving the other as a link for an alternative, instead of presenting both equally (in this doc)?

We could, but I figured most Composer users would just require WPCS and see the suggest and follow that without reading the readme. I'd be happy to adjust it though.

The reason I choose the @Dealerdirect version as the recommendation is that the team of that plugin has been very active trying to help external standards get this issue sorted, created their Composer plugin in response to an issue with another external standard I'm involved with and has been very responsive to queries related to the plugin.

@JDGrimes JDGrimes merged commit 3d15aa6 into WordPress:develop Jun 30, 2017
@jrfnl jrfnl mentioned this pull request Aug 21, 2018
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants