Page MenuHomePhabricator

Detect incorrectly indented array elements
Open, Needs TriagePublic

Description

The following code:

	return new TabPanelLayout(
		$name,
		[
		'id' => $name,
		'label' => $label,
		'expanded' => false,
		'tabItemConfig' => [
			'href' => $this->getFullTitle()->getLinkURL( [ 'tab' => $name ] )
			],
		'content' => $content
	] );

passes phpcs with no warnings, but the indentation of some parts is not correct:

  • Elements of the outer array ('id' to 'content') should have one extra level of indentation (and the inner array should be adjusted accordingly)
  • The closing ] on the last line should be on its own line after 'content', with the same indentation as the opening [
  • The closing ] for the 'tabItemConfig' element has 1 extra tab of indentation

All in all, this would be the end result:

	return new TabPanelLayout(
		$name,
		[
			'id' => $name,
			'label' => $label,
			'expanded' => false,
			'tabItemConfig' => [
				'href' => $this->getFullTitle()->getLinkURL( [ 'tab' => $name ] )
			],
			'content' => $content
		]
	);

If possible, this should be achieved through an existing rule in the phpcs tool, else we would write one. The sniff should have autofix.

Event Timeline

Change 934679 had a related patch set uploaded (by Daimona Eaytoy; author: Daimona Eaytoy):

[mediawiki/core@master] languages: Prettify ZhConversion.php

https://gerrit.wikimedia.org/r/934679

Change 934679 merged by jenkins-bot:

[mediawiki/core@master] languages: Prettify ZhConversion.php

https://gerrit.wikimedia.org/r/934679

Change 934676 had a related patch set uploaded (by Daimona Eaytoy; author: Daimona Eaytoy):

[mediawiki/tools/codesniffer@master] [WIP] Wrong array indentation

https://gerrit.wikimedia.org/r/934676