Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Space not detected in multiline with tabs rule #349

Open
yoriiis opened this issue Jan 23, 2025 · 3 comments
Open

Space not detected in multiline with tabs rule #349

yoriiis opened this issue Jan 23, 2025 · 3 comments

Comments

@yoriiis
Copy link

yoriiis commented Jan 23, 2025

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

@VincentLanglet
Copy link
Owner

Hi,

This was implemented here

if (\strlen($token->getValue()) < $this->spaceRatio) {
return;
}

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 ?

@yoriiis
Copy link
Author

yoriiis commented Jan 24, 2025

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

@VincentLanglet
Copy link
Owner

Maybe we can investigate to see how they handled this case ?

Sure,

  • 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.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants