Indentation check gives wrong suggestions for tab-indented PHP file (php:S1808)

I am coding in PHP with PhpStorm 2022.3 and the plugin SonarLint 7.2.1.58118 on macOS 12.6.1. The plugin is connected to an active subscription of SonarCloud. I am not sure which version is running on SonarCloud, but I assume the cloud version always runs the last one.

The indentation check gives wrong suggestions on PHP file indented with tabs. It counts tabs that are in the actual file as 1 column, but it counts tabs that need to be added as 4 columns.

I have attached a simple PHP file to demonstrate the problem.

<?php

class Test
{
	public function __construct(
		string $string = 'test',
		int $int = 42,
		bool $bool = true
	)
	{
		var_dump(
			$string,
			'foo',
			'bar',
		);


		if ($bool) {
			var_dump(
				$int,
				'bar',
				'foo',
			);
		}
	}
}

I get the following 3 issues:

  • (6, 2) Align all arguments in this list at column “5”.
  • (12, 3) Align all arguments in this list at column “6”.
  • (20, 4) Align all arguments in this list at column “7”.

All those values are 3 too high, the lines should actually be aligned on columns 2, 3 and 4, as they are in the file. So I expected not getting those 3 issues at all.

I think this error is caused by the following Java file, which belongs to rule php:S1808. The indentation should be 4 for files separated by spaces, but 1 for files separated by tabs. Or, at the place where tabs are counted, a tab should be counted as 4, instead of 1.

Hi @RobinvanderVliet,

Happy new year. Sorry for the late reply. You know Christmas and all. Thanks for your report and the reproducer. I’ll try to get back to you quickly with a solution!

Best,
Nils

Hi @RobinvanderVliet,

I had a second look at your code, your request, and the rule. The rule aims to enforce various aspects of the PSR-2 standard. This standard instructs to use 4 spaces instead of tabs. Therefore we will not change this rule. If you still want to use tabs, I can only recommend you disable the indentation check of this rule.

Best,

Would it be an option to make this variable a rule property, with a default value of 4?

There are many people that use tabs, and this way they can still make use of this rule. This rule can also be useful to people that use tabs.