acquia / blt

Acquia's toolset for automating Drupal 8 and 9 development, testing, and deployment.
https://docs.acquia.com/blt/
GNU General Public License v2.0
442 stars 394 forks source link

How to do code sniff/fix on my file list #3054

Closed shelane closed 5 years ago

shelane commented 6 years ago

My system information:

Output of blt doctor:

+---------------------------+------------------------------------------------+
| Property                  | Value                                          |
+---------------------------+------------------------------------------------+
| %paths.%root              | /var/www/docroot                               |
| %paths.%site              | sites/default                                  |
| %paths.%modules           | sites/all/modules                              |
| %paths.%themes            | sites/all/themes                               |
| %paths.%config-sync       | ../config/default                              |
| %paths.%files             | sites/default/files                            |
| %paths.%temp              | /tmp                                           |
| %paths.%private           | /var/www/files-private                         |
| admin-theme               | seven                                          |
| alias-searchpaths.0       | /var/www/drush/sites                           |
| blt-version               | 9.1.1                                          |
| bootstrap                 | Successful                                     |
| composer-version          | Composer version 1.6.3 2018-01-31 16:28:17     |
| config-sync               | ../config/default                              |
| db-driver                 | mysql                                          |
| db-hostname               | db                                             |
| db-name                   | default                                        |
| db-password               | user                                           |
| db-port                   | 3306                                           |
| db-status                 | Connected                                      |
| db-username               | user                                           |
| drupal-settings-file      | sites/default/settings.php                     |
| drupal-version            | 8.5.6                                          |
| drush-alias-files.0       | /var/www/drush/sites/default.site.yml          |
| drush-alias-files.1       | /var/www/drush/sites/www.site.yml              |
| drush-cache-directory     | /home/docker/.drush/cache                      |
| drush-conf.0              | /var/www/vendor/drush/drush/drush.yml          |
| drush-conf.1              | /var/www/drush/drush.yml                       |
| drush-conf.2              | /var/www/docroot/sites/default/local.drush.yml |
| drush-script              | /var/www/vendor/bin/drush                      |
| drush-temp                | /tmp                                           |
| drush-version             | 9.4-dev-g454a174d                              |
| files                     | sites/default/files                            |
| install-profile           | drupal_lightning                                 |
| modules                   | sites/all/modules                              |
| php-bin                   | /usr/local/bin/php                             |
| php-conf.1                | false                                          |
| php-os                    | Linux                                          |
| private                   | /var/www/files-private                         |
| root                      | /var/www/docroot                               |
| site                      | sites/default                                  |
| stacks.drupal-vm.inited   | false                                          |
| stacks.dev-desktop.inited | false                                          |
| temp                      | /tmp                                           |
| theme                     | sienna                                         |
| themes                    | sites/all/themes                               |
| uri                       | drupal8.docksal                                  |
+---------------------------+------------------------------------------------+
+--------------------------------------+--------------------------------------------------------------+
| Check                                | Problem                                                      |
+--------------------------------------+--------------------------------------------------------------+
| BehatCheck:checkBaseUrl:uri          | base_url in tests/behat/local.yml does not match the site    |
|                                      | URI.                                                         |
|                                      |   Behat base_url is set to                                   |
|                                      | http://local.drupalblt.com.                                    |
|                                      |   Drush site URI is set to drupal8.docksal.                    |
| ConfigCheck:checkGitConfig           | Git repositories are not defined in blt.yml.                 |
|                                      |   Add values for git.remotes to blt.yml to enabled automated |
|                                      | deployment.                                                  |
| NodeCheck:checkNodeVersionFileExists | Neither .nvmrc nor .node-version file found in repo root.    |
+--------------------------------------+--------------------------------------------------------------+
[error]  BLT Doctor discovered one or more critical issues. 

I want to be able to run a code "sniff" and a code "fix" (phpcs/phpcbf) on either a path where all the files in the path would be checked/fixed or a single file. Looking through the list of commands, I find: tests:phpcs:sniff:all and tests:phpcs:sniff:files but it's not clear what they are doing and they aren't doing what I would want.

ba66e77 commented 6 years ago

@shelane, can you give me some more detail on what you expect to get from them and what you're seeing them do? Those commands should be doing exactly what you describe. You're a few releases behind current but I can't immediately think of significant changes that have been made to those commands in the interim.

shelane commented 6 years ago

blt tests:phpcs:sniff:all literally sniffs everything. I am working with one custom module, so "everything" can be too much when there are many files that have issues.

fin blt tests:phpcs:sniff:files "/var/www/docroot/modules/custom/sharing" Returns this:

Sniffing directories containing changed files...
[File\Write] Writing to /var/www/tmp/phpcs-fileset.
[ExecStack] '/var/www/vendor/bin/phpcs' --file-list='/var/www/tmp/phpcs-fileset' --bootstrap='/var/www/vendor/acquia/blt/src/Robo/Commands/Validate/phpcs-validate-files-bootstrap.php' -l

I expected to see the same output that I did from running "all" so I'm not sure if it's not accepting the file path or what it's doing. I checked the tmp directory, but there is nothing there.

ba66e77 commented 6 years ago

Is that the entirety of the output of sniff:files? When I have it scan a directory with no errors, what I get is below.

$ blt tests:phpcs:sniff:files "docroot/modules/custom/fnord"
[warning] Drupal VM is locally initialized, but is not running.
Sniffing directories containing changed files...
[File\Write] Writing to /Users/barrett.smith/Desktop/newblt/tmp/phpcs-fileset.
[ExecStack] '/Users/barrett.smith/Desktop/newblt/vendor/bin/phpcs' --file-list='/Users/barrett.smith/Desktop/newblt/tmp/phpcs-fileset' --bootstrap='/Users/barrett.smith/Desktop/newblt/vendor/acquia/blt/src/Robo/Commands/Validate/phpcs-validate-files-bootstrap.php' -l
.

Time: 49ms; Memory: 6Mb

$

What I notice is that it's not traversing directories within the path I gave it. In my example, I have a directory inside fnord which I know contains bad syntax (which with sniff:all flags), but as you can see sniff:files didn't flag it.

What you might do to scan all the files in a single module is to edit your phpcs.xml.dist in your repo root and change the <file>docroot/modules/custom</file> line to <file>docroot/modules/custom/sharing</file>. Not a permanent fix, but might be a decent enough workaround while you focus on that module.

shelane commented 6 years ago

Yes, that was the full output and that directory of files did have issues according to sniff:all, but like yours, is not traversing into files in directories inside of the listed directory.

ba66e77 commented 6 years ago

@shelane did the solution of editing your phpcs.xml.dist provide a suitable workaround?

shelane commented 5 years ago

I did not attempt that work around. I had only a few other files that were coming up in the scan, so I fixed the issues in those files.

danepowell commented 5 years ago

Dupe of #3448