Twig-CS-Fixer icon indicating copy to clipboard operation
Twig-CS-Fixer copied to clipboard

Space not detected in multiline with tabs rule

Open yoriiis opened this issue 10 months ago • 3 comments

Hello @VincentLanglet,

The linter does not catch the space in the following codes. I wanted to get your opinion if it's an issue.

{# example 1 #}
{% set items = [
  {
	title: 'title',
	url: {
	  path: 'url',
	},
  },
]
%}
{# example 2 #}
{% set items = [{
	title: 'title',
	url: {
		 path: 'url',
	},
}] %}

The current config

// .twig-cs-fixer.php
$ruleset = new TwigCsFixer\Ruleset\Ruleset();
$ruleset->addStandard(new TwigCsFixer\Standard\TwigCsFixer());
$ruleset->overrideRule(new TwigCsFixer\Rules\Whitespace\IndentRule(useTab: true));
$ruleset->overrideRule(new TwigCsFixer\Rules\Punctuation\TrailingCommaMultiLineRule());
$config = new TwigCsFixer\Config\Config();
$config->setRuleset($ruleset);

Thanks

yoriiis avatar Jan 23 '25 09:01 yoriiis

Hi,

This was implemented here https://github.com/VincentLanglet/Twig-CS-Fixer/blob/0ab7a8154f7b3a6a42cbe3a467074a47bc32dcf5/src/Rules/Whitespace/IndentRule.php#L69-L71

The issue is that when I see 1, 2 or 3 spaces in a file you use tabs and consider 1 tab = 4 space, I cannot know if those space should be removed or transformed into a new tab.

So I made the choice to ignore them... Do you have a better solution ?

VincentLanglet avatar Jan 23 '25 19:01 VincentLanglet

I understand, It's not easy to handle this.

I've tested similar code with a JavaScript linter that also does formatting (ESLint, Biome) and it works. Maybe we can investigate to see how they handled this case ? Let me know what do you think. Thanks

yoriiis avatar Jan 24 '25 17:01 yoriiis

I've tested similar code with a JavaScript linter that also does formatting (ESLint, Biome) and it works. Maybe we can investigate to see how they handled this case ?

How do they handle this case for those formatting tools ?

  • How do they replace 1 space ? 0 or 1 tab ?
  • How do they replace 2 spaces ? 0 or 1 tab ?
  • How do they replace 3 spaces ? 0 or 1 tab ?
  • I assume 4 spaces are replaced by one tab.

VincentLanglet avatar Feb 23 '25 21:02 VincentLanglet