VincentLanglet / Twig-CS-Fixer

A tool to automatically fix Twig Coding Standards issues
MIT License
223 stars 22 forks source link

FileNameRule not works #193

Closed seb-jean closed 7 months ago

seb-jean commented 7 months ago

Rule(s) related to or rule(s) missing

FileNameRule

Expected behavior

FileNameRule should report errors to me.

Actual behavior

I download Symfony with symfony new myproject --php=8.2 --webapp --docker --cloud

Then I download this bundle with symfony composer require --dev vincentlanglet/twig-cs-fixer

I put this config

// .twig-cs-fixer.php

<?php

use TwigCsFixer\Rules\File\FileNameRule;

$ruleset = new TwigCsFixer\Ruleset\Ruleset();
$ruleset->addRule(new FileNameRule(baseDirectory: 'templates', ignoredSubDirectories: ['bundles']));

$config = new TwigCsFixer\Config\Config();
$config->setRuleset($ruleset);
$config->setCacheFile(null);

return $config;

I rename templates/base.twig.html by templates/Xbase.twig.html for test this rule.

I execute vendor\bin\twig-cs-fixer lint but I have no errors.

VincentLanglet commented 7 months ago

Can you try

$config->setRuleset($ruleset)->allowNonFixableRules();
seb-jean commented 7 months ago

Same problem.

VincentLanglet commented 7 months ago

Same problem.

I do not reproduce with allowNonFixableRules ; do you use an old version ?

$ruleset = new \TwigCsFixer\Ruleset\Ruleset();
$ruleset->addRule(new FileNameRule(baseDirectory: 'templates', ignoredSubDirectories: ['bundles']));

$config = new \TwigCsFixer\Config\Config();
$config->setRuleset($ruleset)->allowNonFixableRules();
$config->setCacheFile(null);

return $config;

image

seb-jean commented 7 months ago

No, new version 2.4.4.

For me, $fileName is null : https://github.com/VincentLanglet/Twig-CS-Fixer/blob/main/src/Rules/File/FileNameRule.php#L49

I am on Windows

seb-jean commented 7 months ago

It's the \DIRECTORY_SEPARATOR that is causing the problem.