Related to #1231118: Generate code according to coding standards, but I don't feel duplicated by.

Since Features seems to be reliant on the export code provided by whatever modules are utilized in the generation of a given Feature, this opens up the possibility of a whole deluge of errors kicked up when putting the code through PHP Code Sniffer.

I would propose there ought to be a checkbox option in the "Advanced usage" (or perhaps just general Settings): 'Insert PHP Code Sniffer directives to ignore generated code.'

If this is enabled, Features would insert
// @codingStandardsIgnoreStart
(at the beginning of a file) and
// @codingStandardsIgnoreEnd
at the end.

I'm thinking this would only be in the individual .inc files. This would not apply to the .install or .module as custom code can be in here which ought to be picked up by phpcs.

One can modify the phpcs command line to not scan .inc files, but I have a Feature module with a custom Views plugin associated and it is an .inc file..

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hefox’s picture

If exported code has coding style issues, it should be fixed instead of ignored imo

reubenavery’s picture

yes of course it should be, but we need to allow for edge cases where it's not and to offer users a way around a potential blocker for their workflow.

this is no different than the 'allow conflicts' option.

hefox’s picture

Allow conflict mode is for stuff like recreating features TMK; I don't see the connection, or at least not enough to justify the extra messyness that adding it and it's option will add. Having an alter for the rendered export, which has been discussed in other issues, seems more worth it.

reubenavery’s picture

The allow overrides option came about from a similar situation. It used to be that two silly features trying to assert the same user permission (or whatever) would block each other from being enabled, even if both settings were identical. This unfairly placed a blockage in development until the so-called conflict was resolved.

Likewise, we have a similar condition here that can throw blocks into a development path. "I'd like to have code sniffing engaged but if I put it on our Features, it blows up with hundreds of errors." Being in a typical dev project, we're behind schedule and overworked anyway and now we're supposed to divert even more time in solving some contrib module's export formatting in order to please phpcs? Sorry, can't do that now, maybe later on. For now, well I guess we will just have to disable phpcs codesniff on our features and hope that we can catch the mistakes in pull request reviews?

The alter hook idea is a good and simple approach, however. I will put something together and sandbox it.

reubenavery’s picture

Status: Active » Needs review
FileSize
2.4 KB

Here's my little patch. I'm introducing a new hook_features_export_header_alter() to allow alteration of the initial code snippet in exported module components' files.

reubenavery’s picture

Title: Option to add PHP Code Sniffer "ignore » Invoke drupal_alter() for initial code snippet injected into export files.

(changing issue title)

Status: Needs review » Needs work

The last submitted patch, features-hook_features_export_header_alter-2099899-5.patch, failed testing.

reubenavery’s picture

blah.. fixing patch format to satsify simpletest.

reubenavery’s picture

Status: Needs work » Needs review
FileSize
2.13 KB

blah.. fixing patch format to satsify simpletest.

hefox’s picture

Issue summary: View changes
Status: Needs review » Needs work

Don't really see why just a hook for header and not entire export