PHPCSStandards/PHP_CodeSniffer

Test files mess with code completition

Closed this issue · 1 comments

mabar commented

Is your feature request related to a problem?

Codesniffer tests have a lot of definitions that match common keywords and it messes up code completition (in PHPStorm):

  • names of test functions like func, true, false and null show up along with coresponding PHP keywords/constants/etc., sometimes even before them
  • in code in global scope variable types get combined (e.g. inside conditions) for variables with the same name (e.g. $container) even when proper phpdoc is defined in the file. In case of the DI container, we have defined method get() with generic return type which does not work (it is random, can't reliably replicate) because of the combined type and the PSR container (used in tests) having method with the same name.

When working with tens of packages, including third-party, working around the problem gets quite annoying. I am currently using drupal/core-vendor-hardening package to remove the test directories, with following config:

	"extra": {
		"drupal-core-vendor-hardening": {
			"squizlabs/php_codesniffer": [
				"tests",
				"src/Standards/Generic/Tests",
				"src/Standards/MySource/Tests",
				"src/Standards/PEAR/Tests",
				"src/Standards/PSR1/Tests",
				"src/Standards/PSR2/Tests",
				"src/Standards/PSR12/Tests",
				"src/Standards/Squiz/Tests",
				"src/Standards/Zend/Tests",
				"src/Standards/Generic/Tests",
				"src/Standards/Generic/Tests"
			]
		}
	},

Describe the solution you'd like

  • remove tests from released package
  • or move them into a single tests directory so they are easier to remove via Composer plugin

Additional context

image
image

jrfnl commented

@mabar This is a known issue and will be fixed in the 4.0 release.

See squizlabs/PHP_CodeSniffer#1908 and squizlabs/PHP_CodeSniffer#548 for historical context and the reasoning for the decision to change this in the 4.0 release (and not before).