Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Linting Exception in non-grouped list of const/function imports #7375

Closed
daniser opened this issue Oct 17, 2023 · 0 comments · Fixed by #7397
Closed

Linting Exception in non-grouped list of const/function imports #7375

daniser opened this issue Oct 17, 2023 · 0 comments · Fixed by #7397
Labels

Comments

@daniser
Copy link

daniser commented Oct 17, 2023

Bug report

Description

CS Fixer throws an exception when I try to fix file with non-grouped const or function imports:

 [PhpCsFixer\Linter\LintingException]
 Parse error: syntax error, unexpected token "const", expecting identifier or fully qualified name or namespaced name on line 17.

Runtime version

PHP CS Fixer 3.35.1 (ec1ccc2) Freezy Vrooom by Fabien Potencier and Dariusz Ruminski.
PHP runtime: 8.1.23

Used command

php-cs-fixer fix -vvv path/to/file.php

Configuration file

<?php

$finder = (new PhpCsFixer\Finder)
    ->in([__DIR__.'/app']);

return (new PhpCsFixer\Config)
    ->setRules([
        '@PhpCsFixer' => true,
        '@PHP81Migration' => true,
        'not_operator_with_successor_space' => true,
        'single_import_per_statement' => false,
        'single_trait_insert_per_statement' => false,
        'no_superfluous_phpdoc_tags' => false,
        'phpdoc_align' => false,
        'phpdoc_var_without_name' => false,
        'phpdoc_no_empty_return' => false,
        'phpdoc_to_comment' => false,
        'return_assignment' => false,
        'new_with_parentheses' => false,
        'explicit_string_variable' => false,
        'yoda_style' => false,
        'global_namespace_import' => [
            'import_classes' => null,
        ],
        'class_attributes_separation' => [
            'elements' => [
                'property' => 'one',
                'method' => 'one',
            ],
        ],
        'ordered_class_elements' => [
            'order' => [
                'use_trait', 'case', 'constant', 'property', 'construct', 'destruct', 'magic', 'phpunit', 'method',
            ],
        ],
        'phpdoc_line_span' => [
            'const' => 'single',
            'property' => 'single',
            'method' => 'multi',
        ],
        'phpdoc_types_order' => [
            'null_adjustment' => 'always_last',
        ],
        'phpdoc_no_alias_tag' => [
            'replacements' => ['type' => 'var', 'link' => 'see'],
        ],
        'multiline_whitespace_before_semicolons' => [
            'strategy' => 'no_multi_line',
        ],
    ])
    ->setFinder($finder)
    ->setLineEnding("\n");

Code snippet that reproduces the problem

<?php

namespace MyNamespace;

use const Namespace1\CONST_1; // ok
use const Namespace1\{CONST_1, CONST_2}; // ok
use const Namespace1\CONST_1, Namespace1\CONST_2; // "syntax error"

use function Namespace2\function1; // ok
use function Namespace2\{function1, function2}; // ok
use function Namespace2\function1, Namespace2\function2; // "syntax error"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant