Closed wongjn closed 6 years ago
@wongjn Thank you for your feedback. Please specify the following information:
PHP 7.0.10 PHP_CodeSniffer 2.9.1 VS PHPCS settings (only globals set, otherwise default):
{
"phpcs.standard": "Drupal,DrupalPractice",
"phpcs.ignorePatterns": [
"*/node_modules/*",
"*/dist/*",
"*/vendor/*",
"*/public_html/core/*",
"*/contrib/*"
]
}
Running a stripped-down equivalent command works fine for a file that when opened in VS, brings up the error:
> phpcs --standard="Drupal,DrupalPractice" --ignore="*/public_html/core/*" public_html/core/modules/node/src/Entity/NodeType.php -
q --report=json
{"totals":{"errors":0,"warnings":0,"fixable":0},"files":{}}
@wongjn Drupal and coding standards version?
@wongjn Also please update vscode-phpcs to 1.0.4
Updated extension. Drupal and DrupalPractice come from the drupal/coder composer package, version 8.2.12.
@wongjn Do you think you can set up a reference repo to reproduce this issue? I don't follow your folder structure and I am not that familiar with Drupal 8.
https://github.com/wongjn/repro
Reproduction steps:
composer install
public_html/core/modules/node/src/Entity/NodeType.php
(as an example file that exhibits the erroneous behaviour).@wongjn Thank you for the reproduction repo. Following your instructions I am getting this error:
phpcs: Referenced sniff "../vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Array/DisallowLongArraySyntaxSniff.php" does not exist
@wongjn Can you try the following configuration:
composer.json
{
"name": "wongjn/repro",
"require": {
"composer/installers": "^1.2",
"drupal/core": "^8.4",
"neronmoon/scriptsdev": "0.1.*"
},
"require-dev": {
"drupal/coder": "^8.2.12"
},
"extra": {
"scripts-dev": {
"post-install-cmd": [
"\"vendor/bin/phpcs\" --config-set installed_paths vendor/drupal/coder/coder_sniffer"
],
"post-update-cmd": [
"\"vendor/bin/phpcs\" --config-set installed_paths vendor/drupal/coder/coder_sniffer"
]
},
"installer-paths": {
"public_html/core": [
"type:drupal-core"
]
}
}
}
.vscode/settings.json
{
"phpcs.standard": "Drupal,DrupalPractice",
"phpcs.autoConfigSearch": false,
"phpcs.ignorePatterns": [
"*/node_modules/*",
"*/dist/*",
"*/vendor/*",
"*/public_html/core/*",
"*/contrib/*"
]
}
Not seeming to get the error anymore - so something to do with global vs local?
Short answer yes.
I noticed that the phpc.autoConfigSearch
picks up /public_html/core/phpcs.xml.dist which uses relative paths to itself whereas phpcs CWD the workspace root. I am not sure that this is relevant or a bug. Also I didn't test with your version of php (7.0.10) which is several versions behind latest (7.0.27)
With phpcs.autoConfigSearch
I get error:
phpcs: Uncaught PHP_CodeSniffer_Exception: Referenced sniff "../vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Array/DisallowLongArraySyntaxSniff.php"
Which is clear that PHP_Codesniffer doesn't resolve the ../vendor/... properly, probably due to the '
@wongjn Can you report the output of the following command:
phpcs --standard=public_html/core/phpcs.xml.dist -q --encoding=UTF-8 --report=json --ignore="*/public_html/core/*" public_html/core/modules/node/src/Entity/NodeType.php
Using original reproduction repo:
phpcs --standard=public_html/core/phpcs.xml.dist -q --encoding=UTF-8 --report=json --ignore="*/public_html/core/*" public_html/core/modules/node/src/Entity/NodeType.php
Fatal error: Uncaught PHP_CodeSniffer_Exception: Referenced sniff "../vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Array/DisallowLongArraySyntaxSniff.php" does not exist in C:\Users\justinwong\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\CodeSniffer.php:1167
Stack trace:
#0 C:\Users\justinwong\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\CodeSniffer.php(780): PHP_CodeSniffer->_expandRulesetReference(Object(SimpleXMLElement), 'C:\\Users\\justin...', 0)
#1 C:\Users\justinwong\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\CodeSniffer.php(578): PHP_CodeSniffer->processRuleset('C:\\Users\\justin...')
#2 C:\Users\justinwong\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\CodeSniffer\CLI.php(956): PHP_CodeSniffer->initStandard(Array, Array, Array)
#3 C:\Users\justinwong\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\CodeSniffer\CLI.php(113): PHP_CodeSniffer_CLI->process()
#4 C:\Users\justinwong\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\scripts\phpcs(25 in C:\Users\justinwong\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\CodeSniffer.php on line 1167
So it seems setting phpc.autoConfigSearch
to false
seems to be the fix?
For your specific setup yes.
I would suggest you include a .vscode/settings.json in your project and use the suggested local composer configuration.
The issue is that PHP_CodeSniffer throws this error before processing the --ignore flag so it assumes that your --standard is valid.
PS: I never got to see your reported error "phpcs: Unexpected token F in JSON at position 0" on ignored files using vscode-phpcs 1.0.4
I got the updated error message you introduced when I updated to 1.0.4. Anyways, thank you for your time, happy to say that it is fixed.
@wongjn You are welcome. I will see whether I should apply the ignorePatterns to the autoConfigSearch settings which would probably remove the necessity to turn it off.
@wongjn I just released 1.0.5 which fixed ignorePatterns issues so they are taken into account for autoConfigSearch. So you can test out removing the autoConfigSearch setting (re-enabling it)
I'm getting this error message when I open some files that have been ignored via the
phpcs.ignorePatterns
settingand that have no code sniffing errors.Extension version 1.0.2